feat: add customer data to report
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 9s

This commit is contained in:
Methapon2001 2025-03-06 15:19:27 +07:00
parent 26c671b032
commit fbd423f84d

View file

@ -32,9 +32,19 @@ export class StatsController extends Controller {
@Query() endDate?: Date,
) {
this.setHeader("Content-Type", "text/csv");
return json2csv(await this.quotationReport(req, limit, startDate, endDate), {
useDateIso8601Format: true,
});
return json2csv(
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")
@ -48,6 +58,10 @@ export class StatsController extends Controller {
select: {
code: true,
quotationStatus: true,
customerBranch: {
select: { customer: true },
},
finalPrice: true,
createdAt: true,
updatedAt: true,
},
@ -63,8 +77,11 @@ export class StatsController extends Controller {
document: "quotation",
code: v.code,
status: v.quotationStatus,
amount: v.finalPrice,
createdAt: v.createdAt,
updatedAt: v.updatedAt,
customerBranch: v.customerBranch,
}));
}
@ -76,9 +93,21 @@ export class StatsController extends Controller {
@Query() endDate?: Date,
) {
this.setHeader("Content-Type", "text/csv");
return json2csv(await this.invoiceReport(req, limit, startDate, endDate), {
useDateIso8601Format: true,
});
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,
},
);
}
@Get("invoice")
@ -91,6 +120,11 @@ export class StatsController extends Controller {
const record = await prisma.invoice.findMany({
select: {
code: true,
quotation: {
select: {
customerBranch: { select: { customer: true } },
},
},
payment: {
select: {
paymentStatus: true,
@ -116,6 +150,8 @@ export class StatsController extends Controller {
status: v.payment?.paymentStatus,
amount: v.amount,
createdAt: v.createdAt,
customerBranch: v.quotation.customerBranch,
}));
}
@ -127,9 +163,21 @@ export class StatsController extends Controller {
@Query() endDate?: Date,
) {
this.setHeader("Content-Type", "text/csv");
return json2csv(await this.receiptReport(req, limit, startDate, endDate), {
useDateIso8601Format: true,
});
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,
},
);
}
@Get("receipt")
@ -142,6 +190,14 @@ export class StatsController extends Controller {
const record = await prisma.payment.findMany({
select: {
code: true,
invoice: {
select: {
quotation: {
select: { customerBranch: { select: { customer: true } } },
},
},
},
amount: true,
paymentStatus: true,
createdAt: true,
},
@ -162,8 +218,11 @@ export class StatsController extends Controller {
return record.map((v) => ({
document: "receipt",
code: v.code,
amount: v.amount,
status: v.paymentStatus,
createdAt: v.createdAt,
customerBranch: v.invoice.quotation.customerBranch,
}));
}