2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

fix: show P&L when either income or expense

This commit is contained in:
18alantom 2022-07-26 19:05:52 +05:30
parent e7b067e3c6
commit f4e5f3d29b

View File

@ -74,21 +74,65 @@ export class ProfitAndLoss extends AccountReport {
async getReportDataFromRows(
incomeRows: ReportData,
expenseRows: ReportData,
incomeRoot: AccountTreeNode,
expenseRoot: AccountTreeNode
incomeRoot: AccountTreeNode | undefined,
expenseRoot: AccountTreeNode | undefined
): Promise<ReportData> {
if (incomeRoot && !expenseRoot) {
return await this.getIncomeOrExpenseRows(
incomeRoot,
incomeRows,
t`Total Income (Credit)`
);
}
if (expenseRoot && !incomeRoot) {
return await this.getIncomeOrExpenseRows(
expenseRoot,
expenseRows,
t`Total Income (Credit)`
);
}
if (!incomeRoot || !expenseRoot) {
return [];
}
return await this.getIncomeAndExpenseRows(
incomeRows,
expenseRows,
incomeRoot,
expenseRoot
);
}
async getIncomeOrExpenseRows(
root: AccountTreeNode,
rows: ReportData,
totalRowName: string
): Promise<ReportData> {
const total = await this.getTotalNode(root, totalRowName);
const totalRow = this.getRowFromAccountListNode(total);
return [rows, totalRow].flat();
}
async getIncomeAndExpenseRows(
incomeRows: ReportData,
expenseRows: ReportData,
incomeRoot: AccountTreeNode,
expenseRoot: AccountTreeNode
) {
const totalIncome = await this.getTotalNode(
incomeRoot,
t`Total Income (Credit)`
);
const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);
const totalExpense = await this.getTotalNode(
expenseRoot,
t`Total Expense (Debit)`
);
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);
const totalValueMap: ValueMap = new Map();
for (const key of totalIncome.valueMap!.keys()) {
@ -103,9 +147,6 @@ export class ProfitAndLoss extends AccountReport {
level: 0,
} as AccountListNode;
const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);
const totalProfitRow = this.getRowFromAccountListNode(totalProfit);
totalProfitRow.cells.forEach((c) => {
c.bold = true;