add : notification after invoice creation
This commit is contained in:
@@ -6,9 +6,11 @@ import { BillsService } from "./bills.service";
|
|||||||
import { Bill } from "./entities/bill.entity";
|
import { Bill } from "./entities/bill.entity";
|
||||||
import { BusinessesModule } from "../businesses/businesses.module";
|
import { BusinessesModule } from "../businesses/businesses.module";
|
||||||
import { CompaniesModule } from "../companies/companies.module";
|
import { CompaniesModule } from "../companies/companies.module";
|
||||||
|
import { NotificationModule } from "../notifications/notifications.module";
|
||||||
|
import { InvoicesModule } from "../invoices/invoices.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [MikroOrmModule.forFeature([Bill]), CompaniesModule, BusinessesModule],
|
imports: [MikroOrmModule.forFeature([Bill]), CompaniesModule, BusinessesModule,NotificationModule,InvoicesModule],
|
||||||
controllers: [BillsController],
|
controllers: [BillsController],
|
||||||
providers: [BillsService],
|
providers: [BillsService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import { Company } from "../companies/entities/company.entity";
|
|||||||
import { CompaniesService } from "../companies/services/companies.service";
|
import { CompaniesService } from "../companies/services/companies.service";
|
||||||
import { InvoiceItem } from "../invoices/entities/invoice-item.entity";
|
import { InvoiceItem } from "../invoices/entities/invoice-item.entity";
|
||||||
import { Invoice } from "../invoices/entities/invoice.entity";
|
import { Invoice } from "../invoices/entities/invoice.entity";
|
||||||
|
import { NotificationQueue } from "../notifications/queue/notification.queue";
|
||||||
|
import { InvoicesService } from "../invoices/providers/invoices.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillsService {
|
export class BillsService {
|
||||||
@@ -25,7 +27,10 @@ export class BillsService {
|
|||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
private readonly companiesService: CompaniesService,
|
private readonly companiesService: CompaniesService,
|
||||||
private readonly billRepository: BillsRepository,
|
private readonly billRepository: BillsRepository,
|
||||||
) {}
|
private readonly notificationQueue: NotificationQueue,
|
||||||
|
private readonly invoicesService: InvoicesService,
|
||||||
|
|
||||||
|
) { }
|
||||||
|
|
||||||
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
||||||
const { values, waterRate, dueDays } = dto;
|
const { values, waterRate, dueDays } = dto;
|
||||||
@@ -69,8 +74,31 @@ export class BillsService {
|
|||||||
totalPrice,
|
totalPrice,
|
||||||
invoice,
|
invoice,
|
||||||
});
|
});
|
||||||
|
|
||||||
invoice.items.add(invoiceItem);
|
invoice.items.add(invoiceItem);
|
||||||
|
|
||||||
|
await this.notificationQueue.addInvoiceCreationNotification(company.user.id, {
|
||||||
|
invoiceId: invoice.numericId.toString(),
|
||||||
|
dueDate: invoice.dueDate,
|
||||||
|
createDate: invoice.createdAt,
|
||||||
|
price: new Decimal(invoice.totalPrice).toNumber(),
|
||||||
|
userPhone: company.user.phone,
|
||||||
|
userEmail: company.user.email,
|
||||||
|
items: invoiceItem.name,
|
||||||
|
paidAt: invoice.paidAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.invoicesService.scheduleInvoiceJobs(invoice, {
|
||||||
|
companyId: company.id,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
name: invoiceItem.name,
|
||||||
|
count: invoiceItem.count,
|
||||||
|
unitPrice: new Decimal(invoiceItem.unitPrice).toNumber(),
|
||||||
|
discount: new Decimal(invoiceItem.discount).toNumber(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
em.persist(invoice);
|
em.persist(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ export class InvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//*********************************** */
|
//*********************************** */
|
||||||
private async scheduleInvoiceJobs(invoice: Invoice, createDto?: CreateInvoiceDto | UpdateInvoiceDto) {
|
async scheduleInvoiceJobs(invoice: Invoice, createDto?: CreateInvoiceDto | UpdateInvoiceDto) {
|
||||||
// Add to queue for billing reminder
|
// Add to queue for billing reminder
|
||||||
await this.invoiceQueue.add(
|
await this.invoiceQueue.add(
|
||||||
INVOICE.REMINDER_JOB_NAME,
|
INVOICE.REMINDER_JOB_NAME,
|
||||||
|
|||||||
Reference in New Issue
Block a user