add: bill title

This commit is contained in:
2026-02-18 09:12:15 +03:30
parent a3be4e9ea9
commit 4959f1e68f
+15 -9
View File
@@ -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,