feat: enhance sales invoice functionality with inquiry, send, retry, and revoke actions

This commit is contained in:
2026-05-10 14:14:01 +03:30
parent afa83895a2
commit a1e8f40417
7 changed files with 232 additions and 51 deletions
@@ -1,15 +1,12 @@
import { IPosPayload } from '@/common/models/posPayload.model'
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
import { translateEnumValue } from '@/common/utils'
import { PrismaService } from '@/prisma/prisma.service'
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'
import { Injectable, NotFoundException } from '@nestjs/common'
import { ResponseMapper } from 'common/response/response-mapper'
import { Prisma } from 'generated/prisma/client'
import {
ConsumerRole,
TspProviderRequestType,
TspProviderResponseStatus,
} from 'generated/prisma/enums'
import { TspProviderRequestType, TspProviderResponseStatus } from 'generated/prisma/enums'
import { SalesInvoiceTspService } from '../../tspProviders/sales-invoice-tsp.service'
import { CreateSalesInvoiceDto } from './dto/create-sales-invoice.dto'
import { SalesInvoicesFilterDto } from './dto/sales-invoices-filter.dto'
@@ -20,6 +17,7 @@ export class SalesInvoicesService {
private prisma: PrismaService,
private salesInvoiceTaxService: SalesInvoiceTspService,
private sharedSaleInvoiceCreateService: SharedSaleInvoiceCreateService,
private sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
) {}
async findAll(posInfo: IPosPayload, query: SalesInvoicesFilterDto = {}) {
@@ -253,9 +251,8 @@ export class SalesInvoicesService {
}
async send(invoiceId: string, posInfo: IPosPayload) {
await this.checkAccessToInvoice(posInfo.consumer_account_id, posInfo.pos_id)
const invoice = await this.salesInvoiceTaxService.originalSend(
const invoice = await this.sharedSaleInvoiceActionsService.send(
posInfo.consumer_account_id,
posInfo.pos_id,
invoiceId,
)
@@ -264,9 +261,8 @@ export class SalesInvoicesService {
}
async retry(invoiceId: string, posInfo: IPosPayload) {
await this.checkAccessToInvoice(posInfo.consumer_account_id, posInfo.pos_id)
const invoice = await this.salesInvoiceTaxService.originalSend(
const invoice = await this.sharedSaleInvoiceActionsService.retry(
posInfo.consumer_account_id,
posInfo.pos_id,
invoiceId,
)
@@ -275,11 +271,9 @@ export class SalesInvoicesService {
}
async revoke(invoiceId: string, posInfo: IPosPayload) {
await this.checkAccessToInvoice(posInfo.consumer_account_id, posInfo.pos_id)
const { consumer_account_id, pos_id, business_id, complex_id } = posInfo
const invoice = await this.salesInvoiceTaxService.revoke(
const invoice = await this.sharedSaleInvoiceActionsService.revoke(
consumer_account_id,
pos_id,
complex_id,
@@ -291,8 +285,11 @@ export class SalesInvoicesService {
}
async inquiry(consumer_account_id: string, pos_id: string, invoiceId: string) {
const consumer_id = await this.checkAccessToInvoice(consumer_account_id, pos_id)
const invoice = await this.salesInvoiceTaxService.get(invoiceId, pos_id, consumer_id)
const invoice = await this.sharedSaleInvoiceActionsService.inquiry(
consumer_account_id,
pos_id,
invoiceId,
)
return ResponseMapper.single(invoice)
}
@@ -447,33 +444,4 @@ export class SalesInvoicesService {
return where
}
private async checkAccessToInvoice(
consumer_account_id: string,
pos_id: string,
): Promise<string> {
const consumer = await this.prisma.consumerAccount.findUnique({
where: {
id: consumer_account_id,
OR: [
{
pos: {
id: pos_id,
},
},
{
role: ConsumerRole.OWNER,
},
],
},
select: {
consumer_id: true,
},
})
if (!consumer) {
throw new BadRequestException('شما دسترسی لازم برای ارسال فاکتور را ندارید.')
}
return consumer.consumer_id
}
}