fix: error field ambigous

This commit is contained in:
Methapon2001 2025-09-17 10:42:35 +07:00
parent 2c790de606
commit 6598cd3bdf
3 changed files with 53 additions and 45 deletions

View file

@ -618,9 +618,22 @@ export class StatsController extends Controller {
startDate = dayjs(startDate).startOf("month").add(1, "month").toDate();
}
const invoices = await tx.invoice.findMany({
select: { id: true },
where: {
quotation: {
quotationStatus: { notIn: [QuotationStatus.Canceled] },
registeredBranch: { OR: permissionCondCompany(req.user) },
},
},
});
if (invoices.length === 0) return [];
return await Promise.all(
months.map(async (v) => {
const date = dayjs(v);
return {
month: date.format("MM"),
year: date.format("YYYY"),
@ -629,12 +642,7 @@ export class StatsController extends Controller {
_sum: { amount: true },
where: {
createdAt: { gte: v, lte: date.endOf("month").toDate() },
invoice: {
quotation: {
quotationStatus: { notIn: [QuotationStatus.Canceled] },
registeredBranch: { OR: permissionCondCompany(req.user) },
},
},
invoiceId: { in: invoices.map((v) => v.id) },
},
by: "paymentStatus",
})