feat: implement bank accounts, branches, and banks modules with CRUD operations
- Added BankAccountsController, BankAccountsService, and related DTOs for managing bank accounts. - Implemented BankBranchesController, BankBranchesService, and related DTOs for managing bank branches. - Created BanksController and BanksService for retrieving bank information. - Integrated Prisma for database operations across all modules. - Added response mapping for consistent API responses.
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to alter the column `quantity` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(10,2)`.
|
||||
- You are about to alter the column `totalCost` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(10,2)`.
|
||||
- You are about to alter the column `avgCost` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Decimal(10,2)`.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Balance` MODIFY `quantity` DECIMAL(10, 2) NOT NULL,
|
||||
MODIFY `totalCost` DECIMAL(10, 2) NOT NULL,
|
||||
MODIFY `avgCost` DECIMAL(10, 2) NOT NULL;
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `Stock_Balance` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
- You are about to drop the column `ProductId` on the `Stock_Balance` table. All the data in the column will be lost.
|
||||
- Added the required column `inventoryId` to the `Stock_Balance` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `productId` to the `Stock_Balance` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Balance` DROP PRIMARY KEY,
|
||||
DROP COLUMN `ProductId`,
|
||||
ADD COLUMN `inventoryId` INTEGER NOT NULL,
|
||||
ADD COLUMN `productId` INTEGER NOT NULL,
|
||||
ADD PRIMARY KEY (`productId`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Inventories` ADD COLUMN `isPointOfSale` BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Movements` MODIFY `referenceType` ENUM('PURCHASE', 'SALES', 'ADJUSTMENT', 'INVENTORY_TRANSFER') NOT NULL;
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `Stock_Balance` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
- You are about to alter the column `quantity` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(14,3)`.
|
||||
- You are about to alter the column `totalCost` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(14,2)`.
|
||||
- You are about to alter the column `avgCost` on the `Stock_Balance` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(14,2)`.
|
||||
- A unique constraint covering the columns `[productId,inventoryId]` on the table `Stock_Balance` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `id` to the `Stock_Balance` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `Stock_Balance` DROP FOREIGN KEY `Stock_Balance_inventoryId_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `Stock_Balance` DROP FOREIGN KEY `Stock_Balance_productId_fkey`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Products` ADD COLUMN `stockBalanceId` INTEGER NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Balance` DROP PRIMARY KEY,
|
||||
ADD COLUMN `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
ADD COLUMN `id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
MODIFY `quantity` DECIMAL(14, 3) NOT NULL DEFAULT 0,
|
||||
MODIFY `totalCost` DECIMAL(14, 2) NOT NULL DEFAULT 0,
|
||||
MODIFY `updatedAt` DATETIME(3) NOT NULL,
|
||||
MODIFY `avgCost` DECIMAL(14, 2) NOT NULL DEFAULT 0,
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Trigger_Logs` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`message` TEXT NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `_StockBalance_product` (
|
||||
`A` INTEGER NOT NULL,
|
||||
`B` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `_StockBalance_product_AB_unique`(`A`, `B`),
|
||||
INDEX `_StockBalance_product_B_index`(`B`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `_StockBalance_inventory` (
|
||||
`A` INTEGER NOT NULL,
|
||||
`B` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `_StockBalance_inventory_AB_unique`(`A`, `B`),
|
||||
INDEX `_StockBalance_inventory_B_index`(`B`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `Stock_Balance_productId_idx` ON `Stock_Balance`(`productId`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `Stock_Balance_productId_inventoryId_key` ON `Stock_Balance`(`productId`, `inventoryId`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_StockBalance_product` ADD CONSTRAINT `_StockBalance_product_A_fkey` FOREIGN KEY (`A`) REFERENCES `Products`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_StockBalance_product` ADD CONSTRAINT `_StockBalance_product_B_fkey` FOREIGN KEY (`B`) REFERENCES `Stock_Balance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_StockBalance_inventory` ADD CONSTRAINT `_StockBalance_inventory_A_fkey` FOREIGN KEY (`A`) REFERENCES `Inventories`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_StockBalance_inventory` ADD CONSTRAINT `_StockBalance_inventory_B_fkey` FOREIGN KEY (`B`) REFERENCES `Stock_Balance`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- RenameIndex
|
||||
ALTER TABLE `Stock_Balance` RENAME INDEX `Stock_Balance_inventoryId_fkey` TO `Stock_Balance_inventoryId_idx`;
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `name` to the `Trigger_Logs` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Balance` MODIFY `updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Trigger_Logs` ADD COLUMN `name` TEXT NOT NULL;
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `stockBalanceId` on the `Products` table. All the data in the column will be lost.
|
||||
- You are about to drop the `_StockBalance_inventory` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `_StockBalance_product` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `_StockBalance_inventory` DROP FOREIGN KEY `_StockBalance_inventory_A_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `_StockBalance_inventory` DROP FOREIGN KEY `_StockBalance_inventory_B_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `_StockBalance_product` DROP FOREIGN KEY `_StockBalance_product_A_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `_StockBalance_product` DROP FOREIGN KEY `_StockBalance_product_B_fkey`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Products` DROP COLUMN `stockBalanceId`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Movements` ADD COLUMN `supplierId` INTEGER NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `_StockBalance_inventory`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `_StockBalance_product`;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -1,8 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `remainedInStock` to the `Stock_Movements` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Movements` ADD COLUMN `remainedInStock` DECIMAL(10, 2) NOT NULL;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Movements` MODIFY `remainedInStock` DECIMAL(10, 2) NOT NULL DEFAULT 0;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Products` ADD COLUMN `salePrice` DECIMAL(10, 2) NOT NULL DEFAULT 0.00;
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[name]` on the table `Roles` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateTable
|
||||
CREATE TABLE `Otp_Codes` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`mobileNumber` VARCHAR(20) NOT NULL,
|
||||
`code` VARCHAR(10) NOT NULL,
|
||||
`used` BOOLEAN NOT NULL DEFAULT false,
|
||||
`expiresAt` TIMESTAMP(0) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
INDEX `Otp_Codes_mobileNumber_idx`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Refresh_Tokens` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`tokenHash` VARCHAR(255) NOT NULL,
|
||||
`userId` INTEGER NOT NULL,
|
||||
`revoked` BOOLEAN NOT NULL DEFAULT false,
|
||||
`expiresAt` TIMESTAMP(0) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
INDEX `Refresh_Tokens_userId_idx`(`userId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `Roles_name_key` ON `Roles`(`name`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Refresh_Tokens` ADD CONSTRAINT `Refresh_Tokens_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `Users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
+383
-201
@@ -25,6 +25,261 @@ CREATE TABLE `Roles` (
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Roles_name_key`(`name`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Otp_Codes` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`mobileNumber` VARCHAR(20) NOT NULL,
|
||||
`code` VARCHAR(10) NOT NULL,
|
||||
`used` BOOLEAN NOT NULL DEFAULT false,
|
||||
`expiresAt` TIMESTAMP(0) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
INDEX `Otp_Codes_mobileNumber_idx`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Refresh_Tokens` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`tokenHash` VARCHAR(255) NOT NULL,
|
||||
`userId` INTEGER NOT NULL,
|
||||
`revoked` BOOLEAN NOT NULL DEFAULT false,
|
||||
`expiresAt` TIMESTAMP(0) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
INDEX `Refresh_Tokens_userId_idx`(`userId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Bank_Branches` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`code` VARCHAR(10) NOT NULL,
|
||||
`address` VARCHAR(500) NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`bankId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Bank_Branches_code_key`(`code`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Bank_Accounts` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`accountNumber` VARCHAR(20) NULL,
|
||||
`cardNumber` VARCHAR(16) NULL,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`iban` VARCHAR(34) NULL,
|
||||
`branchId` INTEGER NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Bank_Accounts_accountNumber_key`(`accountNumber`),
|
||||
UNIQUE INDEX `Bank_Accounts_cardNumber_key`(`cardNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventories` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`location` VARCHAR(255) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`isPointOfSale` BOOLEAN NOT NULL DEFAULT false,
|
||||
`bankAccountId` INTEGER NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventory_Transfers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(100) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`fromInventoryId` INTEGER NOT NULL,
|
||||
`toInventoryId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Inventory_Transfers_code_key`(`code`),
|
||||
INDEX `Inventory_Transfers_fromInventoryId_fkey`(`fromInventoryId`),
|
||||
INDEX `Inventory_Transfers_toInventoryId_fkey`(`toInventoryId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventory_Transfer_Items` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`count` DECIMAL(10, 2) NOT NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
`transferId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Inventory_Transfer_Items_productId_fkey`(`productId`),
|
||||
INDEX `Inventory_Transfer_Items_transferId_fkey`(`transferId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventory_Bank_Accounts` (
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
`bankAccountId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Inventory_Bank_Accounts_bankAccountId_idx`(`bankAccountId`),
|
||||
PRIMARY KEY (`inventoryId`, `bankAccountId`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Pos_Accounts` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`code` VARCHAR(10) NOT NULL,
|
||||
`description` VARCHAR(500) NULL,
|
||||
`bankAccountId` INTEGER NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Pos_Accounts_code_key`(`code`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Banks` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`shortName` VARCHAR(3) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Banks_shortName_key`(`shortName`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Suppliers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`firstName` VARCHAR(255) NOT NULL,
|
||||
`lastName` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NULL,
|
||||
`mobileNumber` CHAR(11) NOT NULL,
|
||||
`address` TEXT NULL,
|
||||
`city` VARCHAR(100) NULL,
|
||||
`state` VARCHAR(100) NULL,
|
||||
`country` VARCHAR(100) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Suppliers_mobileNumber_key`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Supplier_Ledger` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`description` TEXT NULL,
|
||||
`debit` DECIMAL(10, 2) NOT NULL,
|
||||
`credit` DECIMAL(10, 2) NOT NULL,
|
||||
`balance` DECIMAL(10, 2) NOT NULL,
|
||||
`sourceType` ENUM('PURCHASE', 'PAYMENT', 'ADJUSTMENT', 'REFUND') NOT NULL,
|
||||
`sourceId` INTEGER NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`supplierId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Supplier_Ledger_supplierId_fkey`(`supplierId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Customers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`firstName` VARCHAR(255) NOT NULL,
|
||||
`lastName` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NULL,
|
||||
`mobileNumber` CHAR(11) NOT NULL,
|
||||
`address` TEXT NULL,
|
||||
`city` VARCHAR(100) NULL,
|
||||
`state` VARCHAR(100) NULL,
|
||||
`country` VARCHAR(100) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Customers_mobileNumber_key`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Orders` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`orderNumber` VARCHAR(100) NOT NULL,
|
||||
`status` ENUM('PENDING', 'REJECT', 'DONE') NOT NULL DEFAULT 'PENDING',
|
||||
`paymentMethod` ENUM('CASH', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL DEFAULT 'CARD',
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`customerId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Orders_orderNumber_key`(`orderNumber`),
|
||||
INDEX `Orders_customerId_fkey`(`customerId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Sales_Invoices` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(100) NOT NULL,
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`customerId` INTEGER NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Sales_Invoices_code_key`(`code`),
|
||||
INDEX `Sales_Invoices_inventoryId_fkey`(`inventoryId`),
|
||||
INDEX `Sales_Invoices_customerId_fkey`(`customerId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Sales_Invoice_Items` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`count` DECIMAL(10, 2) NOT NULL,
|
||||
`fee` DECIMAL(10, 2) NOT NULL,
|
||||
`total` DECIMAL(10, 2) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`invoiceId` INTEGER NOT NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Sales_Invoice_Items_invoiceId_fkey`(`invoiceId`),
|
||||
INDEX `Sales_Invoice_Items_productId_fkey`(`productId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Trigger_Logs` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`message` TEXT NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`name` TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -64,6 +319,7 @@ CREATE TABLE `Products` (
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`brandId` INTEGER NULL,
|
||||
`categoryId` INTEGER NULL,
|
||||
`salePrice` DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||
|
||||
UNIQUE INDEX `products_sku_unique`(`sku`),
|
||||
UNIQUE INDEX `products_barcode_unique`(`barcode`),
|
||||
@@ -98,116 +354,13 @@ CREATE TABLE `Product_categories` (
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Suppliers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`firstName` VARCHAR(255) NOT NULL,
|
||||
`lastName` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NULL,
|
||||
`mobileNumber` CHAR(11) NOT NULL,
|
||||
`address` TEXT NULL,
|
||||
`city` VARCHAR(100) NULL,
|
||||
`state` VARCHAR(100) NULL,
|
||||
`country` VARCHAR(100) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Suppliers_mobileNumber_key`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Customers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`firstName` VARCHAR(255) NOT NULL,
|
||||
`lastName` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NULL,
|
||||
`mobileNumber` CHAR(11) NOT NULL,
|
||||
`address` TEXT NULL,
|
||||
`city` VARCHAR(100) NULL,
|
||||
`state` VARCHAR(100) NULL,
|
||||
`country` VARCHAR(100) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
UNIQUE INDEX `Customers_mobileNumber_key`(`mobileNumber`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventories` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`location` VARCHAR(255) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Stores` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`location` VARCHAR(255) NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT true,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Product_Charges` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`count` DECIMAL(10, 2) NOT NULL,
|
||||
`fee` DECIMAL(10, 2) NOT NULL,
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`isSettled` BOOLEAN NOT NULL DEFAULT false,
|
||||
`buyAt` TIMESTAMP(0) NULL,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
`supplierId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Product_Charges_inventoryId_fkey`(`inventoryId`),
|
||||
INDEX `Product_Charges_productId_fkey`(`productId`),
|
||||
INDEX `Product_Charges_supplierId_fkey`(`supplierId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Orders` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`orderNumber` VARCHAR(100) NOT NULL,
|
||||
`status` ENUM('pending', 'reject', 'done') NOT NULL DEFAULT 'pending',
|
||||
`paymentMethod` ENUM('cash', 'card') NOT NULL DEFAULT 'card',
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`deletedAt` TIMESTAMP(0) NULL,
|
||||
`customerId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Orders_orderNumber_key`(`orderNumber`),
|
||||
INDEX `Orders_customerId_fkey`(`customerId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Purchase_Receipts` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(100) NOT NULL,
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`paidAmount` DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||
`isSettled` BOOLEAN NOT NULL DEFAULT false,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
@@ -237,32 +390,18 @@ CREATE TABLE `Purchase_Receipt_Items` (
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Sales_Invoices` (
|
||||
CREATE TABLE `Purchase_Receipt_Payments` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(100) NOT NULL,
|
||||
`totalAmount` DECIMAL(10, 2) NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`paymentMethod` ENUM('CASH', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL,
|
||||
`bankAccountId` INTEGER NULL,
|
||||
`description` TEXT NULL,
|
||||
`payedAt` TIMESTAMP(0) NOT NULL,
|
||||
`receiptId` INTEGER NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`customerId` INTEGER NULL,
|
||||
|
||||
UNIQUE INDEX `Sales_Invoices_code_key`(`code`),
|
||||
INDEX `Sales_Invoices_customerId_fkey`(`customerId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Sales_Invoice_Items` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`count` DECIMAL(10, 2) NOT NULL,
|
||||
`fee` DECIMAL(10, 2) NOT NULL,
|
||||
`total` DECIMAL(10, 2) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`invoiceId` INTEGER NOT NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
|
||||
INDEX `Sales_Invoice_Items_invoiceId_fkey`(`invoiceId`),
|
||||
INDEX `Sales_Invoice_Items_productId_fkey`(`productId`),
|
||||
INDEX `Purchase_Receipt_Payments_receiptId_fkey`(`receiptId`),
|
||||
INDEX `Purchase_Receipt_Payments_bankAccountId_fkey`(`bankAccountId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -273,53 +412,39 @@ CREATE TABLE `Stock_Movements` (
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`fee` DECIMAL(10, 2) NOT NULL,
|
||||
`totalCost` DECIMAL(10, 2) NOT NULL,
|
||||
`referenceType` ENUM('PURCHASE', 'SALES', 'ADJUSTMENT') NOT NULL,
|
||||
`referenceType` ENUM('PURCHASE', 'SALES', 'ADJUSTMENT', 'INVENTORY_TRANSFER') NOT NULL,
|
||||
`referenceId` VARCHAR(191) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`productId` INTEGER NOT NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
`avgCost` DECIMAL(10, 2) NOT NULL,
|
||||
`supplierId` INTEGER NULL,
|
||||
`remainedInStock` DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||
`counterInventoryId` INTEGER NULL,
|
||||
`customerId` INTEGER NULL,
|
||||
|
||||
INDEX `Stock_Movements_inventoryId_fkey`(`inventoryId`),
|
||||
INDEX `Stock_Movements_productId_fkey`(`productId`),
|
||||
INDEX `Stock_Movements_counterInventoryId_fkey`(`counterInventoryId`),
|
||||
INDEX `Stock_Movements_customerId_fkey`(`customerId`),
|
||||
INDEX `Stock_Movements_supplierId_fkey`(`supplierId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Stock_Balance` (
|
||||
`quantity` DECIMAL(65, 30) NOT NULL,
|
||||
`totalCost` DECIMAL(65, 30) NOT NULL,
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`ProductId` INTEGER NOT NULL,
|
||||
`avgCost` DECIMAL(65, 30) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`ProductId`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventory_Transfers` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`code` VARCHAR(100) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`fromInventoryId` INTEGER NOT NULL,
|
||||
`toInventoryId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Inventory_Transfers_code_key`(`code`),
|
||||
INDEX `Inventory_Transfers_fromInventoryId_fkey`(`fromInventoryId`),
|
||||
INDEX `Inventory_Transfers_toInventoryId_fkey`(`toInventoryId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Inventory_Transfer_Items` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`count` DECIMAL(10, 2) NOT NULL,
|
||||
`quantity` DECIMAL(14, 3) NOT NULL DEFAULT 0.000,
|
||||
`totalCost` DECIMAL(14, 2) NOT NULL DEFAULT 0.00,
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`avgCost` DECIMAL(14, 2) NOT NULL DEFAULT 0.00,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
`transferId` INTEGER NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
|
||||
INDEX `Inventory_Transfer_Items_productId_fkey`(`productId`),
|
||||
INDEX `Inventory_Transfer_Items_transferId_fkey`(`transferId`),
|
||||
INDEX `Stock_Balance_productId_idx`(`productId`),
|
||||
INDEX `Stock_Balance_inventoryId_idx`(`inventoryId`),
|
||||
UNIQUE INDEX `Stock_Balance_productId_inventoryId_key`(`productId`, `inventoryId`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -336,56 +461,26 @@ CREATE TABLE `Stock_Adjustments` (
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `_Bank_Accounts_inventoryId_fkey` (
|
||||
`A` INTEGER NOT NULL,
|
||||
`B` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `_Bank_Accounts_inventoryId_fkey_AB_unique`(`A`, `B`),
|
||||
INDEX `_Bank_Accounts_inventoryId_fkey_B_index`(`B`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Users` ADD CONSTRAINT `Users_roleId_fkey` FOREIGN KEY (`roleId`) REFERENCES `Roles`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Product_Variants` ADD CONSTRAINT `Product_Variants_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
ALTER TABLE `Refresh_Tokens` ADD CONSTRAINT `Refresh_Tokens_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `Users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Products` ADD CONSTRAINT `Products_brandId_fkey` FOREIGN KEY (`brandId`) REFERENCES `Product_brands`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
|
||||
ALTER TABLE `Bank_Branches` ADD CONSTRAINT `Bank_Branches_bankId_fkey` FOREIGN KEY (`bankId`) REFERENCES `Banks`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Products` ADD CONSTRAINT `Products_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Product_categories`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Product_Charges` ADD CONSTRAINT `Product_Charges_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Product_Charges` ADD CONSTRAINT `Product_Charges_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Product_Charges` ADD CONSTRAINT `Product_Charges_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Orders` ADD CONSTRAINT `Orders_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipts` ADD CONSTRAINT `Purchase_Receipts_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipts` ADD CONSTRAINT `Purchase_Receipts_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Items` ADD CONSTRAINT `Purchase_Receipt_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Items` ADD CONSTRAINT `Purchase_Receipt_Items_receiptId_fkey` FOREIGN KEY (`receiptId`) REFERENCES `Purchase_Receipts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoices` ADD CONSTRAINT `Sales_Invoices_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_invoiceId_fkey` FOREIGN KEY (`invoiceId`) REFERENCES `Sales_Invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
ALTER TABLE `Bank_Accounts` ADD CONSTRAINT `Bank_Accounts_branchId_fkey` FOREIGN KEY (`branchId`) REFERENCES `Bank_Branches`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Transfers` ADD CONSTRAINT `Inventory_Transfers_fromInventoryId_fkey` FOREIGN KEY (`fromInventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -399,8 +494,95 @@ ALTER TABLE `Inventory_Transfer_Items` ADD CONSTRAINT `Inventory_Transfer_Items_
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Transfer_Items` ADD CONSTRAINT `Inventory_Transfer_Items_transferId_fkey` FOREIGN KEY (`transferId`) REFERENCES `Inventory_Transfers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Bank_Accounts` ADD CONSTRAINT `Inventory_Bank_Accounts_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Bank_Accounts` ADD CONSTRAINT `Inventory_Bank_Accounts_bankAccountId_fkey` FOREIGN KEY (`bankAccountId`) REFERENCES `Bank_Accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Pos_Accounts` ADD CONSTRAINT `Pos_Accounts_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Pos_Accounts` ADD CONSTRAINT `Pos_Accounts_bankAccountId_inventoryId_fkey` FOREIGN KEY (`bankAccountId`, `inventoryId`) REFERENCES `Inventory_Bank_Accounts`(`bankAccountId`, `inventoryId`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Pos_Accounts` ADD CONSTRAINT `Pos_Accounts_bankAccountId_fkey` FOREIGN KEY (`bankAccountId`) REFERENCES `Bank_Accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Supplier_Ledger` ADD CONSTRAINT `Supplier_Ledger_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Orders` ADD CONSTRAINT `Orders_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoices` ADD CONSTRAINT `Sales_Invoices_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoices` ADD CONSTRAINT `Sales_Invoices_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_invoiceId_fkey` FOREIGN KEY (`invoiceId`) REFERENCES `Sales_Invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Product_Variants` ADD CONSTRAINT `Product_Variants_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Products` ADD CONSTRAINT `Products_brandId_fkey` FOREIGN KEY (`brandId`) REFERENCES `Product_brands`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Products` ADD CONSTRAINT `Products_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Product_categories`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipts` ADD CONSTRAINT `Purchase_Receipts_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipts` ADD CONSTRAINT `Purchase_Receipts_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Items` ADD CONSTRAINT `Purchase_Receipt_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Items` ADD CONSTRAINT `Purchase_Receipt_Items_receiptId_fkey` FOREIGN KEY (`receiptId`) REFERENCES `Purchase_Receipts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Payments` ADD CONSTRAINT `Purchase_Receipt_Payments_receiptId_fkey` FOREIGN KEY (`receiptId`) REFERENCES `Purchase_Receipts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Purchase_Receipt_Payments` ADD CONSTRAINT `Purchase_Receipt_Payments_bankAccountId_fkey` FOREIGN KEY (`bankAccountId`) REFERENCES `Bank_Accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_counterInventoryId_fkey` FOREIGN KEY (`counterInventoryId`) REFERENCES `Inventories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements` ADD CONSTRAINT `Stock_Movements_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Balance` ADD CONSTRAINT `Stock_Balance_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Adjustments` ADD CONSTRAINT `Stock_Adjustments_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Adjustments` ADD CONSTRAINT `Stock_Adjustments_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_Bank_Accounts_inventoryId_fkey` ADD CONSTRAINT `_Bank_Accounts_inventoryId_fkey_A_fkey` FOREIGN KEY (`A`) REFERENCES `Bank_Accounts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `_Bank_Accounts_inventoryId_fkey` ADD CONSTRAINT `_Bank_Accounts_inventoryId_fkey_B_fkey` FOREIGN KEY (`B`) REFERENCES `Inventories`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1 @@
|
||||
-- This is an empty migration.
|
||||
+27
-44
@@ -1,25 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `inventoryId` to the `Sales_Invoices` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Sales_Invoices`
|
||||
ADD COLUMN `inventoryId` INTEGER NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `Sales_Invoices_inventoryId_fkey` ON `Sales_Invoices` (`inventoryId`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Sales_Invoices`
|
||||
ADD CONSTRAINT `Sales_Invoices_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
-- AUTO-GENERATED MYSQL TRIGGER DUMP
|
||||
-- Generated at: 2025-12-22T15:32:20.184Z
|
||||
|
||||
-- ------------------------------------------
|
||||
-- Trigger: trg_transfer_item_after_insert
|
||||
-- Event: INSERT
|
||||
-- Table: Inventory_Transfer_Items
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_transfer_item_after_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_transfer_item_after_insert` AFTER
|
||||
INSERT
|
||||
ON `Inventory_Transfer_Items` FOR EACH ROW begin
|
||||
CREATE TRIGGER `trg_transfer_item_after_insert` AFTER INSERT ON `Inventory_Transfer_Items` FOR EACH ROW begin
|
||||
|
||||
DECLARE fromInv INT;
|
||||
DECLARE toInv INT;
|
||||
@@ -39,15 +28,15 @@ DECLARE fromInv INT;
|
||||
|
||||
-- OUT from source
|
||||
INSERT INTO Stock_Movements
|
||||
(type, quantity, fee, totalCost, avgCost, referenceType, referenceId, productId, inventoryId, createdAt, remainedInStock)
|
||||
(type, quantity, fee, totalCost, avgCost, referenceType, referenceId, productId, inventoryId, cuonterInventoryId, createdAt, remainedInStock)
|
||||
VALUES
|
||||
('OUT', NEW.count, _avgCost, _avgCost*NEW.count, _avgCost, 'INVENTORY_TRANSFER', NEW.transferId, NEW.productId, fromInv, NOW(), latestQuantityInOrigin-NEW.count);
|
||||
('OUT', NEW.count, _avgCost, _avgCost*NEW.count, _avgCost, 'INVENTORY_TRANSFER', NEW.transferId, NEW.productId, fromInv, toInv, NOW(), latestQuantityInOrigin-NEW.count);
|
||||
|
||||
-- IN to destination
|
||||
INSERT INTO Stock_Movements
|
||||
(type, quantity, fee, totalCost, avgCost, referenceType, referenceId, productId, inventoryId, createdAt, remainedInStock)
|
||||
(type, quantity, fee, totalCost, avgCost, referenceType, referenceId, productId, inventoryId, cuonterInventoryId, createdAt, remainedInStock)
|
||||
VALUES
|
||||
('IN', NEW.count,_avgCost, _avgCost*NEW.count,_avgCost, 'INVENTORY_TRANSFER', NEW.transferId, NEW.productId, toInv, NOW(), latestQuantityInOrigin-NEW.count);
|
||||
('IN', NEW.count,_avgCost, _avgCost*NEW.count,_avgCost, 'INVENTORY_TRANSFER', NEW.transferId, NEW.productId, toInv, fromInv, NOW(), latestQuantityInOrigin-NEW.count);
|
||||
end;
|
||||
|
||||
-- ------------------------------------------
|
||||
@@ -57,9 +46,7 @@ end;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_purchase_receipt_item_after_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_purchase_receipt_item_after_insert` AFTER
|
||||
INSERT
|
||||
ON `Purchase_Receipt_Items` FOR EACH ROW BEGIN DECLARE latestQuantity DECIMAL(10, 2) DEFAULT 0;
|
||||
CREATE TRIGGER `trg_purchase_receipt_item_after_insert` AFTER INSERT ON `Purchase_Receipt_Items` FOR EACH ROW BEGIN DECLARE latestQuantity DECIMAL(10, 2) DEFAULT 0;
|
||||
|
||||
DECLARE invId INT;
|
||||
DECLARE suppId INT;
|
||||
@@ -122,9 +109,7 @@ END;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_sales_invoice_items_before_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_sales_invoice_items_before_insert` BEFORE
|
||||
INSERT
|
||||
ON `Sales_Invoice_Items` FOR EACH ROW begin DECLARE current_stock DECIMAL(10, 2);
|
||||
CREATE TRIGGER `trg_sales_invoice_items_before_insert` BEFORE INSERT ON `Sales_Invoice_Items` FOR EACH ROW begin DECLARE current_stock DECIMAL(10, 2);
|
||||
|
||||
DECLARE inventory_id INT;
|
||||
|
||||
@@ -154,14 +139,13 @@ end;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_sales_invoice_items_after_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_sales_invoice_items_after_insert` AFTER
|
||||
INSERT
|
||||
ON `Sales_Invoice_Items` FOR EACH ROW begin DECLARE current_stock DECIMAL(10, 2);
|
||||
CREATE TRIGGER `trg_sales_invoice_items_after_insert` AFTER INSERT ON `Sales_Invoice_Items` FOR EACH ROW begin DECLARE current_stock DECIMAL(10, 2);
|
||||
|
||||
DECLARE inventory_id INT;
|
||||
DECLARE customer_id INT;
|
||||
|
||||
|
||||
SELECT inventoryId INTO inventory_id
|
||||
SELECT inventoryId , customerId INTO inventory_id, customer_id
|
||||
FROM Sales_Invoices si
|
||||
WHERE si.id = NEW.invoiceId
|
||||
LIMIT 1;
|
||||
@@ -184,6 +168,7 @@ DECLARE inventory_id INT;
|
||||
inventoryId,
|
||||
avgCost,
|
||||
remainedInStock,
|
||||
customerId,
|
||||
createdAt
|
||||
)
|
||||
VALUES (
|
||||
@@ -195,12 +180,16 @@ DECLARE inventory_id INT;
|
||||
NEW.invoiceId,
|
||||
NEW.productId,
|
||||
inventory_id,
|
||||
|
||||
CASE
|
||||
WHEN NEW.count = 0 THEN 0
|
||||
ELSE NEW.total / NEW.count
|
||||
END
|
||||
END,
|
||||
current_stock + NEW.count,
|
||||
customer_id,
|
||||
NOW()
|
||||
);
|
||||
|
||||
, current_stock + NEW.count, NOW() );
|
||||
|
||||
END;
|
||||
|
||||
@@ -211,9 +200,7 @@ END;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_stock_transfer`;
|
||||
|
||||
CREATE TRIGGER `trg_stock_transfer` AFTER
|
||||
INSERT
|
||||
ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'INVENTORY_TRANSFER' THEN IF NEW.type = 'IN' THEN
|
||||
CREATE TRIGGER `trg_stock_transfer` AFTER INSERT ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'INVENTORY_TRANSFER' THEN IF NEW.type = 'IN' THEN
|
||||
INSERT INTO
|
||||
Stock_Balance (
|
||||
productId,
|
||||
@@ -296,9 +283,7 @@ END;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_stock_purchase_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_stock_purchase_insert` AFTER
|
||||
INSERT
|
||||
ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'PURCHASE' THEN
|
||||
CREATE TRIGGER `trg_stock_purchase_insert` AFTER INSERT ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'PURCHASE' THEN
|
||||
|
||||
INSERT INTO
|
||||
Stock_Balance (
|
||||
@@ -333,9 +318,7 @@ END;
|
||||
-- ------------------------------------------
|
||||
DROP TRIGGER IF EXISTS `trg_stock_sale_insert`;
|
||||
|
||||
CREATE TRIGGER `trg_stock_sale_insert` AFTER
|
||||
INSERT
|
||||
ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'SALES' THEN
|
||||
CREATE TRIGGER `trg_stock_sale_insert` AFTER INSERT ON `Stock_Movements` FOR EACH ROW BEGIN IF NEW.referenceType = 'SALES' THEN
|
||||
|
||||
INSERT INTO
|
||||
Stock_Balance (
|
||||
@@ -1,16 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stock_Movements`
|
||||
ADD COLUMN `counterInventoryId` INTEGER NULL,
|
||||
ADD COLUMN `customerId` INTEGER NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements`
|
||||
ADD CONSTRAINT `Stock_Movements_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Stock_Movements`
|
||||
ADD CONSTRAINT `Stock_Movements_counterInventoryId_fkey` FOREIGN KEY (`counterInventoryId`) REFERENCES `Inventories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- ------------------------------------------
|
||||
-- Trigger: trg_transfer_item_after_insert
|
||||
-- Event: INSERT
|
||||
Reference in New Issue
Block a user