@tomei/finance 0.5.6 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -35,12 +35,12 @@
35
35
  "@nestjs/platform-express": "^9.0.8",
36
36
  "@nestjs/sequelize": "^9.0.0",
37
37
  "@nestjs/swagger": "^6.1.4",
38
- "@tomei/general": "^0.0.26",
38
+ "@tomei/general": "^0.5.1",
39
39
  "@tomei/media": "^0.4.2",
40
40
  "axios": "^1.1.3",
41
41
  "class-transformer": "^0.5.1",
42
42
  "class-validator": "^0.13.2",
43
- "cuid": "^2.1.8",
43
+ "cuid": "^3.0.0",
44
44
  "dotenv": "^16.0.3",
45
45
  "intuit-oauth": "^4.0.0",
46
46
  "mariadb": "^3.0.2",
@@ -57,7 +57,7 @@
57
57
  "eslint": "^8.21.0",
58
58
  "eslint-config-prettier": "^8.5.0",
59
59
  "eslint-plugin-prettier": "^4.2.1",
60
- "husky": "^7.0.2",
60
+ "husky": "^8.0.3",
61
61
  "lint-staged": "^11.1.2",
62
62
  "mariadb": "^3.0.2",
63
63
  "prettier": "^2.7.1",
@@ -75,5 +75,9 @@
75
75
  "npm run build",
76
76
  "git add ."
77
77
  ]
78
+ },
79
+ "dependencies": {
80
+ "@tomei/activity-history": "^0.2.1",
81
+ "@tomei/sso": "^0.11.6"
78
82
  }
79
83
  }
@@ -1,4 +1,4 @@
1
- import { RecordNotFoundError } from '@tomei/general';
1
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
2
2
  import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
3
3
  import AccountModel from '../models/account.entity';
4
4
  import { AccountRepository } from './account.repository';
@@ -87,7 +87,10 @@ export default class Account extends AccountSystemEntity {
87
87
  this.PostedById = accountData.PostedById;
88
88
  this.PostedDateTime = accountData.PostedDateTime;
89
89
  } else {
90
- const notFoundError = new RecordNotFoundError('No Record Found.');
90
+ const notFoundError = new RecordNotFoundError(
91
+ 'AccountErrMsg',
92
+ 'No Record Found.',
93
+ );
91
94
  throw notFoundError;
92
95
  }
93
96
  })
@@ -136,7 +139,10 @@ export default class Account extends AccountSystemEntity {
136
139
  account.init(accountData.get({ plain: true }));
137
140
  return account;
138
141
  } else {
139
- const notFoundError = new RecordNotFoundError('No Record Found.');
142
+ const notFoundError = new RecordNotFoundError(
143
+ 'AccountErrMsg',
144
+ 'No Record Found.',
145
+ );
140
146
  throw notFoundError;
141
147
  }
142
148
  } catch (error) {
@@ -3,8 +3,8 @@ import {
3
3
  IRepositoryBase,
4
4
  IPerson,
5
5
  LoginUserBase,
6
- RecordNotFoundError,
7
6
  } from '@tomei/general';
7
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
8
8
  import FinanceCustomerModel from '../models/customer.entity';
9
9
  import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
10
10
  import { FinanceCustomerRepository } from './finance-customer.repository';
@@ -85,7 +85,10 @@ export default abstract class FinanceCustomerBase
85
85
  this.CustSystemCode = custSystemCode;
86
86
  this.CustSystemRefId = custSystemRefId;
87
87
  } else {
88
- const notFoundError = new RecordNotFoundError('No Record Found');
88
+ const notFoundError = new RecordNotFoundError(
89
+ 'FinanceCustomerErrMsg',
90
+ 'No Record Found',
91
+ );
89
92
  throw notFoundError;
90
93
  }
91
94
  }
@@ -124,102 +127,92 @@ export default abstract class FinanceCustomerBase
124
127
  self.PostedDateTime = financeCustomerData.PostedDateTime;
125
128
  return self;
126
129
  } else {
127
- const notFoundError = new RecordNotFoundError('No Record Found');
130
+ const notFoundError = new RecordNotFoundError(
131
+ 'FinanceCustomerErrMsg',
132
+ 'No Record Found',
133
+ );
128
134
  throw notFoundError;
129
135
  }
130
136
  }
131
137
 
132
- get AccountReceivable(): Promise<Account> {
133
- return new Promise((resolve, reject) => {
138
+ async getAccountReceivable(): Promise<Account> {
139
+ try {
134
140
  const transaction = this._DbTransaction;
135
141
  if (this._AccountReceivable) {
136
- resolve(this._AccountReceivable);
142
+ return this._AccountReceivable;
137
143
  } else {
138
- return (
139
- FinanceCustomerBase._AccountRepository
140
- .findOne({
141
- where: {
142
- AccountNo: this.ARAccountNo,
143
- AccountType: 'Account Receivable',
144
- OwnerId: this.CustomerId,
145
- OwnerType: type(this),
146
- },
147
- transaction,
148
- })
149
- // })
150
- .then((accountData) => {
151
- this._AccountReceivable = new Account(transaction);
152
- if (accountData) {
153
- this._AccountReceivable.AccountNo = accountData.AccountNo;
154
- this._AccountReceivable.ParentAccountNo =
155
- accountData.ParentAccountNo;
156
- this._AccountReceivable.AccountType = accountData.AccountType;
157
- this._AccountReceivable.OwnerId = accountData.OwnerId;
158
- this._AccountReceivable.OwnerType = accountData.OwnerType;
159
- } else {
160
- // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
161
- // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
162
- this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
163
- this._AccountReceivable.ParentAccountNo =
164
- this.ParentARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR'
165
- this._AccountReceivable.AccountType = 'Account Receivable';
166
- this._AccountReceivable.OwnerId = this.CustomerId;
167
- this._AccountReceivable.OwnerType = type(this);
168
- }
169
- resolve(this._AccountReceivable);
170
- })
171
- .catch((err) => {
172
- reject(err);
173
- })
174
- );
144
+ const accountData =
145
+ await FinanceCustomerBase._AccountRepository.findOne({
146
+ where: {
147
+ AccountNo: this.ARAccountNo,
148
+ AccountType: 'Account Receivable',
149
+ OwnerId: this.CustomerId,
150
+ OwnerType: type(this),
151
+ },
152
+ transaction,
153
+ });
154
+ this._AccountReceivable = new Account(transaction);
155
+ if (accountData) {
156
+ this._AccountReceivable.AccountNo = accountData.AccountNo;
157
+ this._AccountReceivable.ParentAccountNo = accountData.ParentAccountNo;
158
+ this._AccountReceivable.AccountType = accountData.AccountType;
159
+ this._AccountReceivable.OwnerId = accountData.OwnerId;
160
+ this._AccountReceivable.OwnerType = accountData.OwnerType;
161
+ } else {
162
+ // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
163
+ // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
164
+ this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
165
+ this._AccountReceivable.ParentAccountNo = this.ParentARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR'
166
+ this._AccountReceivable.AccountType = 'Account Receivable';
167
+ this._AccountReceivable.OwnerId = this.CustomerId;
168
+ this._AccountReceivable.OwnerType = type(this);
169
+ }
170
+ return this._AccountReceivable;
175
171
  }
176
- });
172
+ } catch (error) {
173
+ throw error;
174
+ }
177
175
  }
178
176
 
179
- get AccountPayable(): Promise<Account> {
180
- return new Promise((resolve, reject) => {
177
+ async getAccountPayable(): Promise<Account> {
178
+ try {
181
179
  const transaction = this._DbTransaction;
182
180
  if (this._AccountPayable) {
183
- resolve(this._AccountPayable);
181
+ return this._AccountPayable;
184
182
  } else {
185
- return (
186
- FinanceCustomerBase._AccountRepository
187
- .findOne({
188
- where: {
189
- AccountNo: this.APAccountNo,
190
- AccountType: 'Account Payable',
191
- OwnerId: this.CustomerId,
192
- OwnerType: type(this),
193
- },
194
- transaction,
195
- })
196
- // })
197
- .then((accountData) => {
198
- this._AccountPayable = new Account(transaction);
199
- if (accountData) {
200
- this._AccountPayable.AccountNo = accountData.AccountNo;
201
- this._AccountPayable.ParentAccountNo =
202
- accountData.ParentAccountNo;
203
- this._AccountPayable.AccountType = accountData.AccountType;
204
- this._AccountPayable.OwnerId = accountData.OwnerId;
205
- this._AccountPayable.OwnerType = accountData.OwnerType;
206
- } else {
207
- // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
208
- // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
209
- this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
210
- this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
211
- this._AccountPayable.AccountType = 'Account Payable';
212
- this._AccountPayable.OwnerId = this.CustomerId;
213
- this._AccountPayable.OwnerType = type(this);
214
- }
215
- resolve(this._AccountPayable);
216
- })
217
- .catch((err) => {
218
- reject(err);
219
- })
220
- );
183
+ const accountData =
184
+ await FinanceCustomerBase._AccountRepository.findOne({
185
+ where: {
186
+ AccountNo: this.APAccountNo,
187
+ AccountType: 'Account Payable',
188
+ OwnerId: this.CustomerId,
189
+ OwnerType: type(this),
190
+ },
191
+ transaction,
192
+ });
193
+
194
+ this._AccountPayable = new Account(transaction);
195
+ if (accountData) {
196
+ this._AccountPayable.AccountNo = accountData.AccountNo;
197
+ this._AccountPayable.ParentAccountNo = accountData.ParentAccountNo;
198
+ this._AccountPayable.AccountType = accountData.AccountType;
199
+ this._AccountPayable.OwnerId = accountData.OwnerId;
200
+ this._AccountPayable.OwnerType = accountData.OwnerType;
201
+ } else {
202
+ // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
203
+ // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
204
+ this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
205
+ this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
206
+ this._AccountPayable.AccountType = 'Account Payable';
207
+ this._AccountPayable.OwnerId = this.CustomerId;
208
+ this._AccountPayable.OwnerType = type(this);
209
+ }
210
+
211
+ return this._AccountPayable;
221
212
  }
222
- });
213
+ } catch (error) {
214
+ throw error;
215
+ }
223
216
  }
224
217
 
225
218
  /*
@@ -290,7 +283,7 @@ export default abstract class FinanceCustomerBase
290
283
  dbTransaction = await FinanceDb.getConnection().transaction();
291
284
  }
292
285
 
293
- const AR = await this.AccountReceivable;
286
+ const AR = await this.getAccountReceivable();
294
287
 
295
288
  const ledgerTransactions =
296
289
  await FinanceCustomerBase._LedgerTransactionRepository.findAll({
@@ -1,7 +1,7 @@
1
1
  import * as util from 'util';
2
2
  import * as fs from 'fs';
3
3
  import * as puppeteer from 'puppeteer';
4
- import { RecordNotFoundError } from '@tomei/general';
4
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
5
5
  import {
6
6
  Medias,
7
7
  InternalMediaDto,
@@ -167,7 +167,10 @@ export default class Document extends AccountSystemEntity {
167
167
  this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
168
168
  this.IsNewRecord = false;
169
169
  } else {
170
- const notFoundError = new RecordNotFoundError('No Record Found.');
170
+ const notFoundError = new RecordNotFoundError(
171
+ 'FinanceDocumentErrMsg',
172
+ 'No Record Found.',
173
+ );
171
174
  throw notFoundError;
172
175
  }
173
176
  })
@@ -212,7 +215,10 @@ export default class Document extends AccountSystemEntity {
212
215
  document.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
213
216
  document.IsNewRecord = false;
214
217
  } else {
215
- const notFoundError = new RecordNotFoundError('No Record Found.');
218
+ const notFoundError = new RecordNotFoundError(
219
+ 'FinanceDocumentErrMsg',
220
+ 'No Record Found.',
221
+ );
216
222
  throw notFoundError;
217
223
  }
218
224
  return document;
@@ -34,6 +34,8 @@ import { PaymentPaidWithRepository } from '../payment-paid-with/payment-paid-wit
34
34
  import { MediasModel } from '@tomei/media';
35
35
  import DocumentItem from '../document/document-item';
36
36
  import { type } from '../helpers/typeof';
37
+ import { LoginUser } from '@tomei/sso';
38
+ import { ActionEnum, Activity } from '@tomei/activity-history';
37
39
 
38
40
  // eslint-disable-next-line @typescript-eslint/no-var-requires
39
41
  const getConfig = require('../config');
@@ -278,7 +280,7 @@ export default class FinanceCompany extends ObjectBase {
278
280
  custSystemCode: string,
279
281
  custSystemRefId: string,
280
282
  customer: FinanceCustomerBase,
281
- loginUser: LoginUserBase,
283
+ loginUser: LoginUser,
282
284
  ) {
283
285
  try {
284
286
  if (!custSystemCode || !custSystemRefId) {
@@ -314,22 +316,15 @@ export default class FinanceCompany extends ObjectBase {
314
316
  dbTransaction,
315
317
  );
316
318
 
317
- const payload = {
318
- Action: 'Create',
319
- Activity: 'Finance Customer Created',
320
- Description: `Customer (ID: ${newCustomer.CustomerId}) has been created for ${this.AccSystemCode}`,
321
- EntityType: 'finance_Customer',
322
- EntityValueBefore: JSON.stringify({}),
323
- EntityValueAfter: JSON.stringify(newCustomer),
324
- PerformedById: loginUser.ObjectId,
325
- PerformedAt: new Date(),
326
- EntityId: newCustomer.CustomerId,
327
- };
319
+ const activity = new Activity();
320
+ activity.Action = ActionEnum.ADD;
321
+ activity.Description = 'Add Finance Customer';
322
+ activity.EntityType = 'FinanceCustomer';
323
+ activity.EntityId = newCustomer.CustomerId;
324
+ activity.EntityValueBefore = JSON.stringify({});
325
+ activity.EntityValueAfter = JSON.stringify(newCustomer);
328
326
 
329
- await axios.post(
330
- `${process.env.COMMON_API_URL}/activity-histories`,
331
- payload,
332
- );
327
+ await activity.create(loginUser, dbTransaction);
333
328
 
334
329
  return customer;
335
330
  } catch (error) {
@@ -680,7 +675,8 @@ export default class FinanceCompany extends ObjectBase {
680
675
  dt.AccountNo = dtAccountNo;
681
676
  } else {
682
677
  /*Transacting based on default customer AR account*/
683
- dt.AccountNo = (await customer.AccountReceivable).AccountNo;
678
+ const arAccount = await customer.getAccountReceivable();
679
+ dt.AccountNo = arAccount.AccountNo;
684
680
  }
685
681
 
686
682
  dt.Currency = currency ? currency : 'MYR';
@@ -895,7 +891,8 @@ export default class FinanceCompany extends ObjectBase {
895
891
  dt.AccountNo = dtAccountNo;
896
892
  } else {
897
893
  /*Transacting based on default customer AR account*/
898
- dt.AccountNo = (await customer.AccountReceivable).AccountNo;
894
+ const arAccount = await customer.getAccountReceivable();
895
+ dt.AccountNo = arAccount.AccountNo;
899
896
  }
900
897
 
901
898
  dt.Currency = currency ? currency : 'MYR';
@@ -1401,7 +1398,8 @@ export default class FinanceCompany extends ObjectBase {
1401
1398
  if (ctAccountNo) {
1402
1399
  creditLT.AccountNo = ctAccountNo;
1403
1400
  } else {
1404
- creditLT.AccountNo = (await customer.AccountReceivable).AccountNo;
1401
+ const arAccount = await customer.getAccountReceivable();
1402
+ creditLT.AccountNo = arAccount.AccountNo;
1405
1403
  }
1406
1404
  creditLT.Currency = paymentPaidWith.Currency;
1407
1405
  creditLT.CreditAmount = paymentPaidWith.Amount;
@@ -1562,7 +1560,8 @@ export default class FinanceCompany extends ObjectBase {
1562
1560
  if (dtAccountNo) {
1563
1561
  debitLT.AccountNo = dtAccountNo;
1564
1562
  } else {
1565
- debitLT.AccountNo = (await customer.AccountPayable).AccountNo;
1563
+ const apAccount = await customer.getAccountPayable();
1564
+ debitLT.AccountNo = apAccount.AccountNo;
1566
1565
  }
1567
1566
  debitLT.Currency = paymentPaidWithItem.Currency;
1568
1567
  debitLT.DebitAmount = paymentPaidWithItem.Amount;
@@ -6,7 +6,7 @@ import { AccountSystemEntity } from '../account-system-entity/account-system-ent
6
6
  import { LedgerTransactionRepository } from '../ledger-transaction/ledger-transaction.repository';
7
7
  import LedgerTransaction from '../ledger-transaction/ledger-transaction';
8
8
  import { JournalEntryRepository } from './journal-entry.repository';
9
- import { RecordNotFoundError } from '@tomei/general';
9
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
10
10
 
11
11
  export default class JournalEntry extends AccountSystemEntity {
12
12
  private _JournalEntryId = 'New';
@@ -69,7 +69,10 @@ export default class JournalEntry extends AccountSystemEntity {
69
69
  this.PostedById = journalEntryData.PostedById;
70
70
  this.PostedDateTime = journalEntryData.PostedDateTime;
71
71
  } else {
72
- const notFoundError = new RecordNotFoundError('No Record Found.');
72
+ const notFoundError = new RecordNotFoundError(
73
+ 'JournalEntryErrMsg',
74
+ 'No Record Found.',
75
+ );
73
76
  throw notFoundError;
74
77
  }
75
78
  })
@@ -1,4 +1,5 @@
1
- import { ObjectBase, RecordNotFoundError } from '@tomei/general';
1
+ import { ObjectBase } from '@tomei/general';
2
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
2
3
  import { PaymentType } from '../enum';
3
4
  import { IPaymentParams } from './interfaces/payment-params.interface';
4
5
  import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
@@ -111,7 +112,10 @@ export default class Payment extends AccountSystemEntity {
111
112
  payment.PostedDateTime = paymentData.PostedDateTime;
112
113
  return payment;
113
114
  } else {
114
- const notFoundError = new RecordNotFoundError('No Record Found.');
115
+ const notFoundError = new RecordNotFoundError(
116
+ 'PaymentErrMsg',
117
+ 'No Record Found.',
118
+ );
115
119
  throw notFoundError;
116
120
  }
117
121
  } catch (error) {
@@ -1,4 +1,5 @@
1
- import { ObjectBase, RecordNotFoundError } from '@tomei/general';
1
+ import { ObjectBase } from '@tomei/general';
2
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
2
3
  import { PaymentMethodRepository } from './payment-method.repository';
3
4
  import PaymentMethodType from '../payment-method-type/payment-method-type';
4
5
  import { PaymentMethodTypeRepository } from '../payment-method-type/payment-method-type.repository';
@@ -34,7 +35,10 @@ export default class PaymentMethod extends ObjectBase {
34
35
  if (methodData) {
35
36
  this.Name = methodData.Name;
36
37
  } else {
37
- throw new RecordNotFoundError('No record found.');
38
+ throw new RecordNotFoundError(
39
+ 'PaymentMethodErrMsg',
40
+ 'No record found.',
41
+ );
38
42
  }
39
43
  })
40
44
  .catch((err) => {
@@ -1,4 +1,5 @@
1
- import { ObjectBase, RecordNotFoundError } from '@tomei/general';
1
+ import { ObjectBase } from '@tomei/general';
2
+ import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
2
3
  import { PaymentMethodTypeRepository } from './payment-method-type.repository';
3
4
 
4
5
  export default class PaymentMethodType extends ObjectBase {
@@ -47,7 +48,10 @@ export default class PaymentMethodType extends ObjectBase {
47
48
  paymentMethodTypeData.ProcessingFeeAccountNo;
48
49
  return paymentMethodType;
49
50
  } else {
50
- const notFoundError = new RecordNotFoundError('No Record Found.');
51
+ const notFoundError = new RecordNotFoundError(
52
+ 'PaymentMethodTypeErrMsg',
53
+ 'No Record Found.',
54
+ );
51
55
  throw notFoundError;
52
56
  }
53
57
  } catch (error) {