2022-01-21 02:27:29 +05:30
|
|
|
import frappe from 'frappe';
|
2019-02-18 11:12:04 +05:30
|
|
|
|
|
|
|
class BankReconciliation {
|
|
|
|
async run(params) {
|
2019-08-14 13:13:49 +05:30
|
|
|
if (!Object.keys(params).length) return [];
|
|
|
|
|
2019-02-18 11:12:04 +05:30
|
|
|
const filters = {};
|
|
|
|
if (params.paymentAccount) filters.paymentAccount = params.paymentAccount;
|
|
|
|
if (params.party) filters.party = params.party;
|
|
|
|
if (params.toDate || params.fromDate) {
|
|
|
|
filters.date = [];
|
|
|
|
if (params.toDate) filters.date.push('<=', params.toDate);
|
|
|
|
if (params.fromDate) filters.date.push('>=', params.fromDate);
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:26:30 +05:30
|
|
|
filters.paymentMethod = ['in', ['Cheque', 'Transfer']];
|
|
|
|
|
2019-02-18 11:12:04 +05:30
|
|
|
let data = await frappe.db.getAll({
|
|
|
|
doctype: 'Payment',
|
2019-07-22 15:26:30 +05:30
|
|
|
fields: [
|
|
|
|
'date',
|
|
|
|
'account',
|
|
|
|
'paymentAccount',
|
|
|
|
'party',
|
|
|
|
'name',
|
|
|
|
'referenceDate',
|
2019-09-03 15:13:16 +05:30
|
|
|
'referenceId',
|
2022-01-21 02:27:29 +05:30
|
|
|
'clearanceDate',
|
2019-07-22 15:26:30 +05:30
|
|
|
],
|
2022-01-21 02:27:29 +05:30
|
|
|
filters: filters,
|
2019-02-18 11:12:04 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
let ledger = await frappe.db.getAll({
|
|
|
|
doctype: 'AccountingLedgerEntry',
|
|
|
|
fields: ['date', 'referenceType', 'referenceName', 'debit', 'credit'],
|
|
|
|
filters: {
|
|
|
|
referenceType: 'Payment',
|
|
|
|
account: data[i].paymentAccount,
|
2022-01-21 02:27:29 +05:30
|
|
|
referenceName: data[i].name,
|
|
|
|
},
|
2019-07-22 15:26:30 +05:30
|
|
|
});
|
2019-02-18 11:12:04 +05:30
|
|
|
data[i].credit = ledger[0].credit;
|
|
|
|
data[i].debit = ledger[0].debit;
|
2019-09-03 15:13:16 +05:30
|
|
|
data[i].debit = ledger[0].debit;
|
2019-02-18 11:12:04 +05:30
|
|
|
data[i].referenceName = ledger[0].referenceName;
|
|
|
|
data[i].referenceType = ledger[0].referenceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 16:01:26 +05:30
|
|
|
export default BankReconciliation;
|