bkper-js 1.18.1 → 1.19.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/lib/index.d.ts +182 -0
- package/lib/index.js +1 -0
- package/lib/model/BalancesContainer.js +2 -0
- package/lib/model/BalancesContainerAccount.js +99 -0
- package/lib/model/BalancesContainerGroup.js +160 -0
- package/lib/model/BalancesReport.js +106 -0
- package/lib/model/Book.js +26 -0
- package/lib/model/Group.js +12 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -371,6 +371,161 @@ export declare class App {
|
|
|
371
371
|
update(): Promise<App>;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
/**
|
|
375
|
+
* The container of balances of an [[Account]] or [[Group]]
|
|
376
|
+
*
|
|
377
|
+
* The container is composed of a list of [[Balances]] for a window of time, as well as its period and cumulative totals.
|
|
378
|
+
*
|
|
379
|
+
* @public
|
|
380
|
+
*/
|
|
381
|
+
export declare interface BalancesContainer {
|
|
382
|
+
/**
|
|
383
|
+
* @returns The parent BalancesReport of the container
|
|
384
|
+
*/
|
|
385
|
+
getBalancesReport(): BalancesReport;
|
|
386
|
+
/**
|
|
387
|
+
* @returns The [[Account]] or [[Group]] name
|
|
388
|
+
*/
|
|
389
|
+
getName(): string | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* @returns The [[Account]] or [[Group]] name without spaces or special characters.
|
|
392
|
+
*/
|
|
393
|
+
getNormalizedName(): string | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* @returns The [[Group]] associated with this container
|
|
396
|
+
*/
|
|
397
|
+
getGroup(): Promise<Group | null>;
|
|
398
|
+
/**
|
|
399
|
+
* @returns The [[Account]] associated with this container
|
|
400
|
+
*/
|
|
401
|
+
getAccount(): Promise<Account | null>;
|
|
402
|
+
/**
|
|
403
|
+
* @returns The parent BalanceContainer.
|
|
404
|
+
*/
|
|
405
|
+
getParent(): BalancesContainer | null;
|
|
406
|
+
/**
|
|
407
|
+
* @returns The depth in the parent chain up to the root.
|
|
408
|
+
*/
|
|
409
|
+
getDepth(): number;
|
|
410
|
+
/**
|
|
411
|
+
* @returns Gets the credit nature of the BalancesContainer, based on [[Account]] or [[Group]].
|
|
412
|
+
*
|
|
413
|
+
* For [[Account]], the credit nature will be the same as the one from the Account
|
|
414
|
+
*
|
|
415
|
+
* For [[Group]], the credit nature will be the same, if all accounts containing on it has the same credit nature. False if mixed.
|
|
416
|
+
*
|
|
417
|
+
*/
|
|
418
|
+
isCredit(): boolean | undefined;
|
|
419
|
+
/**
|
|
420
|
+
*
|
|
421
|
+
* Tell if this balance container is permament, based on the [[Account]] or [[Group]].
|
|
422
|
+
*
|
|
423
|
+
* Permanent are the ones which final balance is relevant and keep its balances over time.
|
|
424
|
+
*
|
|
425
|
+
* They are also called [Real Accounts](http://en.wikipedia.org/wiki/Account_(accountancy)#Based_on_periodicity_of_flow)
|
|
426
|
+
*
|
|
427
|
+
* Usually represents assets or liabilities, capable of being perceived by the senses or the mind, like bank accounts, money, debts and so on.
|
|
428
|
+
*
|
|
429
|
+
* @returns True if its a permanent Account
|
|
430
|
+
*/
|
|
431
|
+
isPermanent(): boolean | undefined;
|
|
432
|
+
/**
|
|
433
|
+
* @returns True if this balance container if from an [[Account]]
|
|
434
|
+
*/
|
|
435
|
+
isFromAccount(): boolean;
|
|
436
|
+
/**
|
|
437
|
+
* @returns True if this balance container if from a [[Group]]
|
|
438
|
+
*/
|
|
439
|
+
isFromGroup(): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* @returns True if the balance container is from a parent group
|
|
442
|
+
*/
|
|
443
|
+
hasGroupBalances(): boolean;
|
|
444
|
+
/**
|
|
445
|
+
* @returns The cumulative balance to the date.
|
|
446
|
+
*/
|
|
447
|
+
getCumulativeBalance(): Amount;
|
|
448
|
+
/**
|
|
449
|
+
* @returns The cumulative raw balance to the date.
|
|
450
|
+
*/
|
|
451
|
+
getCumulativeBalanceRaw(): Amount;
|
|
452
|
+
/**
|
|
453
|
+
* @returns The cumulative balance formatted according to [[Book]] decimal format and fraction digits.
|
|
454
|
+
*/
|
|
455
|
+
getCumulativeBalanceText(): string;
|
|
456
|
+
/**
|
|
457
|
+
* @returns The cumulative raw balance formatted according to [[Book]] decimal format and fraction digits.
|
|
458
|
+
*/
|
|
459
|
+
getCumulativeBalanceRawText(): string;
|
|
460
|
+
/**
|
|
461
|
+
* @returns The balance on the date period.
|
|
462
|
+
*/
|
|
463
|
+
getPeriodBalance(): Amount;
|
|
464
|
+
/**
|
|
465
|
+
* @returns The raw balance on the date period.
|
|
466
|
+
*/
|
|
467
|
+
getPeriodBalanceRaw(): Amount;
|
|
468
|
+
/**
|
|
469
|
+
* @returns The balance on the date period formatted according to [[Book]] decimal format and fraction digits
|
|
470
|
+
*/
|
|
471
|
+
getPeriodBalanceText(): string;
|
|
472
|
+
/**
|
|
473
|
+
* @returns The raw balance on the date period formatted according to [[Book]] decimal format and fraction digits
|
|
474
|
+
*/
|
|
475
|
+
getPeriodBalanceRawText(): string;
|
|
476
|
+
/**
|
|
477
|
+
* @returns All child [[BalancesContainers]].
|
|
478
|
+
*
|
|
479
|
+
* **NOTE**: Only for Group balance containers. Accounts returns null.
|
|
480
|
+
*/
|
|
481
|
+
getBalancesContainers(): BalancesContainer[];
|
|
482
|
+
/**
|
|
483
|
+
* Gets a specific [[BalancesContainer]].
|
|
484
|
+
*
|
|
485
|
+
* @param name The [[Account]] or [[Group]] name.
|
|
486
|
+
*
|
|
487
|
+
* @returns The retrieved [[BalancesContainer]].
|
|
488
|
+
*/
|
|
489
|
+
getBalancesContainer(name: string): BalancesContainer;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Class representing a Balance Report, generated when calling [Book.getBalanceReport](#book_getbalancesreport)
|
|
494
|
+
*
|
|
495
|
+
* @public
|
|
496
|
+
*/
|
|
497
|
+
export declare class BalancesReport {
|
|
498
|
+
payload: bkper.Balances;
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
constructor(book: Book, payload: bkper.Balances);
|
|
504
|
+
/**
|
|
505
|
+
* @returns The [[Book]] that generated the report.
|
|
506
|
+
*/
|
|
507
|
+
getBook(): Book;
|
|
508
|
+
/**
|
|
509
|
+
* @returns The [[Periodicity]] of the query used to generate the report.
|
|
510
|
+
*/
|
|
511
|
+
getPeriodicity(): Periodicity;
|
|
512
|
+
/**
|
|
513
|
+
* @returns All [[BalancesContainers]] of the report.
|
|
514
|
+
*/
|
|
515
|
+
getBalancesContainers(): BalancesContainer[];
|
|
516
|
+
/**
|
|
517
|
+
* Gets a specific [[BalancesContainer]].
|
|
518
|
+
*
|
|
519
|
+
* @param name The [[Account]] or [[Group]] name.
|
|
520
|
+
*
|
|
521
|
+
* @returns The retrieved [[BalancesContainer]].
|
|
522
|
+
*/
|
|
523
|
+
getBalancesContainer(name: string): BalancesContainer;
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
}
|
|
528
|
+
|
|
374
529
|
/**
|
|
375
530
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
376
531
|
*
|
|
@@ -820,6 +975,25 @@ export declare class Book {
|
|
|
820
975
|
* Perform update Book, applying pending changes.
|
|
821
976
|
*/
|
|
822
977
|
update(): Promise<Book>;
|
|
978
|
+
/**
|
|
979
|
+
*
|
|
980
|
+
* Create a [[BalancesReport]] based on query
|
|
981
|
+
*
|
|
982
|
+
* @param query The balances report query
|
|
983
|
+
*
|
|
984
|
+
* @return The balances report
|
|
985
|
+
*
|
|
986
|
+
* Example:
|
|
987
|
+
*
|
|
988
|
+
* ```js
|
|
989
|
+
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgPXjx7oKDA");
|
|
990
|
+
*
|
|
991
|
+
* var balancesReport = book.getBalancesReport("group:'Equity' after:7/2018 before:8/2018");
|
|
992
|
+
*
|
|
993
|
+
* var accountBalance = balancesReport.getBalancesContainer("Bank Account").getCumulativeBalance();
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
getBalancesReport(query: string): Promise<BalancesReport>;
|
|
823
997
|
}
|
|
824
998
|
|
|
825
999
|
/**
|
|
@@ -1334,6 +1508,14 @@ export declare class Group {
|
|
|
1334
1508
|
* Hide/Show group on main menu.
|
|
1335
1509
|
*/
|
|
1336
1510
|
setHidden(hidden: boolean): Group;
|
|
1511
|
+
/**
|
|
1512
|
+
* Tell if this is a credit (Incoming and Liabities) group
|
|
1513
|
+
*/
|
|
1514
|
+
isCredit(): boolean | undefined;
|
|
1515
|
+
/**
|
|
1516
|
+
* Tell if this is a mixed (Assets/Liabilities or Incoming/Outgoing) group
|
|
1517
|
+
*/
|
|
1518
|
+
isMixed(): boolean | undefined;
|
|
1337
1519
|
/**
|
|
1338
1520
|
* Tell if the Group is permanent
|
|
1339
1521
|
*/
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
export { Account } from './model/Account.js';
|
|
9
9
|
export { Amount } from "./model/Amount.js";
|
|
10
10
|
export { App } from './model/App.js';
|
|
11
|
+
export { BalancesReport } from './model/BalancesReport.js';
|
|
11
12
|
export { Bkper } from './model/Bkper.js';
|
|
12
13
|
export { Book } from './model/Book.js';
|
|
13
14
|
export { Collection } from './model/Collection.js';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getRepresentativeValue, normalizeName } from "../utils";
|
|
11
|
+
import { Amount } from "./Amount";
|
|
12
|
+
/** @internal */
|
|
13
|
+
export class AccountBalancesContainer {
|
|
14
|
+
constructor(parent, balancesReport, payload) {
|
|
15
|
+
this.parent = parent;
|
|
16
|
+
this.balancesReport = balancesReport;
|
|
17
|
+
this.payload = payload;
|
|
18
|
+
}
|
|
19
|
+
getBalancesReport() {
|
|
20
|
+
return this.balancesReport;
|
|
21
|
+
}
|
|
22
|
+
getName() {
|
|
23
|
+
return this.payload.name;
|
|
24
|
+
}
|
|
25
|
+
getNormalizedName() {
|
|
26
|
+
return this.payload.normalizedName;
|
|
27
|
+
}
|
|
28
|
+
getGroup() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getAccount() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const account = yield this.balancesReport.getBook().getAccount(this.getNormalizedName());
|
|
36
|
+
return account || null;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getParent() {
|
|
40
|
+
return this.parent;
|
|
41
|
+
}
|
|
42
|
+
getDepth() {
|
|
43
|
+
if (this.depth == null) {
|
|
44
|
+
const parent = this.getParent();
|
|
45
|
+
this.depth = parent != null ? parent.getDepth() + 1 : 0;
|
|
46
|
+
}
|
|
47
|
+
return this.depth;
|
|
48
|
+
}
|
|
49
|
+
isCredit() {
|
|
50
|
+
return this.payload.credit;
|
|
51
|
+
}
|
|
52
|
+
isPermanent() {
|
|
53
|
+
return this.payload.permanent;
|
|
54
|
+
}
|
|
55
|
+
isFromAccount() {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
isFromGroup() {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
hasGroupBalances() {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
getCumulativeBalance() {
|
|
65
|
+
return getRepresentativeValue(new Amount(this.payload.cumulativeBalance || 0), this.isCredit());
|
|
66
|
+
}
|
|
67
|
+
getCumulativeBalanceRaw() {
|
|
68
|
+
return new Amount(this.payload.cumulativeBalance || 0);
|
|
69
|
+
}
|
|
70
|
+
getCumulativeBalanceText() {
|
|
71
|
+
return this.balancesReport.getBook().formatValue(this.getCumulativeBalance());
|
|
72
|
+
}
|
|
73
|
+
getCumulativeBalanceRawText() {
|
|
74
|
+
return this.balancesReport.getBook().formatValue(this.getCumulativeBalanceRaw());
|
|
75
|
+
}
|
|
76
|
+
getPeriodBalance() {
|
|
77
|
+
return getRepresentativeValue(new Amount(this.payload.periodBalance || 0), this.isCredit());
|
|
78
|
+
}
|
|
79
|
+
getPeriodBalanceRaw() {
|
|
80
|
+
return new Amount(this.payload.periodBalance || 0);
|
|
81
|
+
}
|
|
82
|
+
getPeriodBalanceText() {
|
|
83
|
+
return this.balancesReport.getBook().formatValue(this.getPeriodBalance());
|
|
84
|
+
}
|
|
85
|
+
getPeriodBalanceRawText() {
|
|
86
|
+
return this.balancesReport.getBook().formatValue(this.getPeriodBalanceRaw());
|
|
87
|
+
}
|
|
88
|
+
getBalancesContainers() {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
getBalancesContainer(name) {
|
|
92
|
+
const normalizedName = normalizeName(name);
|
|
93
|
+
if (this.getNormalizedName() == normalizedName) {
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
throw `${name} does not match ${this.getName()}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=BalancesContainerAccount.js.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Amount } from "./Amount";
|
|
11
|
+
import { getRepresentativeValue, normalizeName } from "../utils";
|
|
12
|
+
import { AccountBalancesContainer } from "./BalancesContainerAccount";
|
|
13
|
+
/** @internal */
|
|
14
|
+
export class GroupBalancesContainer {
|
|
15
|
+
constructor(parent, balancesReport, payload) {
|
|
16
|
+
this.parent = parent;
|
|
17
|
+
this.balancesReport = balancesReport;
|
|
18
|
+
this.payload = payload;
|
|
19
|
+
}
|
|
20
|
+
getBalancesReport() {
|
|
21
|
+
return this.balancesReport;
|
|
22
|
+
}
|
|
23
|
+
getName() {
|
|
24
|
+
return this.payload.name;
|
|
25
|
+
}
|
|
26
|
+
getNormalizedName() {
|
|
27
|
+
return this.payload.normalizedName;
|
|
28
|
+
}
|
|
29
|
+
getGroup() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const group = yield this.balancesReport.getBook().getGroup(this.getNormalizedName());
|
|
32
|
+
return group || null;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getAccount() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getParent() {
|
|
41
|
+
return this.parent;
|
|
42
|
+
}
|
|
43
|
+
getDepth() {
|
|
44
|
+
if (this.depth == null) {
|
|
45
|
+
const parent = this.getParent();
|
|
46
|
+
this.depth = parent != null ? parent.getDepth() + 1 : 0;
|
|
47
|
+
}
|
|
48
|
+
return this.depth;
|
|
49
|
+
}
|
|
50
|
+
isCredit() {
|
|
51
|
+
return this.payload.credit;
|
|
52
|
+
}
|
|
53
|
+
isPermanent() {
|
|
54
|
+
return this.payload.permanent;
|
|
55
|
+
}
|
|
56
|
+
isFromAccount() {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
isFromGroup() {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
hasGroupBalances() {
|
|
63
|
+
const groupContainers = this.getGroupContainers();
|
|
64
|
+
return groupContainers != null && groupContainers.length > 0;
|
|
65
|
+
}
|
|
66
|
+
getCumulativeBalance() {
|
|
67
|
+
return getRepresentativeValue(new Amount(this.payload.cumulativeBalance || 0), this.isCredit());
|
|
68
|
+
}
|
|
69
|
+
getCumulativeBalanceRaw() {
|
|
70
|
+
return new Amount(this.payload.cumulativeBalance || 0);
|
|
71
|
+
}
|
|
72
|
+
getCumulativeBalanceText() {
|
|
73
|
+
return this.balancesReport.getBook().formatValue(this.getCumulativeBalance());
|
|
74
|
+
}
|
|
75
|
+
getCumulativeBalanceRawText() {
|
|
76
|
+
return this.balancesReport.getBook().formatValue(this.getCumulativeBalanceRaw());
|
|
77
|
+
}
|
|
78
|
+
getPeriodBalance() {
|
|
79
|
+
return getRepresentativeValue(new Amount(this.payload.periodBalance || 0), this.isCredit());
|
|
80
|
+
}
|
|
81
|
+
getPeriodBalanceRaw() {
|
|
82
|
+
return new Amount(this.payload.periodBalance || 0);
|
|
83
|
+
}
|
|
84
|
+
getPeriodBalanceText() {
|
|
85
|
+
return this.balancesReport.getBook().formatValue(this.getPeriodBalance());
|
|
86
|
+
}
|
|
87
|
+
getPeriodBalanceRawText() {
|
|
88
|
+
return this.balancesReport.getBook().formatValue(this.getPeriodBalanceRaw());
|
|
89
|
+
}
|
|
90
|
+
getBalancesContainers() {
|
|
91
|
+
let containers = [];
|
|
92
|
+
const groupContainers = this.getGroupContainers();
|
|
93
|
+
if (groupContainers && groupContainers.length > 0) {
|
|
94
|
+
containers = containers.concat(groupContainers);
|
|
95
|
+
}
|
|
96
|
+
const accountContainers = this.getAccountContainers();
|
|
97
|
+
if (accountContainers && accountContainers.length > 0) {
|
|
98
|
+
containers = containers.concat(accountContainers);
|
|
99
|
+
}
|
|
100
|
+
return containers;
|
|
101
|
+
}
|
|
102
|
+
/** @internal */
|
|
103
|
+
getGroupContainers() {
|
|
104
|
+
let groupBalances = this.payload.groupBalances;
|
|
105
|
+
if (this.groupBalances == null && groupBalances != null) {
|
|
106
|
+
this.groupBalances = [];
|
|
107
|
+
for (let i = 0; i < groupBalances.length; i++) {
|
|
108
|
+
const groupBalance = groupBalances[i];
|
|
109
|
+
this.groupBalances.push(new GroupBalancesContainer(this, this.balancesReport, groupBalance));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return this.groupBalances || [];
|
|
113
|
+
}
|
|
114
|
+
/** @internal */
|
|
115
|
+
getAccountContainers() {
|
|
116
|
+
let accountBalances = this.payload.accountBalances;
|
|
117
|
+
if (this.accountBalances == null && accountBalances != null) {
|
|
118
|
+
this.accountBalances = [];
|
|
119
|
+
for (let i = 0; i < accountBalances.length; i++) {
|
|
120
|
+
const accountBalance = accountBalances[i];
|
|
121
|
+
this.accountBalances.push(new AccountBalancesContainer(this, this.balancesReport, accountBalance));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return this.accountBalances || [];
|
|
125
|
+
}
|
|
126
|
+
getBalancesContainer(name) {
|
|
127
|
+
var _a;
|
|
128
|
+
const normalizedName = normalizeName(name);
|
|
129
|
+
const rootContainers = this.getBalancesContainers();
|
|
130
|
+
if (rootContainers == null || rootContainers.length === 0) {
|
|
131
|
+
throw `${name} not found on group ${this.getName()}`;
|
|
132
|
+
}
|
|
133
|
+
if (this.balancesContainersMap == null) {
|
|
134
|
+
this.balancesContainersMap = this.fillBalancesContainersMap(new Map(), rootContainers);
|
|
135
|
+
}
|
|
136
|
+
const balancesContainer = (_a = this.balancesContainersMap) === null || _a === void 0 ? void 0 : _a.get(normalizedName);
|
|
137
|
+
if (!balancesContainer) {
|
|
138
|
+
throw `${name} not found on group ${this.getName()}`;
|
|
139
|
+
}
|
|
140
|
+
return balancesContainer;
|
|
141
|
+
}
|
|
142
|
+
/** @internal */
|
|
143
|
+
fillBalancesContainersMap(map, containers) {
|
|
144
|
+
for (let i = 0; i < containers.length; i++) {
|
|
145
|
+
const container = containers[i];
|
|
146
|
+
const normalizedName = container.getNormalizedName();
|
|
147
|
+
if (normalizedName) {
|
|
148
|
+
if (!map.has(normalizedName)) {
|
|
149
|
+
map.set(normalizedName, container);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const nextContainers = container.getBalancesContainers();
|
|
153
|
+
if (nextContainers && nextContainers.length > 0) {
|
|
154
|
+
this.fillBalancesContainersMap(map, nextContainers);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return map;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=BalancesContainerGroup.js.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { normalizeName } from "../utils";
|
|
2
|
+
import { AccountBalancesContainer } from "./BalancesContainerAccount";
|
|
3
|
+
import { GroupBalancesContainer } from "./BalancesContainerGroup";
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a Balance Report, generated when calling [Book.getBalanceReport](#book_getbalancesreport)
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class BalancesReport {
|
|
10
|
+
constructor(book, payload) {
|
|
11
|
+
this.book = book;
|
|
12
|
+
this.payload = payload;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @returns The [[Book]] that generated the report.
|
|
16
|
+
*/
|
|
17
|
+
getBook() {
|
|
18
|
+
return this.book;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @returns The [[Periodicity]] of the query used to generate the report.
|
|
22
|
+
*/
|
|
23
|
+
getPeriodicity() {
|
|
24
|
+
return this.payload.periodicity;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @returns All [[BalancesContainers]] of the report.
|
|
28
|
+
*/
|
|
29
|
+
getBalancesContainers() {
|
|
30
|
+
let containers = [];
|
|
31
|
+
const accountContainers = this.getRootAccountBalancesContainers();
|
|
32
|
+
if (accountContainers && accountContainers.length > 0) {
|
|
33
|
+
containers = containers.concat(accountContainers);
|
|
34
|
+
}
|
|
35
|
+
const groupContainers = this.getGroupBalancesContainers();
|
|
36
|
+
if (groupContainers && groupContainers.length > 0) {
|
|
37
|
+
containers = containers.concat(groupContainers);
|
|
38
|
+
}
|
|
39
|
+
return containers;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets a specific [[BalancesContainer]].
|
|
43
|
+
*
|
|
44
|
+
* @param name The [[Account]] or [[Group]] name.
|
|
45
|
+
*
|
|
46
|
+
* @returns The retrieved [[BalancesContainer]].
|
|
47
|
+
*/
|
|
48
|
+
getBalancesContainer(name) {
|
|
49
|
+
var _a;
|
|
50
|
+
const normalizedName = normalizeName(name);
|
|
51
|
+
const rootContainers = this.getBalancesContainers();
|
|
52
|
+
if (rootContainers == null || rootContainers.length === 0) {
|
|
53
|
+
throw `${name} not found`;
|
|
54
|
+
}
|
|
55
|
+
if (this.balancesContainersMap == null) {
|
|
56
|
+
this.balancesContainersMap = this.fillBalancesContainersMap(new Map(), rootContainers);
|
|
57
|
+
}
|
|
58
|
+
const balancesContainer = (_a = this.balancesContainersMap) === null || _a === void 0 ? void 0 : _a.get(normalizedName);
|
|
59
|
+
if (!balancesContainer) {
|
|
60
|
+
throw `${name} not found`;
|
|
61
|
+
}
|
|
62
|
+
return balancesContainer;
|
|
63
|
+
}
|
|
64
|
+
/** @internal */
|
|
65
|
+
getRootAccountBalancesContainers() {
|
|
66
|
+
if (this.accountBalancesContainers == null && this.payload.accountBalances != null) {
|
|
67
|
+
this.accountBalancesContainers = [];
|
|
68
|
+
for (let i = 0; i < this.payload.accountBalances.length; i++) {
|
|
69
|
+
const accountBalances = this.payload.accountBalances[i];
|
|
70
|
+
const accountBalancesContainer = new AccountBalancesContainer(null, this, accountBalances);
|
|
71
|
+
this.accountBalancesContainers.push(accountBalancesContainer);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return this.accountBalancesContainers || [];
|
|
75
|
+
}
|
|
76
|
+
/** @internal */
|
|
77
|
+
getGroupBalancesContainers() {
|
|
78
|
+
if (this.groupBalancesContainers == null && this.payload.groupBalances != null) {
|
|
79
|
+
this.groupBalancesContainers = [];
|
|
80
|
+
for (let i = 0; i < this.payload.groupBalances.length; i++) {
|
|
81
|
+
const groupBalances = this.payload.groupBalances[i];
|
|
82
|
+
const groupBalancesContainer = new GroupBalancesContainer(null, this, groupBalances);
|
|
83
|
+
this.groupBalancesContainers.push(groupBalancesContainer);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this.groupBalancesContainers || [];
|
|
87
|
+
}
|
|
88
|
+
/** @internal */
|
|
89
|
+
fillBalancesContainersMap(map, containers) {
|
|
90
|
+
for (let i = 0; i < containers.length; i++) {
|
|
91
|
+
const container = containers[i];
|
|
92
|
+
const normalizedName = container.getNormalizedName();
|
|
93
|
+
if (normalizedName) {
|
|
94
|
+
if (!map.has(normalizedName)) {
|
|
95
|
+
map.set(normalizedName, container);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const nextContainers = container.getBalancesContainers();
|
|
99
|
+
if (nextContainers && nextContainers.length > 0) {
|
|
100
|
+
this.fillBalancesContainersMap(map, nextContainers);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return map;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=BalancesReport.js.map
|
package/lib/model/Book.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import * as AccountService from '../service/account-service.js';
|
|
11
11
|
import * as BookService from '../service/book-service.js';
|
|
12
|
+
import * as BalancesService from '../service/balances-service.js';
|
|
12
13
|
import * as FileService from '../service/file-service.js';
|
|
13
14
|
import * as GroupService from '../service/group-service.js';
|
|
14
15
|
import * as IntegrationService from '../service/integration-service.js';
|
|
@@ -24,6 +25,7 @@ import { Group } from './Group.js';
|
|
|
24
25
|
import { Integration } from './Integration.js';
|
|
25
26
|
import { Transaction } from './Transaction.js';
|
|
26
27
|
import { TransactionList } from './TransactionList.js';
|
|
28
|
+
import { BalancesReport } from './BalancesReport.js';
|
|
27
29
|
/**
|
|
28
30
|
*
|
|
29
31
|
* A Book represents [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
|
|
@@ -707,5 +709,29 @@ export class Book {
|
|
|
707
709
|
return this;
|
|
708
710
|
});
|
|
709
711
|
}
|
|
712
|
+
/**
|
|
713
|
+
*
|
|
714
|
+
* Create a [[BalancesReport]] based on query
|
|
715
|
+
*
|
|
716
|
+
* @param query The balances report query
|
|
717
|
+
*
|
|
718
|
+
* @return The balances report
|
|
719
|
+
*
|
|
720
|
+
* Example:
|
|
721
|
+
*
|
|
722
|
+
* ```js
|
|
723
|
+
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgPXjx7oKDA");
|
|
724
|
+
*
|
|
725
|
+
* var balancesReport = book.getBalancesReport("group:'Equity' after:7/2018 before:8/2018");
|
|
726
|
+
*
|
|
727
|
+
* var accountBalance = balancesReport.getBalancesContainer("Bank Account").getCumulativeBalance();
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
getBalancesReport(query) {
|
|
731
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
732
|
+
const balances = yield BalancesService.getBalances(this.getId(), query);
|
|
733
|
+
return new BalancesReport(this, balances);
|
|
734
|
+
});
|
|
735
|
+
}
|
|
710
736
|
}
|
|
711
737
|
//# sourceMappingURL=Book.js.map
|
package/lib/model/Group.js
CHANGED
|
@@ -162,6 +162,18 @@ export class Group {
|
|
|
162
162
|
this.payload.hidden = hidden;
|
|
163
163
|
return this;
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Tell if this is a credit (Incoming and Liabities) group
|
|
167
|
+
*/
|
|
168
|
+
isCredit() {
|
|
169
|
+
return this.payload.credit;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Tell if this is a mixed (Assets/Liabilities or Incoming/Outgoing) group
|
|
173
|
+
*/
|
|
174
|
+
isMixed() {
|
|
175
|
+
return this.payload.mixed;
|
|
176
|
+
}
|
|
165
177
|
/**
|
|
166
178
|
* Tell if the Group is permanent
|
|
167
179
|
*/
|