fix: bug in the send reminder send
This commit is contained in:
@@ -15,8 +15,6 @@ import { InvoiceStatus } from "../enums/invoice-status.enum";
|
||||
@Processor(INVOICE.INVOICE_QUEUE_NAME)
|
||||
export class InvoiceProcessor extends WorkerProcessor {
|
||||
protected readonly logger = new Logger(InvoiceProcessor.name);
|
||||
private readonly FINE_PERCENTAGE = 0.01;
|
||||
private readonly MAX_DAYS_OVERDUE = 1;
|
||||
|
||||
constructor(
|
||||
@InjectQueue(INVOICE.INVOICE_QUEUE_NAME) private readonly invoiceQueue: Queue,
|
||||
@@ -88,7 +86,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
//********************************** */
|
||||
|
||||
private isInvoiceOverdueForCancellation(invoice: Invoice): boolean {
|
||||
const fiveDaysAfterDueDate = dayjs(invoice.dueDate).add(this.MAX_DAYS_OVERDUE, "day");
|
||||
const fiveDaysAfterDueDate = dayjs(invoice.dueDate).add(INVOICE.MAX_DAYS_AFTER_OVERDUE, "day");
|
||||
return dayjs().isAfter(fiveDaysAfterDueDate);
|
||||
}
|
||||
//********************************** */
|
||||
@@ -96,7 +94,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
private async cancelOverdueInvoice(invoice: Invoice, queryRunner: QueryRunner) {
|
||||
invoice.status = InvoiceStatus.CANCELLED;
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
this.logger.log(`Invoice ${invoice.id} has been cancelled as it is more than 5 days overdue.`);
|
||||
this.logger.log(`Invoice ${invoice.id} has been cancelled as it is more than 7 days overdue.`);
|
||||
}
|
||||
//********************************** */
|
||||
|
||||
@@ -105,11 +103,11 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
const dueDate = dayjs(invoice.dueDate);
|
||||
|
||||
if (today.isAfter(dueDate)) {
|
||||
const daysOverdue = Math.min(today.diff(dueDate, "day"), this.MAX_DAYS_OVERDUE);
|
||||
const daysOverdue = Math.min(today.diff(dueDate, "day"), INVOICE.MAX_DAYS_AFTER_OVERDUE);
|
||||
|
||||
const currentFine = invoice.lateFee || new Decimal(0);
|
||||
const totalDaysFineShouldBeApplied = daysOverdue;
|
||||
const finePerDay = new Decimal(invoice.totalPrice).mul(this.FINE_PERCENTAGE);
|
||||
const finePerDay = new Decimal(invoice.totalPrice).mul(INVOICE.FINE_PERCENTAGE);
|
||||
const newTotalFine = finePerDay.mul(totalDaysFineShouldBeApplied);
|
||||
|
||||
if (newTotalFine.gt(currentFine)) {
|
||||
|
||||
Reference in New Issue
Block a user