bkper-js 1.14.1 → 1.16.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
@@ -755,6 +755,7 @@ export declare class Book {
755
755
 
756
756
 
757
757
 
758
+
758
759
  /**
759
760
  * Gets a [[Group]] object
760
761
  *
@@ -1630,6 +1631,10 @@ export declare class Transaction {
1630
1631
  * @returns True if transaction is in trash.
1631
1632
  */
1632
1633
  isTrashed(): boolean | undefined;
1634
+ /**
1635
+ * @returns True if a transaction is locked by the book lock/closing date
1636
+ */
1637
+ isLocked(): boolean;
1633
1638
  /**
1634
1639
  * @returns All #hashtags used on the transaction.
1635
1640
  */
@@ -1773,6 +1778,10 @@ export declare class Transaction {
1773
1778
  * @returns The amount of the transaction.
1774
1779
  */
1775
1780
  getAmount(): Amount | undefined;
1781
+ /**
1782
+ * @returns The amount of the transaction, formatted according to the Book format.
1783
+ */
1784
+ getAmountFormatted(): string | undefined;
1776
1785
  /**
1777
1786
  *
1778
1787
  * Sets the amount of the Transaction.
package/lib/model/Book.js CHANGED
@@ -510,6 +510,26 @@ export class Book {
510
510
  this.idAccountMap.delete(account.getId() || '');
511
511
  }
512
512
  }
513
+ /** @internal */
514
+ getMostRecentLockDate_() {
515
+ const closingDate = this.getClosingDate();
516
+ const lockDate = this.getLockDate();
517
+ if (!closingDate && !lockDate) {
518
+ return null;
519
+ }
520
+ if (!closingDate && lockDate) {
521
+ return lockDate;
522
+ }
523
+ if (closingDate && !lockDate) {
524
+ return closingDate;
525
+ }
526
+ if (Utils.getIsoDateValue(closingDate) > Utils.getIsoDateValue(lockDate)) {
527
+ return closingDate;
528
+ }
529
+ else {
530
+ return lockDate;
531
+ }
532
+ }
513
533
  /**
514
534
  * Gets a [[Group]] object
515
535
  *
@@ -104,6 +104,14 @@ export class Transaction {
104
104
  isTrashed() {
105
105
  return this.payload.trashed;
106
106
  }
107
+ /**
108
+ * @returns True if a transaction is locked by the book lock/closing date
109
+ */
110
+ isLocked() {
111
+ const date = this.getDate() || Utils.formatDateISO(new Date(), this.book.getTimeZone());
112
+ const lockOrClosingDate = this.book.getMostRecentLockDate_();
113
+ return lockOrClosingDate != null && (Utils.getIsoDateValue(lockOrClosingDate) >= Utils.getIsoDateValue(date));
114
+ }
107
115
  /**
108
116
  * @returns All #hashtags used on the transaction.
109
117
  */
@@ -393,6 +401,16 @@ export class Transaction {
393
401
  getAmount() {
394
402
  return this.payload.amount != null && this.payload.amount.trim() != '' ? new Amount(this.payload.amount) : undefined;
395
403
  }
404
+ /**
405
+ * @returns The amount of the transaction, formatted according to the Book format.
406
+ */
407
+ getAmountFormatted() {
408
+ const amount = this.getAmount();
409
+ if (amount) {
410
+ return this.book.formatValue(amount);
411
+ }
412
+ return undefined;
413
+ }
396
414
  /**
397
415
  *
398
416
  * Sets the amount of the Transaction.
package/lib/utils.js CHANGED
@@ -36,7 +36,7 @@ export function formatValue(value, decimalSeparator, fractionDigits) {
36
36
  if (value == null) {
37
37
  return "";
38
38
  }
39
- if (!fractionDigits) {
39
+ if (fractionDigits == null) {
40
40
  fractionDigits = 2;
41
41
  }
42
42
  var formattedValue = (value.toFixed(fractionDigits)) + "";
@@ -119,6 +119,9 @@ export function formatDateISO(date, timeZone) {
119
119
  var formatedDate = DateTime.fromJSDate(date, { zone: timeZone }).toISODate();
120
120
  return formatedDate;
121
121
  }
122
+ export function getIsoDateValue(date) {
123
+ return +(date.replace(/-/g, ''));
124
+ }
122
125
  export function parseDate(date, pattern, timeZone) {
123
126
  if (!pattern) {
124
127
  pattern = 'yyyy-MM-dd';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.14.1",
3
+ "version": "1.16.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",