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,11 +1,15 @@
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
import { ResponseMapper } from '@/common/response/response-mapper'
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { Injectable, NotFoundException } from '@nestjs/common'
@Injectable()
export class SalesInvoicesService {
constructor(private prisma: PrismaService) {}
constructor(
private prisma: PrismaService,
private readonly sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
) {}
async findAll(consumer_id: string, complex_id: string, pos_id: string) {
const defaultWhere: SalesInvoiceWhereInput = {
@@ -117,4 +121,75 @@ export class SalesInvoicesService {
// TODO: Implement fetching a single sales invoice
return {}
}
async send(
consumerAccountId: string,
complexId: string,
posId: string,
invoiceId: string,
) {
const invoice = await this.sharedSaleInvoiceActionsService.send(
consumerAccountId,
posId,
invoiceId,
)
return ResponseMapper.single(invoice)
}
async retry(
consumerAccountId: string,
complexId: string,
posId: string,
invoiceId: string,
) {
const invoice = await this.sharedSaleInvoiceActionsService.retry(
consumerAccountId,
posId,
invoiceId,
)
return ResponseMapper.single(invoice)
}
async revoke(
consumerAccountId: string,
complexId: string,
posId: string,
invoiceId: string,
) {
const pos = await this.prisma.pos.findUnique({
where: {
id: posId,
complex: {
id: complexId,
},
},
select: {
complex: {
select: {
business_activity_id: true,
},
},
},
})
if (!pos) throw new NotFoundException('پایانه فروش مورد نظر یافت نشد.')
const invoice = await this.sharedSaleInvoiceActionsService.revoke(
consumerAccountId,
posId,
complexId,
pos.complex.business_activity_id,
invoiceId,
)
return ResponseMapper.single(invoice)
}
async inquiry(consumerAccountId: string, posId: string, invoiceId: string) {
const invoice = await this.sharedSaleInvoiceActionsService.inquiry(
consumerAccountId,
posId,
invoiceId,
)
return ResponseMapper.single(invoice)
}
}