Refactor: Remove stored procedures and replace with direct database operations
feat: Add economic code and guild information to sales invoice selection fix: Update error messages for invoice access and creation to use "صورتحساب" fix: Change error messages in SaleInvoicesService to use "صورتحساب" instead of "فاکتور" fix: Update error messages in SalesInvoicesService for not found cases to use "صورتحساب" fix: Modify TSP service to handle invoice updates and error messages consistently with "صورتحساب" fix: Update common DTO descriptions to refer to "صورتحساب" instead of "فاکتور" fix: Adjust utility functions to handle invoice references and error messages with "صورتحساب"
This commit is contained in:
@@ -42,20 +42,28 @@ export class SalesInvoiceTspService {
|
||||
|
||||
const attemptNumber = await getOriginalResendAttemptNumber(this.prisma, invoice_id)
|
||||
|
||||
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
||||
const invoice = await this.prisma.salesInvoice.update({
|
||||
where: {
|
||||
id: invoice_id,
|
||||
},
|
||||
data: {
|
||||
attempt_no: attemptNumber,
|
||||
invoice_id,
|
||||
provider_request_payload: {},
|
||||
status: TspProviderResponseStatus.QUEUED,
|
||||
raw_request_payload: JSON.parse(JSON.stringify(payload)),
|
||||
sent_at: new Date().toISOString(),
|
||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||
last_tsp_status: TspProviderResponseStatus.QUEUED,
|
||||
last_attempt_no: attemptNumber,
|
||||
tsp_attempts: {
|
||||
create: {
|
||||
attempt_no: attemptNumber,
|
||||
provider_request_payload: {},
|
||||
status: TspProviderResponseStatus.QUEUED,
|
||||
raw_request_payload: JSON.parse(JSON.stringify(payload)),
|
||||
sent_at: new Date().toISOString(),
|
||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const result = await this.tspSwitchService.send(payload)
|
||||
return await onResult(this.prisma, result, attempt.id)
|
||||
return await onResult(this.prisma, result, invoice.id)
|
||||
}
|
||||
|
||||
async sendBulk(consumer_id: string, invoice_ids: string[]): Promise<void> {
|
||||
@@ -75,18 +83,17 @@ export class SalesInvoiceTspService {
|
||||
pos_id: string,
|
||||
consumer_id: string,
|
||||
): Promise<TspProviderActionResponseDto> {
|
||||
const [attempt, pos] = await this.prisma.$transaction(async tx => [
|
||||
await tx.saleInvoiceTspAttempts.findFirst({
|
||||
const [invoice, pos] = await this.prisma.$transaction(async tx => [
|
||||
await tx.salesInvoice.findUnique({
|
||||
where: {
|
||||
invoice_id,
|
||||
invoice: {
|
||||
pos: {
|
||||
id: pos_id,
|
||||
},
|
||||
id: invoice_id,
|
||||
pos: {
|
||||
id: pos_id,
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
attempt_no: 'desc',
|
||||
select: {
|
||||
last_tsp_status: true,
|
||||
id: true,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -135,12 +142,25 @@ export class SalesInvoiceTspService {
|
||||
}),
|
||||
])
|
||||
|
||||
if (!attempt) {
|
||||
throw new NotFoundException('صورتحساب ارسالی فاکتور شما به سامانه یافت نشد.')
|
||||
if (!invoice) {
|
||||
throw new NotFoundException('صورتحساب ارسالی صورتحساب شما به سامانه یافت نشد.')
|
||||
}
|
||||
if (!pos) {
|
||||
throw new NotFoundException('مشکلی در ساختار اطلاعات ورودی شما وجود دارد.')
|
||||
}
|
||||
if (
|
||||
!invoice.last_tsp_status ||
|
||||
invoice.last_tsp_status === TspProviderResponseStatus.NOT_SEND
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
'صورتحساب شما هنوز به سامانه مالیاتی ارسال نشده است. لطفا چند لحظه دیگر مجددا تلاش کنید.',
|
||||
)
|
||||
}
|
||||
if (invoice.last_tsp_status === TspProviderResponseStatus.QUEUED) {
|
||||
throw new BadRequestException(
|
||||
'صورتحساب شما در صف ارسال به سامانه مالیاتی قرار دارد. لطفا چند لحظه دیگر مجددا تلاش کنید.',
|
||||
)
|
||||
}
|
||||
|
||||
const { business_activity } = pos.complex
|
||||
|
||||
@@ -153,7 +173,7 @@ export class SalesInvoiceTspService {
|
||||
business_activity.partner_token,
|
||||
)
|
||||
|
||||
return await onResult(this.prisma, result, attempt.id)
|
||||
return await onResult(this.prisma, result, invoice.id)
|
||||
}
|
||||
|
||||
async correctionSend(
|
||||
@@ -282,18 +302,18 @@ export class SalesInvoiceTspService {
|
||||
})
|
||||
|
||||
if (!relatedInvoice) {
|
||||
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||
throw new NotFoundException('صورتحساب مورد نظر یافت نشد.')
|
||||
}
|
||||
|
||||
if (relatedInvoice.type === TspProviderRequestType.REVOKE) {
|
||||
throw new BadRequestException(
|
||||
'فاکتور ارسالی قبلا ابطال شده است و امکان ویرایش آن وجود ندارد.',
|
||||
'صورتحساب ارسالی قبلا ابطال شده است و امکان ویرایش آن وجود ندارد.',
|
||||
)
|
||||
}
|
||||
|
||||
if (!relatedInvoice.tax_id) {
|
||||
throw new BadRequestException(
|
||||
'فاکتور قبلی همچنان در حال بررسی است و امکان ویرایش آن وجود ندارد.',
|
||||
'صورتحساب قبلی همچنان در حال بررسی است و امکان ویرایش آن وجود ندارد.',
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user