mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
de7e5ba807
- cause now most of it is different from what it was
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
import frappe from 'fyo';
|
|
import { DateTime } from 'luxon';
|
|
import {
|
|
getFiscalYear,
|
|
getPeriodList,
|
|
} from '../FinancialStatements/FinancialStatements';
|
|
|
|
class Cashflow {
|
|
async run({ fromDate, toDate, periodicity }) {
|
|
const res = await frappe.db.getCashflow(fromDate, toDate);
|
|
let fiscalYear = await getFiscalYear();
|
|
let periodList = getPeriodList(fromDate, toDate, periodicity, fiscalYear);
|
|
|
|
let data = periodList.map((periodKey) => {
|
|
let monthYear = this.getMonthYear(periodKey, 'MMM yyyy');
|
|
let cashflowForPeriod = res.find((d) => d['month-year'] === monthYear);
|
|
if (cashflowForPeriod) {
|
|
cashflowForPeriod.periodKey = periodKey;
|
|
return cashflowForPeriod;
|
|
}
|
|
return {
|
|
inflow: 0,
|
|
outflow: 0,
|
|
periodKey,
|
|
'month-year': monthYear,
|
|
};
|
|
});
|
|
|
|
return {
|
|
data,
|
|
periodList,
|
|
};
|
|
}
|
|
|
|
getMonthYear(periodKey, format) {
|
|
return DateTime.fromFormat(periodKey, format).toFormat('MM-yyyy');
|
|
}
|
|
}
|
|
|
|
export default Cashflow;
|