@tomei/finance 0.3.6 → 0.3.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -46,26 +46,28 @@ export default abstract class FinanceCustomerBase
46
46
  RepositoryBase: IRepositoryBase<any>;
47
47
 
48
48
  constructor(
49
- custSystemRefId: string,
50
- custSystemCode: string,
51
- sFinanceCompanyId: string,
49
+ custSystemRefId?: string,
50
+ custSystemCode?: string,
51
+ sFinanceCompanyId?: string,
52
52
  ) {
53
53
  super();
54
- const financeCustomerData =
55
- FinanceCustomerBase._FinanceCustomerRepository.findOne({
56
- where: {
57
- CompanyId: sFinanceCompanyId,
58
- CustSystemCode: custSystemCode,
59
- CustSystemRefId: custSystemRefId,
60
- },
61
- });
62
- if (financeCustomerData) {
63
- this.CompanyId = sFinanceCompanyId;
64
- this.CustSystemCode = custSystemCode;
65
- this.CustSystemRefId = custSystemRefId;
66
- } else {
67
- const notFoundError = new RecordNotFoundError('No Record Found');
68
- throw notFoundError;
54
+ if (custSystemRefId && custSystemCode && sFinanceCompanyId) {
55
+ const financeCustomerData =
56
+ FinanceCustomerBase._FinanceCustomerRepository.findOne({
57
+ where: {
58
+ CompanyId: sFinanceCompanyId,
59
+ CustSystemCode: custSystemCode,
60
+ CustSystemRefId: custSystemRefId,
61
+ },
62
+ });
63
+ if (financeCustomerData) {
64
+ this.CompanyId = sFinanceCompanyId;
65
+ this.CustSystemCode = custSystemCode;
66
+ this.CustSystemRefId = custSystemRefId;
67
+ } else {
68
+ const notFoundError = new RecordNotFoundError('No Record Found');
69
+ throw notFoundError;
70
+ }
69
71
  }
70
72
  }
71
73
 
@@ -85,8 +87,12 @@ export default abstract class FinanceCustomerBase
85
87
 
86
88
  async save(
87
89
  customerId: string,
90
+ custSystemCode: string,
91
+ custSystemRefId: string,
88
92
  dbTransaction?: any,
89
93
  ): Promise<FinanceCustomerModel> {
94
+ this.CustSystemCode = custSystemCode;
95
+ this.CustSystemRefId = custSystemRefId;
90
96
  const data = await FinanceCustomerBase._FinanceCustomerRepository.create(
91
97
  {
92
98
  CustomerId: customerId,
@@ -36,10 +36,10 @@ export default class FinanceCompany extends ObjectBase {
36
36
  private static _PaymentItemRepository = new PaymentItemRepository();
37
37
  private static _DocumentRepository = new DocumentRepository();
38
38
  private static _DocumentItemRepository = new DocumentItemRepository();
39
-
40
- financeCustomerRepository: FinanceCustomerRepository;
41
- ledgerTransactionRepository: LedgerTransactionRepository;
42
- AccountingSystem: IAccountSystem;
39
+ private static _FinanceCustomerRepository = new FinanceCustomerRepository();
40
+ private static _LedgerTransactionRepository =
41
+ new LedgerTransactionRepository();
42
+ private _AccountingSystem: IAccountSystem;
43
43
 
44
44
  get CompSystemCode(): string {
45
45
  return this._CompSystemCode;
@@ -85,6 +85,14 @@ export default class FinanceCompany extends ObjectBase {
85
85
  return 'finance_Company';
86
86
  }
87
87
 
88
+ get AccountingSystem(): IAccountSystem {
89
+ return this._AccountingSystem;
90
+ }
91
+
92
+ set AccountingSystem(system: IAccountSystem) {
93
+ this._AccountingSystem = system;
94
+ }
95
+
88
96
  constructor(
89
97
  compSystemCode: string,
90
98
  compSystemRefId: string,
@@ -165,6 +173,7 @@ export default class FinanceCompany extends ObjectBase {
165
173
 
166
174
  /*Retrieve and store the CompanyId from the result*/
167
175
  financeCompany.ObjectId = company.CompanyId;
176
+ financeCompany._CompanyId = company.CompanyId;
168
177
 
169
178
  /*Add the details into the hashtable*/
170
179
  const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
@@ -246,15 +255,14 @@ export default class FinanceCompany extends ObjectBase {
246
255
  );
247
256
  }
248
257
 
249
- const financeCustomerData = await this.financeCustomerRepository.findOne({
250
- where: {
251
- /*todo:verify SystemCode*/
252
- // SystemCode: this.SystemCode,
253
- AccSystemCode: this.AccSystemCode,
254
- AccSystemCustomerId: custSystemCode,
255
- CustomerRefId: custSystemRefId,
256
- },
257
- });
258
+ const financeCustomerData =
259
+ await FinanceCompany._FinanceCustomerRepository.findOne({
260
+ where: {
261
+ CompanyId: this._CompanyId,
262
+ CustSystemCode: custSystemCode,
263
+ CustSystemRefId: custSystemRefId,
264
+ },
265
+ });
258
266
 
259
267
  if (financeCustomerData) {
260
268
  throw new Error('Customer already created previously.');
@@ -265,7 +273,12 @@ export default class FinanceCompany extends ObjectBase {
265
273
  customer,
266
274
  });
267
275
 
268
- const newCustomer = await customer.save(customerId, dbTransaction);
276
+ const newCustomer = await customer.save(
277
+ customerId,
278
+ custSystemCode,
279
+ custSystemRefId,
280
+ dbTransaction,
281
+ );
269
282
 
270
283
  const payload = {
271
284
  Action: 'Create',
@@ -315,7 +328,7 @@ export default class FinanceCompany extends ObjectBase {
315
328
  const newJournalEntry = await journalEntry.save('test', dbTransaction);
316
329
 
317
330
  const allLedgerTransactions =
318
- await this.ledgerTransactionRepository.findAll({});
331
+ await FinanceCompany._LedgerTransactionRepository.findAll({});
319
332
 
320
333
  for (const ledgerTransaction of allLedgerTransactions) {
321
334
  ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;