Skip to content

Commit

Permalink
correct recurrence when receiving payment - fix #79
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jul 25, 2024
1 parent c292d88 commit d732507
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import { Request, Response } from "express";
import { Op } from "sequelize";
import moment from "moment";
import AppError from "../../errors/AppError";
import GetSuperSettingService from "../SettingServices/GetSuperSettingService";
import {
Expand Down Expand Up @@ -116,12 +117,30 @@ export const processInvoicePaid = async (invoice: Invoices) => {
invoice.company || (await Company.findByPk(invoice.companyId));

if (company) {
const expiresAt = new Date(company.dueDate);
expiresAt.setDate(expiresAt.getDate() + 30);
const date = expiresAt.toISOString().split("T")[0];
const currentDueDate = moment(company.dueDate);
let { dueDate } = company;

switch (company.recurrence) {
case "BIMESTRAL":
dueDate = currentDueDate.add(2, "month").format("YYYY-MM-DD");
break;
case "TRIMESTRAL":
dueDate = currentDueDate.add(3, "month").format("YYYY-MM-DD");
break;
case "SEMESTRAL":
dueDate = currentDueDate.add(6, "month").format("YYYY-MM-DD");
break;
case "ANUAL":
dueDate = currentDueDate.add(12, "month").format("YYYY-MM-DD");
break;
case "MENSAL":
default:
dueDate = currentDueDate.add(1, "month").format("YYYY-MM-DD");
break;
}

await company.update({
dueDate: date
dueDate
});
await invoice.update({
status: "paid"
Expand Down

0 comments on commit d732507

Please sign in to comment.