taxtank-core 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1762,6 +1762,161 @@
1762
1762
  TankTypeEnum[TankTypeEnum["OTHER"] = 3] = "OTHER";
1763
1763
  })(exports.TankTypeEnum || (exports.TankTypeEnum = {}));
1764
1764
 
1765
+ /**
1766
+ * Collection of transactions
1767
+ */
1768
+ var TransactionCollection = /** @class */ (function (_super) {
1769
+ __extends(TransactionCollection, _super);
1770
+ function TransactionCollection() {
1771
+ return _super !== null && _super.apply(this, arguments) || this;
1772
+ }
1773
+ Object.defineProperty(TransactionCollection.prototype, "amount", {
1774
+ /**
1775
+ * Get total amount of all transactions in the collection
1776
+ */
1777
+ get: function () {
1778
+ return +this.items.reduce(function (sum, transaction) { return sum + transaction.getNetAmount(); }, 0).toFixed(2);
1779
+ },
1780
+ enumerable: false,
1781
+ configurable: true
1782
+ });
1783
+ /**
1784
+ * Difference between allocated amount and total amount
1785
+ */
1786
+ TransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
1787
+ return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
1788
+ };
1789
+ Object.defineProperty(TransactionCollection.prototype, "cashPosition", {
1790
+ /**
1791
+ * Get cash position
1792
+ * Cash Position = Income - Expenses
1793
+ * Cash position is equal to Total Amount because income is positive and expense is negative,
1794
+ */
1795
+ get: function () {
1796
+ return this.claimAmount;
1797
+ },
1798
+ enumerable: false,
1799
+ configurable: true
1800
+ });
1801
+ /**
1802
+ * Get new collection of transactions filtered by tank type
1803
+ * @param tankType
1804
+ */
1805
+ TransactionCollection.prototype.getByTankType = function (tankType) {
1806
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.tankType === tankType; }));
1807
+ };
1808
+ /**
1809
+ * get date of the last transaction
1810
+ */
1811
+ TransactionCollection.prototype.getLastTransactionDate = function () {
1812
+ return new Date(Math.max.apply(Math, this.items.map(function (transaction) { return transaction.date; })));
1813
+ };
1814
+ Object.defineProperty(TransactionCollection.prototype, "claimAmount", {
1815
+ /**
1816
+ * Get summary of claim amounts
1817
+ */
1818
+ get: function () {
1819
+ return this.items.reduce(function (sum, transaction) { return sum + transaction.claimAmount; }, 0);
1820
+ },
1821
+ enumerable: false,
1822
+ configurable: true
1823
+ });
1824
+ Object.defineProperty(TransactionCollection.prototype, "grossAmount", {
1825
+ get: function () {
1826
+ return +this.items.reduce(function (sum, transaction) { return sum + transaction.amount; }, 0).toFixed(2);
1827
+ },
1828
+ enumerable: false,
1829
+ configurable: true
1830
+ });
1831
+ TransactionCollection.prototype.getByCategories = function (categories) {
1832
+ return new TransactionCollection(this.items.filter(function (transaction) { return categories.includes(transaction.chartAccounts.category); }));
1833
+ };
1834
+ /**
1835
+ * Get transactions by month
1836
+ * @param monthIndex by which desired month should be taken
1837
+ */
1838
+ TransactionCollection.prototype.getByMonth = function (monthIndex) {
1839
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.date.getMonth() === monthIndex; }));
1840
+ };
1841
+ /**
1842
+ * get list of transactions filtered by chart accounts id
1843
+ * @param chartAccountsId chart accounts id for filtering
1844
+ */
1845
+ TransactionCollection.prototype.getByChartAccountsId = function (chartAccountsId) {
1846
+ return this.items.filter(function (transaction) { return transaction.chartAccounts.id === chartAccountsId; });
1847
+ };
1848
+ TransactionCollection.prototype.getIncomeTransactions = function () {
1849
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isIncome(); }));
1850
+ };
1851
+ Object.defineProperty(TransactionCollection.prototype, "claimIncome", {
1852
+ get: function () {
1853
+ return this.getIncomeTransactions().claimAmount;
1854
+ },
1855
+ enumerable: false,
1856
+ configurable: true
1857
+ });
1858
+ TransactionCollection.prototype.getExpenseTransactions = function () {
1859
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isExpense() && !transaction.isInterest(); }));
1860
+ };
1861
+ Object.defineProperty(TransactionCollection.prototype, "claimExpense", {
1862
+ get: function () {
1863
+ return this.getExpenseTransactions().claimAmount;
1864
+ },
1865
+ enumerable: false,
1866
+ configurable: true
1867
+ });
1868
+ TransactionCollection.prototype.getInterestTransactions = function () {
1869
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isInterest(); }));
1870
+ };
1871
+ Object.defineProperty(TransactionCollection.prototype, "claimInterest", {
1872
+ get: function () {
1873
+ return this.getInterestTransactions().claimAmount;
1874
+ },
1875
+ enumerable: false,
1876
+ configurable: true
1877
+ });
1878
+ /**
1879
+ * Get collection of transactions and properties filtered by properties ids
1880
+ * @param ids Ids of properties for filter
1881
+ */
1882
+ TransactionCollection.prototype.getByPropertiesIds = function (ids) {
1883
+ return new TransactionCollection(this.items.filter(function (transaction) {
1884
+ var _a;
1885
+ return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
1886
+ }));
1887
+ };
1888
+ /**
1889
+ * Get new collection filtered by income source id
1890
+ * @param id id of income source for filter
1891
+ */
1892
+ TransactionCollection.prototype.getByIncomeSourceId = function (id) {
1893
+ return new TransactionCollection(this.items.filter(function (transaction) { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
1894
+ };
1895
+ /**
1896
+ * Get new collection filtered by chart accounts category
1897
+ * @param category Chart accounts category value
1898
+ */
1899
+ TransactionCollection.prototype.getByChartAccountsCategory = function (category) {
1900
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.chartAccounts.category === category; }));
1901
+ };
1902
+ /**
1903
+ * Get new collection of property transactions
1904
+ */
1905
+ TransactionCollection.prototype.getPropertyTransactions = function () {
1906
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isPropertyTank(); }));
1907
+ };
1908
+ TransactionCollection.prototype.getDebitTransactions = function () {
1909
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isDebit(); }));
1910
+ };
1911
+ TransactionCollection.prototype.getCreditTransactions = function () {
1912
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isCredit(); }));
1913
+ };
1914
+ TransactionCollection.prototype.getByAllocations = function (allocations) {
1915
+ return new TransactionCollection(this.items.filter(function (transaction) { return allocations.hasTransaction(transaction); }));
1916
+ };
1917
+ return TransactionCollection;
1918
+ }(Collection));
1919
+
1765
1920
  var DepreciationCollection = /** @class */ (function (_super) {
1766
1921
  __extends(DepreciationCollection, _super);
1767
1922
  function DepreciationCollection() {
@@ -1844,6 +1999,12 @@
1844
1999
  return depreciation.depreciationCapitalProject;
1845
2000
  })), 'id');
1846
2001
  };
2002
+ /**
2003
+ * Create TransactionCollection from depreciation items
2004
+ */
2005
+ DepreciationCollection.prototype.toTransactions = function () {
2006
+ return new TransactionCollection(this.items.map(function (item) { return item.toTransaction(); }));
2007
+ };
1847
2008
  return DepreciationCollection;
1848
2009
  }(Collection));
1849
2010
 
@@ -2683,154 +2844,6 @@
2683
2844
  return TransactionAllocationCollection;
2684
2845
  }(Collection));
2685
2846
 
2686
- /**
2687
- * Collection of transactions
2688
- */
2689
- var TransactionCollection = /** @class */ (function (_super) {
2690
- __extends(TransactionCollection, _super);
2691
- function TransactionCollection() {
2692
- return _super !== null && _super.apply(this, arguments) || this;
2693
- }
2694
- Object.defineProperty(TransactionCollection.prototype, "amount", {
2695
- /**
2696
- * Get total amount of all transactions in the collection
2697
- */
2698
- get: function () {
2699
- return +this.items.reduce(function (sum, transaction) { return sum + transaction.getNetAmount(); }, 0).toFixed(2);
2700
- },
2701
- enumerable: false,
2702
- configurable: true
2703
- });
2704
- /**
2705
- * Difference between allocated amount and total amount
2706
- */
2707
- TransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
2708
- return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
2709
- };
2710
- Object.defineProperty(TransactionCollection.prototype, "cashPosition", {
2711
- /**
2712
- * Get cash position
2713
- * Cash Position = Income - Expenses
2714
- * Cash position is equal to Total Amount because income is positive and expense is negative,
2715
- */
2716
- get: function () {
2717
- return this.claimAmount;
2718
- },
2719
- enumerable: false,
2720
- configurable: true
2721
- });
2722
- /**
2723
- * Get new collection of transactions filtered by tank type
2724
- * @param tankType
2725
- */
2726
- TransactionCollection.prototype.getByTankType = function (tankType) {
2727
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.tankType === tankType; }));
2728
- };
2729
- /**
2730
- * get date of the last transaction
2731
- */
2732
- TransactionCollection.prototype.getLastTransactionDate = function () {
2733
- return new Date(Math.max.apply(Math, this.items.map(function (transaction) { return transaction.date; })));
2734
- };
2735
- Object.defineProperty(TransactionCollection.prototype, "claimAmount", {
2736
- /**
2737
- * Get summary of claim amounts
2738
- */
2739
- get: function () {
2740
- return this.items.reduce(function (sum, transaction) { return sum + transaction.claimAmount; }, 0);
2741
- },
2742
- enumerable: false,
2743
- configurable: true
2744
- });
2745
- TransactionCollection.prototype.getByCategories = function (categories) {
2746
- return new TransactionCollection(this.items.filter(function (transaction) { return categories.includes(transaction.chartAccounts.category); }));
2747
- };
2748
- /**
2749
- * Get transactions by month
2750
- * @param monthIndex by which desired month should be taken
2751
- */
2752
- TransactionCollection.prototype.getByMonth = function (monthIndex) {
2753
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.date.getMonth() === monthIndex; }));
2754
- };
2755
- /**
2756
- * get list of transactions filtered by chart accounts id
2757
- * @param chartAccountsId chart accounts id for filtering
2758
- */
2759
- TransactionCollection.prototype.getByChartAccountsId = function (chartAccountsId) {
2760
- return this.items.filter(function (transaction) { return transaction.chartAccounts.id === chartAccountsId; });
2761
- };
2762
- TransactionCollection.prototype.getIncomeTransactions = function () {
2763
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isIncome(); }));
2764
- };
2765
- Object.defineProperty(TransactionCollection.prototype, "claimIncome", {
2766
- get: function () {
2767
- return this.getIncomeTransactions().claimAmount;
2768
- },
2769
- enumerable: false,
2770
- configurable: true
2771
- });
2772
- TransactionCollection.prototype.getExpenseTransactions = function () {
2773
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isExpense() && !transaction.isInterest(); }));
2774
- };
2775
- Object.defineProperty(TransactionCollection.prototype, "claimExpense", {
2776
- get: function () {
2777
- return this.getExpenseTransactions().claimAmount;
2778
- },
2779
- enumerable: false,
2780
- configurable: true
2781
- });
2782
- TransactionCollection.prototype.getInterestTransactions = function () {
2783
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isInterest(); }));
2784
- };
2785
- Object.defineProperty(TransactionCollection.prototype, "claimInterest", {
2786
- get: function () {
2787
- return this.getInterestTransactions().claimAmount;
2788
- },
2789
- enumerable: false,
2790
- configurable: true
2791
- });
2792
- /**
2793
- * Get collection of transactions and properties filtered by properties ids
2794
- * @param ids Ids of properties for filter
2795
- */
2796
- TransactionCollection.prototype.getByPropertiesIds = function (ids) {
2797
- return new TransactionCollection(this.items.filter(function (transaction) {
2798
- var _a;
2799
- return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
2800
- }));
2801
- };
2802
- /**
2803
- * Get new collection filtered by income source id
2804
- * @param id id of income source for filter
2805
- */
2806
- TransactionCollection.prototype.getByIncomeSourceId = function (id) {
2807
- return new TransactionCollection(this.items.filter(function (transaction) { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
2808
- };
2809
- /**
2810
- * Get new collection filtered by chart accounts category
2811
- * @param category Chart accounts category value
2812
- */
2813
- TransactionCollection.prototype.getByChartAccountsCategory = function (category) {
2814
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.chartAccounts.category === category; }));
2815
- };
2816
- /**
2817
- * Get new collection of property transactions
2818
- */
2819
- TransactionCollection.prototype.getPropertyTransactions = function () {
2820
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isPropertyTank(); }));
2821
- };
2822
- TransactionCollection.prototype.getDebitTransactions = function () {
2823
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isDebit(); }));
2824
- };
2825
- TransactionCollection.prototype.getCreditTransactions = function () {
2826
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isCredit(); }));
2827
- };
2828
- TransactionCollection.prototype.getByAllocations = function (allocations) {
2829
- return new TransactionCollection(this.items.filter(function (transaction) { return allocations.hasTransaction(transaction); }));
2830
- };
2831
- return TransactionCollection;
2832
- }(Collection));
2833
-
2834
2847
  /**
2835
2848
  * Collection of user event settings
2836
2849
  */
@@ -5524,6 +5537,12 @@
5524
5537
  Depreciation.prototype.isBuildingAtCost = function () {
5525
5538
  return this.chartAccounts.id === exports.ChartAccountsListEnum.BUILDING_AT_COST;
5526
5539
  };
5540
+ /**
5541
+ * Create a new transaction from current depreciation
5542
+ */
5543
+ Depreciation.prototype.toTransaction = function () {
5544
+ return classTransformer.plainToClass(Transaction, this);
5545
+ };
5527
5546
  return Depreciation;
5528
5547
  }(Depreciation$1));
5529
5548
  Depreciation.WRITTEN_OFF_THRESHOLD = 300;
@@ -10462,7 +10481,7 @@
10462
10481
  */
10463
10482
  var PDF_CONFIG = {
10464
10483
  text: {
10465
- fontSize: 18,
10484
+ fontSize: 12,
10466
10485
  fontName: 'helvetica',
10467
10486
  fontStyle: '',
10468
10487
  fontWeight: 'bold',
@@ -10473,7 +10492,7 @@
10473
10492
  },
10474
10493
  // coords for file section title (group, table, e.t.c.)
10475
10494
  contentTitleCoords: {
10476
- marginTop: 20
10495
+ marginTop: 15
10477
10496
  },
10478
10497
  contentCoords: {
10479
10498
  marginTop: 15,
@@ -10507,17 +10526,18 @@
10507
10526
  */
10508
10527
  PdfService.prototype.generateFromTables = function (tables, title) {
10509
10528
  var pdf = new jsPDF__default["default"]();
10510
- // set document title
10511
- pdf.setFontSize(PDF_CONFIG.text.fontSize)
10512
- .setFont(PDF_CONFIG.text.fontName, PDF_CONFIG.text.fontStyle, PDF_CONFIG.text.fontWeight)
10513
- .text(title, PDF_CONFIG.text.positionX, PDF_CONFIG.text.positionY);
10529
+ this.setDocumentTitle(pdf, title);
10514
10530
  tables.forEach(function (table) {
10531
+ var _a, _b;
10515
10532
  // coords of last table
10516
10533
  var lastTableCoords = pdf['lastAutoTable'].finalY || PDF_CONFIG.contentCoords.marginTop;
10534
+ pdf.text((_a = table.caption) === null || _a === void 0 ? void 0 : _a.innerText, PDF_CONFIG.contentCoords.marginLeft, lastTableCoords + PDF_CONFIG.contentCoords.marginTop);
10535
+ // get caption height based on caption content height
10536
+ var captionHeight = pdf.getTextDimensions(pdf.splitTextToSize((_b = table.caption) === null || _b === void 0 ? void 0 : _b.innerText, pdf.internal.pageSize.width)).h;
10517
10537
  // table options
10518
10538
  var options = {
10519
10539
  html: table,
10520
- startY: lastTableCoords + PDF_CONFIG.contentTitleCoords.marginTop,
10540
+ startY: lastTableCoords + captionHeight + PDF_CONFIG.contentTitleCoords.marginTop,
10521
10541
  footStyles: {
10522
10542
  fillColor: PDF_CONFIG.text.fillColor,
10523
10543
  textColor: PDF_CONFIG.text.textColor
@@ -10527,6 +10547,11 @@
10527
10547
  });
10528
10548
  return pdf;
10529
10549
  };
10550
+ PdfService.prototype.setDocumentTitle = function (doc, title) {
10551
+ doc.setFontSize(PDF_CONFIG.text.fontSize)
10552
+ .setFont(PDF_CONFIG.text.fontName, PDF_CONFIG.text.fontStyle, PDF_CONFIG.text.fontWeight)
10553
+ .text(title, PDF_CONFIG.text.positionX, PDF_CONFIG.text.positionY);
10554
+ };
10530
10555
  /**
10531
10556
  * @Todo remove/refactor when all DataTable dependent methods will be cleared-up
10532
10557
  * Generate PDF file from provided data