add: title to bill

This commit is contained in:
2026-02-18 09:01:35 +03:30
parent a9c6854772
commit a3be4e9ea9
6 changed files with 58 additions and 9 deletions
+17 -7
View File
@@ -24,6 +24,9 @@ import { IFile } from "../utils/interfaces/IFile";
@Injectable()
export class BillsService {
readonly SEWAGE_RATE = 0.3;
readonly TAX_RATE = 0.1;
constructor(
private readonly em: EntityManager,
private readonly companiesService: CompaniesService,
@@ -40,7 +43,7 @@ export class BillsService {
try {
await em.begin();
const bill = em.create(Bill, { type: BillType.WATER_BILL, business });
const bill = em.create(Bill, { type: BillType.WATER_BILL, business, title: dto.title });
em.persist(bill);
const dueDate = dayjs().add(dueDays, "day").toDate();
@@ -50,10 +53,10 @@ export class BillsService {
for (const value of values) {
const waterCost = new Decimal(waterRate).mul(value.waterUsage);
const sewageCost = waterCost.mul(0.3);
const sewageCost = waterCost.mul(this.SEWAGE_RATE);
const subtotal = waterCost.plus(sewageCost);
const tax = subtotal.mul(0.1);
const tax = subtotal.mul(this.TAX_RATE);
const totalPrice = subtotal.plus(tax);
const company = companyMap.get(value.companyId);
if (!company) {
@@ -72,7 +75,7 @@ export class BillsService {
const invoiceItem = em.create(InvoiceItem, {
name: "قبض آب",
count: value.waterUsage,
count: 1,
unitPrice: totalPrice,
discount: new Decimal(0),
totalPrice,
@@ -83,9 +86,13 @@ export class BillsService {
em.persist(invoice);
}
await em.flush();
await em.commit();
// Ensure bill.id is available
if (!bill.id) {
await em.refresh(bill);
}
await this.addInvoiceReminderJobs(bill.id);
return bill;
@@ -159,7 +166,7 @@ export class BillsService {
try {
await em.begin();
const bill = em.create(Bill, { type: BillType.MONTHLY_CHARGE, business });
const bill = em.create(Bill, { type: BillType.MONTHLY_CHARGE, business, title: dto.title });
em.persist(bill);
const dueDate = dayjs().add(dueDays, "day").toDate();
@@ -192,8 +199,11 @@ export class BillsService {
em.persist(invoice);
}
await em.flush();
await em.commit();
// Ensure bill.id is available
if (!bill.id) {
await em.refresh(bill);
}
await this.addInvoiceReminderJobs(bill.id);