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 { BusinessesModule } from "../businesses/businesses.module";
|
||||
import { CompaniesModule } from "../companies/companies.module";
|
||||
import { NotificationModule } from "../notifications/notifications.module";
|
||||
import { InvoicesModule } from "../invoices/invoices.module";
|
||||
|
||||
@Module({
|
||||
imports: [MikroOrmModule.forFeature([Bill]), CompaniesModule, BusinessesModule],
|
||||
imports: [MikroOrmModule.forFeature([Bill]), CompaniesModule, BusinessesModule,NotificationModule,InvoicesModule],
|
||||
controllers: [BillsController],
|
||||
providers: [BillsService],
|
||||
})
|
||||
|
||||
@@ -18,6 +18,8 @@ import { Company } from "../companies/entities/company.entity";
|
||||
import { CompaniesService } from "../companies/services/companies.service";
|
||||
import { InvoiceItem } from "../invoices/entities/invoice-item.entity";
|
||||
import { Invoice } from "../invoices/entities/invoice.entity";
|
||||
import { NotificationQueue } from "../notifications/queue/notification.queue";
|
||||
import { InvoicesService } from "../invoices/providers/invoices.service";
|
||||
|
||||
@Injectable()
|
||||
export class BillsService {
|
||||
@@ -25,7 +27,10 @@ export class BillsService {
|
||||
private readonly em: EntityManager,
|
||||
private readonly companiesService: CompaniesService,
|
||||
private readonly billRepository: BillsRepository,
|
||||
) {}
|
||||
private readonly notificationQueue: NotificationQueue,
|
||||
private readonly invoicesService: InvoicesService,
|
||||
|
||||
) { }
|
||||
|
||||
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
||||
const { values, waterRate, dueDays } = dto;
|
||||
@@ -69,8 +74,31 @@ export class BillsService {
|
||||
totalPrice,
|
||||
invoice,
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
await this.invoiceQueue.add(
|
||||
INVOICE.REMINDER_JOB_NAME,
|
||||
|
||||
Reference in New Issue
Block a user