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: {
|
select: {
|
||||||
agentPrice: true,
|
agentPrice: true,
|
||||||
creditNote: true,
|
creditNote: true,
|
||||||
|
createdAt: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -546,6 +547,8 @@ export class StatsController extends Controller {
|
||||||
const netProfit = creditNote ? 0 : precisionRound(finalPrice - expenses);
|
const netProfit = creditNote ? 0 : precisionRound(finalPrice - expenses);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
month: v.quotation.createdAt.getMonth() + 1,
|
||||||
|
year: v.quotation.createdAt.getFullYear(),
|
||||||
income,
|
income,
|
||||||
expenses,
|
expenses,
|
||||||
netProfit,
|
netProfit,
|
||||||
|
|
@ -553,14 +556,25 @@ export class StatsController extends Controller {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.flat().reduce(
|
return data
|
||||||
|
.flat()
|
||||||
|
.reduce<{ income: number; expenses: 0; netProfit: 0; dataset: (typeof data)[number] }>(
|
||||||
(a, c) => {
|
(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.income += c.income;
|
||||||
a.expenses += c.expenses;
|
a.expenses += c.expenses;
|
||||||
a.netProfit += c.netProfit;
|
a.netProfit += c.netProfit;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
{ income: 0, expenses: 0, netProfit: 0 },
|
{ income: 0, expenses: 0, netProfit: 0, dataset: [] },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue