From 4959f1e68fcdbe3a331dfc0961b22737afbc2f03 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 18 Feb 2026 09:12:15 +0330 Subject: [PATCH] add: bill title --- src/modules/bills/bills.service.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/modules/bills/bills.service.ts b/src/modules/bills/bills.service.ts index 7c63c56..e050be5 100644 --- a/src/modules/bills/bills.service.ts +++ b/src/modules/bills/bills.service.ts @@ -37,13 +37,13 @@ export class BillsService { ) {} async createWaterBill(dto: CreateWaterBillDto, business: Business) { - const { values, waterRate, dueDays } = dto; + const { values, waterRate, dueDays, title } = dto; const em = this.em.fork(); try { await em.begin(); - const bill = em.create(Bill, { type: BillType.WATER_BILL, business, title: dto.title }); + const bill = em.create(Bill, { type: BillType.WATER_BILL, business, title }); em.persist(bill); const dueDate = dayjs().add(dueDays, "day").toDate(); @@ -63,6 +63,10 @@ export class BillsService { throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND); } + if (totalPrice.eq(0)) { + continue; + } + const invoice = em.create(Invoice, { company, totalPrice, @@ -74,7 +78,7 @@ export class BillsService { }); const invoiceItem = em.create(InvoiceItem, { - name: "قبض آب", + name: title, count: 1, unitPrice: totalPrice, discount: new Decimal(0), @@ -160,22 +164,24 @@ export class BillsService { } async createChargeBill(dto: CreateChargeBillDto, business: Business) { - const { chargeRate, dueDays } = dto; + const { chargeRate, dueDays, title } = dto; const em = this.em.fork(); try { await em.begin(); - const bill = em.create(Bill, { type: BillType.MONTHLY_CHARGE, business, title: dto.title }); + const bill = em.create(Bill, { type: BillType.MONTHLY_CHARGE, business, title }); em.persist(bill); const dueDate = dayjs().add(dueDays, "day").toDate(); const companies = await this.companiesService.findAllBybusinessId(business.id, em); for (const company of companies) { - const subtotal = new Decimal(chargeRate).mul(company.metrage); - const totalPrice = subtotal; + const totalPrice = new Decimal(chargeRate).mul(company.metrage); + if (totalPrice.eq(0)) { + continue; + } const invoice = em.create(Invoice, { company, totalPrice, @@ -187,9 +193,9 @@ export class BillsService { }); const invoiceItem = em.create(InvoiceItem, { - name: "قبض شارژ", + name: title, count: 1, - unitPrice: subtotal, + unitPrice: totalPrice, discount: new Decimal(0), totalPrice, invoice,