changes 1
This commit is contained in:
@@ -85,7 +85,7 @@ export class CashPaymentsService {
|
||||
paidAmount: dto.paidAmount ?? dto.amount,
|
||||
transferDate: new Date(dto.transferDate),
|
||||
transferTime: dto.transferTime.trim(),
|
||||
trackingNumber: dto.trackingNumber.trim(),
|
||||
trackingNumber: dto.trackingNumber?.trim() || null,
|
||||
destinationAccountId: dto.destinationAccountId,
|
||||
receiptImage: dto.receiptImage || null,
|
||||
notes: dto.notes?.trim() || null,
|
||||
|
||||
@@ -29,9 +29,10 @@ export class SubmitCashReceiptDto {
|
||||
@MinLength(1)
|
||||
transferTime!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MinLength(1)
|
||||
trackingNumber!: string;
|
||||
trackingNumber?: string;
|
||||
|
||||
@IsString()
|
||||
destinationAccountId!: string;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { calculateCheckRass, invoiceAnchorDate } from './check-rass';
|
||||
|
||||
const checks = [
|
||||
{ amount: 100, dueDate: '2026-11-01T00:00:00.000Z' },
|
||||
{ amount: 100, dueDate: '2026-12-01T00:00:00.000Z' },
|
||||
];
|
||||
|
||||
describe('invoiceAnchorDate', () => {
|
||||
const createdAt = new Date('2026-09-01T06:00:00.000Z');
|
||||
|
||||
it('uses the latest invoice issue, not order creation', () => {
|
||||
const firstIssue = new Date('2026-10-01T08:00:00.000Z');
|
||||
const reissue = new Date('2026-10-05T08:00:00.000Z');
|
||||
expect(
|
||||
invoiceAnchorDate(createdAt, [
|
||||
{ toStatus: 'pricing', changedAt: new Date('2026-09-20T08:00:00.000Z') },
|
||||
{ toStatus: 'awaiting_settlement', changedAt: firstIssue },
|
||||
{ toStatus: 'pricing', changedAt: new Date('2026-10-04T08:00:00.000Z') },
|
||||
{ toStatus: 'awaiting_settlement', changedAt: reissue },
|
||||
]),
|
||||
).toEqual(reissue);
|
||||
});
|
||||
|
||||
it('falls back to the order creation date when no invoice was issued', () => {
|
||||
expect(
|
||||
invoiceAnchorDate(createdAt, [
|
||||
{ toStatus: 'awaiting_review', changedAt: createdAt },
|
||||
]),
|
||||
).toEqual(createdAt);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateCheckRass', () => {
|
||||
const invoice = new Date('2026-10-01T08:00:00.000Z');
|
||||
|
||||
it('stays the same when the calendar day changes but the invoice date does not', () => {
|
||||
const onIssueDay = calculateCheckRass(checks, invoice);
|
||||
const stillOnInvoice = calculateCheckRass(checks, invoice);
|
||||
expect(stillOnInvoice).toEqual(onIssueDay);
|
||||
expect(onIssueDay.rassDays).toBe(46);
|
||||
expect(onIssueDay.rassDate).toBe('2026-11-16T00:00:00.000Z');
|
||||
});
|
||||
|
||||
it('is shorter when measured from a later day than the invoice', () => {
|
||||
const fromInvoice = calculateCheckRass(checks, invoice);
|
||||
const fromLater = calculateCheckRass(
|
||||
checks,
|
||||
new Date('2026-10-20T08:00:00.000Z'),
|
||||
);
|
||||
expect(fromLater.rassDays).toBeLessThan(fromInvoice.rassDays);
|
||||
});
|
||||
});
|
||||
@@ -19,9 +19,27 @@ import {
|
||||
tehranCalendarDay,
|
||||
} from './tehran-time';
|
||||
|
||||
/** وضعیتی که فاکتور قیمتگذاریشده برای مشتری ارسال میشود. */
|
||||
const INVOICE_ISSUED_STATUS = 'awaiting_settlement';
|
||||
|
||||
/**
|
||||
* مبدأ راس چک، تاریخ صدور فاکتور است نه امروز و نه تاریخ ثبت پیشسفارش.
|
||||
* اگر فاکتور دوباره ارسال شده باشد، آخرین صدور ملاک است.
|
||||
*/
|
||||
export function invoiceAnchorDate(
|
||||
createdAt: Date,
|
||||
history: { toStatus: string; changedAt: Date }[] = [],
|
||||
): Date {
|
||||
for (let i = history.length - 1; i >= 0; i -= 1) {
|
||||
const row = history[i];
|
||||
if (row?.toStatus === INVOICE_ISSUED_STATUS) return row.changedAt;
|
||||
}
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
export function calculateCheckRass(
|
||||
checks: CheckRassInput[],
|
||||
baseDate: Date = new Date(),
|
||||
baseDate: Date,
|
||||
): CheckRassResult {
|
||||
if (checks.length === 0) {
|
||||
return {
|
||||
|
||||
@@ -8,6 +8,18 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { resolveJwtSecret } from '../common/utils/jwt-secret';
|
||||
|
||||
function normalizeMontactToken(raw?: string): string | undefined {
|
||||
if (!raw) return undefined;
|
||||
let t = raw.trim();
|
||||
if (
|
||||
(t.startsWith('"') && t.endsWith('"')) ||
|
||||
(t.startsWith("'") && t.endsWith("'"))
|
||||
) {
|
||||
t = t.slice(1, -1).trim();
|
||||
}
|
||||
return t.length > 0 ? t : undefined;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class MontactAuthGuard implements CanActivate {
|
||||
constructor(
|
||||
@@ -24,7 +36,9 @@ export class MontactAuthGuard implements CanActivate {
|
||||
throw new UnauthorizedException('توکن نامعتبر یا منقضی شده است');
|
||||
}
|
||||
const token = authHeader.slice(7).trim();
|
||||
const montactToken = this.config.get<string>('MONTACT_API_TOKEN')?.trim();
|
||||
const montactToken = normalizeMontactToken(
|
||||
this.config.get<string>('MONTACT_API_TOKEN'),
|
||||
);
|
||||
if (montactToken && token === montactToken) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,10 @@ import {
|
||||
UpdateOrderStatusDto,
|
||||
} from './dto/order.dto';
|
||||
import { generateOrderNumber } from '../common/utils/order-number';
|
||||
import { calculateCheckRass } from '../common/utils/check-rass';
|
||||
import {
|
||||
calculateCheckRass,
|
||||
invoiceAnchorDate,
|
||||
} from '../common/utils/check-rass';
|
||||
import {
|
||||
usesCashReceiptPhase,
|
||||
usesCheckSettlement,
|
||||
@@ -616,7 +619,7 @@ export class OrdersService {
|
||||
dto.checkMode ?? order.checkMode ?? CheckRegistrationMode.full;
|
||||
const rass = calculateCheckRass(
|
||||
dto.checks.map((c) => ({ amount: c.amount, dueDate: c.dueDate })),
|
||||
order.createdAt,
|
||||
invoiceAnchorDate(order.createdAt, order.statusHistory),
|
||||
);
|
||||
|
||||
// ثبت اولیه و اصلاح، هر دو سفارش را به صف بررسی چک میبرند.
|
||||
@@ -890,6 +893,16 @@ export class OrdersService {
|
||||
);
|
||||
const hidePrices =
|
||||
!adminView && PRICE_HIDDEN_STATUSES.includes(order.status);
|
||||
const liveRass =
|
||||
order.checks.length > 0
|
||||
? calculateCheckRass(
|
||||
order.checks.map((check) => ({
|
||||
amount: check.amount,
|
||||
dueDate: check.dueDate,
|
||||
})),
|
||||
invoiceAnchorDate(order.createdAt, order.statusHistory),
|
||||
)
|
||||
: null;
|
||||
const base = {
|
||||
id: order.id,
|
||||
orderNumber: order.orderNumber,
|
||||
@@ -910,8 +923,10 @@ export class OrdersService {
|
||||
finalAmount: hidePrices ? null : order.finalAmount,
|
||||
pricesVisible: !hidePrices,
|
||||
notes: order.notes ?? undefined,
|
||||
checkRassDays: order.checkRassDays ?? undefined,
|
||||
checkRassDate: order.checkRassDate?.toISOString(),
|
||||
checkRassDays: liveRass
|
||||
? liveRass.rassDays
|
||||
: (order.checkRassDays ?? undefined),
|
||||
checkRassDate: liveRass?.rassDate ?? order.checkRassDate?.toISOString(),
|
||||
cashInvoiceExpiresAt: order.cashInvoiceExpiresAt?.toISOString(),
|
||||
createdAt: order.createdAt.toISOString(),
|
||||
updatedAt: order.updatedAt.toISOString(),
|
||||
|
||||
@@ -20,6 +20,7 @@ const PRODUCT_INCLUDE = {
|
||||
imageUrlsJson: true,
|
||||
widthCm: true,
|
||||
composition: true,
|
||||
weightGrams: true,
|
||||
},
|
||||
},
|
||||
customer: { select: { firstName: true, lastName: true, phone: true } },
|
||||
@@ -148,6 +149,7 @@ export class SuggestionsService {
|
||||
imageUrlsJson: unknown;
|
||||
widthCm: number | null;
|
||||
composition: string | null;
|
||||
weightGrams: number | null;
|
||||
};
|
||||
}) {
|
||||
const colorEntries = parseColorEntries(r.product.colorsJson, r.product.color);
|
||||
@@ -181,6 +183,7 @@ export class SuggestionsService {
|
||||
colorImages,
|
||||
widthCm: r.product.widthCm ?? undefined,
|
||||
composition: r.product.composition?.trim() || undefined,
|
||||
weightGrams: r.product.weightGrams ?? undefined,
|
||||
isNew: r.product.isNew,
|
||||
productIsActive: r.product.isActive,
|
||||
note: r.note ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user