Merge branch 'develop'
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
This commit is contained in:
commit
c6e4959e84
1 changed files with 93 additions and 18 deletions
|
|
@ -32,9 +32,19 @@ export class StatsController extends Controller {
|
||||||
@Query() endDate?: Date,
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
this.setHeader("Content-Type", "text/csv");
|
this.setHeader("Content-Type", "text/csv");
|
||||||
return json2csv(await this.quotationReport(req, limit, startDate, endDate), {
|
return json2csv(
|
||||||
useDateIso8601Format: true,
|
await this.quotationReport(req, limit, startDate, endDate).then((v) =>
|
||||||
});
|
v.map((v) => ({
|
||||||
|
...v,
|
||||||
|
customerBranch: {
|
||||||
|
...v.customerBranch,
|
||||||
|
customerType: v.customerBranch.customer.customerType,
|
||||||
|
customer: undefined,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
{ useDateIso8601Format: true },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("quotation")
|
@Get("quotation")
|
||||||
|
|
@ -48,6 +58,10 @@ export class StatsController extends Controller {
|
||||||
select: {
|
select: {
|
||||||
code: true,
|
code: true,
|
||||||
quotationStatus: true,
|
quotationStatus: true,
|
||||||
|
customerBranch: {
|
||||||
|
include: { customer: true },
|
||||||
|
},
|
||||||
|
finalPrice: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
},
|
},
|
||||||
|
|
@ -63,8 +77,11 @@ export class StatsController extends Controller {
|
||||||
document: "quotation",
|
document: "quotation",
|
||||||
code: v.code,
|
code: v.code,
|
||||||
status: v.quotationStatus,
|
status: v.quotationStatus,
|
||||||
|
amount: v.finalPrice,
|
||||||
createdAt: v.createdAt,
|
createdAt: v.createdAt,
|
||||||
updatedAt: v.updatedAt,
|
updatedAt: v.updatedAt,
|
||||||
|
|
||||||
|
customerBranch: v.customerBranch,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,9 +93,21 @@ export class StatsController extends Controller {
|
||||||
@Query() endDate?: Date,
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
this.setHeader("Content-Type", "text/csv");
|
this.setHeader("Content-Type", "text/csv");
|
||||||
return json2csv(await this.invoiceReport(req, limit, startDate, endDate), {
|
return json2csv(
|
||||||
|
await this.invoiceReport(req, limit, startDate, endDate).then((v) =>
|
||||||
|
v.map((v) => ({
|
||||||
|
...v,
|
||||||
|
customerBranch: {
|
||||||
|
...v.customerBranch,
|
||||||
|
customerType: v.customerBranch.customer.customerType,
|
||||||
|
customer: undefined,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
{
|
||||||
useDateIso8601Format: true,
|
useDateIso8601Format: true,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("invoice")
|
@Get("invoice")
|
||||||
|
|
@ -91,6 +120,11 @@ export class StatsController extends Controller {
|
||||||
const record = await prisma.invoice.findMany({
|
const record = await prisma.invoice.findMany({
|
||||||
select: {
|
select: {
|
||||||
code: true,
|
code: true,
|
||||||
|
quotation: {
|
||||||
|
select: {
|
||||||
|
customerBranch: { include: { customer: true } },
|
||||||
|
},
|
||||||
|
},
|
||||||
payment: {
|
payment: {
|
||||||
select: {
|
select: {
|
||||||
paymentStatus: true,
|
paymentStatus: true,
|
||||||
|
|
@ -116,6 +150,8 @@ export class StatsController extends Controller {
|
||||||
status: v.payment?.paymentStatus,
|
status: v.payment?.paymentStatus,
|
||||||
amount: v.amount,
|
amount: v.amount,
|
||||||
createdAt: v.createdAt,
|
createdAt: v.createdAt,
|
||||||
|
|
||||||
|
customerBranch: v.quotation.customerBranch,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,9 +163,21 @@ export class StatsController extends Controller {
|
||||||
@Query() endDate?: Date,
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
this.setHeader("Content-Type", "text/csv");
|
this.setHeader("Content-Type", "text/csv");
|
||||||
return json2csv(await this.receiptReport(req, limit, startDate, endDate), {
|
return json2csv(
|
||||||
|
await this.receiptReport(req, limit, startDate, endDate).then((v) =>
|
||||||
|
v.map((v) => ({
|
||||||
|
...v,
|
||||||
|
customerBranch: {
|
||||||
|
...v.customerBranch,
|
||||||
|
customerType: v.customerBranch.customer.customerType,
|
||||||
|
customer: undefined,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
{
|
||||||
useDateIso8601Format: true,
|
useDateIso8601Format: true,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("receipt")
|
@Get("receipt")
|
||||||
|
|
@ -142,6 +190,14 @@ export class StatsController extends Controller {
|
||||||
const record = await prisma.payment.findMany({
|
const record = await prisma.payment.findMany({
|
||||||
select: {
|
select: {
|
||||||
code: true,
|
code: true,
|
||||||
|
invoice: {
|
||||||
|
select: {
|
||||||
|
quotation: {
|
||||||
|
select: { customerBranch: { include: { customer: true } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
amount: true,
|
||||||
paymentStatus: true,
|
paymentStatus: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
},
|
},
|
||||||
|
|
@ -162,8 +218,11 @@ export class StatsController extends Controller {
|
||||||
return record.map((v) => ({
|
return record.map((v) => ({
|
||||||
document: "receipt",
|
document: "receipt",
|
||||||
code: v.code,
|
code: v.code,
|
||||||
|
amount: v.amount,
|
||||||
status: v.paymentStatus,
|
status: v.paymentStatus,
|
||||||
createdAt: v.createdAt,
|
createdAt: v.createdAt,
|
||||||
|
|
||||||
|
customerBranch: v.invoice.quotation.customerBranch,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,6 +503,7 @@ export class StatsController extends Controller {
|
||||||
select: {
|
select: {
|
||||||
agentPrice: true,
|
agentPrice: true,
|
||||||
creditNote: true,
|
creditNote: true,
|
||||||
|
createdAt: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -487,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,
|
||||||
|
|
@ -494,14 +556,27 @@ 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;
|
||||||
|
} else {
|
||||||
|
a.dataset.push(c);
|
||||||
|
}
|
||||||
|
|
||||||
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