@tomei/finance 0.6.98 → 0.6.99

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