bkper-js 1.47.2 → 1.47.3

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.
@@ -13,10 +13,9 @@ import { Group } from './Group.js';
13
13
  import { normalizeText, round } from '../utils.js';
14
14
  import { Amount } from './Amount.js';
15
15
  /**
16
- *
17
16
  * This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].
18
17
  *
19
- * It mantains a balance of all amount [credited and debited](http://en.wikipedia.org/wiki/Debits_and_credits) in it by [[Transactions]].
18
+ * It maintains a balance of all amount [credited and debited](http://en.wikipedia.org/wiki/Debits_and_credits) in it by [[Transactions]].
20
19
  *
21
20
  * An Account can be grouped by [[Groups]].
22
21
  *
@@ -30,35 +29,44 @@ export class Account {
30
29
  };
31
30
  }
32
31
  /**
32
+ * Gets an immutable copy of the JSON payload.
33
+ *
33
34
  * @returns An immutable copy of the json payload
34
35
  */
35
36
  json() {
36
37
  return Object.assign({}, this.payload);
37
38
  }
38
39
  /**
39
- * Gets the account internal id.
40
+ * Gets the Account internal id.
41
+ *
42
+ * @returns The Account internal id
40
43
  */
41
44
  getId() {
42
45
  return this.payload.id;
43
46
  }
44
47
  /**
45
- * Gets the account name.
48
+ * Gets the Account name.
49
+ *
50
+ * @returns The Account name
46
51
  */
47
52
  getName() {
48
53
  return this.payload.name;
49
54
  }
50
55
  /**
51
- *
52
56
  * Sets the name of the Account.
53
57
  *
54
- * @returns This Account, for chainning.
58
+ * @param name - The name to set
59
+ *
60
+ * @returns This Account, for chaining
55
61
  */
56
62
  setName(name) {
57
63
  this.payload.name = name;
58
64
  return this;
59
65
  }
60
66
  /**
61
- * @returns The name of this account without spaces or special characters.
67
+ * Gets the normalized name of this Account without spaces or special characters.
68
+ *
69
+ * @returns The name of this Account without spaces or special characters
62
70
  */
63
71
  getNormalizedName() {
64
72
  if (this.payload.normalizedName) {
@@ -69,16 +77,19 @@ export class Account {
69
77
  }
70
78
  }
71
79
  /**
72
- * @returns The type for of this account.
80
+ * Gets the type of this Account.
81
+ *
82
+ * @returns The [[AccountType]] of this Account
73
83
  */
74
84
  getType() {
75
85
  return this.payload.type;
76
86
  }
77
87
  /**
78
- *
79
88
  * Sets the type of the Account.
80
89
  *
81
- * @returns This Account, for chainning
90
+ * @param type - The [[AccountType]] to set
91
+ *
92
+ * @returns This Account, for chaining
82
93
  */
83
94
  setType(type) {
84
95
  this.payload.type = type;
@@ -86,25 +97,29 @@ export class Account {
86
97
  }
87
98
  /**
88
99
  * Gets the custom properties stored in this Account.
100
+ *
101
+ * @returns The custom properties object
89
102
  */
90
103
  getProperties() {
91
104
  return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
92
105
  }
93
106
  /**
94
- * Sets the custom properties of the Account
107
+ * Sets the custom properties of the Account.
95
108
  *
96
109
  * @param properties - Object with key/value pair properties
97
110
  *
98
- * @returns This Account, for chainning.
111
+ * @returns This Account, for chaining
99
112
  */
100
113
  setProperties(properties) {
101
114
  this.payload.properties = Object.assign({}, properties);
102
115
  return this;
103
116
  }
104
117
  /**
105
- * Gets the property value for given keys. First property found will be retrieved
118
+ * Gets the property value for given keys. First property found will be retrieved.
106
119
  *
107
120
  * @param keys - The property key
121
+ *
122
+ * @returns The property value or undefined if not found
108
123
  */
109
124
  getProperty(...keys) {
110
125
  for (let index = 0; index < keys.length; index++) {
@@ -122,7 +137,7 @@ export class Account {
122
137
  * @param key - The property key
123
138
  * @param value - The property value
124
139
  *
125
- * @returns This Account, for chainning.
140
+ * @returns This Account, for chaining
126
141
  */
127
142
  setProperty(key, value) {
128
143
  if (key == null || key.trim() == '') {
@@ -138,11 +153,11 @@ export class Account {
138
153
  return this;
139
154
  }
140
155
  /**
141
- * Delete a custom property
156
+ * Deletes a custom property.
142
157
  *
143
158
  * @param key - The property key
144
159
  *
145
- * @returns This Account, for chainning.
160
+ * @returns This Account, for chaining
146
161
  */
147
162
  deleteProperty(key) {
148
163
  this.setProperty(key, null);
@@ -150,8 +165,10 @@ export class Account {
150
165
  }
151
166
  /**
152
167
  * Gets the balance based on credit nature of this Account.
168
+ *
153
169
  * @deprecated Use `Book.getBalancesReport` instead.
154
- * @returns The balance of this account.
170
+ *
171
+ * @returns The balance of this Account.
155
172
  */
156
173
  getBalance() {
157
174
  var balance = new Amount('0');
@@ -162,8 +179,10 @@ export class Account {
162
179
  }
163
180
  /**
164
181
  * Gets the raw balance, no matter credit nature of this Account.
182
+ *
165
183
  * @deprecated Use `Book.getBalancesReport` instead.
166
- * @returns The balance of this account.
184
+ *
185
+ * @returns The balance of this Account.
167
186
  */
168
187
  getBalanceRaw() {
169
188
  var balance = new Amount('0');
@@ -173,37 +192,42 @@ export class Account {
173
192
  return balance;
174
193
  }
175
194
  /**
176
- * Tell if this account is archived.
195
+ * Tells if this Account is archived.
196
+ *
197
+ * @returns True if the Account is archived
177
198
  */
178
199
  isArchived() {
179
200
  return this.payload.archived;
180
201
  }
181
202
  /**
182
- * Set account archived/unarchived.
203
+ * Sets Account archived/unarchived.
183
204
  *
184
- * @returns This Account, for chainning.
205
+ * @param archived - True to archive, false to unarchive
206
+ *
207
+ * @returns This Account, for chaining
185
208
  */
186
209
  setArchived(archived) {
187
210
  this.payload.archived = archived;
188
211
  return this;
189
212
  }
190
213
  /**
191
- * Tell if the Account has any transaction already posted.
214
+ * Tells if the Account has any transaction already posted.
192
215
  *
193
216
  * Accounts with transaction posted, even with zero balance, can only be archived.
217
+ *
218
+ * @returns True if the Account has transactions posted
194
219
  */
195
220
  hasTransactionPosted() {
196
221
  return this.payload.hasTransactionPosted;
197
222
  }
198
223
  /**
199
- *
200
- * Tell if the account is permanent.
224
+ * Tells if the Account is permanent.
201
225
  *
202
226
  * Permanent Accounts are the ones which final balance is relevant and keep its balances over time.
203
227
  *
204
- * They are also called [Real Accounts](http://en.wikipedia.org/wiki/Account_(accountancy)#Based_on_periodicity_of_flow)
228
+ * They are also called [Real Accounts](http://en.wikipedia.org/wiki/Account_(Accountancy)#Based_on_periodicity_of_flow)
205
229
  *
206
- * Usually represents assets or tangibles, capable of being perceived by the senses or the mind, like bank accounts, money, debts and so on.
230
+ * Usually represents assets or tangibles, capable of being perceived by the senses or the mind, like bank Accounts, money, debts and so on.
207
231
  *
208
232
  * @returns True if its a permanent Account
209
233
  */
@@ -211,30 +235,34 @@ export class Account {
211
235
  return this.payload.permanent;
212
236
  }
213
237
  /**
214
- * Tell if the account has a Credit nature or Debit otherwise
238
+ * Tells if the Account has a Credit nature or Debit otherwise.
215
239
  *
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.
240
+ * 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
241
  *
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.
242
+ * 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
243
  *
220
244
  * ```
221
245
  * Crediting a credit
222
- * Thus ---------------------> account increases its absolute balance
246
+ * Thus ---------------------> Account increases its absolute balance
223
247
  * Debiting a debit
224
248
  *
225
249
  *
226
250
  * Debiting a credit
227
- * Thus ---------------------> account decreases its absolute balance
251
+ * Thus ---------------------> Account decreases its absolute balance
228
252
  * Crediting a debit
229
253
  * ```
230
254
  *
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.
255
+ * 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.
256
+ *
257
+ * @returns True if the Account has credit nature
232
258
  */
233
259
  isCredit() {
234
260
  return this.payload.credit;
235
261
  }
236
262
  /**
237
- * Get the [[Groups]] of this account.
263
+ * Gets the [[Groups]] of this Account.
264
+ *
265
+ * @returns Promise with the [[Groups]] of this Account
238
266
  */
239
267
  getGroups() {
240
268
  return __awaiter(this, void 0, void 0, function* () {
@@ -250,7 +278,9 @@ export class Account {
250
278
  /**
251
279
  * Sets the groups of the Account.
252
280
  *
253
- * @returns This Account, for chainning.
281
+ * @param groups - The groups to set
282
+ *
283
+ * @returns This Account, for chaining
254
284
  */
255
285
  setGroups(groups) {
256
286
  this.payload.groups = undefined;
@@ -260,9 +290,11 @@ export class Account {
260
290
  return this;
261
291
  }
262
292
  /**
263
- * Add a group to the Account.
293
+ * Adds a group to the Account.
264
294
  *
265
- * @returns This Account, for chainning.
295
+ * @param group - The group to add
296
+ *
297
+ * @returns This Account, for chaining
266
298
  */
267
299
  addGroup(group) {
268
300
  if (!this.payload.groups) {
@@ -277,7 +309,11 @@ export class Account {
277
309
  return this;
278
310
  }
279
311
  /**
280
- * Remove a group from the Account.
312
+ * Removes a group from the Account.
313
+ *
314
+ * @param group - The group name, id or object to remove
315
+ *
316
+ * @returns Promise with this Account, for chaining
281
317
  */
282
318
  removeGroup(group) {
283
319
  return __awaiter(this, void 0, void 0, function* () {
@@ -302,9 +338,11 @@ export class Account {
302
338
  });
303
339
  }
304
340
  /**
305
- * Tell if this account is in the [[Group]]
341
+ * Tells if this Account is in the [[Group]].
342
+ *
343
+ * @param group - The Group name, id or object
306
344
  *
307
- * @param group - The Group name, id or object
345
+ * @returns Promise with true if the Account is in the group
308
346
  */
309
347
  isInGroup(group) {
310
348
  return __awaiter(this, void 0, void 0, function* () {
@@ -336,7 +374,9 @@ export class Account {
336
374
  return false;
337
375
  }
338
376
  /**
339
- * Perform create new account.
377
+ * Performs create new Account.
378
+ *
379
+ * @returns Promise with this Account after creation
340
380
  */
341
381
  create() {
342
382
  return __awaiter(this, void 0, void 0, function* () {
@@ -346,7 +386,9 @@ export class Account {
346
386
  });
347
387
  }
348
388
  /**
349
- * Perform update account, applying pending changes.
389
+ * Performs update Account, applying pending changes.
390
+ *
391
+ * @returns Promise with this Account after update
350
392
  */
351
393
  update() {
352
394
  return __awaiter(this, void 0, void 0, function* () {
@@ -356,7 +398,9 @@ export class Account {
356
398
  });
357
399
  }
358
400
  /**
359
- * Perform delete account.
401
+ * Performs delete Account.
402
+ *
403
+ * @returns Promise with this Account after deletion
360
404
  */
361
405
  remove() {
362
406
  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();