@tomei/finance 0.6.52 → 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.
- package/.commitlintrc.json +22 -22
- package/.eslintrc.js +72 -72
- package/.husky/commit-msg +4 -4
- package/.husky/pre-commit +4 -4
- package/.prettierrc +4 -4
- package/CONTRIBUTING.md +30 -30
- package/LICENSE +21 -21
- package/README.md +13 -13
- package/configs/config.js +348 -348
- package/dist/enum/payment-status.enum.d.ts +3 -1
- package/dist/enum/payment-status.enum.js +3 -1
- package/dist/enum/payment-status.enum.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +3 -1
- package/dist/finance-company/finance-company.js +178 -177
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/payment/payment.d.ts +3 -1
- package/dist/payment/payment.js +19 -0
- package/dist/payment/payment.js.map +1 -1
- package/dist/payment-item/payment-item.js +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/invoice-template/assets/css/style.css.map +12 -12
- package/invoice-template/assets/css/style.min.css +1 -1
- package/invoice-template/assets/img/arrow_bg.svg +11 -11
- package/invoice-template/assets/img/coffy_shop_img.svg +18 -18
- package/invoice-template/assets/img/logo_accent.svg +3 -3
- package/invoice-template/assets/img/logo_white.svg +4 -4
- package/invoice-template/assets/img/sign.svg +12 -12
- package/invoice-template/assets/img/tomei-logo.svg +9 -9
- package/invoice-template/assets/js/html2canvas.min.js +10379 -10379
- package/invoice-template/assets/js/jquery.min.js +1 -1
- package/invoice-template/assets/sass/common/_color_variable.scss +12 -12
- package/invoice-template/assets/sass/common/_typography.scss +178 -178
- package/invoice-template/assets/sass/style.scss +12 -12
- package/migrations/finance-account-migration.js +97 -97
- package/migrations/finance-company-migration.js +29 -29
- package/migrations/finance-customer-migration.js +51 -51
- package/migrations/finance-document-item-migration.js +111 -111
- package/migrations/finance-document-migration.js +122 -122
- package/migrations/finance-journal-entry-migration.js +59 -59
- package/migrations/finance-ledger-transaction-migration.js +89 -89
- package/migrations/finance-payment-item-migration.js +52 -52
- package/migrations/finance-payment-method-migration.js +31 -31
- package/migrations/finance-payment-method-type-migration.js +55 -55
- package/migrations/finance-payment-migration.js +96 -96
- package/migrations/finance-post-history-migration.js +45 -45
- package/migrations/finance-tax-migration.js +52 -52
- package/nest-cli.json +19 -19
- package/package.json +82 -82
- package/src/account/account.repository.ts +11 -11
- package/src/account/account.ts +276 -276
- package/src/account/interfaces/account-attr.interface.ts +31 -31
- package/src/account-system-entity/account-system-entity.ts +66 -66
- package/src/account-system-entity/post-history.repository.ts +11 -11
- package/src/config.ts +382 -382
- package/src/customer/customer.ts +300 -300
- package/src/customer/finance-customer.repository.ts +13 -13
- package/src/customer/interfaces/customer.repository.interface.ts +3 -3
- package/src/customer/interfaces/finance-customer-attr.interface.ts +10 -10
- package/src/customer/interfaces/finance-customer.repository.interface.ts +4 -4
- package/src/database.ts +48 -48
- package/src/document/document-item.repository.ts +11 -11
- package/src/document/document.repository.ts +11 -11
- package/src/document/interfaces/document-attr.interface.ts +28 -28
- package/src/document/interfaces/document-item-attr.interface.ts +22 -22
- package/src/document/interfaces/document-item.repository.interface.ts +4 -4
- package/src/enum/doc-type.enum.ts +8 -8
- package/src/enum/index.ts +17 -17
- package/src/enum/payment-method.enum.ts +3 -3
- package/src/enum/payment-status.enum.ts +3 -1
- package/src/enum/payment-type.enum.ts +4 -4
- package/src/enum/quick-book-client-scopes.enum.ts +14 -14
- package/src/finance-company/finance-company.repository.ts +11 -11
- package/src/finance-company/finance-company.ts +2176 -2094
- package/src/helpers/login-user.ts +38 -38
- package/src/helpers/typeof.ts +35 -35
- package/src/index.ts +32 -32
- package/src/interfaces/account-system.interface.ts +20 -20
- package/src/interfaces/index.ts +3 -3
- package/src/models/account.entity.ts +206 -206
- package/src/models/customer.entity.ts +93 -93
- package/src/models/document-item.entity.ts +143 -143
- package/src/models/document.entity.ts +211 -211
- package/src/models/finance-company.entity.ts +29 -29
- package/src/models/journal-entry.entity.ts +110 -110
- package/src/models/ledger-transaction.entity.ts +148 -148
- package/src/models/payment-item.entity.ts +60 -60
- package/src/models/payment-method-type.entity.ts +70 -70
- package/src/models/payment-method.entity.ts +51 -51
- package/src/models/payment.entity.ts +165 -165
- package/src/models/post-history.entity.ts +41 -41
- package/src/models/tax.entity.ts +75 -75
- package/src/payment/interfaces/payment-attr.interface.ts +23 -23
- package/src/payment/interfaces/payment-params.interface.ts +8 -8
- package/src/payment/payment.repository.ts +11 -11
- package/src/payment/payment.ts +274 -236
- package/src/payment-item/interfaces/payment-item-attr.interface.ts +10 -10
- package/src/payment-item/payment-item.repository.ts +11 -11
- package/src/payment-item/payment-item.ts +133 -133
- package/src/payment-method/payment-method.repository.ts +11 -11
- package/src/payment-method-type/payment-method-type.repository.ts +11 -11
- package/src/tax/interfaces/tax-attr.interface.ts +10 -10
- package/src/tax/tax.repository.ts +11 -11
- package/src/tax/tax.ts +61 -61
- package/src/test-document.ts +25 -25
- package/src/test.ts +3 -3
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +22 -22
- package/tslint.json +18 -18
|
@@ -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["
|
|
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,
|
|
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
|
|
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
|
}
|
|
@@ -731,7 +731,7 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
731
731
|
}
|
|
732
732
|
});
|
|
733
733
|
}
|
|
734
|
-
collectPayment(dbTransaction, loginUser, payment
|
|
734
|
+
collectPayment(dbTransaction, loginUser, payment) {
|
|
735
735
|
return __awaiter(this, void 0, void 0, function* () {
|
|
736
736
|
try {
|
|
737
737
|
const paymentItems = yield payment.getPaymentItems();
|
|
@@ -742,111 +742,10 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
742
742
|
if (paymentPaidWithItems.length < 1) {
|
|
743
743
|
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
744
744
|
}
|
|
745
|
-
const receiptDocuments = yield FinanceCompany._DocumentRepository.findAll({
|
|
746
|
-
where: {
|
|
747
|
-
DocType: enum_1.DocType.RECEIPT,
|
|
748
|
-
CompanyId: this.ObjectId,
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
const receipt = new document_1.default(dbTransaction);
|
|
752
|
-
if (receiptNo) {
|
|
753
|
-
receipt.DocNo = receiptNo;
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
|
|
757
|
-
}
|
|
758
|
-
receipt.DocType = enum_1.DocType.RECEIPT;
|
|
759
|
-
receipt.DocDate = new Date();
|
|
760
|
-
receipt.CompanyId = this.ObjectId;
|
|
761
|
-
receipt.Currency = payment.Currency;
|
|
762
|
-
receipt.Description = 'Payment Received';
|
|
763
|
-
receipt.IssuedById = loginUser.ObjectId;
|
|
764
|
-
receipt.IssuedToId = customer.CustomerId;
|
|
765
|
-
receipt.IssuedToType = (0, typeof_1.type)(customer);
|
|
766
|
-
receipt.RelatedObjectId = payment.RelatedObjectId;
|
|
767
|
-
receipt.RelatedObjectType = payment.RelatedObjectType;
|
|
768
|
-
receipt.UseAccSystemDocYN = 'N';
|
|
769
|
-
receipt.CreatedById = loginUser.ObjectId;
|
|
770
|
-
receipt.UpdatedById = loginUser.ObjectId;
|
|
771
|
-
for (const paymentItem of paymentItems) {
|
|
772
|
-
const receiptItem = new document_item_1.default(dbTransaction, receipt);
|
|
773
|
-
receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
774
|
-
receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
775
|
-
receiptItem.Description = '-';
|
|
776
|
-
receiptItem.Currency = paymentItem.Currency;
|
|
777
|
-
receiptItem.UnitPrice = paymentItem.Amount;
|
|
778
|
-
receiptItem.Quantity = 1;
|
|
779
|
-
receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
|
|
780
|
-
receiptItem.ItemId = receipt.DocNo;
|
|
781
|
-
receiptItem.ItemType = (0, typeof_1.type)(payment);
|
|
782
|
-
receiptItem.CtAccountNo = ctAccountNo;
|
|
783
|
-
yield receipt.newDocumentItem(receiptItem);
|
|
784
|
-
}
|
|
785
|
-
const receiptMedia = yield receipt.generateReceipt(receipt.IssuedById, customer, dbTransaction);
|
|
786
|
-
yield FinanceCompany._DocumentRepository.create({
|
|
787
|
-
DocNo: receipt.DocNo,
|
|
788
|
-
DocType: receipt.DocType,
|
|
789
|
-
DocDate: receipt.DocDate,
|
|
790
|
-
CompanyId: receipt.CompanyId,
|
|
791
|
-
Currency: receipt.Currency,
|
|
792
|
-
Amount: receipt.Amount,
|
|
793
|
-
Description: receipt.Description,
|
|
794
|
-
Status: receipt.Status,
|
|
795
|
-
IssuedById: receipt.IssuedById,
|
|
796
|
-
IssuedToId: receipt.IssuedToId,
|
|
797
|
-
IssuedToType: receipt.IssuedToType,
|
|
798
|
-
RelatedObjectId: receipt.RelatedObjectId,
|
|
799
|
-
RelatedObjectType: receipt.RelatedObjectType,
|
|
800
|
-
CreatedById: receipt.CreatedById,
|
|
801
|
-
CreatedAt: new Date(),
|
|
802
|
-
UpdatedById: receipt.UpdatedById,
|
|
803
|
-
UpdatedAt: new Date(),
|
|
804
|
-
DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
|
|
805
|
-
DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
|
|
806
|
-
AccSystemRefId: receipt.AccSystemRefId,
|
|
807
|
-
PostedToAccSystemYN: receipt.PostedToAccSystemYN,
|
|
808
|
-
PostedById: receipt.PostedToAccSystemYN == 'Y' ? receipt.PostedById : null,
|
|
809
|
-
PostedDateTime: new Date(),
|
|
810
|
-
UseAccSystemDocYN: receipt.UseAccSystemDocYN,
|
|
811
|
-
}, {
|
|
812
|
-
transaction: dbTransaction,
|
|
813
|
-
});
|
|
814
|
-
const receiptItems = yield receipt.DocumentItems;
|
|
815
|
-
for (const receiptItem of receiptItems) {
|
|
816
|
-
yield FinanceCompany._DocumentItemRepository.create({
|
|
817
|
-
DocumentItemId: cuid(),
|
|
818
|
-
DocNo: receipt.DocNo,
|
|
819
|
-
Name: receiptItem.Name,
|
|
820
|
-
NameBM: receiptItem.NameBM,
|
|
821
|
-
Description: receiptItem.Description,
|
|
822
|
-
ItemId: receiptItem.ItemId,
|
|
823
|
-
ItemType: receiptItem.ItemType,
|
|
824
|
-
ItemSKU: receiptItem.ItemSKU,
|
|
825
|
-
ItemSerialNo: receiptItem.ItemSerialNo,
|
|
826
|
-
Currency: receiptItem.Currency,
|
|
827
|
-
UnitPrice: receiptItem.UnitPrice,
|
|
828
|
-
Quantity: receiptItem.Quantity,
|
|
829
|
-
QuantityUOM: receiptItem.QuantityUOM,
|
|
830
|
-
Amount: receiptItem.Amount,
|
|
831
|
-
TaxCode: receiptItem.TaxCode,
|
|
832
|
-
TaxAmount: receiptItem.TaxAmount,
|
|
833
|
-
TaxRate: receiptItem.TaxRate,
|
|
834
|
-
TaxInclusiveYN: receiptItem.TaxInclusiveYN,
|
|
835
|
-
DtAccountNo: receiptItem.DtAccountNo
|
|
836
|
-
? receiptItem.DtAccountNo
|
|
837
|
-
: null,
|
|
838
|
-
CtAccountNo: receiptItem.CtAccountNo
|
|
839
|
-
? receiptItem.CtAccountNo
|
|
840
|
-
: null,
|
|
841
|
-
}, {
|
|
842
|
-
transaction: dbTransaction,
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
745
|
payment.PaymentId = cuid();
|
|
846
746
|
payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
|
|
847
747
|
payment.ReceivedBy = loginUser.ObjectId;
|
|
848
748
|
payment.IssuedBy = loginUser.ObjectId;
|
|
849
|
-
payment.ReceiptDocNo = receipt.DocNo;
|
|
850
749
|
yield FinanceCompany._PaymentRepository.create({
|
|
851
750
|
PaymentId: payment.PaymentId,
|
|
852
751
|
PaymentType: payment.PaymentType,
|
|
@@ -854,7 +753,7 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
854
753
|
Description: payment.Description,
|
|
855
754
|
Currency: payment.Currency,
|
|
856
755
|
Amount: payment.Amount,
|
|
857
|
-
Status: enum_1.PaymentStatus.
|
|
756
|
+
Status: enum_1.PaymentStatus.PENDING,
|
|
858
757
|
PostedToAccSystemYN: 'N',
|
|
859
758
|
ReceivedBy: payment.ReceivedBy,
|
|
860
759
|
IssuedBy: payment.IssuedBy,
|
|
@@ -880,6 +779,7 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
880
779
|
yield paymentItem.paid(dbTransaction);
|
|
881
780
|
}
|
|
882
781
|
for (const paymentPaidWithItem of paymentPaidWithItems) {
|
|
782
|
+
yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
|
|
883
783
|
yield FinanceCompany._PaymentPaidWithRepository.create({
|
|
884
784
|
PaymentId: payment.PaymentId,
|
|
885
785
|
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
@@ -899,53 +799,6 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
899
799
|
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
900
800
|
}, { transaction: dbTransaction });
|
|
901
801
|
}
|
|
902
|
-
const transactionDate = new Date();
|
|
903
|
-
for (const paymentPaidWith of paymentPaidWithItems) {
|
|
904
|
-
let paymentMethodType;
|
|
905
|
-
try {
|
|
906
|
-
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
|
|
907
|
-
}
|
|
908
|
-
catch (error) {
|
|
909
|
-
if (error instanceof general_1.RecordNotFoundError) {
|
|
910
|
-
throw new Error('Invalid Payment Method Type Id');
|
|
911
|
-
}
|
|
912
|
-
else {
|
|
913
|
-
throw error;
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
917
|
-
journalEntry.init({
|
|
918
|
-
CompanyId: this.CompanyId,
|
|
919
|
-
Name: 'Collect-payments for ' + payment.PaymentId,
|
|
920
|
-
});
|
|
921
|
-
const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
922
|
-
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
923
|
-
debitLT.Currency = paymentPaidWith.Currency;
|
|
924
|
-
debitLT.DebitAmount = paymentPaidWith.Amount;
|
|
925
|
-
debitLT.Date = transactionDate;
|
|
926
|
-
debitLT.Description = 'Payment Received';
|
|
927
|
-
debitLT.Name = customer.FullName;
|
|
928
|
-
debitLT.RelatedObjectId = payment.PaymentId;
|
|
929
|
-
debitLT.RelatedObjectType = (0, typeof_1.type)(payment);
|
|
930
|
-
debitLT.RelatedPaymentId = payment.PaymentId;
|
|
931
|
-
const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
932
|
-
if (ctAccountNo) {
|
|
933
|
-
creditLT.AccountNo = ctAccountNo;
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
const arAccount = yield customer.getAccountReceivable();
|
|
937
|
-
creditLT.AccountNo = arAccount.AccountNo;
|
|
938
|
-
}
|
|
939
|
-
creditLT.Currency = paymentPaidWith.Currency;
|
|
940
|
-
creditLT.CreditAmount = paymentPaidWith.Amount;
|
|
941
|
-
creditLT.Date = transactionDate;
|
|
942
|
-
creditLT.Description = 'Payment Received';
|
|
943
|
-
creditLT.Name = paymentMethodType.Name;
|
|
944
|
-
creditLT.RelatedObjectId = payment.PaymentId;
|
|
945
|
-
creditLT.RelatedObjectType = (0, typeof_1.type)(payment);
|
|
946
|
-
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
947
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
948
|
-
}
|
|
949
802
|
return payment;
|
|
950
803
|
}
|
|
951
804
|
catch (error) {
|
|
@@ -982,7 +835,7 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
982
835
|
RelatedObjectId: payment.RelatedObjectId,
|
|
983
836
|
RelatedObjectType: payment.RelatedObjectType,
|
|
984
837
|
Amount: payment.Amount,
|
|
985
|
-
Status: enum_1.PaymentStatus.
|
|
838
|
+
Status: enum_1.PaymentStatus.CONFIRMED,
|
|
986
839
|
PostedToAccSystemYN: 'N',
|
|
987
840
|
UpdatedAt: new Date(),
|
|
988
841
|
UpdatedBy: loginUser.ObjectId,
|
|
@@ -1316,7 +1169,7 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
1316
1169
|
Description: payment.Description,
|
|
1317
1170
|
Currency: payment.Currency,
|
|
1318
1171
|
Amount: payment.Amount,
|
|
1319
|
-
Status: enum_1.PaymentStatus.
|
|
1172
|
+
Status: enum_1.PaymentStatus.PENDING,
|
|
1320
1173
|
PostedToAccSystemYN: 'N',
|
|
1321
1174
|
ReceivedBy: payment.ReceivedBy,
|
|
1322
1175
|
IssuedBy: payment.IssuedBy,
|
|
@@ -1360,33 +1213,181 @@ class FinanceCompany extends general_1.ObjectBase {
|
|
|
1360
1213
|
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
1361
1214
|
}, { transaction: dbTransaction });
|
|
1362
1215
|
}));
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
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.`);
|
|
1378
1231
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
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.`);
|
|
1387
1390
|
}
|
|
1388
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1389
|
-
return payment;
|
|
1390
1391
|
}
|
|
1391
1392
|
catch (error) {
|
|
1392
1393
|
throw error;
|