@tomei/finance 0.3.87 → 0.3.89

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.87",
3
+ "version": "0.3.89",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -201,27 +201,51 @@ export default class Account extends AccountSystemEntity {
201
201
  dbTransaction?: any,
202
202
  ): Promise<AccountModel> {
203
203
  this.AccSystemRefId = AccSystemRefId;
204
- const data = await this.RepositoryBase.create(
205
- {
204
+ const data = await this.RepositoryBase.findOne({
205
+ where: {
206
206
  AccountNo: this.AccountNo,
207
- AccSystemRefId: this.AccSystemRefId,
208
- Name: this.Name,
209
- Description: this.Description,
210
- AccountType: this.AccountType,
211
- AccountSubtype: this.AccountSubtype,
212
- CompanyId: CompanyId,
213
- OwnerId: this.OwnerId,
214
- OwnerType: this.OwnerType,
215
- RelatedObjectId: this.RelatedObjectId,
216
- RelatedObjectType: this.RelatedObjectType,
217
- PostedToAccSystemYN: this.PostedToAccSystemYN,
218
- CreatedAt: new Date(),
219
- CreatedById: userId,
220
207
  },
221
- {
222
- transaction: dbTransaction,
223
- },
224
- );
208
+ transaction: dbTransaction,
209
+ });
210
+ if (data) {
211
+ this.AccountNo = data.AccountNo;
212
+ this.AccSystemRefId = data.AccSystemRefId;
213
+ this.Name = data.Name;
214
+ this.Description = data.Description;
215
+ this.AccountType = data.AccountType;
216
+ this.AccountSubtype = data.AccountSubType;
217
+ this.CompanyId = data.CompanyId;
218
+ this.OwnerId = data.OwnerId;
219
+ this.OwnerType = data.OwnerType;
220
+ this.RelatedObjectId = data.RelatedObjectId;
221
+ this.RelatedObjectType = data.RelatedObjectType;
222
+ this.PostedToAccSystemYN = data.PostedToAccSystemYN;
223
+ this.CreatedAt = data.CreatedAt;
224
+ this.CreatedById = data.CreatedById;
225
+ } else {
226
+ await this.RepositoryBase.create(
227
+ {
228
+ AccountNo: this.AccountNo,
229
+ AccSystemRefId: this.AccSystemRefId,
230
+ Name: this.Name,
231
+ Description: this.Description,
232
+ AccountType: this.AccountType,
233
+ AccountSubtype: this.AccountSubtype,
234
+ CompanyId: CompanyId,
235
+ OwnerId: this.OwnerId,
236
+ OwnerType: this.OwnerType,
237
+ RelatedObjectId: this.RelatedObjectId,
238
+ RelatedObjectType: this.RelatedObjectType,
239
+ PostedToAccSystemYN: this.PostedToAccSystemYN,
240
+ CreatedAt: new Date(),
241
+ CreatedById: userId,
242
+ },
243
+ {
244
+ transaction: dbTransaction,
245
+ },
246
+ );
247
+ }
248
+
225
249
  return data;
226
250
  }
227
251
  }
@@ -1205,8 +1205,8 @@ export default class FinanceCompany extends ObjectBase {
1205
1205
  TransactionTypeOptions.DEBIT,
1206
1206
  );
1207
1207
  debitLT.AccountNo = paymentMethodType.AccountNo;
1208
- debitLT.Currency = payment.Currency;
1209
- debitLT.DebitAmount = payment.Amount;
1208
+ debitLT.Currency = paymentPaidWith.Currency;
1209
+ debitLT.DebitAmount = paymentPaidWith.Amount;
1210
1210
  debitLT.Date = transactionDate;
1211
1211
  debitLT.Description = customer.FullName;
1212
1212
  debitLT.Name = customer.FullName;
@@ -1220,8 +1220,8 @@ export default class FinanceCompany extends ObjectBase {
1220
1220
  } else {
1221
1221
  creditLT.AccountNo = (await customer.AccountReceivable).AccountNo;
1222
1222
  }
1223
- creditLT.Currency = payment.Currency;
1224
- creditLT.CreditAmount = payment.Amount;
1223
+ creditLT.Currency = paymentPaidWith.Currency;
1224
+ creditLT.CreditAmount = paymentPaidWith.Amount;
1225
1225
  creditLT.Date = transactionDate;
1226
1226
  creditLT.Description = paymentMethodType.Name;
1227
1227
  creditLT.Name = paymentMethodType.Name;
@@ -1257,15 +1257,15 @@ export default class FinanceCompany extends ObjectBase {
1257
1257
  ): Promise<Payment> {
1258
1258
  let paymentMethodType: PaymentMethodType;
1259
1259
  try {
1260
- const PaymentPaidWith = await payment.PaymentPaidWith;
1261
- if (PaymentPaidWith.length < 1) {
1260
+ const paymentPaidWith = await payment.PaymentPaidWith;
1261
+ if (paymentPaidWith.length < 1) {
1262
1262
  throw new Error(
1263
1263
  'Atleast one payment paid with item is required to identify how the payment was made.',
1264
1264
  );
1265
1265
  }
1266
1266
  paymentMethodType = await PaymentMethodType.initMethodType(
1267
1267
  dbTransaction,
1268
- PaymentPaidWith[0].MethodTypeId,
1268
+ paymentPaidWith[0].MethodTypeId,
1269
1269
  );
1270
1270
 
1271
1271
  const paymentItems = await payment.PaymentItems;
@@ -1313,40 +1313,77 @@ export default class FinanceCompany extends ObjectBase {
1313
1313
  );
1314
1314
  });
1315
1315
 
1316
- const journalEntry = new JournalEntry(dbTransaction);
1317
- //Temporary fix to successfully save journal entry in PostJournal
1318
- journalEntry.init({
1319
- CompanyId: this.CompanyId,
1320
- Name: 'Make Payment for ' + payment.PaymentId,
1321
- });
1316
+ for (const paymentPaidWithItem of paymentPaidWith) {
1317
+ await FinanceCompany._PaymentPaidWithRepository.create(
1318
+ {
1319
+ PaymentId: payment.PaymentId,
1320
+ MethodTypeId: paymentPaidWithItem.MethodTypeId,
1321
+ Currency: paymentPaidWithItem.Currency,
1322
+ Amount: paymentPaidWithItem.Amount,
1323
+ Status: paymentPaidWithItem.Status,
1324
+ TransactionId: paymentPaidWithItem.TransactionId,
1325
+ RefBank: paymentPaidWithItem.RefBank,
1326
+ RefName: paymentPaidWithItem.RefName,
1327
+ RefNo: paymentPaidWithItem.RefNo,
1328
+ RefOther1: paymentPaidWithItem.RefOther1,
1329
+ RefOther2: paymentPaidWithItem.RefOther2,
1330
+ RefOther3: paymentPaidWithItem.RefOther3,
1331
+ RefOther4: paymentPaidWithItem.RefOther4,
1332
+ RefOther5: paymentPaidWithItem.RefOther5,
1333
+ Remarks: paymentPaidWithItem.Remarks,
1334
+ PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
1335
+ },
1336
+ { transaction: dbTransaction },
1337
+ );
1338
+ }
1322
1339
  const transactionDate = new Date();
1340
+ for (const paymentPaidWithItem of paymentPaidWith) {
1341
+ try {
1342
+ paymentMethodType = await PaymentMethodType.initMethodType(
1343
+ dbTransaction,
1344
+ paymentPaidWithItem.MethodTypeId,
1345
+ );
1323
1346
 
1324
- const creditLT = await journalEntry.newLedgerTransaction(
1325
- TransactionTypeOptions.CREDIT,
1326
- );
1327
- creditLT.AccountNo = paymentMethodType.AccountNo;
1328
- creditLT.Currency = payment.Currency;
1329
- creditLT.CreditAmount = payment.Amount;
1330
- creditLT.Date = transactionDate;
1331
- creditLT.Description = customer.FullName;
1332
- creditLT.Name = customer.FullName;
1333
-
1334
- const debitLT = await journalEntry.newLedgerTransaction(
1335
- TransactionTypeOptions.DEBIT,
1336
- );
1337
- if (dtAccountNo) {
1338
- debitLT.AccountNo = dtAccountNo;
1339
- } else {
1340
- debitLT.AccountNo = (await customer.AccountPayable).AccountNo;
1341
- }
1342
- debitLT.Currency = payment.Currency;
1343
- debitLT.DebitAmount = payment.Amount;
1344
- debitLT.Date = transactionDate;
1345
- debitLT.Description = paymentMethodType.Name;
1346
- debitLT.Name = paymentMethodType.Name;
1347
+ const journalEntry = new JournalEntry(dbTransaction);
1348
+ //Temporary fix to successfully save journal entry in PostJournal
1349
+ journalEntry.init({
1350
+ CompanyId: this.CompanyId,
1351
+ Name: 'Make Payment for ' + payment.PaymentId,
1352
+ });
1347
1353
 
1348
- await this.postJournal(dbTransaction, journalEntry);
1354
+ const creditLT = await journalEntry.newLedgerTransaction(
1355
+ TransactionTypeOptions.CREDIT,
1356
+ );
1357
+ creditLT.AccountNo = paymentMethodType.AccountNo;
1358
+ creditLT.Currency = paymentPaidWithItem.Currency;
1359
+ creditLT.CreditAmount = paymentPaidWithItem.Amount;
1360
+ creditLT.Date = transactionDate;
1361
+ creditLT.Description = customer.FullName;
1362
+ creditLT.Name = customer.FullName;
1363
+
1364
+ const debitLT = await journalEntry.newLedgerTransaction(
1365
+ TransactionTypeOptions.DEBIT,
1366
+ );
1367
+ if (dtAccountNo) {
1368
+ debitLT.AccountNo = dtAccountNo;
1369
+ } else {
1370
+ debitLT.AccountNo = (await customer.AccountPayable).AccountNo;
1371
+ }
1372
+ debitLT.Currency = paymentPaidWithItem.Currency;
1373
+ debitLT.DebitAmount = paymentPaidWithItem.Amount;
1374
+ debitLT.Date = transactionDate;
1375
+ debitLT.Description = paymentMethodType.Name;
1376
+ debitLT.Name = paymentMethodType.Name;
1349
1377
 
1378
+ await this.postJournal(dbTransaction, journalEntry);
1379
+ } catch (error) {
1380
+ if (error instanceof RecordNotFoundError) {
1381
+ throw new Error('Invalid Payment Method Type Id');
1382
+ } else {
1383
+ throw error;
1384
+ }
1385
+ }
1386
+ }
1350
1387
  /*todo: saving a record into the activity history table*/
1351
1388
 
1352
1389
  return payment;