bkper-js 2.28.0 → 2.29.0
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/CHANGELOG.md +32 -10
- package/lib/builders/AccountsDataTableBuilder.js +247 -0
- package/lib/{model → builders}/BalancesDataTableBuilder.js +36 -13
- package/lib/builders/BooksDataTableBuilder.js +127 -0
- package/lib/builders/GroupsDataTableBuilder.js +193 -0
- package/lib/builders/TransactionsDataTableBuilder.js +359 -0
- package/lib/index.d.ts +367 -0
- package/lib/index.js +31 -27
- package/lib/model/BalancesContainerAccount.js +4 -4
- package/lib/model/BalancesContainerGroup.js +5 -5
- package/lib/model/BalancesReport.js +3 -3
- package/lib/model/Book.js +104 -60
- package/lib/model/Enums.js +24 -0
- package/lib/model/Transaction.js +46 -35
- package/package.json +1 -1
package/lib/model/Book.js
CHANGED
|
@@ -7,33 +7,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import * as AccountService from
|
|
11
|
-
import * as BookService from
|
|
12
|
-
import * as QueryService from
|
|
13
|
-
import * as BalancesService from
|
|
14
|
-
import * as FileService from
|
|
15
|
-
import * as GroupService from
|
|
16
|
-
import * as IntegrationService from
|
|
17
|
-
import * as TransactionService from
|
|
18
|
-
import * as EventService from
|
|
19
|
-
import * as CollaboratorService from
|
|
20
|
-
import * as Utils from
|
|
21
|
-
import { ResourceProperty } from
|
|
22
|
-
import { Account } from
|
|
23
|
-
import { Collaborator } from
|
|
24
|
-
import { Collection } from
|
|
25
|
-
import { Permission
|
|
26
|
-
import { EventList } from
|
|
27
|
-
import { File } from
|
|
28
|
-
import { Group } from
|
|
29
|
-
import { Integration } from
|
|
30
|
-
import { Transaction } from
|
|
31
|
-
import { TransactionList } from
|
|
32
|
-
import { BalancesReport } from
|
|
33
|
-
import { App } from
|
|
34
|
-
import { Query } from
|
|
35
|
-
import { Bkper } from
|
|
36
|
-
import { Backlog } from
|
|
10
|
+
import * as AccountService from '../service/account-service.js';
|
|
11
|
+
import * as BookService from '../service/book-service.js';
|
|
12
|
+
import * as QueryService from '../service/query-service.js';
|
|
13
|
+
import * as BalancesService from '../service/balances-service.js';
|
|
14
|
+
import * as FileService from '../service/file-service.js';
|
|
15
|
+
import * as GroupService from '../service/group-service.js';
|
|
16
|
+
import * as IntegrationService from '../service/integration-service.js';
|
|
17
|
+
import * as TransactionService from '../service/transaction-service.js';
|
|
18
|
+
import * as EventService from '../service/event-service.js';
|
|
19
|
+
import * as CollaboratorService from '../service/collaborator-service.js';
|
|
20
|
+
import * as Utils from '../utils.js';
|
|
21
|
+
import { ResourceProperty } from './ResourceProperty.js';
|
|
22
|
+
import { Account } from './Account.js';
|
|
23
|
+
import { Collaborator } from './Collaborator.js';
|
|
24
|
+
import { Collection } from './Collection.js';
|
|
25
|
+
import { Permission } from './Enums.js';
|
|
26
|
+
import { EventList } from './EventList.js';
|
|
27
|
+
import { File } from './File.js';
|
|
28
|
+
import { Group } from './Group.js';
|
|
29
|
+
import { Integration } from './Integration.js';
|
|
30
|
+
import { Transaction } from './Transaction.js';
|
|
31
|
+
import { TransactionList } from './TransactionList.js';
|
|
32
|
+
import { BalancesReport } from './BalancesReport.js';
|
|
33
|
+
import { App } from './App.js';
|
|
34
|
+
import { Query } from './Query.js';
|
|
35
|
+
import { Bkper } from './Bkper.js';
|
|
36
|
+
import { Backlog } from './Backlog.js';
|
|
37
|
+
import { AccountsDataTableBuilder } from '../builders/AccountsDataTableBuilder.js';
|
|
38
|
+
import { GroupsDataTableBuilder } from '../builders/GroupsDataTableBuilder.js';
|
|
39
|
+
import { TransactionsDataTableBuilder } from '../builders/TransactionsDataTableBuilder.js';
|
|
37
40
|
/**
|
|
38
41
|
* A Book represents a [General Ledger](https://en.wikipedia.org/wiki/General_ledger) for a company or business, but can also represent a [Ledger](https://en.wikipedia.org/wiki/Ledger) for a project or department
|
|
39
42
|
*
|
|
@@ -64,7 +67,7 @@ export class Book extends ResourceProperty {
|
|
|
64
67
|
* @returns This Book's unique identifier
|
|
65
68
|
*/
|
|
66
69
|
getId() {
|
|
67
|
-
return this.payload.id ||
|
|
70
|
+
return this.payload.id || '';
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
73
|
* Gets the name of this Book.
|
|
@@ -232,7 +235,7 @@ export class Book extends ResourceProperty {
|
|
|
232
235
|
*/
|
|
233
236
|
setLockDate(lockDate) {
|
|
234
237
|
if (lockDate == null) {
|
|
235
|
-
lockDate =
|
|
238
|
+
lockDate = '1900-00-00';
|
|
236
239
|
}
|
|
237
240
|
this.payload.lockDate = lockDate;
|
|
238
241
|
return this;
|
|
@@ -254,7 +257,7 @@ export class Book extends ResourceProperty {
|
|
|
254
257
|
*/
|
|
255
258
|
setClosingDate(closingDate) {
|
|
256
259
|
if (closingDate == null) {
|
|
257
|
-
closingDate =
|
|
260
|
+
closingDate = '1900-00-00';
|
|
258
261
|
}
|
|
259
262
|
this.payload.closingDate = closingDate;
|
|
260
263
|
return this;
|
|
@@ -388,7 +391,7 @@ export class Book extends ResourceProperty {
|
|
|
388
391
|
* @returns The formatted date
|
|
389
392
|
*/
|
|
390
393
|
formatDate(date, timeZone) {
|
|
391
|
-
if (timeZone == null || timeZone.trim() ==
|
|
394
|
+
if (timeZone == null || timeZone.trim() == '') {
|
|
392
395
|
timeZone = this.getTimeZone();
|
|
393
396
|
}
|
|
394
397
|
return Utils.formatDate(date, this.getDatePattern(), timeZone);
|
|
@@ -412,7 +415,7 @@ export class Book extends ResourceProperty {
|
|
|
412
415
|
*/
|
|
413
416
|
formatValue(value) {
|
|
414
417
|
if (!value) {
|
|
415
|
-
return
|
|
418
|
+
return '';
|
|
416
419
|
}
|
|
417
420
|
return Utils.formatValue(value, this.getDecimalSeparator(), this.getFractionDigits());
|
|
418
421
|
}
|
|
@@ -446,9 +449,9 @@ export class Book extends ResourceProperty {
|
|
|
446
449
|
batchCreateTransactions(transactions) {
|
|
447
450
|
return __awaiter(this, void 0, void 0, function* () {
|
|
448
451
|
let transactionPayloads = [];
|
|
449
|
-
transactions.forEach(
|
|
452
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
450
453
|
transactionPayloads = yield TransactionService.createTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
451
|
-
transactions = transactionPayloads.map(
|
|
454
|
+
transactions = transactionPayloads.map(tx => new Transaction(this, tx));
|
|
452
455
|
return transactions;
|
|
453
456
|
});
|
|
454
457
|
}
|
|
@@ -460,7 +463,7 @@ export class Book extends ResourceProperty {
|
|
|
460
463
|
batchPostTransactions(transactions) {
|
|
461
464
|
return __awaiter(this, void 0, void 0, function* () {
|
|
462
465
|
let transactionPayloads = [];
|
|
463
|
-
transactions.forEach(
|
|
466
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
464
467
|
yield TransactionService.postTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
465
468
|
});
|
|
466
469
|
}
|
|
@@ -476,9 +479,9 @@ export class Book extends ResourceProperty {
|
|
|
476
479
|
batchUpdateTransactions(transactions, updateChecked) {
|
|
477
480
|
return __awaiter(this, void 0, void 0, function* () {
|
|
478
481
|
let transactionPayloads = [];
|
|
479
|
-
transactions.forEach(
|
|
482
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
480
483
|
transactionPayloads = yield TransactionService.updateTransactionsBatch(this.getId(), transactionPayloads, updateChecked, this.getConfig());
|
|
481
|
-
transactions = transactionPayloads.map(
|
|
484
|
+
transactions = transactionPayloads.map(tx => new Transaction(this, tx));
|
|
482
485
|
return transactions;
|
|
483
486
|
});
|
|
484
487
|
}
|
|
@@ -490,7 +493,7 @@ export class Book extends ResourceProperty {
|
|
|
490
493
|
batchCheckTransactions(transactions) {
|
|
491
494
|
return __awaiter(this, void 0, void 0, function* () {
|
|
492
495
|
let transactionPayloads = [];
|
|
493
|
-
transactions.forEach(
|
|
496
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
494
497
|
yield TransactionService.checkTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
495
498
|
});
|
|
496
499
|
}
|
|
@@ -502,7 +505,7 @@ export class Book extends ResourceProperty {
|
|
|
502
505
|
batchUncheckTransactions(transactions) {
|
|
503
506
|
return __awaiter(this, void 0, void 0, function* () {
|
|
504
507
|
let transactionPayloads = [];
|
|
505
|
-
transactions.forEach(
|
|
508
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
506
509
|
yield TransactionService.uncheckTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
507
510
|
});
|
|
508
511
|
}
|
|
@@ -515,7 +518,7 @@ export class Book extends ResourceProperty {
|
|
|
515
518
|
batchTrashTransactions(transactions, trashChecked) {
|
|
516
519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517
520
|
let transactionPayloads = [];
|
|
518
|
-
transactions.forEach(
|
|
521
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
519
522
|
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads, trashChecked, this.getConfig());
|
|
520
523
|
});
|
|
521
524
|
}
|
|
@@ -527,7 +530,7 @@ export class Book extends ResourceProperty {
|
|
|
527
530
|
batchUntrashTransactions(transactions) {
|
|
528
531
|
return __awaiter(this, void 0, void 0, function* () {
|
|
529
532
|
let transactionPayloads = [];
|
|
530
|
-
transactions.forEach(
|
|
533
|
+
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
531
534
|
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
532
535
|
});
|
|
533
536
|
}
|
|
@@ -539,8 +542,8 @@ export class Book extends ResourceProperty {
|
|
|
539
542
|
*/
|
|
540
543
|
batchReplayEvents(events, errorOnly) {
|
|
541
544
|
return __awaiter(this, void 0, void 0, function* () {
|
|
542
|
-
const eventIds = events.map(
|
|
543
|
-
const eventPayloads = eventIds.map(
|
|
545
|
+
const eventIds = events.map(event => event.getId());
|
|
546
|
+
const eventPayloads = eventIds.map(id => ({ id: id }));
|
|
544
547
|
const eventList = { items: eventPayloads };
|
|
545
548
|
yield EventService.replayEventsBatch(this, eventList, errorOnly, this.getConfig());
|
|
546
549
|
});
|
|
@@ -556,7 +559,7 @@ export class Book extends ResourceProperty {
|
|
|
556
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
557
560
|
if (accounts.length > 0) {
|
|
558
561
|
const accountList = {
|
|
559
|
-
items: accounts.map(
|
|
562
|
+
items: accounts.map(a => a.json()),
|
|
560
563
|
};
|
|
561
564
|
const payloads = yield AccountService.createAccounts(this.getId(), accountList, this.getConfig());
|
|
562
565
|
const createdAccounts = [];
|
|
@@ -581,7 +584,7 @@ export class Book extends ResourceProperty {
|
|
|
581
584
|
batchCreateGroups(groups) {
|
|
582
585
|
return __awaiter(this, void 0, void 0, function* () {
|
|
583
586
|
if (groups.length > 0) {
|
|
584
|
-
const groupList = { items: groups.map(
|
|
587
|
+
const groupList = { items: groups.map(g => g.json()) };
|
|
585
588
|
const payloads = yield GroupService.createGroups(this.getId(), groupList, this.getConfig());
|
|
586
589
|
const createdGroups = [];
|
|
587
590
|
for (const payload of payloads) {
|
|
@@ -612,7 +615,7 @@ export class Book extends ResourceProperty {
|
|
|
612
615
|
return this.apps;
|
|
613
616
|
}
|
|
614
617
|
const appsPlain = yield BookService.getApps(this.getId(), this.getConfig());
|
|
615
|
-
this.apps = appsPlain.map(
|
|
618
|
+
this.apps = appsPlain.map(a => new App(a, this.config));
|
|
616
619
|
return this.apps;
|
|
617
620
|
});
|
|
618
621
|
}
|
|
@@ -624,7 +627,7 @@ export class Book extends ResourceProperty {
|
|
|
624
627
|
getIntegrations() {
|
|
625
628
|
return __awaiter(this, void 0, void 0, function* () {
|
|
626
629
|
const integrationsPlain = yield IntegrationService.listIntegrations(this.getId(), this.getConfig());
|
|
627
|
-
const integrations = integrationsPlain.map(
|
|
630
|
+
const integrations = integrationsPlain.map(i => new Integration(i, this.config));
|
|
628
631
|
return integrations;
|
|
629
632
|
});
|
|
630
633
|
}
|
|
@@ -692,7 +695,7 @@ export class Book extends ResourceProperty {
|
|
|
692
695
|
*/
|
|
693
696
|
getAccount(idOrName) {
|
|
694
697
|
return __awaiter(this, void 0, void 0, function* () {
|
|
695
|
-
if (!idOrName || idOrName.trim() ==
|
|
698
|
+
if (!idOrName || idOrName.trim() == '') {
|
|
696
699
|
return undefined;
|
|
697
700
|
}
|
|
698
701
|
let account;
|
|
@@ -806,7 +809,7 @@ export class Book extends ResourceProperty {
|
|
|
806
809
|
*/
|
|
807
810
|
getGroup(idOrName) {
|
|
808
811
|
return __awaiter(this, void 0, void 0, function* () {
|
|
809
|
-
if (!idOrName || idOrName.trim() ==
|
|
812
|
+
if (!idOrName || idOrName.trim() == '') {
|
|
810
813
|
return undefined;
|
|
811
814
|
}
|
|
812
815
|
let group;
|
|
@@ -864,7 +867,7 @@ export class Book extends ResourceProperty {
|
|
|
864
867
|
if (!groups) {
|
|
865
868
|
return false;
|
|
866
869
|
}
|
|
867
|
-
let groupsObj = groups.map(
|
|
870
|
+
let groupsObj = groups.map(group => new Group(this, group));
|
|
868
871
|
this.idGroupMap = new Map();
|
|
869
872
|
this.nameGroupMap = new Map();
|
|
870
873
|
for (const group of groupsObj) {
|
|
@@ -913,7 +916,7 @@ export class Book extends ResourceProperty {
|
|
|
913
916
|
if (!accounts) {
|
|
914
917
|
return false;
|
|
915
918
|
}
|
|
916
|
-
let accountsObj = accounts.map(
|
|
919
|
+
let accountsObj = accounts.map(account => new Account(this, account));
|
|
917
920
|
this.idAccountMap = new Map();
|
|
918
921
|
this.nameAccountMap = new Map();
|
|
919
922
|
for (const account of accountsObj) {
|
|
@@ -928,7 +931,7 @@ export class Book extends ResourceProperty {
|
|
|
928
931
|
var _a;
|
|
929
932
|
const groupPayloads = account.json().groups || [];
|
|
930
933
|
for (const groupPayload of groupPayloads) {
|
|
931
|
-
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id ||
|
|
934
|
+
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || '');
|
|
932
935
|
if (group != null) {
|
|
933
936
|
group.addAccount(account);
|
|
934
937
|
}
|
|
@@ -969,12 +972,12 @@ export class Book extends ResourceProperty {
|
|
|
969
972
|
setAccount(account, remove) {
|
|
970
973
|
const accountPayloads = this.payload.accounts || [];
|
|
971
974
|
if (remove) {
|
|
972
|
-
this.payload.accounts = accountPayloads.filter(
|
|
975
|
+
this.payload.accounts = accountPayloads.filter(a => a.id !== account.id);
|
|
973
976
|
}
|
|
974
977
|
else {
|
|
975
|
-
const existingAccount = accountPayloads.find(
|
|
978
|
+
const existingAccount = accountPayloads.find(a => a.id === account.id);
|
|
976
979
|
if (existingAccount) {
|
|
977
|
-
this.payload.accounts = accountPayloads.map(
|
|
980
|
+
this.payload.accounts = accountPayloads.map(a => a.id === account.id ? account : a);
|
|
978
981
|
}
|
|
979
982
|
else {
|
|
980
983
|
this.payload.accounts = [...accountPayloads, account];
|
|
@@ -985,12 +988,12 @@ export class Book extends ResourceProperty {
|
|
|
985
988
|
setGroup(group, remove) {
|
|
986
989
|
const groupPayloads = this.payload.groups || [];
|
|
987
990
|
if (remove) {
|
|
988
|
-
this.payload.groups = groupPayloads.filter(
|
|
991
|
+
this.payload.groups = groupPayloads.filter(g => g.id !== group.id);
|
|
989
992
|
}
|
|
990
993
|
else {
|
|
991
|
-
const existingGroup = groupPayloads.find(
|
|
994
|
+
const existingGroup = groupPayloads.find(g => g.id === group.id);
|
|
992
995
|
if (existingGroup) {
|
|
993
|
-
this.payload.groups = groupPayloads.map(
|
|
996
|
+
this.payload.groups = groupPayloads.map(g => (g.id === group.id ? group : g));
|
|
994
997
|
}
|
|
995
998
|
else {
|
|
996
999
|
this.payload.groups = [...groupPayloads, group];
|
|
@@ -1161,7 +1164,7 @@ export class Book extends ResourceProperty {
|
|
|
1161
1164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1162
1165
|
if (this.queries == null) {
|
|
1163
1166
|
const queryPayloads = yield QueryService.getSavedQueries(this.getId(), this.getConfig());
|
|
1164
|
-
this.queries = queryPayloads.map(
|
|
1167
|
+
this.queries = queryPayloads.map(payload => new Query(this, payload));
|
|
1165
1168
|
}
|
|
1166
1169
|
return this.queries;
|
|
1167
1170
|
});
|
|
@@ -1175,7 +1178,7 @@ export class Book extends ResourceProperty {
|
|
|
1175
1178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1176
1179
|
if (!this.collaborators) {
|
|
1177
1180
|
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId(), this.getConfig());
|
|
1178
|
-
this.collaborators = collaboratorPayloads.map(
|
|
1181
|
+
this.collaborators = collaboratorPayloads.map(payload => new Collaborator(this, payload));
|
|
1179
1182
|
}
|
|
1180
1183
|
return this.collaborators;
|
|
1181
1184
|
});
|
|
@@ -1191,5 +1194,46 @@ export class Book extends ResourceProperty {
|
|
|
1191
1194
|
return new Backlog(backlogPayload, this.config);
|
|
1192
1195
|
});
|
|
1193
1196
|
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Create a {@link AccountsDataTableBuilder}, to build two dimensional Array representations of {@link Account} dataset.
|
|
1199
|
+
*
|
|
1200
|
+
* @param accounts - Optional array of accounts. If not provided, all accounts will be fetched.
|
|
1201
|
+
*
|
|
1202
|
+
* @returns Accounts data table builder.
|
|
1203
|
+
*/
|
|
1204
|
+
createAccountsDataTable(accounts) {
|
|
1205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1206
|
+
if (!accounts) {
|
|
1207
|
+
accounts = yield this.getAccounts();
|
|
1208
|
+
}
|
|
1209
|
+
return new AccountsDataTableBuilder(accounts);
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Create a {@link GroupsDataTableBuilder}, to build two dimensional Array representations of {@link Group} dataset.
|
|
1214
|
+
*
|
|
1215
|
+
* @param groups - Optional array of groups. If not provided, all groups will be fetched.
|
|
1216
|
+
*
|
|
1217
|
+
* @returns Groups data table builder.
|
|
1218
|
+
*/
|
|
1219
|
+
createGroupsDataTable(groups) {
|
|
1220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1221
|
+
if (!groups) {
|
|
1222
|
+
groups = yield this.getGroups();
|
|
1223
|
+
}
|
|
1224
|
+
return new GroupsDataTableBuilder(groups);
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Create a {@link TransactionsDataTableBuilder}, to build two dimensional Array representations of {@link Transaction} dataset.
|
|
1229
|
+
*
|
|
1230
|
+
* @param transactions - Array of transactions to include in the table.
|
|
1231
|
+
* @param account - Optional account for balance column display.
|
|
1232
|
+
*
|
|
1233
|
+
* @returns Transactions data table builder.
|
|
1234
|
+
*/
|
|
1235
|
+
createTransactionsDataTable(transactions, account) {
|
|
1236
|
+
return new TransactionsDataTableBuilder(this, transactions, account);
|
|
1237
|
+
}
|
|
1194
1238
|
}
|
|
1195
1239
|
//# sourceMappingURL=Book.js.map
|
package/lib/model/Enums.js
CHANGED
|
@@ -168,6 +168,30 @@ export var Month;
|
|
|
168
168
|
Month["NOVEMBER"] = "NOVEMBER";
|
|
169
169
|
Month["DECEMBER"] = "DECEMBER";
|
|
170
170
|
})(Month || (Month = {}));
|
|
171
|
+
/**
|
|
172
|
+
* Enum that represents the status of a Transaction.
|
|
173
|
+
*
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
export var TransactionStatus;
|
|
177
|
+
(function (TransactionStatus) {
|
|
178
|
+
/**
|
|
179
|
+
* Transaction is in the trash
|
|
180
|
+
*/
|
|
181
|
+
TransactionStatus["TRASHED"] = "TRASHED";
|
|
182
|
+
/**
|
|
183
|
+
* Transaction is a draft, not yet posted
|
|
184
|
+
*/
|
|
185
|
+
TransactionStatus["DRAFT"] = "DRAFT";
|
|
186
|
+
/**
|
|
187
|
+
* Transaction is posted but not checked
|
|
188
|
+
*/
|
|
189
|
+
TransactionStatus["UNCHECKED"] = "UNCHECKED";
|
|
190
|
+
/**
|
|
191
|
+
* Transaction is posted and checked
|
|
192
|
+
*/
|
|
193
|
+
TransactionStatus["CHECKED"] = "CHECKED";
|
|
194
|
+
})(TransactionStatus || (TransactionStatus = {}));
|
|
171
195
|
/**
|
|
172
196
|
* Enum that represents the type of a Bot Response
|
|
173
197
|
*
|
package/lib/model/Transaction.js
CHANGED
|
@@ -7,13 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { File } from
|
|
11
|
-
import { Account } from
|
|
12
|
-
import { ResourceProperty } from
|
|
13
|
-
import
|
|
14
|
-
import * as
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
10
|
+
import { File } from './File.js';
|
|
11
|
+
import { Account } from './Account.js';
|
|
12
|
+
import { ResourceProperty } from './ResourceProperty.js';
|
|
13
|
+
import { TransactionStatus } from './Enums.js';
|
|
14
|
+
import * as TransactionService from '../service/transaction-service.js';
|
|
15
|
+
import * as Utils from '../utils.js';
|
|
16
|
+
import { Amount } from './Amount.js';
|
|
17
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
17
18
|
/**
|
|
18
19
|
*
|
|
19
20
|
* This class defines a Transaction between [credit and debit](http://en.wikipedia.org/wiki/Debits_and_credits) [[Accounts]].
|
|
@@ -146,12 +147,28 @@ export class Transaction extends ResourceProperty {
|
|
|
146
147
|
* @returns True if a transaction is locked by the book lock/closing date
|
|
147
148
|
*/
|
|
148
149
|
isLocked() {
|
|
149
|
-
const date = this.getDate() ||
|
|
150
|
-
Utils.formatDateISO(new Date(), this.book.getTimeZone());
|
|
150
|
+
const date = this.getDate() || Utils.formatDateISO(new Date(), this.book.getTimeZone());
|
|
151
151
|
const lockOrClosingDate = this.book.getMostRecentLockDate_();
|
|
152
152
|
return (lockOrClosingDate != null &&
|
|
153
153
|
Utils.getIsoDateValue(lockOrClosingDate) >= Utils.getIsoDateValue(date));
|
|
154
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets the status of the transaction.
|
|
157
|
+
*
|
|
158
|
+
* @returns The status of the Transaction
|
|
159
|
+
*/
|
|
160
|
+
getStatus() {
|
|
161
|
+
if (this.isTrashed()) {
|
|
162
|
+
return TransactionStatus.TRASHED;
|
|
163
|
+
}
|
|
164
|
+
if (!this.isPosted()) {
|
|
165
|
+
return TransactionStatus.DRAFT;
|
|
166
|
+
}
|
|
167
|
+
if (this.isChecked()) {
|
|
168
|
+
return TransactionStatus.CHECKED;
|
|
169
|
+
}
|
|
170
|
+
return TransactionStatus.UNCHECKED;
|
|
171
|
+
}
|
|
155
172
|
/**
|
|
156
173
|
* Gets all hashtags used in the transaction.
|
|
157
174
|
*
|
|
@@ -185,7 +202,7 @@ export class Transaction extends ResourceProperty {
|
|
|
185
202
|
setUrls(urls) {
|
|
186
203
|
this.payload.urls = undefined;
|
|
187
204
|
if (urls) {
|
|
188
|
-
urls.forEach(
|
|
205
|
+
urls.forEach(url => {
|
|
189
206
|
this.addUrl(url);
|
|
190
207
|
});
|
|
191
208
|
}
|
|
@@ -214,7 +231,7 @@ export class Transaction extends ResourceProperty {
|
|
|
214
231
|
*/
|
|
215
232
|
getFiles() {
|
|
216
233
|
if (this.payload.files && this.payload.files.length > 0) {
|
|
217
|
-
const files = this.payload.files.map(
|
|
234
|
+
const files = this.payload.files.map(file => new File(this.book, file));
|
|
218
235
|
return files;
|
|
219
236
|
}
|
|
220
237
|
else {
|
|
@@ -337,7 +354,7 @@ export class Transaction extends ResourceProperty {
|
|
|
337
354
|
return (_a = (yield this.getCreditAccount())) === null || _a === void 0 ? void 0 : _a.getName();
|
|
338
355
|
}
|
|
339
356
|
else {
|
|
340
|
-
return
|
|
357
|
+
return '';
|
|
341
358
|
}
|
|
342
359
|
});
|
|
343
360
|
}
|
|
@@ -400,7 +417,7 @@ export class Transaction extends ResourceProperty {
|
|
|
400
417
|
return (_a = (yield this.getDebitAccount())) === null || _a === void 0 ? void 0 : _a.getName();
|
|
401
418
|
}
|
|
402
419
|
else {
|
|
403
|
-
return
|
|
420
|
+
return '';
|
|
404
421
|
}
|
|
405
422
|
});
|
|
406
423
|
}
|
|
@@ -444,7 +461,7 @@ export class Transaction extends ResourceProperty {
|
|
|
444
461
|
* @returns The amount of this Transaction
|
|
445
462
|
*/
|
|
446
463
|
getAmount() {
|
|
447
|
-
return this.payload.amount != null && this.payload.amount.trim() !=
|
|
464
|
+
return this.payload.amount != null && this.payload.amount.trim() != ''
|
|
448
465
|
? new Amount(this.payload.amount)
|
|
449
466
|
: undefined;
|
|
450
467
|
}
|
|
@@ -468,8 +485,8 @@ export class Transaction extends ResourceProperty {
|
|
|
468
485
|
* @returns This Transaction, for chaining
|
|
469
486
|
*/
|
|
470
487
|
setAmount(amount) {
|
|
471
|
-
if (typeof amount ==
|
|
472
|
-
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) +
|
|
488
|
+
if (typeof amount == 'string') {
|
|
489
|
+
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) + '';
|
|
473
490
|
this.payload.amount = amount.toString();
|
|
474
491
|
return this;
|
|
475
492
|
}
|
|
@@ -546,7 +563,7 @@ export class Transaction extends ResourceProperty {
|
|
|
546
563
|
return otherAccount.getName();
|
|
547
564
|
}
|
|
548
565
|
else {
|
|
549
|
-
return
|
|
566
|
+
return '';
|
|
550
567
|
}
|
|
551
568
|
});
|
|
552
569
|
}
|
|
@@ -562,8 +579,7 @@ export class Transaction extends ResourceProperty {
|
|
|
562
579
|
var _a;
|
|
563
580
|
return ((yield this.getCreditAccount()) != null &&
|
|
564
581
|
account != null &&
|
|
565
|
-
((_a = (yield this.getCreditAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
566
|
-
account.getNormalizedName());
|
|
582
|
+
((_a = (yield this.getCreditAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) == account.getNormalizedName());
|
|
567
583
|
});
|
|
568
584
|
}
|
|
569
585
|
/**
|
|
@@ -578,8 +594,7 @@ export class Transaction extends ResourceProperty {
|
|
|
578
594
|
var _a;
|
|
579
595
|
return ((yield this.getDebitAccount()) != null &&
|
|
580
596
|
account != null &&
|
|
581
|
-
((_a = (yield this.getDebitAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
582
|
-
account.getNormalizedName());
|
|
597
|
+
((_a = (yield this.getDebitAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) == account.getNormalizedName());
|
|
583
598
|
});
|
|
584
599
|
}
|
|
585
600
|
/** @internal */
|
|
@@ -598,7 +613,7 @@ export class Transaction extends ResourceProperty {
|
|
|
598
613
|
*/
|
|
599
614
|
getDescription() {
|
|
600
615
|
if (this.payload.description == null) {
|
|
601
|
-
return
|
|
616
|
+
return '';
|
|
602
617
|
}
|
|
603
618
|
return this.payload.description;
|
|
604
619
|
}
|
|
@@ -629,16 +644,16 @@ export class Transaction extends ResourceProperty {
|
|
|
629
644
|
* @returns This Transaction, for chaining
|
|
630
645
|
*/
|
|
631
646
|
setDate(date) {
|
|
632
|
-
if (typeof date ==
|
|
633
|
-
if (date.indexOf(
|
|
647
|
+
if (typeof date == 'string') {
|
|
648
|
+
if (date.indexOf('/') > 0) {
|
|
634
649
|
let dateObject = Utils.parseDate(date, this.book.getDatePattern(), this.book.getTimeZone());
|
|
635
650
|
this.payload.date = Utils.formatDateISO(dateObject, this.book.getTimeZone());
|
|
636
651
|
}
|
|
637
|
-
else if (date.indexOf(
|
|
652
|
+
else if (date.indexOf('-') >= 0) {
|
|
638
653
|
this.payload.date = date;
|
|
639
654
|
}
|
|
640
655
|
}
|
|
641
|
-
else if (Object.prototype.toString.call(date) ===
|
|
656
|
+
else if (Object.prototype.toString.call(date) === '[object Date]') {
|
|
642
657
|
this.payload.date = Utils.formatDateISO(date, this.book.getTimeZone());
|
|
643
658
|
}
|
|
644
659
|
return this;
|
|
@@ -681,7 +696,7 @@ export class Transaction extends ResourceProperty {
|
|
|
681
696
|
* @returns The date the transaction was created, formatted according to the date pattern of the [[Book]]
|
|
682
697
|
*/
|
|
683
698
|
getCreatedAtFormatted() {
|
|
684
|
-
return Utils.formatDate(this.getCreatedAt(), this.book.getDatePattern() +
|
|
699
|
+
return Utils.formatDate(this.getCreatedAt(), this.book.getDatePattern() + ' HH:mm:ss', this.book.getTimeZone());
|
|
685
700
|
}
|
|
686
701
|
/**
|
|
687
702
|
* Gets the username of the user who created the transaction.
|
|
@@ -705,19 +720,17 @@ export class Transaction extends ResourceProperty {
|
|
|
705
720
|
* @returns The date the transaction was last updated, formatted according to the date pattern of the [[Book]]
|
|
706
721
|
*/
|
|
707
722
|
getUpdatedAtFormatted() {
|
|
708
|
-
return Utils.formatDate(this.getUpdatedAt(), this.book.getDatePattern() +
|
|
723
|
+
return Utils.formatDate(this.getUpdatedAt(), this.book.getDatePattern() + ' HH:mm:ss', this.book.getTimeZone());
|
|
709
724
|
}
|
|
710
725
|
/** @internal */
|
|
711
726
|
getCaEvolvedBalance_() {
|
|
712
|
-
return this.payload.creditAccount != null &&
|
|
713
|
-
this.payload.creditAccount.balance != null
|
|
727
|
+
return this.payload.creditAccount != null && this.payload.creditAccount.balance != null
|
|
714
728
|
? new Amount(this.payload.creditAccount.balance)
|
|
715
729
|
: undefined;
|
|
716
730
|
}
|
|
717
731
|
/** @internal */
|
|
718
732
|
getDaEvolvedBalance_() {
|
|
719
|
-
return this.payload.debitAccount != null &&
|
|
720
|
-
this.payload.debitAccount.balance != null
|
|
733
|
+
return this.payload.debitAccount != null && this.payload.debitAccount.balance != null
|
|
721
734
|
? new Amount(this.payload.debitAccount.balance)
|
|
722
735
|
: undefined;
|
|
723
736
|
}
|
|
@@ -742,9 +755,7 @@ export class Transaction extends ResourceProperty {
|
|
|
742
755
|
}
|
|
743
756
|
if (accountBalance != null) {
|
|
744
757
|
if (!raw) {
|
|
745
|
-
var account = isCa
|
|
746
|
-
? yield this.getCreditAccount()
|
|
747
|
-
: yield this.getDebitAccount();
|
|
758
|
+
var account = isCa ? yield this.getCreditAccount() : yield this.getDebitAccount();
|
|
748
759
|
accountBalance = Utils.getRepresentativeValue(accountBalance, account === null || account === void 0 ? void 0 : account.isCredit());
|
|
749
760
|
}
|
|
750
761
|
return Utils.round(accountBalance, this.book.getFractionDigits());
|