feat: add series
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 9s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 9s
This commit is contained in:
parent
fbd423f84d
commit
329c69ec3d
1 changed files with 23 additions and 9 deletions
|
|
@ -503,6 +503,7 @@ export class StatsController extends Controller {
|
|||
select: {
|
||||
agentPrice: true,
|
||||
creditNote: true,
|
||||
createdAt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -546,6 +547,8 @@ export class StatsController extends Controller {
|
|||
const netProfit = creditNote ? 0 : precisionRound(finalPrice - expenses);
|
||||
|
||||
return {
|
||||
month: v.quotation.createdAt.getMonth() + 1,
|
||||
year: v.quotation.createdAt.getFullYear(),
|
||||
income,
|
||||
expenses,
|
||||
netProfit,
|
||||
|
|
@ -553,15 +556,26 @@ export class StatsController extends Controller {
|
|||
});
|
||||
});
|
||||
|
||||
return data.flat().reduce(
|
||||
(a, c) => {
|
||||
a.income += c.income;
|
||||
a.expenses += c.expenses;
|
||||
a.netProfit += c.netProfit;
|
||||
return a;
|
||||
},
|
||||
{ income: 0, expenses: 0, netProfit: 0 },
|
||||
);
|
||||
return data
|
||||
.flat()
|
||||
.reduce<{ income: number; expenses: 0; netProfit: 0; dataset: (typeof data)[number] }>(
|
||||
(a, c) => {
|
||||
const current = a.dataset.find((v) => v.month === c.month && v.year === c.year);
|
||||
|
||||
if (current) {
|
||||
current.income += c.income;
|
||||
current.expenses += c.expenses;
|
||||
current.netProfit += c.netProfit;
|
||||
}
|
||||
|
||||
a.income += c.income;
|
||||
a.expenses += c.expenses;
|
||||
a.netProfit += c.netProfit;
|
||||
|
||||
return a;
|
||||
},
|
||||
{ income: 0, expenses: 0, netProfit: 0, dataset: [] },
|
||||
);
|
||||
}
|
||||
|
||||
@Get("payment")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue