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.
- package/bundles/taxtank-core.umd.js +180 -155
- package/bundles/taxtank-core.umd.js.map +1 -1
- package/esm2015/lib/collections/depreciation.collection.js +8 -1
- package/esm2015/lib/collections/transaction.collection.js +4 -1
- package/esm2015/lib/models/depreciation/depreciation.js +9 -2
- package/esm2015/lib/models/pdf/pdf-config.js +3 -3
- package/esm2015/lib/services/pdf/pdf.service.js +12 -6
- package/fesm2015/taxtank-core.js +147 -126
- package/fesm2015/taxtank-core.js.map +1 -1
- package/lib/collections/depreciation.collection.d.ts +5 -0
- package/lib/collections/transaction.collection.d.ts +1 -0
- package/lib/models/depreciation/depreciation.d.ts +5 -0
- package/lib/services/pdf/pdf.service.d.ts +1 -0
- package/package.json +1 -1
package/fesm2015/taxtank-core.js
CHANGED
|
@@ -1257,6 +1257,128 @@ var TankTypeEnum;
|
|
|
1257
1257
|
TankTypeEnum[TankTypeEnum["OTHER"] = 3] = "OTHER";
|
|
1258
1258
|
})(TankTypeEnum || (TankTypeEnum = {}));
|
|
1259
1259
|
|
|
1260
|
+
/**
|
|
1261
|
+
* Collection of transactions
|
|
1262
|
+
*/
|
|
1263
|
+
class TransactionCollection extends Collection {
|
|
1264
|
+
/**
|
|
1265
|
+
* Get total amount of all transactions in the collection
|
|
1266
|
+
*/
|
|
1267
|
+
get amount() {
|
|
1268
|
+
return +this.items.reduce((sum, transaction) => sum + transaction.getNetAmount(), 0).toFixed(2);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Difference between allocated amount and total amount
|
|
1272
|
+
*/
|
|
1273
|
+
getUnallocatedAmount(allocations) {
|
|
1274
|
+
return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Get cash position
|
|
1278
|
+
* Cash Position = Income - Expenses
|
|
1279
|
+
* Cash position is equal to Total Amount because income is positive and expense is negative,
|
|
1280
|
+
*/
|
|
1281
|
+
get cashPosition() {
|
|
1282
|
+
return this.claimAmount;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Get new collection of transactions filtered by tank type
|
|
1286
|
+
* @param tankType
|
|
1287
|
+
*/
|
|
1288
|
+
getByTankType(tankType) {
|
|
1289
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.tankType === tankType));
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* get date of the last transaction
|
|
1293
|
+
*/
|
|
1294
|
+
getLastTransactionDate() {
|
|
1295
|
+
return new Date(Math.max.apply(Math, this.items.map((transaction) => transaction.date)));
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Get summary of claim amounts
|
|
1299
|
+
*/
|
|
1300
|
+
get claimAmount() {
|
|
1301
|
+
return this.items.reduce((sum, transaction) => sum + transaction.claimAmount, 0);
|
|
1302
|
+
}
|
|
1303
|
+
get grossAmount() {
|
|
1304
|
+
return +this.items.reduce((sum, transaction) => sum + transaction.amount, 0).toFixed(2);
|
|
1305
|
+
}
|
|
1306
|
+
getByCategories(categories) {
|
|
1307
|
+
return new TransactionCollection(this.items.filter((transaction) => categories.includes(transaction.chartAccounts.category)));
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Get transactions by month
|
|
1311
|
+
* @param monthIndex by which desired month should be taken
|
|
1312
|
+
*/
|
|
1313
|
+
getByMonth(monthIndex) {
|
|
1314
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.date.getMonth() === monthIndex));
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* get list of transactions filtered by chart accounts id
|
|
1318
|
+
* @param chartAccountsId chart accounts id for filtering
|
|
1319
|
+
*/
|
|
1320
|
+
getByChartAccountsId(chartAccountsId) {
|
|
1321
|
+
return this.items.filter((transaction) => transaction.chartAccounts.id === chartAccountsId);
|
|
1322
|
+
}
|
|
1323
|
+
getIncomeTransactions() {
|
|
1324
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isIncome()));
|
|
1325
|
+
}
|
|
1326
|
+
get claimIncome() {
|
|
1327
|
+
return this.getIncomeTransactions().claimAmount;
|
|
1328
|
+
}
|
|
1329
|
+
getExpenseTransactions() {
|
|
1330
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isExpense() && !transaction.isInterest()));
|
|
1331
|
+
}
|
|
1332
|
+
get claimExpense() {
|
|
1333
|
+
return this.getExpenseTransactions().claimAmount;
|
|
1334
|
+
}
|
|
1335
|
+
getInterestTransactions() {
|
|
1336
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isInterest()));
|
|
1337
|
+
}
|
|
1338
|
+
get claimInterest() {
|
|
1339
|
+
return this.getInterestTransactions().claimAmount;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Get collection of transactions and properties filtered by properties ids
|
|
1343
|
+
* @param ids Ids of properties for filter
|
|
1344
|
+
*/
|
|
1345
|
+
getByPropertiesIds(ids) {
|
|
1346
|
+
return new TransactionCollection(this.items.filter((transaction) => {
|
|
1347
|
+
var _a;
|
|
1348
|
+
return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
|
|
1349
|
+
}));
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Get new collection filtered by income source id
|
|
1353
|
+
* @param id id of income source for filter
|
|
1354
|
+
*/
|
|
1355
|
+
getByIncomeSourceId(id) {
|
|
1356
|
+
return new TransactionCollection(this.items.filter((transaction) => { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Get new collection filtered by chart accounts category
|
|
1360
|
+
* @param category Chart accounts category value
|
|
1361
|
+
*/
|
|
1362
|
+
getByChartAccountsCategory(category) {
|
|
1363
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.chartAccounts.category === category));
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Get new collection of property transactions
|
|
1367
|
+
*/
|
|
1368
|
+
getPropertyTransactions() {
|
|
1369
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isPropertyTank()));
|
|
1370
|
+
}
|
|
1371
|
+
getDebitTransactions() {
|
|
1372
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isDebit()));
|
|
1373
|
+
}
|
|
1374
|
+
getCreditTransactions() {
|
|
1375
|
+
return new TransactionCollection(this.items.filter((transaction) => transaction.isCredit()));
|
|
1376
|
+
}
|
|
1377
|
+
getByAllocations(allocations) {
|
|
1378
|
+
return new TransactionCollection(this.items.filter((transaction) => allocations.hasTransaction(transaction)));
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1260
1382
|
class DepreciationCollection extends Collection {
|
|
1261
1383
|
/**
|
|
1262
1384
|
* Get total amount of all depreciations in the collection
|
|
@@ -1323,6 +1445,12 @@ class DepreciationCollection extends Collection {
|
|
|
1323
1445
|
return depreciation.depreciationCapitalProject;
|
|
1324
1446
|
})), 'id');
|
|
1325
1447
|
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Create TransactionCollection from depreciation items
|
|
1450
|
+
*/
|
|
1451
|
+
toTransactions() {
|
|
1452
|
+
return new TransactionCollection(this.items.map((item) => item.toTransaction()));
|
|
1453
|
+
}
|
|
1326
1454
|
}
|
|
1327
1455
|
|
|
1328
1456
|
/**
|
|
@@ -1934,125 +2062,6 @@ class TransactionAllocationCollection extends Collection {
|
|
|
1934
2062
|
}
|
|
1935
2063
|
}
|
|
1936
2064
|
|
|
1937
|
-
/**
|
|
1938
|
-
* Collection of transactions
|
|
1939
|
-
*/
|
|
1940
|
-
class TransactionCollection extends Collection {
|
|
1941
|
-
/**
|
|
1942
|
-
* Get total amount of all transactions in the collection
|
|
1943
|
-
*/
|
|
1944
|
-
get amount() {
|
|
1945
|
-
return +this.items.reduce((sum, transaction) => sum + transaction.getNetAmount(), 0).toFixed(2);
|
|
1946
|
-
}
|
|
1947
|
-
/**
|
|
1948
|
-
* Difference between allocated amount and total amount
|
|
1949
|
-
*/
|
|
1950
|
-
getUnallocatedAmount(allocations) {
|
|
1951
|
-
return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
|
|
1952
|
-
}
|
|
1953
|
-
/**
|
|
1954
|
-
* Get cash position
|
|
1955
|
-
* Cash Position = Income - Expenses
|
|
1956
|
-
* Cash position is equal to Total Amount because income is positive and expense is negative,
|
|
1957
|
-
*/
|
|
1958
|
-
get cashPosition() {
|
|
1959
|
-
return this.claimAmount;
|
|
1960
|
-
}
|
|
1961
|
-
/**
|
|
1962
|
-
* Get new collection of transactions filtered by tank type
|
|
1963
|
-
* @param tankType
|
|
1964
|
-
*/
|
|
1965
|
-
getByTankType(tankType) {
|
|
1966
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.tankType === tankType));
|
|
1967
|
-
}
|
|
1968
|
-
/**
|
|
1969
|
-
* get date of the last transaction
|
|
1970
|
-
*/
|
|
1971
|
-
getLastTransactionDate() {
|
|
1972
|
-
return new Date(Math.max.apply(Math, this.items.map((transaction) => transaction.date)));
|
|
1973
|
-
}
|
|
1974
|
-
/**
|
|
1975
|
-
* Get summary of claim amounts
|
|
1976
|
-
*/
|
|
1977
|
-
get claimAmount() {
|
|
1978
|
-
return this.items.reduce((sum, transaction) => sum + transaction.claimAmount, 0);
|
|
1979
|
-
}
|
|
1980
|
-
getByCategories(categories) {
|
|
1981
|
-
return new TransactionCollection(this.items.filter((transaction) => categories.includes(transaction.chartAccounts.category)));
|
|
1982
|
-
}
|
|
1983
|
-
/**
|
|
1984
|
-
* Get transactions by month
|
|
1985
|
-
* @param monthIndex by which desired month should be taken
|
|
1986
|
-
*/
|
|
1987
|
-
getByMonth(monthIndex) {
|
|
1988
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.date.getMonth() === monthIndex));
|
|
1989
|
-
}
|
|
1990
|
-
/**
|
|
1991
|
-
* get list of transactions filtered by chart accounts id
|
|
1992
|
-
* @param chartAccountsId chart accounts id for filtering
|
|
1993
|
-
*/
|
|
1994
|
-
getByChartAccountsId(chartAccountsId) {
|
|
1995
|
-
return this.items.filter((transaction) => transaction.chartAccounts.id === chartAccountsId);
|
|
1996
|
-
}
|
|
1997
|
-
getIncomeTransactions() {
|
|
1998
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isIncome()));
|
|
1999
|
-
}
|
|
2000
|
-
get claimIncome() {
|
|
2001
|
-
return this.getIncomeTransactions().claimAmount;
|
|
2002
|
-
}
|
|
2003
|
-
getExpenseTransactions() {
|
|
2004
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isExpense() && !transaction.isInterest()));
|
|
2005
|
-
}
|
|
2006
|
-
get claimExpense() {
|
|
2007
|
-
return this.getExpenseTransactions().claimAmount;
|
|
2008
|
-
}
|
|
2009
|
-
getInterestTransactions() {
|
|
2010
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isInterest()));
|
|
2011
|
-
}
|
|
2012
|
-
get claimInterest() {
|
|
2013
|
-
return this.getInterestTransactions().claimAmount;
|
|
2014
|
-
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Get collection of transactions and properties filtered by properties ids
|
|
2017
|
-
* @param ids Ids of properties for filter
|
|
2018
|
-
*/
|
|
2019
|
-
getByPropertiesIds(ids) {
|
|
2020
|
-
return new TransactionCollection(this.items.filter((transaction) => {
|
|
2021
|
-
var _a;
|
|
2022
|
-
return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
|
|
2023
|
-
}));
|
|
2024
|
-
}
|
|
2025
|
-
/**
|
|
2026
|
-
* Get new collection filtered by income source id
|
|
2027
|
-
* @param id id of income source for filter
|
|
2028
|
-
*/
|
|
2029
|
-
getByIncomeSourceId(id) {
|
|
2030
|
-
return new TransactionCollection(this.items.filter((transaction) => { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
|
|
2031
|
-
}
|
|
2032
|
-
/**
|
|
2033
|
-
* Get new collection filtered by chart accounts category
|
|
2034
|
-
* @param category Chart accounts category value
|
|
2035
|
-
*/
|
|
2036
|
-
getByChartAccountsCategory(category) {
|
|
2037
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.chartAccounts.category === category));
|
|
2038
|
-
}
|
|
2039
|
-
/**
|
|
2040
|
-
* Get new collection of property transactions
|
|
2041
|
-
*/
|
|
2042
|
-
getPropertyTransactions() {
|
|
2043
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isPropertyTank()));
|
|
2044
|
-
}
|
|
2045
|
-
getDebitTransactions() {
|
|
2046
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isDebit()));
|
|
2047
|
-
}
|
|
2048
|
-
getCreditTransactions() {
|
|
2049
|
-
return new TransactionCollection(this.items.filter((transaction) => transaction.isCredit()));
|
|
2050
|
-
}
|
|
2051
|
-
getByAllocations(allocations) {
|
|
2052
|
-
return new TransactionCollection(this.items.filter((transaction) => allocations.hasTransaction(transaction)));
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
2065
|
/**
|
|
2057
2066
|
* Collection of user event settings
|
|
2058
2067
|
*/
|
|
@@ -4206,6 +4215,12 @@ class Depreciation extends Depreciation$1 {
|
|
|
4206
4215
|
isBuildingAtCost() {
|
|
4207
4216
|
return this.chartAccounts.id === ChartAccountsListEnum.BUILDING_AT_COST;
|
|
4208
4217
|
}
|
|
4218
|
+
/**
|
|
4219
|
+
* Create a new transaction from current depreciation
|
|
4220
|
+
*/
|
|
4221
|
+
toTransaction() {
|
|
4222
|
+
return plainToClass(Transaction, this);
|
|
4223
|
+
}
|
|
4209
4224
|
}
|
|
4210
4225
|
Depreciation.WRITTEN_OFF_THRESHOLD = 300;
|
|
4211
4226
|
Depreciation.LOW_VALUE_POOL_THRESHOLD = 1000;
|
|
@@ -8511,7 +8526,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
|
8511
8526
|
*/
|
|
8512
8527
|
const PDF_CONFIG = {
|
|
8513
8528
|
text: {
|
|
8514
|
-
fontSize:
|
|
8529
|
+
fontSize: 12,
|
|
8515
8530
|
fontName: 'helvetica',
|
|
8516
8531
|
fontStyle: '',
|
|
8517
8532
|
fontWeight: 'bold',
|
|
@@ -8522,7 +8537,7 @@ const PDF_CONFIG = {
|
|
|
8522
8537
|
},
|
|
8523
8538
|
// coords for file section title (group, table, e.t.c.)
|
|
8524
8539
|
contentTitleCoords: {
|
|
8525
|
-
marginTop:
|
|
8540
|
+
marginTop: 15
|
|
8526
8541
|
},
|
|
8527
8542
|
contentCoords: {
|
|
8528
8543
|
marginTop: 15,
|
|
@@ -8554,17 +8569,18 @@ class PdfService {
|
|
|
8554
8569
|
*/
|
|
8555
8570
|
generateFromTables(tables, title) {
|
|
8556
8571
|
const pdf = new jsPDF();
|
|
8557
|
-
|
|
8558
|
-
pdf.setFontSize(PDF_CONFIG.text.fontSize)
|
|
8559
|
-
.setFont(PDF_CONFIG.text.fontName, PDF_CONFIG.text.fontStyle, PDF_CONFIG.text.fontWeight)
|
|
8560
|
-
.text(title, PDF_CONFIG.text.positionX, PDF_CONFIG.text.positionY);
|
|
8572
|
+
this.setDocumentTitle(pdf, title);
|
|
8561
8573
|
tables.forEach((table) => {
|
|
8574
|
+
var _a, _b;
|
|
8562
8575
|
// coords of last table
|
|
8563
8576
|
const lastTableCoords = pdf['lastAutoTable'].finalY || PDF_CONFIG.contentCoords.marginTop;
|
|
8577
|
+
pdf.text((_a = table.caption) === null || _a === void 0 ? void 0 : _a.innerText, PDF_CONFIG.contentCoords.marginLeft, lastTableCoords + PDF_CONFIG.contentCoords.marginTop);
|
|
8578
|
+
// get caption height based on caption content height
|
|
8579
|
+
const captionHeight = pdf.getTextDimensions(pdf.splitTextToSize((_b = table.caption) === null || _b === void 0 ? void 0 : _b.innerText, pdf.internal.pageSize.width)).h;
|
|
8564
8580
|
// table options
|
|
8565
8581
|
const options = {
|
|
8566
8582
|
html: table,
|
|
8567
|
-
startY: lastTableCoords + PDF_CONFIG.contentTitleCoords.marginTop,
|
|
8583
|
+
startY: lastTableCoords + captionHeight + PDF_CONFIG.contentTitleCoords.marginTop,
|
|
8568
8584
|
footStyles: {
|
|
8569
8585
|
fillColor: PDF_CONFIG.text.fillColor,
|
|
8570
8586
|
textColor: PDF_CONFIG.text.textColor
|
|
@@ -8574,6 +8590,11 @@ class PdfService {
|
|
|
8574
8590
|
});
|
|
8575
8591
|
return pdf;
|
|
8576
8592
|
}
|
|
8593
|
+
setDocumentTitle(doc, title) {
|
|
8594
|
+
doc.setFontSize(PDF_CONFIG.text.fontSize)
|
|
8595
|
+
.setFont(PDF_CONFIG.text.fontName, PDF_CONFIG.text.fontStyle, PDF_CONFIG.text.fontWeight)
|
|
8596
|
+
.text(title, PDF_CONFIG.text.positionX, PDF_CONFIG.text.positionY);
|
|
8597
|
+
}
|
|
8577
8598
|
/**
|
|
8578
8599
|
* @Todo remove/refactor when all DataTable dependent methods will be cleared-up
|
|
8579
8600
|
* Generate PDF file from provided data
|