Initial admin edits
This commit is contained in:
@@ -4,7 +4,12 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { CashPaymentStatus, OrderStatus, SettlementType } from '@prisma/client';
|
||||
import {
|
||||
CashPaymentStatus,
|
||||
CheckRegistrationMode,
|
||||
OrderStatus,
|
||||
SettlementType,
|
||||
} from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import {
|
||||
SubmitCashReceiptDto,
|
||||
@@ -12,7 +17,10 @@ import {
|
||||
} from './dto/cash-payment.dto';
|
||||
import { joinFullName } from '../common/utils/name';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
|
||||
import { requirePaymentRecipientCompany } from '../companies/default-company';
|
||||
import {
|
||||
usesCashReceiptPhase,
|
||||
} from '../common/utils/settlement-type';
|
||||
/** بعد از تأیید پرداخت یا ارسال، رسید جدید نباید وضعیت را به عقب برگرداند. */
|
||||
const RECEIPT_SUBMITTABLE_STATUSES: OrderStatus[] = [
|
||||
OrderStatus.cash_in_progress,
|
||||
@@ -42,7 +50,7 @@ export class CashPaymentsService {
|
||||
if (order.userId !== userId) {
|
||||
throw new ForbiddenException('دسترسی به این سفارش مجاز نیست');
|
||||
}
|
||||
if (order.settlementType !== SettlementType.cash) {
|
||||
if (!usesCashReceiptPhase(order.settlementType)) {
|
||||
throw new BadRequestException('این سفارش تسویه نقدی نیست');
|
||||
}
|
||||
if (!RECEIPT_SUBMITTABLE_STATUSES.includes(order.status)) {
|
||||
@@ -59,18 +67,11 @@ export class CashPaymentsService {
|
||||
);
|
||||
}
|
||||
|
||||
const companyIds = [
|
||||
...new Set(
|
||||
[
|
||||
order.companyId,
|
||||
...order.items.map((item) => item.companyId).filter(Boolean),
|
||||
].filter(Boolean),
|
||||
),
|
||||
];
|
||||
const paymentRecipient = await requirePaymentRecipientCompany(this.prisma);
|
||||
const account = await this.prisma.bankAccount.findFirst({
|
||||
where: {
|
||||
id: dto.destinationAccountId,
|
||||
companyId: { in: companyIds },
|
||||
companyId: paymentRecipient.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
@@ -175,7 +176,10 @@ export class CashPaymentsService {
|
||||
// رد رسید باید مشتری را به مرحله پرداخت برگرداند تا بتواند رسید تازه بفرستد.
|
||||
let nextStatus: OrderStatus | null = null;
|
||||
if (dto.status === CashPaymentStatus.approved) {
|
||||
nextStatus = OrderStatus.cash_confirmed;
|
||||
nextStatus =
|
||||
receipt.order.settlementType === SettlementType.cash_check
|
||||
? OrderStatus.check_in_progress
|
||||
: OrderStatus.cash_confirmed;
|
||||
} else if (dto.status === CashPaymentStatus.rejected) {
|
||||
nextStatus = OrderStatus.awaiting_cash_payment;
|
||||
} else if (dto.status === CashPaymentStatus.expired) {
|
||||
@@ -185,7 +189,16 @@ export class CashPaymentsService {
|
||||
if (nextStatus && nextStatus !== receipt.order.status) {
|
||||
await tx.order.update({
|
||||
where: { id: receipt.orderId },
|
||||
data: { status: nextStatus },
|
||||
data: {
|
||||
status: nextStatus,
|
||||
...(nextStatus === OrderStatus.check_in_progress &&
|
||||
receipt.order.settlementType === SettlementType.cash_check
|
||||
? {
|
||||
checkMode:
|
||||
receipt.order.checkMode ?? CheckRegistrationMode.full,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
await tx.orderStatusHistory.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user