bkper-js 2.0.0 → 2.2.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/CHANGELOG.md +4 -1
- package/README.md +5 -2
- package/lib/index.d.ts +344 -11
- package/lib/model/Balance.js +120 -0
- package/lib/model/BalancesContainerAccount.js +62 -1
- package/lib/model/BalancesContainerGroup.js +63 -2
- package/lib/model/BalancesDataTableBuilder.js +587 -0
- package/lib/model/Bkper.js +17 -7
- package/lib/model/Enums.js +20 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,9 +8,12 @@ See what's new and what has changed in bkper-js
|
|
|
8
8
|
**July 2025**
|
|
9
9
|
* **BREAKING CHANGE:** Refactored `Bkper` class from static methods to constructor-based pattern
|
|
10
10
|
* **BREAKING CHANGE:** Removed deprecated methods: `Transaction.remove()`, `Transaction.restore()`, `Account.getBalance()`, `Account.getBalanceRaw()`
|
|
11
|
-
* **MIGRATION:** Replace `Bkper.setConfig(config); Bkper.getBook(id)` with `const bkper = new Bkper(config); bkper.getBook(id)`
|
|
12
11
|
* **MIGRATION:** Use `transaction.trash()` and `transaction.untrash()` instead of `remove()` and `restore()`
|
|
13
12
|
* **MIGRATION:** Use `Book.getBalancesReport()` instead of `Account.getBalance()` methods
|
|
13
|
+
* Added [Balance](/docs/bkper-js/#balance) class back for improved balance reporting
|
|
14
|
+
* Added [BalancesDataTableBuilder](/docs/bkper-js/#balancesdatatablebuilder) for building balance data tables
|
|
15
|
+
* Added [BalanceType](/docs/bkper-js/#balancetype) enum with TOTAL, PERIOD, and CUMULATIVE options
|
|
16
|
+
* Updated `Book.getDatePattern()` to return default pattern 'dd/MM/yyyy' when not set
|
|
14
17
|
|
|
15
18
|
**June 2025**
|
|
16
19
|
* Added [Book.copy](/docs/bkper-js/#book_copy)
|
package/README.md
CHANGED
|
@@ -32,12 +32,15 @@ bun add bkper-js
|
|
|
32
32
|
```typescript
|
|
33
33
|
import { Bkper } from 'bkper-js';
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
|
|
35
|
+
// Set global configuration
|
|
36
|
+
Bkper.setConfig({
|
|
37
37
|
apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
38
38
|
oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
// Create Bkper instance (uses global config)
|
|
42
|
+
const bkper = new Bkper();
|
|
43
|
+
|
|
41
44
|
// Get a book and work with it
|
|
42
45
|
const book = await bkper.getBook('your-book-id');
|
|
43
46
|
console.log(`Book: ${book.getName()}`);
|
package/lib/index.d.ts
CHANGED
|
@@ -623,6 +623,87 @@ export declare class App {
|
|
|
623
623
|
update(): Promise<App>;
|
|
624
624
|
}
|
|
625
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Class that represents an [[Account]] or [[Group]] balance on a window of time (Day / Month / Year).
|
|
628
|
+
*
|
|
629
|
+
* @public
|
|
630
|
+
*/
|
|
631
|
+
declare class Balance {
|
|
632
|
+
json: bkper.Balance;
|
|
633
|
+
private container;
|
|
634
|
+
constructor(container: BalancesContainer, balancePlain: bkper.Balance);
|
|
635
|
+
/**
|
|
636
|
+
* The day of the balance. Days starts on 1 to 31.
|
|
637
|
+
*
|
|
638
|
+
* Day can be 0 (zero) in case of Monthly or Early [[Periodicity]] of the [[BalancesReport]]
|
|
639
|
+
*/
|
|
640
|
+
getDay(): number;
|
|
641
|
+
/**
|
|
642
|
+
* The month of the balance. Months starts on 1 (January) to 12 (December)
|
|
643
|
+
*
|
|
644
|
+
* Month can be 0 (zero) in case of Early [[Periodicity]] of the [[BalancesReport]]
|
|
645
|
+
*/
|
|
646
|
+
getMonth(): number;
|
|
647
|
+
/**
|
|
648
|
+
* The year of the balance
|
|
649
|
+
*/
|
|
650
|
+
getYear(): number;
|
|
651
|
+
/**
|
|
652
|
+
* Date object constructed based on [[Book]] time zone offset. Usefull for
|
|
653
|
+
*
|
|
654
|
+
* If Month or Day is zero, the date will be constructed with first Month (January) or Day (1).
|
|
655
|
+
*/
|
|
656
|
+
getDate(): Date;
|
|
657
|
+
/**
|
|
658
|
+
* The Fuzzy Date of the balance, based on [[Periodicity]] of the [[BalancesReport]] query, composed by Year, Month and Day.
|
|
659
|
+
*
|
|
660
|
+
* The format is **YYYYMMDD**. Very usefull for ordering and indexing
|
|
661
|
+
*
|
|
662
|
+
* Month and Day can be 0 (zero), depending on the granularity of the [[Periodicity]].
|
|
663
|
+
*
|
|
664
|
+
* *Example:*
|
|
665
|
+
*
|
|
666
|
+
* **20180125** - 25, January, 2018 - DAILY Periodicity
|
|
667
|
+
*
|
|
668
|
+
* **20180100** - January, 2018 - MONTHLY Periodicity
|
|
669
|
+
*
|
|
670
|
+
* **20180000** - 2018 - YEARLY Periodicity
|
|
671
|
+
*/
|
|
672
|
+
getFuzzyDate(): number;
|
|
673
|
+
/**
|
|
674
|
+
* The cumulative balance to the date, based on the credit nature of the container
|
|
675
|
+
*/
|
|
676
|
+
getCumulativeBalance(): Amount;
|
|
677
|
+
/**
|
|
678
|
+
* The raw cumulative balance to the date.
|
|
679
|
+
*/
|
|
680
|
+
getCumulativeBalanceRaw(): Amount;
|
|
681
|
+
/**
|
|
682
|
+
* The cumulative credit to the date.
|
|
683
|
+
*/
|
|
684
|
+
getCumulativeCredit(): Amount;
|
|
685
|
+
/**
|
|
686
|
+
* The cumulative debit to the date.
|
|
687
|
+
*/
|
|
688
|
+
getCumulativeDebit(): Amount;
|
|
689
|
+
/**
|
|
690
|
+
* The balance on the date period, based on credit nature of the container.
|
|
691
|
+
*/
|
|
692
|
+
getPeriodBalance(): Amount;
|
|
693
|
+
/**
|
|
694
|
+
* The raw balance on the date period.
|
|
695
|
+
*/
|
|
696
|
+
getPeriodBalanceRaw(): Amount;
|
|
697
|
+
/**
|
|
698
|
+
* The credit on the date period.
|
|
699
|
+
*/
|
|
700
|
+
getPeriodCredit(): Amount;
|
|
701
|
+
/**
|
|
702
|
+
* The debit on the date period.
|
|
703
|
+
*/
|
|
704
|
+
getPeriodDebit(): Amount;
|
|
705
|
+
}
|
|
706
|
+
|
|
626
707
|
/**
|
|
627
708
|
* The container of balances of an [[Account]] or [[Group]]
|
|
628
709
|
*
|
|
@@ -642,13 +723,13 @@ export declare interface BalancesContainer {
|
|
|
642
723
|
*
|
|
643
724
|
* @returns The [[Account]] or [[Group]] name
|
|
644
725
|
*/
|
|
645
|
-
getName: () => string
|
|
726
|
+
getName: () => string;
|
|
646
727
|
/**
|
|
647
728
|
* Gets the [[Account]] or [[Group]] name without spaces or special characters.
|
|
648
729
|
*
|
|
649
730
|
* @returns The [[Account]] or [[Group]] name without spaces or special characters
|
|
650
731
|
*/
|
|
651
|
-
getNormalizedName: () => string
|
|
732
|
+
getNormalizedName: () => string;
|
|
652
733
|
/**
|
|
653
734
|
* Gets the [[Group]] associated with this container.
|
|
654
735
|
*
|
|
@@ -667,6 +748,12 @@ export declare interface BalancesContainer {
|
|
|
667
748
|
* @returns The parent BalanceContainer
|
|
668
749
|
*/
|
|
669
750
|
getParent: () => BalancesContainer | null;
|
|
751
|
+
/**
|
|
752
|
+
* Gets all [[Balances]] of the container
|
|
753
|
+
*
|
|
754
|
+
* @returns All [[Balances]] of the container
|
|
755
|
+
*/
|
|
756
|
+
getBalances: () => Balance[];
|
|
670
757
|
/**
|
|
671
758
|
* Gets the depth in the parent chain up to the root.
|
|
672
759
|
*
|
|
@@ -694,7 +781,7 @@ export declare interface BalancesContainer {
|
|
|
694
781
|
*
|
|
695
782
|
* @returns True if its a permanent Account
|
|
696
783
|
*/
|
|
697
|
-
isPermanent: () => boolean
|
|
784
|
+
isPermanent: () => boolean;
|
|
698
785
|
/**
|
|
699
786
|
* Gets whether this balance container is from an [[Account]].
|
|
700
787
|
*
|
|
@@ -725,6 +812,14 @@ export declare interface BalancesContainer {
|
|
|
725
812
|
* @returns The cumulative raw balance to the date
|
|
726
813
|
*/
|
|
727
814
|
getCumulativeBalanceRaw: () => Amount;
|
|
815
|
+
/**
|
|
816
|
+
* The cumulative credit to the date.
|
|
817
|
+
*/
|
|
818
|
+
getCumulativeCredit(): Amount;
|
|
819
|
+
/**
|
|
820
|
+
* The cumulative debit to the date.
|
|
821
|
+
*/
|
|
822
|
+
getCumulativeDebit(): Amount;
|
|
728
823
|
/**
|
|
729
824
|
* Gets the cumulative balance formatted according to [[Book]] decimal format and fraction digits.
|
|
730
825
|
*
|
|
@@ -737,6 +832,14 @@ export declare interface BalancesContainer {
|
|
|
737
832
|
* @returns The cumulative raw balance formatted according to [[Book]] decimal format and fraction digits
|
|
738
833
|
*/
|
|
739
834
|
getCumulativeBalanceRawText: () => string;
|
|
835
|
+
/**
|
|
836
|
+
* The cumulative credit formatted according to [[Book]] decimal format and fraction digits.
|
|
837
|
+
*/
|
|
838
|
+
getCumulativeCreditText(): string;
|
|
839
|
+
/**
|
|
840
|
+
* The cumulative credit formatted according to [[Book]] decimal format and fraction digits.
|
|
841
|
+
*/
|
|
842
|
+
getCumulativeDebitText(): string;
|
|
740
843
|
/**
|
|
741
844
|
* Gets the balance on the date period.
|
|
742
845
|
*
|
|
@@ -749,6 +852,14 @@ export declare interface BalancesContainer {
|
|
|
749
852
|
* @returns The raw balance on the date period
|
|
750
853
|
*/
|
|
751
854
|
getPeriodBalanceRaw: () => Amount;
|
|
855
|
+
/**
|
|
856
|
+
* The credit on the date period.
|
|
857
|
+
*/
|
|
858
|
+
getPeriodCredit(): Amount;
|
|
859
|
+
/**
|
|
860
|
+
* The debit on the date period.
|
|
861
|
+
*/
|
|
862
|
+
getPeriodDebit(): Amount;
|
|
752
863
|
/**
|
|
753
864
|
* Gets the balance on the date period formatted according to [[Book]] decimal format and fraction digits.
|
|
754
865
|
*
|
|
@@ -761,6 +872,35 @@ export declare interface BalancesContainer {
|
|
|
761
872
|
* @returns The raw balance on the date period formatted according to [[Book]] decimal format and fraction digits
|
|
762
873
|
*/
|
|
763
874
|
getPeriodBalanceRawText: () => string;
|
|
875
|
+
/**
|
|
876
|
+
* The credit on the date period formatted according to [[Book]] decimal format and fraction digits
|
|
877
|
+
*/
|
|
878
|
+
getPeriodCreditText(): string;
|
|
879
|
+
/**
|
|
880
|
+
* The debit on the date period formatted according to [[Book]] decimal format and fraction digits
|
|
881
|
+
*/
|
|
882
|
+
getPeriodDebitText(): string;
|
|
883
|
+
/**
|
|
884
|
+
* Gets the custom properties stored in this Account or Group.
|
|
885
|
+
*/
|
|
886
|
+
getProperties(): {
|
|
887
|
+
[key: string]: string;
|
|
888
|
+
};
|
|
889
|
+
/**
|
|
890
|
+
*
|
|
891
|
+
* Gets the property value for given keys. First property found will be retrieved
|
|
892
|
+
*
|
|
893
|
+
* @param keys The property key
|
|
894
|
+
*/
|
|
895
|
+
getProperty(...keys: string[]): string | undefined;
|
|
896
|
+
/**
|
|
897
|
+
* Gets the custom properties keys stored in the associated [[Account]] or [[Group]].
|
|
898
|
+
*/
|
|
899
|
+
getPropertyKeys(): string[];
|
|
900
|
+
/**
|
|
901
|
+
* Creates a BalancesDataTableBuilder to generate a two-dimensional array with all [[BalancesContainers]]
|
|
902
|
+
*/
|
|
903
|
+
createDataTable(): BalancesDataTableBuilder;
|
|
764
904
|
/**
|
|
765
905
|
* Gets all child [[BalancesContainers]].
|
|
766
906
|
*
|
|
@@ -779,6 +919,171 @@ export declare interface BalancesContainer {
|
|
|
779
919
|
getBalancesContainer: (name: string) => BalancesContainer;
|
|
780
920
|
}
|
|
781
921
|
|
|
922
|
+
/**
|
|
923
|
+
* A BalancesDataTableBuilder is used to setup and build two-dimensional arrays containing balance information.
|
|
924
|
+
*
|
|
925
|
+
* @public
|
|
926
|
+
*/
|
|
927
|
+
declare class BalancesDataTableBuilder implements BalancesDataTableBuilder {
|
|
928
|
+
private balanceType;
|
|
929
|
+
private balancesContainers;
|
|
930
|
+
private periodicity;
|
|
931
|
+
private shouldFormatDate;
|
|
932
|
+
private shouldHideDates;
|
|
933
|
+
private shouldHideNames;
|
|
934
|
+
private shouldFormatValue;
|
|
935
|
+
private book;
|
|
936
|
+
private shouldTranspose;
|
|
937
|
+
private shouldTrial;
|
|
938
|
+
private shouldPeriod;
|
|
939
|
+
private shouldRaw;
|
|
940
|
+
private shouldAddProperties;
|
|
941
|
+
private maxDepth;
|
|
942
|
+
private expandAllAccounts;
|
|
943
|
+
private expandAllGroups;
|
|
944
|
+
private skipRoot;
|
|
945
|
+
constructor(book: Book, balancesContainers: BalancesContainer[], periodicity: Periodicity);
|
|
946
|
+
private getBalance;
|
|
947
|
+
private getRepresentativeBalance;
|
|
948
|
+
private getBalanceText;
|
|
949
|
+
/**
|
|
950
|
+
* Defines whether the dates should be formatted based on date pattern and periodicity of the [[Book]].
|
|
951
|
+
*
|
|
952
|
+
* @returns This builder with respective formatting option, for chaining.
|
|
953
|
+
*/
|
|
954
|
+
formatDates(format: boolean): BalancesDataTableBuilder;
|
|
955
|
+
/**
|
|
956
|
+
* Defines whether the value should be formatted based on decimal separator of the [[Book]].
|
|
957
|
+
*
|
|
958
|
+
* @returns This builder with respective formatting option, for chaining.
|
|
959
|
+
*/
|
|
960
|
+
formatValues(format: boolean): BalancesDataTableBuilder;
|
|
961
|
+
/**
|
|
962
|
+
* Defines whether Groups should expand its child accounts. true to expand itself, -1 to expand all subgroups. -2 to expand all accounts.
|
|
963
|
+
*
|
|
964
|
+
*
|
|
965
|
+
* @returns This builder with respective expanded option, for chaining.
|
|
966
|
+
*/
|
|
967
|
+
expanded(expanded: boolean | number): BalancesDataTableBuilder;
|
|
968
|
+
/**
|
|
969
|
+
* Fluent method to set the [[BalanceType]] for the builder.
|
|
970
|
+
*
|
|
971
|
+
* @param type The type of balance for this data table
|
|
972
|
+
*
|
|
973
|
+
* For **TOTAL** [[BalanceType]], the table format looks like:
|
|
974
|
+
*
|
|
975
|
+
* ```
|
|
976
|
+
* _____________________
|
|
977
|
+
* | Expenses | -4568.23 |
|
|
978
|
+
* | Income | 5678.93 |
|
|
979
|
+
* | ... | ... |
|
|
980
|
+
* |___________|__________|
|
|
981
|
+
*
|
|
982
|
+
* ```
|
|
983
|
+
* Two columns, and each [[Account]] or [[Group]] per line.
|
|
984
|
+
*
|
|
985
|
+
* For **PERIOD** or **CUMULATIVE** [[BalanceType]], the table will be a time table, and the format looks like:
|
|
986
|
+
*
|
|
987
|
+
* ```
|
|
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
|
+
* |____________|___________|_________|__________|
|
|
995
|
+
*
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* First column will be the Date column, and one column for each [[Account]] or [[Group]].
|
|
999
|
+
*
|
|
1000
|
+
* @returns This builder with respective balance type, for chaining.
|
|
1001
|
+
*/
|
|
1002
|
+
type(type: BalanceType): BalancesDataTableBuilder;
|
|
1003
|
+
/**
|
|
1004
|
+
* Defines whether should rows and columns should be transposed.
|
|
1005
|
+
*
|
|
1006
|
+
* For **TOTAL** [[BalanceType]], the **transposed** table looks like:
|
|
1007
|
+
*
|
|
1008
|
+
* ```
|
|
1009
|
+
* _____________________________
|
|
1010
|
+
* | Expenses | Income | ... |
|
|
1011
|
+
* | -4568.23 | 5678.93 | ... |
|
|
1012
|
+
* |___________|_________|_______|
|
|
1013
|
+
*
|
|
1014
|
+
* ```
|
|
1015
|
+
* Two rows, and each [[Account]] or [[Group]] per column.
|
|
1016
|
+
*
|
|
1017
|
+
*
|
|
1018
|
+
* For **PERIOD** or **CUMULATIVE** [[BalanceType]], the **transposed** table will be a time table, and the format looks like:
|
|
1019
|
+
*
|
|
1020
|
+
* ```
|
|
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 | ... |
|
|
1025
|
+
* | ... | ... | ... | ... | ... |
|
|
1026
|
+
* |____________|____________|____________|____________|___________|
|
|
1027
|
+
*
|
|
1028
|
+
* ```
|
|
1029
|
+
*
|
|
1030
|
+
* First column will be each [[Account]] or [[Group]], and one column for each Date.
|
|
1031
|
+
*
|
|
1032
|
+
* @returns This builder with respective transposed option, for chaining.
|
|
1033
|
+
*/
|
|
1034
|
+
transposed(transposed: boolean): BalancesDataTableBuilder;
|
|
1035
|
+
/**
|
|
1036
|
+
* Defines whether the dates should be hidden for **PERIOD** or **CUMULATIVE** [[BalanceType]].
|
|
1037
|
+
*
|
|
1038
|
+
* @returns This builder with respective hide dates option, for chaining.
|
|
1039
|
+
*/
|
|
1040
|
+
hideDates(hide: boolean): BalancesDataTableBuilder;
|
|
1041
|
+
/**
|
|
1042
|
+
* Defines whether the [[Accounts]] and [[Groups]] names should be hidden.
|
|
1043
|
+
*
|
|
1044
|
+
* @returns This builder with respective hide names option, for chaining.
|
|
1045
|
+
*/
|
|
1046
|
+
hideNames(hide: boolean): BalancesDataTableBuilder;
|
|
1047
|
+
/**
|
|
1048
|
+
* Defines whether include custom [[Accounts]] and [[Groups]] properties.
|
|
1049
|
+
*
|
|
1050
|
+
* @returns This builder with respective include properties option, for chaining.
|
|
1051
|
+
*/
|
|
1052
|
+
properties(include: boolean): BalancesDataTableBuilder;
|
|
1053
|
+
/**
|
|
1054
|
+
* Defines whether should split **TOTAL** [[BalanceType]] into debit and credit.
|
|
1055
|
+
*
|
|
1056
|
+
* @returns This builder with respective trial option, for chaining.
|
|
1057
|
+
*/
|
|
1058
|
+
trial(trial: boolean): BalancesDataTableBuilder;
|
|
1059
|
+
/**
|
|
1060
|
+
* Defines whether should force use of period balances for **TOTAL** [[BalanceType]].
|
|
1061
|
+
*
|
|
1062
|
+
* @returns This builder with respective trial option, for chaining.
|
|
1063
|
+
*/
|
|
1064
|
+
period(period: boolean): BalancesDataTableBuilder;
|
|
1065
|
+
/**
|
|
1066
|
+
* Defines whether should show raw balances, no matter the credit nature of the Account or Group.
|
|
1067
|
+
*
|
|
1068
|
+
* @returns This builder with respective trial option, for chaining.
|
|
1069
|
+
*/
|
|
1070
|
+
raw(raw: boolean): BalancesDataTableBuilder;
|
|
1071
|
+
/**
|
|
1072
|
+
*
|
|
1073
|
+
* Builds an two-dimensional array with the balances.
|
|
1074
|
+
*
|
|
1075
|
+
*/
|
|
1076
|
+
build(): any[][];
|
|
1077
|
+
private addPropertyKeys;
|
|
1078
|
+
private flattenContainers;
|
|
1079
|
+
private flattenAllAccounts;
|
|
1080
|
+
private sortContainersFunction;
|
|
1081
|
+
private flattenMaxDepth;
|
|
1082
|
+
private flattenAllGroups;
|
|
1083
|
+
private buildTotalDataTable_;
|
|
1084
|
+
private buildTimeDataTable_;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
782
1087
|
/**
|
|
783
1088
|
* Class representing a Balance Report, generated when calling [Book.getBalanceReport](#book_getbalancesreport)
|
|
784
1089
|
*
|
|
@@ -822,31 +1127,59 @@ export declare class BalancesReport {
|
|
|
822
1127
|
|
|
823
1128
|
}
|
|
824
1129
|
|
|
1130
|
+
/**
|
|
1131
|
+
* Enum that represents balance types.
|
|
1132
|
+
*
|
|
1133
|
+
* @public
|
|
1134
|
+
*/
|
|
1135
|
+
declare enum BalanceType {
|
|
1136
|
+
/**
|
|
1137
|
+
* Total balance
|
|
1138
|
+
*/
|
|
1139
|
+
TOTAL = "TOTAL",
|
|
1140
|
+
/**
|
|
1141
|
+
* Period balance
|
|
1142
|
+
*/
|
|
1143
|
+
PERIOD = "PERIOD",
|
|
1144
|
+
/**
|
|
1145
|
+
* Cumulative balance
|
|
1146
|
+
*/
|
|
1147
|
+
CUMULATIVE = "CUMULATIVE"
|
|
1148
|
+
}
|
|
1149
|
+
|
|
825
1150
|
/**
|
|
826
1151
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
827
1152
|
*
|
|
828
|
-
* You start by setting the API [[Config]] object.
|
|
1153
|
+
* You start by setting the API [[Config]] object using the static setConfig method.
|
|
829
1154
|
*
|
|
830
1155
|
* Example:
|
|
831
1156
|
*
|
|
832
1157
|
* ```javascript
|
|
833
|
-
* Bkper.
|
|
1158
|
+
* Bkper.setConfig({
|
|
834
1159
|
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
835
1160
|
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
836
|
-
* })
|
|
1161
|
+
* });
|
|
1162
|
+
*
|
|
1163
|
+
* const bkper = new Bkper();
|
|
1164
|
+
* const book = await bkper.getBook('bookId');
|
|
837
1165
|
* ```
|
|
838
1166
|
*
|
|
839
|
-
* Once the config is set, you can start using the library.
|
|
1167
|
+
* Once the config is set, you can create instances and start using the library.
|
|
840
1168
|
*
|
|
841
1169
|
* @public
|
|
842
1170
|
*/
|
|
843
1171
|
export declare class Bkper {
|
|
844
1172
|
/**
|
|
845
|
-
*
|
|
1173
|
+
* Sets the global API configuration for all Bkper operations.
|
|
846
1174
|
*
|
|
847
|
-
* @param config - The Config object
|
|
1175
|
+
* @param config - The Config object containing API key and OAuth token providers
|
|
1176
|
+
*/
|
|
1177
|
+
static setConfig(config: Config): void;
|
|
1178
|
+
/**
|
|
1179
|
+
* Creates a new Bkper instance using the global configuration set via setConfig().
|
|
1180
|
+
* Make sure to call Bkper.setConfig() before creating instances.
|
|
848
1181
|
*/
|
|
849
|
-
constructor(
|
|
1182
|
+
constructor();
|
|
850
1183
|
/**
|
|
851
1184
|
* Gets the [[Book]] with the specified bookId from url param.
|
|
852
1185
|
*
|
|
@@ -1031,7 +1364,7 @@ export declare class Book {
|
|
|
1031
1364
|
*
|
|
1032
1365
|
* @returns The date pattern of the Book. Current: dd/MM/yyyy | MM/dd/yyyy | yyyy/MM/dd
|
|
1033
1366
|
*/
|
|
1034
|
-
getDatePattern(): string
|
|
1367
|
+
getDatePattern(): string;
|
|
1035
1368
|
/**
|
|
1036
1369
|
* Sets the date pattern of the Book. Current: dd/MM/yyyy | MM/dd/yyyy | yyyy/MM/dd
|
|
1037
1370
|
*
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as Utils from '../utils.js';
|
|
2
|
+
import { Amount } from "./Amount";
|
|
3
|
+
/**
|
|
4
|
+
* Class that represents an [[Account]] or [[Group]] balance on a window of time (Day / Month / Year).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class Balance {
|
|
9
|
+
constructor(container, balancePlain) {
|
|
10
|
+
this.container = container;
|
|
11
|
+
this.json = balancePlain;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The day of the balance. Days starts on 1 to 31.
|
|
15
|
+
*
|
|
16
|
+
* Day can be 0 (zero) in case of Monthly or Early [[Periodicity]] of the [[BalancesReport]]
|
|
17
|
+
*/
|
|
18
|
+
getDay() {
|
|
19
|
+
return this.json.day;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The month of the balance. Months starts on 1 (January) to 12 (December)
|
|
23
|
+
*
|
|
24
|
+
* Month can be 0 (zero) in case of Early [[Periodicity]] of the [[BalancesReport]]
|
|
25
|
+
*/
|
|
26
|
+
getMonth() {
|
|
27
|
+
return this.json.month;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The year of the balance
|
|
31
|
+
*/
|
|
32
|
+
getYear() {
|
|
33
|
+
return this.json.year;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Date object constructed based on [[Book]] time zone offset. Usefull for
|
|
37
|
+
*
|
|
38
|
+
* If Month or Day is zero, the date will be constructed with first Month (January) or Day (1).
|
|
39
|
+
*/
|
|
40
|
+
getDate() {
|
|
41
|
+
var year = this.getYear();
|
|
42
|
+
var month = this.getMonth();
|
|
43
|
+
var day = this.getDay();
|
|
44
|
+
if (month == null || month == 0) {
|
|
45
|
+
year++;
|
|
46
|
+
}
|
|
47
|
+
if (day == null || day == 0) {
|
|
48
|
+
month++;
|
|
49
|
+
}
|
|
50
|
+
var date = Utils.createDate(year, month, day, this.container.getBalancesReport().getBook().getTimeZoneOffset());
|
|
51
|
+
return date;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The Fuzzy Date of the balance, based on [[Periodicity]] of the [[BalancesReport]] query, composed by Year, Month and Day.
|
|
55
|
+
*
|
|
56
|
+
* The format is **YYYYMMDD**. Very usefull for ordering and indexing
|
|
57
|
+
*
|
|
58
|
+
* Month and Day can be 0 (zero), depending on the granularity of the [[Periodicity]].
|
|
59
|
+
*
|
|
60
|
+
* *Example:*
|
|
61
|
+
*
|
|
62
|
+
* **20180125** - 25, January, 2018 - DAILY Periodicity
|
|
63
|
+
*
|
|
64
|
+
* **20180100** - January, 2018 - MONTHLY Periodicity
|
|
65
|
+
*
|
|
66
|
+
* **20180000** - 2018 - YEARLY Periodicity
|
|
67
|
+
*/
|
|
68
|
+
getFuzzyDate() {
|
|
69
|
+
return this.json.fuzzyDate;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The cumulative balance to the date, based on the credit nature of the container
|
|
73
|
+
*/
|
|
74
|
+
getCumulativeBalance() {
|
|
75
|
+
return Utils.getRepresentativeValue(this.getCumulativeBalanceRaw(), this.container.isCredit());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The raw cumulative balance to the date.
|
|
79
|
+
*/
|
|
80
|
+
getCumulativeBalanceRaw() {
|
|
81
|
+
return new Amount(this.json.cumulativeBalance);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The cumulative credit to the date.
|
|
85
|
+
*/
|
|
86
|
+
getCumulativeCredit() {
|
|
87
|
+
return new Amount(this.json.cumulativeCredit);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The cumulative debit to the date.
|
|
91
|
+
*/
|
|
92
|
+
getCumulativeDebit() {
|
|
93
|
+
return new Amount(this.json.cumulativeDebit);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The balance on the date period, based on credit nature of the container.
|
|
97
|
+
*/
|
|
98
|
+
getPeriodBalance() {
|
|
99
|
+
return Utils.getRepresentativeValue(this.getPeriodBalanceRaw(), this.container.isCredit());
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The raw balance on the date period.
|
|
103
|
+
*/
|
|
104
|
+
getPeriodBalanceRaw() {
|
|
105
|
+
return new Amount(this.json.periodBalance);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The credit on the date period.
|
|
109
|
+
*/
|
|
110
|
+
getPeriodCredit() {
|
|
111
|
+
return new Amount(this.json.periodCredit);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The debit on the date period.
|
|
115
|
+
*/
|
|
116
|
+
getPeriodDebit() {
|
|
117
|
+
return new Amount(this.json.periodDebit);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=Balance.js.map
|