mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: show P&L when either income or expense
This commit is contained in:
parent
e7b067e3c6
commit
f4e5f3d29b
@ -74,21 +74,65 @@ export class ProfitAndLoss extends AccountReport {
|
|||||||
async getReportDataFromRows(
|
async getReportDataFromRows(
|
||||||
incomeRows: ReportData,
|
incomeRows: ReportData,
|
||||||
expenseRows: ReportData,
|
expenseRows: ReportData,
|
||||||
incomeRoot: AccountTreeNode,
|
incomeRoot: AccountTreeNode | undefined,
|
||||||
expenseRoot: AccountTreeNode
|
expenseRoot: AccountTreeNode | undefined
|
||||||
): Promise<ReportData> {
|
): 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) {
|
if (!incomeRoot || !expenseRoot) {
|
||||||
return [];
|
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(
|
const totalIncome = await this.getTotalNode(
|
||||||
incomeRoot,
|
incomeRoot,
|
||||||
t`Total Income (Credit)`
|
t`Total Income (Credit)`
|
||||||
);
|
);
|
||||||
|
const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);
|
||||||
|
|
||||||
const totalExpense = await this.getTotalNode(
|
const totalExpense = await this.getTotalNode(
|
||||||
expenseRoot,
|
expenseRoot,
|
||||||
t`Total Expense (Debit)`
|
t`Total Expense (Debit)`
|
||||||
);
|
);
|
||||||
|
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);
|
||||||
|
|
||||||
const totalValueMap: ValueMap = new Map();
|
const totalValueMap: ValueMap = new Map();
|
||||||
for (const key of totalIncome.valueMap!.keys()) {
|
for (const key of totalIncome.valueMap!.keys()) {
|
||||||
@ -103,9 +147,6 @@ export class ProfitAndLoss extends AccountReport {
|
|||||||
level: 0,
|
level: 0,
|
||||||
} as AccountListNode;
|
} as AccountListNode;
|
||||||
|
|
||||||
const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);
|
|
||||||
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);
|
|
||||||
|
|
||||||
const totalProfitRow = this.getRowFromAccountListNode(totalProfit);
|
const totalProfitRow = this.getRowFromAccountListNode(totalProfit);
|
||||||
totalProfitRow.cells.forEach((c) => {
|
totalProfitRow.cells.forEach((c) => {
|
||||||
c.bold = true;
|
c.bold = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user