2022-04-21 13:08:36 +00:00
|
|
|
import { fyo } from 'src/initFyo'
|
2019-02-18 05:42:04 +00:00
|
|
|
|
|
|
|
class BankReconciliation {
|
|
|
|
async run(params) {
|
2019-08-14 07:43:49 +00:00
|
|
|
if (!Object.keys(params).length) return [];
|
|
|
|
|
2019-02-18 05:42:04 +00:00
|
|
|
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 09:56:30 +00:00
|
|
|
filters.paymentMethod = ['in', ['Cheque', 'Transfer']];
|
|
|
|
|
2022-04-21 13:08:36 +00:00
|
|
|
let data = await fyo.db.getAll({
|
2019-02-18 05:42:04 +00:00
|
|
|
doctype: 'Payment',
|
2019-07-22 09:56:30 +00:00
|
|
|
fields: [
|
|
|
|
'date',
|
|
|
|
'account',
|
|
|
|
'paymentAccount',
|
|
|
|
'party',
|
|
|
|
'name',
|
|
|
|
'referenceDate',
|
2019-09-03 09:43:16 +00:00
|
|
|
'referenceId',
|
2022-01-20 20:57:29 +00:00
|
|
|
'clearanceDate',
|
2019-07-22 09:56:30 +00:00
|
|
|
],
|
2022-01-20 20:57:29 +00:00
|
|
|
filters: filters,
|
2019-02-18 05:42:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
2022-04-21 13:08:36 +00:00
|
|
|
let ledger = await fyo.db.getAll({
|
2019-02-18 05:42:04 +00:00
|
|
|
doctype: 'AccountingLedgerEntry',
|
|
|
|
fields: ['date', 'referenceType', 'referenceName', 'debit', 'credit'],
|
|
|
|
filters: {
|
|
|
|
referenceType: 'Payment',
|
|
|
|
account: data[i].paymentAccount,
|
2022-01-20 20:57:29 +00:00
|
|
|
referenceName: data[i].name,
|
|
|
|
},
|
2019-07-22 09:56:30 +00:00
|
|
|
});
|
2019-02-18 05:42:04 +00:00
|
|
|
data[i].credit = ledger[0].credit;
|
|
|
|
data[i].debit = ledger[0].debit;
|
2019-09-03 09:43:16 +00:00
|
|
|
data[i].debit = ledger[0].debit;
|
2019-02-18 05:42:04 +00:00
|
|
|
data[i].referenceName = ledger[0].referenceName;
|
|
|
|
data[i].referenceType = ledger[0].referenceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 10:31:26 +00:00
|
|
|
export default BankReconciliation;
|