@tomei/finance 0.3.91 → 0.3.93

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.91",
3
+ "version": "0.3.93",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -201,13 +201,20 @@ export default class Account extends AccountSystemEntity {
201
201
  dbTransaction?: any,
202
202
  ): Promise<AccountModel> {
203
203
  this.AccSystemRefId = AccSystemRefId;
204
+ console.log('Account Save: Before AccountNo FindOne');
205
+
204
206
  let data = await this.RepositoryBase.findOne({
205
207
  where: {
206
208
  AccountNo: this.AccountNo,
207
209
  },
208
210
  transaction: dbTransaction,
209
211
  });
212
+ console.log('Account Save: After AccountNo FindOne');
213
+ console.log(data, '<><><><><> Account Data Result <><><><><><>');
214
+
210
215
  if (data) {
216
+ console.log('Account Save: THERE IS DATA FOUND');
217
+
211
218
  this.AccountNo = data.AccountNo;
212
219
  this.AccSystemRefId = data.AccSystemRefId;
213
220
  this.Name = data.Name;
@@ -223,6 +230,8 @@ export default class Account extends AccountSystemEntity {
223
230
  this.CreatedAt = data.CreatedAt;
224
231
  this.CreatedById = data.CreatedById;
225
232
  } else {
233
+ console.log('Account Save: THERE IS NO DATA FOUND');
234
+
226
235
  data = await this.RepositoryBase.create(
227
236
  {
228
237
  AccountNo: this.AccountNo,
@@ -244,8 +253,12 @@ export default class Account extends AccountSystemEntity {
244
253
  transaction: dbTransaction,
245
254
  },
246
255
  );
256
+
257
+ console.log(data, '<><><><><><><> DATA THAT GETS CREATED <><><><><><><>');
247
258
  }
248
259
 
260
+ console.log(data, 'Account Save: Account details returned');
261
+
249
262
  return data;
250
263
  }
251
264
  }
@@ -38,6 +38,8 @@ export default abstract class FinanceCustomerBase
38
38
  private _AccountReceivable: Account;
39
39
  private _AccountPayable: Account;
40
40
 
41
+ protected _DbTransaction: any;
42
+
41
43
  private static _AccountRepository = new AccountRepository();
42
44
 
43
45
  // note: getDetails from spec is void type. Meaning that this probably needed a fix soon
@@ -91,7 +93,12 @@ export default abstract class FinanceCustomerBase
91
93
  custSystemRefId: string,
92
94
  custSystemCode: string,
93
95
  sFinanceCompanyId: string,
96
+ dbTransaction?: any,
94
97
  ): Promise<C> {
98
+ if (!dbTransaction) {
99
+ dbTransaction = await FinanceDb.getConnection().transaction();
100
+ }
101
+
95
102
  const financeCustomerData =
96
103
  await FinanceCustomerBase._FinanceCustomerRepository.findOne({
97
104
  where: {
@@ -99,9 +106,11 @@ export default abstract class FinanceCustomerBase
99
106
  CustSystemCode: custSystemCode,
100
107
  CustSystemRefId: custSystemRefId,
101
108
  },
109
+ transaction: dbTransaction,
102
110
  });
103
111
  if (financeCustomerData) {
104
112
  const self = new this();
113
+ self._DbTransaction = dbTransaction;
105
114
  self.CustomerId = financeCustomerData.CustomerId;
106
115
  self.CompanyId = sFinanceCompanyId;
107
116
  self.CustSystemCode = custSystemCode;
@@ -119,90 +128,101 @@ export default abstract class FinanceCustomerBase
119
128
 
120
129
  get AccountReceivable(): Promise<Account> {
121
130
  return new Promise((resolve, reject) => {
122
- let transaction;
131
+ let transaction = this._DbTransaction;
123
132
  if (this._AccountReceivable) {
124
133
  resolve(this._AccountReceivable);
125
134
  } else {
126
- FinanceDb.getConnection()
127
- .transaction()
128
- .then((t) => {
129
- transaction = t;
130
- return FinanceCustomerBase._AccountRepository.findOne({
135
+ // FinanceDb.getConnection()
136
+ // .transaction()
137
+ // transaction
138
+ // .then((t) => {
139
+ // transaction = t;
140
+ return (
141
+ FinanceCustomerBase._AccountRepository
142
+ .findOne({
131
143
  where: {
132
144
  AccountType: 'Account Receivable',
133
145
  OwnerId: this.CustomerId,
134
146
  OwnerType: type(this),
135
147
  },
136
- });
137
- })
138
- .then((accountData) => {
139
- this._AccountReceivable = new Account(transaction);
140
- if (accountData) {
141
- this._AccountReceivable.AccountNo = accountData.AccountNo;
142
- this._AccountReceivable.ParentAccountNo =
143
- accountData.ParentAccountNo;
144
- this._AccountReceivable.AccountType = accountData.AccountType;
145
- this._AccountReceivable.OwnerId = accountData.OwnerId;
146
- this._AccountReceivable.OwnerType = accountData.OwnerType;
147
- } else {
148
- // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
149
- // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
150
- this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
151
- this._AccountReceivable.ParentAccountNo = this.ParentARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR'
152
- this._AccountReceivable.AccountType = 'Account Receivable';
153
- this._AccountReceivable.OwnerId = this.CustomerId;
154
- this._AccountReceivable.OwnerType = type(this);
155
- }
156
- resolve(this._AccountReceivable);
157
- })
158
- .catch((err) => {
159
- reject(err);
160
- });
148
+ transaction,
149
+ })
150
+ // })
151
+ .then((accountData) => {
152
+ this._AccountReceivable = new Account(transaction);
153
+ if (accountData) {
154
+ this._AccountReceivable.AccountNo = accountData.AccountNo;
155
+ this._AccountReceivable.ParentAccountNo =
156
+ accountData.ParentAccountNo;
157
+ this._AccountReceivable.AccountType = accountData.AccountType;
158
+ this._AccountReceivable.OwnerId = accountData.OwnerId;
159
+ this._AccountReceivable.OwnerType = accountData.OwnerType;
160
+ } else {
161
+ // this._AccountReceivable.AccountNo = `${this.CustSystemCode}-AR-123456789`;
162
+ // this._AccountReceivable.ParentAccountNo = `${this.CustSystemCode}-AR`;
163
+ this._AccountReceivable.AccountNo = this.ARAccountNo; //SystemInfo.SYSTEM_CODE + '-AR-' + '8 digit running no'
164
+ this._AccountReceivable.ParentAccountNo =
165
+ 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
+ resolve(this._AccountReceivable);
171
+ })
172
+ .catch((err) => {
173
+ reject(err);
174
+ })
175
+ );
161
176
  }
162
177
  });
163
178
  }
164
179
 
165
180
  get AccountPayable(): Promise<Account> {
166
181
  return new Promise((resolve, reject) => {
167
- let transaction;
182
+ let transaction = this._DbTransaction;
168
183
  if (this._AccountPayable) {
169
184
  resolve(this._AccountPayable);
170
185
  } else {
171
- FinanceDb.getConnection()
172
- .transaction()
173
- .then((t) => {
174
- transaction = t;
175
- return FinanceCustomerBase._AccountRepository.findOne({
186
+ // FinanceDb.getConnection()
187
+ // .transaction()
188
+ // transaction
189
+ // .then((t) => {
190
+ // transaction = t;
191
+ return (
192
+ FinanceCustomerBase._AccountRepository
193
+ .findOne({
176
194
  where: {
177
195
  AccountType: 'Account Payable',
178
196
  OwnerId: this.CustomerId,
179
197
  OwnerType: type(this),
180
198
  },
181
- });
182
- })
183
- .then((accountData) => {
184
- this._AccountPayable = new Account(transaction);
185
- if (accountData) {
186
- this._AccountPayable.AccountNo = accountData.AccountNo;
187
- this._AccountPayable.ParentAccountNo =
188
- accountData.ParentAccountNo;
189
- this._AccountPayable.AccountType = accountData.AccountType;
190
- this._AccountPayable.OwnerId = accountData.OwnerId;
191
- this._AccountPayable.OwnerType = accountData.OwnerType;
192
- } else {
193
- // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
194
- // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
195
- this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
196
- this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
197
- this._AccountPayable.AccountType = 'Account Payable';
198
- this._AccountPayable.OwnerId = this.CustomerId;
199
- this._AccountPayable.OwnerType = type(this);
200
- }
201
- resolve(this._AccountPayable);
202
- })
203
- .catch((err) => {
204
- reject(err);
205
- });
199
+ transaction,
200
+ })
201
+ // })
202
+ .then((accountData) => {
203
+ this._AccountPayable = new Account(transaction);
204
+ if (accountData) {
205
+ this._AccountPayable.AccountNo = accountData.AccountNo;
206
+ this._AccountPayable.ParentAccountNo =
207
+ accountData.ParentAccountNo;
208
+ this._AccountPayable.AccountType = accountData.AccountType;
209
+ this._AccountPayable.OwnerId = accountData.OwnerId;
210
+ this._AccountPayable.OwnerType = accountData.OwnerType;
211
+ } else {
212
+ // this._AccountPayable.AccountNo = `${this.CustSystemCode}-AP-123456789`;
213
+ // this._AccountPayable.ParentAccountNo = `${this.CustSystemCode}-AP`;
214
+ this._AccountPayable.AccountNo = this.APAccountNo; //SystemInfo.SYSTEM_CODE + '-AP-' + '8 digit running no'
215
+ this._AccountPayable.ParentAccountNo = this.ParentAPAccountNo; //SystemInfo.SYSTEM_CODE + '-AP'
216
+ this._AccountPayable.AccountType = 'Account Payable';
217
+ this._AccountPayable.OwnerId = this.CustomerId;
218
+ this._AccountPayable.OwnerType = type(this);
219
+ }
220
+ resolve(this._AccountPayable);
221
+ })
222
+ .catch((err) => {
223
+ reject(err);
224
+ })
225
+ );
206
226
  }
207
227
  });
208
228
  }
@@ -429,10 +429,20 @@ export default class FinanceCompany extends ObjectBase {
429
429
  };
430
430
  }
431
431
 
432
+ console.log(
433
+ 'Finance Company Create Account: Before accSystemAccountId Create',
434
+ );
435
+
432
436
  const accSystemAccountId = await this.AccountingSystem.createAccount(
433
437
  createAccountPayload,
434
438
  );
439
+
440
+ console.log(
441
+ 'Finance Company Create Account: After accSystemAccountId Create',
442
+ );
443
+
435
444
  account.PostedToAccSystemYN = 'Y';
445
+ console.log('Finance Company Create Account: Before new Account Create');
436
446
  const newAccount = await account.save(
437
447
  this.CompanyId,
438
448
  accSystemAccountId,
@@ -440,6 +450,8 @@ export default class FinanceCompany extends ObjectBase {
440
450
  dbTransaction,
441
451
  );
442
452
 
453
+ console.log('Finance Company Create Account: After new Account Create');
454
+
443
455
  const payload = {
444
456
  Action: 'Create',
445
457
  Activity: 'Account Created',