add: bill title
This commit is contained in:
@@ -37,13 +37,13 @@ export class BillsService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
||||||
const { values, waterRate, dueDays } = dto;
|
const { values, waterRate, dueDays, title } = dto;
|
||||||
const em = this.em.fork();
|
const em = this.em.fork();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await em.begin();
|
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);
|
em.persist(bill);
|
||||||
const dueDate = dayjs().add(dueDays, "day").toDate();
|
const dueDate = dayjs().add(dueDays, "day").toDate();
|
||||||
|
|
||||||
@@ -63,6 +63,10 @@ export class BillsService {
|
|||||||
throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND);
|
throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (totalPrice.eq(0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const invoice = em.create(Invoice, {
|
const invoice = em.create(Invoice, {
|
||||||
company,
|
company,
|
||||||
totalPrice,
|
totalPrice,
|
||||||
@@ -74,7 +78,7 @@ export class BillsService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const invoiceItem = em.create(InvoiceItem, {
|
const invoiceItem = em.create(InvoiceItem, {
|
||||||
name: "قبض آب",
|
name: title,
|
||||||
count: 1,
|
count: 1,
|
||||||
unitPrice: totalPrice,
|
unitPrice: totalPrice,
|
||||||
discount: new Decimal(0),
|
discount: new Decimal(0),
|
||||||
@@ -160,22 +164,24 @@ export class BillsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createChargeBill(dto: CreateChargeBillDto, business: Business) {
|
async createChargeBill(dto: CreateChargeBillDto, business: Business) {
|
||||||
const { chargeRate, dueDays } = dto;
|
const { chargeRate, dueDays, title } = dto;
|
||||||
const em = this.em.fork();
|
const em = this.em.fork();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await em.begin();
|
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);
|
em.persist(bill);
|
||||||
const dueDate = dayjs().add(dueDays, "day").toDate();
|
const dueDate = dayjs().add(dueDays, "day").toDate();
|
||||||
|
|
||||||
const companies = await this.companiesService.findAllBybusinessId(business.id, em);
|
const companies = await this.companiesService.findAllBybusinessId(business.id, em);
|
||||||
|
|
||||||
for (const company of companies) {
|
for (const company of companies) {
|
||||||
const subtotal = new Decimal(chargeRate).mul(company.metrage);
|
const totalPrice = new Decimal(chargeRate).mul(company.metrage);
|
||||||
const totalPrice = subtotal;
|
|
||||||
|
|
||||||
|
if (totalPrice.eq(0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const invoice = em.create(Invoice, {
|
const invoice = em.create(Invoice, {
|
||||||
company,
|
company,
|
||||||
totalPrice,
|
totalPrice,
|
||||||
@@ -187,9 +193,9 @@ export class BillsService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const invoiceItem = em.create(InvoiceItem, {
|
const invoiceItem = em.create(InvoiceItem, {
|
||||||
name: "قبض شارژ",
|
name: title,
|
||||||
count: 1,
|
count: 1,
|
||||||
unitPrice: subtotal,
|
unitPrice: totalPrice,
|
||||||
discount: new Decimal(0),
|
discount: new Decimal(0),
|
||||||
totalPrice,
|
totalPrice,
|
||||||
invoice,
|
invoice,
|
||||||
|
|||||||
Reference in New Issue
Block a user