feat: implement correction and original send functionality for Nama provider
- Added new DTOs for correction requests and responses in `nama-provider.dto.ts`. - Updated `nama-provider.adapter.ts` to include `originalSend` and `correctionSend` methods. - Enhanced `nama-provider.util.ts` with mapping functions for correction requests. - Created operational guidelines for agents in `AGENT.md`. - Updated Prisma migrations to support new invoice types and relationships. - Introduced new service and DTO for creating sales invoices in `sale-invoice-create.service.ts` and `sale-invoice-create.dto.ts`. - Added utility for handling Prisma errors in `prisma-error.util.ts`.
This commit is contained in:
@@ -0,0 +1,80 @@
|
|||||||
|
# AGENT.md
|
||||||
|
|
||||||
|
Operational guide for AI/coding agents working in `consumer_api`.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
- Applies to the whole repository.
|
||||||
|
- Stack: NestJS + Prisma + TypeScript.
|
||||||
|
|
||||||
|
## Primary Goals
|
||||||
|
- Deliver minimal, safe, and focused changes.
|
||||||
|
- Preserve existing API behavior unless explicitly requested.
|
||||||
|
- Keep Prisma schema/data operations forward-safe.
|
||||||
|
|
||||||
|
## Project Conventions
|
||||||
|
- Keep module layering consistent: `controller -> service -> prisma/shared service`.
|
||||||
|
- Reuse shared services for cross-module business logic (for example, sales invoice create flow).
|
||||||
|
- Keep DTO validation at API boundaries; avoid unchecked `any` in new code.
|
||||||
|
- Keep response shaping aligned with existing `ResponseMapper` usage.
|
||||||
|
- Prefer explicit Prisma `select`/`include` to control payload shape.
|
||||||
|
|
||||||
|
## Sales Invoice / TSP Rules
|
||||||
|
- `originalSend`, `correctionSend`, and `revoke` flows should be consistent and auditable.
|
||||||
|
- For correction/revoke creation, prepare data from the related invoice when required.
|
||||||
|
- Persist attempt records with clear status transitions (`QUEUED` -> final status).
|
||||||
|
- Store request/response payloads for traceability.
|
||||||
|
- Avoid changing fiscal/tax status semantics without explicit approval.
|
||||||
|
|
||||||
|
## Prisma and Migration Safety
|
||||||
|
- Treat committed migrations as immutable history.
|
||||||
|
- Prefer forward migrations; avoid destructive resets unless explicitly requested.
|
||||||
|
- For data-affecting changes:
|
||||||
|
- use transactions,
|
||||||
|
- verify expected row scope,
|
||||||
|
- keep logic idempotent where possible.
|
||||||
|
|
||||||
|
## Editing Principles
|
||||||
|
- Do not modify unrelated files.
|
||||||
|
- Do not revert user changes unless asked.
|
||||||
|
- Keep functions cohesive; extract shared logic when duplication appears.
|
||||||
|
- Remove debug leftovers (`console.log`, dead code) before finishing unless explicitly needed.
|
||||||
|
|
||||||
|
## Validation Checklist (before handoff)
|
||||||
|
1. Read target module/service/DTO end-to-end before edits.
|
||||||
|
2. Apply minimal patch with consistent naming.
|
||||||
|
3. Run typecheck: `pnpm -s tsc --noEmit`.
|
||||||
|
4. If behavior changed, run targeted checks/tests where possible.
|
||||||
|
5. Summarize changed files and behavior impact clearly.
|
||||||
|
|
||||||
|
## Useful Commands
|
||||||
|
- Typecheck: `pnpm -s tsc --noEmit`
|
||||||
|
- Migration status: `pnpm prisma migrate status`
|
||||||
|
- Create migration: `pnpm prisma migrate dev --name <name>`
|
||||||
|
- Deploy migrations: `pnpm prisma migrate deploy`
|
||||||
|
|
||||||
|
## Communication Style
|
||||||
|
- Be concise and implementation-focused.
|
||||||
|
- Call out assumptions/risk before risky steps.
|
||||||
|
- Provide practical next actions after task completion.
|
||||||
|
|
||||||
|
## Do / Don't (Repo-Specific)
|
||||||
|
|
||||||
|
### Do
|
||||||
|
- Do derive correction/revoke invoice creation data from `relatedInvoice` when the flow requires historical consistency.
|
||||||
|
- Do keep TSP attempt lifecycle explicit (`QUEUED`, then update with provider result and timestamps).
|
||||||
|
- Do use shared invoice-creation service instead of duplicating create logic across modules.
|
||||||
|
- Do normalize numeric DB values (`Decimal`) with `Number(...)` before DTO/payload composition.
|
||||||
|
- Do keep Prisma queries tight with `select`/`include` only for fields you actually use.
|
||||||
|
|
||||||
|
### Don't
|
||||||
|
- Don't pass undefined/out-of-scope variables in TSP flows (common regressions: `invoice_id`, `attemptId`, `pos_id` mismatches).
|
||||||
|
- Don't leave placeholder query blocks (for example empty `select: {}`) in production code.
|
||||||
|
- Don't mix method semantics (`send` vs `originalSend`) across services without verifying signatures.
|
||||||
|
- Don't leave debug logs (`console.log`) in critical invoice/tax paths unless explicitly requested.
|
||||||
|
- Don't change invoice type semantics (`ORIGINAL`, `CORRECTION`, `REVOKE`) implicitly.
|
||||||
|
|
||||||
|
### Common Pitfalls To Recheck
|
||||||
|
- Incorrect relation field names (`tax_id` on wrong model, missing relation selects).
|
||||||
|
- 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.
|
||||||
|
- Mismatch between DTO shapes and shared service input contracts.
|
||||||
+14
-23
@@ -1,48 +1,39 @@
|
|||||||
FROM node:22-slim AS deps
|
FROM node:22-slim AS base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG NPM_REGISTRY=https://registry.npmjs.org/
|
ARG NPM_REGISTRY=https://registry.npmjs.org/
|
||||||
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
|
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
|
||||||
ENV npm_config_registry=${NPM_REGISTRY}
|
ENV npm_config_registry=${NPM_REGISTRY}
|
||||||
|
ENV PNPM_HOME="/pnpm"
|
||||||
|
ENV PATH="${PNPM_HOME}:${PATH}"
|
||||||
|
|
||||||
RUN corepack enable
|
RUN corepack enable && npm config set registry ${NPM_REGISTRY}
|
||||||
RUN npm config set registry ${NPM_REGISTRY}
|
|
||||||
|
FROM base AS build
|
||||||
|
|
||||||
COPY package.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
RUN pnpm install --frozen-lockfile
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
|
||||||
FROM node:22-slim AS build
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
ARG NPM_REGISTRY=https://registry.npmjs.org/
|
|
||||||
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
|
|
||||||
ENV npm_config_registry=${NPM_REGISTRY}
|
|
||||||
|
|
||||||
RUN corepack enable
|
|
||||||
RUN npm config set registry ${NPM_REGISTRY}
|
|
||||||
|
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ENV PRISMA_CLIENT_ENGINE_TYPE=binary
|
ENV PRISMA_CLIENT_ENGINE_TYPE=binary
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
RUN pnpm run build && pnpm prune --prod
|
FROM base AS prod-deps
|
||||||
|
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install --prod --frozen-lockfile \
|
||||||
|
&& pnpm store prune \
|
||||||
|
&& rm -rf /root/.npm /root/.cache
|
||||||
|
|
||||||
FROM node:22-slim AS runtime
|
FROM node:22-slim AS runtime
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG NPM_REGISTRY=https://registry.npmjs.org/
|
|
||||||
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
|
|
||||||
ENV npm_config_registry=${NPM_REGISTRY}
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
COPY --from=build /app/node_modules ./node_modules
|
COPY --from=prod-deps /app/node_modules ./node_modules
|
||||||
COPY --from=build /app/dist ./dist
|
COPY --from=build /app/dist ./dist
|
||||||
COPY --from=build /app/prisma ./prisma
|
COPY --from=build /app/prisma ./prisma
|
||||||
COPY --from=build /app/package.json ./package.json
|
COPY --from=build /app/package.json ./package.json
|
||||||
|
|
||||||
|
USER node
|
||||||
CMD ["node", "dist/src/main.js"]
|
CMD ["node", "dist/src/main.js"]
|
||||||
|
|
||||||
|
|||||||
+48
-5
@@ -15,7 +15,6 @@ services:
|
|||||||
- "${DATABASE_PORT}:3306"
|
- "${DATABASE_PORT}:3306"
|
||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
- ./prisma/migrations:/docker-entrypoint-initdb.d
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: "mysqladmin ping -h 127.0.0.1 -u ${DATABASE_USER} -p'${DB_ROOT_PASSWORD}'"
|
test: "mysqladmin ping -h 127.0.0.1 -u ${DATABASE_USER} -p'${DB_ROOT_PASSWORD}'"
|
||||||
interval: 15s # Shortened interval, as MySQL is starting fast now
|
interval: 15s # Shortened interval, as MySQL is starting fast now
|
||||||
@@ -68,10 +67,13 @@ services:
|
|||||||
OTP_STATIC_CODE: ${OTP_STATIC_CODE} # From .env
|
OTP_STATIC_CODE: ${OTP_STATIC_CODE} # From .env
|
||||||
ports:
|
ports:
|
||||||
- "${PORT:-5002}:5002"
|
- "${PORT:-5002}:5002"
|
||||||
volumes:
|
read_only: true
|
||||||
- ./src:/app/src
|
tmpfs:
|
||||||
- /app/dist
|
- /tmp
|
||||||
- /app/node_modules
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
cap_drop:
|
||||||
|
- ALL
|
||||||
networks:
|
networks:
|
||||||
- psp_consumer_network
|
- psp_consumer_network
|
||||||
# healthcheck:
|
# healthcheck:
|
||||||
@@ -89,6 +91,47 @@ services:
|
|||||||
# retries: 3
|
# retries: 3
|
||||||
# start_period: 10s
|
# start_period: 10s
|
||||||
|
|
||||||
|
seed:
|
||||||
|
platform: ${DOCKER_PLATFORM:-linux/amd64}
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
target: build
|
||||||
|
args:
|
||||||
|
NODE_ENV: ${NODE_ENV:-production}
|
||||||
|
PORT: ${PORT}
|
||||||
|
DATABASE_NAME: ${DATABASE_NAME}
|
||||||
|
DATABASE_USER: ${DATABASE_USER}
|
||||||
|
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
|
||||||
|
DATABASE_PORT: ${DATABASE_PORT}
|
||||||
|
DATABASE_HOST: ${DATABASE_HOST}
|
||||||
|
DATABASE_URL: mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
|
||||||
|
SHADOW_DATABASE_URL: mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}_shadow
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN}
|
||||||
|
OTP_STATIC_CODE: ${OTP_STATIC_CODE}
|
||||||
|
depends_on:
|
||||||
|
database:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
NODE_ENV: ${NODE_ENV:-production}
|
||||||
|
PORT: ${PORT}
|
||||||
|
DATABASE_NAME: ${DATABASE_NAME}
|
||||||
|
DATABASE_USER: ${DATABASE_USER}
|
||||||
|
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
|
||||||
|
DATABASE_PORT: ${DATABASE_PORT}
|
||||||
|
DATABASE_HOST: ${DATABASE_HOST}
|
||||||
|
DATABASE_URL: mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
|
||||||
|
SHADOW_DATABASE_URL: mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}_shadow
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN}
|
||||||
|
OTP_STATIC_CODE: ${OTP_STATIC_CODE}
|
||||||
|
networks:
|
||||||
|
- psp_consumer_network
|
||||||
|
profiles:
|
||||||
|
- tools
|
||||||
|
command: ["pnpm", "seed:sku"]
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db_data:
|
db_data:
|
||||||
driver: local
|
driver: local
|
||||||
|
|||||||
+1
-1
@@ -8,6 +8,7 @@
|
|||||||
"@nestjs/jwt": "^11.0.2",
|
"@nestjs/jwt": "^11.0.2",
|
||||||
"@nestjs/platform-express": "^11.1.19",
|
"@nestjs/platform-express": "^11.1.19",
|
||||||
"@nestjs/swagger": "^11.3.2",
|
"@nestjs/swagger": "^11.3.2",
|
||||||
|
"@prisma/client": "^7.7.0",
|
||||||
"@prisma/adapter-mariadb": "^7.7.0",
|
"@prisma/adapter-mariadb": "^7.7.0",
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"@types/multer": "^2.1.0",
|
"@types/multer": "^2.1.0",
|
||||||
@@ -33,7 +34,6 @@
|
|||||||
"@nestjs/cli": "^11.0.21",
|
"@nestjs/cli": "^11.0.21",
|
||||||
"@nestjs/schematics": "^11.1.0",
|
"@nestjs/schematics": "^11.1.0",
|
||||||
"@nestjs/testing": "^11.1.19",
|
"@nestjs/testing": "^11.1.19",
|
||||||
"@prisma/client": "^7.7.0",
|
|
||||||
"@types/cookie-parser": "^1.4.10",
|
"@types/cookie-parser": "^1.4.10",
|
||||||
"@types/express": "^5.0.6",
|
"@types/express": "^5.0.6",
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
|
|||||||
Generated
+3
-3
@@ -32,6 +32,9 @@ importers:
|
|||||||
'@prisma/adapter-mariadb':
|
'@prisma/adapter-mariadb':
|
||||||
specifier: ^7.7.0
|
specifier: ^7.7.0
|
||||||
version: 7.7.0
|
version: 7.7.0
|
||||||
|
'@prisma/client':
|
||||||
|
specifier: ^7.7.0
|
||||||
|
version: 7.7.0(prisma@7.7.0(@types/react@19.2.7)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(typescript@5.9.3))(typescript@5.9.3)
|
||||||
'@types/bcrypt':
|
'@types/bcrypt':
|
||||||
specifier: ^6.0.0
|
specifier: ^6.0.0
|
||||||
version: 6.0.0
|
version: 6.0.0
|
||||||
@@ -96,9 +99,6 @@ importers:
|
|||||||
'@nestjs/testing':
|
'@nestjs/testing':
|
||||||
specifier: ^11.1.19
|
specifier: ^11.1.19
|
||||||
version: 11.1.19(@nestjs/common@11.1.19(class-transformer@0.5.1)(class-validator@0.14.4)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.19)(@nestjs/platform-express@11.1.19)
|
version: 11.1.19(@nestjs/common@11.1.19(class-transformer@0.5.1)(class-validator@0.14.4)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.19)(@nestjs/platform-express@11.1.19)
|
||||||
'@prisma/client':
|
|
||||||
specifier: ^7.7.0
|
|
||||||
version: 7.7.0(prisma@7.7.0(@types/react@19.2.7)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(typescript@5.9.3))(typescript@5.9.3)
|
|
||||||
'@types/cookie-parser':
|
'@types/cookie-parser':
|
||||||
specifier: ^1.4.10
|
specifier: ^1.4.10
|
||||||
version: 1.4.10(@types/express@5.0.6)
|
version: 1.4.10(@types/express@5.0.6)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `type` on the `sale_invoice_tsp_attempts` table. All the data in the column will be lost.
|
||||||
|
- A unique constraint covering the columns `[ref_id]` on the table `sales_invoices` will be added. If there are existing duplicate values, this will fail.
|
||||||
|
- Added the required column `type` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts` DROP COLUMN `type`;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `sales_invoices` ADD COLUMN `main_id` VARCHAR(50) NULL,
|
||||||
|
ADD COLUMN `ref_id` VARCHAR(50) NULL,
|
||||||
|
ADD COLUMN `type` ENUM('ORIGINAL', 'CORRECTION', 'REVOKE', 'RETURN') NOT NULL;
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX `sales_invoices_ref_id_key` ON `sales_invoices`(`ref_id`);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX `sales_invoices_ref_id_idx` ON `sales_invoices`(`ref_id`);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_ref_id_fkey` FOREIGN KEY (`ref_id`) REFERENCES `sales_invoices`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `error_message` on the `sale_invoice_tsp_attempts` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `tax_id` on the `sale_invoice_tsp_attempts` table. All the data in the column will be lost.
|
||||||
|
- A unique constraint covering the columns `[tax_id]` on the table `sales_invoices` will be added. If there are existing duplicate values, this will fail.
|
||||||
|
- Added the required column `message` to the `sale_invoice_tsp_attempts` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- 1) Add new columns in a backward-compatible way
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts`
|
||||||
|
ADD COLUMN `message` TEXT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `sales_invoices`
|
||||||
|
ADD COLUMN `tax_id` VARCHAR(32) NULL;
|
||||||
|
|
||||||
|
-- 2) Backfill message from old error_message, fallback to a default text
|
||||||
|
UPDATE `sale_invoice_tsp_attempts`
|
||||||
|
SET `message` = COALESCE(`error_message`, 'وضعیت ارسال فاکتور ثبت شد.')
|
||||||
|
WHERE `message` IS NULL;
|
||||||
|
|
||||||
|
-- 3) Backfill tax_id to sales_invoices from attempts
|
||||||
|
UPDATE `sales_invoices` si
|
||||||
|
JOIN `sale_invoice_tsp_attempts` sita ON sita.`invoice_id` = si.`id`
|
||||||
|
SET si.`tax_id` = sita.`tax_id`
|
||||||
|
WHERE sita.`tax_id` IS NOT NULL
|
||||||
|
AND si.`tax_id` IS NULL;
|
||||||
|
|
||||||
|
-- 4) Enforce required constraint after backfill
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts`
|
||||||
|
MODIFY `message` TEXT NOT NULL;
|
||||||
|
|
||||||
|
-- 5) Remove old indexes/columns after successful data move
|
||||||
|
DROP INDEX `sale_invoice_tsp_attempts_tax_id_idx` ON `sale_invoice_tsp_attempts`;
|
||||||
|
DROP INDEX `sale_invoice_tsp_attempts_tax_id_key` ON `sale_invoice_tsp_attempts`;
|
||||||
|
|
||||||
|
ALTER TABLE `sale_invoice_tsp_attempts`
|
||||||
|
DROP COLUMN `error_message`,
|
||||||
|
DROP COLUMN `tax_id`;
|
||||||
|
|
||||||
|
-- 6) Add indexes on new tax_id location
|
||||||
|
CREATE UNIQUE INDEX `sales_invoices_tax_id_key` ON `sales_invoices`(`tax_id`);
|
||||||
|
CREATE INDEX `sales_invoices_tax_id_idx` ON `sales_invoices`(`tax_id`);
|
||||||
@@ -167,12 +167,11 @@ enum TspProviderResponseStatus {
|
|||||||
FAILURE
|
FAILURE
|
||||||
NOT_SEND
|
NOT_SEND
|
||||||
QUEUED
|
QUEUED
|
||||||
REVOKED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TspProviderRequestType {
|
enum TspProviderRequestType {
|
||||||
MAIN
|
ORIGINAL
|
||||||
UPDATE
|
CORRECTION
|
||||||
REVOKE
|
REVOKE
|
||||||
RETURN
|
RETURN
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
model SalesInvoice {
|
model SalesInvoice {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
code String @unique @db.VarChar(100)
|
code String @unique @db.VarChar(100)
|
||||||
total_amount Decimal @db.Decimal(15, 2)
|
total_amount Decimal @db.Decimal(15, 2)
|
||||||
invoice_number Int @db.Int()
|
invoice_number Int @db.Int()
|
||||||
invoice_date DateTime @default(now()) @db.Timestamp(0)
|
invoice_date DateTime @default(now()) @db.Timestamp(0)
|
||||||
|
type TspProviderRequestType
|
||||||
|
tax_id String? @unique @db.VarChar(32)
|
||||||
|
|
||||||
notes String? @db.Text
|
notes String? @db.Text
|
||||||
unknown_customer Json? @db.Json
|
unknown_customer Json? @db.Json
|
||||||
@@ -11,6 +13,10 @@ model SalesInvoice {
|
|||||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||||
updated_at DateTime @updatedAt @db.Timestamp(0)
|
updated_at DateTime @updatedAt @db.Timestamp(0)
|
||||||
|
|
||||||
|
main_id String? @db.VarChar(50)
|
||||||
|
ref_id String? @unique @db.VarChar(50)
|
||||||
|
reference_invoice SalesInvoice? @relation("SalesInvoiceReference", fields: [ref_id], references: [id])
|
||||||
|
|
||||||
customer_id String?
|
customer_id String?
|
||||||
customer Customer? @relation(fields: [customer_id], references: [id])
|
customer Customer? @relation(fields: [customer_id], references: [id])
|
||||||
|
|
||||||
@@ -20,11 +26,14 @@ model SalesInvoice {
|
|||||||
pos_id String
|
pos_id String
|
||||||
pos Pos @relation(fields: [pos_id], references: [id])
|
pos Pos @relation(fields: [pos_id], references: [id])
|
||||||
|
|
||||||
items SalesInvoiceItem[]
|
referenced_by SalesInvoice? @relation("SalesInvoiceReference")
|
||||||
payments SalesInvoicePayment[]
|
items SalesInvoiceItem[]
|
||||||
tsp_attempts SaleInvoiceTspAttempts[]
|
payments SalesInvoicePayment[]
|
||||||
|
tsp_attempts SaleInvoiceTspAttempts[]
|
||||||
|
|
||||||
@@unique([invoice_number, pos_id])
|
@@unique([invoice_number, pos_id])
|
||||||
|
@@index([ref_id])
|
||||||
|
@@index([tax_id])
|
||||||
@@map("sales_invoices")
|
@@map("sales_invoices")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +71,10 @@ model SaleInvoiceTspAttempts {
|
|||||||
|
|
||||||
attempt_no Int
|
attempt_no Int
|
||||||
status TspProviderResponseStatus
|
status TspProviderResponseStatus
|
||||||
tax_id String? @unique @db.VarChar(191)
|
|
||||||
type TspProviderRequestType
|
|
||||||
|
|
||||||
request_payload Json?
|
request_payload Json?
|
||||||
response_payload Json?
|
response_payload Json?
|
||||||
error_message String? @db.Text
|
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)
|
||||||
@@ -78,7 +85,6 @@ model SaleInvoiceTspAttempts {
|
|||||||
|
|
||||||
@@unique([invoice_id, attempt_no])
|
@@unique([invoice_id, attempt_no])
|
||||||
@@index([status])
|
@@index([status])
|
||||||
@@index([tax_id])
|
|
||||||
@@index([invoice_id])
|
@@index([invoice_id])
|
||||||
@@map("sale_invoice_tsp_attempts")
|
@@map("sale_invoice_tsp_attempts")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ export default {
|
|||||||
[TspProviderResponseStatus.QUEUED]: 'در صف ارسال',
|
[TspProviderResponseStatus.QUEUED]: 'در صف ارسال',
|
||||||
},
|
},
|
||||||
TspProviderRequestType: {
|
TspProviderRequestType: {
|
||||||
MAIN: 'اصلی',
|
ORIGINAL: 'اصلی',
|
||||||
UPDATE: 'اصلاح',
|
CORRECTION: 'اصلاح',
|
||||||
REVOKE: 'ابطال',
|
REVOKE: 'ابطال',
|
||||||
REMOVE: 'حذف',
|
REMOVE: 'حذف',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ export enum GoldKarat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum TspProviderRequestType {
|
export enum TspProviderRequestType {
|
||||||
MAIN = 'MAIN',
|
ORIGINAL = 'ORIGINAL',
|
||||||
UPDATE = 'UPDATE',
|
CORRECTION = 'CORRECTION',
|
||||||
REVOKE = 'REVOKE',
|
REVOKE = 'REVOKE',
|
||||||
REMOVE = 'REMOVE',
|
REMOVE = 'REMOVE',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const infoSelect: ConsumerSelect = {
|
|||||||
first_name: true,
|
first_name: true,
|
||||||
last_name: true,
|
last_name: true,
|
||||||
mobile_number: true,
|
mobile_number: true,
|
||||||
|
national_code: true,
|
||||||
partner: {
|
partner: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -0,0 +1,209 @@
|
|||||||
|
import type { SaleInvoiceType } from '@/common/interfaces/sale-invoice-payload'
|
||||||
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
|
import { Type } from 'class-transformer'
|
||||||
|
import {
|
||||||
|
ArrayMinSize,
|
||||||
|
IsBoolean,
|
||||||
|
IsDate,
|
||||||
|
IsDateString,
|
||||||
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsNumber,
|
||||||
|
IsObject,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
Min,
|
||||||
|
ValidateNested,
|
||||||
|
} from 'class-validator'
|
||||||
|
import type { CustomerIndividual, CustomerLegal } from 'generated/prisma/client'
|
||||||
|
import { CustomerType } from 'generated/prisma/enums'
|
||||||
|
|
||||||
|
export class SharedCreateSalesInvoiceItemDto {
|
||||||
|
@IsNumber()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
unit_price: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@ApiProperty({ required: true, default: 1 })
|
||||||
|
quantity: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
total_amount: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
discount_amount: number
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
invoice_id: string
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
good_id?: string
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
service_id?: string
|
||||||
|
|
||||||
|
// @IsEnum(SalesInvoiceItemPricingModel)
|
||||||
|
// @ApiProperty({ enum: Object.values(SalesInvoiceItemPricingModel) })
|
||||||
|
// @IsOptional()
|
||||||
|
// pricingModel: SalesInvoiceItemPricingModel
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsObject()
|
||||||
|
@ApiProperty({ required: false, default: {} })
|
||||||
|
payload: SaleInvoiceType
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false, default: '' })
|
||||||
|
notes: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SharedCreateTerminalPayment {
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
amount?: number
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
terminalId: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
stan: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
rrn: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
response_code?: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
customer_card_no?: string
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
|
@IsDate()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
transaction_date_time: Date
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
description?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SharedCreateSalesInvoicePaymentsDto {
|
||||||
|
@IsOptional()
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => SharedCreateTerminalPayment)
|
||||||
|
@ApiProperty({ required: false, type: () => SharedCreateTerminalPayment })
|
||||||
|
terminals?: SharedCreateTerminalPayment
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
cash?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
set_off?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
card?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
bank?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
check?: number
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({ required: false, default: 0 })
|
||||||
|
other?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SharedCreateSalesInvoiceDto {
|
||||||
|
// @TODO: totalAmount must calculated instead of get from api
|
||||||
|
@IsNumber()
|
||||||
|
@ApiProperty({ required: true, default: 0 })
|
||||||
|
total_amount: number
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsDateString(
|
||||||
|
{ strict: true },
|
||||||
|
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||||
|
)
|
||||||
|
invoice_date: Date
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsObject()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => SharedCreateSalesInvoicePaymentsDto)
|
||||||
|
payments: SharedCreateSalesInvoicePaymentsDto
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@ArrayMinSize(1)
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
items: SharedCreateSalesInvoiceItemDto[]
|
||||||
|
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
notes?: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: false, default: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
send_to_tsp?: boolean
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, default: CustomerType.UNKNOWN })
|
||||||
|
@IsEnum(CustomerType)
|
||||||
|
customer_type: CustomerType
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
customer_id?: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsObject()
|
||||||
|
customer?: {
|
||||||
|
customer_individual?: Omit<CustomerIndividual, 'business_activity_id' | 'customer_id'>
|
||||||
|
customer_legal?: Omit<CustomerLegal, 'business_activity_id' | 'customer_id'>
|
||||||
|
customer_unknown?: {
|
||||||
|
first_name: string
|
||||||
|
last_name: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,529 @@
|
|||||||
|
import { SalesInvoiceCreateInput } from '@/generated/prisma/models'
|
||||||
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
|
import { Prisma } from 'generated/prisma/client'
|
||||||
|
import {
|
||||||
|
CustomerType,
|
||||||
|
PaymentMethodType,
|
||||||
|
TspProviderRequestType,
|
||||||
|
} from 'generated/prisma/enums'
|
||||||
|
import { SharedCreateSalesInvoiceDto } from './sale-invoice-create.dto'
|
||||||
|
|
||||||
|
interface TerminalPaymentInfo {
|
||||||
|
terminalId: string
|
||||||
|
stan: string
|
||||||
|
rrn: string
|
||||||
|
transactionDateTime: string | Date
|
||||||
|
customerCardNO?: string
|
||||||
|
description?: string
|
||||||
|
amount?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NormalizedPayment {
|
||||||
|
method: PaymentMethodType
|
||||||
|
amount: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CreateSharedSaleInvoiceInput {
|
||||||
|
tx?: Prisma.TransactionClient
|
||||||
|
data: SharedCreateSalesInvoiceDto
|
||||||
|
businessId: string
|
||||||
|
complexId: string
|
||||||
|
posId: string
|
||||||
|
consumerAccountId: string
|
||||||
|
type: TspProviderRequestType
|
||||||
|
main_invoice_id?: string
|
||||||
|
ref_invoice_id?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SharedSaleInvoiceCreateService {
|
||||||
|
private readonly createInvoiceRetries = 3
|
||||||
|
|
||||||
|
constructor(private prisma: PrismaService) {}
|
||||||
|
|
||||||
|
async create(input: CreateSharedSaleInvoiceInput) {
|
||||||
|
const {
|
||||||
|
tx = this.prisma,
|
||||||
|
data,
|
||||||
|
businessId,
|
||||||
|
complexId,
|
||||||
|
posId,
|
||||||
|
consumerAccountId,
|
||||||
|
type,
|
||||||
|
main_invoice_id,
|
||||||
|
ref_invoice_id,
|
||||||
|
} = input
|
||||||
|
|
||||||
|
const normalizedInvoiceDate = this.normalizeInvoiceDate(data.invoice_date)
|
||||||
|
const { payments, terminalInfo } = this.buildPaymentsData(
|
||||||
|
data.payments,
|
||||||
|
data.total_amount,
|
||||||
|
)
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= this.createInvoiceRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
return await tx.$transaction(async $tx => {
|
||||||
|
const invoiceNumber = await this.getNextInvoiceNumber($tx, businessId)
|
||||||
|
const customerId = await this.resolveCustomerId($tx, data, businessId)
|
||||||
|
const goodsById = await this.getGoodsById($tx, data)
|
||||||
|
const salesInvoiceData = this.buildSalesInvoiceData({
|
||||||
|
data,
|
||||||
|
normalizedInvoiceDate,
|
||||||
|
invoiceNumber,
|
||||||
|
consumerAccountId,
|
||||||
|
businessId,
|
||||||
|
complexId,
|
||||||
|
posId,
|
||||||
|
goodsById,
|
||||||
|
customerId,
|
||||||
|
type,
|
||||||
|
main_invoice_id,
|
||||||
|
ref_invoice_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
const salesInvoice = await $tx.salesInvoice.create({
|
||||||
|
data: salesInvoiceData,
|
||||||
|
})
|
||||||
|
|
||||||
|
await this.createPayments(
|
||||||
|
$tx,
|
||||||
|
salesInvoice.id,
|
||||||
|
payments,
|
||||||
|
terminalInfo,
|
||||||
|
normalizedInvoiceDate,
|
||||||
|
)
|
||||||
|
|
||||||
|
return salesInvoice
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
this.isRetryableInvoiceConflict(error) &&
|
||||||
|
attempt < this.createInvoiceRetries
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadRequestException('ایجاد فاکتور با خطا مواجه شد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
private isRetryableInvoiceConflict(error: unknown) {
|
||||||
|
if (!(error instanceof Prisma.PrismaClientKnownRequestError)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.code !== 'P2002') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const target = (error.meta?.target as string[]) || []
|
||||||
|
return (
|
||||||
|
target.includes('invoice_number') ||
|
||||||
|
target.includes('sales_invoices_invoice_number_pos_id_key')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private normalizeInvoiceDate(invoiceDate: Date | string) {
|
||||||
|
return new Date(invoiceDate).toISOString() as any
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildPaymentsData(
|
||||||
|
paymentsData: SharedCreateSalesInvoiceDto['payments'],
|
||||||
|
totalAmount: number,
|
||||||
|
) {
|
||||||
|
const paymentMethodMap: Record<string, PaymentMethodType> = {
|
||||||
|
cash: PaymentMethodType.CASH,
|
||||||
|
set_off: PaymentMethodType.SET_OFF,
|
||||||
|
card: PaymentMethodType.CARD,
|
||||||
|
payment_gateway: PaymentMethodType.PAYMENT_GATEWAY,
|
||||||
|
bank: PaymentMethodType.BANK,
|
||||||
|
check: PaymentMethodType.CHEQUE,
|
||||||
|
other: PaymentMethodType.OTHER,
|
||||||
|
terminal: PaymentMethodType.TERMINAL,
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawPayments = (paymentsData || {}) as Record<string, unknown>
|
||||||
|
const terminalInfo = rawPayments.terminals as TerminalPaymentInfo | undefined
|
||||||
|
|
||||||
|
const payments: NormalizedPayment[] = Object.entries(rawPayments)
|
||||||
|
.filter(([key]) => key !== 'terminals')
|
||||||
|
.map(([key, value]) => ({
|
||||||
|
method: paymentMethodMap[key.toLowerCase()],
|
||||||
|
amount: typeof value === 'number' ? value : Number(value || 0),
|
||||||
|
}))
|
||||||
|
.filter(payment => payment.method && payment.amount > 0) as NormalizedPayment[]
|
||||||
|
|
||||||
|
const hasTerminalPayment = payments.some(
|
||||||
|
payment => payment.method === PaymentMethodType.TERMINAL,
|
||||||
|
)
|
||||||
|
const nonTerminalTotal = payments
|
||||||
|
.filter(payment => payment.method !== PaymentMethodType.TERMINAL)
|
||||||
|
.reduce((sum, payment) => sum + payment.amount, 0)
|
||||||
|
|
||||||
|
if (!hasTerminalPayment && terminalInfo) {
|
||||||
|
const terminalAmount =
|
||||||
|
typeof terminalInfo.amount === 'number'
|
||||||
|
? terminalInfo.amount
|
||||||
|
: Math.max(0, Number(totalAmount) - nonTerminalTotal)
|
||||||
|
|
||||||
|
if (terminalAmount > 0) {
|
||||||
|
payments.push({
|
||||||
|
method: PaymentMethodType.TERMINAL,
|
||||||
|
amount: terminalAmount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.validatePayments(payments, totalAmount, terminalInfo)
|
||||||
|
|
||||||
|
return {
|
||||||
|
payments,
|
||||||
|
terminalInfo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validatePayments(
|
||||||
|
payments: NormalizedPayment[],
|
||||||
|
totalAmount: number,
|
||||||
|
terminalInfo?: TerminalPaymentInfo,
|
||||||
|
) {
|
||||||
|
const totalPayments = payments.reduce((sum, payment) => sum + payment.amount, 0)
|
||||||
|
const roundedTotalPayments = Number(totalPayments.toFixed(2))
|
||||||
|
const roundedTotalAmount = Number(Number(totalAmount).toFixed(2))
|
||||||
|
|
||||||
|
if (roundedTotalPayments !== roundedTotalAmount) {
|
||||||
|
throw new BadRequestException('مبلغ پرداختی باید برابر با مبلغ کل فاکتور باشد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const terminalPayments = payments.filter(
|
||||||
|
payment => payment.method === PaymentMethodType.TERMINAL,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (terminalPayments.length > 0 && !terminalInfo) {
|
||||||
|
throw new BadRequestException('برای پرداخت ترمینال اطلاعات ترمینال الزامی است.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async resolveCustomerId(
|
||||||
|
tx: Prisma.TransactionClient,
|
||||||
|
data: SharedCreateSalesInvoiceDto,
|
||||||
|
businessId: string,
|
||||||
|
) {
|
||||||
|
if (data.customer_id) {
|
||||||
|
return data.customer_id
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.customer_type === CustomerType.INDIVIDUAL &&
|
||||||
|
data.customer?.customer_individual
|
||||||
|
) {
|
||||||
|
const { national_id, mobile_number, ...rest } = data.customer.customer_individual
|
||||||
|
|
||||||
|
const customerIndividual = await tx.customerIndividual.upsert({
|
||||||
|
where: {
|
||||||
|
business_activity_id_national_id: {
|
||||||
|
business_activity_id: businessId,
|
||||||
|
national_id: data.customer.customer_individual.national_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
...data.customer.customer_individual,
|
||||||
|
customer: {
|
||||||
|
create: {
|
||||||
|
type: CustomerType.INDIVIDUAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
business_activity: {
|
||||||
|
connect: {
|
||||||
|
id: businessId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: { ...rest },
|
||||||
|
select: {
|
||||||
|
customer_id: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!customerIndividual) {
|
||||||
|
throw new BadRequestException('متاسفانه مشکلی در اطلاعات مشتری وجود دارد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
return customerIndividual.customer_id
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.customer_type === CustomerType.LEGAL && data.customer?.customer_legal) {
|
||||||
|
const { registration_number, ...rest } = data.customer.customer_legal
|
||||||
|
const customerLegal = await tx.customerLegal.upsert({
|
||||||
|
where: {
|
||||||
|
business_activity_id_economic_code: {
|
||||||
|
business_activity_id: businessId,
|
||||||
|
economic_code: data.customer.customer_legal.economic_code,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
...data.customer.customer_legal,
|
||||||
|
customer: {
|
||||||
|
create: {
|
||||||
|
type: CustomerType.LEGAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
business_activity: {
|
||||||
|
connect: {
|
||||||
|
id: businessId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
...rest,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
customer_id: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!customerLegal) {
|
||||||
|
throw new BadRequestException('متاسفانه مشکلی در اطلاعات مشتری وجود دارد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
return customerLegal.customer_id
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getGoodsById(
|
||||||
|
tx: Prisma.TransactionClient,
|
||||||
|
data: SharedCreateSalesInvoiceDto,
|
||||||
|
) {
|
||||||
|
const itemGoodIds = data.items
|
||||||
|
.map(item => item.good_id)
|
||||||
|
.filter((goodId): goodId is string => Boolean(goodId))
|
||||||
|
|
||||||
|
const goods = itemGoodIds.length
|
||||||
|
? await tx.good.findMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: itemGoodIds,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
sku: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
code: true,
|
||||||
|
VAT: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
local_sku: true,
|
||||||
|
barcode: true,
|
||||||
|
pricing_model: true,
|
||||||
|
measure_unit: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
code: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
base_sale_price: true,
|
||||||
|
image_url: true,
|
||||||
|
category: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: []
|
||||||
|
|
||||||
|
return new Map(goods.map(good => [good.id, good]))
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildSalesInvoiceData(params: {
|
||||||
|
data: SharedCreateSalesInvoiceDto
|
||||||
|
normalizedInvoiceDate: Date
|
||||||
|
invoiceNumber: number
|
||||||
|
consumerAccountId: string
|
||||||
|
businessId: string
|
||||||
|
complexId: string
|
||||||
|
posId: string
|
||||||
|
goodsById: Map<string, any>
|
||||||
|
customerId: string | null
|
||||||
|
type: TspProviderRequestType
|
||||||
|
main_invoice_id?: string
|
||||||
|
ref_invoice_id?: string
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
normalizedInvoiceDate,
|
||||||
|
invoiceNumber,
|
||||||
|
consumerAccountId,
|
||||||
|
posId,
|
||||||
|
goodsById,
|
||||||
|
customerId,
|
||||||
|
businessId,
|
||||||
|
complexId,
|
||||||
|
type,
|
||||||
|
main_invoice_id,
|
||||||
|
ref_invoice_id,
|
||||||
|
} = params
|
||||||
|
const { customer_id, customer_type, customer, payments, ...invoiceData } = data
|
||||||
|
|
||||||
|
if (
|
||||||
|
type !== TspProviderRequestType.ORIGINAL &&
|
||||||
|
!(main_invoice_id || ref_invoice_id)
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('متاسفانه مشکلی در اطلاعات فاکتور وجود دارد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const salesInvoiceData: SalesInvoiceCreateInput = {
|
||||||
|
...invoiceData,
|
||||||
|
invoice_date: normalizedInvoiceDate,
|
||||||
|
invoice_number: invoiceNumber,
|
||||||
|
total_amount: data.total_amount,
|
||||||
|
code: this.generateInvoiceCode(businessId, complexId, posId, invoiceNumber),
|
||||||
|
type,
|
||||||
|
items: {
|
||||||
|
createMany: {
|
||||||
|
data: data.items.map(item => ({
|
||||||
|
good_id: item.good_id!,
|
||||||
|
quantity: item.quantity,
|
||||||
|
unit_price: item.unit_price,
|
||||||
|
total_amount: item.total_amount,
|
||||||
|
measure_unit_text: goodsById.get(item.good_id!)?.measure_unit.name || null,
|
||||||
|
measure_unit_code: goodsById.get(item.good_id!)?.measure_unit.code || null,
|
||||||
|
sku_code: goodsById.get(item.good_id!)?.sku.code || null,
|
||||||
|
sku_vat: goodsById.get(item.good_id!)?.sku.VAT || null,
|
||||||
|
payload: item.payload ? JSON.parse(JSON.stringify(item.payload)) : undefined,
|
||||||
|
good_snapshot: item.good_id
|
||||||
|
? JSON.parse(
|
||||||
|
JSON.stringify({
|
||||||
|
good: goodsById.get(item.good_id) || null,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
unknown_customer: {},
|
||||||
|
consumer_account: {
|
||||||
|
connect: {
|
||||||
|
id: consumerAccountId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pos: {
|
||||||
|
connect: {
|
||||||
|
id: posId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customerId) {
|
||||||
|
salesInvoiceData.customer = {
|
||||||
|
connect: {
|
||||||
|
id: customerId,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type !== TspProviderRequestType.ORIGINAL) {
|
||||||
|
salesInvoiceData.main_id = main_invoice_id
|
||||||
|
salesInvoiceData.reference_invoice = {
|
||||||
|
connect: {
|
||||||
|
id: ref_invoice_id,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return salesInvoiceData
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getNextInvoiceNumber(tx: Prisma.TransactionClient, businessId: string) {
|
||||||
|
const latestInvoice = await tx.salesInvoice.findFirst({
|
||||||
|
where: {
|
||||||
|
pos: {
|
||||||
|
complex: {
|
||||||
|
business_activity_id: businessId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
invoice_number: 'desc',
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
invoice_number: true,
|
||||||
|
pos: {
|
||||||
|
select: {
|
||||||
|
complex: {
|
||||||
|
select: {
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
invoice_number_sequence: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const latestSequence =
|
||||||
|
latestInvoice?.pos?.complex?.business_activity?.invoice_number_sequence.toNumber() ||
|
||||||
|
0
|
||||||
|
|
||||||
|
return Math.max(latestInvoice?.invoice_number || 0, latestSequence) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
private async createPayments(
|
||||||
|
tx: Prisma.TransactionClient,
|
||||||
|
invoiceId: string,
|
||||||
|
payments: NormalizedPayment[],
|
||||||
|
terminalInfo: TerminalPaymentInfo | undefined,
|
||||||
|
paidAt: Date,
|
||||||
|
) {
|
||||||
|
for (const payment of payments) {
|
||||||
|
if (payment.amount <= 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const createdPayment = await tx.salesInvoicePayment.create({
|
||||||
|
data: {
|
||||||
|
invoice_id: invoiceId,
|
||||||
|
amount: payment.amount,
|
||||||
|
payment_method: payment.method,
|
||||||
|
paid_at: paidAt,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (payment.method === PaymentMethodType.TERMINAL && terminalInfo) {
|
||||||
|
await tx.salesInvoicePaymentTerminalInfo.create({
|
||||||
|
data: {
|
||||||
|
payment_id: createdPayment.id,
|
||||||
|
terminal_id: terminalInfo.terminalId,
|
||||||
|
stan: terminalInfo.stan,
|
||||||
|
rrn: terminalInfo.rrn,
|
||||||
|
transaction_date_time: new Date(terminalInfo.transactionDateTime || ''),
|
||||||
|
customer_card_no: terminalInfo.customerCardNO || null,
|
||||||
|
description: terminalInfo.description || null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private generateInvoiceCode(
|
||||||
|
businessId: string,
|
||||||
|
complexId: string,
|
||||||
|
posId: string,
|
||||||
|
invoiceNumber: number,
|
||||||
|
) {
|
||||||
|
return `${businessId.substring(businessId.length - 2, businessId.length)}-${complexId.substring(complexId.length - 2, complexId.length)}-${posId.substring(posId.length - 2, posId.length)}-${invoiceNumber.toString()}`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ export default (consumer: any) => {
|
|||||||
status: translateEnumValue('ConsumerStatus', consumer.status),
|
status: translateEnumValue('ConsumerStatus', consumer.status),
|
||||||
legal: legal ? { ...legal } : null,
|
legal: legal ? { ...legal } : null,
|
||||||
individual: individual
|
individual: individual
|
||||||
? { ...individual, fullname: `${rest?.first_name} ${rest?.last_name}` }
|
? { ...individual, fullname: `${individual?.first_name} ${individual?.last_name}` }
|
||||||
: null,
|
: null,
|
||||||
name: legal ? legal.name : `${individual?.first_name} ${individual?.last_name}`,
|
name: legal ? legal.name : `${individual?.first_name} ${individual?.last_name}`,
|
||||||
business_counts,
|
business_counts,
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { BadRequestException, ConflictException } from '@nestjs/common'
|
||||||
|
import { Prisma } from 'generated/prisma/client'
|
||||||
|
|
||||||
|
type UniqueMessageMap = Record<string, string>
|
||||||
|
|
||||||
|
export class PrismaErrorUtil {
|
||||||
|
static isKnownError(error: unknown): error is Prisma.PrismaClientKnownRequestError {
|
||||||
|
return error instanceof Prisma.PrismaClientKnownRequestError
|
||||||
|
}
|
||||||
|
|
||||||
|
static isCode(error: unknown, code: string): boolean {
|
||||||
|
return this.isKnownError(error) && error.code === code
|
||||||
|
}
|
||||||
|
|
||||||
|
static hasTarget(error: unknown, targetKey: string): boolean {
|
||||||
|
if (!this.isKnownError(error)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const target = error.meta?.target as string[] | string | undefined
|
||||||
|
if (Array.isArray(target)) {
|
||||||
|
return target.includes(targetKey)
|
||||||
|
}
|
||||||
|
if (typeof target === 'string') {
|
||||||
|
return target.includes(targetKey)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
static throwIfKnown(error: unknown, uniqueMap: UniqueMessageMap = {}) {
|
||||||
|
if (!(error instanceof Prisma.PrismaClientKnownRequestError)) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.code === 'P2002') {
|
||||||
|
const target = (error.meta?.target as string[]) || []
|
||||||
|
for (const key of Object.keys(uniqueMap)) {
|
||||||
|
if (target.includes(key)) {
|
||||||
|
throw new BadRequestException(uniqueMap[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ConflictException('رکورد تکراری است.')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.code === 'P2003') {
|
||||||
|
throw new BadRequestException('ارتباط دادهای نامعتبر است.')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.code === 'P2025') {
|
||||||
|
throw new BadRequestException('رکورد مورد نظر یافت نشد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { randomBytes } from 'crypto'
|
import { randomBytes } from 'crypto'
|
||||||
|
import { PrismaErrorUtil } from './prisma-error.util'
|
||||||
|
|
||||||
export function generateTrackingCode(prefix: string, suffixLength: number) {
|
export function generateTrackingCode(prefix: string, suffixLength: number) {
|
||||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
@@ -13,23 +14,8 @@ export function generateTrackingCode(prefix: string, suffixLength: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isTrackingCodeUniqueViolation(error: unknown) {
|
export function isTrackingCodeUniqueViolation(error: unknown) {
|
||||||
const prismaError = error as {
|
if (!PrismaErrorUtil.isCode(error, 'P2002')) {
|
||||||
code?: string
|
|
||||||
meta?: { target?: string[] | string }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prismaError?.code !== 'P2002') {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return PrismaErrorUtil.hasTarget(error, 'tracking_code')
|
||||||
const target = prismaError.meta?.target
|
|
||||||
if (Array.isArray(target)) {
|
|
||||||
return target.includes('tracking_code')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof target === 'string') {
|
|
||||||
return target.includes('tracking_code')
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -650,6 +650,23 @@ export type EnumInvoiceTemplateTypeWithAggregatesFilter<$PrismaModel = never> =
|
|||||||
_max?: Prisma.NestedEnumInvoiceTemplateTypeFilter<$PrismaModel>
|
_max?: Prisma.NestedEnumInvoiceTemplateTypeFilter<$PrismaModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EnumTspProviderRequestTypeFilter<$PrismaModel = never> = {
|
||||||
|
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
||||||
|
in?: $Enums.TspProviderRequestType[]
|
||||||
|
notIn?: $Enums.TspProviderRequestType[]
|
||||||
|
not?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel = never> = {
|
||||||
|
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
||||||
|
in?: $Enums.TspProviderRequestType[]
|
||||||
|
notIn?: $Enums.TspProviderRequestType[]
|
||||||
|
not?: Prisma.NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
||||||
|
_count?: Prisma.NestedIntFilter<$PrismaModel>
|
||||||
|
_min?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
||||||
|
_max?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
||||||
|
}
|
||||||
|
|
||||||
export type JsonFilter<$PrismaModel = never> =
|
export type JsonFilter<$PrismaModel = never> =
|
||||||
| Prisma.PatchUndefined<
|
| Prisma.PatchUndefined<
|
||||||
Prisma.Either<Required<JsonFilterBase<$PrismaModel>>, Exclude<keyof Required<JsonFilterBase<$PrismaModel>>, 'path'>>,
|
Prisma.Either<Required<JsonFilterBase<$PrismaModel>>, Exclude<keyof Required<JsonFilterBase<$PrismaModel>>, 'path'>>,
|
||||||
@@ -708,13 +725,6 @@ export type EnumTspProviderResponseStatusFilter<$PrismaModel = never> = {
|
|||||||
not?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel> | $Enums.TspProviderResponseStatus
|
not?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel> | $Enums.TspProviderResponseStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EnumTspProviderRequestTypeFilter<$PrismaModel = never> = {
|
|
||||||
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
|
||||||
in?: $Enums.TspProviderRequestType[]
|
|
||||||
notIn?: $Enums.TspProviderRequestType[]
|
|
||||||
not?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel = never> = {
|
export type EnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel = never> = {
|
||||||
equals?: $Enums.TspProviderResponseStatus | Prisma.EnumTspProviderResponseStatusFieldRefInput<$PrismaModel>
|
equals?: $Enums.TspProviderResponseStatus | Prisma.EnumTspProviderResponseStatusFieldRefInput<$PrismaModel>
|
||||||
in?: $Enums.TspProviderResponseStatus[]
|
in?: $Enums.TspProviderResponseStatus[]
|
||||||
@@ -725,16 +735,6 @@ export type EnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel = nev
|
|||||||
_max?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel>
|
_max?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel = never> = {
|
|
||||||
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
|
||||||
in?: $Enums.TspProviderRequestType[]
|
|
||||||
notIn?: $Enums.TspProviderRequestType[]
|
|
||||||
not?: Prisma.NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
|
||||||
_count?: Prisma.NestedIntFilter<$PrismaModel>
|
|
||||||
_min?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
|
||||||
_max?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EnumPaymentMethodTypeFilter<$PrismaModel = never> = {
|
export type EnumPaymentMethodTypeFilter<$PrismaModel = never> = {
|
||||||
equals?: $Enums.PaymentMethodType | Prisma.EnumPaymentMethodTypeFieldRefInput<$PrismaModel>
|
equals?: $Enums.PaymentMethodType | Prisma.EnumPaymentMethodTypeFieldRefInput<$PrismaModel>
|
||||||
in?: $Enums.PaymentMethodType[]
|
in?: $Enums.PaymentMethodType[]
|
||||||
@@ -1378,6 +1378,23 @@ export type NestedEnumInvoiceTemplateTypeWithAggregatesFilter<$PrismaModel = nev
|
|||||||
_max?: Prisma.NestedEnumInvoiceTemplateTypeFilter<$PrismaModel>
|
_max?: Prisma.NestedEnumInvoiceTemplateTypeFilter<$PrismaModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type NestedEnumTspProviderRequestTypeFilter<$PrismaModel = never> = {
|
||||||
|
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
||||||
|
in?: $Enums.TspProviderRequestType[]
|
||||||
|
notIn?: $Enums.TspProviderRequestType[]
|
||||||
|
not?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel = never> = {
|
||||||
|
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
||||||
|
in?: $Enums.TspProviderRequestType[]
|
||||||
|
notIn?: $Enums.TspProviderRequestType[]
|
||||||
|
not?: Prisma.NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
||||||
|
_count?: Prisma.NestedIntFilter<$PrismaModel>
|
||||||
|
_min?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
||||||
|
_max?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
||||||
|
}
|
||||||
|
|
||||||
export type NestedJsonFilter<$PrismaModel = never> =
|
export type NestedJsonFilter<$PrismaModel = never> =
|
||||||
| Prisma.PatchUndefined<
|
| Prisma.PatchUndefined<
|
||||||
Prisma.Either<Required<NestedJsonFilterBase<$PrismaModel>>, Exclude<keyof Required<NestedJsonFilterBase<$PrismaModel>>, 'path'>>,
|
Prisma.Either<Required<NestedJsonFilterBase<$PrismaModel>>, Exclude<keyof Required<NestedJsonFilterBase<$PrismaModel>>, 'path'>>,
|
||||||
@@ -1409,13 +1426,6 @@ export type NestedEnumTspProviderResponseStatusFilter<$PrismaModel = never> = {
|
|||||||
not?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel> | $Enums.TspProviderResponseStatus
|
not?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel> | $Enums.TspProviderResponseStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NestedEnumTspProviderRequestTypeFilter<$PrismaModel = never> = {
|
|
||||||
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
|
||||||
in?: $Enums.TspProviderRequestType[]
|
|
||||||
notIn?: $Enums.TspProviderRequestType[]
|
|
||||||
not?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NestedEnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel = never> = {
|
export type NestedEnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel = never> = {
|
||||||
equals?: $Enums.TspProviderResponseStatus | Prisma.EnumTspProviderResponseStatusFieldRefInput<$PrismaModel>
|
equals?: $Enums.TspProviderResponseStatus | Prisma.EnumTspProviderResponseStatusFieldRefInput<$PrismaModel>
|
||||||
in?: $Enums.TspProviderResponseStatus[]
|
in?: $Enums.TspProviderResponseStatus[]
|
||||||
@@ -1426,16 +1436,6 @@ export type NestedEnumTspProviderResponseStatusWithAggregatesFilter<$PrismaModel
|
|||||||
_max?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel>
|
_max?: Prisma.NestedEnumTspProviderResponseStatusFilter<$PrismaModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel = never> = {
|
|
||||||
equals?: $Enums.TspProviderRequestType | Prisma.EnumTspProviderRequestTypeFieldRefInput<$PrismaModel>
|
|
||||||
in?: $Enums.TspProviderRequestType[]
|
|
||||||
notIn?: $Enums.TspProviderRequestType[]
|
|
||||||
not?: Prisma.NestedEnumTspProviderRequestTypeWithAggregatesFilter<$PrismaModel> | $Enums.TspProviderRequestType
|
|
||||||
_count?: Prisma.NestedIntFilter<$PrismaModel>
|
|
||||||
_min?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
|
||||||
_max?: Prisma.NestedEnumTspProviderRequestTypeFilter<$PrismaModel>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NestedEnumPaymentMethodTypeFilter<$PrismaModel = never> = {
|
export type NestedEnumPaymentMethodTypeFilter<$PrismaModel = never> = {
|
||||||
equals?: $Enums.PaymentMethodType | Prisma.EnumPaymentMethodTypeFieldRefInput<$PrismaModel>
|
equals?: $Enums.PaymentMethodType | Prisma.EnumPaymentMethodTypeFieldRefInput<$PrismaModel>
|
||||||
in?: $Enums.PaymentMethodType[]
|
in?: $Enums.PaymentMethodType[]
|
||||||
|
|||||||
@@ -261,16 +261,15 @@ export const TspProviderResponseStatus = {
|
|||||||
SUCCESS: 'SUCCESS',
|
SUCCESS: 'SUCCESS',
|
||||||
FAILURE: 'FAILURE',
|
FAILURE: 'FAILURE',
|
||||||
NOT_SEND: 'NOT_SEND',
|
NOT_SEND: 'NOT_SEND',
|
||||||
QUEUED: 'QUEUED',
|
QUEUED: 'QUEUED'
|
||||||
REVOKED: 'REVOKED'
|
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type TspProviderResponseStatus = (typeof TspProviderResponseStatus)[keyof typeof TspProviderResponseStatus]
|
export type TspProviderResponseStatus = (typeof TspProviderResponseStatus)[keyof typeof TspProviderResponseStatus]
|
||||||
|
|
||||||
|
|
||||||
export const TspProviderRequestType = {
|
export const TspProviderRequestType = {
|
||||||
MAIN: 'MAIN',
|
ORIGINAL: 'ORIGINAL',
|
||||||
UPDATE: 'UPDATE',
|
CORRECTION: 'CORRECTION',
|
||||||
REVOKE: 'REVOKE',
|
REVOKE: 'REVOKE',
|
||||||
RETURN: 'RETURN'
|
RETURN: 'RETURN'
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -4031,10 +4031,14 @@ export const SalesInvoiceScalarFieldEnum = {
|
|||||||
total_amount: 'total_amount',
|
total_amount: 'total_amount',
|
||||||
invoice_number: 'invoice_number',
|
invoice_number: 'invoice_number',
|
||||||
invoice_date: 'invoice_date',
|
invoice_date: 'invoice_date',
|
||||||
|
type: 'type',
|
||||||
|
tax_id: 'tax_id',
|
||||||
notes: 'notes',
|
notes: 'notes',
|
||||||
unknown_customer: 'unknown_customer',
|
unknown_customer: 'unknown_customer',
|
||||||
created_at: 'created_at',
|
created_at: 'created_at',
|
||||||
updated_at: 'updated_at',
|
updated_at: 'updated_at',
|
||||||
|
main_id: 'main_id',
|
||||||
|
ref_id: 'ref_id',
|
||||||
customer_id: 'customer_id',
|
customer_id: 'customer_id',
|
||||||
consumer_account_id: 'consumer_account_id',
|
consumer_account_id: 'consumer_account_id',
|
||||||
pos_id: 'pos_id'
|
pos_id: 'pos_id'
|
||||||
@@ -4069,11 +4073,9 @@ export const SaleInvoiceTspAttemptsScalarFieldEnum = {
|
|||||||
id: 'id',
|
id: 'id',
|
||||||
attempt_no: 'attempt_no',
|
attempt_no: 'attempt_no',
|
||||||
status: 'status',
|
status: 'status',
|
||||||
tax_id: 'tax_id',
|
|
||||||
type: 'type',
|
|
||||||
request_payload: 'request_payload',
|
request_payload: 'request_payload',
|
||||||
response_payload: 'response_payload',
|
response_payload: 'response_payload',
|
||||||
error_message: 'error_message',
|
message: 'message',
|
||||||
sent_at: 'sent_at',
|
sent_at: 'sent_at',
|
||||||
received_at: 'received_at',
|
received_at: 'received_at',
|
||||||
created_at: 'created_at',
|
created_at: 'created_at',
|
||||||
@@ -4586,7 +4588,10 @@ export type GuildOrderByRelevanceFieldEnum = (typeof GuildOrderByRelevanceFieldE
|
|||||||
export const SalesInvoiceOrderByRelevanceFieldEnum = {
|
export const SalesInvoiceOrderByRelevanceFieldEnum = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
code: 'code',
|
code: 'code',
|
||||||
|
tax_id: 'tax_id',
|
||||||
notes: 'notes',
|
notes: 'notes',
|
||||||
|
main_id: 'main_id',
|
||||||
|
ref_id: 'ref_id',
|
||||||
customer_id: 'customer_id',
|
customer_id: 'customer_id',
|
||||||
consumer_account_id: 'consumer_account_id',
|
consumer_account_id: 'consumer_account_id',
|
||||||
pos_id: 'pos_id'
|
pos_id: 'pos_id'
|
||||||
@@ -4611,8 +4616,7 @@ export type SalesInvoiceItemOrderByRelevanceFieldEnum = (typeof SalesInvoiceItem
|
|||||||
|
|
||||||
export const SaleInvoiceTspAttemptsOrderByRelevanceFieldEnum = {
|
export const SaleInvoiceTspAttemptsOrderByRelevanceFieldEnum = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
tax_id: 'tax_id',
|
message: 'message',
|
||||||
error_message: 'error_message',
|
|
||||||
invoice_id: 'invoice_id'
|
invoice_id: 'invoice_id'
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
@@ -4870,16 +4874,16 @@ export type EnumInvoiceTemplateTypeFieldRefInput<$PrismaModel> = FieldRefInputTy
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to a field of type 'TspProviderResponseStatus'
|
* Reference to a field of type 'TspProviderRequestType'
|
||||||
*/
|
*/
|
||||||
export type EnumTspProviderResponseStatusFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'TspProviderResponseStatus'>
|
export type EnumTspProviderRequestTypeFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'TspProviderRequestType'>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to a field of type 'TspProviderRequestType'
|
* Reference to a field of type 'TspProviderResponseStatus'
|
||||||
*/
|
*/
|
||||||
export type EnumTspProviderRequestTypeFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'TspProviderRequestType'>
|
export type EnumTspProviderResponseStatusFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'TspProviderResponseStatus'>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -622,10 +622,14 @@ export const SalesInvoiceScalarFieldEnum = {
|
|||||||
total_amount: 'total_amount',
|
total_amount: 'total_amount',
|
||||||
invoice_number: 'invoice_number',
|
invoice_number: 'invoice_number',
|
||||||
invoice_date: 'invoice_date',
|
invoice_date: 'invoice_date',
|
||||||
|
type: 'type',
|
||||||
|
tax_id: 'tax_id',
|
||||||
notes: 'notes',
|
notes: 'notes',
|
||||||
unknown_customer: 'unknown_customer',
|
unknown_customer: 'unknown_customer',
|
||||||
created_at: 'created_at',
|
created_at: 'created_at',
|
||||||
updated_at: 'updated_at',
|
updated_at: 'updated_at',
|
||||||
|
main_id: 'main_id',
|
||||||
|
ref_id: 'ref_id',
|
||||||
customer_id: 'customer_id',
|
customer_id: 'customer_id',
|
||||||
consumer_account_id: 'consumer_account_id',
|
consumer_account_id: 'consumer_account_id',
|
||||||
pos_id: 'pos_id'
|
pos_id: 'pos_id'
|
||||||
@@ -660,11 +664,9 @@ export const SaleInvoiceTspAttemptsScalarFieldEnum = {
|
|||||||
id: 'id',
|
id: 'id',
|
||||||
attempt_no: 'attempt_no',
|
attempt_no: 'attempt_no',
|
||||||
status: 'status',
|
status: 'status',
|
||||||
tax_id: 'tax_id',
|
|
||||||
type: 'type',
|
|
||||||
request_payload: 'request_payload',
|
request_payload: 'request_payload',
|
||||||
response_payload: 'response_payload',
|
response_payload: 'response_payload',
|
||||||
error_message: 'error_message',
|
message: 'message',
|
||||||
sent_at: 'sent_at',
|
sent_at: 'sent_at',
|
||||||
received_at: 'received_at',
|
received_at: 'received_at',
|
||||||
created_at: 'created_at',
|
created_at: 'created_at',
|
||||||
@@ -1177,7 +1179,10 @@ export type GuildOrderByRelevanceFieldEnum = (typeof GuildOrderByRelevanceFieldE
|
|||||||
export const SalesInvoiceOrderByRelevanceFieldEnum = {
|
export const SalesInvoiceOrderByRelevanceFieldEnum = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
code: 'code',
|
code: 'code',
|
||||||
|
tax_id: 'tax_id',
|
||||||
notes: 'notes',
|
notes: 'notes',
|
||||||
|
main_id: 'main_id',
|
||||||
|
ref_id: 'ref_id',
|
||||||
customer_id: 'customer_id',
|
customer_id: 'customer_id',
|
||||||
consumer_account_id: 'consumer_account_id',
|
consumer_account_id: 'consumer_account_id',
|
||||||
pos_id: 'pos_id'
|
pos_id: 'pos_id'
|
||||||
@@ -1202,8 +1207,7 @@ export type SalesInvoiceItemOrderByRelevanceFieldEnum = (typeof SalesInvoiceItem
|
|||||||
|
|
||||||
export const SaleInvoiceTspAttemptsOrderByRelevanceFieldEnum = {
|
export const SaleInvoiceTspAttemptsOrderByRelevanceFieldEnum = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
tax_id: 'tax_id',
|
message: 'message',
|
||||||
error_message: 'error_message',
|
|
||||||
invoice_id: 'invoice_id'
|
invoice_id: 'invoice_id'
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ export type SaleInvoiceTspAttemptsMinAggregateOutputType = {
|
|||||||
id: string | null
|
id: string | null
|
||||||
attempt_no: number | null
|
attempt_no: number | null
|
||||||
status: $Enums.TspProviderResponseStatus | null
|
status: $Enums.TspProviderResponseStatus | null
|
||||||
tax_id: string | null
|
message: string | null
|
||||||
type: $Enums.TspProviderRequestType | null
|
|
||||||
error_message: string | null
|
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
created_at: Date | null
|
created_at: Date | null
|
||||||
@@ -51,9 +49,7 @@ export type SaleInvoiceTspAttemptsMaxAggregateOutputType = {
|
|||||||
id: string | null
|
id: string | null
|
||||||
attempt_no: number | null
|
attempt_no: number | null
|
||||||
status: $Enums.TspProviderResponseStatus | null
|
status: $Enums.TspProviderResponseStatus | null
|
||||||
tax_id: string | null
|
message: string | null
|
||||||
type: $Enums.TspProviderRequestType | null
|
|
||||||
error_message: string | null
|
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
created_at: Date | null
|
created_at: Date | null
|
||||||
@@ -64,11 +60,9 @@ export type SaleInvoiceTspAttemptsCountAggregateOutputType = {
|
|||||||
id: number
|
id: number
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: number
|
status: number
|
||||||
tax_id: number
|
|
||||||
type: number
|
|
||||||
request_payload: number
|
request_payload: number
|
||||||
response_payload: number
|
response_payload: number
|
||||||
error_message: number
|
message: number
|
||||||
sent_at: number
|
sent_at: number
|
||||||
received_at: number
|
received_at: number
|
||||||
created_at: number
|
created_at: number
|
||||||
@@ -89,9 +83,7 @@ export type SaleInvoiceTspAttemptsMinAggregateInputType = {
|
|||||||
id?: true
|
id?: true
|
||||||
attempt_no?: true
|
attempt_no?: true
|
||||||
status?: true
|
status?: true
|
||||||
tax_id?: true
|
message?: true
|
||||||
type?: true
|
|
||||||
error_message?: true
|
|
||||||
sent_at?: true
|
sent_at?: true
|
||||||
received_at?: true
|
received_at?: true
|
||||||
created_at?: true
|
created_at?: true
|
||||||
@@ -102,9 +94,7 @@ export type SaleInvoiceTspAttemptsMaxAggregateInputType = {
|
|||||||
id?: true
|
id?: true
|
||||||
attempt_no?: true
|
attempt_no?: true
|
||||||
status?: true
|
status?: true
|
||||||
tax_id?: true
|
message?: true
|
||||||
type?: true
|
|
||||||
error_message?: true
|
|
||||||
sent_at?: true
|
sent_at?: true
|
||||||
received_at?: true
|
received_at?: true
|
||||||
created_at?: true
|
created_at?: true
|
||||||
@@ -115,11 +105,9 @@ export type SaleInvoiceTspAttemptsCountAggregateInputType = {
|
|||||||
id?: true
|
id?: true
|
||||||
attempt_no?: true
|
attempt_no?: true
|
||||||
status?: true
|
status?: true
|
||||||
tax_id?: true
|
|
||||||
type?: true
|
|
||||||
request_payload?: true
|
request_payload?: true
|
||||||
response_payload?: true
|
response_payload?: true
|
||||||
error_message?: true
|
message?: true
|
||||||
sent_at?: true
|
sent_at?: true
|
||||||
received_at?: true
|
received_at?: true
|
||||||
created_at?: true
|
created_at?: true
|
||||||
@@ -217,11 +205,9 @@ export type SaleInvoiceTspAttemptsGroupByOutputType = {
|
|||||||
id: string
|
id: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload: runtime.JsonValue | null
|
request_payload: runtime.JsonValue | null
|
||||||
response_payload: runtime.JsonValue | null
|
response_payload: runtime.JsonValue | null
|
||||||
error_message: string | null
|
message: string
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
created_at: Date
|
created_at: Date
|
||||||
@@ -255,11 +241,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
|
||||||
tax_id?: Prisma.StringNullableFilter<"SaleInvoiceTspAttempts"> | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
error_message?: Prisma.StringNullableFilter<"SaleInvoiceTspAttempts"> | string | null
|
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
|
||||||
@@ -271,11 +255,9 @@ export type SaleInvoiceTspAttemptsOrderByWithRelationInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
tax_id?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
||||||
type?: Prisma.SortOrder
|
|
||||||
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
error_message?: Prisma.SortOrderInput | 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
|
||||||
created_at?: Prisma.SortOrder
|
created_at?: Prisma.SortOrder
|
||||||
@@ -286,7 +268,6 @@ export type SaleInvoiceTspAttemptsOrderByWithRelationInput = {
|
|||||||
|
|
||||||
export type SaleInvoiceTspAttemptsWhereUniqueInput = Prisma.AtLeast<{
|
export type SaleInvoiceTspAttemptsWhereUniqueInput = Prisma.AtLeast<{
|
||||||
id?: string
|
id?: string
|
||||||
tax_id?: string
|
|
||||||
invoice_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[]
|
||||||
@@ -294,25 +275,22 @@ export type SaleInvoiceTspAttemptsWhereUniqueInput = Prisma.AtLeast<{
|
|||||||
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
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
error_message?: Prisma.StringNullableFilter<"SaleInvoiceTspAttempts"> | string | null
|
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?: Prisma.XOR<Prisma.SalesInvoiceScalarRelationFilter, Prisma.SalesInvoiceWhereInput>
|
invoice?: Prisma.XOR<Prisma.SalesInvoiceScalarRelationFilter, Prisma.SalesInvoiceWhereInput>
|
||||||
}, "id" | "tax_id" | "invoice_id" | "invoice_id_attempt_no">
|
}, "id" | "invoice_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
|
||||||
tax_id?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
||||||
type?: Prisma.SortOrder
|
|
||||||
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
request_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
response_payload?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||||
error_message?: Prisma.SortOrderInput | 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
|
||||||
created_at?: Prisma.SortOrder
|
created_at?: Prisma.SortOrder
|
||||||
@@ -331,11 +309,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
|
||||||
tax_id?: Prisma.StringNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeWithAggregatesFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
request_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
response_payload?: Prisma.JsonNullableWithAggregatesFilter<"SaleInvoiceTspAttempts">
|
||||||
error_message?: Prisma.StringNullableWithAggregatesFilter<"SaleInvoiceTspAttempts"> | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string
|
created_at?: Prisma.DateTimeWithAggregatesFilter<"SaleInvoiceTspAttempts"> | Date | string
|
||||||
@@ -346,11 +322,9 @@ export type SaleInvoiceTspAttemptsCreateInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -361,11 +335,9 @@ export type SaleInvoiceTspAttemptsUncheckedCreateInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -376,11 +348,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -391,11 +361,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -406,11 +374,9 @@ export type SaleInvoiceTspAttemptsCreateManyInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -421,11 +387,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -435,11 +399,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -471,11 +433,9 @@ export type SaleInvoiceTspAttemptsCountOrderByAggregateInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
tax_id?: Prisma.SortOrder
|
|
||||||
type?: Prisma.SortOrder
|
|
||||||
request_payload?: Prisma.SortOrder
|
request_payload?: Prisma.SortOrder
|
||||||
response_payload?: Prisma.SortOrder
|
response_payload?: Prisma.SortOrder
|
||||||
error_message?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
sent_at?: Prisma.SortOrder
|
sent_at?: Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrder
|
received_at?: Prisma.SortOrder
|
||||||
created_at?: Prisma.SortOrder
|
created_at?: Prisma.SortOrder
|
||||||
@@ -490,9 +450,7 @@ export type SaleInvoiceTspAttemptsMaxOrderByAggregateInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
tax_id?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
type?: Prisma.SortOrder
|
|
||||||
error_message?: Prisma.SortOrder
|
|
||||||
sent_at?: Prisma.SortOrder
|
sent_at?: Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrder
|
received_at?: Prisma.SortOrder
|
||||||
created_at?: Prisma.SortOrder
|
created_at?: Prisma.SortOrder
|
||||||
@@ -503,9 +461,7 @@ export type SaleInvoiceTspAttemptsMinOrderByAggregateInput = {
|
|||||||
id?: Prisma.SortOrder
|
id?: Prisma.SortOrder
|
||||||
attempt_no?: Prisma.SortOrder
|
attempt_no?: Prisma.SortOrder
|
||||||
status?: Prisma.SortOrder
|
status?: Prisma.SortOrder
|
||||||
tax_id?: Prisma.SortOrder
|
message?: Prisma.SortOrder
|
||||||
type?: Prisma.SortOrder
|
|
||||||
error_message?: Prisma.SortOrder
|
|
||||||
sent_at?: Prisma.SortOrder
|
sent_at?: Prisma.SortOrder
|
||||||
received_at?: Prisma.SortOrder
|
received_at?: Prisma.SortOrder
|
||||||
created_at?: Prisma.SortOrder
|
created_at?: Prisma.SortOrder
|
||||||
@@ -562,19 +518,13 @@ export type EnumTspProviderResponseStatusFieldUpdateOperationsInput = {
|
|||||||
set?: $Enums.TspProviderResponseStatus
|
set?: $Enums.TspProviderResponseStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EnumTspProviderRequestTypeFieldUpdateOperationsInput = {
|
|
||||||
set?: $Enums.TspProviderRequestType
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SaleInvoiceTspAttemptsCreateWithoutInvoiceInput = {
|
export type SaleInvoiceTspAttemptsCreateWithoutInvoiceInput = {
|
||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -584,11 +534,9 @@ export type SaleInvoiceTspAttemptsUncheckedCreateWithoutInvoiceInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -627,11 +575,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
|
||||||
tax_id?: Prisma.StringNullableFilter<"SaleInvoiceTspAttempts"> | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFilter<"SaleInvoiceTspAttempts"> | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
request_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
response_payload?: Prisma.JsonNullableFilter<"SaleInvoiceTspAttempts">
|
||||||
error_message?: Prisma.StringNullableFilter<"SaleInvoiceTspAttempts"> | string | null
|
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
|
||||||
@@ -642,11 +588,9 @@ export type SaleInvoiceTspAttemptsCreateManyInvoiceInput = {
|
|||||||
id?: string
|
id?: string
|
||||||
attempt_no: number
|
attempt_no: number
|
||||||
status: $Enums.TspProviderResponseStatus
|
status: $Enums.TspProviderResponseStatus
|
||||||
tax_id?: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: string | null
|
message: string
|
||||||
sent_at?: Date | string | null
|
sent_at?: Date | string | null
|
||||||
received_at?: Date | string | null
|
received_at?: Date | string | null
|
||||||
created_at?: Date | string
|
created_at?: Date | string
|
||||||
@@ -656,11 +600,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -670,11 +612,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -684,11 +624,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
|
||||||
tax_id?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
||||||
type?: Prisma.EnumTspProviderRequestTypeFieldUpdateOperationsInput | $Enums.TspProviderRequestType
|
|
||||||
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
request_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
response_payload?: Prisma.NullableJsonNullValueInput | runtime.InputJsonValue
|
||||||
error_message?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
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
|
||||||
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
created_at?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||||
@@ -700,11 +638,9 @@ export type SaleInvoiceTspAttemptsSelect<ExtArgs extends runtime.Types.Extension
|
|||||||
id?: boolean
|
id?: boolean
|
||||||
attempt_no?: boolean
|
attempt_no?: boolean
|
||||||
status?: boolean
|
status?: boolean
|
||||||
tax_id?: boolean
|
|
||||||
type?: boolean
|
|
||||||
request_payload?: boolean
|
request_payload?: boolean
|
||||||
response_payload?: boolean
|
response_payload?: boolean
|
||||||
error_message?: boolean
|
message?: boolean
|
||||||
sent_at?: boolean
|
sent_at?: boolean
|
||||||
received_at?: boolean
|
received_at?: boolean
|
||||||
created_at?: boolean
|
created_at?: boolean
|
||||||
@@ -718,18 +654,16 @@ export type SaleInvoiceTspAttemptsSelectScalar = {
|
|||||||
id?: boolean
|
id?: boolean
|
||||||
attempt_no?: boolean
|
attempt_no?: boolean
|
||||||
status?: boolean
|
status?: boolean
|
||||||
tax_id?: boolean
|
|
||||||
type?: boolean
|
|
||||||
request_payload?: boolean
|
request_payload?: boolean
|
||||||
response_payload?: boolean
|
response_payload?: boolean
|
||||||
error_message?: boolean
|
message?: boolean
|
||||||
sent_at?: boolean
|
sent_at?: boolean
|
||||||
received_at?: boolean
|
received_at?: boolean
|
||||||
created_at?: boolean
|
created_at?: boolean
|
||||||
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" | "tax_id" | "type" | "request_payload" | "response_payload" | "error_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" | "request_payload" | "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>
|
||||||
}
|
}
|
||||||
@@ -743,11 +677,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
|
||||||
tax_id: string | null
|
|
||||||
type: $Enums.TspProviderRequestType
|
|
||||||
request_payload: runtime.JsonValue | null
|
request_payload: runtime.JsonValue | null
|
||||||
response_payload: runtime.JsonValue | null
|
response_payload: runtime.JsonValue | null
|
||||||
error_message: string | null
|
message: string
|
||||||
sent_at: Date | null
|
sent_at: Date | null
|
||||||
received_at: Date | null
|
received_at: Date | null
|
||||||
created_at: Date
|
created_at: Date
|
||||||
@@ -1125,11 +1057,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 tax_id: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'String'>
|
|
||||||
readonly type: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'TspProviderRequestType'>
|
|
||||||
readonly request_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
readonly request_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
||||||
readonly response_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
readonly response_payload: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'Json'>
|
||||||
readonly error_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'>
|
||||||
readonly created_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
readonly created_at: Prisma.FieldRef<"SaleInvoiceTspAttempts", 'DateTime'>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -181,7 +181,7 @@ export class SaleInvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async send(consumer_id: string, invoice_id: string) {
|
async send(consumer_id: string, invoice_id: string) {
|
||||||
const tspProviderResult = await this.salesInvoiceTaxService.send(
|
const tspProviderResult = await this.salesInvoiceTaxService.originalSend(
|
||||||
consumer_id,
|
consumer_id,
|
||||||
invoice_id,
|
invoice_id,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,22 +9,28 @@ import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
|||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
async findAll(partner_id: string) {
|
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||||
const accounts = await this.prisma.partnerAccount.findMany({
|
const where = { partner_id }
|
||||||
where: { partner_id },
|
const [accounts, total] = await this.prisma.$transaction(async tx => [
|
||||||
select: {
|
await tx.partnerAccount.findMany({
|
||||||
id: true,
|
where,
|
||||||
role: true,
|
select: {
|
||||||
created_at: true,
|
id: true,
|
||||||
account: {
|
role: true,
|
||||||
select: {
|
created_at: true,
|
||||||
username: true,
|
account: {
|
||||||
status: true,
|
select: {
|
||||||
|
username: true,
|
||||||
|
status: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
skip: (page - 1) * perPage,
|
||||||
})
|
take: perPage,
|
||||||
return ResponseMapper.list(accounts)
|
}),
|
||||||
|
await tx.partnerAccount.count({ where }),
|
||||||
|
])
|
||||||
|
return ResponseMapper.paginate(accounts, { total, page, perPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
|
|||||||
@@ -58,11 +58,17 @@ export class AccountsService {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
async findAll(partner_id: string, consumer_id: string) {
|
async findAll(partner_id: string, consumer_id: string, page = 1, perPage = 10) {
|
||||||
const accounts = await this.prisma.consumerAccount.findMany({
|
const where = this.defaultWhere(partner_id, consumer_id)
|
||||||
where: this.defaultWhere(partner_id, consumer_id),
|
const [accounts, total] = await this.prisma.$transaction(async tx => [
|
||||||
select: this.default_select,
|
await tx.consumerAccount.findMany({
|
||||||
})
|
where,
|
||||||
|
select: this.default_select,
|
||||||
|
skip: (page - 1) * perPage,
|
||||||
|
take: perPage,
|
||||||
|
}),
|
||||||
|
await tx.consumerAccount.count({ where }),
|
||||||
|
])
|
||||||
|
|
||||||
const mappedAccounts = accounts.map(account => {
|
const mappedAccounts = accounts.map(account => {
|
||||||
const { account: mainAccount, role, ...rest } = account
|
const { account: mainAccount, role, ...rest } = account
|
||||||
@@ -77,7 +83,7 @@ export class AccountsService {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return ResponseMapper.list(mappedAccounts)
|
return ResponseMapper.paginate(mappedAccounts, { total, page, perPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(partner_id: string, consumer_id: string, id: string) {
|
async findOne(partner_id: string, consumer_id: string, id: string) {
|
||||||
|
|||||||
+8
-3
@@ -1,5 +1,5 @@
|
|||||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||||
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { BusinessActivitiesService } from './business-activities.service'
|
import { BusinessActivitiesService } from './business-activities.service'
|
||||||
import {
|
import {
|
||||||
@@ -38,7 +38,7 @@ export class BusinessActivitiesController {
|
|||||||
return this.businessActivitiesService.create(partnerId, consumerId, data)
|
return this.businessActivitiesService.create(partnerId, consumerId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Patch(':id')
|
||||||
async update(
|
async update(
|
||||||
@PartnerInfo('id') partnerId: string,
|
@PartnerInfo('id') partnerId: string,
|
||||||
@Param('consumerId') consumerId: string,
|
@Param('consumerId') consumerId: string,
|
||||||
@@ -54,4 +54,9 @@ export class BusinessActivitiesController {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
import type { BusinessActivitiesServiceCreateResponseDto, BusinessActivitiesServiceFindAllResponseDto, BusinessActivitiesServiceFindOneResponseDto, BusinessActivitiesServiceUpdateResponseDto } from './dto/business-activities-response.dto'
|
import type {
|
||||||
|
BusinessActivitiesServiceCreateResponseDto,
|
||||||
|
BusinessActivitiesServiceFindAllResponseDto,
|
||||||
|
BusinessActivitiesServiceFindOneResponseDto,
|
||||||
|
BusinessActivitiesServiceUpdateResponseDto,
|
||||||
|
} from './dto/business-activities-response.dto'
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export class BusinessActivitiesService {
|
|||||||
name: true,
|
name: true,
|
||||||
economic_code: true,
|
economic_code: true,
|
||||||
created_at: true,
|
created_at: true,
|
||||||
|
fiscal_id: true,
|
||||||
|
invoice_number_sequence: true,
|
||||||
|
partner_token: true,
|
||||||
guild: {
|
guild: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -81,13 +84,20 @@ export class BusinessActivitiesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(partner_id: string, consumer_id: string) {
|
async findAll(partner_id: string, consumer_id: string, page = 1, perPage = 10) {
|
||||||
const businessActivities = await this.prisma.businessActivity.findMany({
|
const where = this.defaultWhere(partner_id, consumer_id)
|
||||||
where: this.defaultWhere(partner_id, consumer_id),
|
const [businessActivities, total] = await this.prisma.$transaction(async tx => [
|
||||||
select: this.defaultSelect,
|
await tx.businessActivity.findMany({
|
||||||
})
|
where,
|
||||||
return ResponseMapper.list(
|
select: this.defaultSelect,
|
||||||
|
skip: (page - 1) * perPage,
|
||||||
|
take: perPage,
|
||||||
|
}),
|
||||||
|
await tx.businessActivity.count({ where }),
|
||||||
|
])
|
||||||
|
return ResponseMapper.paginate(
|
||||||
businessActivities.map(this.prepareBusinessActivityResponse),
|
businessActivities.map(this.prepareBusinessActivityResponse),
|
||||||
|
{ total, page, perPage },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,18 +42,30 @@ export class BusinessActivityComplexesService {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
async findAll(partner_id: string, consumer_id: string, business_activity_id: string) {
|
async findAll(
|
||||||
const complexes = await this.prisma.complex.findMany({
|
partner_id: string,
|
||||||
where: this.defaultWhere(partner_id, consumer_id, business_activity_id),
|
consumer_id: string,
|
||||||
select: {
|
business_activity_id: string,
|
||||||
...this.defaultSelect,
|
page = 1,
|
||||||
_count: {
|
perPage = 10,
|
||||||
select: {
|
) {
|
||||||
pos_list: true,
|
const where = this.defaultWhere(partner_id, consumer_id, business_activity_id)
|
||||||
|
const [complexes, total] = await this.prisma.$transaction(async tx => [
|
||||||
|
await tx.complex.findMany({
|
||||||
|
where,
|
||||||
|
select: {
|
||||||
|
...this.defaultSelect,
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
pos_list: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
skip: (page - 1) * perPage,
|
||||||
})
|
take: perPage,
|
||||||
|
}),
|
||||||
|
await tx.complex.count({ where }),
|
||||||
|
])
|
||||||
|
|
||||||
const mappedComplexes = complexes.map(complex => {
|
const mappedComplexes = complexes.map(complex => {
|
||||||
const { _count, ...rest } = complex
|
const { _count, ...rest } = complex
|
||||||
@@ -62,7 +74,7 @@ export class BusinessActivityComplexesService {
|
|||||||
pos_count: _count.pos_list,
|
pos_count: _count.pos_list,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return ResponseMapper.list(mappedComplexes)
|
return ResponseMapper.paginate(mappedComplexes, { total, page, perPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(
|
async findOne(
|
||||||
|
|||||||
+114
-90
@@ -1,5 +1,6 @@
|
|||||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
import { consumerRelatedPartner } from '@/common/queryConstants/consumer'
|
import { consumerRelatedPartner } from '@/common/queryConstants/consumer'
|
||||||
|
import { PrismaErrorUtil } from '@/common/utils/prisma-error.util'
|
||||||
import { PasswordUtil } from '@/common/utils/password.util'
|
import { PasswordUtil } from '@/common/utils/password.util'
|
||||||
import {
|
import {
|
||||||
AccountStatus,
|
AccountStatus,
|
||||||
@@ -97,17 +98,32 @@ export class ComplexPosesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(partner_id: string, business_activity_id: string, complex_id: string) {
|
async findAll(
|
||||||
const poses = await this.prisma.pos.findMany({
|
partner_id: string,
|
||||||
where: {
|
business_activity_id: string,
|
||||||
...this.defaultWhere(partner_id, complex_id, business_activity_id),
|
complex_id: string,
|
||||||
},
|
page = 1,
|
||||||
select: this.defaultSelect,
|
perPage = 10,
|
||||||
})
|
) {
|
||||||
|
const [poses, total] = await this.prisma.$transaction(async tx => [
|
||||||
|
await tx.pos.findMany({
|
||||||
|
where: {
|
||||||
|
...this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
skip: (page - 1) * perPage,
|
||||||
|
take: perPage,
|
||||||
|
}),
|
||||||
|
await tx.pos.count({
|
||||||
|
where: {
|
||||||
|
...this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
const mappedPoses = poses.map(this.mapPos)
|
const mappedPoses = poses.map(this.mapPos)
|
||||||
|
|
||||||
return ResponseMapper.list(mappedPoses)
|
return ResponseMapper.paginate(mappedPoses, { total, page, perPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(
|
async findOne(
|
||||||
@@ -129,94 +145,102 @@ export class ComplexPosesService {
|
|||||||
complex_id: string,
|
complex_id: string,
|
||||||
data: CreatePosDto,
|
data: CreatePosDto,
|
||||||
) {
|
) {
|
||||||
const pos = this.prisma.$transaction(async tx => {
|
let pos
|
||||||
const activeAccountAllocation = await tx.licenseAccountAllocation.findFirst({
|
try {
|
||||||
where: {
|
pos = await this.prisma.$transaction(async tx => {
|
||||||
account_id: null,
|
const activeAccountAllocation = await tx.licenseAccountAllocation.findFirst({
|
||||||
license_activation: {
|
where: {
|
||||||
business_activity_id,
|
account_id: null,
|
||||||
...QUERY_CONSTANTS.LICENSE_ACTIVATION.activeOnDate(),
|
license_activation: {
|
||||||
license: {
|
business_activity_id,
|
||||||
charge_transaction: {
|
...QUERY_CONSTANTS.LICENSE_ACTIVATION.activeOnDate(),
|
||||||
partner_id,
|
license: {
|
||||||
},
|
charge_transaction: {
|
||||||
},
|
partner_id,
|
||||||
},
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
license_activation: {
|
|
||||||
select: {
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
consumer_id: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
select: {
|
||||||
|
id: true,
|
||||||
|
license_activation: {
|
||||||
|
select: {
|
||||||
|
business_activity: {
|
||||||
|
select: {
|
||||||
|
consumer_id: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!activeAccountAllocation) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`محدودیت تعریف تعداد کاربران این فعالیت تجاری به پایان رسیده است.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { device_id, provider_id, username, password, ...rest } = data
|
||||||
|
|
||||||
|
return await tx.pos.create({
|
||||||
|
data: {
|
||||||
|
...rest,
|
||||||
|
status: POSStatus.ACTIVE,
|
||||||
|
|
||||||
|
account: {
|
||||||
|
create: {
|
||||||
|
role: ConsumerRole.OPERATOR,
|
||||||
|
|
||||||
|
consumer: {
|
||||||
|
connect: {
|
||||||
|
id: activeAccountAllocation.license_activation!.business_activity
|
||||||
|
.consumer_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
account_allocation: {
|
||||||
|
connect: {
|
||||||
|
id: activeAccountAllocation.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
account: {
|
||||||
|
create: {
|
||||||
|
username,
|
||||||
|
password: await PasswordUtil.hash(password),
|
||||||
|
type: AccountType.CONSUMER,
|
||||||
|
status: AccountStatus.ACTIVE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
complex: {
|
||||||
|
connect: {
|
||||||
|
id: complex_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
device: device_id
|
||||||
|
? {
|
||||||
|
connect: {
|
||||||
|
id: device_id,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
provider: provider_id
|
||||||
|
? {
|
||||||
|
connect: {
|
||||||
|
id: provider_id,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
if (!activeAccountAllocation) {
|
PrismaErrorUtil.throwIfKnown(error, {
|
||||||
throw new BadRequestException(
|
username: 'نام کاربری تکراری است',
|
||||||
`محدودیت تعریف تعداد کاربران این فعالیت تجاری به پایان رسیده است.`,
|
accounts_username_key: 'نام کاربری تکراری است',
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { device_id, provider_id, username, password, ...rest } = data
|
|
||||||
|
|
||||||
return await tx.pos.create({
|
|
||||||
data: {
|
|
||||||
...rest,
|
|
||||||
status: POSStatus.ACTIVE,
|
|
||||||
|
|
||||||
account: {
|
|
||||||
create: {
|
|
||||||
role: ConsumerRole.OPERATOR,
|
|
||||||
|
|
||||||
consumer: {
|
|
||||||
connect: {
|
|
||||||
id: activeAccountAllocation.license_activation!.business_activity
|
|
||||||
.consumer_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
account_allocation: {
|
|
||||||
connect: {
|
|
||||||
id: activeAccountAllocation.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
account: {
|
|
||||||
create: {
|
|
||||||
username,
|
|
||||||
password: await PasswordUtil.hash(password),
|
|
||||||
type: AccountType.CONSUMER,
|
|
||||||
status: AccountStatus.ACTIVE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
complex: {
|
|
||||||
connect: {
|
|
||||||
id: complex_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
device: device_id
|
|
||||||
? {
|
|
||||||
connect: {
|
|
||||||
id: device_id,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
provider: provider_id
|
|
||||||
? {
|
|
||||||
connect: {
|
|
||||||
id: provider_id,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return ResponseMapper.create(pos)
|
return ResponseMapper.create(pos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,42 +16,48 @@ export class LicensesService {
|
|||||||
).toISOString()
|
).toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(partner_id: string, consumer_id: string) {
|
async findAll(partner_id: string, consumer_id: string, page = 1, perPage = 10) {
|
||||||
const licenses = await this.prisma.licenseActivation.findMany({
|
const where = {
|
||||||
where: {
|
business_activity: {
|
||||||
business_activity: {
|
consumer_id,
|
||||||
consumer_id,
|
},
|
||||||
},
|
license: {
|
||||||
license: {
|
charge_transaction: {
|
||||||
charge_transaction: {
|
partner_id,
|
||||||
partner_id,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
}
|
||||||
id: true,
|
const [licenses, total] = await this.prisma.$transaction(async tx => [
|
||||||
starts_at: true,
|
await tx.licenseActivation.findMany({
|
||||||
expires_at: true,
|
where,
|
||||||
created_at: true,
|
select: {
|
||||||
license: {
|
id: true,
|
||||||
select: {
|
starts_at: true,
|
||||||
id: true,
|
expires_at: true,
|
||||||
charge_transaction: {
|
created_at: true,
|
||||||
select: {
|
license: {
|
||||||
partner: {
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
charge_transaction: {
|
||||||
name: true,
|
select: {
|
||||||
|
partner: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
skip: (page - 1) * perPage,
|
||||||
})
|
take: perPage,
|
||||||
|
}),
|
||||||
|
await tx.licenseActivation.count({ where }),
|
||||||
|
])
|
||||||
|
|
||||||
return ResponseMapper.list(licenses)
|
return ResponseMapper.paginate(licenses, { total, page, perPage })
|
||||||
}
|
}
|
||||||
|
|
||||||
// async create(consumerId: string, data: CreateLicenseDto) {
|
// async create(consumerId: string, data: CreateLicenseDto) {
|
||||||
|
|||||||
@@ -66,16 +66,23 @@ export const getPartnerFirstRemainingLicense = async (
|
|||||||
id: true,
|
id: true,
|
||||||
charge_transaction_id: true,
|
charge_transaction_id: true,
|
||||||
accounts_limit: true,
|
accounts_limit: true,
|
||||||
parent: {
|
charge_transaction: {
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
partner: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!license) {
|
if (!license) {
|
||||||
throw new BadRequestException(`لایسنس فعالی برای ${license.parent.name} وجود ندارد.`)
|
throw new BadRequestException(
|
||||||
|
`لایسنس فعالی برای ${license.charge_transaction.parent.name} وجود ندارد.`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return license
|
return license
|
||||||
|
|||||||
@@ -1,163 +1,6 @@
|
|||||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
import { SharedCreateSalesInvoiceDto } from '@/common/services/saleInvoices/sale-invoice-create.dto'
|
||||||
import { Type } from 'class-transformer'
|
import { PartialType } from '@nestjs/swagger'
|
||||||
import {
|
|
||||||
ArrayMinSize,
|
|
||||||
IsBoolean,
|
|
||||||
IsDate,
|
|
||||||
IsDateString,
|
|
||||||
IsEnum,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsNumber,
|
|
||||||
IsObject,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
Min,
|
|
||||||
ValidateNested,
|
|
||||||
} from 'class-validator'
|
|
||||||
import type { CustomerIndividual, CustomerLegal } from 'generated/prisma/client'
|
|
||||||
import { CustomerType } from 'generated/prisma/enums'
|
|
||||||
import { CreateSalesInvoiceItemDto } from '../sales-invoice-items/dto/create-sales-invoice-item.dto'
|
|
||||||
|
|
||||||
export class CreateTerminalPayment {
|
export class CreateSalesInvoiceDto extends SharedCreateSalesInvoiceDto {}
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
amount?: number
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
terminalId: string
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
stan: string
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
rrn: string
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
response_code?: string
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
customer_card_no?: string
|
|
||||||
|
|
||||||
@Type(() => Date)
|
|
||||||
@IsDate()
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
transaction_date_time: Date
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@ApiProperty({ required: false })
|
|
||||||
description?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CreateSalesInvoicePaymentsDto {
|
|
||||||
@IsOptional()
|
|
||||||
@ValidateNested()
|
|
||||||
@Type(() => CreateTerminalPayment)
|
|
||||||
@ApiProperty({ required: false, type: () => CreateTerminalPayment })
|
|
||||||
terminals?: CreateTerminalPayment
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
cash?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
set_off?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
card?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
bank?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
check?: number
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Min(0)
|
|
||||||
@ApiProperty({ required: false, default: 0 })
|
|
||||||
other?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CreateSalesInvoiceDto {
|
|
||||||
// @TODO: totalAmount must calculated instead of get from api
|
|
||||||
@IsNumber()
|
|
||||||
@ApiProperty({ required: true, default: 0 })
|
|
||||||
total_amount: number
|
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
@IsDateString(
|
|
||||||
{ strict: true },
|
|
||||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
|
||||||
)
|
|
||||||
invoice_date: Date
|
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
|
||||||
@IsObject()
|
|
||||||
@ValidateNested()
|
|
||||||
@Type(() => CreateSalesInvoicePaymentsDto)
|
|
||||||
payments: CreateSalesInvoicePaymentsDto
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@ArrayMinSize(1)
|
|
||||||
items: CreateSalesInvoiceItemDto[]
|
|
||||||
|
|
||||||
@ApiProperty({ required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
notes?: string
|
|
||||||
|
|
||||||
@ApiProperty({ required: false, default: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
send_to_tsp?: boolean
|
|
||||||
|
|
||||||
@ApiProperty({ required: true, default: CustomerType.UNKNOWN })
|
|
||||||
@IsEnum(CustomerType)
|
|
||||||
customer_type: CustomerType
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@ApiProperty({ required: false })
|
|
||||||
customer_id?: string
|
|
||||||
|
|
||||||
@ApiProperty({ required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsObject()
|
|
||||||
customer?: {
|
|
||||||
customer_individual?: Omit<CustomerIndividual, 'business_activity_id' | 'customer_id'>
|
|
||||||
customer_legal?: Omit<CustomerLegal, 'business_activity_id' | 'customer_id'>
|
|
||||||
customer_unknown?: {
|
|
||||||
first_name: string
|
|
||||||
last_name: string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UpdateSalesInvoiceDto extends PartialType(CreateSalesInvoiceDto) {}
|
export class UpdateSalesInvoiceDto extends PartialType(CreateSalesInvoiceDto) {}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { SalesInvoicesController } from './sales-invoices.controller'
|
import { SalesInvoicesController } from './sales-invoices.controller'
|
||||||
@@ -6,6 +7,6 @@ import { SalesInvoicesService } from './sales-invoices.service'
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [SaleInvoiceTspModule],
|
imports: [SaleInvoiceTspModule],
|
||||||
controllers: [SalesInvoicesController],
|
controllers: [SalesInvoicesController],
|
||||||
providers: [SalesInvoicesService],
|
providers: [SalesInvoicesService, SharedSaleInvoiceCreateService],
|
||||||
})
|
})
|
||||||
export class PosSalesInvoicesModule {}
|
export class PosSalesInvoicesModule {}
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import { IPosPayload } from '@/common/models/posPayload.model'
|
import { IPosPayload } from '@/common/models/posPayload.model'
|
||||||
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
import { translateEnumValue } from '@/common/utils'
|
import { translateEnumValue } from '@/common/utils'
|
||||||
import { SalesInvoiceCreateInput } from '@/generated/prisma/models'
|
|
||||||
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 { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import type { CustomerIndividual, CustomerLegal } from 'generated/prisma/client'
|
|
||||||
import { Prisma } from 'generated/prisma/client'
|
import { Prisma } from 'generated/prisma/client'
|
||||||
import {
|
import {
|
||||||
ConsumerRole,
|
ConsumerRole,
|
||||||
CustomerType,
|
|
||||||
PaymentMethodType,
|
|
||||||
TspProviderRequestType,
|
TspProviderRequestType,
|
||||||
TspProviderResponseStatus,
|
TspProviderResponseStatus,
|
||||||
} from 'generated/prisma/enums'
|
} from 'generated/prisma/enums'
|
||||||
@@ -17,46 +14,12 @@ import { SalesInvoiceTspService } from '../../tspProviders/sales-invoice-tsp.ser
|
|||||||
import { CreateSalesInvoiceDto } from './dto/create-sales-invoice.dto'
|
import { CreateSalesInvoiceDto } from './dto/create-sales-invoice.dto'
|
||||||
import { SalesInvoicesFilterDto } from './dto/sales-invoices-filter.dto'
|
import { SalesInvoicesFilterDto } from './dto/sales-invoices-filter.dto'
|
||||||
|
|
||||||
// Define type guard for CustomerIndividual
|
|
||||||
function isCustomerIndividual(customer: any): customer is CustomerIndividual {
|
|
||||||
return (
|
|
||||||
customer &&
|
|
||||||
typeof customer.first_name === 'string' &&
|
|
||||||
typeof customer.last_name === 'string'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define type guard for CustomerLegal
|
|
||||||
function isCustomerLegal(customer: any): customer is CustomerLegal {
|
|
||||||
return (
|
|
||||||
customer &&
|
|
||||||
typeof customer.company_name === 'string' &&
|
|
||||||
typeof customer.registration_number === 'string'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TerminalPaymentInfo {
|
|
||||||
terminalId: string
|
|
||||||
stan: string
|
|
||||||
rrn: string
|
|
||||||
transactionDateTime: string | Date
|
|
||||||
customerCardNO?: string
|
|
||||||
description?: string
|
|
||||||
amount?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NormalizedPayment {
|
|
||||||
method: PaymentMethodType
|
|
||||||
amount: number
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesInvoicesService {
|
export class SalesInvoicesService {
|
||||||
private readonly createInvoiceRetries = 3
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private prisma: PrismaService,
|
private prisma: PrismaService,
|
||||||
private salesInvoiceTaxService: SalesInvoiceTspService,
|
private salesInvoiceTaxService: SalesInvoiceTspService,
|
||||||
|
private sharedSaleInvoiceCreateService: SharedSaleInvoiceCreateService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findAll(posInfo: IPosPayload, query: SalesInvoicesFilterDto = {}) {
|
async findAll(posInfo: IPosPayload, query: SalesInvoicesFilterDto = {}) {
|
||||||
@@ -145,6 +108,7 @@ export class SalesInvoicesService {
|
|||||||
notes: true,
|
notes: true,
|
||||||
total_amount: true,
|
total_amount: true,
|
||||||
unknown_customer: true,
|
unknown_customer: true,
|
||||||
|
tax_id: true,
|
||||||
customer: {
|
customer: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -242,8 +206,7 @@ export class SalesInvoicesService {
|
|||||||
id: true,
|
id: true,
|
||||||
attempt_no: true,
|
attempt_no: true,
|
||||||
status: true,
|
status: true,
|
||||||
tax_id: true,
|
message: true,
|
||||||
error_message: true,
|
|
||||||
sent_at: true,
|
sent_at: true,
|
||||||
received_at: true,
|
received_at: true,
|
||||||
created_at: true,
|
created_at: true,
|
||||||
@@ -267,71 +230,27 @@ export class SalesInvoicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateSalesInvoiceDto, posInfo: IPosPayload) {
|
async create(data: CreateSalesInvoiceDto, posInfo: IPosPayload) {
|
||||||
const { business_id, pos_id, consumer_account_id, complex_id } = posInfo
|
const salesInvoice = await this.sharedSaleInvoiceCreateService.create({
|
||||||
const normalizedInvoiceDate = this.normalizeInvoiceDate(data.invoice_date)
|
data,
|
||||||
const { payments, terminalInfo } = this.buildPaymentsData(
|
businessId: posInfo.business_id,
|
||||||
data.payments,
|
complexId: posInfo.complex_id,
|
||||||
data.total_amount,
|
posId: posInfo.pos_id,
|
||||||
)
|
consumerAccountId: posInfo.consumer_account_id,
|
||||||
|
type: TspProviderRequestType.ORIGINAL,
|
||||||
|
})
|
||||||
|
|
||||||
for (let attempt = 1; attempt <= this.createInvoiceRetries; attempt++) {
|
if (data.send_to_tsp) {
|
||||||
try {
|
await this.salesInvoiceTaxService.originalSend(salesInvoice.id, posInfo.pos_id)
|
||||||
const salesInvoice = await this.prisma.$transaction(async $tx => {
|
|
||||||
const invoiceNumber = await this.getNextInvoiceNumber($tx, business_id)
|
|
||||||
const newCustomerId = await this.resolveCustomerId($tx, data, business_id)
|
|
||||||
const goodsById = await this.getGoodsById($tx, data)
|
|
||||||
const salesInvoiceData = this.buildSalesInvoiceData({
|
|
||||||
data,
|
|
||||||
normalizedInvoiceDate,
|
|
||||||
invoiceNumber,
|
|
||||||
consumer_account_id,
|
|
||||||
businessId: business_id,
|
|
||||||
complexId: complex_id,
|
|
||||||
pos_id,
|
|
||||||
goodsById,
|
|
||||||
customerId: newCustomerId,
|
|
||||||
})
|
|
||||||
|
|
||||||
const salesInvoice = await $tx.salesInvoice.create({
|
|
||||||
data: salesInvoiceData,
|
|
||||||
})
|
|
||||||
|
|
||||||
await this.createPayments(
|
|
||||||
$tx,
|
|
||||||
salesInvoice.id,
|
|
||||||
payments,
|
|
||||||
terminalInfo,
|
|
||||||
normalizedInvoiceDate,
|
|
||||||
)
|
|
||||||
|
|
||||||
if (data.send_to_tsp) {
|
|
||||||
await this.salesInvoiceTaxService.send(salesInvoice.id, pos_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
return salesInvoice
|
|
||||||
})
|
|
||||||
|
|
||||||
return ResponseMapper.create(salesInvoice)
|
|
||||||
} catch (error) {
|
|
||||||
if (
|
|
||||||
this.isRetryableInvoiceConflict(error) &&
|
|
||||||
attempt < this.createInvoiceRetries
|
|
||||||
) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new BadRequestException('ایجاد فاکتور با خطا مواجه شد.')
|
return ResponseMapper.create(salesInvoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(invoiceId: string, posInfo: IPosPayload) {
|
async send(invoiceId: string, posInfo: IPosPayload) {
|
||||||
const consumer_id = await this.checkAccessToInvoice(
|
const invoice = await this.salesInvoiceTaxService.originalSend(
|
||||||
posInfo.consumer_account_id,
|
|
||||||
posInfo.pos_id,
|
posInfo.pos_id,
|
||||||
|
invoiceId,
|
||||||
)
|
)
|
||||||
const invoice = await this.salesInvoiceTaxService.send(consumer_id, invoiceId)
|
|
||||||
|
|
||||||
return ResponseMapper.single(invoice)
|
return ResponseMapper.single(invoice)
|
||||||
}
|
}
|
||||||
@@ -339,7 +258,15 @@ export class SalesInvoicesService {
|
|||||||
async revoke(invoiceId: string, posInfo: IPosPayload) {
|
async revoke(invoiceId: string, posInfo: IPosPayload) {
|
||||||
await this.checkAccessToInvoice(posInfo.consumer_account_id, posInfo.pos_id)
|
await this.checkAccessToInvoice(posInfo.consumer_account_id, posInfo.pos_id)
|
||||||
|
|
||||||
const invoice = await this.salesInvoiceTaxService.revoke(posInfo.pos_id, invoiceId)
|
const { consumer_account_id, pos_id, business_id, complex_id } = posInfo
|
||||||
|
|
||||||
|
const invoice = await this.salesInvoiceTaxService.revoke(
|
||||||
|
consumer_account_id,
|
||||||
|
pos_id,
|
||||||
|
complex_id,
|
||||||
|
business_id,
|
||||||
|
invoiceId,
|
||||||
|
)
|
||||||
|
|
||||||
return ResponseMapper.single(invoice)
|
return ResponseMapper.single(invoice)
|
||||||
}
|
}
|
||||||
@@ -350,38 +277,10 @@ export class SalesInvoicesService {
|
|||||||
return ResponseMapper.single(invoice)
|
return ResponseMapper.single(invoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// async sendBulk(invoiceIds: string[], posInfo: IPosPayload) {
|
|
||||||
// if (!invoiceIds.length) {
|
|
||||||
// throw new BadRequestException('invoice_ids is required and cannot be empty.')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await this.salesInvoiceTaxService.sendBulk(invoiceIds, posInfo.pos_id)
|
|
||||||
|
|
||||||
// return ResponseMapper.single({
|
|
||||||
// invoice_ids: invoiceIds,
|
|
||||||
// sent_to_tax: true,
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
private isRetryableInvoiceConflict(error: unknown) {
|
|
||||||
if (!(error instanceof Prisma.PrismaClientKnownRequestError)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.code !== 'P2002') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const target = (error.meta?.target as string[]) || []
|
|
||||||
return (
|
|
||||||
target.includes('invoice_number') ||
|
|
||||||
target.includes('sales_invoices_invoice_number_pos_id_key')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildFindAllWhere(posInfo: IPosPayload, query: SalesInvoicesFilterDto) {
|
private buildFindAllWhere(posInfo: IPosPayload, query: SalesInvoicesFilterDto) {
|
||||||
const where: Prisma.SalesInvoiceWhereInput = {
|
const where: Prisma.SalesInvoiceWhereInput = {
|
||||||
pos: {
|
pos: {
|
||||||
|
id: posInfo.pos_id,
|
||||||
complex: {
|
complex: {
|
||||||
business_activity_id: posInfo.business_id,
|
business_activity_id: posInfo.business_id,
|
||||||
},
|
},
|
||||||
@@ -530,393 +429,6 @@ export class SalesInvoicesService {
|
|||||||
return where
|
return where
|
||||||
}
|
}
|
||||||
|
|
||||||
private normalizeInvoiceDate(invoiceDate: Date | string) {
|
|
||||||
return new Date(invoiceDate).toISOString() as any
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildPaymentsData(
|
|
||||||
paymentsData: CreateSalesInvoiceDto['payments'],
|
|
||||||
totalAmount: number,
|
|
||||||
) {
|
|
||||||
const paymentMethodMap: Record<string, PaymentMethodType> = {
|
|
||||||
cash: PaymentMethodType.CASH,
|
|
||||||
set_off: PaymentMethodType.SET_OFF,
|
|
||||||
card: PaymentMethodType.CARD,
|
|
||||||
payment_gateway: PaymentMethodType.PAYMENT_GATEWAY,
|
|
||||||
bank: PaymentMethodType.BANK,
|
|
||||||
check: PaymentMethodType.CHEQUE,
|
|
||||||
other: PaymentMethodType.OTHER,
|
|
||||||
terminal: PaymentMethodType.TERMINAL,
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawPayments = (paymentsData || {}) as Record<string, unknown>
|
|
||||||
const terminalInfo = rawPayments.terminals as TerminalPaymentInfo | undefined
|
|
||||||
|
|
||||||
const payments: NormalizedPayment[] = Object.entries(rawPayments)
|
|
||||||
.filter(([key]) => key !== 'terminals')
|
|
||||||
.map(([key, value]) => ({
|
|
||||||
method: paymentMethodMap[key.toLowerCase()],
|
|
||||||
amount: typeof value === 'number' ? value : Number(value || 0),
|
|
||||||
}))
|
|
||||||
.filter(payment => payment.method && payment.amount > 0) as NormalizedPayment[]
|
|
||||||
|
|
||||||
const hasTerminalPayment = payments.some(
|
|
||||||
payment => payment.method === PaymentMethodType.TERMINAL,
|
|
||||||
)
|
|
||||||
const nonTerminalTotal = payments
|
|
||||||
.filter(payment => payment.method !== PaymentMethodType.TERMINAL)
|
|
||||||
.reduce((sum, payment) => sum + payment.amount, 0)
|
|
||||||
|
|
||||||
if (!hasTerminalPayment && terminalInfo) {
|
|
||||||
const terminalAmount =
|
|
||||||
typeof terminalInfo.amount === 'number'
|
|
||||||
? terminalInfo.amount
|
|
||||||
: Math.max(0, Number(totalAmount) - nonTerminalTotal)
|
|
||||||
|
|
||||||
if (terminalAmount > 0) {
|
|
||||||
payments.push({
|
|
||||||
method: PaymentMethodType.TERMINAL,
|
|
||||||
amount: terminalAmount,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.validatePayments(payments, totalAmount, terminalInfo)
|
|
||||||
|
|
||||||
return {
|
|
||||||
payments,
|
|
||||||
terminalInfo,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private validatePayments(
|
|
||||||
payments: NormalizedPayment[],
|
|
||||||
totalAmount: number,
|
|
||||||
terminalInfo?: TerminalPaymentInfo,
|
|
||||||
) {
|
|
||||||
const totalPayments = payments.reduce((sum, payment) => sum + payment.amount, 0)
|
|
||||||
const roundedTotalPayments = Number(totalPayments.toFixed(2))
|
|
||||||
const roundedTotalAmount = Number(Number(totalAmount).toFixed(2))
|
|
||||||
|
|
||||||
if (roundedTotalPayments !== roundedTotalAmount) {
|
|
||||||
throw new BadRequestException('مبلغ پرداختی باید برابر با مبلغ کل فاکتور باشد.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const terminalPayments = payments.filter(
|
|
||||||
payment => payment.method === PaymentMethodType.TERMINAL,
|
|
||||||
)
|
|
||||||
|
|
||||||
if (terminalPayments.length > 0 && !terminalInfo) {
|
|
||||||
throw new BadRequestException('برای پرداخت ترمینال اطلاعات ترمینال الزامی است.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async resolveCustomerId(
|
|
||||||
tx: Prisma.TransactionClient,
|
|
||||||
data: CreateSalesInvoiceDto,
|
|
||||||
businessId: string,
|
|
||||||
) {
|
|
||||||
if (data.customer_id) {
|
|
||||||
return data.customer_id
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.customer_type === CustomerType.INDIVIDUAL &&
|
|
||||||
data.customer?.customer_individual
|
|
||||||
) {
|
|
||||||
const { national_id, mobile_number, ...rest } = data.customer.customer_individual
|
|
||||||
|
|
||||||
const customerIndividual = await tx.customerIndividual.upsert({
|
|
||||||
where: {
|
|
||||||
business_activity_id_national_id: {
|
|
||||||
business_activity_id: businessId,
|
|
||||||
national_id: data.customer.customer_individual.national_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
...data.customer.customer_individual,
|
|
||||||
customer: {
|
|
||||||
create: {
|
|
||||||
type: CustomerType.INDIVIDUAL,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
business_activity: {
|
|
||||||
connect: {
|
|
||||||
id: businessId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update: { ...rest },
|
|
||||||
select: {
|
|
||||||
customer_id: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!customerIndividual) {
|
|
||||||
throw new BadRequestException('متاسفانه مشکلی در اطلاعات مشتری وجود دارد.')
|
|
||||||
}
|
|
||||||
|
|
||||||
return customerIndividual.customer_id
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.customer_type === CustomerType.LEGAL && data.customer?.customer_legal) {
|
|
||||||
const { registration_number, ...rest } = data.customer.customer_legal
|
|
||||||
const customerLegal = await tx.customerLegal.upsert({
|
|
||||||
where: {
|
|
||||||
business_activity_id_economic_code: {
|
|
||||||
business_activity_id: businessId,
|
|
||||||
economic_code: data.customer.customer_legal.economic_code,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
...data.customer.customer_legal,
|
|
||||||
customer: {
|
|
||||||
create: {
|
|
||||||
type: CustomerType.LEGAL,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
business_activity: {
|
|
||||||
connect: {
|
|
||||||
id: businessId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update: {
|
|
||||||
...rest,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
customer_id: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!customerLegal) {
|
|
||||||
throw new BadRequestException('متاسفانه مشکلی در اطلاعات مشتری وجود دارد.')
|
|
||||||
}
|
|
||||||
|
|
||||||
return customerLegal.customer_id
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getGoodsById(tx: Prisma.TransactionClient, data: CreateSalesInvoiceDto) {
|
|
||||||
const itemGoodIds = data.items
|
|
||||||
.map(item => item.good_id)
|
|
||||||
.filter((goodId): goodId is string => Boolean(goodId))
|
|
||||||
|
|
||||||
const goods = itemGoodIds.length
|
|
||||||
? await tx.good.findMany({
|
|
||||||
where: {
|
|
||||||
id: {
|
|
||||||
in: itemGoodIds,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
sku: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
code: true,
|
|
||||||
VAT: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
local_sku: true,
|
|
||||||
barcode: true,
|
|
||||||
pricing_model: true,
|
|
||||||
measure_unit: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
code: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
base_sale_price: true,
|
|
||||||
image_url: true,
|
|
||||||
category: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
: []
|
|
||||||
|
|
||||||
return new Map(goods.map(good => [good.id, good]))
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildSalesInvoiceData(params: {
|
|
||||||
data: CreateSalesInvoiceDto
|
|
||||||
normalizedInvoiceDate: Date
|
|
||||||
invoiceNumber: number
|
|
||||||
consumer_account_id: string
|
|
||||||
businessId: string
|
|
||||||
complexId: string
|
|
||||||
pos_id: string
|
|
||||||
goodsById: Map<string, any>
|
|
||||||
customerId: string | null
|
|
||||||
}) {
|
|
||||||
const {
|
|
||||||
data,
|
|
||||||
normalizedInvoiceDate,
|
|
||||||
invoiceNumber,
|
|
||||||
consumer_account_id,
|
|
||||||
pos_id,
|
|
||||||
goodsById,
|
|
||||||
customerId,
|
|
||||||
businessId,
|
|
||||||
complexId,
|
|
||||||
} = params
|
|
||||||
const { customer_id, customer_type, customer, payments, ...invoiceData } = data
|
|
||||||
|
|
||||||
const salesInvoiceData: SalesInvoiceCreateInput = {
|
|
||||||
...invoiceData,
|
|
||||||
invoice_date: normalizedInvoiceDate,
|
|
||||||
invoice_number: invoiceNumber,
|
|
||||||
total_amount: data.total_amount,
|
|
||||||
code: this.generateInvoiceCode(businessId, complexId, pos_id, invoiceNumber),
|
|
||||||
items: {
|
|
||||||
createMany: {
|
|
||||||
data: data.items.map(item => ({
|
|
||||||
good_id: item.good_id!,
|
|
||||||
quantity: item.quantity,
|
|
||||||
unit_price: item.unit_price,
|
|
||||||
total_amount: item.total_amount,
|
|
||||||
measure_unit_text: goodsById.get(item.good_id!)?.measure_unit.name || null,
|
|
||||||
measure_unit_code: goodsById.get(item.good_id!)?.measure_unit.code || null,
|
|
||||||
sku_code: goodsById.get(item.good_id!)?.sku.code || null,
|
|
||||||
sku_vat: goodsById.get(item.good_id!)?.sku.VAT || null,
|
|
||||||
payload: item.payload ? JSON.parse(JSON.stringify(item.payload)) : undefined,
|
|
||||||
good_snapshot: item.good_id
|
|
||||||
? JSON.parse(
|
|
||||||
JSON.stringify({
|
|
||||||
good: goodsById.get(item.good_id) || null,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
: undefined,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
unknown_customer: {},
|
|
||||||
consumer_account: {
|
|
||||||
connect: {
|
|
||||||
id: consumer_account_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
pos: {
|
|
||||||
connect: {
|
|
||||||
id: pos_id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.send_to_tsp) {
|
|
||||||
salesInvoiceData.tsp_attempts = {
|
|
||||||
create: {
|
|
||||||
attempt_no: 1,
|
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
|
||||||
type: TspProviderRequestType.MAIN,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customerId) {
|
|
||||||
salesInvoiceData.customer = {
|
|
||||||
connect: {
|
|
||||||
id: customerId,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return salesInvoiceData
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getNextInvoiceNumber(tx: Prisma.TransactionClient, businessId: string) {
|
|
||||||
const latestInvoice = await tx.salesInvoice.findFirst({
|
|
||||||
where: {
|
|
||||||
pos: {
|
|
||||||
complex: {
|
|
||||||
business_activity_id: businessId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
invoice_number: 'desc',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
invoice_number: true,
|
|
||||||
pos: {
|
|
||||||
select: {
|
|
||||||
complex: {
|
|
||||||
select: {
|
|
||||||
business_activity: {
|
|
||||||
select: {
|
|
||||||
invoice_number_sequence: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const latestSequence =
|
|
||||||
latestInvoice?.pos?.complex?.business_activity?.invoice_number_sequence.toNumber() ||
|
|
||||||
0
|
|
||||||
|
|
||||||
console.log(latestSequence)
|
|
||||||
|
|
||||||
return Math.max(latestInvoice?.invoice_number || 0, latestSequence) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createPayments(
|
|
||||||
tx: Prisma.TransactionClient,
|
|
||||||
invoiceId: string,
|
|
||||||
payments: NormalizedPayment[],
|
|
||||||
terminalInfo: TerminalPaymentInfo | undefined,
|
|
||||||
paidAt: Date,
|
|
||||||
) {
|
|
||||||
for (const payment of payments) {
|
|
||||||
if (payment.amount <= 0) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const createdPayment = await tx.salesInvoicePayment.create({
|
|
||||||
data: {
|
|
||||||
invoice_id: invoiceId,
|
|
||||||
amount: payment.amount,
|
|
||||||
payment_method: payment.method,
|
|
||||||
paid_at: paidAt,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (payment.method === PaymentMethodType.TERMINAL && terminalInfo) {
|
|
||||||
await tx.salesInvoicePaymentTerminalInfo.create({
|
|
||||||
data: {
|
|
||||||
payment_id: createdPayment.id,
|
|
||||||
terminal_id: terminalInfo.terminalId,
|
|
||||||
stan: terminalInfo.stan,
|
|
||||||
rrn: terminalInfo.rrn,
|
|
||||||
transaction_date_time: new Date(terminalInfo.transactionDateTime || ''),
|
|
||||||
customer_card_no: terminalInfo.customerCardNO || null,
|
|
||||||
description: terminalInfo.description || null,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateInvoiceCode(
|
|
||||||
business_id: string,
|
|
||||||
complex_id: string,
|
|
||||||
pos_id: string,
|
|
||||||
invoice_number: number,
|
|
||||||
) {
|
|
||||||
return `${business_id.substring(business_id.length - 2, business_id.length)}-${complex_id.substring(complex_id.length - 2, complex_id.length)}-${pos_id.substring(pos_id.length - 2, pos_id.length)}-${invoice_number.toString()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
private async checkAccessToInvoice(
|
private async checkAccessToInvoice(
|
||||||
consumer_account_id: string,
|
consumer_account_id: string,
|
||||||
pos_id: string,
|
pos_id: string,
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import {
|
||||||
|
SharedCreateSalesInvoiceItemDto,
|
||||||
|
SharedCreateSalesInvoicePaymentsDto,
|
||||||
|
} from '@/common/services/saleInvoices/sale-invoice-create.dto'
|
||||||
import {
|
import {
|
||||||
CustomerType,
|
CustomerType,
|
||||||
InvoiceTemplateType,
|
InvoiceTemplateType,
|
||||||
@@ -10,6 +14,7 @@ import {
|
|||||||
import { ApiProperty } from '@nestjs/swagger'
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
import { Type } from 'class-transformer'
|
import { Type } from 'class-transformer'
|
||||||
import {
|
import {
|
||||||
|
ArrayMinSize,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsDateString,
|
IsDateString,
|
||||||
@@ -142,7 +147,7 @@ export class TspProviderSendItemPayloadDto {
|
|||||||
payload?: unknown
|
payload?: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TspProviderSendPayloadDto {
|
export class TspProviderOriginalSendPayloadDto {
|
||||||
@ApiProperty({ required: true, enum: TspProviderRequestType })
|
@ApiProperty({ required: true, enum: TspProviderRequestType })
|
||||||
@IsEnum(TspProviderRequestType)
|
@IsEnum(TspProviderRequestType)
|
||||||
type: TspProviderRequestType
|
type: TspProviderRequestType
|
||||||
@@ -219,11 +224,14 @@ export class TspProviderSendItemResultDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
tax_id?: string | null
|
tax_id?: string | null
|
||||||
|
|
||||||
@ApiProperty({ required: true, nullable: true, type: TspProviderSendPayloadDto })
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
nullable: true,
|
||||||
|
type: TspProviderOriginalSendPayloadDto,
|
||||||
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsObject()
|
@IsObject()
|
||||||
@Type(() => TspProviderSendPayloadDto)
|
request_payload: Object
|
||||||
request_payload: TspProviderSendPayloadDto
|
|
||||||
|
|
||||||
@ApiProperty({ required: false, nullable: true, type: Object })
|
@ApiProperty({ required: false, nullable: true, type: Object })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -260,6 +268,8 @@ export class TspProviderBulkSendResultDto {
|
|||||||
items: TspProviderSendItemResultDto[]
|
items: TspProviderSendItemResultDto[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////// GET RELATED DTOs /////////////
|
||||||
|
|
||||||
export class TspProviderGetResultDto {
|
export class TspProviderGetResultDto {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -292,6 +302,8 @@ export class TspProviderGetResultDto {
|
|||||||
received_at: string
|
received_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////// REVOKE RELATED DTOs /////////////
|
||||||
|
|
||||||
export class TspProviderRevokePayloadDto {
|
export class TspProviderRevokePayloadDto {
|
||||||
@ApiProperty({ required: true, nullable: true })
|
@ApiProperty({ required: true, nullable: true })
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@@ -319,7 +331,7 @@ export class TspProviderRevokePayloadDto {
|
|||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@IsString()
|
@IsString()
|
||||||
last_attempt_tax_id: string
|
last_tax_id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TspProviderRevokeResponseDto {
|
export class TspProviderRevokeResponseDto {
|
||||||
@@ -363,10 +375,55 @@ export class TspProviderRevokeResponseDto {
|
|||||||
received_at: string
|
received_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////// CORRECTION RELATED DTOs /////////////
|
||||||
|
export class TspProviderCorrectionInvoicePayloadDto {
|
||||||
|
@ApiProperty({ type: [SharedCreateSalesInvoiceItemDto] })
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => SharedCreateSalesInvoiceItemDto)
|
||||||
|
@ArrayMinSize(1)
|
||||||
|
items: SharedCreateSalesInvoiceItemDto[]
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsNumber()
|
||||||
|
total_amount: number
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, type: SharedCreateSalesInvoicePaymentsDto })
|
||||||
|
@IsObject()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => SharedCreateSalesInvoicePaymentsDto)
|
||||||
|
payments: SharedCreateSalesInvoicePaymentsDto
|
||||||
|
}
|
||||||
|
export class TspProviderCorrectionSendPayloadDto extends TspProviderOriginalSendPayloadDto {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsString()
|
||||||
|
last_tax_id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TspProviderCorrectionSendResponseDto {}
|
||||||
|
|
||||||
|
export class TspProviderActionResponseDto {
|
||||||
|
@IsObject()
|
||||||
|
invoice: object
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message: string
|
||||||
|
|
||||||
|
@IsEnum(TspProviderResponseStatus)
|
||||||
|
status: TspProviderResponseStatus
|
||||||
|
}
|
||||||
|
|
||||||
export interface IProviderSwitchAdapter {
|
export interface IProviderSwitchAdapter {
|
||||||
readonly code: string
|
readonly code: string
|
||||||
send(payload: TspProviderSendPayloadDto): Promise<TspProviderSendItemResultDto>
|
originalSend(
|
||||||
sendBulk(payloads: TspProviderSendPayloadDto[]): Promise<TspProviderBulkSendResultDto[]>
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): Promise<TspProviderSendItemResultDto>
|
||||||
|
sendBulk(
|
||||||
|
payloads: TspProviderOriginalSendPayloadDto[],
|
||||||
|
): Promise<TspProviderBulkSendResultDto[]>
|
||||||
|
correctionSend(
|
||||||
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
|
): Promise<TspProviderCorrectionSendResponseDto>
|
||||||
get(invoiceId: string, tsp_token: string): Promise<TspProviderGetResultDto>
|
get(invoiceId: string, tsp_token: string): Promise<TspProviderGetResultDto>
|
||||||
revoke(payload: TspProviderRevokePayloadDto): Promise<TspProviderRevokeResponseDto>
|
revoke(payload: TspProviderRevokePayloadDto): Promise<TspProviderRevokeResponseDto>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import {
|
import {
|
||||||
TspProviderBulkSendResultDto,
|
TspProviderBulkSendResultDto,
|
||||||
|
TspProviderCorrectionSendPayloadDto,
|
||||||
|
TspProviderCorrectionSendResponseDto,
|
||||||
TspProviderGetResultDto,
|
TspProviderGetResultDto,
|
||||||
|
TspProviderOriginalSendPayloadDto,
|
||||||
TspProviderRevokePayloadDto,
|
TspProviderRevokePayloadDto,
|
||||||
TspProviderRevokeResponseDto,
|
TspProviderRevokeResponseDto,
|
||||||
TspProviderSendItemResultDto,
|
TspProviderSendItemResultDto,
|
||||||
TspProviderSendPayloadDto,
|
|
||||||
} from './dto/provider-switch.dto'
|
} from './dto/provider-switch.dto'
|
||||||
import { NamaProviderSwitchAdapter } from './switch/nama/nama-provider.adapter'
|
import { NamaProviderSwitchAdapter } from './switch/nama/nama-provider.adapter'
|
||||||
|
|
||||||
@@ -23,15 +25,24 @@ export class SalesInvoiceTspSwitchService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(payload: TspProviderSendPayloadDto): Promise<TspProviderSendItemResultDto> {
|
async send(
|
||||||
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): Promise<TspProviderSendItemResultDto> {
|
||||||
const adapter = this.resolveSwitch(payload.tsp_provider)
|
const adapter = this.resolveSwitch(payload.tsp_provider)
|
||||||
return adapter.send(payload)
|
return adapter.originalSend(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
async correction(
|
||||||
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
|
): Promise<TspProviderCorrectionSendResponseDto> {
|
||||||
|
const adapter = this.resolveSwitch(payload.tsp_provider)
|
||||||
|
return adapter.correctionSend(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendBulk(
|
async sendBulk(
|
||||||
payloads: TspProviderSendPayloadDto[],
|
payloads: TspProviderOriginalSendPayloadDto[],
|
||||||
): Promise<TspProviderBulkSendResultDto[]> {
|
): Promise<TspProviderBulkSendResultDto[]> {
|
||||||
const groupedByProvider = new Map<string, TspProviderSendPayloadDto[]>()
|
const groupedByProvider = new Map<string, TspProviderOriginalSendPayloadDto[]>()
|
||||||
|
|
||||||
for (const payload of payloads) {
|
for (const payload of payloads) {
|
||||||
const key = payload.tsp_provider?.trim().toUpperCase() || 'NAMA'
|
const key = payload.tsp_provider?.trim().toUpperCase() || 'NAMA'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { HttpClientUtil } from '@/common/utils'
|
import { HttpClientUtil } from '@/common/utils'
|
||||||
|
import { SharedSaleInvoiceCreateService } from '@/common/services/saleInvoices/sale-invoice-create.service'
|
||||||
import { NamaProviderUtils } from '@/modules/tspProviders/switch/nama/nama-provider.util'
|
import { NamaProviderUtils } from '@/modules/tspProviders/switch/nama/nama-provider.util'
|
||||||
import { PrismaModule } from '@/prisma/prisma.module'
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
@@ -14,6 +15,7 @@ import { NamaProviderSwitchAdapter } from './switch/nama/nama-provider.adapter'
|
|||||||
SalesInvoiceTspSwitchService,
|
SalesInvoiceTspSwitchService,
|
||||||
NamaProviderSwitchAdapter,
|
NamaProviderSwitchAdapter,
|
||||||
NamaProviderUtils,
|
NamaProviderUtils,
|
||||||
|
SharedSaleInvoiceCreateService,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
HttpClientUtil,
|
HttpClientUtil,
|
||||||
@@ -21,6 +23,7 @@ import { NamaProviderSwitchAdapter } from './switch/nama/nama-provider.adapter'
|
|||||||
SalesInvoiceTspSwitchService,
|
SalesInvoiceTspSwitchService,
|
||||||
NamaProviderSwitchAdapter,
|
NamaProviderSwitchAdapter,
|
||||||
NamaProviderUtils,
|
NamaProviderUtils,
|
||||||
|
SharedSaleInvoiceCreateService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class SaleInvoiceTspModule {}
|
export class SaleInvoiceTspModule {}
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
|
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 {
|
import {
|
||||||
|
CustomerType,
|
||||||
|
Prisma,
|
||||||
TspProviderCustomerType,
|
TspProviderCustomerType,
|
||||||
TspProviderRequestType,
|
TspProviderRequestType,
|
||||||
TspProviderResponseStatus,
|
TspProviderResponseStatus,
|
||||||
} from 'generated/prisma/client'
|
} from 'generated/prisma/client'
|
||||||
import { CreateSalesInvoiceDto } from '../pos/sales-invoices/dto/create-sales-invoice.dto'
|
|
||||||
import {
|
import {
|
||||||
|
TspProviderActionResponseDto,
|
||||||
|
TspProviderCorrectionInvoicePayloadDto,
|
||||||
|
TspProviderCorrectionSendPayloadDto,
|
||||||
|
TspProviderCorrectionSendResponseDto,
|
||||||
|
TspProviderOriginalSendPayloadDto,
|
||||||
TspProviderRevokePayloadDto,
|
TspProviderRevokePayloadDto,
|
||||||
TspProviderRevokeResponseDto,
|
|
||||||
TspProviderSendItemResultDto,
|
TspProviderSendItemResultDto,
|
||||||
TspProviderSendPayloadDto,
|
|
||||||
} 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'
|
||||||
|
|
||||||
@@ -19,81 +24,51 @@ type ItemTspRow = {
|
|||||||
tax_id: string | null
|
tax_id: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type IAttempt = any
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesInvoiceTspService {
|
export class SalesInvoiceTspService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly tspSwitchService: SalesInvoiceTspSwitchService,
|
private readonly tspSwitchService: SalesInvoiceTspSwitchService,
|
||||||
|
private sharedSaleInvoiceCreateService: SharedSaleInvoiceCreateService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async send(consumer_id: string, invoice_id: string): Promise<IAttempt> {
|
async originalSend(
|
||||||
const posId = await this.getPosId(consumer_id, invoice_id)
|
posId: string,
|
||||||
|
invoice_id: string,
|
||||||
|
): Promise<TspProviderActionResponseDto> {
|
||||||
const payload = await this.buildPayload(invoice_id, posId)
|
const payload = await this.buildPayload(invoice_id, posId)
|
||||||
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
||||||
data: {
|
data: {
|
||||||
attempt_no: 1,
|
attempt_no: 1,
|
||||||
invoice_id,
|
invoice_id,
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
type: TspProviderRequestType.MAIN,
|
|
||||||
request_payload: JSON.parse(JSON.stringify(payload)),
|
request_payload: JSON.parse(JSON.stringify(payload)),
|
||||||
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const sendResult = await this.trySend(payload)
|
const result = await this.trySend(payload)
|
||||||
|
|
||||||
console.log('sendResult')
|
return await this.onCreateCorrectionResult(result, attempt.id)
|
||||||
console.log(sendResult)
|
|
||||||
|
|
||||||
if (sendResult) {
|
|
||||||
if (sendResult.hasError) {
|
|
||||||
throw new Error(sendResult.message || '')
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedAttempt = await this.prisma.saleInvoiceTspAttempts.update({
|
|
||||||
where: {
|
|
||||||
id: attempt.id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
response_payload: JSON.parse(JSON.stringify(sendResult)),
|
|
||||||
status: sendResult.status,
|
|
||||||
tax_id: sendResult.tax_id,
|
|
||||||
sent_at: sendResult.sent_at,
|
|
||||||
received_at: sendResult.received_at,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
status: true,
|
|
||||||
invoice: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
...updatedAttempt.invoice,
|
|
||||||
status: updatedAttempt.status,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new NotFoundException(
|
|
||||||
'متاسفانه امکان ارسال فاکتور به سیستم مالیاتی در حال حاضر وجود ندارد. لطفا بعدا تلاش کنید.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendBulk(consumer_id: string, invoice_ids: string[]): Promise<void> {
|
async sendBulk(consumer_id: string, invoice_ids: string[]): Promise<void> {
|
||||||
if (!invoice_ids.length) return
|
// if (!invoice_ids.length) return
|
||||||
|
// const payloads: TspProviderOriginalSendPayloadDto[] = []
|
||||||
const payloads: TspProviderSendPayloadDto[] = []
|
// for (const invoiceId of invoice_ids) {
|
||||||
for (const invoiceId of invoice_ids) {
|
// const posId = await this.getPosId(consumer_id, invoiceId)
|
||||||
const posId = await this.getPosId(consumer_id, invoiceId)
|
// payloads.push(await this.buildPayload(invoiceId, posId))
|
||||||
payloads.push(await this.buildPayload(invoiceId, posId))
|
// }
|
||||||
}
|
// const bulkResult = await this.tspSwitchService.sendBulk(payloads)
|
||||||
|
// const allItemResults = bulkResult.flatMap(result => result.items)
|
||||||
const bulkResult = await this.tspSwitchService.sendBulk(payloads)
|
// await this.persistAttemptResults(allItemResults)
|
||||||
const allItemResults = bulkResult.flatMap(result => result.items)
|
|
||||||
await this.persistAttemptResults(allItemResults)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(invoice_id: string, pos_id: string, consumer_id: string): Promise<IAttempt> {
|
async get(
|
||||||
|
invoice_id: string,
|
||||||
|
pos_id: string,
|
||||||
|
consumer_id: string,
|
||||||
|
): Promise<TspProviderActionResponseDto> {
|
||||||
const [attempt, pos] = await this.prisma.$transaction(async tx => [
|
const [attempt, pos] = await this.prisma.$transaction(async tx => [
|
||||||
await tx.saleInvoiceTspAttempts.findFirst({
|
await tx.saleInvoiceTspAttempts.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -190,206 +165,307 @@ export class SalesInvoiceTspService {
|
|||||||
select: {
|
select: {
|
||||||
status: true,
|
status: true,
|
||||||
invoice: true,
|
invoice: true,
|
||||||
|
message: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...updatedAttempt.invoice,
|
invoice: updatedAttempt.invoice,
|
||||||
status: updatedAttempt.status,
|
status: updatedAttempt.status,
|
||||||
|
message: updatedAttempt.message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(
|
async correctionSend(
|
||||||
consumer_id: string,
|
consumerAccountId: string,
|
||||||
invoice_id: string,
|
posId: string,
|
||||||
dataToUpdate: CreateSalesInvoiceDto,
|
complexId: string,
|
||||||
): Promise<IAttempt> {
|
businessId: string,
|
||||||
const posId = await this.getPosId(consumer_id, invoice_id)
|
ref_invoice_id: string,
|
||||||
const payload = await this.buildPayload(invoice_id, posId)
|
dataToUpdate: TspProviderCorrectionInvoicePayloadDto,
|
||||||
|
): Promise<TspProviderActionResponseDto> {
|
||||||
const lastAttempt = await this.prisma.saleInvoiceTspAttempts.findFirst({
|
const [newInvoice, attempt, correctionPayload] = await this.prisma.$transaction(
|
||||||
where: {
|
async tx => {
|
||||||
invoice_id,
|
const relatedInvoice = await tx.salesInvoice.findUnique({
|
||||||
invoice: {
|
where: {
|
||||||
pos: {
|
id: ref_invoice_id,
|
||||||
complex: {
|
},
|
||||||
business_activity: {
|
include: {
|
||||||
consumer_id,
|
customer: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
tsp_attempts: {
|
||||||
},
|
orderBy: {
|
||||||
},
|
attempt_no: 'desc',
|
||||||
orderBy: {
|
|
||||||
attempt_no: 'desc',
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
invoice: {
|
|
||||||
include: {
|
|
||||||
items: {
|
|
||||||
include: {
|
|
||||||
good: true,
|
|
||||||
},
|
},
|
||||||
|
take: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!relatedInvoice) {
|
||||||
|
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relatedInvoice.type === TspProviderRequestType.REVOKE) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'فاکتور ارسالی قبلا ابطال شده است و امکان ویرایش آن وجود ندارد.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!relatedInvoice.tax_id) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'فاکتور قبلی همچنان در حال بررسی است و امکان ویرایش آن وجود ندارد.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const newInvoice = await this.sharedSaleInvoiceCreateService.create({
|
||||||
|
data: {
|
||||||
|
customer_type: relatedInvoice.customer?.type || CustomerType.UNKNOWN,
|
||||||
|
invoice_date: new Date(),
|
||||||
|
payments: dataToUpdate.payments,
|
||||||
|
items: dataToUpdate.items,
|
||||||
|
total_amount: dataToUpdate.total_amount,
|
||||||
|
customer_id: relatedInvoice.customer_id || undefined,
|
||||||
|
},
|
||||||
|
businessId,
|
||||||
|
complexId,
|
||||||
|
posId,
|
||||||
|
consumerAccountId,
|
||||||
|
main_invoice_id: relatedInvoice.main_id || relatedInvoice.id,
|
||||||
|
ref_invoice_id: relatedInvoice.id,
|
||||||
|
type: TspProviderRequestType.CORRECTION,
|
||||||
|
})
|
||||||
|
|
||||||
|
const correctionPayload = await this.buildCorrectionPayload(tx, newInvoice.id)
|
||||||
|
|
||||||
|
const attempt = await tx.saleInvoiceTspAttempts.create({
|
||||||
|
data: {
|
||||||
|
attempt_no: 1,
|
||||||
|
invoice_id: newInvoice.id,
|
||||||
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
|
request_payload: JSON.parse(JSON.stringify(correctionPayload)),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return [newInvoice, attempt, correctionPayload]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = await this.trySend(correctionPayload)
|
||||||
|
|
||||||
|
console.log('sendResult')
|
||||||
|
console.log(result)
|
||||||
|
return this.onCreateCorrectionResult(result, attempt.id)
|
||||||
|
|
||||||
|
// const countByGoodId = (goodIds: string[]): Map<string, number> => {
|
||||||
|
// const counts = new Map<string, number>()
|
||||||
|
// for (const goodId of goodIds) {
|
||||||
|
// counts.set(goodId, (counts.get(goodId) ?? 0) + 1)
|
||||||
|
// }
|
||||||
|
// return counts
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const updatedGoodIds = dataToUpdate.items.map(item => item.good_id!)
|
||||||
|
// const previousGoodIds = lastAttempt.invoice.items.map(item => item.good_id)
|
||||||
|
|
||||||
|
// const updatedCounts = countByGoodId(updatedGoodIds)
|
||||||
|
// const previousCounts = countByGoodId(previousGoodIds)
|
||||||
|
|
||||||
|
// let isBackFromSale = false
|
||||||
|
// if (updatedCounts.size !== previousCounts.size) {
|
||||||
|
// isBackFromSale = true
|
||||||
|
// } else {
|
||||||
|
// for (const [goodId, count] of updatedCounts) {
|
||||||
|
// if (previousCounts.get(goodId) !== count) {
|
||||||
|
// isBackFromSale = true
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
async revoke(
|
||||||
|
consumerAccountId: string,
|
||||||
|
posId: string,
|
||||||
|
complexId: string,
|
||||||
|
businessId: string,
|
||||||
|
ref_invoice_id: string,
|
||||||
|
): Promise<TspProviderActionResponseDto> {
|
||||||
|
const [newInvoice, attempt, revokePayload] = await this.prisma.$transaction(
|
||||||
|
async tx => {
|
||||||
|
const relatedInvoice = await tx.salesInvoice.findUnique({
|
||||||
|
where: {
|
||||||
|
id: ref_invoice_id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
customer: {
|
||||||
|
select: {
|
||||||
|
type: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tsp_attempts: {
|
||||||
|
orderBy: {
|
||||||
|
attempt_no: 'desc',
|
||||||
|
},
|
||||||
|
take: 1,
|
||||||
},
|
},
|
||||||
payments: {
|
payments: {
|
||||||
include: {
|
include: {
|
||||||
terminal_info: true,
|
terminal_info: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
items: true,
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!lastAttempt) {
|
if (!relatedInvoice) {
|
||||||
throw new NotFoundException('صورتحساب ارسالی فاکتور شما به سامانه یافت نشد.')
|
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||||
}
|
|
||||||
|
|
||||||
if (lastAttempt.status === TspProviderResponseStatus.QUEUED) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'فاکتور هنوز به سامانه مالیاتی ارسال نشده است یا در صف ارسال قرار دارد. لطفا بعدا تلاش کنید.',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const countByGoodId = (goodIds: string[]): Map<string, number> => {
|
|
||||||
const counts = new Map<string, number>()
|
|
||||||
for (const goodId of goodIds) {
|
|
||||||
counts.set(goodId, (counts.get(goodId) ?? 0) + 1)
|
|
||||||
}
|
|
||||||
return counts
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedGoodIds = dataToUpdate.items.map(item => item.good_id!)
|
|
||||||
const previousGoodIds = lastAttempt.invoice.items.map(item => item.good_id)
|
|
||||||
|
|
||||||
const updatedCounts = countByGoodId(updatedGoodIds)
|
|
||||||
const previousCounts = countByGoodId(previousGoodIds)
|
|
||||||
|
|
||||||
let isBackFromSale = false
|
|
||||||
if (updatedCounts.size !== previousCounts.size) {
|
|
||||||
isBackFromSale = true
|
|
||||||
} else {
|
|
||||||
for (const [goodId, count] of updatedCounts) {
|
|
||||||
if (previousCounts.get(goodId) !== count) {
|
|
||||||
isBackFromSale = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const attempt = await this.prisma.saleInvoiceTspAttempts.create({
|
if (relatedInvoice.type === TspProviderRequestType.REVOKE) {
|
||||||
data: {
|
throw new BadRequestException(
|
||||||
attempt_no: 1,
|
'فاکتور ارسالی قبلا ابطال شده است و امکان ویرایش آن وجود ندارد.',
|
||||||
invoice_id,
|
)
|
||||||
status: TspProviderResponseStatus.QUEUED,
|
}
|
||||||
type: TspProviderRequestType.MAIN,
|
|
||||||
request_payload: JSON.parse(JSON.stringify(payload)),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const sendResult = await this.trySend(payload)
|
if (!relatedInvoice.tax_id) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'فاکتور قبلی همچنان در حال بررسی است و امکان ویرایش آن وجود ندارد.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('sendResult')
|
const payments = relatedInvoice.payments.reduce(
|
||||||
console.log(sendResult)
|
(acc, payment) => {
|
||||||
|
const amount = Number(payment.amount)
|
||||||
if (sendResult) {
|
switch (payment.payment_method) {
|
||||||
if (sendResult.hasError) {
|
case 'CASH':
|
||||||
throw new Error(sendResult.message || '')
|
acc.cash = (acc.cash || 0) + amount
|
||||||
}
|
break
|
||||||
|
case 'SET_OFF':
|
||||||
const updatedAttempt = await this.prisma.saleInvoiceTspAttempts.update({
|
acc.set_off = (acc.set_off || 0) + amount
|
||||||
where: {
|
break
|
||||||
id: attempt.id,
|
case 'CARD':
|
||||||
},
|
acc.card = (acc.card || 0) + amount
|
||||||
data: {
|
break
|
||||||
response_payload: JSON.parse(JSON.stringify(sendResult)),
|
case 'BANK':
|
||||||
status: sendResult.status,
|
acc.bank = (acc.bank || 0) + amount
|
||||||
tax_id: sendResult.tax_id,
|
break
|
||||||
sent_at: sendResult.sent_at,
|
case 'CHEQUE':
|
||||||
received_at: sendResult.received_at,
|
acc.check = (acc.check || 0) + amount
|
||||||
},
|
break
|
||||||
select: {
|
case 'OTHER':
|
||||||
status: true,
|
acc.other = (acc.other || 0) + amount
|
||||||
invoice: true,
|
break
|
||||||
},
|
case 'TERMINAL':
|
||||||
})
|
acc.terminals = payment.terminal_info
|
||||||
|
? {
|
||||||
return {
|
amount,
|
||||||
...updatedAttempt.invoice,
|
terminalId: payment.terminal_info.terminal_id,
|
||||||
status: updatedAttempt.status,
|
stan: payment.terminal_info.stan,
|
||||||
}
|
rrn: payment.terminal_info.rrn,
|
||||||
} else {
|
customer_card_no:
|
||||||
throw new NotFoundException(
|
payment.terminal_info.customer_card_no || undefined,
|
||||||
'متاسفانه امکان ارسال فاکتور به سیستم مالیاتی در حال حاضر وجود ندارد. لطفا بعدا تلاش کنید.',
|
transaction_date_time: payment.terminal_info.transaction_date_time,
|
||||||
)
|
description: payment.terminal_info.description || undefined,
|
||||||
}
|
}
|
||||||
}
|
: acc.terminals
|
||||||
|
break
|
||||||
async revoke(
|
default:
|
||||||
pos_id: string,
|
break
|
||||||
invoice_id: string,
|
}
|
||||||
): Promise<TspProviderRevokeResponseDto> {
|
return acc
|
||||||
const attempt = await this.prisma.saleInvoiceTspAttempts.findFirst({
|
|
||||||
where: {
|
|
||||||
invoice_id,
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
attempt_no: 'desc',
|
|
||||||
},
|
|
||||||
take: 1,
|
|
||||||
select: {
|
|
||||||
tax_id: true,
|
|
||||||
status: true,
|
|
||||||
attempt_no: true,
|
|
||||||
invoice: {
|
|
||||||
select: {
|
|
||||||
invoice_number: true,
|
|
||||||
},
|
},
|
||||||
},
|
{} as {
|
||||||
},
|
terminals?: {
|
||||||
})
|
amount?: number
|
||||||
|
terminalId: string
|
||||||
|
stan: string
|
||||||
|
rrn: string
|
||||||
|
customer_card_no?: string
|
||||||
|
transaction_date_time: Date
|
||||||
|
description?: string
|
||||||
|
}
|
||||||
|
cash?: number
|
||||||
|
set_off?: number
|
||||||
|
card?: number
|
||||||
|
bank?: number
|
||||||
|
check?: number
|
||||||
|
other?: number
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if (!attempt) {
|
const newInvoice = await this.sharedSaleInvoiceCreateService.create({
|
||||||
throw new NotFoundException('صورتحساب ارسالی فاکتور شما به سامانه یافت نشد.')
|
data: {
|
||||||
}
|
customer_type: relatedInvoice.customer?.type || CustomerType.UNKNOWN,
|
||||||
if (attempt.status === TspProviderResponseStatus.QUEUED) {
|
invoice_date: new Date(),
|
||||||
throw new BadRequestException(
|
payments,
|
||||||
'فاکتور هنوز به سامانه مالیاتی ارسال نشده است یا در صف ارسال قرار دارد. لطفا بعدا تلاش کنید.',
|
items: relatedInvoice.items.map(item => ({
|
||||||
)
|
unit_price: Number(item.unit_price),
|
||||||
}
|
quantity: Number(item.quantity),
|
||||||
|
total_amount: Number(item.total_amount),
|
||||||
const payload = await this.buildRevokePayload(invoice_id, pos_id)
|
discount_amount: Number(item.discount || 0),
|
||||||
|
invoice_id: '',
|
||||||
const result = await this.tspSwitchService.revoke(payload)
|
good_id: item.good_id,
|
||||||
|
service_id: item.service_id || undefined,
|
||||||
if (result) {
|
payload: item.payload as any,
|
||||||
await this.prisma.saleInvoiceTspAttempts.create({
|
notes: item.notes || '',
|
||||||
data: {
|
})),
|
||||||
attempt_no: attempt.attempt_no + 1,
|
total_amount: Number(relatedInvoice.total_amount),
|
||||||
invoice_id,
|
customer_id: relatedInvoice.customer_id || undefined,
|
||||||
status: TspProviderResponseStatus.REVOKED,
|
},
|
||||||
|
businessId,
|
||||||
|
complexId,
|
||||||
|
posId,
|
||||||
|
consumerAccountId,
|
||||||
|
main_invoice_id: relatedInvoice.main_id || relatedInvoice.id,
|
||||||
|
ref_invoice_id: relatedInvoice.id,
|
||||||
type: TspProviderRequestType.REVOKE,
|
type: TspProviderRequestType.REVOKE,
|
||||||
received_at: new Date(),
|
})
|
||||||
request_payload: JSON.parse(JSON.stringify(result.request_payload)),
|
|
||||||
sent_at: result.sent_at ? new Date(result.sent_at) : new Date(),
|
|
||||||
response_payload: JSON.parse(JSON.stringify(result)),
|
|
||||||
tax_id: result.tax_id,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
const payload = await this.buildRevokePayload(newInvoice.id, posId)
|
||||||
|
|
||||||
|
const attempt = await tx.saleInvoiceTspAttempts.create({
|
||||||
|
data: {
|
||||||
|
attempt_no: 1,
|
||||||
|
invoice_id: newInvoice.id,
|
||||||
|
message: 'در حال ارسال به سامانه مالیاتی...',
|
||||||
|
status: TspProviderResponseStatus.QUEUED,
|
||||||
|
request_payload: JSON.parse(JSON.stringify(payload)),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return [newInvoice, attempt, payload]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = await this.tspSwitchService.revoke(revokePayload)
|
||||||
|
|
||||||
|
return await this.onCreateCorrectionResult(result, attempt.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getPosId(consumer_id: string, invoice_id: string): Promise<string> {
|
private async getPosId(
|
||||||
|
consumer_account_id: string,
|
||||||
|
invoice_id: string,
|
||||||
|
): Promise<string> {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
console.log(consumer_account_id, invoice_id)
|
||||||
const saleInvoice = await this.prisma.salesInvoice.findUnique({
|
const saleInvoice = await this.prisma.salesInvoice.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: invoice_id,
|
id: invoice_id,
|
||||||
pos: {
|
pos: {
|
||||||
complex: {
|
complex: {
|
||||||
business_activity: {
|
business_activity: {
|
||||||
consumer_id,
|
consumer: {
|
||||||
|
accounts: {
|
||||||
|
some: {
|
||||||
|
id: consumer_account_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -462,6 +538,7 @@ export class SalesInvoiceTspService {
|
|||||||
total_amount: true,
|
total_amount: true,
|
||||||
invoice_date: true,
|
invoice_date: true,
|
||||||
invoice_number: true,
|
invoice_number: true,
|
||||||
|
tax_id: true,
|
||||||
tsp_attempts: {
|
tsp_attempts: {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
created_at: 'asc',
|
created_at: 'asc',
|
||||||
@@ -470,7 +547,6 @@ export class SalesInvoiceTspService {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
status: true,
|
status: true,
|
||||||
tax_id: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pos: {
|
pos: {
|
||||||
@@ -532,14 +608,147 @@ export class SalesInvoiceTspService {
|
|||||||
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
fiscal_id: invoice.pos.complex.business_activity.fiscal_id,
|
||||||
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
tsp_token: invoice.pos.complex.business_activity.partner_token,
|
||||||
tsp_provider: partner.tsp_provider!,
|
tsp_provider: partner.tsp_provider!,
|
||||||
last_attempt_tax_id: invoice.tsp_attempts[0].tax_id!,
|
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(
|
private async buildPayload(
|
||||||
invoiceId: string,
|
invoiceId: string,
|
||||||
posId: string,
|
posId: string,
|
||||||
): Promise<TspProviderSendPayloadDto> {
|
): Promise<TspProviderOriginalSendPayloadDto> {
|
||||||
const invoice = await this.prisma.salesInvoice.findUnique({
|
const invoice = await this.prisma.salesInvoice.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: invoiceId,
|
id: invoiceId,
|
||||||
@@ -644,6 +853,8 @@ export class SalesInvoiceTspService {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(invoiceId, posId)
|
||||||
|
|
||||||
if (!invoice) {
|
if (!invoice) {
|
||||||
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
throw new NotFoundException('فاکتور مورد نظر یافت نشد.')
|
||||||
}
|
}
|
||||||
@@ -667,7 +878,7 @@ export class SalesInvoiceTspService {
|
|||||||
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
card_number: payment.terminal_info ? payment.terminal_info.stan : undefined,
|
||||||
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
tracking_code: payment.terminal_info ? payment.terminal_info.rrn : undefined,
|
||||||
})),
|
})),
|
||||||
type: TspProviderRequestType.MAIN,
|
type: TspProviderRequestType.ORIGINAL,
|
||||||
tsp_provider: partner.tsp_provider!,
|
tsp_provider: partner.tsp_provider!,
|
||||||
customer_type: invoice.customer?.type
|
customer_type: invoice.customer?.type
|
||||||
? TspProviderCustomerType.Known
|
? TspProviderCustomerType.Known
|
||||||
@@ -696,62 +907,79 @@ export class SalesInvoiceTspService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async tryCorrection(
|
||||||
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
|
): Promise<TspProviderCorrectionSendResponseDto | null> {
|
||||||
|
const taxResult = await this.tspSwitchService.correction(payload)
|
||||||
|
|
||||||
|
return taxResult || null
|
||||||
|
}
|
||||||
|
|
||||||
private async trySend(
|
private async trySend(
|
||||||
payload: TspProviderSendPayloadDto,
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
): Promise<TspProviderSendItemResultDto | null> {
|
): Promise<TspProviderSendItemResultDto | null> {
|
||||||
const taxResult = await this.tspSwitchService.send(payload)
|
const taxResult = await this.tspSwitchService.send(payload)
|
||||||
|
|
||||||
return taxResult || null
|
return taxResult || null
|
||||||
}
|
}
|
||||||
|
|
||||||
private async persistAttemptResults(
|
private async onCreateCorrectionResult(
|
||||||
itemResults: TspProviderSendItemResultDto[],
|
result: any,
|
||||||
): Promise<any> {
|
attempt_id: string,
|
||||||
if (!itemResults.length) return
|
): Promise<TspProviderActionResponseDto> {
|
||||||
|
if (result) {
|
||||||
const attemptsResult = [] as any[]
|
if (result.hasError) {
|
||||||
console.log('persistAttemptResults')
|
const updatedAttempt = await this.prisma.saleInvoiceTspAttempts.update({
|
||||||
|
|
||||||
for (const itemResult of itemResults) {
|
|
||||||
const attempt = await this.prisma.$transaction(async tx => {
|
|
||||||
const lastAttempt = await tx.saleInvoiceTspAttempts.findFirst({
|
|
||||||
where: {
|
where: {
|
||||||
invoice_id: itemResult.invoice_id,
|
id: attempt_id,
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
attempt_no: 'desc',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const attempt = await tx.saleInvoiceTspAttempts.update({
|
|
||||||
where: {
|
|
||||||
id: lastAttempt!.id,
|
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
status: itemResult.status,
|
response_payload: JSON.parse(JSON.stringify(result)),
|
||||||
tax_id: itemResult.tax_id,
|
status: result.status,
|
||||||
request_payload: JSON.parse(JSON.stringify(itemResult.request_payload)),
|
message: result.message?.toString() || 'وجود مشکل در ارسال به سامانه مالیاتی',
|
||||||
response_payload: JSON.parse(JSON.stringify(itemResult.response_payload)),
|
},
|
||||||
error_message: itemResult.message,
|
select: {
|
||||||
sent_at: itemResult.sent_at ? new Date(itemResult.sent_at) : new Date(),
|
status: true,
|
||||||
received_at: itemResult.received_at
|
invoice: true,
|
||||||
? new Date(itemResult.received_at)
|
message: true,
|
||||||
: new Date(),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
return {
|
||||||
|
invoice: updatedAttempt.invoice,
|
||||||
|
status: updatedAttempt.status,
|
||||||
|
message: updatedAttempt.message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return attempt
|
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: 'ارسال با موفقیت انجام شد.',
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
status: true,
|
||||||
|
invoice: true,
|
||||||
|
message: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
attemptsResult.push(attempt)
|
|
||||||
|
return {
|
||||||
|
invoice: updatedAttempt.invoice,
|
||||||
|
status: updatedAttempt.status,
|
||||||
|
message: updatedAttempt.message,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new NotFoundException(
|
||||||
|
'متاسفانه امکان ارسال فاکتور به سیستم مالیاتی در حال حاضر وجود ندارد. لطفا بعدا تلاش کنید.',
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(attemptsResult)
|
|
||||||
|
|
||||||
return attemptsResult
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {"type": "MAIN", "items": [{"sku": "2720000044726", "good_id": "01KQHY48M299C9BG2D06DMWK4E", "payload": {"karat": "18", "wages": 40000000, "profit": 48000000, "commission": 40000000}, "sku_vat": "0", "discount": "0", "quantity": 2, "service_id": null, "unit_price": 200000000, "measure_unit": "63", "total_amount": 540800000, "good_snapshot": {"good": {"id": "01KQHY48M299C9BG2D06DMWK4E", "sku": {"id": "01KQHXE2D4XEFSDK4DSV2J6GT2", "VAT": "0", "code": "2720000044726", "name": "گوشواره طلا زیورالات ساخته شده از طلا"}, "name": "گوشواره", "barcode": null, "category": {"id": "01KQHY48CF6X2TK2AG09MKDVKQ", "name": "زیورآلات"}, "image_url": null, "local_sku": null, "measure_unit": {"id": "01KQHY489HE02787SE8TWDE18S", "code": "63", "name": "گرم"}, "pricing_model": "GOLD", "base_sale_price": "0"}}, "invoice_item_id": "01KQMZTMDC4M4T7VE9GFZJEW4E"}], "payments": [{"amount": 540800000, "paid_at": "2026-05-02T18:39:46.000Z", "payment_method": "CASH"}], "fiscal_id": "A296T3", "tsp_token": "pfFE6QxOJxUIhzkpUCPWYMR5", "invoice_id": "98c3377d-4e42-4703-97f0-38c3b3c8e87f", "invoice_date": "2026-05-02T18:39:46.000Z", "total_amount": 540800000, "tsp_provider": "NAMA", "customer_type": "Unknown", "economic_code": "14003579468", "invoice_number": 13, "invoice_template": "GOLD_JEWELRY"}
|
// {"type": "ORIGINAL", "items": [{"sku": "2720000044726", "good_id": "01KQHY48M299C9BG2D06DMWK4E", "payload": {"karat": "18", "wages": 40000000, "profit": 48000000, "commission": 40000000}, "sku_vat": "0", "discount": "0", "quantity": 2, "service_id": null, "unit_price": 200000000, "measure_unit": "63", "total_amount": 540800000, "good_snapshot": {"good": {"id": "01KQHY48M299C9BG2D06DMWK4E", "sku": {"id": "01KQHXE2D4XEFSDK4DSV2J6GT2", "VAT": "0", "code": "2720000044726", "name": "گوشواره طلا زیورالات ساخته شده از طلا"}, "name": "گوشواره", "barcode": null, "category": {"id": "01KQHY48CF6X2TK2AG09MKDVKQ", "name": "زیورآلات"}, "image_url": null, "local_sku": null, "measure_unit": {"id": "01KQHY489HE02787SE8TWDE18S", "code": "63", "name": "گرم"}, "pricing_model": "GOLD", "base_sale_price": "0"}}, "invoice_item_id": "01KQMZTMDC4M4T7VE9GFZJEW4E"}], "payments": [{"amount": 540800000, "paid_at": "2026-05-02T18:39:46.000Z", "payment_method": "CASH"}], "fiscal_id": "A296T3", "tsp_token": "pfFE6QxOJxUIhzkpUCPWYMR5", "invoice_id": "98c3377d-4e42-4703-97f0-38c3b3c8e87f", "invoice_date": "2026-05-02T18:39:46.000Z", "total_amount": 540800000, "tsp_provider": "NAMA", "customer_type": "Unknown", "economic_code": "14003579468", "invoice_number": 13, "invoice_template": "GOLD_JEWELRY"}
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ import { Injectable, Logger } from '@nestjs/common'
|
|||||||
import {
|
import {
|
||||||
IProviderSwitchAdapter,
|
IProviderSwitchAdapter,
|
||||||
TspProviderBulkSendResultDto,
|
TspProviderBulkSendResultDto,
|
||||||
|
TspProviderCorrectionSendPayloadDto,
|
||||||
|
TspProviderCorrectionSendResponseDto,
|
||||||
TspProviderGetResultDto,
|
TspProviderGetResultDto,
|
||||||
|
TspProviderOriginalSendPayloadDto,
|
||||||
TspProviderRevokePayloadDto,
|
TspProviderRevokePayloadDto,
|
||||||
TspProviderRevokeResponseDto,
|
TspProviderRevokeResponseDto,
|
||||||
TspProviderSendItemResultDto,
|
TspProviderSendItemResultDto,
|
||||||
TspProviderSendPayloadDto,
|
|
||||||
} from '../../dto/provider-switch.dto'
|
} from '../../dto/provider-switch.dto'
|
||||||
import {
|
import {
|
||||||
NamaProviderGetResponseDto,
|
NamaProviderGetResponseDto,
|
||||||
@@ -73,7 +75,9 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(payload: TspProviderSendPayloadDto): Promise<TspProviderSendItemResultDto> {
|
async originalSend(
|
||||||
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): Promise<TspProviderSendItemResultDto> {
|
||||||
const mappedRequest = this.namaProviderUtils.mapToNamaRequestDto(payload)
|
const mappedRequest = this.namaProviderUtils.mapToNamaRequestDto(payload)
|
||||||
try {
|
try {
|
||||||
console.log(mappedRequest)
|
console.log(mappedRequest)
|
||||||
@@ -120,12 +124,60 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async correctionSend(
|
||||||
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
|
): Promise<TspProviderCorrectionSendResponseDto> {
|
||||||
|
const mappedRequest = this.namaProviderUtils.mapToNamaRequestDto(payload)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.httpClient.request(
|
||||||
|
this.buildSendUrl(),
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(mappedRequest),
|
||||||
|
},
|
||||||
|
this.createRequestInterceptors(payload.tsp_token),
|
||||||
|
)
|
||||||
|
const providerResponse: NamaProviderSendItemResponseDto = await response.json()
|
||||||
|
this.logger.debug('NAMA provider response', providerResponse)
|
||||||
|
|
||||||
|
const result: TspProviderSendItemResultDto = {
|
||||||
|
invoice_id: payload.invoice_id,
|
||||||
|
request_payload: mappedRequest,
|
||||||
|
hasError: !response.ok,
|
||||||
|
message: providerResponse.message,
|
||||||
|
sent_at: new Date().toISOString(),
|
||||||
|
response_payload: providerResponse,
|
||||||
|
received_at: providerResponse.tsp_update_time,
|
||||||
|
tax_id: providerResponse.tax_id,
|
||||||
|
status: this.namaProviderUtils.mapResponseStatus(
|
||||||
|
providerResponse.status as NamaProviderResponseStatus,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error('NAMA send failed', err)
|
||||||
|
const failure: TspProviderSendItemResultDto = {
|
||||||
|
invoice_id: payload.invoice_id,
|
||||||
|
request_payload: mappedRequest,
|
||||||
|
hasError: true,
|
||||||
|
message: (err as Error).message,
|
||||||
|
sent_at: new Date().toISOString(),
|
||||||
|
received_at: new Date().toISOString(),
|
||||||
|
tax_id: null,
|
||||||
|
status: TspProviderResponseStatus.NOT_SEND,
|
||||||
|
}
|
||||||
|
return failure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async sendBulk(
|
async sendBulk(
|
||||||
payloads: TspProviderSendPayloadDto[],
|
payloads: TspProviderOriginalSendPayloadDto[],
|
||||||
): Promise<TspProviderBulkSendResultDto[]> {
|
): Promise<TspProviderBulkSendResultDto[]> {
|
||||||
const result: TspProviderBulkSendResultDto[] = []
|
const result: TspProviderBulkSendResultDto[] = []
|
||||||
for (const payload of payloads) {
|
for (const payload of payloads) {
|
||||||
const itemResults = await this.send(payload)
|
const itemResults = await this.originalSend(payload)
|
||||||
result.push({
|
result.push({
|
||||||
invoice_id: payload.invoice_id,
|
invoice_id: payload.invoice_id,
|
||||||
items: [itemResults],
|
items: [itemResults],
|
||||||
|
|||||||
@@ -383,3 +383,163 @@ export class NamaProviderRevokeResponseDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
tsp_update_time: string
|
tsp_update_time: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////// Correction DTOs ///////////////
|
||||||
|
export class NamaProviderCorrectionBodyItemDto {
|
||||||
|
@ApiProperty({ required: true, description: 'شناسه کالا / خدمت' })
|
||||||
|
@IsString()
|
||||||
|
sstid: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: `نرخ مالیات بر ارزش افزوده`,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
vra: string
|
||||||
|
|
||||||
|
// @ApiProperty()
|
||||||
|
// @IsString()
|
||||||
|
// sstt: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: 'مبلغ واحد',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
fee: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: 'مبلغ تخفیف',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
dis: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: 'واحد اندازه گیری',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
mu: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: 'تعداد / مقدار',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
am: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: ' اجرت ساخت (طلا)',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
consfee: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'حق العمل',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
bros: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'سود فروشنده',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
spro: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NamaProviderCorrectionHeaderDto {
|
||||||
|
@ApiProperty({ required: true, description: 'موضوع صورتحساب' })
|
||||||
|
@IsString()
|
||||||
|
ins: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, description: 'الگوی صورتحساب' })
|
||||||
|
@IsString()
|
||||||
|
inp: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, description: 'نوع صورتحساب' })
|
||||||
|
@IsString()
|
||||||
|
inty: string
|
||||||
|
|
||||||
|
// @ApiProperty({required: true})
|
||||||
|
// @IsString()
|
||||||
|
// unique_tax_code: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, description: 'سریال صورتحساب داخلی حافظه مالیاتی' })
|
||||||
|
@IsString()
|
||||||
|
inno: string
|
||||||
|
|
||||||
|
// @ApiProperty({ required: true })
|
||||||
|
// @IsString()
|
||||||
|
// tins: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: true,
|
||||||
|
description: 'تاریخ و زمان صدور صورتحساب به صورت timestamp',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
indatim: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, description: 'نام مشتری' })
|
||||||
|
@IsString()
|
||||||
|
name: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'نوع شخصیت خریدار (در صورتیکه خریدار نوع ۲ باشه باید ۱ یا ۲ گذاشته بشه)',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
tob: string
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'آدرس' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
address?: string
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'شماره موبایل' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
mobile?: string
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: `شماره ملی / شناسه ملی / شناسه مشارکت مدنی / کد فراگیر خریدار`,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
bid: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, description: 'روش تسویه' })
|
||||||
|
@IsString()
|
||||||
|
setm: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NamaProviderCorrectionRequestDto {
|
||||||
|
@ApiProperty({ type: [NamaProviderCorrectionBodyItemDto] })
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => NamaProviderCorrectionBodyItemDto)
|
||||||
|
body: NamaProviderCorrectionBodyItemDto[]
|
||||||
|
|
||||||
|
@ApiProperty({ type: [NamaProviderPaymentInfoDto] })
|
||||||
|
@IsArray()
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@Type(() => NamaProviderPaymentInfoDto)
|
||||||
|
payment: NamaProviderPaymentInfoDto[]
|
||||||
|
|
||||||
|
@ApiProperty({ type: NamaProviderCorrectionHeaderDto })
|
||||||
|
@ValidateNested()
|
||||||
|
@Type(() => NamaProviderCorrectionHeaderDto)
|
||||||
|
header: NamaProviderCorrectionHeaderDto
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
uuid: string
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
economic_code: string
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
fiscal_id: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import {
|
|||||||
import {
|
import {
|
||||||
CustomerInfoDto,
|
CustomerInfoDto,
|
||||||
PaymentInfoDto,
|
PaymentInfoDto,
|
||||||
|
TspProviderCorrectionSendPayloadDto,
|
||||||
|
TspProviderOriginalSendPayloadDto,
|
||||||
TspProviderRevokePayloadDto,
|
TspProviderRevokePayloadDto,
|
||||||
TspProviderSendPayloadDto,
|
|
||||||
} from '../../dto/provider-switch.dto'
|
} from '../../dto/provider-switch.dto'
|
||||||
import {
|
import {
|
||||||
|
NamaProviderCorrectionRequestDto,
|
||||||
NamaProviderPaymentInfoDto,
|
NamaProviderPaymentInfoDto,
|
||||||
NamaProviderRequestDto,
|
NamaProviderRequestDto,
|
||||||
NamaProviderResponseStatus,
|
NamaProviderResponseStatus,
|
||||||
@@ -35,7 +37,9 @@ export class NamaProviderUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mapToNamaRequestDto(payload: TspProviderSendPayloadDto): NamaProviderRequestDto {
|
mapToNamaRequestDto(
|
||||||
|
payload: TspProviderOriginalSendPayloadDto,
|
||||||
|
): NamaProviderRequestDto {
|
||||||
return {
|
return {
|
||||||
uuid: payload.invoice_id,
|
uuid: payload.invoice_id,
|
||||||
economic_code: payload.economic_code,
|
economic_code: payload.economic_code,
|
||||||
@@ -66,6 +70,39 @@ export class NamaProviderUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapToNamaCorrectionDto(
|
||||||
|
payload: TspProviderCorrectionSendPayloadDto,
|
||||||
|
): NamaProviderCorrectionRequestDto {
|
||||||
|
return {
|
||||||
|
uuid: payload.invoice_id,
|
||||||
|
economic_code: payload.economic_code,
|
||||||
|
fiscal_id: payload.fiscal_id,
|
||||||
|
payment: this.mapPayments(payload.payments),
|
||||||
|
header: {
|
||||||
|
ins: this.mapTspProviderRequestType(TspProviderRequestType.CORRECTION),
|
||||||
|
inp: this.mapInvoiceTemplate(payload.invoice_template),
|
||||||
|
inty: this.mapTspProviderCustomerType(payload.customer_type),
|
||||||
|
inno: payload.invoice_number.toString(),
|
||||||
|
tins: '',
|
||||||
|
indatim: payload.invoice_date.getTime() + '',
|
||||||
|
setm: '1',
|
||||||
|
...this.mapCustomerInfo(payload.customer),
|
||||||
|
},
|
||||||
|
body: payload.items.map(item => ({
|
||||||
|
sstid: item.sku,
|
||||||
|
vra: item.sku_vat,
|
||||||
|
// sstt: item.unit_type,
|
||||||
|
fee: String(item.unit_price),
|
||||||
|
dis: String(item.discount),
|
||||||
|
mu: item.measure_unit,
|
||||||
|
am: String(item.quantity),
|
||||||
|
consfee: '0',
|
||||||
|
bros: '0',
|
||||||
|
spro: '0',
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mapRevokeToNamaRequestDto(
|
mapRevokeToNamaRequestDto(
|
||||||
payload: TspProviderRevokePayloadDto,
|
payload: TspProviderRevokePayloadDto,
|
||||||
): NamaProviderRevokeRequestDto {
|
): NamaProviderRevokeRequestDto {
|
||||||
@@ -76,7 +113,7 @@ export class NamaProviderUtils {
|
|||||||
header: {
|
header: {
|
||||||
inno: payload.invoice_number.toString(),
|
inno: payload.invoice_number.toString(),
|
||||||
ins: this.mapTspProviderRequestType(TspProviderRequestType.REVOKE),
|
ins: this.mapTspProviderRequestType(TspProviderRequestType.REVOKE),
|
||||||
irtaxid: payload.last_attempt_tax_id,
|
irtaxid: payload.last_tax_id,
|
||||||
indatim: new Date().getTime() + '',
|
indatim: new Date().getTime() + '',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -84,9 +121,9 @@ export class NamaProviderUtils {
|
|||||||
|
|
||||||
private mapTspProviderRequestType(type: TspProviderRequestType) {
|
private mapTspProviderRequestType(type: TspProviderRequestType) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TspProviderRequestType.MAIN:
|
case TspProviderRequestType.ORIGINAL:
|
||||||
return '1'
|
return '1'
|
||||||
case TspProviderRequestType.UPDATE:
|
case TspProviderRequestType.CORRECTION:
|
||||||
return '2'
|
return '2'
|
||||||
case TspProviderRequestType.REVOKE:
|
case TspProviderRequestType.REVOKE:
|
||||||
return '3'
|
return '3'
|
||||||
|
|||||||
Reference in New Issue
Block a user