fix(billing): compute plan expiry with Jalali months
Server/plugin/support charges used Gregorian Date#setMonth, so 3 months from 1405/06/01 became 1405/09/02. Now add N Jalali months minus one day (1405/08/30).
This commit is contained in:
@@ -11,6 +11,7 @@ import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditService } from '../audit/audit.service';
|
||||
import { AdminNotifyService } from '../notifications/admin-notify.service';
|
||||
import {
|
||||
addIranPlanExpiry,
|
||||
formatIranDate,
|
||||
iranDaysUntil,
|
||||
iranYmd,
|
||||
@@ -204,7 +205,7 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
||||
if (!PLUGIN_PLAN_MONTHS.includes(planMonths as any)) {
|
||||
throw new BadRequestException('مدت اشتراک نامعتبر است');
|
||||
}
|
||||
expiresAt = this.addMonths(chargedAt, planMonths);
|
||||
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
|
||||
}
|
||||
|
||||
const plugin = await this.prisma.pluginSubscription.create({
|
||||
@@ -277,7 +278,7 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
||||
chargedAt &&
|
||||
planMonths
|
||||
) {
|
||||
expiresAt = this.addMonths(chargedAt, planMonths);
|
||||
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
|
||||
}
|
||||
|
||||
const plugin = await this.prisma.pluginSubscription.update({
|
||||
@@ -329,7 +330,7 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
||||
if (Number.isNaN(chargedAt.getTime())) {
|
||||
throw new BadRequestException('تاریخ شارژ نامعتبر است');
|
||||
}
|
||||
const expiresAt = this.addMonths(chargedAt, dto.planMonths);
|
||||
const expiresAt = addIranPlanExpiry(chargedAt, dto.planMonths);
|
||||
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.pluginSubscription.update({
|
||||
@@ -541,14 +542,6 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private addMonths(from: Date, months: number) {
|
||||
const d = new Date(from.getTime());
|
||||
const day = d.getDate();
|
||||
d.setMonth(d.getMonth() + months);
|
||||
if (d.getDate() < day) d.setDate(0);
|
||||
return d;
|
||||
}
|
||||
|
||||
private async requireTenant(tenantId: string) {
|
||||
const tenant = await this.prisma.tenant.findUnique({ where: { id: tenantId } });
|
||||
if (!tenant) throw new NotFoundException('نسخه یافت نشد');
|
||||
|
||||
Reference in New Issue
Block a user