@tomei/finance 0.6.48 → 0.6.50

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.
Files changed (101) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc.js +72 -72
  3. package/.husky/commit-msg +4 -4
  4. package/.husky/pre-commit +4 -4
  5. package/.prettierrc +4 -4
  6. package/CONTRIBUTING.md +30 -30
  7. package/LICENSE +21 -21
  8. package/README.md +13 -13
  9. package/configs/config.js +348 -348
  10. package/dist/document/document.js +9 -9
  11. package/dist/document/document.js.map +1 -1
  12. package/dist/finance-company/finance-company.js +48 -32
  13. package/dist/finance-company/finance-company.js.map +1 -1
  14. package/dist/payment-item/payment-item.js +4 -4
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/invoice-template/assets/css/style.css.map +12 -12
  17. package/invoice-template/assets/css/style.min.css +1 -1
  18. package/invoice-template/assets/img/arrow_bg.svg +11 -11
  19. package/invoice-template/assets/img/coffy_shop_img.svg +18 -18
  20. package/invoice-template/assets/img/logo_accent.svg +3 -3
  21. package/invoice-template/assets/img/logo_white.svg +4 -4
  22. package/invoice-template/assets/img/sign.svg +12 -12
  23. package/invoice-template/assets/img/tomei-logo.svg +9 -9
  24. package/invoice-template/assets/js/html2canvas.min.js +10379 -10379
  25. package/invoice-template/assets/js/jquery.min.js +1 -1
  26. package/invoice-template/assets/sass/common/_color_variable.scss +12 -12
  27. package/invoice-template/assets/sass/common/_typography.scss +178 -178
  28. package/invoice-template/assets/sass/style.scss +12 -12
  29. package/migrations/finance-account-migration.js +97 -97
  30. package/migrations/finance-company-migration.js +29 -29
  31. package/migrations/finance-customer-migration.js +51 -51
  32. package/migrations/finance-document-item-migration.js +111 -111
  33. package/migrations/finance-document-migration.js +122 -122
  34. package/migrations/finance-journal-entry-migration.js +59 -59
  35. package/migrations/finance-ledger-transaction-migration.js +89 -89
  36. package/migrations/finance-payment-item-migration.js +52 -52
  37. package/migrations/finance-payment-method-migration.js +31 -31
  38. package/migrations/finance-payment-method-type-migration.js +55 -55
  39. package/migrations/finance-payment-migration.js +96 -96
  40. package/migrations/finance-post-history-migration.js +45 -45
  41. package/migrations/finance-tax-migration.js +52 -52
  42. package/nest-cli.json +19 -19
  43. package/package.json +82 -82
  44. package/src/account/account.repository.ts +11 -11
  45. package/src/account/account.ts +276 -276
  46. package/src/account/interfaces/account-attr.interface.ts +31 -31
  47. package/src/account-system-entity/account-system-entity.ts +66 -66
  48. package/src/account-system-entity/post-history.repository.ts +11 -11
  49. package/src/config.ts +382 -382
  50. package/src/customer/customer.ts +300 -300
  51. package/src/customer/finance-customer.repository.ts +13 -13
  52. package/src/customer/interfaces/customer.repository.interface.ts +3 -3
  53. package/src/customer/interfaces/finance-customer-attr.interface.ts +10 -10
  54. package/src/customer/interfaces/finance-customer.repository.interface.ts +4 -4
  55. package/src/database.ts +48 -48
  56. package/src/document/document-item.repository.ts +11 -11
  57. package/src/document/document.repository.ts +11 -11
  58. package/src/document/document.ts +11 -10
  59. package/src/document/interfaces/document-attr.interface.ts +28 -28
  60. package/src/document/interfaces/document-item-attr.interface.ts +22 -22
  61. package/src/document/interfaces/document-item.repository.interface.ts +4 -4
  62. package/src/enum/doc-type.enum.ts +8 -8
  63. package/src/enum/index.ts +17 -17
  64. package/src/enum/payment-method.enum.ts +3 -3
  65. package/src/enum/payment-type.enum.ts +4 -4
  66. package/src/finance-company/finance-company.repository.ts +11 -11
  67. package/src/finance-company/finance-company.ts +2085 -2066
  68. package/src/helpers/login-user.ts +38 -38
  69. package/src/helpers/typeof.ts +35 -35
  70. package/src/index.ts +32 -32
  71. package/src/interfaces/account-system.interface.ts +20 -20
  72. package/src/interfaces/index.ts +3 -3
  73. package/src/models/account.entity.ts +206 -206
  74. package/src/models/customer.entity.ts +93 -93
  75. package/src/models/document-item.entity.ts +143 -143
  76. package/src/models/document.entity.ts +211 -211
  77. package/src/models/finance-company.entity.ts +29 -29
  78. package/src/models/journal-entry.entity.ts +110 -110
  79. package/src/models/ledger-transaction.entity.ts +148 -148
  80. package/src/models/payment-item.entity.ts +60 -60
  81. package/src/models/payment-method-type.entity.ts +70 -70
  82. package/src/models/payment-method.entity.ts +51 -51
  83. package/src/models/payment.entity.ts +165 -165
  84. package/src/models/post-history.entity.ts +41 -41
  85. package/src/models/tax.entity.ts +75 -75
  86. package/src/payment/interfaces/payment-attr.interface.ts +23 -23
  87. package/src/payment/interfaces/payment-params.interface.ts +8 -8
  88. package/src/payment/payment.repository.ts +11 -11
  89. package/src/payment/payment.ts +236 -236
  90. package/src/payment-item/interfaces/payment-item-attr.interface.ts +10 -10
  91. package/src/payment-item/payment-item.repository.ts +11 -11
  92. package/src/payment-item/payment-item.ts +133 -133
  93. package/src/payment-method/payment-method.repository.ts +11 -11
  94. package/src/payment-method-type/payment-method-type.repository.ts +11 -11
  95. package/src/tax/interfaces/tax-attr.interface.ts +10 -10
  96. package/src/tax/tax.repository.ts +11 -11
  97. package/src/tax/tax.ts +61 -61
  98. package/src/test-document.ts +25 -25
  99. package/tsconfig.build.json +4 -4
  100. package/tsconfig.json +22 -22
  101. package/tslint.json +18 -18
@@ -1,300 +1,300 @@
1
- import {
2
- IAddress,
3
- IRepositoryBase,
4
- IPerson,
5
- LoginUserBase,
6
- } from '@tomei/general';
7
- import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
8
- import FinanceCustomerModel from '../models/customer.entity';
9
- import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
10
- import { FinanceCustomerRepository } from './finance-customer.repository';
11
- import * as cuid from 'cuid';
12
- import Account from '../account/account';
13
- import { AccountRepository } from '../account/account.repository';
14
- import { type } from '../helpers/typeof';
15
- import * as FinanceDb from '../database';
16
- import { LedgerTransactionRepository } from '../ledger-transaction/ledger-transaction.repository';
17
-
18
- // const AccountSystemEntity = import('../account-system-entity').then(({AccountSystemEntity}) => AccountSystemEntity);
19
- export default abstract class FinanceCustomerBase
20
- extends AccountSystemEntity
21
- implements IPerson
22
- {
23
- CustomerId = 'New';
24
- CustSystemCode = '';
25
- CustSystemRefId = '';
26
-
27
- protected abstract ParentARAccountNo: string;
28
- protected abstract ParentAPAccountNo: string;
29
- protected abstract ARAccountNo: string;
30
- protected abstract APAccountNo: string;
31
- protected abstract _ObjectType: string;
32
-
33
- abstract FullName: string;
34
- abstract IDNo: string;
35
- abstract IDType: string;
36
- abstract ContactNo: string;
37
- abstract Email: string;
38
- abstract DefaultAddress: IAddress;
39
-
40
- private _AccountReceivable: Account;
41
- private _AccountPayable: Account;
42
-
43
- protected _DbTransaction: any;
44
-
45
- private static _AccountRepository = new AccountRepository();
46
- private static _LedgerTransactionRepository =
47
- new LedgerTransactionRepository();
48
-
49
- // note: getDetails from spec is void type. Meaning that this probably needed a fix soon
50
- async getDetails(): Promise<{
51
- FullName: string;
52
- IDNo: string;
53
- IDType: string;
54
- Email: string;
55
- ContactNo: string;
56
- }> {
57
- return {
58
- FullName: this.FullName,
59
- IDNo: this.IDNo,
60
- IDType: this.IDType,
61
- Email: this.Email,
62
- ContactNo: this.ContactNo,
63
- };
64
- }
65
-
66
- protected static _FinanceCustomerRepository = new FinanceCustomerRepository();
67
- RepositoryBase: IRepositoryBase<any>;
68
-
69
- constructor(
70
- custSystemRefId?: string,
71
- custSystemCode?: string,
72
- sFinanceCompanyId?: string,
73
- ) {
74
- super();
75
- if (custSystemRefId && custSystemCode && sFinanceCompanyId) {
76
- this.CustSystemRefId = custSystemRefId;
77
- this.CustSystemCode = custSystemCode;
78
- this.CompanyId = sFinanceCompanyId;
79
- }
80
- }
81
-
82
- public static async initCustomer<C extends FinanceCustomerBase>(
83
- this: new () => C,
84
- custSystemRefId: string,
85
- custSystemCode: string,
86
- sFinanceCompanyId: string,
87
- dbTransaction?: any,
88
- ): Promise<C> {
89
- if (!dbTransaction) {
90
- dbTransaction = await FinanceDb.getConnection().transaction();
91
- }
92
-
93
- const financeCustomerData =
94
- await FinanceCustomerBase._FinanceCustomerRepository.findOne({
95
- where: {
96
- CompanyId: sFinanceCompanyId,
97
- CustSystemCode: custSystemCode,
98
- CustSystemRefId: custSystemRefId,
99
- },
100
- transaction: dbTransaction,
101
- });
102
- if (financeCustomerData) {
103
- const self = new this();
104
- self._DbTransaction = dbTransaction;
105
- self.CustomerId = financeCustomerData.CustomerId;
106
- self.CompanyId = sFinanceCompanyId;
107
- self.CustSystemCode = custSystemCode;
108
- self.CustSystemRefId = custSystemRefId;
109
- self.AccSystemRefId = financeCustomerData.AccSystemRefId;
110
- self.PostedToAccSystemYN = financeCustomerData.PostedToAccSystemYN;
111
- self.PostedById = financeCustomerData.PostedById;
112
- self.PostedDateTime = financeCustomerData.PostedDateTime;
113
- return self;
114
- } else {
115
- const notFoundError = new RecordNotFoundError(
116
- 'FinanceCustomerErrMsg',
117
- 'No Record Found',
118
- );
119
- throw notFoundError;
120
- }
121
- }
122
-
123
- async getAccountReceivable(): Promise<Account> {
124
- try {
125
- const transaction = this._DbTransaction;
126
- if (this._AccountReceivable) {
127
- return this._AccountReceivable;
128
- } else {
129
- const accountData =
130
- await FinanceCustomerBase._AccountRepository.findOne({
131
- where: {
132
- AccountNo: this.ARAccountNo,
133
- AccountType: 'Account Receivable',
134
- OwnerId: this.CustomerId,
135
- OwnerType: type(this),
136
- },
137
- transaction,
138
- });
139
- this._AccountReceivable = new Account(transaction);
140
- if (accountData) {
141
- this._AccountReceivable.AccountNo = accountData.AccountNo;
142
- this._AccountReceivable.ParentAccountNo = accountData.ParentAccountNo;
143
- this._AccountReceivable.AccountType = accountData.AccountType;
144
- this._AccountReceivable.OwnerId = accountData.OwnerId;
145
- this._AccountReceivable.OwnerType = accountData.OwnerType;
146
- } else {
147
- // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
148
- // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
149
- this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
150
- this._AccountReceivable.ParentAccountNo = this.ParentARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR'
151
- this._AccountReceivable.AccountType = 'Account Receivable';
152
- this._AccountReceivable.OwnerId = this.CustomerId;
153
- this._AccountReceivable.OwnerType = type(this);
154
- }
155
- return this._AccountReceivable;
156
- }
157
- } catch (error) {
158
- throw error;
159
- }
160
- }
161
-
162
- async getAccountPayable(): Promise<Account> {
163
- try {
164
- const transaction = this._DbTransaction;
165
- if (this._AccountPayable) {
166
- return this._AccountPayable;
167
- } else {
168
- const accountData =
169
- await FinanceCustomerBase._AccountRepository.findOne({
170
- where: {
171
- AccountNo: this.APAccountNo,
172
- AccountType: 'Account Payable',
173
- OwnerId: this.CustomerId,
174
- OwnerType: type(this),
175
- },
176
- transaction,
177
- });
178
-
179
- this._AccountPayable = new Account(transaction);
180
- if (accountData) {
181
- this._AccountPayable.AccountNo = accountData.AccountNo;
182
- this._AccountPayable.ParentAccountNo = accountData.ParentAccountNo;
183
- this._AccountPayable.AccountType = accountData.AccountType;
184
- this._AccountPayable.OwnerId = accountData.OwnerId;
185
- this._AccountPayable.OwnerType = accountData.OwnerType;
186
- } else {
187
- // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
188
- // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
189
- this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
190
- this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
191
- this._AccountPayable.AccountType = 'Account Payable';
192
- this._AccountPayable.OwnerId = this.CustomerId;
193
- this._AccountPayable.OwnerType = type(this);
194
- }
195
-
196
- return this._AccountPayable;
197
- }
198
- } catch (error) {
199
- throw error;
200
- }
201
- }
202
-
203
- /*
204
- * Get the billing address for a person.
205
- **/
206
- abstract getBillingAddress(params: any): Promise<IAddress>;
207
-
208
- init(person: LoginUserBase) {
209
- this.FullName = person.FullName;
210
- this.IDNo = person.IDNo;
211
- this.IDType = person.IDType;
212
- this.Email = person.Email;
213
- this.ContactNo = person.ContactNo;
214
- this.DefaultAddress = person.DefaultAddress;
215
- }
216
-
217
- async save(
218
- accSystemRefId: string,
219
- custSystemCode: string,
220
- custSystemRefId: string,
221
- dbTransaction?: any,
222
- ): Promise<FinanceCustomerModel> {
223
- this.CustSystemCode = custSystemCode;
224
- this.CustSystemRefId = custSystemRefId;
225
- this.AccSystemRefId = accSystemRefId;
226
- this.PostedToAccSystemYN = 'Y';
227
- const data = await FinanceCustomerBase._FinanceCustomerRepository.create(
228
- {
229
- CompanyId: this.CompanyId,
230
- CustomerId: cuid(),
231
- CustSystemCode: this.CustSystemCode,
232
- CustSystemRefId: this.CustSystemRefId,
233
- AccSystemRefId: this.AccSystemRefId,
234
- PostedToAccSystemYN: this.PostedToAccSystemYN,
235
- },
236
- { transaction: dbTransaction },
237
- );
238
- return data;
239
- }
240
-
241
- static async isFinanceCustomerExist(
242
- custSystemRefId: string,
243
- custSystemCode: string,
244
- sFinanceCompanyId: string,
245
- dbTransaction?: any,
246
- ): Promise<boolean> {
247
- const data = await FinanceCustomerBase._FinanceCustomerRepository.findAll({
248
- where: {
249
- CustSystemRefId: custSystemRefId,
250
- CustSystemCode: custSystemCode,
251
- CompanyId: sFinanceCompanyId,
252
- },
253
- transaction: dbTransaction,
254
- });
255
-
256
- if (data.length > 0) {
257
- return true;
258
- }
259
- return false;
260
- }
261
-
262
- /**
263
- * Method to calculate and return the outstanding balance for customer receivable account
264
- *
265
- * @param dbTransaction
266
- * @returns {number}
267
- */
268
- async getOutstandingBalance(dbTransaction: any): Promise<number> {
269
- if (!dbTransaction) {
270
- dbTransaction = await FinanceDb.getConnection().transaction();
271
- }
272
-
273
- const AR = await this.getAccountReceivable();
274
-
275
- const ledgerTransactions =
276
- await FinanceCustomerBase._LedgerTransactionRepository.findAll({
277
- where: {
278
- AccountNo: AR.AccountNo,
279
- },
280
- transaction: dbTransaction,
281
- });
282
-
283
- const totalDebitAmount = ledgerTransactions.reduce(
284
- (accumulator, currentValue) => accumulator + +currentValue.DebitAmount,
285
- 0,
286
- );
287
-
288
- const totalCreditAmount = ledgerTransactions.reduce(
289
- (accumulator, currentValue) => accumulator + +currentValue.CreditAmount,
290
- 0,
291
- );
292
-
293
- if (totalCreditAmount > totalDebitAmount) {
294
- return 0;
295
- }
296
-
297
- const balance = totalDebitAmount - totalCreditAmount;
298
- return balance;
299
- }
300
- }
1
+ import {
2
+ IAddress,
3
+ IRepositoryBase,
4
+ IPerson,
5
+ LoginUserBase,
6
+ } from '@tomei/general';
7
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
8
+ import FinanceCustomerModel from '../models/customer.entity';
9
+ import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
10
+ import { FinanceCustomerRepository } from './finance-customer.repository';
11
+ import * as cuid from 'cuid';
12
+ import Account from '../account/account';
13
+ import { AccountRepository } from '../account/account.repository';
14
+ import { type } from '../helpers/typeof';
15
+ import * as FinanceDb from '../database';
16
+ import { LedgerTransactionRepository } from '../ledger-transaction/ledger-transaction.repository';
17
+
18
+ // const AccountSystemEntity = import('../account-system-entity').then(({AccountSystemEntity}) => AccountSystemEntity);
19
+ export default abstract class FinanceCustomerBase
20
+ extends AccountSystemEntity
21
+ implements IPerson
22
+ {
23
+ CustomerId = 'New';
24
+ CustSystemCode = '';
25
+ CustSystemRefId = '';
26
+
27
+ protected abstract ParentARAccountNo: string;
28
+ protected abstract ParentAPAccountNo: string;
29
+ protected abstract ARAccountNo: string;
30
+ protected abstract APAccountNo: string;
31
+ protected abstract _ObjectType: string;
32
+
33
+ abstract FullName: string;
34
+ abstract IDNo: string;
35
+ abstract IDType: string;
36
+ abstract ContactNo: string;
37
+ abstract Email: string;
38
+ abstract DefaultAddress: IAddress;
39
+
40
+ private _AccountReceivable: Account;
41
+ private _AccountPayable: Account;
42
+
43
+ protected _DbTransaction: any;
44
+
45
+ private static _AccountRepository = new AccountRepository();
46
+ private static _LedgerTransactionRepository =
47
+ new LedgerTransactionRepository();
48
+
49
+ // note: getDetails from spec is void type. Meaning that this probably needed a fix soon
50
+ async getDetails(): Promise<{
51
+ FullName: string;
52
+ IDNo: string;
53
+ IDType: string;
54
+ Email: string;
55
+ ContactNo: string;
56
+ }> {
57
+ return {
58
+ FullName: this.FullName,
59
+ IDNo: this.IDNo,
60
+ IDType: this.IDType,
61
+ Email: this.Email,
62
+ ContactNo: this.ContactNo,
63
+ };
64
+ }
65
+
66
+ protected static _FinanceCustomerRepository = new FinanceCustomerRepository();
67
+ RepositoryBase: IRepositoryBase<any>;
68
+
69
+ constructor(
70
+ custSystemRefId?: string,
71
+ custSystemCode?: string,
72
+ sFinanceCompanyId?: string,
73
+ ) {
74
+ super();
75
+ if (custSystemRefId && custSystemCode && sFinanceCompanyId) {
76
+ this.CustSystemRefId = custSystemRefId;
77
+ this.CustSystemCode = custSystemCode;
78
+ this.CompanyId = sFinanceCompanyId;
79
+ }
80
+ }
81
+
82
+ public static async initCustomer<C extends FinanceCustomerBase>(
83
+ this: new () => C,
84
+ custSystemRefId: string,
85
+ custSystemCode: string,
86
+ sFinanceCompanyId: string,
87
+ dbTransaction?: any,
88
+ ): Promise<C> {
89
+ if (!dbTransaction) {
90
+ dbTransaction = await FinanceDb.getConnection().transaction();
91
+ }
92
+
93
+ const financeCustomerData =
94
+ await FinanceCustomerBase._FinanceCustomerRepository.findOne({
95
+ where: {
96
+ CompanyId: sFinanceCompanyId,
97
+ CustSystemCode: custSystemCode,
98
+ CustSystemRefId: custSystemRefId,
99
+ },
100
+ transaction: dbTransaction,
101
+ });
102
+ if (financeCustomerData) {
103
+ const self = new this();
104
+ self._DbTransaction = dbTransaction;
105
+ self.CustomerId = financeCustomerData.CustomerId;
106
+ self.CompanyId = sFinanceCompanyId;
107
+ self.CustSystemCode = custSystemCode;
108
+ self.CustSystemRefId = custSystemRefId;
109
+ self.AccSystemRefId = financeCustomerData.AccSystemRefId;
110
+ self.PostedToAccSystemYN = financeCustomerData.PostedToAccSystemYN;
111
+ self.PostedById = financeCustomerData.PostedById;
112
+ self.PostedDateTime = financeCustomerData.PostedDateTime;
113
+ return self;
114
+ } else {
115
+ const notFoundError = new RecordNotFoundError(
116
+ 'FinanceCustomerErrMsg',
117
+ 'No Record Found',
118
+ );
119
+ throw notFoundError;
120
+ }
121
+ }
122
+
123
+ async getAccountReceivable(): Promise<Account> {
124
+ try {
125
+ const transaction = this._DbTransaction;
126
+ if (this._AccountReceivable) {
127
+ return this._AccountReceivable;
128
+ } else {
129
+ const accountData =
130
+ await FinanceCustomerBase._AccountRepository.findOne({
131
+ where: {
132
+ AccountNo: this.ARAccountNo,
133
+ AccountType: 'Account Receivable',
134
+ OwnerId: this.CustomerId,
135
+ OwnerType: type(this),
136
+ },
137
+ transaction,
138
+ });
139
+ this._AccountReceivable = new Account(transaction);
140
+ if (accountData) {
141
+ this._AccountReceivable.AccountNo = accountData.AccountNo;
142
+ this._AccountReceivable.ParentAccountNo = accountData.ParentAccountNo;
143
+ this._AccountReceivable.AccountType = accountData.AccountType;
144
+ this._AccountReceivable.OwnerId = accountData.OwnerId;
145
+ this._AccountReceivable.OwnerType = accountData.OwnerType;
146
+ } else {
147
+ // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
148
+ // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
149
+ this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
150
+ this._AccountReceivable.ParentAccountNo = this.ParentARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR'
151
+ this._AccountReceivable.AccountType = 'Account Receivable';
152
+ this._AccountReceivable.OwnerId = this.CustomerId;
153
+ this._AccountReceivable.OwnerType = type(this);
154
+ }
155
+ return this._AccountReceivable;
156
+ }
157
+ } catch (error) {
158
+ throw error;
159
+ }
160
+ }
161
+
162
+ async getAccountPayable(): Promise<Account> {
163
+ try {
164
+ const transaction = this._DbTransaction;
165
+ if (this._AccountPayable) {
166
+ return this._AccountPayable;
167
+ } else {
168
+ const accountData =
169
+ await FinanceCustomerBase._AccountRepository.findOne({
170
+ where: {
171
+ AccountNo: this.APAccountNo,
172
+ AccountType: 'Account Payable',
173
+ OwnerId: this.CustomerId,
174
+ OwnerType: type(this),
175
+ },
176
+ transaction,
177
+ });
178
+
179
+ this._AccountPayable = new Account(transaction);
180
+ if (accountData) {
181
+ this._AccountPayable.AccountNo = accountData.AccountNo;
182
+ this._AccountPayable.ParentAccountNo = accountData.ParentAccountNo;
183
+ this._AccountPayable.AccountType = accountData.AccountType;
184
+ this._AccountPayable.OwnerId = accountData.OwnerId;
185
+ this._AccountPayable.OwnerType = accountData.OwnerType;
186
+ } else {
187
+ // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
188
+ // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
189
+ this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
190
+ this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
191
+ this._AccountPayable.AccountType = 'Account Payable';
192
+ this._AccountPayable.OwnerId = this.CustomerId;
193
+ this._AccountPayable.OwnerType = type(this);
194
+ }
195
+
196
+ return this._AccountPayable;
197
+ }
198
+ } catch (error) {
199
+ throw error;
200
+ }
201
+ }
202
+
203
+ /*
204
+ * Get the billing address for a person.
205
+ **/
206
+ abstract getBillingAddress(params: any): Promise<IAddress>;
207
+
208
+ init(person: LoginUserBase) {
209
+ this.FullName = person.FullName;
210
+ this.IDNo = person.IDNo;
211
+ this.IDType = person.IDType;
212
+ this.Email = person.Email;
213
+ this.ContactNo = person.ContactNo;
214
+ this.DefaultAddress = person.DefaultAddress;
215
+ }
216
+
217
+ async save(
218
+ accSystemRefId: string,
219
+ custSystemCode: string,
220
+ custSystemRefId: string,
221
+ dbTransaction?: any,
222
+ ): Promise<FinanceCustomerModel> {
223
+ this.CustSystemCode = custSystemCode;
224
+ this.CustSystemRefId = custSystemRefId;
225
+ this.AccSystemRefId = accSystemRefId;
226
+ this.PostedToAccSystemYN = 'Y';
227
+ const data = await FinanceCustomerBase._FinanceCustomerRepository.create(
228
+ {
229
+ CompanyId: this.CompanyId,
230
+ CustomerId: cuid(),
231
+ CustSystemCode: this.CustSystemCode,
232
+ CustSystemRefId: this.CustSystemRefId,
233
+ AccSystemRefId: this.AccSystemRefId,
234
+ PostedToAccSystemYN: this.PostedToAccSystemYN,
235
+ },
236
+ { transaction: dbTransaction },
237
+ );
238
+ return data;
239
+ }
240
+
241
+ static async isFinanceCustomerExist(
242
+ custSystemRefId: string,
243
+ custSystemCode: string,
244
+ sFinanceCompanyId: string,
245
+ dbTransaction?: any,
246
+ ): Promise<boolean> {
247
+ const data = await FinanceCustomerBase._FinanceCustomerRepository.findAll({
248
+ where: {
249
+ CustSystemRefId: custSystemRefId,
250
+ CustSystemCode: custSystemCode,
251
+ CompanyId: sFinanceCompanyId,
252
+ },
253
+ transaction: dbTransaction,
254
+ });
255
+
256
+ if (data.length > 0) {
257
+ return true;
258
+ }
259
+ return false;
260
+ }
261
+
262
+ /**
263
+ * Method to calculate and return the outstanding balance for customer receivable account
264
+ *
265
+ * @param dbTransaction
266
+ * @returns {number}
267
+ */
268
+ async getOutstandingBalance(dbTransaction: any): Promise<number> {
269
+ if (!dbTransaction) {
270
+ dbTransaction = await FinanceDb.getConnection().transaction();
271
+ }
272
+
273
+ const AR = await this.getAccountReceivable();
274
+
275
+ const ledgerTransactions =
276
+ await FinanceCustomerBase._LedgerTransactionRepository.findAll({
277
+ where: {
278
+ AccountNo: AR.AccountNo,
279
+ },
280
+ transaction: dbTransaction,
281
+ });
282
+
283
+ const totalDebitAmount = ledgerTransactions.reduce(
284
+ (accumulator, currentValue) => accumulator + +currentValue.DebitAmount,
285
+ 0,
286
+ );
287
+
288
+ const totalCreditAmount = ledgerTransactions.reduce(
289
+ (accumulator, currentValue) => accumulator + +currentValue.CreditAmount,
290
+ 0,
291
+ );
292
+
293
+ if (totalCreditAmount > totalDebitAmount) {
294
+ return 0;
295
+ }
296
+
297
+ const balance = totalDebitAmount - totalCreditAmount;
298
+ return balance;
299
+ }
300
+ }
@@ -1,13 +1,13 @@
1
- import { Injectable } from '@nestjs/common/decorators';
2
- import { RepositoryBase, IRepositoryBase } from '@tomei/general';
3
- import FinanceCustomerModel from '../models/customer.entity';
4
-
5
- @Injectable()
6
- export class FinanceCustomerRepository
7
- extends RepositoryBase<FinanceCustomerModel>
8
- implements IRepositoryBase<FinanceCustomerModel>
9
- {
10
- constructor() {
11
- super(FinanceCustomerModel);
12
- }
13
- }
1
+ import { Injectable } from '@nestjs/common/decorators';
2
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
3
+ import FinanceCustomerModel from '../models/customer.entity';
4
+
5
+ @Injectable()
6
+ export class FinanceCustomerRepository
7
+ extends RepositoryBase<FinanceCustomerModel>
8
+ implements IRepositoryBase<FinanceCustomerModel>
9
+ {
10
+ constructor() {
11
+ super(FinanceCustomerModel);
12
+ }
13
+ }
@@ -1,3 +1,3 @@
1
- export interface ICustomerRepository<T> {
2
- findOne?(options: any): Promise<T>;
3
- }
1
+ export interface ICustomerRepository<T> {
2
+ findOne?(options: any): Promise<T>;
3
+ }
@@ -1,10 +1,10 @@
1
- export interface IFinanceCustomerAttr {
2
- CustomerId: string;
3
- CompanyId: string;
4
- CustSystemCode: string;
5
- CustSystemRefId: string;
6
- AccSystemRefId: string;
7
- PostedToAccSystemYN: string;
8
- PostedById: string;
9
- PostedDateTime?: Date;
10
- }
1
+ export interface IFinanceCustomerAttr {
2
+ CustomerId: string;
3
+ CompanyId: string;
4
+ CustSystemCode: string;
5
+ CustSystemRefId: string;
6
+ AccSystemRefId: string;
7
+ PostedToAccSystemYN: string;
8
+ PostedById: string;
9
+ PostedDateTime?: Date;
10
+ }
@@ -1,4 +1,4 @@
1
- import { IRepositoryBase } from '@tomei/general';
2
- import FinanceCustomerModel from '../../models/customer.entity';
3
-
4
- export type IFinanceCustomerRepository = IRepositoryBase<FinanceCustomerModel>;
1
+ import { IRepositoryBase } from '@tomei/general';
2
+ import FinanceCustomerModel from '../../models/customer.entity';
3
+
4
+ export type IFinanceCustomerRepository = IRepositoryBase<FinanceCustomerModel>;