2022-04-19 05:59:36 +00:00
|
|
|
import frappe from 'fyo';
|
2021-11-04 10:31:26 +00:00
|
|
|
import { DateTime } from 'luxon';
|
2022-04-11 06:04:55 +00:00
|
|
|
import {
|
|
|
|
getFiscalYear,
|
|
|
|
getPeriodList,
|
|
|
|
} from '../FinancialStatements/FinancialStatements';
|
2019-11-22 17:43:32 +00:00
|
|
|
|
|
|
|
class Cashflow {
|
|
|
|
async run({ fromDate, toDate, periodicity }) {
|
2022-04-11 06:04:55 +00:00
|
|
|
const res = await frappe.db.getCashflow(fromDate, toDate);
|
2022-04-01 10:20:45 +00:00
|
|
|
let fiscalYear = await getFiscalYear();
|
|
|
|
let periodList = getPeriodList(fromDate, toDate, periodicity, fiscalYear);
|
2019-11-22 17:43:32 +00:00
|
|
|
|
2022-01-20 20:57:29 +00:00
|
|
|
let data = periodList.map((periodKey) => {
|
2019-11-22 17:43:32 +00:00
|
|
|
let monthYear = this.getMonthYear(periodKey, 'MMM yyyy');
|
2022-01-20 20:57:29 +00:00
|
|
|
let cashflowForPeriod = res.find((d) => d['month-year'] === monthYear);
|
2019-11-22 17:43:32 +00:00
|
|
|
if (cashflowForPeriod) {
|
|
|
|
cashflowForPeriod.periodKey = periodKey;
|
|
|
|
return cashflowForPeriod;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
inflow: 0,
|
|
|
|
outflow: 0,
|
|
|
|
periodKey,
|
2022-01-20 20:57:29 +00:00
|
|
|
'month-year': monthYear,
|
2019-11-22 17:43:32 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data,
|
2022-01-20 20:57:29 +00:00
|
|
|
periodList,
|
2019-11-22 17:43:32 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getMonthYear(periodKey, format) {
|
|
|
|
return DateTime.fromFormat(periodKey, format).toFormat('MM-yyyy');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 10:31:26 +00:00
|
|
|
export default Cashflow;
|