@tomei/finance 0.6.22 → 0.6.24
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.js +8 -5
- package/dist/document/document.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +5 -0
- package/dist/finance-company/finance-company.js +124 -0
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/invoice-template/assets/img/ezcash-logo.png +0 -0
- package/invoice-template/index.html +11 -3
- package/package.json +1 -1
- package/src/document/document.ts +12 -13
- package/src/finance-company/finance-company.ts +202 -0
|
Binary file
|
|
@@ -17,12 +17,20 @@
|
|
|
17
17
|
<div class="tm_invoice tm_style1" id="tm_download_section">
|
|
18
18
|
<div class="tm_invoice_in">
|
|
19
19
|
<div class="tm_invoice_head tm_align_center tm_mb20">
|
|
20
|
-
<div class="tm_invoice_left">
|
|
20
|
+
<div class="tm_invoice_left" style="width: max-content;">
|
|
21
21
|
<div class="tm_logo">
|
|
22
22
|
<img src="./assets/img/logo.svg" alt="Logo" />
|
|
23
23
|
</div>
|
|
24
|
+
<div>
|
|
25
|
+
<p class="tm_m0" style="font-size: small;">
|
|
26
|
+
<b class="tm_primary_color">TXG Financial Solutions Sdn Bhd</b> (200201019252)(586915-X)
|
|
27
|
+
</p>
|
|
28
|
+
<p class="tm_m0" style="font-size: smaller;">
|
|
29
|
+
4-3, Jalan 2/131A, Project Jaya Industrial Estate, Batu 6, Jalan Kelang Lama, 58200 Kuala Lumpur, Malaysia.
|
|
30
|
+
</p>
|
|
31
|
+
</div>
|
|
24
32
|
</div>
|
|
25
|
-
<div class="tm_invoice_right tm_text_right tm_invoice_title">
|
|
33
|
+
<div class="tm_invoice_right tm_text_right tm_invoice_title" style="width: 30%;">
|
|
26
34
|
<div class="tm_primary_color tm_f50 tm_text_uppercase">
|
|
27
35
|
Invoice
|
|
28
36
|
</div>
|
|
@@ -143,7 +151,7 @@
|
|
|
143
151
|
Credit Card - 236***********928 <br />Amount: $1732
|
|
144
152
|
</p>
|
|
145
153
|
</div>
|
|
146
|
-
<div class="tm_item_total_section">
|
|
154
|
+
<div class="tm_item_total_section" style="padding-left: 120px;">
|
|
147
155
|
<table>
|
|
148
156
|
<tbody>
|
|
149
157
|
<tr>
|
package/package.json
CHANGED
package/src/document/document.ts
CHANGED
|
@@ -334,14 +334,12 @@ export default class Document extends AccountSystemEntity {
|
|
|
334
334
|
const page = await browser.newPage();
|
|
335
335
|
|
|
336
336
|
const imagePath = path.resolve(
|
|
337
|
-
'./invoice-template/assets/img/
|
|
337
|
+
'./invoice-template/assets/img/ezcash-logo.png',
|
|
338
338
|
);
|
|
339
339
|
const imageBuffer = await readFileContent(imagePath);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
// temporary to hide the logo
|
|
344
|
-
const imageDataUrl = '';
|
|
340
|
+
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString(
|
|
341
|
+
'base64',
|
|
342
|
+
)}`;
|
|
345
343
|
|
|
346
344
|
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
347
345
|
|
|
@@ -558,18 +556,19 @@ export default class Document extends AccountSystemEntity {
|
|
|
558
556
|
]);
|
|
559
557
|
|
|
560
558
|
/* converting HTML to PDF */
|
|
561
|
-
const browser = await puppeteer.launch(
|
|
559
|
+
const browser = await puppeteer.launch({
|
|
560
|
+
headless: true,
|
|
561
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
562
|
+
});
|
|
562
563
|
const page = await browser.newPage();
|
|
563
564
|
|
|
564
565
|
const imagePath = path.resolve(
|
|
565
|
-
'./invoice-template/assets/img/
|
|
566
|
+
'./invoice-template/assets/img/ezcash-logo.png',
|
|
566
567
|
);
|
|
567
568
|
const imageBuffer = await readFileContent(imagePath);
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
// temporary to hide tomei logo
|
|
572
|
-
const imageDataUrl = '';
|
|
569
|
+
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString(
|
|
570
|
+
'base64',
|
|
571
|
+
)}`;
|
|
573
572
|
|
|
574
573
|
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
575
574
|
|
|
@@ -36,6 +36,7 @@ import DocumentItem from '../document/document-item';
|
|
|
36
36
|
import { type } from '../helpers/typeof';
|
|
37
37
|
import { LoginUser } from '@tomei/sso';
|
|
38
38
|
import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
39
|
+
import { ApplicationConfig } from '@tomei/config';
|
|
39
40
|
|
|
40
41
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
41
42
|
const getConfig = require('../config');
|
|
@@ -1775,4 +1776,205 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1775
1776
|
}
|
|
1776
1777
|
});
|
|
1777
1778
|
}
|
|
1779
|
+
|
|
1780
|
+
async collectPaymentForMultipleCustomers(
|
|
1781
|
+
dbTransaction: any,
|
|
1782
|
+
loginUser: LoginUserBase,
|
|
1783
|
+
payment: Payment,
|
|
1784
|
+
creditTransaction: {
|
|
1785
|
+
AccountNo: string;
|
|
1786
|
+
Currency: string;
|
|
1787
|
+
Amount: number;
|
|
1788
|
+
}[],
|
|
1789
|
+
receiptNo?: string,
|
|
1790
|
+
): Promise<Payment> {
|
|
1791
|
+
//Method to collect payment for multiple customer.
|
|
1792
|
+
try {
|
|
1793
|
+
//Part 1: Privilege Checking\
|
|
1794
|
+
const systemCode = await ApplicationConfig.getComponentConfigValue(
|
|
1795
|
+
'system-code',
|
|
1796
|
+
);
|
|
1797
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
1798
|
+
systemCode,
|
|
1799
|
+
'Collect Payment For Multiple Customers',
|
|
1800
|
+
);
|
|
1801
|
+
|
|
1802
|
+
if (!isPrivileged) {
|
|
1803
|
+
throw new Error('User is not authorized to perform this action');
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
//Part 2: Validation
|
|
1807
|
+
//Make sure that the payment has at least 1 payment item
|
|
1808
|
+
const paymentItems = await payment.PaymentItems;
|
|
1809
|
+
if (paymentItems.length < 1) {
|
|
1810
|
+
throw new Error(
|
|
1811
|
+
'Atleast one payment item is required to identify what payment is being paid for.',
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
//Make sure that the payment has at least 1 payment method
|
|
1816
|
+
const paymentPaidWithItems = await payment.PaymentPaidWith;
|
|
1817
|
+
if (paymentPaidWithItems.length < 1) {
|
|
1818
|
+
throw new Error(
|
|
1819
|
+
'Atleast one payment paid with item is required to identify how the payment was made.',
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
//Make sure the payment items length is equal to creditTransactions length records.
|
|
1824
|
+
if (paymentItems.length !== creditTransaction.length) {
|
|
1825
|
+
throw new Error(
|
|
1826
|
+
'Payment items length is not equal to creditTransaction length',
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
//Make sure the payment items total Amount is equal to credit transactions total Amount.
|
|
1831
|
+
let totalAmount = 0;
|
|
1832
|
+
paymentItems.forEach((paymentItem) => {
|
|
1833
|
+
totalAmount += paymentItem.Amount;
|
|
1834
|
+
});
|
|
1835
|
+
|
|
1836
|
+
const totalCreditTransactionAmount = creditTransaction.reduce(
|
|
1837
|
+
(accumulator, currentValue) => {
|
|
1838
|
+
return accumulator + currentValue.Amount;
|
|
1839
|
+
},
|
|
1840
|
+
0,
|
|
1841
|
+
);
|
|
1842
|
+
|
|
1843
|
+
if (totalAmount !== totalCreditTransactionAmount) {
|
|
1844
|
+
throw new Error(
|
|
1845
|
+
'Payment items total Amount is dnot equal to credit transactions total Amount',
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
//Part 3:Generate Receipt (KIV)
|
|
1850
|
+
|
|
1851
|
+
//Part 4: Saving Payment, Payment Items and Payment Paid with Details to the Database
|
|
1852
|
+
|
|
1853
|
+
//Set below Payment attributes:
|
|
1854
|
+
payment.PaymentId = cuid();
|
|
1855
|
+
payment.PaymentType = PaymentType.PAYMENT_RECEIVED;
|
|
1856
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
1857
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
1858
|
+
|
|
1859
|
+
//Call Payment Repository create() method by passing:
|
|
1860
|
+
await FinanceCompany._PaymentRepository.create(
|
|
1861
|
+
{
|
|
1862
|
+
PaymentId: payment.PaymentId,
|
|
1863
|
+
PaymentType: payment.PaymentType,
|
|
1864
|
+
PaymentDate: payment.PaymentDate,
|
|
1865
|
+
Description: payment.Description,
|
|
1866
|
+
Currency: payment.Currency,
|
|
1867
|
+
Amount: payment.Amount,
|
|
1868
|
+
Status: PaymentStatus.SUCCESSFUL,
|
|
1869
|
+
PostedToAccSystemYN: 'N',
|
|
1870
|
+
ReceivedBy: payment.ReceivedBy,
|
|
1871
|
+
IssuedBy: payment.IssuedBy,
|
|
1872
|
+
Remarks: payment.Remarks,
|
|
1873
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
1874
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
1875
|
+
ReceiptDocNo: payment.ReceiptDocNo,
|
|
1876
|
+
UpdatedAt: new Date(),
|
|
1877
|
+
UpdatedBy: loginUser.ObjectId,
|
|
1878
|
+
CreatedAt: new Date(),
|
|
1879
|
+
CreatedBy: loginUser.ObjectId,
|
|
1880
|
+
},
|
|
1881
|
+
{ transaction: dbTransaction },
|
|
1882
|
+
);
|
|
1883
|
+
|
|
1884
|
+
//Map Payment.PaymentItems and insert record by passing dbTransaction
|
|
1885
|
+
paymentItems.forEach(async (paymentItem) => {
|
|
1886
|
+
await FinanceCompany._PaymentItemRepository.create(
|
|
1887
|
+
{
|
|
1888
|
+
PaymentId: payment.PaymentId,
|
|
1889
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
1890
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
1891
|
+
Currency: paymentItem.Currency,
|
|
1892
|
+
Amount: paymentItem.Amount,
|
|
1893
|
+
Name: paymentItem.Name,
|
|
1894
|
+
Description: paymentItem.Description,
|
|
1895
|
+
},
|
|
1896
|
+
{ transaction: dbTransaction },
|
|
1897
|
+
);
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
// Map Payment.PaymentPaidWith and insert record by passing dbTransaction.
|
|
1901
|
+
paymentPaidWithItems.forEach(async (paymentPaidWithItem) => {
|
|
1902
|
+
await FinanceCompany._PaymentPaidWithRepository.create(
|
|
1903
|
+
{
|
|
1904
|
+
PaymentId: payment.PaymentId,
|
|
1905
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
1906
|
+
Currency: paymentPaidWithItem.Currency,
|
|
1907
|
+
Amount: paymentPaidWithItem.Amount,
|
|
1908
|
+
Status: paymentPaidWithItem.Status,
|
|
1909
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
1910
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
1911
|
+
RefName: paymentPaidWithItem.RefName,
|
|
1912
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
1913
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
1914
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
1915
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
1916
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
1917
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
1918
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
1919
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
1920
|
+
},
|
|
1921
|
+
{ transaction: dbTransaction },
|
|
1922
|
+
);
|
|
1923
|
+
});
|
|
1924
|
+
|
|
1925
|
+
//Part 5: Registering the Journal Entries for the transaction
|
|
1926
|
+
//Initialise TransactionDate
|
|
1927
|
+
const transactionDate = new Date();
|
|
1928
|
+
//Initialise new JournalEntry
|
|
1929
|
+
const journalEntry = new JournalEntry(dbTransaction);
|
|
1930
|
+
|
|
1931
|
+
// For each Payment.PaymentPaidWith:
|
|
1932
|
+
paymentPaidWithItems.forEach(async (paymentPaidWithItem) => {
|
|
1933
|
+
// check if its payment method type is valid.
|
|
1934
|
+
try {
|
|
1935
|
+
const paymentMethodType = await PaymentMethodType.initMethodType(
|
|
1936
|
+
dbTransaction,
|
|
1937
|
+
paymentPaidWithItem.MethodTypeId,
|
|
1938
|
+
);
|
|
1939
|
+
|
|
1940
|
+
//Initialise new Debit LedgerTransaction by calling JournalEntry.newLedgerTransaction() method and set below attributes:
|
|
1941
|
+
const debitLT = await journalEntry.newLedgerTransaction(
|
|
1942
|
+
TransactionTypeOptions.DEBIT,
|
|
1943
|
+
);
|
|
1944
|
+
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
1945
|
+
debitLT.Currency = paymentPaidWithItem.Currency;
|
|
1946
|
+
debitLT.DebitAmount = paymentPaidWithItem.Amount;
|
|
1947
|
+
debitLT.Date = transactionDate;
|
|
1948
|
+
debitLT.Description = 'Payment Received';
|
|
1949
|
+
debitLT.RelatedPaymentId = payment.PaymentId;
|
|
1950
|
+
} catch (error) {
|
|
1951
|
+
if (error instanceof RecordNotFoundError) {
|
|
1952
|
+
throw new Error('Invalid Payment Method Type Id');
|
|
1953
|
+
} else {
|
|
1954
|
+
throw error;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
|
|
1959
|
+
//For each creditTransactions, Initialise new Credit LedgerTransaction by calling JournalEntry.newLedgerTransaction() method
|
|
1960
|
+
creditTransaction.forEach(async (creditTransaction) => {
|
|
1961
|
+
const creditLT = await journalEntry.newLedgerTransaction(
|
|
1962
|
+
TransactionTypeOptions.CREDIT,
|
|
1963
|
+
);
|
|
1964
|
+
creditLT.AccountNo = creditTransaction.AccountNo;
|
|
1965
|
+
creditLT.Currency = creditTransaction.Currency;
|
|
1966
|
+
creditLT.CreditAmount = creditTransaction.Amount;
|
|
1967
|
+
creditLT.Date = transactionDate;
|
|
1968
|
+
creditLT.Description = 'Payment Received';
|
|
1969
|
+
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
1970
|
+
});
|
|
1971
|
+
|
|
1972
|
+
// Call this.postJournal()
|
|
1973
|
+
this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1974
|
+
|
|
1975
|
+
return payment;
|
|
1976
|
+
} catch (error) {
|
|
1977
|
+
throw error;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1778
1980
|
}
|