mirror of
https://github.com/frappe/books.git
synced 2025-02-10 16:08:35 +00:00
* init() * Country-wise Chart of accounts on setup * Add a sample invoice template * Some error fixes * [fix] missing COA - move importCOA.js from models/doctype/account to models/doctype/Account * All Account initial balance zero * setup Bank Reconciliation * New chart of accounts tree component * GST taxes added. initialized gst reports. * [chore] add *.db to .gitignore * [fix] importCOA path error * fix error + bank reconciliation fields * [feat] add gst taxes * GST report initialized * GST report finalized * GST report finalized * Complete min. reconciliation * [feat] auto select tax in invoice based on states * [chore] fix merge changes * Fix date issue - Make Payment * Add invoice templates and invoice customizer panel * Restructure invoice vue components * update file with fiscal year * Fix issues in invoice designs * Add company settings. Dynamic addresses in invoice * Move invoice styles to different file and add separate components for addresses * [feat] add export-filtered-data-to-csv to reports * [feat] add Export Wizard component for customizing export * Fix invoice customizer position while scrolling. Fix address displayed as undefined in invoice if not found in db * [chore] change markup for select all chkbox * Setup config as doctype * GSTIN bug fix * Add custom google fonts * Add Send email footer * Fix DateTime * Complete Merge + Resolve * Complete Merge + Resolve * [chore] change layout of Export Wizard * [enh] optimize checkNoneSelected, style export modal footer divider * Add Tax to SideBar * Remove extra logs * [fix] db name section in sidebar showing absolute path instead of dbname in windows i.e. platform=win32 * Country-wise Chart of accounts on setup (#78) * Country-wise Chart of accounts on setup * Some error fixes * All Account initial balance zero * Update README.md - updated installation instructions with more detail * Merge #79 Winter Sprint: Work https://github.com/frappe/accounting/pull/79 * Revert "Merge #79 Winter Sprint: Work" This reverts commit 171511666817caa430af672791c8d452e3b4b680.
155 lines
4.1 KiB
JavaScript
155 lines
4.1 KiB
JavaScript
const frappe = require('frappejs');
|
|
|
|
module.exports = class AccountsReceivablePayable {
|
|
async run(reportType, { date }) {
|
|
|
|
const rows = await getReceivablePayable({
|
|
reportType,
|
|
date
|
|
});
|
|
|
|
return { rows };
|
|
}
|
|
}
|
|
|
|
async function getReceivablePayable({ reportType = 'Receivable', date }) {
|
|
let entries = [];
|
|
const debitOrCredit = reportType === 'Receivable' ? 'debit' : 'credit';
|
|
const referenceType = reportType === 'Receivable' ? 'Invoice' : 'Bill';
|
|
|
|
entries = await getLedgerEntries();
|
|
const vouchers = await getVouchers();
|
|
|
|
const futureEntries = getFutureEntries();
|
|
const returnEntries = getReturnEntries();
|
|
const pdc = getPDC();
|
|
|
|
const validEntries = getValidEntries();
|
|
|
|
let data = [];
|
|
|
|
for (let entry of validEntries) {
|
|
|
|
const { outStandingAmount, creditNoteAmount } = getOutstandingAmount(entry);
|
|
|
|
console.log(outStandingAmount);
|
|
|
|
if (outStandingAmount > 0.1 / 10) {
|
|
const row = {
|
|
date: entry.date,
|
|
party: entry.party
|
|
};
|
|
|
|
// due date / bill date
|
|
|
|
row.voucherType = entry.referenceType;
|
|
row.voucherNo = entry.referenceName;
|
|
|
|
// bill details
|
|
|
|
const invoicedAmount = entry[debitOrCredit] || 0;
|
|
const paidAmount = invoicedAmount - outStandingAmount - creditNoteAmount;
|
|
|
|
Object.assign(row, {
|
|
invoicedAmount,
|
|
paidAmount,
|
|
outStandingAmount,
|
|
creditNoteAmount
|
|
});
|
|
|
|
// ageing
|
|
|
|
data.push(row);
|
|
}
|
|
}
|
|
|
|
return data;
|
|
|
|
// helpers
|
|
|
|
async function getVouchers() {
|
|
return await frappe.db.getAll({
|
|
doctype: referenceType,
|
|
fields: ['name', 'date'],
|
|
filters: {
|
|
submitted: 1
|
|
}
|
|
});
|
|
}
|
|
|
|
function getValidEntries() {
|
|
return entries.filter(entry => {
|
|
return (
|
|
entry.date <= date &&
|
|
entry.referenceType === referenceType && entry[debitOrCredit] > 0
|
|
);
|
|
});
|
|
}
|
|
|
|
function getOutstandingAmount(entry) {
|
|
let paymentAmount = 0.0, creditNoteAmount = 0.0;
|
|
let reverseDebitOrCredit = debitOrCredit === 'debit' ? 'credit' : 'debit';
|
|
|
|
for (let e of getEntriesFor(entry.party, entry.referenceType, entry.referenceName)) {
|
|
if (e.date <= date) {
|
|
const amount = e[reverseDebitOrCredit] - e[debitOrCredit];
|
|
|
|
if (!Object.keys(returnEntries).includes(e.referenceName)) {
|
|
paymentAmount += amount;
|
|
} else {
|
|
creditNoteAmount += amount;
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
outStandingAmount: (entry[debitOrCredit] - entry[reverseDebitOrCredit]) - paymentAmount - creditNoteAmount,
|
|
creditNoteAmount
|
|
}
|
|
}
|
|
|
|
function getEntriesFor(party, againstVoucherType, againstVoucher) {
|
|
// TODO
|
|
return []
|
|
}
|
|
|
|
function getFutureEntries() {
|
|
return entries.filter(entry => entry.date > date);
|
|
}
|
|
|
|
function getReturnEntries() {
|
|
// TODO
|
|
return {};
|
|
}
|
|
|
|
function getPDC() {
|
|
return [];
|
|
}
|
|
|
|
async function getLedgerEntries() {
|
|
if (entries.length) {
|
|
return entries;
|
|
}
|
|
|
|
const partyType = reportType === 'Receivable' ? 'customer': 'supplier'
|
|
const partyList = (await frappe.db.getAll({
|
|
doctype: 'Party',
|
|
filters: {
|
|
[partyType]: 1
|
|
}
|
|
})).map(d => d.name);
|
|
|
|
return await frappe.db.getAll({
|
|
doctype: 'AccountingLedgerEntry',
|
|
fields: ['name', 'date', 'account', 'party',
|
|
'referenceType', 'referenceName',
|
|
'sum(debit) as debit', 'sum(credit) as credit'],
|
|
filters: {
|
|
party: ['in', partyList]
|
|
},
|
|
groupBy: ['referenceType', 'referenceName', 'party'],
|
|
orderBy: 'date'
|
|
});
|
|
}
|
|
}
|