diff --git a/backend/src/services/PaymentGatewayServices/PaymentGatewayServices.ts b/backend/src/services/PaymentGatewayServices/PaymentGatewayServices.ts index b25d399..ccf3f76 100644 --- a/backend/src/services/PaymentGatewayServices/PaymentGatewayServices.ts +++ b/backend/src/services/PaymentGatewayServices/PaymentGatewayServices.ts @@ -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 { @@ -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"