update return from sale invoices jurney and set nama return from sale
This commit is contained in:
@@ -6,17 +6,14 @@ import {
|
||||
TspProviderRequestType,
|
||||
TspProviderResponseStatus,
|
||||
} from 'generated/prisma/client'
|
||||
import {
|
||||
TspProviderActionResponseDto,
|
||||
TspProviderCorrectionInvoicePayloadDto,
|
||||
} from './dto'
|
||||
import { TspProviderActionResponseDto } from './dto'
|
||||
import { SalesInvoiceTspSwitchService } from './sales-invoice-tsp-switch.service'
|
||||
import {
|
||||
buildCorrectionPayload,
|
||||
buildOriginalPayload,
|
||||
buildReturnFromSalePayload,
|
||||
buildRevokePayload,
|
||||
getOriginalResendAttemptNumber,
|
||||
getRelatedInvoiceForCorrection,
|
||||
onResult,
|
||||
} from './utils/sales-invoice-tsp.utils'
|
||||
|
||||
@@ -176,60 +173,68 @@ export class SalesInvoiceTspService {
|
||||
}
|
||||
|
||||
async correctionSend(
|
||||
consumerAccountId: string,
|
||||
posId: string,
|
||||
complexId: string,
|
||||
businessId: string,
|
||||
ref_invoice_id: string,
|
||||
dataToUpdate: TspProviderCorrectionInvoicePayloadDto,
|
||||
invoice_id: string,
|
||||
): Promise<TspProviderActionResponseDto> {
|
||||
const [newInvoice, attempt, correctionPayload] = await this.prisma.$transaction(
|
||||
async tx => {
|
||||
const relatedInvoice = await getRelatedInvoiceForCorrection(tx, ref_invoice_id)
|
||||
const payload = await buildCorrectionPayload(this.prisma, invoice_id, posId)
|
||||
|
||||
const newInvoice = await this.sharedSaleInvoiceCreateService.create({
|
||||
tx,
|
||||
data: {
|
||||
customer_type: relatedInvoice.customer?.type || CustomerType.UNKNOWN,
|
||||
invoice_date: dataToUpdate.invoice_date,
|
||||
payments: dataToUpdate.payments,
|
||||
items: dataToUpdate.items,
|
||||
total_amount: dataToUpdate.total_amount,
|
||||
discount_amount: dataToUpdate.discount_amount,
|
||||
tax_amount: dataToUpdate.tax_amount,
|
||||
customer_id: relatedInvoice.customer_id || undefined,
|
||||
settlement_type: relatedInvoice.settlement_type,
|
||||
},
|
||||
businessId,
|
||||
complexId,
|
||||
posId,
|
||||
consumerAccountId,
|
||||
main_invoice_id: relatedInvoice.main_id || relatedInvoice.id,
|
||||
ref_invoice_id: relatedInvoice.id,
|
||||
type: TspProviderRequestType.CORRECTION,
|
||||
})
|
||||
const attemptNumber = 1
|
||||
|
||||
const correctionPayload = await buildCorrectionPayload(tx, newInvoice.id)
|
||||
|
||||
const attempt = await tx.saleInvoiceTspAttempts.create({
|
||||
data: {
|
||||
attempt_no: 1,
|
||||
invoice_id: newInvoice.id,
|
||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||
status: TspProviderResponseStatus.QUEUED,
|
||||
sent_at: new Date().toISOString(),
|
||||
raw_request_payload: JSON.parse(JSON.stringify(correctionPayload)),
|
||||
provider_request_payload: {},
|
||||
},
|
||||
})
|
||||
|
||||
return [newInvoice, attempt, correctionPayload]
|
||||
const invoice = await this.prisma.salesInvoice.update({
|
||||
where: {
|
||||
id: invoice_id,
|
||||
},
|
||||
)
|
||||
data: {
|
||||
last_tsp_status: TspProviderResponseStatus.QUEUED,
|
||||
last_attempt_no: attemptNumber,
|
||||
type: TspProviderRequestType.CORRECTION,
|
||||
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.correction(correctionPayload)
|
||||
const result = await this.tspSwitchService.send(payload)
|
||||
return await onResult(this.prisma, result, invoice.id)
|
||||
}
|
||||
|
||||
return await onResult(this.prisma, result, newInvoice.id)
|
||||
async returnFromSaleSend(
|
||||
pos_id: string,
|
||||
business_id: string,
|
||||
invoice_id: string,
|
||||
): Promise<TspProviderActionResponseDto> {
|
||||
const payload = await buildReturnFromSalePayload(this.prisma, invoice_id, pos_id)
|
||||
|
||||
const attemptNumber = 1
|
||||
|
||||
const invoice = await this.prisma.salesInvoice.update({
|
||||
where: {
|
||||
id: invoice_id,
|
||||
},
|
||||
data: {
|
||||
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.returnFromSale(payload)
|
||||
return await onResult(this.prisma, result, invoice.id)
|
||||
}
|
||||
|
||||
async revoke(
|
||||
|
||||
Reference in New Issue
Block a user