bkper-js 1.47.2 → 2.0.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.
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as AccountService from '../service/account-service.js';
11
11
  import * as GroupService from '../service/group-service.js';
12
12
  import { Group } from './Group.js';
13
- import { normalizeText, round } from '../utils.js';
14
- import { Amount } from './Amount.js';
13
+ import { normalizeText } from '../utils.js';
15
14
  /**
16
- *
17
15
  * This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].
18
16
  *
19
- * It mantains a balance of all amount [credited and debited](http://en.wikipedia.org/wiki/Debits_and_credits) in it by [[Transactions]].
17
+ * It maintains a balance of all amount [credited and debited](http://en.wikipedia.org/wiki/Debits_and_credits) in it by [[Transactions]].
20
18
  *
21
19
  * An Account can be grouped by [[Groups]].
22
20
  *
@@ -30,35 +28,44 @@ export class Account {
30
28
  };
31
29
  }
32
30
  /**
31
+ * Gets an immutable copy of the JSON payload.
32
+ *
33
33
  * @returns An immutable copy of the json payload
34
34
  */
35
35
  json() {
36
36
  return Object.assign({}, this.payload);
37
37
  }
38
38
  /**
39
- * Gets the account internal id.
39
+ * Gets the Account internal id.
40
+ *
41
+ * @returns The Account internal id
40
42
  */
41
43
  getId() {
42
44
  return this.payload.id;
43
45
  }
44
46
  /**
45
- * Gets the account name.
47
+ * Gets the Account name.
48
+ *
49
+ * @returns The Account name
46
50
  */
47
51
  getName() {
48
52
  return this.payload.name;
49
53
  }
50
54
  /**
51
- *
52
55
  * Sets the name of the Account.
53
56
  *
54
- * @returns This Account, for chainning.
57
+ * @param name - The name to set
58
+ *
59
+ * @returns This Account, for chaining
55
60
  */
56
61
  setName(name) {
57
62
  this.payload.name = name;
58
63
  return this;
59
64
  }
60
65
  /**
61
- * @returns The name of this account without spaces or special characters.
66
+ * Gets the normalized name of this Account without spaces or special characters.
67
+ *
68
+ * @returns The name of this Account without spaces or special characters
62
69
  */
63
70
  getNormalizedName() {
64
71
  if (this.payload.normalizedName) {
@@ -69,16 +76,19 @@ export class Account {
69
76
  }
70
77
  }
71
78
  /**
72
- * @returns The type for of this account.
79
+ * Gets the type of this Account.
80
+ *
81
+ * @returns The [[AccountType]] of this Account
73
82
  */
74
83
  getType() {
75
84
  return this.payload.type;
76
85
  }
77
86
  /**
78
- *
79
87
  * Sets the type of the Account.
80
88
  *
81
- * @returns This Account, for chainning
89
+ * @param type - The [[AccountType]] to set
90
+ *
91
+ * @returns This Account, for chaining
82
92
  */
83
93
  setType(type) {
84
94
  this.payload.type = type;
@@ -86,25 +96,29 @@ export class Account {
86
96
  }
87
97
  /**
88
98
  * Gets the custom properties stored in this Account.
99
+ *
100
+ * @returns The custom properties object
89
101
  */
90
102
  getProperties() {
91
103
  return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
92
104
  }
93
105
  /**
94
- * Sets the custom properties of the Account
106
+ * Sets the custom properties of the Account.
95
107
  *
96
108
  * @param properties - Object with key/value pair properties
97
109
  *
98
- * @returns This Account, for chainning.
110
+ * @returns This Account, for chaining
99
111
  */
100
112
  setProperties(properties) {
101
113
  this.payload.properties = Object.assign({}, properties);
102
114
  return this;
103
115
  }
104
116
  /**
105
- * Gets the property value for given keys. First property found will be retrieved
117
+ * Gets the property value for given keys. First property found will be retrieved.
106
118
  *
107
119
  * @param keys - The property key
120
+ *
121
+ * @returns The property value or undefined if not found
108
122
  */
109
123
  getProperty(...keys) {
110
124
  for (let index = 0; index < keys.length; index++) {
@@ -122,7 +136,7 @@ export class Account {
122
136
  * @param key - The property key
123
137
  * @param value - The property value
124
138
  *
125
- * @returns This Account, for chainning.
139
+ * @returns This Account, for chaining
126
140
  */
127
141
  setProperty(key, value) {
128
142
  if (key == null || key.trim() == '') {
@@ -138,72 +152,53 @@ export class Account {
138
152
  return this;
139
153
  }
140
154
  /**
141
- * Delete a custom property
155
+ * Deletes a custom property.
142
156
  *
143
157
  * @param key - The property key
144
158
  *
145
- * @returns This Account, for chainning.
159
+ * @returns This Account, for chaining
146
160
  */
147
161
  deleteProperty(key) {
148
162
  this.setProperty(key, null);
149
163
  return this;
150
164
  }
151
165
  /**
152
- * Gets the balance based on credit nature of this Account.
153
- * @deprecated Use `Book.getBalancesReport` instead.
154
- * @returns The balance of this account.
155
- */
156
- getBalance() {
157
- var balance = new Amount('0');
158
- if (this.payload.balance != null) {
159
- balance = round(this.payload.balance, this.book.getFractionDigits());
160
- }
161
- return balance;
162
- }
163
- /**
164
- * Gets the raw balance, no matter credit nature of this Account.
165
- * @deprecated Use `Book.getBalancesReport` instead.
166
- * @returns The balance of this account.
167
- */
168
- getBalanceRaw() {
169
- var balance = new Amount('0');
170
- if (this.payload.balance != null) {
171
- balance = round(this.payload.balance, this.book.getFractionDigits());
172
- }
173
- return balance;
174
- }
175
- /**
176
- * Tell if this account is archived.
166
+ * Tells if this Account is archived.
167
+ *
168
+ * @returns True if the Account is archived
177
169
  */
178
170
  isArchived() {
179
171
  return this.payload.archived;
180
172
  }
181
173
  /**
182
- * Set account archived/unarchived.
174
+ * Sets Account archived/unarchived.
175
+ *
176
+ * @param archived - True to archive, false to unarchive
183
177
  *
184
- * @returns This Account, for chainning.
178
+ * @returns This Account, for chaining
185
179
  */
186
180
  setArchived(archived) {
187
181
  this.payload.archived = archived;
188
182
  return this;
189
183
  }
190
184
  /**
191
- * Tell if the Account has any transaction already posted.
185
+ * Tells if the Account has any transaction already posted.
192
186
  *
193
187
  * Accounts with transaction posted, even with zero balance, can only be archived.
188
+ *
189
+ * @returns True if the Account has transactions posted
194
190
  */
195
191
  hasTransactionPosted() {
196
192
  return this.payload.hasTransactionPosted;
197
193
  }
198
194
  /**
199
- *
200
- * Tell if the account is permanent.
195
+ * Tells if the Account is permanent.
201
196
  *
202
197
  * Permanent Accounts are the ones which final balance is relevant and keep its balances over time.
203
198
  *
204
- * They are also called [Real Accounts](http://en.wikipedia.org/wiki/Account_(accountancy)#Based_on_periodicity_of_flow)
199
+ * They are also called [Real Accounts](http://en.wikipedia.org/wiki/Account_(Accountancy)#Based_on_periodicity_of_flow)
205
200
  *
206
- * Usually represents assets or tangibles, capable of being perceived by the senses or the mind, like bank accounts, money, debts and so on.
201
+ * Usually represents assets or tangibles, capable of being perceived by the senses or the mind, like bank Accounts, money, debts and so on.
207
202
  *
208
203
  * @returns True if its a permanent Account
209
204
  */
@@ -211,30 +206,34 @@ export class Account {
211
206
  return this.payload.permanent;
212
207
  }
213
208
  /**
214
- * Tell if the account has a Credit nature or Debit otherwise
209
+ * Tells if the Account has a Credit nature or Debit otherwise.
215
210
  *
216
- * Credit accounts are just for representation purposes. It increase or decrease the absolute balance. It doesn't affect the overall balance or the behavior of the system.
211
+ * Credit Accounts are just for representation purposes. It increase or decrease the absolute balance. It doesn't affect the overall balance or the behavior of the system.
217
212
  *
218
- * The absolute balance of credit accounts increase when it participate as a credit/origin in a transaction. Its usually for Accounts that increase the balance of the assets, like revenue accounts.
213
+ * The absolute balance of credit Accounts increase when it participate as a credit/origin in a transaction. Its usually for Accounts that increase the balance of the assets, like revenue Accounts.
219
214
  *
220
215
  * ```
221
216
  * Crediting a credit
222
- * Thus ---------------------> account increases its absolute balance
217
+ * Thus ---------------------> Account increases its absolute balance
223
218
  * Debiting a debit
224
219
  *
225
220
  *
226
221
  * Debiting a credit
227
- * Thus ---------------------> account decreases its absolute balance
222
+ * Thus ---------------------> Account decreases its absolute balance
228
223
  * Crediting a debit
229
224
  * ```
230
225
  *
231
- * As a rule of thumb, and for simple understanding, almost all accounts are Debit nature (NOT credit), except the ones that "offers" amount for the books, like revenue accounts.
226
+ * As a rule of thumb, and for simple understanding, almost all Accounts are Debit nature (NOT credit), except the ones that "offers" amount for the books, like revenue Accounts.
227
+ *
228
+ * @returns True if the Account has credit nature
232
229
  */
233
230
  isCredit() {
234
231
  return this.payload.credit;
235
232
  }
236
233
  /**
237
- * Get the [[Groups]] of this account.
234
+ * Gets the [[Groups]] of this Account.
235
+ *
236
+ * @returns Promise with the [[Groups]] of this Account
238
237
  */
239
238
  getGroups() {
240
239
  return __awaiter(this, void 0, void 0, function* () {
@@ -250,7 +249,9 @@ export class Account {
250
249
  /**
251
250
  * Sets the groups of the Account.
252
251
  *
253
- * @returns This Account, for chainning.
252
+ * @param groups - The groups to set
253
+ *
254
+ * @returns This Account, for chaining
254
255
  */
255
256
  setGroups(groups) {
256
257
  this.payload.groups = undefined;
@@ -260,9 +261,11 @@ export class Account {
260
261
  return this;
261
262
  }
262
263
  /**
263
- * Add a group to the Account.
264
+ * Adds a group to the Account.
265
+ *
266
+ * @param group - The group to add
264
267
  *
265
- * @returns This Account, for chainning.
268
+ * @returns This Account, for chaining
266
269
  */
267
270
  addGroup(group) {
268
271
  if (!this.payload.groups) {
@@ -277,7 +280,11 @@ export class Account {
277
280
  return this;
278
281
  }
279
282
  /**
280
- * Remove a group from the Account.
283
+ * Removes a group from the Account.
284
+ *
285
+ * @param group - The group name, id or object to remove
286
+ *
287
+ * @returns Promise with this Account, for chaining
281
288
  */
282
289
  removeGroup(group) {
283
290
  return __awaiter(this, void 0, void 0, function* () {
@@ -302,9 +309,11 @@ export class Account {
302
309
  });
303
310
  }
304
311
  /**
305
- * Tell if this account is in the [[Group]]
312
+ * Tells if this Account is in the [[Group]].
306
313
  *
307
- * @param group - The Group name, id or object
314
+ * @param group - The Group name, id or object
315
+ *
316
+ * @returns Promise with true if the Account is in the group
308
317
  */
309
318
  isInGroup(group) {
310
319
  return __awaiter(this, void 0, void 0, function* () {
@@ -336,7 +345,9 @@ export class Account {
336
345
  return false;
337
346
  }
338
347
  /**
339
- * Perform create new account.
348
+ * Performs create new Account.
349
+ *
350
+ * @returns Promise with this Account after creation
340
351
  */
341
352
  create() {
342
353
  return __awaiter(this, void 0, void 0, function* () {
@@ -346,7 +357,9 @@ export class Account {
346
357
  });
347
358
  }
348
359
  /**
349
- * Perform update account, applying pending changes.
360
+ * Performs update Account, applying pending changes.
361
+ *
362
+ * @returns Promise with this Account after update
350
363
  */
351
364
  update() {
352
365
  return __awaiter(this, void 0, void 0, function* () {
@@ -356,7 +369,9 @@ export class Account {
356
369
  });
357
370
  }
358
371
  /**
359
- * Perform delete account.
372
+ * Performs delete Account.
373
+ *
374
+ * @returns Promise with this Account after deletion
360
375
  */
361
376
  remove() {
362
377
  return __awaiter(this, void 0, void 0, function* () {
@@ -10,12 +10,15 @@ export class Agent {
10
10
  this.payload = payload || {};
11
11
  }
12
12
  /**
13
+ * Gets the wrapped plain JSON object.
14
+ *
13
15
  * @returns The wrapped plain json object
14
16
  */
15
17
  json() {
16
18
  return Object.assign({}, this.payload);
17
19
  }
18
20
  /**
21
+ * Gets the Agent universal identifier.
19
22
  *
20
23
  * @returns The Agent universal identifier
21
24
  */
@@ -23,6 +26,7 @@ export class Agent {
23
26
  return this.payload.id;
24
27
  }
25
28
  /**
29
+ * Gets the Agent name.
26
30
  *
27
31
  * @returns The Agent name
28
32
  */
@@ -30,6 +34,7 @@ export class Agent {
30
34
  return this.payload.name;
31
35
  }
32
36
  /**
37
+ * Gets the Agent logo URL.
33
38
  *
34
39
  * @returns The Agent logo url
35
40
  */
@@ -37,6 +42,7 @@ export class Agent {
37
42
  return this.payload.logo;
38
43
  }
39
44
  /**
45
+ * Gets the Agent logo URL in dark mode.
40
46
  *
41
47
  * @returns The Agent logo url in dark mode
42
48
  */
@@ -9,6 +9,8 @@ import Big from "big.js";
9
9
  export class Amount {
10
10
  /**
11
11
  * The Amount constructor.
12
+ *
13
+ * @param n - The number, string, or Amount to initialize with
12
14
  */
13
15
  constructor(n) {
14
16
  this.checkNumberNotNull(n);
@@ -27,13 +29,19 @@ export class Amount {
27
29
  }
28
30
  /**
29
31
  * Returns an absolute Amount.
32
+ *
33
+ * @returns The absolute value as a new Amount
30
34
  */
31
35
  abs() {
32
36
  let big = this.big.abs();
33
37
  return this.wrap(big);
34
38
  }
35
39
  /**
36
- * Compare
40
+ * Compares this Amount with another value.
41
+ *
42
+ * @param n - The value to compare with
43
+ *
44
+ * @returns -1 if less than, 0 if equal, 1 if greater than
37
45
  */
38
46
  cmp(n) {
39
47
  this.checkNumberNotNull(n);
@@ -51,7 +59,11 @@ export class Amount {
51
59
  }
52
60
  }
53
61
  /**
54
- * Divide by
62
+ * Divides this Amount by another value.
63
+ *
64
+ * @param n - The divisor value
65
+ *
66
+ * @returns The division result as a new Amount
55
67
  */
56
68
  div(n) {
57
69
  this.checkNumberNotNull(n);
@@ -71,7 +83,11 @@ export class Amount {
71
83
  return this.wrap(big);
72
84
  }
73
85
  /**
74
- * Equals to
86
+ * Checks if this Amount equals another value.
87
+ *
88
+ * @param n - The value to compare with
89
+ *
90
+ * @returns True if equal, false otherwise
75
91
  */
76
92
  eq(n) {
77
93
  this.checkNumberNotNull(n);
@@ -89,7 +105,11 @@ export class Amount {
89
105
  }
90
106
  }
91
107
  /**
92
- * Greater than
108
+ * Checks if this Amount is greater than another value.
109
+ *
110
+ * @param n - The value to compare with
111
+ *
112
+ * @returns True if greater than, false otherwise
93
113
  */
94
114
  gt(n) {
95
115
  this.checkNumberNotNull(n);
@@ -107,7 +127,11 @@ export class Amount {
107
127
  }
108
128
  }
109
129
  /**
110
- * Greater than or equal
130
+ * Checks if this Amount is greater than or equal to another value.
131
+ *
132
+ * @param n - The value to compare with
133
+ *
134
+ * @returns True if greater than or equal, false otherwise
111
135
  */
112
136
  gte(n) {
113
137
  this.checkNumberNotNull(n);
@@ -125,7 +149,11 @@ export class Amount {
125
149
  }
126
150
  }
127
151
  /**
128
- * Less than
152
+ * Checks if this Amount is less than another value.
153
+ *
154
+ * @param n - The value to compare with
155
+ *
156
+ * @returns True if less than, false otherwise
129
157
  */
130
158
  lt(n) {
131
159
  this.checkNumberNotNull(n);
@@ -143,7 +171,11 @@ export class Amount {
143
171
  }
144
172
  }
145
173
  /**
146
- * Less than or equal to
174
+ * Checks if this Amount is less than or equal to another value.
175
+ *
176
+ * @param n - The value to compare with
177
+ *
178
+ * @returns True if less than or equal, false otherwise
147
179
  */
148
180
  lte(n) {
149
181
  this.checkNumberNotNull(n);
@@ -161,7 +193,11 @@ export class Amount {
161
193
  }
162
194
  }
163
195
  /**
164
- * Sum
196
+ * Adds another value to this Amount.
197
+ *
198
+ * @param n - The value to add
199
+ *
200
+ * @returns The sum as a new Amount
165
201
  */
166
202
  plus(n) {
167
203
  this.checkNumberNotNull(n);
@@ -181,7 +217,11 @@ export class Amount {
181
217
  return this.wrap(big);
182
218
  }
183
219
  /**
184
- * Minus
220
+ * Subtracts another value from this Amount.
221
+ *
222
+ * @param n - The value to subtract
223
+ *
224
+ * @returns The difference as a new Amount
185
225
  */
186
226
  minus(n) {
187
227
  this.checkNumberNotNull(n);
@@ -201,10 +241,13 @@ export class Amount {
201
241
  return this.wrap(big);
202
242
  }
203
243
  /**
204
- * Modulo - the integer remainder of dividing this Amount by n.
244
+ * Calculates the modulo (remainder) of dividing this Amount by another value.
205
245
  *
206
246
  * Similar to % operator
207
247
  *
248
+ * @param n - The divisor value
249
+ *
250
+ * @returns The remainder as a new Amount
208
251
  */
209
252
  mod(n) {
210
253
  this.checkNumberNotNull(n);
@@ -224,14 +267,22 @@ export class Amount {
224
267
  return this.wrap(big);
225
268
  }
226
269
  /**
227
- * Round to a maximum of dp decimal places.
270
+ * Rounds this Amount to a maximum of dp decimal places.
271
+ *
272
+ * @param dp - The number of decimal places (optional)
273
+ *
274
+ * @returns The rounded value as a new Amount
228
275
  */
229
276
  round(dp) {
230
277
  let big = this.big.round(dp);
231
278
  return this.wrap(big);
232
279
  }
233
280
  /**
234
- * Multiply
281
+ * Multiplies this Amount by another value.
282
+ *
283
+ * @param n - The value to multiply by
284
+ *
285
+ * @returns The product as a new Amount
235
286
  */
236
287
  times(n) {
237
288
  this.checkNumberNotNull(n);
@@ -251,19 +302,27 @@ export class Amount {
251
302
  return this.wrap(big);
252
303
  }
253
304
  /**
254
- * Returns a string representing the value of this Amount in normal notation to a fixed number of decimal places dp.
305
+ * Returns a string representing the value of this Amount in normal notation to a fixed number of decimal places.
306
+ *
307
+ * @param dp - The number of decimal places (optional)
308
+ *
309
+ * @returns The formatted string representation
255
310
  */
256
311
  toFixed(dp) {
257
312
  return this.big.toFixed(dp);
258
313
  }
259
314
  /**
260
315
  * Returns a string representing the value of this Amount.
316
+ *
317
+ * @returns The string representation of this Amount
261
318
  */
262
319
  toString() {
263
320
  return this.big.toString();
264
321
  }
265
322
  /**
266
323
  * Returns a primitive number representing the value of this Amount.
324
+ *
325
+ * @returns The numeric value of this Amount
267
326
  */
268
327
  toNumber() {
269
328
  return this.big.toNumber();