bkper-js 2.2.2 → 2.3.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 CHANGED
@@ -628,8 +628,8 @@ export declare class App {
628
628
  *
629
629
  * @public
630
630
  */
631
- declare class Balance {
632
- json: bkper.Balance;
631
+ export declare class Balance {
632
+ payload: bkper.Balance;
633
633
  private container;
634
634
  constructor(container: BalancesContainer, balancePlain: bkper.Balance);
635
635
  /**
@@ -651,7 +651,7 @@ declare class Balance {
651
651
  /**
652
652
  * Date object constructed based on [[Book]] time zone offset. Usefull for
653
653
  *
654
- * If Month or Day is zero, the date will be constructed with first Month (January) or Day (1).
654
+ * If Month or Day is zero, the date will be constructed with first Month (January) or Day (1) of the next period.
655
655
  */
656
656
  getDate(): Date;
657
657
  /**
@@ -712,6 +712,7 @@ declare class Balance {
712
712
  * @public
713
713
  */
714
714
  export declare interface BalancesContainer {
715
+ payload: bkper.AccountBalances | bkper.GroupBalances;
715
716
  /**
716
717
  * Gets the parent [[BalancesReport]] of the container.
717
718
  *
@@ -924,7 +925,7 @@ export declare interface BalancesContainer {
924
925
  *
925
926
  * @public
926
927
  */
927
- declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
928
+ export declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
928
929
  private balanceType;
929
930
  private balancesContainers;
930
931
  private periodicity;
@@ -947,7 +948,7 @@ declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
947
948
  private getRepresentativeBalance;
948
949
  private getBalanceText;
949
950
  /**
950
- * Defines whether the dates should be formatted based on date pattern and periodicity of the [[Book]].
951
+ * Defines whether the dates should be ISO formatted YYYY-MM-DD. E.g. 2025-01-01
951
952
  *
952
953
  * @returns This builder with respective formatting option, for chaining.
953
954
  */
@@ -985,17 +986,16 @@ declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
985
986
  * For **PERIOD** or **CUMULATIVE** [[BalanceType]], the table will be a time table, and the format looks like:
986
987
  *
987
988
  * ```
988
- * _____________________________________________
989
- * | | Expenses | Income | ... |
990
- * | 15/01/2014 | -2345.23 | 3452.93 | ... |
991
- * | 15/02/2014 | -2345.93 | 3456.46 | ... |
992
- * | 15/03/2014 | -2456.45 | 3567.87 | ... |
993
- * | ... | ... | ... | ... |
994
- * |____________|___________|_________|__________|
989
+ * _______________________________________________________________
990
+ * | | 15/01/2014 | 15/02/2014 | 15/03/2014 | ... |
991
+ * | Expenses | -2345.23 | -2345.93 | -2456.45 | ... |
992
+ * | Income | 3452.93 | 3456.46 | 3567.87 | ... |
993
+ * | ... | ... | ... | ... | ... |
994
+ * |____________|____________|____________|____________|___________|
995
995
  *
996
996
  * ```
997
997
  *
998
- * First column will be the Date column, and one column for each [[Account]] or [[Group]].
998
+ * First column will be the [[Account]] or [[Group]] name, and one column for each Date.
999
999
  *
1000
1000
  * @returns This builder with respective balance type, for chaining.
1001
1001
  */
@@ -1019,15 +1019,16 @@ declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
1019
1019
  *
1020
1020
  * ```
1021
1021
  * _______________________________________________________________
1022
- * | | 15/01/2014 | 15/02/2014 | 15/03/2014 | ... |
1023
- * | Expenses | -2345.23 | -2345.93 | -2456.45 | ... |
1024
- * | Income | 3452.93 | 3456.46 | 3567.87 | ... |
1022
+ * | | Expenses | Income | ... | ... |
1023
+ * | 15/01/2014 | -2345.23 | 3452.93 | ... | ... |
1024
+ * | 15/02/2014 | -2345.93 | 3456.46 | ... | ... |
1025
+ * | 15/03/2014 | -2456.45 | 3567.87 | ... | ... |
1025
1026
  * | ... | ... | ... | ... | ... |
1026
1027
  * |____________|____________|____________|____________|___________|
1027
1028
  *
1028
1029
  * ```
1029
1030
  *
1030
- * First column will be each [[Account]] or [[Group]], and one column for each Date.
1031
+ * First column will be each Date, and one column for each [[Account]] or [[Group]].
1031
1032
  *
1032
1033
  * @returns This builder with respective transposed option, for chaining.
1033
1034
  */
@@ -1102,6 +1103,10 @@ export declare class BalancesReport {
1102
1103
  * @returns The [[Book]] that generated the report
1103
1104
  */
1104
1105
  getBook(): Book;
1106
+ /**
1107
+ * Creates a BalancesDataTableBuilder to generate a two-dimensional array with all [[BalancesContainers]].
1108
+ */
1109
+ createDataTable(): BalancesDataTableBuilder;
1105
1110
  /**
1106
1111
  * Gets the [[Periodicity]] of the query used to generate the report.
1107
1112
  *
@@ -1132,7 +1137,7 @@ export declare class BalancesReport {
1132
1137
  *
1133
1138
  * @public
1134
1139
  */
1135
- declare enum BalanceType {
1140
+ export declare enum BalanceType {
1136
1141
  /**
1137
1142
  * Total balance
1138
1143
  */
package/lib/index.js CHANGED
@@ -9,6 +9,8 @@ export { Account } from './model/Account.js';
9
9
  export { Agent } from './model/Agent.js';
10
10
  export { Amount } from "./model/Amount.js";
11
11
  export { App } from './model/App.js';
12
+ export { Balance } from './model/Balance.js';
13
+ export { BalancesDataTableBuilder } from './model/BalancesDataTableBuilder.js';
12
14
  export { BalancesReport } from './model/BalancesReport.js';
13
15
  export { Bkper } from './model/Bkper.js';
14
16
  export { Book } from './model/Book.js';
@@ -27,5 +29,5 @@ export { Event } from './model/Event.js';
27
29
  export { BotResponse } from './model/BotResponse.js';
28
30
  export { EventList } from './model/EventList.js';
29
31
  export { User } from './model/User.js';
30
- export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, Period, Month, EventType, BotResponseType } from './model/Enums.js';
32
+ export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, BalanceType, Period, Month, EventType, BotResponseType } from './model/Enums.js';
31
33
  //# sourceMappingURL=index.js.map
@@ -8,7 +8,7 @@ import { Amount } from "./Amount.js";
8
8
  export class Balance {
9
9
  constructor(container, balancePlain) {
10
10
  this.container = container;
11
- this.json = balancePlain;
11
+ this.payload = balancePlain;
12
12
  }
13
13
  /**
14
14
  * The day of the balance. Days starts on 1 to 31.
@@ -16,7 +16,7 @@ export class Balance {
16
16
  * Day can be 0 (zero) in case of Monthly or Early [[Periodicity]] of the [[BalancesReport]]
17
17
  */
18
18
  getDay() {
19
- return this.json.day;
19
+ return this.payload.day;
20
20
  }
21
21
  /**
22
22
  * The month of the balance. Months starts on 1 (January) to 12 (December)
@@ -24,18 +24,18 @@ export class Balance {
24
24
  * Month can be 0 (zero) in case of Early [[Periodicity]] of the [[BalancesReport]]
25
25
  */
26
26
  getMonth() {
27
- return this.json.month;
27
+ return this.payload.month;
28
28
  }
29
29
  /**
30
30
  * The year of the balance
31
31
  */
32
32
  getYear() {
33
- return this.json.year;
33
+ return this.payload.year;
34
34
  }
35
35
  /**
36
36
  * Date object constructed based on [[Book]] time zone offset. Usefull for
37
37
  *
38
- * If Month or Day is zero, the date will be constructed with first Month (January) or Day (1).
38
+ * If Month or Day is zero, the date will be constructed with first Month (January) or Day (1) of the next period.
39
39
  */
40
40
  getDate() {
41
41
  var year = this.getYear();
@@ -66,7 +66,7 @@ export class Balance {
66
66
  * **20180000** - 2018 - YEARLY Periodicity
67
67
  */
68
68
  getFuzzyDate() {
69
- return this.json.fuzzyDate;
69
+ return this.payload.fuzzyDate;
70
70
  }
71
71
  /**
72
72
  * The cumulative balance to the date, based on the credit nature of the container
@@ -78,19 +78,19 @@ export class Balance {
78
78
  * The raw cumulative balance to the date.
79
79
  */
80
80
  getCumulativeBalanceRaw() {
81
- return new Amount(this.json.cumulativeBalance);
81
+ return new Amount(this.payload.cumulativeBalance);
82
82
  }
83
83
  /**
84
84
  * The cumulative credit to the date.
85
85
  */
86
86
  getCumulativeCredit() {
87
- return new Amount(this.json.cumulativeCredit);
87
+ return new Amount(this.payload.cumulativeCredit);
88
88
  }
89
89
  /**
90
90
  * The cumulative debit to the date.
91
91
  */
92
92
  getCumulativeDebit() {
93
- return new Amount(this.json.cumulativeDebit);
93
+ return new Amount(this.payload.cumulativeDebit);
94
94
  }
95
95
  /**
96
96
  * The balance on the date period, based on credit nature of the container.
@@ -102,19 +102,19 @@ export class Balance {
102
102
  * The raw balance on the date period.
103
103
  */
104
104
  getPeriodBalanceRaw() {
105
- return new Amount(this.json.periodBalance);
105
+ return new Amount(this.payload.periodBalance);
106
106
  }
107
107
  /**
108
108
  * The credit on the date period.
109
109
  */
110
110
  getPeriodCredit() {
111
- return new Amount(this.json.periodCredit);
111
+ return new Amount(this.payload.periodCredit);
112
112
  }
113
113
  /**
114
114
  * The debit on the date period.
115
115
  */
116
116
  getPeriodDebit() {
117
- return new Amount(this.json.periodDebit);
117
+ return new Amount(this.payload.periodDebit);
118
118
  }
119
119
  }
120
120
  //# sourceMappingURL=Balance.js.map
@@ -42,7 +42,7 @@ export class BalancesDataTableBuilder {
42
42
  return this.book.formatValue(this.getRepresentativeBalance(balance, permanent));
43
43
  }
44
44
  /**
45
- * Defines whether the dates should be formatted based on date pattern and periodicity of the [[Book]].
45
+ * Defines whether the dates should be ISO formatted YYYY-MM-DD. E.g. 2025-01-01
46
46
  *
47
47
  * @returns This builder with respective formatting option, for chaining.
48
48
  */
@@ -101,17 +101,16 @@ export class BalancesDataTableBuilder {
101
101
  * For **PERIOD** or **CUMULATIVE** [[BalanceType]], the table will be a time table, and the format looks like:
102
102
  *
103
103
  * ```
104
- * _____________________________________________
105
- * | | Expenses | Income | ... |
106
- * | 15/01/2014 | -2345.23 | 3452.93 | ... |
107
- * | 15/02/2014 | -2345.93 | 3456.46 | ... |
108
- * | 15/03/2014 | -2456.45 | 3567.87 | ... |
109
- * | ... | ... | ... | ... |
110
- * |____________|___________|_________|__________|
104
+ * _______________________________________________________________
105
+ * | | 15/01/2014 | 15/02/2014 | 15/03/2014 | ... |
106
+ * | Expenses | -2345.23 | -2345.93 | -2456.45 | ... |
107
+ * | Income | 3452.93 | 3456.46 | 3567.87 | ... |
108
+ * | ... | ... | ... | ... | ... |
109
+ * |____________|____________|____________|____________|___________|
111
110
  *
112
111
  * ```
113
112
  *
114
- * First column will be the Date column, and one column for each [[Account]] or [[Group]].
113
+ * First column will be the [[Account]] or [[Group]] name, and one column for each Date.
115
114
  *
116
115
  * @returns This builder with respective balance type, for chaining.
117
116
  */
@@ -138,15 +137,16 @@ export class BalancesDataTableBuilder {
138
137
  *
139
138
  * ```
140
139
  * _______________________________________________________________
141
- * | | 15/01/2014 | 15/02/2014 | 15/03/2014 | ... |
142
- * | Expenses | -2345.23 | -2345.93 | -2456.45 | ... |
143
- * | Income | 3452.93 | 3456.46 | 3567.87 | ... |
140
+ * | | Expenses | Income | ... | ... |
141
+ * | 15/01/2014 | -2345.23 | 3452.93 | ... | ... |
142
+ * | 15/02/2014 | -2345.93 | 3456.46 | ... | ... |
143
+ * | 15/03/2014 | -2456.45 | 3567.87 | ... | ... |
144
144
  * | ... | ... | ... | ... | ... |
145
145
  * |____________|____________|____________|____________|___________|
146
146
  *
147
147
  * ```
148
148
  *
149
- * First column will be each [[Account]] or [[Group]], and one column for each Date.
149
+ * First column will be each Date, and one column for each [[Account]] or [[Group]].
150
150
  *
151
151
  * @returns This builder with respective transposed option, for chaining.
152
152
  */
@@ -235,7 +235,7 @@ export class BalancesDataTableBuilder {
235
235
  this.flattenAllAccounts(container, containersFlat, propertyKeys);
236
236
  containersFlat.sort(this.sortContainersFunction);
237
237
  }
238
- else if (this.expandAllGroups) {
238
+ else if (container.isFromGroup() && this.expandAllGroups) {
239
239
  this.flattenAllGroups(container, containersFlat, propertyKeys);
240
240
  }
241
241
  else {
@@ -302,8 +302,7 @@ export class BalancesDataTableBuilder {
302
302
  let depth = container.getDepth();
303
303
  if (depth <= this.maxDepth) {
304
304
  if (!this.skipRoot && !this.shouldTranspose) {
305
- //@ts-ignore
306
- container.json.name = Utils_.repeatString(" ", depth * 4) + container.json.name;
305
+ container.payload.name = Utils.repeatString(" ", depth * 4) + container.payload.name;
307
306
  }
308
307
  if (!this.skipRoot || depth != 0) {
309
308
  containersFlat.push(container);
@@ -324,8 +323,7 @@ export class BalancesDataTableBuilder {
324
323
  if (container.isFromGroup()) {
325
324
  if (!this.shouldTranspose) {
326
325
  let depth = container.getDepth();
327
- //@ts-ignore
328
- container.json.name = Utils_.repeatString(" ", depth * 4) + container.json.name;
326
+ container.payload.name = Utils.repeatString(" ", depth * 4) + container.payload.name;
329
327
  }
330
328
  containersFlat.push(container);
331
329
  if (this.shouldAddProperties) {
@@ -553,12 +551,12 @@ export class BalancesDataTableBuilder {
553
551
  table.push(row);
554
552
  }
555
553
  if (this.shouldFormatDate && table.length > 0) {
556
- var pattern = Utils.getDateFormatterPattern(this.book.getDatePattern(), this.periodicity);
554
+ // var pattern = Utils.getDateFormatterPattern(this.book.getDatePattern(), this.periodicity);
557
555
  for (var j = 1; j < table.length; j++) {
558
556
  var row = table[j];
559
557
  if (row.length > 0) {
560
558
  //first column
561
- row[0] = Utils.formatDate(row[0], pattern, this.book.getTimeZone());
559
+ row[0] = Utils.formatDateISO(row[0], this.book.getTimeZone());
562
560
  }
563
561
  }
564
562
  }
@@ -578,7 +576,7 @@ export class BalancesDataTableBuilder {
578
576
  if (this.shouldHideDates) {
579
577
  table = table.map(row => row.slice(1));
580
578
  }
581
- if (this.shouldTranspose && table.length > 0) {
579
+ if (!this.shouldTranspose && table.length > 0) {
582
580
  table = table[0].map((col, i) => table.map(row => row[i]));
583
581
  }
584
582
  return table;
@@ -1,6 +1,7 @@
1
1
  import { normalizeName } from '../utils.js';
2
2
  import { AccountBalancesContainer } from "./BalancesContainerAccount.js";
3
3
  import { GroupBalancesContainer } from "./BalancesContainerGroup.js";
4
+ import { BalancesDataTableBuilder } from './BalancesDataTableBuilder.js';
4
5
  /**
5
6
  * Class representing a Balance Report, generated when calling [Book.getBalanceReport](#book_getbalancesreport)
6
7
  *
@@ -19,6 +20,12 @@ export class BalancesReport {
19
20
  getBook() {
20
21
  return this.book;
21
22
  }
23
+ /**
24
+ * Creates a BalancesDataTableBuilder to generate a two-dimensional array with all [[BalancesContainers]].
25
+ */
26
+ createDataTable() {
27
+ return new BalancesDataTableBuilder(this.book, this.getBalancesContainers(), this.getPeriodicity());
28
+ }
22
29
  /**
23
30
  * Gets the [[Periodicity]] of the query used to generate the report.
24
31
  *
@@ -35,11 +42,11 @@ export class BalancesReport {
35
42
  getBalancesContainers() {
36
43
  let containers = [];
37
44
  const accountContainers = this.getRootAccountBalancesContainers();
38
- if (accountContainers && accountContainers.length > 0) {
45
+ if (accountContainers != null && accountContainers.length > 0) {
39
46
  containers = containers.concat(accountContainers);
40
47
  }
41
48
  const groupContainers = this.getGroupBalancesContainers();
42
- if (groupContainers && groupContainers.length > 0) {
49
+ if (groupContainers != null && groupContainers.length > 0) {
43
50
  containers = containers.concat(groupContainers);
44
51
  }
45
52
  return containers;
package/lib/utils.js CHANGED
@@ -10,6 +10,16 @@ export function sleep(ms) {
10
10
  export function base64Decode(data) {
11
11
  return Buffer.from(data, 'base64');
12
12
  }
13
+ export function repeatString(text, times) {
14
+ if (times <= 0) {
15
+ return "";
16
+ }
17
+ if (times === 1) {
18
+ return text;
19
+ }
20
+ return text + repeatString(text, times - 1);
21
+ ;
22
+ }
13
23
  //SAME AS bkper-app
14
24
  var diacriticsMap_ = null;
15
25
  export function round(number, fractionDigits) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",