refactor: remove SalesInvoiceItemsService and update sales invoice handling
- Deleted SalesInvoiceItemsService as it was not implemented. - Changed variable declaration from `const` to `let` in SalesInvoicesService for sales invoice creation. - Updated response handling after sending to TSP provider in SalesInvoicesService. - Renamed payload properties in TspProvider DTOs for clarity. - Enhanced error handling in SalesInvoiceTspSwitchService for unsupported providers. - Refactored SalesInvoiceTspService to utilize utility functions for payload building and sending. - Updated PrismaService to increase connection limit and utilize dynamic options. - Added new migration scripts to update database schema for sale_invoice_tsp_attempts. - Introduced utility functions for building payloads and handling responses in sales invoice processing.
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- Added the required column `raw_request_payload` to the `sale_invoice_tsp_attempts` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts` DROP FOREIGN KEY `sale_invoice_tsp_attempts_invoice_id_fkey`;
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX `sale_invoice_tsp_attempts_invoice_id_key` ON `sale_invoice_tsp_attempts`;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts` ADD COLUMN `raw_request_payload` JSON NOT NULL,
|
||||||
|
ADD COLUMN `raw_response_payload` JSON NULL;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
@@ -78,3 +78,27 @@ Operational guide for AI/coding agents working in `consumer_api`.
|
|||||||
- Building payloads from the wrong invoice (must match the expected new/ref invoice in each flow).
|
- Building payloads from the wrong invoice (must match the expected new/ref invoice in each flow).
|
||||||
- Creating attempts without persisting request payload and final response payload.
|
- Creating attempts without persisting request payload and final response payload.
|
||||||
- Mismatch between DTO shapes and shared service input contracts.
|
- Mismatch between DTO shapes and shared service input contracts.
|
||||||
|
|
||||||
|
## Thread Notes (May 2026)
|
||||||
|
- Shared sale-invoice creation was introduced and must be injected/exported correctly in consuming modules (example failure: `UnknownDependenciesException` for `SharedSaleInvoiceCreateService`).
|
||||||
|
- In `SalesInvoiceTspService.revoke`, prepare all creation/update data from `relatedInvoice` (no external `dataToUpdate` argument expected).
|
||||||
|
- Prisma client is generated to `src/generated/prisma` via:
|
||||||
|
- `provider = "prisma-client"`
|
||||||
|
- `output = "../../src/generated/prisma"`
|
||||||
|
- `moduleFormat = "cjs"`
|
||||||
|
- Docker/runtime must include generated Prisma artifacts and `@prisma/client` runtime; missing `@prisma/client/runtime/client` indicates build/copy/install mismatch.
|
||||||
|
- Seeder commands that use `tsx` require dev dependencies/runtime tools; if running in slim production container, use a dedicated seed target/container or run seed from build/dev image.
|
||||||
|
- `pnpm` invocation in containers should use executable form (`pnpm ...`), not `node /app/pnpm`.
|
||||||
|
- Added SQL/Prisma error normalization utility: `src/common/utils/prisma-error.util.ts`; prefer mapping duplicate/constraint DB errors to domain-friendly messages.
|
||||||
|
- Partner-module list endpoints were standardized toward `ResponseMapper.paginate` where pagination response contract is expected.
|
||||||
|
- For heavy license provisioning (100+), request path should not synchronously insert all licenses; queue/background + batching is required.
|
||||||
|
|
||||||
|
## Migration Drift Playbook (Prisma/MySQL)
|
||||||
|
- If Prisma reports `modified after applied`, never edit an already-applied migration in-place for shared environments; create a new forward migration instead.
|
||||||
|
- If migration history and DB drift mismatch:
|
||||||
|
1. Verify local migration folders are complete and ordered.
|
||||||
|
2. Check `_prisma_migrations` for missing/applied names.
|
||||||
|
3. Use `prisma migrate resolve` only to reconcile history state, then apply a forward fix migration.
|
||||||
|
- Duplicate FK error seen in this repo: `sales_invoices_ref_id_fkey` (MySQL 1826). Recheck migration SQL for repeated `ADD CONSTRAINT` statements before rerun.
|
||||||
|
- Drift that repeatedly showed in this project: missing FK/unique on `sale_invoice_tsp_attempts.invoice_id`. Validate both schema and migration SQL produce the same final state.
|
||||||
|
- `prisma migrate status` may show up-to-date while `migrate dev` still detects drift (shadow DB/application history issue); treat `migrate dev` output as source of truth for fixing local history.
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `request_payload` on the `sale_invoice_tsp_attempts` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `response_payload` on the `sale_invoice_tsp_attempts` table. All the data in the column will be lost.
|
||||||
|
- Added the required column `raw_request_payload` to the `sale_invoice_tsp_attempts` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts` DROP FOREIGN KEY `sale_invoice_tsp_attempts_invoice_id_fkey`;
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX `sale_invoice_tsp_attempts_invoice_id_key` ON `sale_invoice_tsp_attempts`;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts`
|
||||||
|
ADD COLUMN `provider_request_payload` JSON NULL,
|
||||||
|
ADD COLUMN `provider_response_payload` JSON NULL,
|
||||||
|
ADD COLUMN `raw_request_payload` JSON NOT NULL;
|
||||||
|
|
||||||
|
UPDATE `sale_invoice_tsp_attempts`
|
||||||
|
SET `provider_response_payload` = `response_payload`;
|
||||||
|
UPDATE `sale_invoice_tsp_attempts`
|
||||||
|
SET `raw_request_payload` = `request_payload`;
|
||||||
|
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts`
|
||||||
|
DROP COLUMN `response_payload`,
|
||||||
|
DROP COLUMN `request_payload`;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
-- Check if the foreign key constraint already exists before adding it
|
||||||
|
SET @constraint_exists = (
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM information_schema.TABLE_CONSTRAINTS
|
||||||
|
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'customer_legal'
|
||||||
|
AND CONSTRAINT_NAME = 'customer_legal_business_activity_id_fkey'
|
||||||
|
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||||
|
);
|
||||||
|
|
||||||
|
SET @sql = IF(@constraint_exists = 0,
|
||||||
|
'ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;',
|
||||||
|
'SELECT "Foreign key constraint customer_legal_business_activity_id_fkey already exists" as message;'
|
||||||
|
);
|
||||||
|
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
@@ -72,15 +72,16 @@ model SaleInvoiceTspAttempts {
|
|||||||
attempt_no Int
|
attempt_no Int
|
||||||
status TspProviderResponseStatus
|
status TspProviderResponseStatus
|
||||||
|
|
||||||
request_payload Json?
|
raw_request_payload Json
|
||||||
response_payload Json?
|
provider_request_payload Json?
|
||||||
message String @db.Text
|
provider_response_payload Json?
|
||||||
|
message String @db.Text
|
||||||
|
|
||||||
sent_at DateTime? @db.Timestamp(0)
|
sent_at DateTime? @db.Timestamp(0)
|
||||||
received_at DateTime? @db.Timestamp(0)
|
received_at DateTime? @db.Timestamp(0)
|
||||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||||
|
|
||||||
invoice_id String @unique
|
invoice_id String
|
||||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id], onDelete: Cascade)
|
invoice SalesInvoice @relation(fields: [invoice_id], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@unique([invoice_id, attempt_no])
|
@@unique([invoice_id, attempt_no])
|
||||||
|
|||||||
+1
-3
@@ -9,7 +9,6 @@ import { ConsumerModule } from './modules/consumer/consumer.module'
|
|||||||
import { EnumsModule } from './modules/enums/enums.module'
|
import { EnumsModule } from './modules/enums/enums.module'
|
||||||
import { PartnerModule } from './modules/partners/partners.module'
|
import { PartnerModule } from './modules/partners/partners.module'
|
||||||
import { PosModule } from './modules/pos/pos.module'
|
import { PosModule } from './modules/pos/pos.module'
|
||||||
import { SalesInvoiceItemsModule } from './modules/pos/sales-invoices/sales-invoice-items/sales-invoice-items.module'
|
|
||||||
import { SalesInvoicePaymentsModule } from './modules/pos/sales-invoices/sales-invoice-payments/sales-invoice-payments.module'
|
import { SalesInvoicePaymentsModule } from './modules/pos/sales-invoices/sales-invoice-payments/sales-invoice-payments.module'
|
||||||
import { TriggerLogsModule } from './modules/trigger-logs/trigger-logs.module'
|
import { TriggerLogsModule } from './modules/trigger-logs/trigger-logs.module'
|
||||||
import { UploaderModule } from './modules/uploader/uploader.module'
|
import { UploaderModule } from './modules/uploader/uploader.module'
|
||||||
@@ -20,12 +19,11 @@ import { PrismaModule } from './prisma/prisma.module'
|
|||||||
PrismaModule,
|
PrismaModule,
|
||||||
EnumsModule,
|
EnumsModule,
|
||||||
AdminModule,
|
AdminModule,
|
||||||
|
AuthModule,
|
||||||
CatalogModule,
|
CatalogModule,
|
||||||
ConsumerModule,
|
ConsumerModule,
|
||||||
PosModule,
|
PosModule,
|
||||||
PartnerModule,
|
PartnerModule,
|
||||||
AuthModule,
|
|
||||||
SalesInvoiceItemsModule,
|
|
||||||
SalesInvoicePaymentsModule,
|
SalesInvoicePaymentsModule,
|
||||||
TriggerLogsModule,
|
TriggerLogsModule,
|
||||||
UploaderModule,
|
UploaderModule,
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import * as CONSUMER from './consumer'
|
import * as CONSUMER from './consumer'
|
||||||
import * as LICENSE_ACTIVATION from './licenseActivation'
|
import * as LICENSE_ACTIVATION from './licenseActivation'
|
||||||
import * as POS from './pos'
|
import * as POS from './pos'
|
||||||
|
import * as SALE_INVOICE from './saleInvoice'
|
||||||
|
|
||||||
export const QUERY_CONSTANTS = {
|
export const QUERY_CONSTANTS = {
|
||||||
POS,
|
POS,
|
||||||
CONSUMER,
|
CONSUMER,
|
||||||
LICENSE_ACTIVATION,
|
LICENSE_ACTIVATION,
|
||||||
|
SALE_INVOICE,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { SalesInvoiceSelect } from '@/generated/prisma/models'
|
||||||
|
|
||||||
|
export const summarySelect: SalesInvoiceSelect = {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
invoice_date: true,
|
||||||
|
invoice_number: true,
|
||||||
|
main_id: true,
|
||||||
|
total_amount: true,
|
||||||
|
tax_id: true,
|
||||||
|
type: true,
|
||||||
|
notes: true,
|
||||||
|
tsp_attempts: {
|
||||||
|
select: {
|
||||||
|
status: true,
|
||||||
|
sent_at: true,
|
||||||
|
message: true,
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
attempt_no: 'desc',
|
||||||
|
},
|
||||||
|
take: 1,
|
||||||
|
},
|
||||||
|
reference_invoice: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
invoice_number: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const select: SalesInvoiceSelect = {
|
||||||
|
...summarySelect,
|
||||||
|
payments: {
|
||||||
|
select: {
|
||||||
|
amount: true,
|
||||||
|
paid_at: true,
|
||||||
|
payment_method: true,
|
||||||
|
terminal_info: {
|
||||||
|
select: {
|
||||||
|
customer_card_no: true,
|
||||||
|
terminal_id: true,
|
||||||
|
rrn: true,
|
||||||
|
stan: true,
|
||||||
|
transaction_date_time: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unknown_customer: true,
|
||||||
|
customer: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
legal: true,
|
||||||
|
individual: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
items: {
|
||||||
|
select: {
|
||||||
|
quantity: true,
|
||||||
|
unit_price: true,
|
||||||
|
discount: true,
|
||||||
|
total_amount: true,
|
||||||
|
payload: true,
|
||||||
|
measure_unit_code: true,
|
||||||
|
measure_unit_text: true,
|
||||||
|
sku_code: true,
|
||||||
|
sku_vat: true,
|
||||||
|
good_snapshot: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import { SalesInvoiceCreateInput } from '@/generated/prisma/models'
|
import { SalesInvoiceCreateInput } from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
@@ -84,6 +85,7 @@ export class SharedSaleInvoiceCreateService {
|
|||||||
|
|
||||||
const salesInvoice = await $tx.salesInvoice.create({
|
const salesInvoice = await $tx.salesInvoice.create({
|
||||||
data: salesInvoiceData,
|
data: salesInvoiceData,
|
||||||
|
select: { ...QUERY_CONSTANTS.SALE_INVOICE.select },
|
||||||
})
|
})
|
||||||
|
|
||||||
await this.createPayments(
|
await this.createPayments(
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -4073,8 +4073,9 @@ export const SaleInvoiceTspAttemptsScalarFieldEnum = {
|
|||||||
id: 'id',
|
id: 'id',
|
||||||
attempt_no: 'attempt_no',
|
attempt_no: 'attempt_no',
|
||||||
status: 'status',
|
status: 'status',
|
||||||
request_payload: 'request_payload',
|
raw_request_payload: 'raw_request_payload',
|
||||||
response_payload: 'response_payload',
|
provider_request_payload: 'provider_request_payload',
|
||||||
|
provider_response_payload: 'provider_response_payload',
|
||||||
message: 'message',
|
message: 'message',
|
||||||
sent_at: 'sent_at',
|
sent_at: 'sent_at',
|
||||||
received_at: 'received_at',
|
received_at: 'received_at',
|
||||||
|
|||||||
@@ -664,8 +664,9 @@ export const SaleInvoiceTspAttemptsScalarFieldEnum = {
|
|||||||
id: 'id',
|
id: 'id',
|
||||||
attempt_no: 'attempt_no',
|
attempt_no: 'attempt_no',
|
||||||
status: 'status',
|
status: 'status',
|
||||||
request_payload: 'request_payload',
|
raw_request_payload: 'raw_request_payload',
|
||||||
response_payload: 'response_payload',
|
provider_request_payload: 'provider_request_payload',
|
||||||
|
provider_response_payload: 'provider_response_payload',
|
||||||
message: 'message',
|
message: 'message',
|
||||||
sent_at: 'sent_at',
|
sent_at: 'sent_at',
|
||||||
received_at: 'received_at',
|
received_at: 'received_at',
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ export type SaleInvoiceTspAttemptsCountAggregateOutputType = {
|
|||||||
id: number
|
id: number
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: number
|
status: number
|
||||||
request_payload: number
|
raw_request_payload: number
|
||||||
response_payload: number
|
provider_request_payload: number
|
||||||
|
provider_response_payload: number
|
||||||
message: number
|
message: number
|
||||||
sent_at: number
|
sent_at: number
|
||||||
received_at: number
|
received_at: number
|
||||||
@@ -105,8 +106,9 @@ export type SaleInvoiceTspAttemptsCountAggregateInputType = {
|
|||||||
id?: true
|
id?: true
|
||||||
attempt_no?: true
|
attempt_no?: true
|
||||||
status?: true
|
status?: true
|
||||||
request_payload?: true
|
raw_request_payload?: true
|
||||||
response_payload?: true
|
provider_request_payload?: true
|
||||||
|
provider_response_payload?: true
|
||||||
message?: true
|
message?: true
|
||||||
sent_at?: true
|
sent_at?: true
|
||||||
received_at?: true
|
received_at?: true
|
||||||
@@ -205,8 +207,9 @@ export type SaleInvoiceTspAttemptsGroupByOutputType = {
|
|||||||
id: string
|
id: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload: runtime.JsonValue | null
|
raw_request_payload: runtime.JsonValue
|
||||||
response_payload: runtime.JsonValue | null
|
provider_request_payload: runtime.JsonValue | null
|
||||||
|
provider_response_payload: runtime.JsonValue | null
|
||||||
message: string
|
message: string
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
@@ -241,8 +244,9 @@ export type SaleInvoiceTspAttemptsWhereInput = {
|
|||||||
id?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
id?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
raw_request_payload?: Prisma.JsonFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
provider_request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
|
provider_response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
@@ -255,8 +259,9 @@ export type SaleInvoiceTspAttemptsOrderByWithRelationInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
raw_request_payload?: Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
provider_request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
|
provider_response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
message?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
sent_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
sent_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
received_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
@@ -268,28 +273,30 @@ export type SaleInvoiceTspAttemptsOrderByWithRelationInput = {
|
|||||||
|
|
||||||
export type SaleInvoiceTspAttemptsWhereUniqueInput = Prisma.AtLeast<{
|
export type SaleInvoiceTspAttemptsWhereUniqueInput = Prisma.AtLeast<{
|
||||||
id?: string
|
id?: string
|
||||||
invoice_id?: string
|
|
||||||
invoice_id_attempt_no?: Prisma.SaleInvoiceTspAttemptsInvoice_idAttempt_noCompoundUniqueInput
|
invoice_id_attempt_no?: Prisma.SaleInvoiceTspAttemptsInvoice_idAttempt_noCompoundUniqueInput
|
||||||
AND?: Prisma.SaleInvoiceTspAttemptsWhereInput | Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
AND?: Prisma.SaleInvoiceTspAttemptsWhereInput | Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
||||||
OR?: Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
OR?: Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
||||||
NOT?: Prisma.SaleInvoiceTspAttemptsWhereInput | Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
NOT?: Prisma.SaleInvoiceTspAttemptsWhereInput | Prisma.SaleInvoiceTspAttemptsWhereInput[]
|
||||||
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
raw_request_payload?: Prisma.JsonFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
provider_request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
|
provider_response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
created_at?: Prisma.DateTimeFilter<"SaleInvoiceTspAttempts"> | Date | string
|
created_at?: Prisma.DateTimeFilter<"SaleInvoiceTspAttempts"> | Date | string
|
||||||
|
invoice_id?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
invoice?: Prisma.XOR<Prisma.SalesInvoiceScalarRelationFilter, Prisma.SalesInvoiceWhereInput>
|
invoice?: Prisma.XOR<Prisma.SalesInvoiceScalarRelationFilter, Prisma.SalesInvoiceWhereInput>
|
||||||
}, "id" | "invoice_id" | "invoice_id_attempt_no">
|
}, "id" | "invoice_id_attempt_no">
|
||||||
|
|
||||||
export type SaleInvoiceTspAttemptsOrderByWithAggregationInput = {
|
export type SaleInvoiceTspAttemptsOrderByWithAggregationInput = {
|
||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
raw_request_payload?: Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
provider_request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
|
provider_response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
message?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
sent_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
sent_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
received_at?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
@@ -309,8 +316,9 @@ export type SaleInvoiceTspAttemptsScalarWhereWithAggregatesInput = {
|
|||||||
id?: Prisma.StringWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string
|
id?: Prisma.StringWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
attempt_no?: Prisma.IntWithAggregatesFilter<"SaleInvoiceTspAttempts"> | number
|
attempt_no?: Prisma.IntWithAggregatesFilter<"SaleInvoiceTspAttempts"> | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusWithAggregatesFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusWithAggregatesFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
raw_request_payload?: Prisma.JsonWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
provider_request_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
||||||
|
provider_response_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
||||||
message?: Prisma.StringWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string
|
message?: Prisma.StringWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
sent_at?: Prisma.DateTimeNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
sent_at?: Prisma.DateTimeNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
received_at?: Prisma.DateTimeNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
received_at?: Prisma.DateTimeNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
@@ -322,8 +330,9 @@ export type SaleInvoiceTspAttemptsCreateInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -335,8 +344,9 @@ export type SaleInvoiceTspAttemptsUncheckedCreateInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -348,8 +358,9 @@ export type SaleInvoiceTspAttemptsUpdateInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -361,8 +372,9 @@ export type SaleInvoiceTspAttemptsUncheckedUpdateInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -374,8 +386,9 @@ export type SaleInvoiceTspAttemptsCreateManyInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -387,8 +400,9 @@ export type SaleInvoiceTspAttemptsUpdateManyMutationInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -399,8 +413,9 @@ export type SaleInvoiceTspAttemptsUncheckedUpdateManyInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -433,8 +448,9 @@ export type SaleInvoiceTspAttemptsCountOrderByAggregateInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
request_payload?: Prisma.SortOrder
|
raw_request_payload?: Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrder
|
provider_request_payload?: Prisma.SortOrder
|
||||||
|
provider_response_payload?: Prisma.SortOrder
|
||||||
message?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
sent_at?: Prisma.SortOrder
|
sent_at?: Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrder
|
received_at?: Prisma.SortOrder
|
||||||
@@ -522,8 +538,9 @@ export type SaleInvoiceTspAttemptsCreateWithoutInvoiceInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -534,8 +551,9 @@ export type SaleInvoiceTspAttemptsUncheckedCreateWithoutInvoiceInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -575,8 +593,9 @@ export type SaleInvoiceTspAttemptsScalarWhereInput = {
|
|||||||
id?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
id?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
attempt_no?: Prisma.IntFilter<"SaleInvoiceTspAttempts"> | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
raw_request_payload?: Prisma.JsonFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
provider_request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
|
provider_response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
message?: Prisma.StringFilter<"SaleInvoiceTspAttempts"> | string
|
||||||
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
sent_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
received_at?: Prisma.DateTimeNullableFilter<"SaleInvoiceTspAttempts"> | Date | string | null
|
||||||
@@ -588,8 +607,9 @@ export type SaleInvoiceTspAttemptsCreateManyInvoiceInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message: string
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
@@ -600,8 +620,9 @@ export type SaleInvoiceTspAttemptsUpdateWithoutInvoiceInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -612,8 +633,9 @@ export type SaleInvoiceTspAttemptsUncheckedUpdateWithoutInvoiceInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -624,8 +646,9 @@ export type SaleInvoiceTspAttemptsUncheckedUpdateManyWithoutInvoiceInput = {
|
|||||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
attempt_no?: Prisma.IntFieldUpdateOperationsInput | number
|
||||||
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
status?: Prisma.EnumTspProviderResponseStatusFieldUpdateOperationsInput | $Enums.TspProviderResponseStatus
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
raw_request_payload?: Prisma.JsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
provider_request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
|
provider_response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
message?: Prisma.StringFieldUpdateOperationsInput | string
|
message?: Prisma.StringFieldUpdateOperationsInput | string
|
||||||
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
sent_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
received_at?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
||||||
@@ -638,8 +661,9 @@ export type SaleInvoiceTspAttemptsSelect<ExtArgs extends runtime.Types.Extension
|
|||||||
id?: boolean
|
id?: boolean
|
||||||
attempt_no?: boolean
|
attempt_no?: boolean
|
||||||
status?: boolean
|
status?: boolean
|
||||||
request_payload?: boolean
|
raw_request_payload?: boolean
|
||||||
response_payload?: boolean
|
provider_request_payload?: boolean
|
||||||
|
provider_response_payload?: boolean
|
||||||
message?: boolean
|
message?: boolean
|
||||||
sent_at?: boolean
|
sent_at?: boolean
|
||||||
received_at?: boolean
|
received_at?: boolean
|
||||||
@@ -654,8 +678,9 @@ export type SaleInvoiceTspAttemptsSelectScalar = {
|
|||||||
id?: boolean
|
id?: boolean
|
||||||
attempt_no?: boolean
|
attempt_no?: boolean
|
||||||
status?: boolean
|
status?: boolean
|
||||||
request_payload?: boolean
|
raw_request_payload?: boolean
|
||||||
response_payload?: boolean
|
provider_request_payload?: boolean
|
||||||
|
provider_response_payload?: boolean
|
||||||
message?: boolean
|
message?: boolean
|
||||||
sent_at?: boolean
|
sent_at?: boolean
|
||||||
received_at?: boolean
|
received_at?: boolean
|
||||||
@@ -663,7 +688,7 @@ export type SaleInvoiceTspAttemptsSelectScalar = {
|
|||||||
invoice_id?: boolean
|
invoice_id?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SaleInvoiceTspAttemptsOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "attempt_no" | "status" | "request_payload" | "response_payload" | "message" | "sent_at" | "received_at" | "created_at" | "invoice_id", ExtArgs["result"]["saleInvoiceTspAttempts"]>
|
export type SaleInvoiceTspAttemptsOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "attempt_no" | "status" | "raw_request_payload" | "provider_request_payload" | "provider_response_payload" | "message" | "sent_at" | "received_at" | "created_at" | "invoice_id", ExtArgs["result"]["saleInvoiceTspAttempts"]>
|
||||||
export type SaleInvoiceTspAttemptsInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
export type SaleInvoiceTspAttemptsInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
||||||
invoice?: boolean | Prisma.SalesInvoiceDefaultArgs<ExtArgs>
|
invoice?: boolean | Prisma.SalesInvoiceDefaultArgs<ExtArgs>
|
||||||
}
|
}
|
||||||
@@ -677,8 +702,9 @@ export type $SaleInvoiceTspAttemptsPayload<ExtArgs extends runtime.Types.Extensi
|
|||||||
id: string
|
id: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
request_payload: runtime.JsonValue | null
|
raw_request_payload: runtime.JsonValue
|
||||||
response_payload: runtime.JsonValue | null
|
provider_request_payload: runtime.JsonValue | null
|
||||||
|
provider_response_payload: runtime.JsonValue | null
|
||||||
message: string
|
message: string
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
@@ -1057,8 +1083,9 @@ export interface SaleInvoiceTspAttemptsFieldRefs {
|
|||||||
readonly id: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'String'>
|
readonly id: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'String'>
|
||||||
readonly attempt_no: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Int'>
|
readonly attempt_no: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Int'>
|
||||||
readonly status: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'TspProviderResponseStatus'>
|
readonly status: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'TspProviderResponseStatus'>
|
||||||
readonly request_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
readonly raw_request_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
||||||
readonly response_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
readonly provider_request_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
||||||
|
readonly provider_response_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
||||||
readonly message: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'String'>
|
readonly message: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'String'>
|
||||||
readonly sent_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
readonly sent_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
||||||
readonly received_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
readonly received_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
||||||
|
|||||||
+3
-3
@@ -87,9 +87,9 @@ async function bootstrap() {
|
|||||||
new JwtAuthGuard(
|
new JwtAuthGuard(
|
||||||
app.get(JwtService),
|
app.get(JwtService),
|
||||||
app.get(Reflector),
|
app.get(Reflector),
|
||||||
new ConsumerGuard(new PrismaService()),
|
new ConsumerGuard(app.get(PrismaService)),
|
||||||
new PosGuard(new PrismaService()),
|
new PosGuard(app.get(PrismaService)),
|
||||||
new PartnerGuard(new PrismaService()),
|
new PartnerGuard(app.get(PrismaService)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ export class GuildsService {
|
|||||||
const guild = await this.prisma.guild.findUnique({
|
const guild = await this.prisma.guild.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
include: {
|
include: {
|
||||||
business_activities: {
|
_count: {
|
||||||
omit: {
|
select: {
|
||||||
guild_id: true,
|
business_activities: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+47
-23
@@ -5,7 +5,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
PartnerAccountQuotaChargeTransactionSelect,
|
PartnerAccountQuotaChargeTransactionSelect,
|
||||||
PartnerAccountQuotaChargeTransactionWhereInput,
|
PartnerAccountQuotaChargeTransactionWhereInput,
|
||||||
PartnerAccountQuotaCreditCreateInput,
|
|
||||||
} from '@/generated/prisma/models'
|
} from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
@@ -18,6 +17,8 @@ export class PartnerAccountChargeTransactionService {
|
|||||||
|
|
||||||
private readonly TRACKING_CODE_LENGTH = 8
|
private readonly TRACKING_CODE_LENGTH = 8
|
||||||
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
||||||
|
private readonly QUOTA_BATCH_SIZE = 200
|
||||||
|
private readonly MAX_QUANTITY_PER_REQUEST = 1000
|
||||||
|
|
||||||
private readonly mappedTransaction = (transaction: any) => {
|
private readonly mappedTransaction = (transaction: any) => {
|
||||||
const { allocations, purchased_count, _count, ...rest } = transaction
|
const { allocations, purchased_count, _count, ...rest } = transaction
|
||||||
@@ -90,19 +91,28 @@ export class PartnerAccountChargeTransactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(partner_id: string, data: ChargeAccountQuotaDto) {
|
async create(partner_id: string, data: ChargeAccountQuotaDto) {
|
||||||
|
if (data.quantity > this.MAX_QUANTITY_PER_REQUEST) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`تعداد درخواستی بیش از حد مجاز است. حداکثر ${this.MAX_QUANTITY_PER_REQUEST} عدد مجاز است.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.prisma.$transaction(async tx => {
|
const transaction = await this.prisma.$transaction(async tx => {
|
||||||
let transaction: { id: string } | null = null
|
let createdTransaction: { id: string } | null = null
|
||||||
|
|
||||||
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
||||||
try {
|
try {
|
||||||
transaction = await tx.partnerAccountQuotaChargeTransaction.create({
|
createdTransaction = await tx.partnerAccountQuotaChargeTransaction.create({
|
||||||
data: {
|
data: {
|
||||||
activation_expires_at: data.activated_expires_at,
|
activation_expires_at: data.activated_expires_at,
|
||||||
tracking_code: generateTrackingCode('AQC', this.TRACKING_CODE_LENGTH),
|
tracking_code: generateTrackingCode('AQC', this.TRACKING_CODE_LENGTH),
|
||||||
purchased_count: data.quantity,
|
purchased_count: data.quantity,
|
||||||
partner: { connect: { id: partner_id } },
|
partner: { connect: { id: partner_id } },
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -116,33 +126,47 @@ export class PartnerAccountChargeTransactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transaction) {
|
if (!createdTransaction) {
|
||||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است.')
|
throw new BadRequestException('متاسفانه مشکلی پیش آمده است.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const creditCreationPromises: any[] = []
|
return createdTransaction
|
||||||
for (let i = 0; i < data.quantity; i++) {
|
})
|
||||||
const credit: PartnerAccountQuotaCreditCreateInput = {
|
|
||||||
charge_transaction: {
|
|
||||||
connect: {
|
|
||||||
id: transaction.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
creditCreationPromises.push(
|
this.scheduleQuotaCreditProvisioning(transaction.id, data.quantity)
|
||||||
tx.partnerAccountQuotaCredit.create({ data: credit }),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const createdCredits = await Promise.all(creditCreationPromises)
|
|
||||||
|
|
||||||
if (createdCredits.some(createdCredit => createdCredit.activation_id === null)) {
|
return ResponseMapper.create({
|
||||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است. ')
|
transaction_id: transaction.id,
|
||||||
}
|
charged_license_count: data.quantity,
|
||||||
return { transaction, createdCredits }
|
status: 'QUEUED',
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private scheduleQuotaCreditProvisioning(transactionId: string, quantity: number) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.provisionQuotaCreditsInBackground(transactionId, quantity).catch(() => null)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async provisionQuotaCreditsInBackground(
|
||||||
|
transactionId: string,
|
||||||
|
quantity: number,
|
||||||
|
) {
|
||||||
|
let createdCount = 0
|
||||||
|
|
||||||
|
while (createdCount < quantity) {
|
||||||
|
const batchSize = Math.min(this.QUOTA_BATCH_SIZE, quantity - createdCount)
|
||||||
|
|
||||||
|
await this.prisma.partnerAccountQuotaCredit.createMany({
|
||||||
|
data: Array.from({ length: batchSize }, () => ({
|
||||||
|
charge_transaction_id: transactionId,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
createdCount += batchSize
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-25
@@ -5,7 +5,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
LicenseChargeTransactionSelect,
|
LicenseChargeTransactionSelect,
|
||||||
LicenseChargeTransactionWhereInput,
|
LicenseChargeTransactionWhereInput,
|
||||||
LicenseCreateInput,
|
|
||||||
} from '@/generated/prisma/models'
|
} from '@/generated/prisma/models'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
@@ -18,6 +17,8 @@ export class PartnerLicenseChargeTransactionService {
|
|||||||
|
|
||||||
private readonly TRACKING_CODE_LENGTH = 8
|
private readonly TRACKING_CODE_LENGTH = 8
|
||||||
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
||||||
|
private readonly LICENSE_BATCH_SIZE = 200
|
||||||
|
private readonly MAX_QUANTITY_PER_REQUEST = 1000
|
||||||
|
|
||||||
private readonly mappedTransaction = (transaction: any) => {
|
private readonly mappedTransaction = (transaction: any) => {
|
||||||
const { licenses, purchased_count, _count, ...rest } = transaction
|
const { licenses, purchased_count, _count, ...rest } = transaction
|
||||||
@@ -78,7 +79,7 @@ export class PartnerLicenseChargeTransactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOne(partner_id: string, id: string) {
|
async findOne(partner_id: string, id: string) {
|
||||||
const transaction = this.prisma.licenseChargeTransaction.findUniqueOrThrow({
|
const transaction = await this.prisma.licenseChargeTransaction.findUniqueOrThrow({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
partner_id,
|
partner_id,
|
||||||
@@ -89,19 +90,29 @@ export class PartnerLicenseChargeTransactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(partner_id: string, data: ChargeLicenseDto) {
|
async create(partner_id: string, data: ChargeLicenseDto) {
|
||||||
|
if (data.quantity > this.MAX_QUANTITY_PER_REQUEST) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`تعداد درخواستی بیش از حد مجاز است. حداکثر ${this.MAX_QUANTITY_PER_REQUEST} عدد مجاز است.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.prisma.$transaction(async tx => {
|
const transaction = await this.prisma.$transaction(async tx => {
|
||||||
let transaction: { id: string } | null = null
|
let createdTransaction: { id: string; purchased_count: number } | null = null
|
||||||
|
|
||||||
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
||||||
try {
|
try {
|
||||||
transaction = await tx.licenseChargeTransaction.create({
|
createdTransaction = await tx.licenseChargeTransaction.create({
|
||||||
data: {
|
data: {
|
||||||
activation_expires_at: data.activated_expires_at,
|
activation_expires_at: data.activated_expires_at,
|
||||||
tracking_code: generateTrackingCode('LIC', this.TRACKING_CODE_LENGTH),
|
tracking_code: generateTrackingCode('LIC', this.TRACKING_CODE_LENGTH),
|
||||||
purchased_count: data.quantity,
|
purchased_count: data.quantity,
|
||||||
partner: { connect: { id: partner_id } },
|
partner: { connect: { id: partner_id } },
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
purchased_count: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -115,33 +126,43 @@ export class PartnerLicenseChargeTransactionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transaction) {
|
if (!createdTransaction) {
|
||||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است.')
|
throw new BadRequestException('متاسفانه مشکلی پیش آمده است.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const licenseCreationPromises: any[] = []
|
return createdTransaction
|
||||||
for (let i = 0; i < data.quantity; i++) {
|
})
|
||||||
const license: LicenseCreateInput = {
|
|
||||||
charge_transaction: {
|
|
||||||
connect: {
|
|
||||||
id: transaction.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
licenseCreationPromises.push(tx.license.create({ data: license }))
|
this.scheduleLicenseProvisioning(transaction.id, transaction.purchased_count)
|
||||||
}
|
return ResponseMapper.create({
|
||||||
const createdLicenses = await Promise.all(licenseCreationPromises)
|
transaction_id: transaction.id,
|
||||||
|
charged_license_count: transaction.purchased_count,
|
||||||
if (
|
status: 'QUEUED',
|
||||||
createdLicenses.some(createdLicense => createdLicense.activation_id === null)
|
|
||||||
) {
|
|
||||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است. ')
|
|
||||||
}
|
|
||||||
return { transaction, createdLicenses }
|
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private scheduleLicenseProvisioning(transactionId: string, quantity: number) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.provisionLicensesInBackground(transactionId, quantity).catch(() => null)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async provisionLicensesInBackground(transactionId: string, quantity: number) {
|
||||||
|
let createdCount = 0
|
||||||
|
|
||||||
|
while (createdCount < quantity) {
|
||||||
|
const batchSize = Math.min(this.LICENSE_BATCH_SIZE, quantity - createdCount)
|
||||||
|
|
||||||
|
await this.prisma.license.createMany({
|
||||||
|
data: Array.from({ length: batchSize }, () => ({
|
||||||
|
charge_transaction_id: transactionId,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
createdCount += batchSize
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { UploadedFileTypes } from '@/common/enums/enums'
|
import { UploadedFileTypes } from '@/common/enums/enums'
|
||||||
|
import { translateEnumValue } from '@/common/utils'
|
||||||
import { PasswordUtil } from '@/common/utils/password.util'
|
import { PasswordUtil } from '@/common/utils/password.util'
|
||||||
import {
|
import {
|
||||||
AccountStatus,
|
AccountStatus,
|
||||||
@@ -87,6 +88,7 @@ export class PartnersService {
|
|||||||
license_charge_transactions,
|
license_charge_transactions,
|
||||||
account_quota_charge_transactions,
|
account_quota_charge_transactions,
|
||||||
license_renew_charge_transactions,
|
license_renew_charge_transactions,
|
||||||
|
status,
|
||||||
...rest
|
...rest
|
||||||
} = partner
|
} = partner
|
||||||
|
|
||||||
@@ -127,6 +129,7 @@ export class PartnersService {
|
|||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
status: translateEnumValue('PartnerStatus', status),
|
||||||
licenses_status,
|
licenses_status,
|
||||||
license_renew_status,
|
license_renew_status,
|
||||||
account_quota_status,
|
account_quota_status,
|
||||||
|
|||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
import type { SalesInvoiceItemsService } from '../sales-invoice-items.service'
|
|
||||||
|
|
||||||
export type SalesInvoiceItemsServiceCreateResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['create']>>
|
|
||||||
export type SalesInvoiceItemsServiceFindAllResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['findAll']>>
|
|
||||||
export type SalesInvoiceItemsServiceFindOneResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['findOne']>>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
|
||||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
|
||||||
|
|
||||||
@Controller('sales_invoice_items')
|
|
||||||
export class SalesInvoiceItemsController {
|
|
||||||
constructor(private readonly salesInvoiceItemsService: SalesInvoiceItemsService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
findAll() {
|
|
||||||
return this.salesInvoiceItemsService.findAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
findOne(@Param('id') id: string) {
|
|
||||||
return this.salesInvoiceItemsService.findOne(+id)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
create(@Body() data: any) {
|
|
||||||
return this.salesInvoiceItemsService.create(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common'
|
|
||||||
import { SalesInvoiceItemsController } from './sales-invoice-items.controller'
|
|
||||||
import { SalesInvoiceItemsService } from './sales-invoice-items.service'
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [SalesInvoiceItemsController],
|
|
||||||
providers: [SalesInvoiceItemsService],
|
|
||||||
})
|
|
||||||
export class SalesInvoiceItemsModule {}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class SalesInvoiceItemsService {
|
|
||||||
findAll() {
|
|
||||||
// TODO: Implement fetching all sales invoice items
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
findOne(id: number) {
|
|
||||||
// TODO: Implement fetching a single sales invoice item
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
create(data: any) {
|
|
||||||
// TODO: Implement sales invoice item creation
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -230,7 +230,7 @@ export class SalesInvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateSalesInvoiceDto, posInfo: IPosPayload) {
|
async create(data: CreateSalesInvoiceDto, posInfo: IPosPayload) {
|
||||||
const salesInvoice = await this.sharedSaleInvoiceCreateService.create({
|
let salesInvoice = await this.sharedSaleInvoiceCreateService.create({
|
||||||
data,
|
data,
|
||||||
businessId: posInfo.business_id,
|
businessId: posInfo.business_id,
|
||||||
complexId: posInfo.complex_id,
|
complexId: posInfo.complex_id,
|
||||||
@@ -240,7 +240,13 @@ export class SalesInvoicesService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (data.send_to_tsp) {
|
if (data.send_to_tsp) {
|
||||||
await this.salesInvoiceTaxService.originalSend(salesInvoice.id, posInfo.pos_id)
|
const providerResponse = await this.salesInvoiceTaxService.originalSend(
|
||||||
|
salesInvoice.id,
|
||||||
|
posInfo.pos_id,
|
||||||
|
)
|
||||||
|
if (providerResponse?.invoice) {
|
||||||
|
salesInvoice = providerResponse?.invoice as any
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseMapper.create(salesInvoice)
|
return ResponseMapper.create(salesInvoice)
|
||||||
|
|||||||
@@ -231,12 +231,12 @@ export class TspProviderSendItemResultDto {
|
|||||||
})
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
request_payload: Object
|
provider_request_payload: Object
|
||||||
|
|
||||||
@ApiProperty({ required: false, nullable: true, type: Object })
|
@ApiProperty({ required: false, nullable: true, type: Object })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
response_payload?: unknown
|
provider_response_payload?: Object
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@@ -291,7 +291,7 @@ export class TspProviderGetResultDto {
|
|||||||
@ApiProperty({ required: false, nullable: true, type: Object })
|
@ApiProperty({ required: false, nullable: true, type: Object })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
response_payload?: unknown
|
provider_response_payload?: Object
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
@@ -359,12 +359,12 @@ export class TspProviderRevokeResponseDto {
|
|||||||
@ApiProperty({ required: false, nullable: true, type: Object })
|
@ApiProperty({ required: false, nullable: true, type: Object })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
request_payload?: unknown
|
provider_request_payload?: unknown
|
||||||
|
|
||||||
@ApiProperty({ required: false, nullable: true, type: Object })
|
@ApiProperty({ required: false, nullable: true, type: Object })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
response_payload?: unknown
|
provider_response_payload?: unknown
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
import {
|
import {
|
||||||
TspProviderBulkSendResultDto,
|
TspProviderBulkSendResultDto,
|
||||||
TspProviderCorrectionSendPayloadDto,
|
TspProviderCorrectionSendPayloadDto,
|
||||||
@@ -18,17 +18,25 @@ export class SalesInvoiceTspSwitchService {
|
|||||||
private resolveSwitch(providerCode: string) {
|
private resolveSwitch(providerCode: string) {
|
||||||
const normalizedCode = providerCode.trim().toUpperCase() || ''
|
const normalizedCode = providerCode.trim().toUpperCase() || ''
|
||||||
|
|
||||||
|
let adapter: NamaProviderSwitchAdapter | null = null
|
||||||
switch (normalizedCode) {
|
switch (normalizedCode) {
|
||||||
case 'NAMA':
|
case 'NAMA':
|
||||||
default:
|
adapter = this.namaAdapter
|
||||||
return this.namaAdapter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!adapter) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`${providerCode} برای ارسال انتخاب شده است که در حال حاضر پشتیبانی نمی شود.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(
|
async send(
|
||||||
payload: TspProviderOriginalSendPayloadDto,
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
): Promise<TspProviderSendItemResultDto> {
|
): Promise<TspProviderSendItemResultDto> {
|
||||||
const adapter = this.resolveSwitch(payload.tsp_provider)
|
const adapter = this.resolveSwitch(payload.tsp_provider)
|
||||||
|
|
||||||
return adapter.originalSend(payload)
|
return adapter.originalSend(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +44,7 @@ export class SalesInvoiceTspSwitchService {
|
|||||||
payload: TspProviderCorrectionSendPayloadDto,
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
): Promise<TspProviderCorrectionSendResponseDto> {
|
): Promise<TspProviderCorrectionSendResponseDto> {
|
||||||
const adapter = this.resolveSwitch(payload.tsp_provider)
|
const adapter = this.resolveSwitch(payload.tsp_provider)
|
||||||
|
|
||||||
return adapter.correctionSend(payload)
|
return adapter.correctionSend(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'
|
||||||
import { TspProviderCustomerType } from 'common/enums/enums'
|
|
||||||
import {
|
import {
|
||||||
CustomerType,
|
CustomerType,
|
||||||
Prisma,
|
|
||||||
TspProviderRequestType,
|
TspProviderRequestType,
|
||||||
TspProviderResponseStatus,
|
TspProviderResponseStatus,
|
||||||
} from 'generated/prisma/client'
|
} from 'generated/prisma/client'
|
||||||
import {
|
import {
|
||||||
TspProviderActionResponseDto,
|
TspProviderActionResponseDto,
|
||||||
TspProviderCorrectionInvoicePayloadDto,
|
TspProviderCorrectionInvoicePayloadDto,
|
||||||
TspProviderCorrectionSendPayloadDto,
|
|
||||||
TspProviderOriginalSendPayloadDto,
|
|
||||||
TspProviderRevokePayloadDto,
|
|
||||||
TspProviderSendItemResultDto,
|
|
||||||
} from './dto/provider-switch.dto'
|
} from './dto/provider-switch.dto'
|
||||||
import { SalesInvoiceTspSwitchService } from './sales-invoice-tsp-switch.service'
|
import { SalesInvoiceTspSwitchService } from './sales-invoice-tsp-switch.service'
|
||||||
|
import {
|
||||||
|
buildCorrectionPayload,
|
||||||
|
buildPayload,
|
||||||
|
buildRevokePayload,
|
||||||
|
getOriginalResendAttemptNumber,
|
||||||
|
onResult,
|
||||||
|
trySend,
|
||||||
|
} from './utils/sales-invoice-tsp.utils'
|
||||||
|
|
||||||
type ItemTspRow = {
|
type ItemTspRow = {
|
||||||
tsp_provider: string | null
|
tsp_provider: string | null
|
||||||
@@ -35,23 +37,23 @@ export class SalesInvoiceTspService {
|
|||||||
posId: string,
|
posId: string,
|
||||||
invoice_id: string,
|
invoice_id: string,
|
||||||
): Promise<TspProviderActionResponseDto> {
|
): Promise<TspProviderActionResponseDto> {
|
||||||
const payload = await this.buildPayload(invoice_id, posId)
|
const payload = await buildPayload(this.prisma, invoice_id, posId)
|
||||||
|
|
||||||
const attemptNumber = await this.getOriginalResendAttemptNumber(invoice_id)
|
const attemptNumber = await getOriginalResendAttemptNumber(this.prisma, invoice_id)
|
||||||
|
|
||||||
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
||||||
data: {
|
data: {
|
||||||
attempt_no: attemptNumber,
|
attempt_no: attemptNumber,
|
||||||
invoice_id,
|
invoice_id,
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
request_payload: JSON.parse(JSON.stringify(payload)),
|
raw_request_payload: JSON.parse(JSON.stringify(payload)),
|
||||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const result = await this.trySend(payload)
|
const result = await trySend(this.tspSwitchService, payload)
|
||||||
|
|
||||||
return await this.onResult(result, attempt.id)
|
return await onResult(this.prisma, result, attempt.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendBulk(consumer_id: string, invoice_ids: string[]): Promise<void> {
|
async sendBulk(consumer_id: string, invoice_ids: string[]): Promise<void> {
|
||||||
@@ -160,7 +162,7 @@ export class SalesInvoiceTspService {
|
|||||||
id: attempt.id,
|
id: attempt.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
response_payload: JSON.parse(JSON.stringify(result)),
|
provider_response_payload: JSON.parse(JSON.stringify(result)),
|
||||||
status: result.status,
|
status: result.status,
|
||||||
received_at: result.received_at,
|
received_at: result.received_at,
|
||||||
},
|
},
|
||||||
@@ -241,7 +243,7 @@ export class SalesInvoiceTspService {
|
|||||||
type: TspProviderRequestType.CORRECTION,
|
type: TspProviderRequestType.CORRECTION,
|
||||||
})
|
})
|
||||||
|
|
||||||
const correctionPayload = await this.buildCorrectionPayload(tx, newInvoice.id)
|
const correctionPayload = await buildCorrectionPayload(tx, newInvoice.id)
|
||||||
|
|
||||||
const attempt = await tx.saleInvoiceTspAttempts.create({
|
const attempt = await tx.saleInvoiceTspAttempts.create({
|
||||||
data: {
|
data: {
|
||||||
@@ -249,7 +251,8 @@ export class SalesInvoiceTspService {
|
|||||||
invoice_id: newInvoice.id,
|
invoice_id: newInvoice.id,
|
||||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
request_payload: JSON.parse(JSON.stringify(correctionPayload)),
|
sent_at: new Date().toISOString(),
|
||||||
|
raw_request_payload: JSON.parse(JSON.stringify(correctionPayload)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -257,11 +260,11 @@ export class SalesInvoiceTspService {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const result = await this.trySend(correctionPayload)
|
const result = await trySend(this.tspSwitchService, correctionPayload)
|
||||||
|
|
||||||
console.log('sendResult')
|
console.log('sendResult')
|
||||||
console.log(result)
|
console.log(result)
|
||||||
return this.onResult(result, attempt.id)
|
return onResult(this.prisma, result, attempt.id)
|
||||||
|
|
||||||
// const countByGoodId = (goodIds: string[]): Map<string, number> => {
|
// const countByGoodId = (goodIds: string[]): Map<string, number> => {
|
||||||
// const counts = new Map<string, number>()
|
// const counts = new Map<string, number>()
|
||||||
@@ -428,7 +431,7 @@ export class SalesInvoiceTspService {
|
|||||||
type: TspProviderRequestType.REVOKE,
|
type: TspProviderRequestType.REVOKE,
|
||||||
})
|
})
|
||||||
|
|
||||||
const payload = await this.buildRevokePayload(newInvoice.id, posId)
|
const payload = await buildRevokePayload(this.prisma, newInvoice.id, posId)
|
||||||
|
|
||||||
const attempt = await tx.saleInvoiceTspAttempts.create({
|
const attempt = await tx.saleInvoiceTspAttempts.create({
|
||||||
data: {
|
data: {
|
||||||
@@ -436,7 +439,7 @@ export class SalesInvoiceTspService {
|
|||||||
invoice_id: newInvoice.id,
|
invoice_id: newInvoice.id,
|
||||||
message: 'در حال ارسال به سامانه مالیاتی...',
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
request_payload: JSON.parse(JSON.stringify(payload)),
|
raw_request_payload: JSON.parse(JSON.stringify(payload)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -446,496 +449,6 @@ export class SalesInvoiceTspService {
|
|||||||
|
|
||||||
const result = await this.tspSwitchService.revoke(revokePayload)
|
const result = await this.tspSwitchService.revoke(revokePayload)
|
||||||
|
|
||||||
return await this.onResult(result, attempt.id)
|
return await onResult(this.prisma, result, attempt.id)
|
||||||
}
|
|
||||||
|
|
||||||
private async getOriginalResendAttemptNumber(invoice_id: string): Promise<number> {
|
|
||||||
let attemptNumber = 1
|
|
||||||
|
|
||||||
const existingAttempt = await this.prisma.saleInvoiceTspAttempts.findFirst({
|
|
||||||
where: {
|
|
||||||
invoice_id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
invoice: {
|
|
||||||
select: {
|
|
||||||
type: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (existingAttempt) {
|
|
||||||
attemptNumber = existingAttempt.attempt_no + 1
|
|
||||||
if (existingAttempt.invoice.type !== TspProviderRequestType.ORIGINAL) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'فقط فاکتورهای اصلی قابل ارسال مجدد به سامانه مالیاتی هستند.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingAttempt.status === TspProviderResponseStatus.SUCCESS) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'فاکتور تایید شده از طرف سازمان مالیاتی قابل ارسال مجدد نیست.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (existingAttempt.status === TspProviderResponseStatus.QUEUED) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'در حال حاضر فاکتور شما در حال بررسی توسط سازمان مالیاتی است.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return attemptNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
private async buildRevokePayload(
|
|
||||||
invoiceId: string,
|
|
||||||
posId: string,
|
|
||||||
): Promise<TspProviderRevokePayloadDto> {
|
|
||||||
const invoice = await this.prisma.salesInvoice.findUnique({
|
|
||||||
where: {
|
|
||||||
id: invoiceId,
|
|
||||||
pos_id: posId,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
code: true,
|
|
||||||
total_amount: true,
|
|
||||||
invoice_date: true,
|
|
||||||
invoice_number: true,
|
|
||||||
tax_id: true,
|
|
||||||
tsp_attempts: {
|
|
||||||
orderBy: {
|
|
||||||
created_at: 'asc',
|
|
||||||
},
|
|
||||||
take: 1,
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
status: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
pos: {
|
|
||||||
select: {
|
|
||||||
complex: {
|
|
||||||
select: {
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
fiscal_id: true,
|
|
||||||
economic_code: true,
|
|
||||||
partner_token: true,
|
|
||||||
guild: {
|
|
||||||
select: {
|
|
||||||
invoice_template: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
consumer: {
|
|
||||||
select: {
|
|
||||||
legal: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
individual: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!invoice) {
|
|
||||||
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
|
||||||
invoice.pos.complex.business_activity.consumer.individual)!
|
|
||||||
|
|
||||||
return {
|
|
||||||
invoice_id: invoice.id,
|
|
||||||
invoice_number: invoice.invoice_number,
|
|
||||||
economic_code: invoice.pos.complex.business_activity.economic_code,
|
|
||||||
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
|
||||||
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
|
||||||
tsp_provider: partner.tsp_provider!,
|
|
||||||
last_tax_id: invoice.tax_id!,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async buildCorrectionPayload(
|
|
||||||
tx: Prisma.TransactionClient,
|
|
||||||
invoice_id: string,
|
|
||||||
): Promise<TspProviderCorrectionSendPayloadDto> {
|
|
||||||
const invoice = await tx.salesInvoice.findUnique({
|
|
||||||
where: {
|
|
||||||
id: invoice_id,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
code: true,
|
|
||||||
total_amount: true,
|
|
||||||
invoice_date: true,
|
|
||||||
invoice_number: true,
|
|
||||||
items: true,
|
|
||||||
pos: {
|
|
||||||
select: {
|
|
||||||
complex: {
|
|
||||||
select: {
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
fiscal_id: true,
|
|
||||||
economic_code: true,
|
|
||||||
partner_token: true,
|
|
||||||
guild: {
|
|
||||||
select: {
|
|
||||||
invoice_template: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
consumer: {
|
|
||||||
select: {
|
|
||||||
legal: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
individual: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
customer: {
|
|
||||||
select: {
|
|
||||||
type: true,
|
|
||||||
individual: true,
|
|
||||||
legal: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
reference_invoice: {
|
|
||||||
select: {
|
|
||||||
tax_id: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
payments: {
|
|
||||||
include: {
|
|
||||||
terminal_info: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (!invoice) {
|
|
||||||
throw Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
|
||||||
invoice.pos.complex.business_activity.consumer.individual)!
|
|
||||||
|
|
||||||
const returnData: TspProviderCorrectionSendPayloadDto = {
|
|
||||||
items: invoice.items.map(item => ({
|
|
||||||
invoice_item_id: item.id,
|
|
||||||
quantity: Number(item.quantity),
|
|
||||||
unit_price: Number(item.unit_price),
|
|
||||||
total_amount: Number(item.total_amount),
|
|
||||||
measure_unit: item.measure_unit_code,
|
|
||||||
sku: item.sku_code,
|
|
||||||
sku_vat: String(item.sku_vat),
|
|
||||||
discount: String((item.payload as Record<string, any>)?.discount || '0'),
|
|
||||||
good_id: item.good_id,
|
|
||||||
service_id: item.service_id,
|
|
||||||
payload: item.payload,
|
|
||||||
good_snapshot: item.good_snapshot,
|
|
||||||
})),
|
|
||||||
payments: invoice.payments.map(payment => ({
|
|
||||||
amount: Number(payment.amount),
|
|
||||||
payment_method: payment.payment_method,
|
|
||||||
paid_at: payment.paid_at,
|
|
||||||
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
|
||||||
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
|
||||||
})),
|
|
||||||
total_amount: Number(invoice.total_amount),
|
|
||||||
last_tax_id: invoice.reference_invoice!.tax_id!,
|
|
||||||
invoice_number: invoice.invoice_number,
|
|
||||||
invoice_id: invoice.id,
|
|
||||||
economic_code: invoice.pos.complex.business_activity.economic_code,
|
|
||||||
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
|
||||||
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
|
||||||
type: TspProviderRequestType.CORRECTION,
|
|
||||||
tsp_provider: partner.tsp_provider!,
|
|
||||||
invoice_template: invoice.pos.complex.business_activity.guild.invoice_template,
|
|
||||||
invoice_date: new Date(),
|
|
||||||
|
|
||||||
customer_type: invoice.customer?.type
|
|
||||||
? TspProviderCustomerType.KNOWN
|
|
||||||
: TspProviderCustomerType.UNKNOWN,
|
|
||||||
customer: invoice.customer?.type
|
|
||||||
? {
|
|
||||||
type: invoice.customer.type,
|
|
||||||
legal_info: invoice.customer.legal ?? undefined,
|
|
||||||
individual_info: invoice.customer.individual ?? undefined,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
return returnData
|
|
||||||
}
|
|
||||||
|
|
||||||
private async buildPayload(
|
|
||||||
invoiceId: string,
|
|
||||||
posId: string,
|
|
||||||
): Promise<TspProviderOriginalSendPayloadDto> {
|
|
||||||
const invoice = await this.prisma.salesInvoice.findUnique({
|
|
||||||
where: {
|
|
||||||
id: invoiceId,
|
|
||||||
pos_id: posId,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
code: true,
|
|
||||||
total_amount: true,
|
|
||||||
invoice_date: true,
|
|
||||||
invoice_number: true,
|
|
||||||
items: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
quantity: true,
|
|
||||||
unit_price: true,
|
|
||||||
total_amount: true,
|
|
||||||
measure_unit_code: true,
|
|
||||||
measure_unit_text: true,
|
|
||||||
sku_code: true,
|
|
||||||
sku_vat: true,
|
|
||||||
good_id: true,
|
|
||||||
service_id: true,
|
|
||||||
payload: true,
|
|
||||||
good_snapshot: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
pos: {
|
|
||||||
select: {
|
|
||||||
complex: {
|
|
||||||
select: {
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
fiscal_id: true,
|
|
||||||
economic_code: true,
|
|
||||||
partner_token: true,
|
|
||||||
guild: {
|
|
||||||
select: {
|
|
||||||
invoice_template: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
consumer: {
|
|
||||||
select: {
|
|
||||||
legal: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
individual: {
|
|
||||||
select: {
|
|
||||||
partner: {
|
|
||||||
select: {
|
|
||||||
tsp_provider: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
customer: {
|
|
||||||
select: {
|
|
||||||
type: true,
|
|
||||||
individual: {
|
|
||||||
select: {
|
|
||||||
first_name: true,
|
|
||||||
last_name: true,
|
|
||||||
national_id: true,
|
|
||||||
mobile_number: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legal: {
|
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
economic_code: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
payments: {
|
|
||||||
select: {
|
|
||||||
amount: true,
|
|
||||||
payment_method: true,
|
|
||||||
paid_at: true,
|
|
||||||
terminal_info: {
|
|
||||||
select: {
|
|
||||||
stan: true,
|
|
||||||
rrn: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(invoiceId, posId)
|
|
||||||
|
|
||||||
if (!invoice) {
|
|
||||||
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
|
||||||
invoice.pos.complex.business_activity.consumer.individual)!
|
|
||||||
|
|
||||||
return {
|
|
||||||
invoice_id: invoice.id,
|
|
||||||
invoice_number: invoice.invoice_number,
|
|
||||||
invoice_date: invoice.invoice_date,
|
|
||||||
total_amount: Number(invoice.total_amount),
|
|
||||||
economic_code: invoice.pos.complex.business_activity.economic_code,
|
|
||||||
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
|
||||||
invoice_template: invoice.pos.complex.business_activity.guild.invoice_template,
|
|
||||||
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
|
||||||
payments: invoice.payments.map(payment => ({
|
|
||||||
amount: Number(payment.amount),
|
|
||||||
payment_method: payment.payment_method,
|
|
||||||
paid_at: payment.paid_at,
|
|
||||||
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
|
||||||
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
|
||||||
})),
|
|
||||||
type: TspProviderRequestType.ORIGINAL,
|
|
||||||
tsp_provider: partner.tsp_provider!,
|
|
||||||
customer_type: invoice.customer?.type
|
|
||||||
? TspProviderCustomerType.KNOWN
|
|
||||||
: TspProviderCustomerType.UNKNOWN,
|
|
||||||
customer: invoice.customer?.type
|
|
||||||
? {
|
|
||||||
type: invoice.customer.type,
|
|
||||||
legal_info: invoice.customer.legal ?? undefined,
|
|
||||||
individual_info: invoice.customer.individual ?? undefined,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
items: invoice.items.map(item => ({
|
|
||||||
invoice_item_id: item.id,
|
|
||||||
quantity: Number(item.quantity),
|
|
||||||
unit_price: Number(item.unit_price),
|
|
||||||
total_amount: Number(item.total_amount),
|
|
||||||
measure_unit: item.measure_unit_code,
|
|
||||||
sku: item.sku_code,
|
|
||||||
sku_vat: String(item.sku_vat),
|
|
||||||
discount: String((item.payload as Record<string, any>)?.discount || '0'),
|
|
||||||
good_id: item.good_id,
|
|
||||||
service_id: item.service_id,
|
|
||||||
payload: item.payload,
|
|
||||||
good_snapshot: item.good_snapshot,
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async trySend(
|
|
||||||
payload: TspProviderOriginalSendPayloadDto,
|
|
||||||
): Promise<TspProviderSendItemResultDto | null> {
|
|
||||||
const taxResult = await this.tspSwitchService.send(payload)
|
|
||||||
|
|
||||||
return taxResult || null
|
|
||||||
}
|
|
||||||
|
|
||||||
private async onResult(
|
|
||||||
result: any,
|
|
||||||
attempt_id: string,
|
|
||||||
): Promise<TspProviderActionResponseDto> {
|
|
||||||
if (result) {
|
|
||||||
if (result.hasError) {
|
|
||||||
const updatedAttempt = await this.prisma.saleInvoiceTspAttempts.update({
|
|
||||||
where: {
|
|
||||||
id: attempt_id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
response_payload: JSON.parse(JSON.stringify(result)),
|
|
||||||
status: result.status,
|
|
||||||
message: result.message?.toString() || 'وجود مشکل در ارسال به سامانه مالیاتی',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
status: true,
|
|
||||||
invoice: true,
|
|
||||||
message: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
invoice: updatedAttempt.invoice,
|
|
||||||
status: updatedAttempt.status,
|
|
||||||
message: updatedAttempt.message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedAttempt = await this.prisma.saleInvoiceTspAttempts.update({
|
|
||||||
where: {
|
|
||||||
id: attempt_id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
response_payload: JSON.parse(JSON.stringify(result)),
|
|
||||||
status: result.status,
|
|
||||||
sent_at: result.sent_at,
|
|
||||||
received_at: result.received_at,
|
|
||||||
message:
|
|
||||||
result.message?.toString() || 'فاکتور با موفقیت به سامانه مالیاتی ارسال شد.',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
status: true,
|
|
||||||
invoice: true,
|
|
||||||
message: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
invoice: updatedAttempt.invoice,
|
|
||||||
status: updatedAttempt.status,
|
|
||||||
message: updatedAttempt.message,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new NotFoundException(
|
|
||||||
'متاسفانه امکان ارسال فاکتور به سیستم مالیاتی در حال حاضر وجود ندارد. لطفا بعدا تلاش کنید.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
|
|
||||||
const result: TspProviderSendItemResultDto = {
|
const result: TspProviderSendItemResultDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: payload,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: !response.ok,
|
hasError: !response.ok,
|
||||||
message: providerResponse.message,
|
message: providerResponse.message,
|
||||||
sent_at: new Date().toISOString(),
|
provider_response_payload: JSON.parse(JSON.stringify(providerResponse)),
|
||||||
response_payload: providerResponse,
|
|
||||||
received_at: providerResponse.tsp_update_time,
|
received_at: providerResponse.tsp_update_time,
|
||||||
|
sent_at: new Date().toISOString(),
|
||||||
tax_id: providerResponse.tax_id,
|
tax_id: providerResponse.tax_id,
|
||||||
status: this.namaProviderUtils.mapResponseStatus(
|
status: this.namaProviderUtils.mapResponseStatus(
|
||||||
providerResponse.status as NamaProviderResponseStatus,
|
providerResponse.status as NamaProviderResponseStatus,
|
||||||
@@ -112,7 +112,7 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
this.logger.error('NAMA send failed', err)
|
this.logger.error('NAMA send failed', err)
|
||||||
const failure: TspProviderSendItemResultDto = {
|
const failure: TspProviderSendItemResultDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: payload,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: true,
|
hasError: true,
|
||||||
message: (err as Error).message,
|
message: (err as Error).message,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
@@ -143,11 +143,11 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
|
|
||||||
const result: TspProviderSendItemResultDto = {
|
const result: TspProviderSendItemResultDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: mappedRequest,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: !response.ok,
|
hasError: !response.ok,
|
||||||
message: providerResponse.message,
|
message: providerResponse.message,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
response_payload: providerResponse,
|
provider_response_payload: JSON.parse(JSON.stringify(providerResponse)),
|
||||||
received_at: providerResponse.tsp_update_time,
|
received_at: providerResponse.tsp_update_time,
|
||||||
tax_id: providerResponse.tax_id,
|
tax_id: providerResponse.tax_id,
|
||||||
status: this.namaProviderUtils.mapResponseStatus(
|
status: this.namaProviderUtils.mapResponseStatus(
|
||||||
@@ -160,7 +160,7 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
this.logger.error('NAMA send failed', err)
|
this.logger.error('NAMA send failed', err)
|
||||||
const failure: TspProviderSendItemResultDto = {
|
const failure: TspProviderSendItemResultDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: mappedRequest,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: true,
|
hasError: true,
|
||||||
message: (err as Error).message,
|
message: (err as Error).message,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
@@ -201,7 +201,7 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
const result: TspProviderGetResultDto = {
|
const result: TspProviderGetResultDto = {
|
||||||
hasError: !response.ok,
|
hasError: !response.ok,
|
||||||
message: providerResponse.message,
|
message: providerResponse.message,
|
||||||
response_payload: providerResponse,
|
provider_response_payload: providerResponse,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
received_at: providerResponse.tsp_update_time || new Date().toISOString(),
|
received_at: providerResponse.tsp_update_time || new Date().toISOString(),
|
||||||
tax_id: providerResponse.tax_id,
|
tax_id: providerResponse.tax_id,
|
||||||
@@ -248,11 +248,11 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
|
|
||||||
const result: TspProviderRevokeResponseDto = {
|
const result: TspProviderRevokeResponseDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: mappedRequest,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: !response.ok,
|
hasError: !response.ok,
|
||||||
message: providerResponse.message,
|
message: providerResponse.message,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
response_payload: providerResponse,
|
provider_response_payload: providerResponse,
|
||||||
received_at: providerResponse.tsp_update_time,
|
received_at: providerResponse.tsp_update_time,
|
||||||
tax_id: providerResponse.tax_id,
|
tax_id: providerResponse.tax_id,
|
||||||
status: this.namaProviderUtils.mapResponseStatus(
|
status: this.namaProviderUtils.mapResponseStatus(
|
||||||
@@ -265,7 +265,7 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
this.logger.error('NAMA Revoke failed', err)
|
this.logger.error('NAMA Revoke failed', err)
|
||||||
const failure: TspProviderRevokeResponseDto = {
|
const failure: TspProviderRevokeResponseDto = {
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
request_payload: mappedRequest,
|
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||||
hasError: true,
|
hasError: true,
|
||||||
message: (err as Error).message,
|
message: (err as Error).message,
|
||||||
sent_at: new Date().toISOString(),
|
sent_at: new Date().toISOString(),
|
||||||
|
|||||||
@@ -0,0 +1,513 @@
|
|||||||
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
|
import { BadRequestException, NotFoundException } from '@nestjs/common'
|
||||||
|
import { TspProviderCustomerType } from 'common/enums/enums'
|
||||||
|
import {
|
||||||
|
Prisma,
|
||||||
|
TspProviderRequestType,
|
||||||
|
TspProviderResponseStatus,
|
||||||
|
} from 'generated/prisma/client'
|
||||||
|
import {
|
||||||
|
TspProviderActionResponseDto,
|
||||||
|
TspProviderCorrectionSendPayloadDto,
|
||||||
|
TspProviderOriginalSendPayloadDto,
|
||||||
|
TspProviderRevokePayloadDto,
|
||||||
|
TspProviderSendItemResultDto,
|
||||||
|
} from '../dto/provider-switch.dto'
|
||||||
|
|
||||||
|
export async function getOriginalResendAttemptNumber(
|
||||||
|
prisma: PrismaService,
|
||||||
|
invoice_id: string,
|
||||||
|
): Promise<number> {
|
||||||
|
let attemptNumber = 1
|
||||||
|
|
||||||
|
const existingAttempt = await prisma.saleInvoiceTspAttempts.findFirst({
|
||||||
|
where: {
|
||||||
|
invoice_id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
invoice: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (existingAttempt) {
|
||||||
|
attemptNumber = existingAttempt.attempt_no + 1
|
||||||
|
if (existingAttempt.invoice.type !== TspProviderRequestType.ORIGINAL) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'فقط فاکتورهای اصلی قابل ارسال مجدد به سامانه مالیاتی هستند.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingAttempt.status === TspProviderResponseStatus.SUCCESS) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'فاکتور تایید شده از طرف سازمان مالیاتی قابل ارسال مجدد نیست.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (existingAttempt.status === TspProviderResponseStatus.QUEUED) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'در حال حاضر فاکتور شما در حال بررسی توسط سازمان مالیاتی است.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return attemptNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildRevokePayload(
|
||||||
|
prisma: PrismaService,
|
||||||
|
invoiceId: string,
|
||||||
|
posId: string,
|
||||||
|
): Promise<TspProviderRevokePayloadDto> {
|
||||||
|
const invoice = await prisma.salesInvoice.findUnique({
|
||||||
|
where: {
|
||||||
|
id: invoiceId,
|
||||||
|
pos_id: posId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
total_amount: true,
|
||||||
|
invoice_date: true,
|
||||||
|
invoice_number: true,
|
||||||
|
tax_id: true,
|
||||||
|
tsp_attempts: {
|
||||||
|
orderBy: {
|
||||||
|
created_at: 'asc',
|
||||||
|
},
|
||||||
|
take: 1,
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
status: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pos: {
|
||||||
|
select: {
|
||||||
|
complex: {
|
||||||
|
select: {
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
fiscal_id: true,
|
||||||
|
economic_code: true,
|
||||||
|
partner_token: true,
|
||||||
|
guild: {
|
||||||
|
select: {
|
||||||
|
invoice_template: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
consumer: {
|
||||||
|
select: {
|
||||||
|
legal: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
individual: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!invoice) {
|
||||||
|
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
||||||
|
invoice.pos.complex.business_activity.consumer.individual)!
|
||||||
|
|
||||||
|
return {
|
||||||
|
invoice_id: invoice.id,
|
||||||
|
invoice_number: invoice.invoice_number,
|
||||||
|
economic_code: invoice.pos.complex.business_activity.economic_code,
|
||||||
|
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
||||||
|
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
||||||
|
tsp_provider: partner.tsp_provider!,
|
||||||
|
last_tax_id: invoice.tax_id!,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildCorrectionPayload(
|
||||||
|
tx: Prisma.TransactionClient,
|
||||||
|
invoice_id: string,
|
||||||
|
): Promise<TspProviderCorrectionSendPayloadDto> {
|
||||||
|
const invoice = await tx.salesInvoice.findUnique({
|
||||||
|
where: {
|
||||||
|
id: invoice_id,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
total_amount: true,
|
||||||
|
invoice_date: true,
|
||||||
|
invoice_number: true,
|
||||||
|
items: true,
|
||||||
|
pos: {
|
||||||
|
select: {
|
||||||
|
complex: {
|
||||||
|
select: {
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
fiscal_id: true,
|
||||||
|
economic_code: true,
|
||||||
|
partner_token: true,
|
||||||
|
guild: {
|
||||||
|
select: {
|
||||||
|
invoice_template: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
consumer: {
|
||||||
|
select: {
|
||||||
|
legal: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
individual: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
individual: true,
|
||||||
|
legal: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reference_invoice: {
|
||||||
|
select: {
|
||||||
|
tax_id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payments: {
|
||||||
|
include: {
|
||||||
|
terminal_info: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!invoice) {
|
||||||
|
throw Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
||||||
|
invoice.pos.complex.business_activity.consumer.individual)!
|
||||||
|
|
||||||
|
return {
|
||||||
|
items: invoice.items.map(item => ({
|
||||||
|
invoice_item_id: item.id,
|
||||||
|
quantity: Number(item.quantity),
|
||||||
|
unit_price: Number(item.unit_price),
|
||||||
|
total_amount: Number(item.total_amount),
|
||||||
|
measure_unit: item.measure_unit_code,
|
||||||
|
sku: item.sku_code,
|
||||||
|
sku_vat: String(item.sku_vat),
|
||||||
|
discount: String((item.payload as Record<string, any>)?.discount || '0'),
|
||||||
|
good_id: item.good_id,
|
||||||
|
service_id: item.service_id,
|
||||||
|
payload: item.payload,
|
||||||
|
good_snapshot: item.good_snapshot,
|
||||||
|
})),
|
||||||
|
payments: invoice.payments.map(payment => ({
|
||||||
|
amount: Number(payment.amount),
|
||||||
|
payment_method: payment.payment_method,
|
||||||
|
paid_at: payment.paid_at,
|
||||||
|
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
||||||
|
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
||||||
|
})),
|
||||||
|
total_amount: Number(invoice.total_amount),
|
||||||
|
last_tax_id: invoice.reference_invoice!.tax_id!,
|
||||||
|
invoice_number: invoice.invoice_number,
|
||||||
|
invoice_id: invoice.id,
|
||||||
|
economic_code: invoice.pos.complex.business_activity.economic_code,
|
||||||
|
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
||||||
|
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
||||||
|
type: TspProviderRequestType.CORRECTION,
|
||||||
|
tsp_provider: partner.tsp_provider!,
|
||||||
|
invoice_template: invoice.pos.complex.business_activity.guild.invoice_template,
|
||||||
|
invoice_date: new Date(),
|
||||||
|
|
||||||
|
customer_type: invoice.customer?.type
|
||||||
|
? TspProviderCustomerType.KNOWN
|
||||||
|
: TspProviderCustomerType.UNKNOWN,
|
||||||
|
customer: invoice.customer?.type
|
||||||
|
? {
|
||||||
|
type: invoice.customer.type,
|
||||||
|
legal_info: invoice.customer.legal ?? undefined,
|
||||||
|
individual_info: invoice.customer.individual ?? undefined,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildPayload(
|
||||||
|
prisma: PrismaService,
|
||||||
|
invoiceId: string,
|
||||||
|
posId: string,
|
||||||
|
): Promise<TspProviderOriginalSendPayloadDto> {
|
||||||
|
const invoice = await prisma.salesInvoice.findUnique({
|
||||||
|
where: {
|
||||||
|
id: invoiceId,
|
||||||
|
pos_id: posId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
total_amount: true,
|
||||||
|
invoice_date: true,
|
||||||
|
invoice_number: true,
|
||||||
|
items: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
quantity: true,
|
||||||
|
unit_price: true,
|
||||||
|
total_amount: true,
|
||||||
|
measure_unit_code: true,
|
||||||
|
measure_unit_text: true,
|
||||||
|
sku_code: true,
|
||||||
|
sku_vat: true,
|
||||||
|
good_id: true,
|
||||||
|
service_id: true,
|
||||||
|
payload: true,
|
||||||
|
good_snapshot: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pos: {
|
||||||
|
select: {
|
||||||
|
complex: {
|
||||||
|
select: {
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
fiscal_id: true,
|
||||||
|
economic_code: true,
|
||||||
|
partner_token: true,
|
||||||
|
guild: {
|
||||||
|
select: {
|
||||||
|
invoice_template: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
consumer: {
|
||||||
|
select: {
|
||||||
|
legal: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
individual: {
|
||||||
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
tsp_provider: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
individual: {
|
||||||
|
select: {
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
national_id: true,
|
||||||
|
mobile_number: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
legal: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
economic_code: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payments: {
|
||||||
|
select: {
|
||||||
|
amount: true,
|
||||||
|
payment_method: true,
|
||||||
|
paid_at: true,
|
||||||
|
terminal_info: {
|
||||||
|
select: {
|
||||||
|
stan: true,
|
||||||
|
rrn: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!invoice) {
|
||||||
|
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { partner } = (invoice.pos.complex.business_activity.consumer.legal ||
|
||||||
|
invoice.pos.complex.business_activity.consumer.individual)!
|
||||||
|
|
||||||
|
return {
|
||||||
|
invoice_id: invoice.id,
|
||||||
|
invoice_number: invoice.invoice_number,
|
||||||
|
invoice_date: invoice.invoice_date,
|
||||||
|
total_amount: Number(invoice.total_amount),
|
||||||
|
economic_code: invoice.pos.complex.business_activity.economic_code,
|
||||||
|
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
||||||
|
invoice_template: invoice.pos.complex.business_activity.guild.invoice_template,
|
||||||
|
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
||||||
|
payments: invoice.payments.map(payment => ({
|
||||||
|
amount: Number(payment.amount),
|
||||||
|
payment_method: payment.payment_method,
|
||||||
|
paid_at: payment.paid_at,
|
||||||
|
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
||||||
|
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
||||||
|
})),
|
||||||
|
type: TspProviderRequestType.ORIGINAL,
|
||||||
|
tsp_provider: partner.tsp_provider!,
|
||||||
|
customer_type: invoice.customer?.type
|
||||||
|
? TspProviderCustomerType.KNOWN
|
||||||
|
: TspProviderCustomerType.UNKNOWN,
|
||||||
|
customer: invoice.customer?.type
|
||||||
|
? {
|
||||||
|
type: invoice.customer.type,
|
||||||
|
legal_info: invoice.customer.legal ?? undefined,
|
||||||
|
individual_info: invoice.customer.individual ?? undefined,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
items: invoice.items.map(item => ({
|
||||||
|
invoice_item_id: item.id,
|
||||||
|
quantity: Number(item.quantity),
|
||||||
|
unit_price: Number(item.unit_price),
|
||||||
|
total_amount: Number(item.total_amount),
|
||||||
|
measure_unit: item.measure_unit_code,
|
||||||
|
sku: item.sku_code,
|
||||||
|
sku_vat: String(item.sku_vat),
|
||||||
|
discount: String((item.payload as Record<string, any>)?.discount || '0'),
|
||||||
|
good_id: item.good_id,
|
||||||
|
service_id: item.service_id,
|
||||||
|
payload: item.payload,
|
||||||
|
good_snapshot: item.good_snapshot,
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function trySend(
|
||||||
|
tspSwitchService: {
|
||||||
|
send(
|
||||||
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): Promise<TspProviderSendItemResultDto | null>
|
||||||
|
},
|
||||||
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): Promise<TspProviderSendItemResultDto | null> {
|
||||||
|
return (await tspSwitchService.send(payload)) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function onResult(
|
||||||
|
prisma: PrismaService,
|
||||||
|
result: any,
|
||||||
|
attempt_id: string,
|
||||||
|
): Promise<TspProviderActionResponseDto> {
|
||||||
|
if (result) {
|
||||||
|
if (result.hasError) {
|
||||||
|
const updatedAttempt = await prisma.saleInvoiceTspAttempts.update({
|
||||||
|
where: {
|
||||||
|
id: attempt_id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
provider_request_payload: result.provider_request_payload,
|
||||||
|
provider_response_payload: JSON.parse(JSON.stringify(result)),
|
||||||
|
status: result.status,
|
||||||
|
message: result.message?.toString() || 'وجود مشکل در ارسال به سامانه مالیاتی',
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
status: true,
|
||||||
|
invoice: true,
|
||||||
|
message: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
invoice: updatedAttempt.invoice,
|
||||||
|
status: updatedAttempt.status,
|
||||||
|
message: updatedAttempt.message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedAttempt = await prisma.saleInvoiceTspAttempts.update({
|
||||||
|
where: {
|
||||||
|
id: attempt_id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
provider_request_payload: result.provider_request_payload,
|
||||||
|
provider_response_payload: JSON.parse(JSON.stringify(result)),
|
||||||
|
status: result.status,
|
||||||
|
sent_at: result.sent_at,
|
||||||
|
received_at: result.received_at,
|
||||||
|
message:
|
||||||
|
result.message?.toString() || 'فاکتور با موفقیت به سامانه مالیاتی ارسال شد.',
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
status: true,
|
||||||
|
invoice: true,
|
||||||
|
message: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
invoice: updatedAttempt.invoice,
|
||||||
|
status: updatedAttempt.status,
|
||||||
|
message: updatedAttempt.message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotFoundException(
|
||||||
|
'متاسفانه امکان ارسال فاکتور به سیستم مالیاتی در حال حاضر وجود ندارد. لطفا بعدا تلاش کنید.',
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { PrismaMariaDb } from '@prisma/adapter-mariadb'
|
|||||||
import 'dotenv/config'
|
import 'dotenv/config'
|
||||||
import { env } from 'prisma/config'
|
import { env } from 'prisma/config'
|
||||||
import { PrismaClient } from '../generated/prisma/client'
|
import { PrismaClient } from '../generated/prisma/client'
|
||||||
|
import { getPrismaOptions } from './prisma-config.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||||
@@ -13,9 +14,11 @@ export class PrismaService extends PrismaClient implements OnModuleInit, OnModul
|
|||||||
password: env('DATABASE_PASSWORD'),
|
password: env('DATABASE_PASSWORD'),
|
||||||
database: env('DATABASE_NAME'),
|
database: env('DATABASE_NAME'),
|
||||||
port: env('DATABASE_PORT') ? Number(env('DATABASE_PORT')) : 3306,
|
port: env('DATABASE_PORT') ? Number(env('DATABASE_PORT')) : 3306,
|
||||||
connectionLimit: 5,
|
connectionLimit: 50,
|
||||||
})
|
})
|
||||||
super({ adapter })
|
|
||||||
|
const prismaOptions = getPrismaOptions()
|
||||||
|
super({ ...prismaOptions, adapter })
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user