@tomei/finance 0.3.33 → 0.3.35
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/dist/document/document.d.ts +1 -1
- package/dist/document/document.js +9 -6
- package/dist/document/document.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +1 -0
- package/dist/finance-company/finance-company.js +176 -102
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +2 -1
- package/dist/ledger-transaction/ledger-transaction.d.ts +4 -2
- package/dist/ledger-transaction/ledger-transaction.js +6 -5
- package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
- package/dist/models/ledger-transaction.entity.d.ts +6 -1
- package/dist/models/ledger-transaction.entity.js +31 -14
- package/dist/models/ledger-transaction.entity.js.map +1 -1
- package/dist/models/payment-item.entity.d.ts +2 -1
- package/dist/models/payment-item.entity.js +9 -2
- package/dist/models/payment-item.entity.js.map +1 -1
- package/dist/models/payment-paid-with.entity.d.ts +18 -0
- package/dist/models/payment-paid-with.entity.js +117 -0
- package/dist/models/payment-paid-with.entity.js.map +1 -0
- package/dist/models/payment.entity.d.ts +1 -6
- package/dist/models/payment.entity.js +2 -29
- package/dist/models/payment.entity.js.map +1 -1
- package/dist/payment/interfaces/payment-attr.interface.d.ts +1 -6
- package/dist/payment/interfaces/payment-attr.interface.js.map +1 -1
- package/dist/payment/payment.d.ts +10 -17
- package/dist/payment/payment.js +43 -30
- package/dist/payment/payment.js.map +1 -1
- package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +3 -1
- package/dist/payment-item/interfaces/payment-item-attr.interface.js.map +1 -1
- package/dist/payment-item/payment-item.d.ts +3 -0
- package/dist/payment-item/payment-item.js +6 -0
- package/dist/payment-item/payment-item.js.map +1 -1
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +13 -0
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js +7 -0
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js.map +1 -0
- package/dist/payment-paid-with/payment-paid-with.d.ts +24 -0
- package/dist/payment-paid-with/payment-paid-with.js +44 -0
- package/dist/payment-paid-with/payment-paid-with.js.map +1 -0
- package/dist/payment-paid-with/payment-paid-with.repository.d.ts +5 -0
- package/dist/payment-paid-with/payment-paid-with.repository.js +12 -0
- package/dist/payment-paid-with/payment-paid-with.repository.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/finance-ledger-transaction-migration.js +23 -7
- package/migrations/finance-payment-item-migration.js +10 -2
- package/migrations/finance-payment-migration.js +2 -34
- package/migrations/finance-paymentpaidwith-migration.js +66 -0
- package/package.json +1 -1
- package/src/document/document.ts +20 -10
- package/src/finance-company/finance-company.ts +233 -175
- package/src/index.ts +2 -0
- package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +2 -1
- package/src/ledger-transaction/ledger-transaction.ts +6 -4
- package/src/models/ledger-transaction.entity.ts +27 -13
- package/src/models/payment-item.entity.ts +8 -2
- package/src/models/payment-paid-with.entity.ts +97 -0
- package/src/models/payment.entity.ts +2 -28
- package/src/payment/interfaces/payment-attr.interface.ts +1 -6
- package/src/payment/payment.ts +55 -50
- package/src/payment-item/interfaces/payment-item-attr.interface.ts +3 -1
- package/src/payment-item/payment-item.ts +6 -3
- package/src/payment-paid-with/interfaces/payment-paid-with.interface.ts +14 -0
- package/src/payment-paid-with/payment-paid-with.repository.ts +11 -0
- package/src/payment-paid-with/payment-paid-with.ts +54 -0
|
@@ -29,6 +29,7 @@ import { DocumentItemRepository } from '../document/document-item.repository';
|
|
|
29
29
|
import { PaymentMethodRepository } from '../payment-method/payment-method.repository';
|
|
30
30
|
import { PaymentMethodTypeRepository } from '../payment-method-type/payment-method-type.repository';
|
|
31
31
|
import PaymentMethod from '../payment-method/payment-method';
|
|
32
|
+
import { PaymentPaidWithRepository } from 'src/payment-paid-with/payment-paid-with.repository';
|
|
32
33
|
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
35
|
const getConfig = require('../config');
|
|
@@ -45,6 +46,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
45
46
|
private static _financeCompanyRepository = new FinanceCompanyRepository();
|
|
46
47
|
private static _PaymentRepository = new PaymentRepository();
|
|
47
48
|
private static _PaymentItemRepository = new PaymentItemRepository();
|
|
49
|
+
private static _PaymentPaidWithRepository = new PaymentPaidWithRepository();
|
|
48
50
|
private static _PaymentMethodRepository = new PaymentMethodRepository();
|
|
49
51
|
private static _PaymentMethodTypeRepository =
|
|
50
52
|
new PaymentMethodTypeRepository();
|
|
@@ -482,6 +484,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
482
484
|
|
|
483
485
|
/*Set up the document type*/
|
|
484
486
|
invoice.DocType = DocType.INVOICE;
|
|
487
|
+
invoice.DocNo = cuid();
|
|
485
488
|
|
|
486
489
|
/*Saving the document and document items to the database*/
|
|
487
490
|
await FinanceCompany._DocumentRepository.create(
|
|
@@ -514,37 +517,35 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
514
517
|
},
|
|
515
518
|
);
|
|
516
519
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
// );
|
|
547
|
-
// });
|
|
520
|
+
documentItems.forEach(async (documentItem) => {
|
|
521
|
+
await FinanceCompany._DocumentItemRepository.create(
|
|
522
|
+
{
|
|
523
|
+
DocumentItemId: cuid(),
|
|
524
|
+
DocNo: documentItem.DocNo,
|
|
525
|
+
Name: documentItem.Name,
|
|
526
|
+
NameBM: documentItem.NameBM,
|
|
527
|
+
Description: documentItem.Description,
|
|
528
|
+
ItemId: documentItem.ItemId,
|
|
529
|
+
ItemType: documentItem.ItemType,
|
|
530
|
+
ItemSKU: documentItem.ItemSKU,
|
|
531
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
532
|
+
Currency: documentItem.Currency,
|
|
533
|
+
UnitPrice: documentItem.UnitPrice,
|
|
534
|
+
Quantity: documentItem.Quantity,
|
|
535
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
536
|
+
Amount: documentItem.Amount,
|
|
537
|
+
TaxCode: documentItem.TaxCode,
|
|
538
|
+
TaxAmount: documentItem.TaxAmount,
|
|
539
|
+
TaxRate: documentItem.TaxRate,
|
|
540
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
541
|
+
DtAccountNo: documentItem.DtAccountNo,
|
|
542
|
+
CtAccountNo: documentItem.CtAccountNo,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
transaction: dbTransaction,
|
|
546
|
+
},
|
|
547
|
+
);
|
|
548
|
+
});
|
|
548
549
|
|
|
549
550
|
/*Generating the invoice*/
|
|
550
551
|
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
@@ -557,57 +558,70 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
557
558
|
invoice.generateInvoice(invoice.IssuedById);
|
|
558
559
|
}
|
|
559
560
|
|
|
560
|
-
const journalEntry = new JournalEntry(dbTransaction);
|
|
561
561
|
const transactionDate = new Date();
|
|
562
|
+
const htCreditAccountAmount = new HashTable();
|
|
563
|
+
const htCreditAccountCurrency = new HashTable();
|
|
564
|
+
|
|
565
|
+
documentItems.forEach((invoiceItem) => {
|
|
566
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
567
|
+
//add the credit account to the hash table
|
|
568
|
+
htCreditAccountAmount.add(
|
|
569
|
+
invoiceItem.CtAccountNo,
|
|
570
|
+
invoiceItem.Amount,
|
|
571
|
+
);
|
|
562
572
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
573
|
+
htCreditAccountCurrency.add(
|
|
574
|
+
invoiceItem.CtAccountNo,
|
|
575
|
+
invoiceItem.Currency,
|
|
576
|
+
);
|
|
577
|
+
} else {
|
|
578
|
+
//update the credit account amount
|
|
579
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
580
|
+
htCreditAccountAmount.add(
|
|
581
|
+
invoiceItem.CtAccountNo,
|
|
582
|
+
d + invoiceItem.Amount,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
566
586
|
|
|
567
|
-
|
|
568
|
-
/*Transacting using AR account provided*/
|
|
569
|
-
ledgerTransaction.AccountNo = dtAccountNo;
|
|
570
|
-
} else {
|
|
571
|
-
/*Transacting based on default customer AR account*/
|
|
572
|
-
ledgerTransaction.AccountNo = customer.CustSystemCode + '-AR';
|
|
573
|
-
}
|
|
587
|
+
const savedItems = htCreditAccountAmount.list();
|
|
574
588
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
589
|
+
for (let i = 0; i < savedItems.length; i++) {
|
|
590
|
+
const journalEntry = new JournalEntry(dbTransaction);
|
|
591
|
+
const account = new Account(dbTransaction, savedItems[i].key);
|
|
592
|
+
const creditAmount = savedItems[i].value;
|
|
593
|
+
const currency = htCreditAccountCurrency.get(savedItems[i].key);
|
|
579
594
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
TransactionTypeOptions.CREDIT,
|
|
595
|
+
const dt = await journalEntry.newLedgerTransaction(
|
|
596
|
+
TransactionTypeOptions.DEBIT,
|
|
583
597
|
);
|
|
584
|
-
itemLedger.AccountNo = invoiceItem.CtAccountNo;
|
|
585
|
-
itemLedger.Currency = invoiceItem.Currency;
|
|
586
|
-
itemLedger.CreditAmount = invoiceItem.Amount;
|
|
587
|
-
itemLedger.Date = transactionDate;
|
|
588
|
-
itemLedger.Name = invoiceItem.Name;
|
|
589
|
-
}
|
|
590
598
|
|
|
591
|
-
|
|
599
|
+
if (dtAccountNo) {
|
|
600
|
+
/*Transacting using AR account provided*/
|
|
601
|
+
dt.AccountNo = dtAccountNo;
|
|
602
|
+
} else {
|
|
603
|
+
/*Transacting based on default customer AR account*/
|
|
604
|
+
dt.AccountNo = (await customer.AccountReceivable).AccountNo;
|
|
605
|
+
}
|
|
592
606
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
607
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
608
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
609
|
+
dt.Date = transactionDate;
|
|
610
|
+
dt.Description = account.Name;
|
|
611
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
612
|
+
|
|
613
|
+
const ct = await journalEntry.newLedgerTransaction(
|
|
614
|
+
TransactionTypeOptions.CREDIT,
|
|
615
|
+
);
|
|
616
|
+
ct.AccountNo = savedItems[i].key;
|
|
617
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
618
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
619
|
+
ct.Date = transactionDate;
|
|
620
|
+
ct.Description = account.Name;
|
|
621
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
622
|
+
|
|
623
|
+
await this.postJournal(dbTransaction, journalEntry);
|
|
624
|
+
}
|
|
611
625
|
|
|
612
626
|
return invoice;
|
|
613
627
|
} catch (err) {
|
|
@@ -668,6 +682,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
668
682
|
|
|
669
683
|
/*Set up the document type*/
|
|
670
684
|
invoice.DocType = DocType.DEBIT_NOTE;
|
|
685
|
+
invoice.DocNo = cuid();
|
|
671
686
|
|
|
672
687
|
/*Saving the document and document items to the database*/
|
|
673
688
|
await FinanceCompany._DocumentRepository.create(
|
|
@@ -741,55 +756,70 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
741
756
|
invoice.generateInvoice(loginUser.IDNo, customer);
|
|
742
757
|
}
|
|
743
758
|
|
|
744
|
-
const journalEntry = new JournalEntry(dbTransaction);
|
|
745
759
|
const transactionDate = new Date();
|
|
760
|
+
const htCreditAccountAmount = new HashTable();
|
|
761
|
+
const htCreditAccountCurrency = new HashTable();
|
|
762
|
+
|
|
763
|
+
documentItems.forEach((invoiceItem) => {
|
|
764
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
765
|
+
//add the credit account to the hash table
|
|
766
|
+
htCreditAccountAmount.add(
|
|
767
|
+
invoiceItem.CtAccountNo,
|
|
768
|
+
invoiceItem.Amount,
|
|
769
|
+
);
|
|
746
770
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
771
|
+
htCreditAccountCurrency.add(
|
|
772
|
+
invoiceItem.CtAccountNo,
|
|
773
|
+
invoiceItem.Currency,
|
|
774
|
+
);
|
|
775
|
+
} else {
|
|
776
|
+
//update the credit account amount
|
|
777
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
778
|
+
htCreditAccountAmount.add(
|
|
779
|
+
invoiceItem.CtAccountNo,
|
|
780
|
+
d + invoiceItem.Amount,
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
750
784
|
|
|
751
|
-
|
|
752
|
-
/*Transacting using AR account provided*/
|
|
753
|
-
debitTransaction.AccountNo = dtAccountNo;
|
|
754
|
-
} else {
|
|
755
|
-
/*Transacting based on default customer AR account*/
|
|
756
|
-
debitTransaction.AccountNo = customer.CustSystemCode + '-AR';
|
|
757
|
-
}
|
|
785
|
+
const savedItems = htCreditAccountAmount.list();
|
|
758
786
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
787
|
+
for (let i = 0; i < savedItems.length; i++) {
|
|
788
|
+
const journalEntry = new JournalEntry(dbTransaction);
|
|
789
|
+
const account = new Account(dbTransaction, savedItems[i].key);
|
|
790
|
+
const creditAmount = savedItems[i].value;
|
|
791
|
+
const currency = htCreditAccountCurrency.get(savedItems[i].key);
|
|
763
792
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
TransactionTypeOptions.CREDIT,
|
|
793
|
+
const dt = await journalEntry.newLedgerTransaction(
|
|
794
|
+
TransactionTypeOptions.DEBIT,
|
|
767
795
|
);
|
|
768
|
-
itemLedger.AccountNo = invoiceItem.CtAccountNo;
|
|
769
|
-
itemLedger.Currency = invoiceItem.Currency;
|
|
770
|
-
itemLedger.CreditAmount = invoiceItem.Amount;
|
|
771
|
-
itemLedger.Date = transactionDate;
|
|
772
|
-
itemLedger.Name = invoiceItem.Name;
|
|
773
|
-
}
|
|
774
796
|
|
|
775
|
-
|
|
797
|
+
if (dtAccountNo) {
|
|
798
|
+
/*Transacting using AR account provided*/
|
|
799
|
+
dt.AccountNo = dtAccountNo;
|
|
800
|
+
} else {
|
|
801
|
+
/*Transacting based on default customer AR account*/
|
|
802
|
+
dt.AccountNo = (await customer.AccountReceivable).AccountNo;
|
|
803
|
+
}
|
|
776
804
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
Description
|
|
781
|
-
|
|
782
|
-
EntityValueBefore: JSON.stringify({}),
|
|
783
|
-
EntityValueAfter: JSON.stringify(debitTransaction),
|
|
784
|
-
PerformedById: 'test',
|
|
785
|
-
PerformedAt: new Date(),
|
|
786
|
-
EntityId: debitTransaction.TransactionId,
|
|
787
|
-
};
|
|
805
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
806
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
807
|
+
dt.Date = transactionDate;
|
|
808
|
+
dt.Description = account.Name;
|
|
809
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
788
810
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
811
|
+
const ct = await journalEntry.newLedgerTransaction(
|
|
812
|
+
TransactionTypeOptions.CREDIT,
|
|
813
|
+
);
|
|
814
|
+
ct.AccountNo = savedItems[i].key;
|
|
815
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
816
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
817
|
+
ct.Date = transactionDate;
|
|
818
|
+
ct.Description = account.Name;
|
|
819
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
820
|
+
|
|
821
|
+
await this.postJournal(dbTransaction, journalEntry);
|
|
822
|
+
}
|
|
793
823
|
|
|
794
824
|
return invoice;
|
|
795
825
|
} catch (err) {
|
|
@@ -940,7 +970,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
940
970
|
creditTransaction.Currency = creditNote.Currency;
|
|
941
971
|
creditTransaction.CreditAmount = creditNote.Amount;
|
|
942
972
|
creditTransaction.Date = transactionDate;
|
|
943
|
-
creditTransaction.
|
|
973
|
+
creditTransaction.Description = creditNote.DocNo;
|
|
944
974
|
|
|
945
975
|
for (const invoiceItem of documentItems) {
|
|
946
976
|
const itemLedger = await journalEntry.newLedgerTransaction(
|
|
@@ -950,7 +980,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
950
980
|
itemLedger.Currency = invoiceItem.Currency;
|
|
951
981
|
itemLedger.DebitAmount = invoiceItem.Amount;
|
|
952
982
|
itemLedger.Date = transactionDate;
|
|
953
|
-
itemLedger.
|
|
983
|
+
itemLedger.Description = invoiceItem.Description;
|
|
954
984
|
}
|
|
955
985
|
|
|
956
986
|
this.postJournal(dbTransaction, journalEntry);
|
|
@@ -998,38 +1028,36 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
998
1028
|
customer: FinanceCustomerBase,
|
|
999
1029
|
ctAccountNo?: string,
|
|
1000
1030
|
): Promise<Payment> {
|
|
1001
|
-
let paymentMethodType: PaymentMethodType;
|
|
1002
1031
|
try {
|
|
1003
|
-
|
|
1004
|
-
dbTransaction,
|
|
1005
|
-
payment.MethodTypeId,
|
|
1006
|
-
);
|
|
1007
|
-
|
|
1032
|
+
/*validation 1: Make sure that the payment has at least 1 payment item*/
|
|
1008
1033
|
const paymentItems = await payment.PaymentItems;
|
|
1009
1034
|
if (paymentItems.length < 1) {
|
|
1010
1035
|
throw new Error(
|
|
1011
|
-
'Atleast one payment item is required to identify what payment is being paid for',
|
|
1036
|
+
'Atleast one payment item is required to identify what payment is being paid for.',
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/*validation 2: Make sure that the payment has at least 1 payment method*/
|
|
1041
|
+
const paymentPaidWithItems = await payment.PaymentPaidWith;
|
|
1042
|
+
if (paymentPaidWithItems.length < 1) {
|
|
1043
|
+
throw new Error(
|
|
1044
|
+
'Atleast one payment paid with item is required to identify how the payment was made.',
|
|
1012
1045
|
);
|
|
1013
1046
|
}
|
|
1014
1047
|
|
|
1015
1048
|
payment.PaymentId = cuid();
|
|
1016
1049
|
payment.PaymentType = PaymentType.PAYMENT_RECEIVED;
|
|
1050
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
1017
1051
|
|
|
1018
1052
|
await FinanceCompany._PaymentRepository.create(
|
|
1019
1053
|
{
|
|
1020
1054
|
PaymentId: payment.PaymentId,
|
|
1021
1055
|
PaymentType: payment.PaymentType,
|
|
1022
1056
|
PaymentDate: payment.PaymentDate,
|
|
1023
|
-
|
|
1024
|
-
MethodTypeId: payment.MethodTypeId,
|
|
1057
|
+
Description: payment.Description,
|
|
1025
1058
|
Currency: payment.Currency,
|
|
1026
1059
|
Amount: payment.Amount,
|
|
1027
1060
|
Status: PaymentStatus.SUCCESSFUL,
|
|
1028
|
-
TransactionId: payment.TransactionId,
|
|
1029
|
-
TransactionApprovalCode: payment.TransactionApprovalCode,
|
|
1030
|
-
TransactionAccountName: payment.TransactionAccountName,
|
|
1031
|
-
TransactionAccountNo: payment.TransactionAccountNo,
|
|
1032
|
-
ReceivedBy: payment.ReceivedBy,
|
|
1033
1061
|
PostedToAccSystemYN: 'N',
|
|
1034
1062
|
UpdatedAt: new Date(),
|
|
1035
1063
|
UpdatedBy: loginUser.ObjectId,
|
|
@@ -1047,53 +1075,89 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1047
1075
|
PayForObjectType: paymentItem.PayForObjectType,
|
|
1048
1076
|
Currency: paymentItem.Currency,
|
|
1049
1077
|
Amount: paymentItem.Amount,
|
|
1078
|
+
Name: paymentItem.Name,
|
|
1079
|
+
Description: paymentItem.Description,
|
|
1050
1080
|
},
|
|
1051
1081
|
{ transaction: dbTransaction },
|
|
1052
1082
|
);
|
|
1053
1083
|
});
|
|
1054
1084
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1085
|
+
paymentPaidWithItems.forEach(async (paymentPaidWithItem) => {
|
|
1086
|
+
await FinanceCompany._PaymentPaidWithRepository.create(
|
|
1087
|
+
{
|
|
1088
|
+
PaymentId: payment.PaymentId,
|
|
1089
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
1090
|
+
Currency: paymentPaidWithItem.Currency,
|
|
1091
|
+
Amount: paymentPaidWithItem.Amount,
|
|
1092
|
+
Status: paymentPaidWithItem.Status,
|
|
1093
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
1094
|
+
TransactionApprovalCode:
|
|
1095
|
+
paymentPaidWithItem.TransactionApprovalCode,
|
|
1096
|
+
TransactionApprovalName:
|
|
1097
|
+
paymentPaidWithItem.TransactionApprovalName,
|
|
1098
|
+
TransactionAccountNo: paymentPaidWithItem.TransactionAccountNo,
|
|
1099
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
1100
|
+
},
|
|
1101
|
+
{ transaction: dbTransaction },
|
|
1102
|
+
);
|
|
1060
1103
|
});
|
|
1104
|
+
|
|
1105
|
+
/*Registering the Journal Entries for the transaction*/
|
|
1061
1106
|
const transactionDate = new Date();
|
|
1062
1107
|
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
);
|
|
1066
|
-
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
1067
|
-
debitLT.Currency = payment.Currency;
|
|
1068
|
-
debitLT.DebitAmount = payment.Amount;
|
|
1069
|
-
debitLT.Date = transactionDate;
|
|
1070
|
-
debitLT.Name = customer.FullName;
|
|
1108
|
+
for (const paymentPaidWith of paymentPaidWithItems) {
|
|
1109
|
+
let paymentMethodType: PaymentMethodType;
|
|
1071
1110
|
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1111
|
+
try {
|
|
1112
|
+
paymentMethodType = new PaymentMethodType(
|
|
1113
|
+
dbTransaction,
|
|
1114
|
+
paymentPaidWith.MethodTypeId,
|
|
1115
|
+
);
|
|
1116
|
+
} catch (error) {
|
|
1117
|
+
if (error instanceof RecordNotFoundError) {
|
|
1118
|
+
throw new Error('Invalid Payment Method Type Id');
|
|
1119
|
+
} else {
|
|
1120
|
+
throw error;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
const journalEntry = new JournalEntry(dbTransaction);
|
|
1124
|
+
//Temporary fix to successfully save journal entry in PostJournal
|
|
1125
|
+
journalEntry.init({
|
|
1126
|
+
CompanyId: this.CompanyId,
|
|
1127
|
+
Name: 'Collect-payments for ' + payment.PaymentId,
|
|
1128
|
+
});
|
|
1075
1129
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
creditLT.Name = paymentMethodType.Name;
|
|
1130
|
+
const debitLT = await journalEntry.newLedgerTransaction(
|
|
1131
|
+
TransactionTypeOptions.DEBIT,
|
|
1132
|
+
);
|
|
1133
|
+
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
1134
|
+
debitLT.Currency = payment.Currency;
|
|
1135
|
+
debitLT.DebitAmount = payment.Amount;
|
|
1136
|
+
debitLT.Date = transactionDate;
|
|
1137
|
+
debitLT.Description = customer.FullName;
|
|
1085
1138
|
|
|
1086
|
-
|
|
1139
|
+
const creditLT = await journalEntry.newLedgerTransaction(
|
|
1140
|
+
TransactionTypeOptions.CREDIT,
|
|
1141
|
+
);
|
|
1142
|
+
|
|
1143
|
+
if (ctAccountNo) {
|
|
1144
|
+
creditLT.AccountNo = ctAccountNo;
|
|
1145
|
+
} else {
|
|
1146
|
+
creditLT.AccountNo = (await customer.AccountReceivable).AccountNo;
|
|
1147
|
+
}
|
|
1148
|
+
creditLT.Currency = payment.Currency;
|
|
1149
|
+
creditLT.CreditAmount = payment.Amount;
|
|
1150
|
+
creditLT.Date = transactionDate;
|
|
1151
|
+
creditLT.Description = paymentMethodType.Name;
|
|
1152
|
+
|
|
1153
|
+
await this.postJournal(dbTransaction, journalEntry);
|
|
1154
|
+
}
|
|
1087
1155
|
|
|
1088
1156
|
/*todo: saving a record into the activity history table*/
|
|
1089
1157
|
|
|
1090
1158
|
return payment;
|
|
1091
1159
|
} catch (error) {
|
|
1092
|
-
|
|
1093
|
-
throw new Error('Invalid PaymentMethodType id');
|
|
1094
|
-
} else {
|
|
1095
|
-
throw error;
|
|
1096
|
-
}
|
|
1160
|
+
throw error;
|
|
1097
1161
|
}
|
|
1098
1162
|
}
|
|
1099
1163
|
|
|
@@ -1106,7 +1170,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1106
1170
|
* @param customer - The customer who is receiving the payment.
|
|
1107
1171
|
* @param ctAccountNo - The account number of the customer's Account Payable account to transact, else the default customer account payable will be used.
|
|
1108
1172
|
*
|
|
1109
|
-
* @returns {Payment} - Payment object representing the full
|
|
1173
|
+
* @returns {Payment} - Payment object representing the full details of the payment collection recorded
|
|
1110
1174
|
*/
|
|
1111
1175
|
async makePayment(
|
|
1112
1176
|
dbTransaction: any,
|
|
@@ -1117,10 +1181,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1117
1181
|
): Promise<Payment> {
|
|
1118
1182
|
let paymentMethodType: PaymentMethodType;
|
|
1119
1183
|
try {
|
|
1120
|
-
paymentMethodType = new PaymentMethodType(
|
|
1121
|
-
dbTransaction,
|
|
1122
|
-
payment.MethodTypeId,
|
|
1123
|
-
);
|
|
1184
|
+
paymentMethodType = new PaymentMethodType(dbTransaction);
|
|
1124
1185
|
|
|
1125
1186
|
const paymentItems = await payment.PaymentItems;
|
|
1126
1187
|
if (paymentItems.length < 1) {
|
|
@@ -1131,22 +1192,17 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1131
1192
|
|
|
1132
1193
|
payment.PaymentId = cuid();
|
|
1133
1194
|
payment.PaymentType = PaymentType.PAYOUT;
|
|
1195
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
1134
1196
|
|
|
1135
1197
|
await FinanceCompany._PaymentRepository.create(
|
|
1136
1198
|
{
|
|
1137
1199
|
PaymentId: payment.PaymentId,
|
|
1138
1200
|
PaymentType: payment.PaymentType,
|
|
1139
1201
|
PaymentDate: payment.PaymentDate,
|
|
1140
|
-
|
|
1141
|
-
MethodTypeId: payment.MethodTypeId,
|
|
1202
|
+
Description: payment.Description,
|
|
1142
1203
|
Currency: payment.Currency,
|
|
1143
1204
|
Amount: payment.Amount,
|
|
1144
1205
|
Status: PaymentStatus.SUCCESSFUL,
|
|
1145
|
-
TransactionId: payment.TransactionId,
|
|
1146
|
-
TransactionApprovalCode: payment.TransactionApprovalCode,
|
|
1147
|
-
TransactionAccountName: payment.TransactionAccountName,
|
|
1148
|
-
TransactionAccountNo: payment.TransactionAccountNo,
|
|
1149
|
-
ReceivedBy: payment.ReceivedBy,
|
|
1150
1206
|
PostedToAccSystemYN: 'N',
|
|
1151
1207
|
UpdatedAt: new Date(),
|
|
1152
1208
|
UpdatedBy: loginUser.ObjectId,
|
|
@@ -1164,6 +1220,8 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1164
1220
|
PayForObjectType: paymentItem.PayForObjectType,
|
|
1165
1221
|
Currency: paymentItem.Currency,
|
|
1166
1222
|
Amount: paymentItem.Amount,
|
|
1223
|
+
Name: paymentItem.Name,
|
|
1224
|
+
Description: paymentItem.Description,
|
|
1167
1225
|
},
|
|
1168
1226
|
{ transaction: dbTransaction },
|
|
1169
1227
|
);
|
|
@@ -1184,7 +1242,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1184
1242
|
creditLT.Currency = payment.Currency;
|
|
1185
1243
|
creditLT.CreditAmount = payment.Amount;
|
|
1186
1244
|
creditLT.Date = transactionDate;
|
|
1187
|
-
creditLT.
|
|
1245
|
+
creditLT.Description = customer.FullName;
|
|
1188
1246
|
|
|
1189
1247
|
const debitLT = await journalEntry.newLedgerTransaction(
|
|
1190
1248
|
TransactionTypeOptions.DEBIT,
|
|
@@ -1197,7 +1255,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1197
1255
|
debitLT.Currency = payment.Currency;
|
|
1198
1256
|
debitLT.DebitAmount = payment.Amount;
|
|
1199
1257
|
debitLT.Date = transactionDate;
|
|
1200
|
-
debitLT.
|
|
1258
|
+
debitLT.Description = paymentMethodType.Name;
|
|
1201
1259
|
|
|
1202
1260
|
await this.postJournal(dbTransaction, journalEntry);
|
|
1203
1261
|
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import Payment from './payment/payment';
|
|
|
9
9
|
import PaymentItem from './payment-item/payment-item';
|
|
10
10
|
import PaymentMethod from './payment-method/payment-method';
|
|
11
11
|
import PaymentMethodType from './payment-method-type/payment-method-type';
|
|
12
|
+
import PaymentPaidWith from './payment-paid-with/payment-paid-with';
|
|
12
13
|
|
|
13
14
|
export {
|
|
14
15
|
FinanceCompany,
|
|
@@ -22,6 +23,7 @@ export {
|
|
|
22
23
|
PaymentItem,
|
|
23
24
|
PaymentMethod,
|
|
24
25
|
PaymentMethodType,
|
|
26
|
+
PaymentPaidWith,
|
|
25
27
|
};
|
|
26
28
|
export * as FinanceEnum from './enum';
|
|
27
29
|
export * as FinanceInterfaces from './interfaces';
|
|
@@ -6,11 +6,12 @@ export interface ILedgerTransactionAttr {
|
|
|
6
6
|
JournalEntryId: string;
|
|
7
7
|
AccountNo: string;
|
|
8
8
|
Date: Date;
|
|
9
|
-
Name: string;
|
|
10
9
|
Description: string;
|
|
11
10
|
Currency: string;
|
|
12
11
|
DebitAmount: number;
|
|
13
12
|
CreditAmount: number;
|
|
14
13
|
RelatedObjectId: string;
|
|
15
14
|
RelatedObjectType: string;
|
|
15
|
+
RelatedDocNo: string;
|
|
16
|
+
RelatedPaymentId: string;
|
|
16
17
|
}
|
|
@@ -9,13 +9,14 @@ export default class LedgerTransaction {
|
|
|
9
9
|
JournalEntryId = '';
|
|
10
10
|
AccountNo = '';
|
|
11
11
|
Date = new Date();
|
|
12
|
-
Name = '';
|
|
13
12
|
Description = '';
|
|
14
13
|
Currency = 'MYR';
|
|
15
14
|
DebitAmount = 0;
|
|
16
15
|
CreditAmount = 0;
|
|
17
16
|
RelatedObjectId = '';
|
|
18
17
|
RelatedObjectType = '';
|
|
18
|
+
RelatedDocNo = '';
|
|
19
|
+
RelatedPaymentId = '';
|
|
19
20
|
|
|
20
21
|
private _DbTransaction: any;
|
|
21
22
|
|
|
@@ -37,7 +38,6 @@ export default class LedgerTransaction {
|
|
|
37
38
|
if (params.JournalEntryId) this.JournalEntryId = params.JournalEntryId;
|
|
38
39
|
if (params.AccountNo) this.AccountNo = params.AccountNo;
|
|
39
40
|
if (params.Date) this.Date = params.Date;
|
|
40
|
-
if (params.Name) this.Name = params.Name;
|
|
41
41
|
if (params.Description) this.Description = params.Description;
|
|
42
42
|
if (params.Currency) this.Currency = params.Currency;
|
|
43
43
|
if (params.DebitAmount) this.DebitAmount = params.DebitAmount;
|
|
@@ -54,13 +54,14 @@ export default class LedgerTransaction {
|
|
|
54
54
|
JournalEntryId: this.JournalEntryId,
|
|
55
55
|
AccountNo: this.AccountNo,
|
|
56
56
|
Date: this.Date,
|
|
57
|
-
Name: this.Name,
|
|
58
57
|
Description: this.Description,
|
|
59
58
|
Currency: this.Currency,
|
|
60
59
|
DebitAmount: this.DebitAmount,
|
|
61
60
|
CreditAmount: this.CreditAmount,
|
|
62
61
|
RelatedObjectId: this.RelatedObjectId,
|
|
63
62
|
RelatedObjectType: this.RelatedObjectType,
|
|
63
|
+
RelatedDocNo: this.RelatedDocNo,
|
|
64
|
+
RelatedPaymentId: this.RelatedPaymentId,
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -82,13 +83,14 @@ export default class LedgerTransaction {
|
|
|
82
83
|
//TODO: AccountNo should be Filled In. Not sure with What
|
|
83
84
|
AccountNo: '',
|
|
84
85
|
Date: new Date(),
|
|
85
|
-
Name: '',
|
|
86
86
|
Description: '',
|
|
87
87
|
Currency: 'MYR',
|
|
88
88
|
DebitAmount: 0,
|
|
89
89
|
CreditAmount: 0,
|
|
90
90
|
RelatedObjectId: '',
|
|
91
91
|
RelatedObjectType: '',
|
|
92
|
+
RelatedDocNo: '',
|
|
93
|
+
RelatedPaymentId: '',
|
|
92
94
|
});
|
|
93
95
|
|
|
94
96
|
if (transactionType === TransactionTypeOptions.DEBIT) {
|