feat: add DTOs and services for tax switch integration
- Created SendBulkSaleInvoicesDto for handling bulk sale invoice requests. - Implemented TaxSwitchSendPayloadDto and related DTOs for tax switch item payloads and results. - Developed SalesInvoiceTaxSwitchService to manage tax switch operations, including sending and retrieving tax information. - Added SalesInvoiceTaxService for handling sales invoice tax logic, including bulk sending and persistence of results. - Introduced NamaTaxSwitchAdapter to interact with the tax switch service, simulating external API responses. - Created SendBulkSalesInvoicesDto for POS module to handle bulk sales invoice requests.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `account_id` on the `sales_invoices` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[invoice_number,pos_id]` on the table `sales_invoices` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `fiscal_id` to the `business_activities` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `partner_token` to the `business_activities` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `consumer_account_id` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `invoice_number` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
|
||||
- Made the column `invoice_date` on table `sales_invoices` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `sales_invoices` DROP FOREIGN KEY `sales_invoices_account_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `sales_invoices_account_id_fkey` ON `sales_invoices`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `business_activities` ADD COLUMN `fiscal_id` VARCHAR(191) NOT NULL DEFAULT '',
|
||||
ADD COLUMN `partner_token` VARCHAR(191) NOT NULL DEFAULT '';
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `sales_invoice_items` ADD COLUMN `good_snapshot` JSON NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `sales_invoice_payments` MODIFY `paid_at` TIMESTAMP(0) NOT NULL,
|
||||
MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `sales_invoices` DROP COLUMN `account_id`,
|
||||
ADD COLUMN `consumer_account_id` VARCHAR(191) NOT NULL,
|
||||
ADD COLUMN `invoice_number` INTEGER NOT NULL,
|
||||
MODIFY `invoice_date` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `sale_invoice_fiscals` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`retry_count` INTEGER NOT NULL DEFAULT 0,
|
||||
`last_attempt_at` TIMESTAMP(0) NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`invoice_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `sale_invoice_fiscals_invoice_id_key`(`invoice_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `sale_invoice_fiscal_attempts` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`attempt_no` INTEGER NOT NULL,
|
||||
`status` VARCHAR(50) NOT NULL,
|
||||
`tax_id` VARCHAR(191) NULL,
|
||||
`request_payload` JSON NULL,
|
||||
`response_payload` JSON NULL,
|
||||
`error_message` TEXT NULL,
|
||||
`sent_at` TIMESTAMP(0) NULL,
|
||||
`received_at` TIMESTAMP(0) NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`fiscal_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `sale_invoice_fiscal_attempts_tax_id_key`(`tax_id`),
|
||||
INDEX `sale_invoice_fiscal_attempts_status_idx`(`status`),
|
||||
INDEX `sale_invoice_fiscal_attempts_tax_id_idx`(`tax_id`),
|
||||
UNIQUE INDEX `sale_invoice_fiscal_attempts_fiscal_id_attempt_no_key`(`fiscal_id`, `attempt_no`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `sales_invoices_invoice_number_pos_id_key` ON `sales_invoices`(`invoice_number`, `pos_id`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sale_invoice_fiscals` ADD CONSTRAINT `sale_invoice_fiscals_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sale_invoice_fiscal_attempts` ADD CONSTRAINT `sale_invoice_fiscal_attempts_fiscal_id_fkey` FOREIGN KEY (`fiscal_id`) REFERENCES `sale_invoice_fiscals`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `business_activities` ALTER COLUMN `fiscal_id` DROP DEFAULT,
|
||||
ALTER COLUMN `partner_token` DROP DEFAULT;
|
||||
@@ -77,6 +77,8 @@ model BusinessActivity {
|
||||
id String @id @default(ulid())
|
||||
economic_code String
|
||||
name String
|
||||
fiscal_id String
|
||||
partner_token String
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
@@ -87,9 +89,9 @@ model BusinessActivity {
|
||||
consumer_id String
|
||||
consumer Consumer @relation(fields: [consumer_id], references: [id])
|
||||
|
||||
license_activation LicenseActivation?
|
||||
complexes Complex[]
|
||||
permission_businesses PermissionBusiness[]
|
||||
license_activation LicenseActivation?
|
||||
goods Good[]
|
||||
customer_individuals CustomerIndividual[]
|
||||
customer_legals CustomerLegal[]
|
||||
@@ -1,10 +1,12 @@
|
||||
model SalesInvoice {
|
||||
id String @id @default(ulid())
|
||||
code String @unique @db.VarChar(100)
|
||||
total_amount Decimal @db.Decimal(15, 2)
|
||||
notes String? @db.Text
|
||||
unknown_customer Json? @db.Json
|
||||
invoice_date DateTime? @default(now()) @db.Timestamp(0)
|
||||
id String @id @default(uuid())
|
||||
code String @unique @db.VarChar(100)
|
||||
total_amount Decimal @db.Decimal(15, 2)
|
||||
invoice_number Int @db.Int()
|
||||
invoice_date DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
notes String? @db.Text
|
||||
unknown_customer Json? @db.Json
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt @db.Timestamp(0)
|
||||
@@ -12,15 +14,18 @@ model SalesInvoice {
|
||||
customer_id String?
|
||||
customer Customer? @relation(fields: [customer_id], references: [id])
|
||||
|
||||
account_id String
|
||||
consumer_account ConsumerAccount @relation(fields: [account_id], references: [id])
|
||||
consumer_account_id String
|
||||
consumer_account ConsumerAccount @relation(fields: [consumer_account_id], references: [id])
|
||||
|
||||
pos_id String
|
||||
pos Pos @relation(fields: [pos_id], references: [id])
|
||||
|
||||
fiscal SaleInvoiceFiscals?
|
||||
|
||||
items SalesInvoiceItem[]
|
||||
payments SalesInvoicePayment[]
|
||||
|
||||
@@unique([invoice_number, pos_id])
|
||||
@@map("sales_invoices")
|
||||
}
|
||||
|
||||
@@ -34,29 +39,73 @@ model SalesInvoiceItem {
|
||||
discount Decimal @default(0.00) @db.Decimal(15, 2)
|
||||
notes String? @db.Text
|
||||
|
||||
payload Json?
|
||||
good_snapshot Json?
|
||||
|
||||
invoice_id String
|
||||
good_id String?
|
||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id])
|
||||
|
||||
good_id String?
|
||||
good Good? @relation(fields: [good_id], references: [id])
|
||||
|
||||
service_id String?
|
||||
|
||||
payload Json?
|
||||
|
||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id])
|
||||
good Good? @relation(fields: [good_id], references: [id])
|
||||
service Service? @relation(fields: [service_id], references: [id])
|
||||
service Service? @relation(fields: [service_id], references: [id])
|
||||
|
||||
@@index([invoice_id, good_id])
|
||||
@@map("sales_invoice_items")
|
||||
}
|
||||
|
||||
model SaleInvoiceFiscals {
|
||||
id String @id @default(ulid())
|
||||
|
||||
retry_count Int @default(0)
|
||||
last_attempt_at DateTime? @db.Timestamp(0)
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
invoice_id String @unique
|
||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id], onDelete: Cascade)
|
||||
|
||||
attempts SaleInvoiceFiscalAttempts[]
|
||||
|
||||
@@map("sale_invoice_fiscals")
|
||||
}
|
||||
|
||||
model SaleInvoiceFiscalAttempts {
|
||||
id String @id @default(ulid())
|
||||
|
||||
attempt_no Int
|
||||
status String @db.VarChar(50)
|
||||
tax_id String? @unique @db.VarChar(191)
|
||||
|
||||
request_payload Json?
|
||||
response_payload Json?
|
||||
error_message String? @db.Text
|
||||
|
||||
sent_at DateTime? @db.Timestamp(0)
|
||||
received_at DateTime? @db.Timestamp(0)
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
fiscal_id String
|
||||
fiscal SaleInvoiceFiscals @relation(fields: [fiscal_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([fiscal_id, attempt_no])
|
||||
@@index([status])
|
||||
@@index([tax_id])
|
||||
@@map("sale_invoice_fiscal_attempts")
|
||||
}
|
||||
|
||||
model SalesInvoicePayment {
|
||||
id String @id @default(ulid())
|
||||
invoice_id String
|
||||
amount Decimal @db.Decimal(15, 2)
|
||||
payment_method PaymentMethodType
|
||||
paid_at DateTime
|
||||
created_at DateTime @default(now())
|
||||
paid_at DateTime @db.Timestamp(0)
|
||||
|
||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id])
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
invoice_id String
|
||||
invoice SalesInvoice @relation(fields: [invoice_id], references: [id])
|
||||
|
||||
@@index([invoice_id])
|
||||
@@map("sales_invoice_payments")
|
||||
|
||||
@@ -330,6 +330,8 @@ async function main() {
|
||||
data: {
|
||||
name: 'طلا فروشی',
|
||||
economic_code: '0111111111',
|
||||
fiscal_id: '0111111111',
|
||||
partner_token: 'TIS-BA-001',
|
||||
license_activation: {
|
||||
create: {
|
||||
expires_at: startOfToday,
|
||||
|
||||
Reference in New Issue
Block a user