@tomei/finance 0.6.51 → 0.6.53

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.
@@ -1,4 +1,6 @@
1
1
  export declare enum PaymentStatus {
2
- SUCCESSFUL = "Successful",
2
+ PENDING = "Pending",
3
+ CONFIRMED = "Confirmed",
4
+ REJECTED = "Rejected",
3
5
  FAILED = "Failed"
4
6
  }
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PaymentStatus = void 0;
4
4
  var PaymentStatus;
5
5
  (function (PaymentStatus) {
6
- PaymentStatus["SUCCESSFUL"] = "Successful";
6
+ PaymentStatus["PENDING"] = "Pending";
7
+ PaymentStatus["CONFIRMED"] = "Confirmed";
8
+ PaymentStatus["REJECTED"] = "Rejected";
7
9
  PaymentStatus["FAILED"] = "Failed";
8
10
  })(PaymentStatus = exports.PaymentStatus || (exports.PaymentStatus = {}));
9
11
  //# sourceMappingURL=payment-status.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment-status.enum.js","sourceRoot":"","sources":["../../src/enum/payment-status.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,0CAAyB,CAAA;IACzB,kCAAiB,CAAA;AACnB,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB"}
1
+ {"version":3,"file":"payment-status.enum.js","sourceRoot":"","sources":["../../src/enum/payment-status.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,sCAAqB,CAAA;IACrB,kCAAiB,CAAA;AACnB,CAAC,EALW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAKxB"}
@@ -4,6 +4,7 @@ import JournalEntry from '../journal-entry/journal-entry';
4
4
  import FinanceCustomerBase from '../customer/customer';
5
5
  import Document from '../document/document';
6
6
  import { IAccountSystem } from '../interfaces';
7
+ import { PaymentStatus } from '../enum';
7
8
  import Payment from '../payment/payment';
8
9
  import PaymentMethod from '../payment-method/payment-method';
9
10
  import { LoginUser } from '@tomei/sso';
@@ -56,7 +57,7 @@ export default class FinanceCompany extends ObjectBase {
56
57
  issueInvoice(dbTransaction: any, invoice: Document, loginUser?: LoginUserBase, customer?: FinanceCustomerBase, dtAccountNo?: string): Promise<Document>;
57
58
  issueDebitNote(dbTransaction: any, loginUser: LoginUserBase, invoice: Document, customer: FinanceCustomerBase, dtAccountNo?: string): Promise<Document>;
58
59
  issueCreditNote(dbTransaction: any, loginUser: LoginUserBase, creditNote: Document, customer: FinanceCustomerBase, ctAccountNo?: string): Promise<Document>;
59
- collectPayment(dbTransaction: any, loginUser: LoginUserBase, payment: Payment, customer: FinanceCustomerBase, ctAccountNo?: string, receiptNo?: string): Promise<Payment>;
60
+ collectPayment(dbTransaction: any, loginUser: LoginUserBase, payment: Payment): Promise<Payment>;
60
61
  makePayment(dbTransaction: any, loginUser: LoginUserBase, payment: Payment, customer: FinanceCustomerBase, dtAccountNo?: string): Promise<Payment>;
61
62
  get PaymentMethods(): Promise<PaymentMethod[]>;
62
63
  get TaxCodes(): Promise<Tax[]>;
@@ -67,4 +68,5 @@ export default class FinanceCompany extends ObjectBase {
67
68
  Currency: string;
68
69
  Amount: number;
69
70
  }[], receiptNo?: string): Promise<Payment>;
71
+ confirmPayment(dbTransaction: any, loginUser: LoginUserBase, customer: FinanceCustomerBase, payment: Payment, status: PaymentStatus.CONFIRMED | PaymentStatus.REJECTED | PaymentStatus.FAILED, remarks: string, ctAccountNo?: string, receiptNo?: string): Promise<void>;
70
72
  }
@@ -209,9 +209,17 @@ class FinanceCompany extends general_1.ObjectBase {
209
209
  if (creditTransactions.length < 1 || (debitTransactions === null || debitTransactions === void 0 ? void 0 : debitTransactions.length) < 1) {
210
210
  throw new Error('There should be at least 1 debit ledger transaction and 1 credit ledger transaction in the journal entry');
211
211
  }
212
- const totalCreditAmount = creditTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.CreditAmount, 0);
213
- const totalDebitAmount = debitTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.DebitAmount, 0);
214
- if (totalCreditAmount !== totalDebitAmount) {
212
+ let totalCreditAmount = creditTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.CreditAmount, 0);
213
+ let totalDebitAmount = debitTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.DebitAmount, 0);
214
+ console.log('totalCreditAmount: ', totalCreditAmount);
215
+ console.log('totalDebitAmount: ', totalDebitAmount);
216
+ if (typeof totalCreditAmount === 'string') {
217
+ totalCreditAmount = parseFloat(totalCreditAmount);
218
+ }
219
+ if (typeof totalDebitAmount === 'string') {
220
+ totalDebitAmount = parseFloat(totalDebitAmount);
221
+ }
222
+ if (totalCreditAmount.toFixed(2) !== totalDebitAmount.toFixed(2)) {
215
223
  throw new Error('Credit ledger transaction and debit ledger transaction should the same amount');
216
224
  }
217
225
  const newJournalEntry = yield journalEntry.save(loginUser.ObjectId, dbTransaction);
@@ -723,7 +731,7 @@ class FinanceCompany extends general_1.ObjectBase {
723
731
  }
724
732
  });
725
733
  }
726
- collectPayment(dbTransaction, loginUser, payment, customer, ctAccountNo, receiptNo) {
734
+ collectPayment(dbTransaction, loginUser, payment) {
727
735
  return __awaiter(this, void 0, void 0, function* () {
728
736
  try {
729
737
  const paymentItems = yield payment.getPaymentItems();
@@ -734,111 +742,10 @@ class FinanceCompany extends general_1.ObjectBase {
734
742
  if (paymentPaidWithItems.length < 1) {
735
743
  throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
736
744
  }
737
- const receiptDocuments = yield FinanceCompany._DocumentRepository.findAll({
738
- where: {
739
- DocType: enum_1.DocType.RECEIPT,
740
- CompanyId: this.ObjectId,
741
- },
742
- });
743
- const receipt = new document_1.default(dbTransaction);
744
- if (receiptNo) {
745
- receipt.DocNo = receiptNo;
746
- }
747
- else {
748
- receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
749
- }
750
- receipt.DocType = enum_1.DocType.RECEIPT;
751
- receipt.DocDate = new Date();
752
- receipt.CompanyId = this.ObjectId;
753
- receipt.Currency = payment.Currency;
754
- receipt.Description = 'Payment Received';
755
- receipt.IssuedById = loginUser.ObjectId;
756
- receipt.IssuedToId = customer.CustomerId;
757
- receipt.IssuedToType = (0, typeof_1.type)(customer);
758
- receipt.RelatedObjectId = payment.RelatedObjectId;
759
- receipt.RelatedObjectType = payment.RelatedObjectType;
760
- receipt.UseAccSystemDocYN = 'N';
761
- receipt.CreatedById = loginUser.ObjectId;
762
- receipt.UpdatedById = loginUser.ObjectId;
763
- for (const paymentItem of paymentItems) {
764
- const receiptItem = new document_item_1.default(dbTransaction, receipt);
765
- receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
766
- receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
767
- receiptItem.Description = '-';
768
- receiptItem.Currency = paymentItem.Currency;
769
- receiptItem.UnitPrice = paymentItem.Amount;
770
- receiptItem.Quantity = 1;
771
- receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
772
- receiptItem.ItemId = receipt.DocNo;
773
- receiptItem.ItemType = (0, typeof_1.type)(payment);
774
- receiptItem.CtAccountNo = ctAccountNo;
775
- yield receipt.newDocumentItem(receiptItem);
776
- }
777
- const receiptMedia = yield receipt.generateReceipt(receipt.IssuedById, customer, dbTransaction);
778
- yield FinanceCompany._DocumentRepository.create({
779
- DocNo: receipt.DocNo,
780
- DocType: receipt.DocType,
781
- DocDate: receipt.DocDate,
782
- CompanyId: receipt.CompanyId,
783
- Currency: receipt.Currency,
784
- Amount: receipt.Amount,
785
- Description: receipt.Description,
786
- Status: receipt.Status,
787
- IssuedById: receipt.IssuedById,
788
- IssuedToId: receipt.IssuedToId,
789
- IssuedToType: receipt.IssuedToType,
790
- RelatedObjectId: receipt.RelatedObjectId,
791
- RelatedObjectType: receipt.RelatedObjectType,
792
- CreatedById: receipt.CreatedById,
793
- CreatedAt: new Date(),
794
- UpdatedById: receipt.UpdatedById,
795
- UpdatedAt: new Date(),
796
- DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
797
- DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
798
- AccSystemRefId: receipt.AccSystemRefId,
799
- PostedToAccSystemYN: receipt.PostedToAccSystemYN,
800
- PostedById: receipt.PostedToAccSystemYN == 'Y' ? receipt.PostedById : null,
801
- PostedDateTime: new Date(),
802
- UseAccSystemDocYN: receipt.UseAccSystemDocYN,
803
- }, {
804
- transaction: dbTransaction,
805
- });
806
- const receiptItems = yield receipt.DocumentItems;
807
- for (const receiptItem of receiptItems) {
808
- yield FinanceCompany._DocumentItemRepository.create({
809
- DocumentItemId: cuid(),
810
- DocNo: receipt.DocNo,
811
- Name: receiptItem.Name,
812
- NameBM: receiptItem.NameBM,
813
- Description: receiptItem.Description,
814
- ItemId: receiptItem.ItemId,
815
- ItemType: receiptItem.ItemType,
816
- ItemSKU: receiptItem.ItemSKU,
817
- ItemSerialNo: receiptItem.ItemSerialNo,
818
- Currency: receiptItem.Currency,
819
- UnitPrice: receiptItem.UnitPrice,
820
- Quantity: receiptItem.Quantity,
821
- QuantityUOM: receiptItem.QuantityUOM,
822
- Amount: receiptItem.Amount,
823
- TaxCode: receiptItem.TaxCode,
824
- TaxAmount: receiptItem.TaxAmount,
825
- TaxRate: receiptItem.TaxRate,
826
- TaxInclusiveYN: receiptItem.TaxInclusiveYN,
827
- DtAccountNo: receiptItem.DtAccountNo
828
- ? receiptItem.DtAccountNo
829
- : null,
830
- CtAccountNo: receiptItem.CtAccountNo
831
- ? receiptItem.CtAccountNo
832
- : null,
833
- }, {
834
- transaction: dbTransaction,
835
- });
836
- }
837
745
  payment.PaymentId = cuid();
838
746
  payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
839
747
  payment.ReceivedBy = loginUser.ObjectId;
840
748
  payment.IssuedBy = loginUser.ObjectId;
841
- payment.ReceiptDocNo = receipt.DocNo;
842
749
  yield FinanceCompany._PaymentRepository.create({
843
750
  PaymentId: payment.PaymentId,
844
751
  PaymentType: payment.PaymentType,
@@ -846,7 +753,7 @@ class FinanceCompany extends general_1.ObjectBase {
846
753
  Description: payment.Description,
847
754
  Currency: payment.Currency,
848
755
  Amount: payment.Amount,
849
- Status: enum_1.PaymentStatus.SUCCESSFUL,
756
+ Status: enum_1.PaymentStatus.PENDING,
850
757
  PostedToAccSystemYN: 'N',
851
758
  ReceivedBy: payment.ReceivedBy,
852
759
  IssuedBy: payment.IssuedBy,
@@ -872,6 +779,7 @@ class FinanceCompany extends general_1.ObjectBase {
872
779
  yield paymentItem.paid(dbTransaction);
873
780
  }
874
781
  for (const paymentPaidWithItem of paymentPaidWithItems) {
782
+ yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
875
783
  yield FinanceCompany._PaymentPaidWithRepository.create({
876
784
  PaymentId: payment.PaymentId,
877
785
  MethodTypeId: paymentPaidWithItem.MethodTypeId,
@@ -891,53 +799,6 @@ class FinanceCompany extends general_1.ObjectBase {
891
799
  PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
892
800
  }, { transaction: dbTransaction });
893
801
  }
894
- const transactionDate = new Date();
895
- for (const paymentPaidWith of paymentPaidWithItems) {
896
- let paymentMethodType;
897
- try {
898
- paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
899
- }
900
- catch (error) {
901
- if (error instanceof general_1.RecordNotFoundError) {
902
- throw new Error('Invalid Payment Method Type Id');
903
- }
904
- else {
905
- throw error;
906
- }
907
- }
908
- const journalEntry = new journal_entry_1.default(dbTransaction);
909
- journalEntry.init({
910
- CompanyId: this.CompanyId,
911
- Name: 'Collect-payments for ' + payment.PaymentId,
912
- });
913
- const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
914
- debitLT.AccountNo = paymentMethodType.AccountNo;
915
- debitLT.Currency = paymentPaidWith.Currency;
916
- debitLT.DebitAmount = paymentPaidWith.Amount;
917
- debitLT.Date = transactionDate;
918
- debitLT.Description = 'Payment Received';
919
- debitLT.Name = customer.FullName;
920
- debitLT.RelatedObjectId = payment.PaymentId;
921
- debitLT.RelatedObjectType = (0, typeof_1.type)(payment);
922
- debitLT.RelatedPaymentId = payment.PaymentId;
923
- const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
924
- if (ctAccountNo) {
925
- creditLT.AccountNo = ctAccountNo;
926
- }
927
- else {
928
- const arAccount = yield customer.getAccountReceivable();
929
- creditLT.AccountNo = arAccount.AccountNo;
930
- }
931
- creditLT.Currency = paymentPaidWith.Currency;
932
- creditLT.CreditAmount = paymentPaidWith.Amount;
933
- creditLT.Date = transactionDate;
934
- creditLT.Description = 'Payment Received';
935
- creditLT.Name = paymentMethodType.Name;
936
- creditLT.RelatedObjectId = payment.PaymentId;
937
- creditLT.RelatedObjectType = (0, typeof_1.type)(payment);
938
- creditLT.RelatedPaymentId = payment.PaymentId;
939
- yield this.postJournal(dbTransaction, journalEntry, loginUser);
940
- }
941
802
  return payment;
942
803
  }
943
804
  catch (error) {
@@ -974,7 +835,7 @@ class FinanceCompany extends general_1.ObjectBase {
974
835
  RelatedObjectId: payment.RelatedObjectId,
975
836
  RelatedObjectType: payment.RelatedObjectType,
976
837
  Amount: payment.Amount,
977
- Status: enum_1.PaymentStatus.SUCCESSFUL,
838
+ Status: enum_1.PaymentStatus.CONFIRMED,
978
839
  PostedToAccSystemYN: 'N',
979
840
  UpdatedAt: new Date(),
980
841
  UpdatedBy: loginUser.ObjectId,
@@ -1308,7 +1169,7 @@ class FinanceCompany extends general_1.ObjectBase {
1308
1169
  Description: payment.Description,
1309
1170
  Currency: payment.Currency,
1310
1171
  Amount: payment.Amount,
1311
- Status: enum_1.PaymentStatus.SUCCESSFUL,
1172
+ Status: enum_1.PaymentStatus.PENDING,
1312
1173
  PostedToAccSystemYN: 'N',
1313
1174
  ReceivedBy: payment.ReceivedBy,
1314
1175
  IssuedBy: payment.IssuedBy,
@@ -1352,33 +1213,181 @@ class FinanceCompany extends general_1.ObjectBase {
1352
1213
  PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
1353
1214
  }, { transaction: dbTransaction });
1354
1215
  }));
1355
- const transactionDate = new Date();
1356
- const journalEntry = new journal_entry_1.default(dbTransaction);
1357
- journalEntry.init({
1358
- CompanyId: this.CompanyId,
1359
- Name: 'Collect-payments for ' + payment.PaymentId,
1360
- });
1361
- for (const paymentPaidWithItem of paymentPaidWithItems) {
1362
- const paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
1363
- const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
1364
- debitLT.AccountNo = paymentMethodType.AccountNo;
1365
- debitLT.Currency = paymentPaidWithItem.Currency;
1366
- debitLT.DebitAmount = paymentPaidWithItem.Amount;
1367
- debitLT.Date = transactionDate;
1368
- debitLT.Description = 'Payment Received';
1369
- debitLT.RelatedPaymentId = payment.PaymentId;
1216
+ return payment;
1217
+ }
1218
+ catch (error) {
1219
+ throw error;
1220
+ }
1221
+ });
1222
+ }
1223
+ confirmPayment(dbTransaction, loginUser, customer, payment, status, remarks, ctAccountNo, receiptNo) {
1224
+ return __awaiter(this, void 0, void 0, function* () {
1225
+ try {
1226
+ this._DbTransaction = dbTransaction;
1227
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1228
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'FinanceCompany - Confirm Payment');
1229
+ if (!isPrivileged) {
1230
+ throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg00', `You do not have 'Payment - Confirm' privilege.`);
1370
1231
  }
1371
- for (const ct of creditTransaction) {
1372
- const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
1373
- creditLT.AccountNo = ct.AccountNo;
1374
- creditLT.Currency = ct.Currency;
1375
- creditLT.CreditAmount = ct.Amount;
1376
- creditLT.Date = transactionDate;
1377
- creditLT.Description = 'Payment Received';
1378
- creditLT.RelatedPaymentId = payment.PaymentId;
1232
+ if (payment.PaymentId === 'New') {
1233
+ throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg01', `Payment not found.`);
1234
+ }
1235
+ if (payment.Status !== enum_1.PaymentStatus.PENDING) {
1236
+ throw new general_1.ClassError('Payment', 'PaymentConfirmPaymentErrMsg02', `Payment status is not 'Pending'.`);
1237
+ }
1238
+ payment.Remarks = remarks;
1239
+ switch (status) {
1240
+ case enum_1.PaymentStatus.REJECTED:
1241
+ payment.Status = enum_1.PaymentStatus.REJECTED;
1242
+ break;
1243
+ case enum_1.PaymentStatus.FAILED:
1244
+ payment.Status = enum_1.PaymentStatus.FAILED;
1245
+ break;
1246
+ case enum_1.PaymentStatus.CONFIRMED:
1247
+ payment.Status = enum_1.PaymentStatus.CONFIRMED;
1248
+ const receiptDocuments = yield FinanceCompany._DocumentRepository.findAll({
1249
+ where: {
1250
+ DocType: enum_1.DocType.RECEIPT,
1251
+ CompanyId: this.ObjectId,
1252
+ },
1253
+ });
1254
+ const receipt = new document_1.default(dbTransaction);
1255
+ if (receiptNo) {
1256
+ receipt.DocNo = receiptNo;
1257
+ }
1258
+ else {
1259
+ receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
1260
+ }
1261
+ receipt.DocType = enum_1.DocType.RECEIPT;
1262
+ receipt.DocDate = new Date();
1263
+ receipt.CompanyId = this.ObjectId;
1264
+ receipt.Currency = payment.Currency;
1265
+ receipt.Description = 'Payment Received';
1266
+ receipt.IssuedById = loginUser.ObjectId;
1267
+ receipt.IssuedToId = customer.CustomerId;
1268
+ receipt.IssuedToType = (0, typeof_1.type)(customer);
1269
+ receipt.RelatedObjectId = payment.RelatedObjectId;
1270
+ receipt.RelatedObjectType = payment.RelatedObjectType;
1271
+ receipt.UseAccSystemDocYN = 'N';
1272
+ receipt.CreatedById = loginUser.ObjectId;
1273
+ receipt.UpdatedById = loginUser.ObjectId;
1274
+ const paymentItems = yield payment.getPaymentItems();
1275
+ for (const paymentItem of paymentItems) {
1276
+ const receiptItem = new document_item_1.default(dbTransaction, receipt);
1277
+ receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
1278
+ receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
1279
+ receiptItem.Description = '-';
1280
+ receiptItem.Currency = paymentItem.Currency;
1281
+ receiptItem.UnitPrice = paymentItem.Amount;
1282
+ receiptItem.Quantity = 1;
1283
+ receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
1284
+ receiptItem.ItemId = receipt.DocNo;
1285
+ receiptItem.ItemType = (0, typeof_1.type)(payment);
1286
+ receiptItem.CtAccountNo = ctAccountNo;
1287
+ yield receipt.newDocumentItem(receiptItem);
1288
+ }
1289
+ const receiptMedia = yield receipt.generateReceipt(receipt.IssuedById, customer, dbTransaction);
1290
+ yield FinanceCompany._DocumentRepository.create({
1291
+ DocNo: receipt.DocNo,
1292
+ DocType: receipt.DocType,
1293
+ DocDate: receipt.DocDate,
1294
+ CompanyId: receipt.CompanyId,
1295
+ Currency: receipt.Currency,
1296
+ Amount: receipt.Amount,
1297
+ Description: receipt.Description,
1298
+ Status: receipt.Status,
1299
+ IssuedById: receipt.IssuedById,
1300
+ IssuedToId: receipt.IssuedToId,
1301
+ IssuedToType: receipt.IssuedToType,
1302
+ RelatedObjectId: receipt.RelatedObjectId,
1303
+ RelatedObjectType: receipt.RelatedObjectType,
1304
+ CreatedById: receipt.CreatedById,
1305
+ CreatedAt: new Date(),
1306
+ UpdatedById: receipt.UpdatedById,
1307
+ UpdatedAt: new Date(),
1308
+ DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
1309
+ DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
1310
+ AccSystemRefId: receipt.AccSystemRefId,
1311
+ PostedToAccSystemYN: receipt.PostedToAccSystemYN,
1312
+ PostedById: receipt.PostedToAccSystemYN == 'Y' ? receipt.PostedById : null,
1313
+ PostedDateTime: new Date(),
1314
+ UseAccSystemDocYN: receipt.UseAccSystemDocYN,
1315
+ }, {
1316
+ transaction: dbTransaction,
1317
+ });
1318
+ const receiptItems = yield receipt.DocumentItems;
1319
+ for (const receiptItem of receiptItems) {
1320
+ yield FinanceCompany._DocumentItemRepository.create({
1321
+ DocumentItemId: cuid(),
1322
+ DocNo: receipt.DocNo,
1323
+ Name: receiptItem.Name,
1324
+ NameBM: receiptItem.NameBM,
1325
+ Description: receiptItem.Description,
1326
+ ItemId: receiptItem.ItemId,
1327
+ ItemType: receiptItem.ItemType,
1328
+ ItemSKU: receiptItem.ItemSKU,
1329
+ ItemSerialNo: receiptItem.ItemSerialNo,
1330
+ Currency: receiptItem.Currency,
1331
+ UnitPrice: receiptItem.UnitPrice,
1332
+ Quantity: receiptItem.Quantity,
1333
+ QuantityUOM: receiptItem.QuantityUOM,
1334
+ Amount: receiptItem.Amount,
1335
+ TaxCode: receiptItem.TaxCode,
1336
+ TaxAmount: receiptItem.TaxAmount,
1337
+ TaxRate: receiptItem.TaxRate,
1338
+ TaxInclusiveYN: receiptItem.TaxInclusiveYN,
1339
+ DtAccountNo: receiptItem.DtAccountNo
1340
+ ? receiptItem.DtAccountNo
1341
+ : null,
1342
+ CtAccountNo: receiptItem.CtAccountNo
1343
+ ? receiptItem.CtAccountNo
1344
+ : null,
1345
+ }, {
1346
+ transaction: dbTransaction,
1347
+ });
1348
+ }
1349
+ payment.ReceiptDocNo = receipt.DocNo;
1350
+ const transactionDate = new Date();
1351
+ const paymentPaidWithItems = yield payment.getPaymentPaidWith();
1352
+ for (const paymentPaidWith of paymentPaidWithItems) {
1353
+ let paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
1354
+ const journalEntry = new journal_entry_1.default(dbTransaction);
1355
+ journalEntry.init({
1356
+ CompanyId: this.CompanyId,
1357
+ Name: 'Collect-payments for ' + payment.PaymentId,
1358
+ });
1359
+ const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
1360
+ debitLT.AccountNo = paymentMethodType.AccountNo;
1361
+ debitLT.Currency = paymentPaidWith.Currency;
1362
+ debitLT.DebitAmount = paymentPaidWith.Amount;
1363
+ debitLT.Date = transactionDate;
1364
+ debitLT.Description = 'Payment Received';
1365
+ debitLT.Name = customer.FullName;
1366
+ debitLT.RelatedObjectId = payment.PaymentId;
1367
+ debitLT.RelatedObjectType = "Payment";
1368
+ debitLT.RelatedPaymentId = payment.PaymentId;
1369
+ const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
1370
+ if (ctAccountNo) {
1371
+ creditLT.AccountNo = ctAccountNo;
1372
+ }
1373
+ else {
1374
+ const arAccount = yield customer.getAccountReceivable();
1375
+ creditLT.AccountNo = arAccount.AccountNo;
1376
+ }
1377
+ creditLT.Currency = paymentPaidWith.Currency;
1378
+ creditLT.CreditAmount = paymentPaidWith.Amount;
1379
+ creditLT.Date = transactionDate;
1380
+ creditLT.Description = 'Payment Received';
1381
+ creditLT.Name = paymentMethodType.Name;
1382
+ creditLT.RelatedObjectId = payment.PaymentId;
1383
+ creditLT.RelatedObjectType = (0, typeof_1.type)(payment);
1384
+ creditLT.RelatedPaymentId = payment.PaymentId;
1385
+ yield yield this.postJournal(dbTransaction, journalEntry, loginUser);
1386
+ }
1387
+ break;
1388
+ default:
1389
+ throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg03', `Invalid status.`);
1379
1390
  }
1380
- yield this.postJournal(dbTransaction, journalEntry, loginUser);
1381
- return payment;
1382
1391
  }
1383
1392
  catch (error) {
1384
1393
  throw error;