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
|
||||
@@ -1,522 +0,0 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
previewFeatures = ["views"]
|
||||
moduleFormat = "cjs"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
password String
|
||||
firstName String
|
||||
lastName String
|
||||
roleId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
role Role @relation("User_Role", fields: [roleId], references: [id], onUpdate: NoAction)
|
||||
refreshTokens RefreshToken[]
|
||||
|
||||
@@index([roleId], map: "Users_roleId_fkey")
|
||||
@@map("Users")
|
||||
}
|
||||
|
||||
model Role {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique() @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
permissions Json?
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
users User[] @relation("User_Role")
|
||||
|
||||
@@map("Roles")
|
||||
}
|
||||
|
||||
model ProductVariant {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
basePrice Decimal @db.Decimal(10, 2)
|
||||
salePrice Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
||||
imageUrl String? @db.VarChar(255)
|
||||
unit String? @db.VarChar(10)
|
||||
quantity Decimal? @default(0.00) @db.Decimal(10, 2)
|
||||
alertQuantity Decimal? @default(5.00) @db.Decimal(10, 2)
|
||||
isActive Boolean @default(true)
|
||||
isFeatured Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
productId Int
|
||||
product Product @relation("Product_Variant", fields: [productId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([productId], map: "Product_Variants_productId_fkey")
|
||||
@@map("Product_Variants")
|
||||
}
|
||||
|
||||
model Product {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
sku String? @unique(map: "products_sku_unique") @db.VarChar(100)
|
||||
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
brandId Int?
|
||||
categoryId Int?
|
||||
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
|
||||
productCharges ProductCharge[] @relation("Product_Charges")
|
||||
variants ProductVariant[] @relation("Product_Variant")
|
||||
brand ProductBrand? @relation("Product_Brand", fields: [brandId], references: [id], onUpdate: NoAction)
|
||||
category ProductCategory? @relation("Product_Category", fields: [categoryId], references: [id], onUpdate: NoAction)
|
||||
purchaseReceiptItems PurchaseReceiptItem[] @relation("Product_PurchaseReceiptItems")
|
||||
salesInvoiceItems SalesInvoiceItem[] @relation("Product_SalesInvoiceItems")
|
||||
stockAdjustments StockAdjustment[] @relation("Product_Stock_Adjustments")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Product")
|
||||
|
||||
stockBalances StockBalance[] @relation("StockBalance_Product")
|
||||
|
||||
@@index([brandId], map: "Products_brandId_fkey")
|
||||
@@index([categoryId], map: "Products_categoryId_fkey")
|
||||
@@map("Products")
|
||||
}
|
||||
|
||||
model ProductBrand {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
imageUrl String? @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
products Product[] @relation("Product_Brand")
|
||||
|
||||
@@map("Product_brands")
|
||||
}
|
||||
|
||||
model ProductCategory {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
imageUrl String? @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
products Product[] @relation("Product_Category")
|
||||
|
||||
@@map("Product_categories")
|
||||
}
|
||||
|
||||
model Supplier {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String @db.VarChar(255)
|
||||
lastName String @db.VarChar(255)
|
||||
email String? @db.VarChar(255)
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
address String? @db.Text
|
||||
city String? @db.VarChar(100)
|
||||
state String? @db.VarChar(100)
|
||||
country String? @db.VarChar(100)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
productCharges ProductCharge[] @relation("Supplier_Product_Charges")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
||||
|
||||
@@map("Suppliers")
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String @db.VarChar(255)
|
||||
lastName String @db.VarChar(255)
|
||||
email String? @db.VarChar(255)
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
address String? @db.Text
|
||||
city String? @db.VarChar(100)
|
||||
state String? @db.VarChar(100)
|
||||
country String? @db.VarChar(100)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
orders Order[] @relation("Customer_Orders")
|
||||
salesInvoices SalesInvoice[] @relation("Customer_Sales_Invoices")
|
||||
|
||||
@@map("Customers")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Customer")
|
||||
}
|
||||
|
||||
model Inventory {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
location String? @db.VarChar(255)
|
||||
isActive Boolean @default(true)
|
||||
isPointOfSale Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
inventoryTransfersFrom InventoryTransfer[] @relation("Inventory_From")
|
||||
inventoryTransfersTo InventoryTransfer[] @relation("Inventory_To")
|
||||
productCharges ProductCharge[] @relation("Inventory_Product_Charges")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
||||
counterStockMovements StockMovement[] @relation("StockMovement_CounterInventory")
|
||||
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
||||
salesInvoices SalesInvoice[] @relation("Inventory_SalesInvoices")
|
||||
|
||||
@@map("Inventories")
|
||||
}
|
||||
|
||||
model Store {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
location String? @db.VarChar(255)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
@@map("Stores")
|
||||
}
|
||||
|
||||
model ProductCharge {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
isSettled Boolean @default(false)
|
||||
buyAt DateTime? @db.Timestamp(0)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
supplierId Int
|
||||
inventory Inventory @relation("Inventory_Product_Charges", fields: [inventoryId], references: [id], onUpdate: NoAction)
|
||||
product Product @relation("Product_Charges", fields: [productId], references: [id], onUpdate: NoAction)
|
||||
supplier Supplier @relation("Supplier_Product_Charges", fields: [supplierId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([inventoryId], map: "Product_Charges_inventoryId_fkey")
|
||||
@@index([productId], map: "Product_Charges_productId_fkey")
|
||||
@@index([supplierId], map: "Product_Charges_supplierId_fkey")
|
||||
@@map("Product_Charges")
|
||||
}
|
||||
|
||||
model Order {
|
||||
id Int @id @default(autoincrement())
|
||||
orderNumber String @unique @db.VarChar(100)
|
||||
status OrderStatus @default(pending)
|
||||
paymentMethod paymentMethod @default(card)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
customerId Int
|
||||
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([customerId], map: "Orders_customerId_fkey")
|
||||
@@map("Orders")
|
||||
}
|
||||
|
||||
model PurchaseReceipt {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
supplierId Int
|
||||
inventoryId Int
|
||||
items PurchaseReceiptItem[] @relation("PurchaseReceipt_Items")
|
||||
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Purchase_Receipts_inventoryId_fkey")
|
||||
@@index([supplierId], map: "Purchase_Receipts_supplierId_fkey")
|
||||
@@map("Purchase_Receipts")
|
||||
}
|
||||
|
||||
model PurchaseReceiptItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
receiptId Int
|
||||
productId Int
|
||||
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
||||
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
||||
|
||||
@@index([productId], map: "Purchase_Receipt_Items_productId_fkey")
|
||||
@@index([receiptId], map: "Purchase_Receipt_Items_receiptId_fkey")
|
||||
@@map("Purchase_Receipt_Items")
|
||||
}
|
||||
|
||||
model SalesInvoice {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
customerId Int?
|
||||
inventoryId Int
|
||||
items SalesInvoiceItem[] @relation("SalesInvoice_Items")
|
||||
customer Customer? @relation("Customer_Sales_Invoices", fields: [customerId], references: [id])
|
||||
inventory Inventory @relation("Inventory_SalesInvoices", fields: [inventoryId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Sales_Invoices_inventoryId_fkey")
|
||||
@@index([customerId], map: "Sales_Invoices_customerId_fkey")
|
||||
@@map("Sales_Invoices")
|
||||
}
|
||||
|
||||
model SalesInvoiceItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
invoiceId Int
|
||||
productId Int
|
||||
invoice SalesInvoice @relation("SalesInvoice_Items", fields: [invoiceId], references: [id])
|
||||
product Product @relation("Product_SalesInvoiceItems", fields: [productId], references: [id])
|
||||
|
||||
@@index([invoiceId], map: "Sales_Invoice_Items_invoiceId_fkey")
|
||||
@@index([productId], map: "Sales_Invoice_Items_productId_fkey")
|
||||
@@map("Sales_Invoice_Items")
|
||||
}
|
||||
|
||||
model StockMovement {
|
||||
id Int @id @default(autoincrement())
|
||||
type MovementType
|
||||
quantity Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
totalCost Decimal @db.Decimal(10, 2)
|
||||
referenceType MovementReferenceType
|
||||
referenceId String
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
avgCost Decimal @db.Decimal(10, 2)
|
||||
remainedInStock Decimal @default(0) @db.Decimal(10, 2)
|
||||
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
||||
supplierId Int?
|
||||
supplier Supplier? @relation("StockMovement_Supplier", fields: [supplierId], references: [id])
|
||||
customerId Int?
|
||||
customer Customer? @relation("StockMovement_Customer", fields: [customerId], references: [id])
|
||||
counterInventoryId Int?
|
||||
counterInventory Inventory? @relation("StockMovement_CounterInventory", fields: [counterInventoryId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Movements_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Movements_productId_fkey")
|
||||
@@map("Stock_Movements")
|
||||
}
|
||||
|
||||
model StockBalance {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
productId Int
|
||||
inventoryId Int
|
||||
|
||||
quantity Decimal @default(0) @db.Decimal(14, 3)
|
||||
|
||||
avgCost Decimal @default(0) @db.Decimal(14, 2)
|
||||
totalCost Decimal @default(0) @db.Decimal(14, 2)
|
||||
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
|
||||
product Product @relation("StockBalance_Product", fields: [productId], references: [id])
|
||||
inventory Inventory @relation("StockBalance_inventory", fields: [inventoryId], references: [id])
|
||||
|
||||
@@unique([productId, inventoryId])
|
||||
@@index([productId])
|
||||
@@index([inventoryId])
|
||||
@@map("Stock_Balance")
|
||||
}
|
||||
|
||||
model OtpCode {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @db.VarChar(20)
|
||||
code String @db.VarChar(10)
|
||||
used Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@index([mobileNumber])
|
||||
@@map("Otp_Codes")
|
||||
}
|
||||
|
||||
model RefreshToken {
|
||||
id Int @id @default(autoincrement())
|
||||
tokenHash String @db.VarChar(255)
|
||||
userId Int
|
||||
revoked Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@index([userId])
|
||||
@@map("Refresh_Tokens")
|
||||
}
|
||||
|
||||
model InventoryTransfer {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
fromInventoryId Int
|
||||
toInventoryId Int
|
||||
items InventoryTransferItem[] @relation("InventoryTransfer_Items")
|
||||
fromInventory Inventory @relation("Inventory_From", fields: [fromInventoryId], references: [id])
|
||||
toInventory Inventory @relation("Inventory_To", fields: [toInventoryId], references: [id])
|
||||
|
||||
@@index([fromInventoryId], map: "Inventory_Transfers_fromInventoryId_fkey")
|
||||
@@index([toInventoryId], map: "Inventory_Transfers_toInventoryId_fkey")
|
||||
@@map("Inventory_Transfers")
|
||||
}
|
||||
|
||||
model InventoryTransferItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
productId Int
|
||||
transferId Int
|
||||
product Product @relation("InventoryTransferItem_Product", fields: [productId], references: [id])
|
||||
transfer InventoryTransfer @relation("InventoryTransfer_Items", fields: [transferId], references: [id])
|
||||
|
||||
@@index([productId], map: "Inventory_Transfer_Items_productId_fkey")
|
||||
@@index([transferId], map: "Inventory_Transfer_Items_transferId_fkey")
|
||||
@@map("Inventory_Transfer_Items")
|
||||
}
|
||||
|
||||
model StockAdjustment {
|
||||
id Int @id @default(autoincrement())
|
||||
adjustedQuantity Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
inventory Inventory @relation("Inventory_Stock_Adjustments", fields: [inventoryId], references: [id])
|
||||
product Product @relation("Product_Stock_Adjustments", fields: [productId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Adjustments_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Adjustments_productId_fkey")
|
||||
@@map("Stock_Adjustments")
|
||||
}
|
||||
|
||||
view StockMovements_View {
|
||||
id Int @default(0)
|
||||
productId Int
|
||||
type stock_movements_view_type
|
||||
quantity Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
totalCost Decimal @db.Decimal(10, 2)
|
||||
referenceId String
|
||||
referenceType stock_movements_view_referenceType
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
current_stock Decimal?
|
||||
current_avg_cost Decimal?
|
||||
|
||||
@@map("Stock_Movements_View")
|
||||
@@ignore
|
||||
}
|
||||
|
||||
view inventory_overview {
|
||||
ProductId Int
|
||||
stock_quantity Decimal
|
||||
avgCost Decimal
|
||||
totalCost Decimal
|
||||
updatedAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@map("Inventory_Overview")
|
||||
}
|
||||
|
||||
view stock_cardex {
|
||||
productId Int
|
||||
movement_id Int @default(0)
|
||||
type stock_cardex_type
|
||||
quantity Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
totalCost Decimal @db.Decimal(10, 2)
|
||||
balance_quantity Decimal?
|
||||
balance_avg_cost Decimal?
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@map("Stock_Cardex")
|
||||
}
|
||||
|
||||
view stock_view {
|
||||
productId Int
|
||||
inventoryId Int
|
||||
stock Decimal? @db.Decimal(32, 2)
|
||||
|
||||
@@map("Stock_View")
|
||||
}
|
||||
|
||||
enum OrderStatus {
|
||||
pending
|
||||
reject
|
||||
done
|
||||
}
|
||||
|
||||
enum paymentMethod {
|
||||
cash
|
||||
card
|
||||
}
|
||||
|
||||
enum MovementType {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum MovementReferenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
INVENTORY_TRANSFER
|
||||
}
|
||||
|
||||
enum stock_cardex_type {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum stock_movements_view_type {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum stock_movements_view_referenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
}
|
||||
|
||||
model TriggerLog {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.Text
|
||||
message String @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@map("Trigger_Logs")
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
password String
|
||||
firstName String
|
||||
lastName String
|
||||
roleId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
refreshTokens RefreshToken[]
|
||||
role Role @relation("User_Role", fields: [roleId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([roleId], map: "Users_roleId_fkey")
|
||||
@@map("Users")
|
||||
}
|
||||
|
||||
model Role {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
permissions Json?
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
users User[] @relation("User_Role")
|
||||
|
||||
@@map("Roles")
|
||||
}
|
||||
|
||||
model OtpCode {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @db.VarChar(20)
|
||||
code String @db.VarChar(10)
|
||||
used Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@index([mobileNumber])
|
||||
@@map("Otp_Codes")
|
||||
}
|
||||
|
||||
model RefreshToken {
|
||||
id Int @id @default(autoincrement())
|
||||
tokenHash String @db.VarChar(255)
|
||||
userId Int
|
||||
revoked Boolean @default(false)
|
||||
expiresAt DateTime @db.Timestamp(0)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@index([userId])
|
||||
@@map("Refresh_Tokens")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
model BankBranch {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
code String @unique() @db.VarChar(10)
|
||||
address String? @db.VarChar(500)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
bankId Int
|
||||
|
||||
bank Bank @relation("bank_branches", fields: [bankId], references: [id])
|
||||
bankAccounts BankAccount[] @relation("Bank_Accounts_branchId_fkey")
|
||||
|
||||
@@map("Bank_Branches")
|
||||
}
|
||||
|
||||
model BankAccount {
|
||||
id Int @id @default(autoincrement())
|
||||
accountNumber String? @unique @db.VarChar(20)
|
||||
cardNumber String? @unique @db.VarChar(16)
|
||||
name String @db.VarChar(255)
|
||||
iban String? @db.VarChar(34)
|
||||
branchId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
branch BankBranch @relation("Bank_Accounts_branchId_fkey", fields: [branchId], references: [id])
|
||||
inventories Inventory[] @relation("Bank_Accounts_inventoryId_fkey")
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
posAccounts PosAccount[]
|
||||
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_bankAccountId_fkey")
|
||||
|
||||
@@map("Bank_Accounts")
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
enum OrderStatus {
|
||||
PENDING
|
||||
REJECT
|
||||
DONE
|
||||
}
|
||||
|
||||
enum MovementType {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum MovementReferenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
INVENTORY_TRANSFER
|
||||
}
|
||||
|
||||
enum payment_method_type {
|
||||
CASH
|
||||
CARD
|
||||
BANK
|
||||
CHECK
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum ledgerSourceType {
|
||||
PURCHASE
|
||||
PAYMENT
|
||||
ADJUSTMENT
|
||||
REFUND
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
model Inventory {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
location String? @db.VarChar(255)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
isPointOfSale Boolean @default(false)
|
||||
inventoryTransfersFrom InventoryTransfer[] @relation("Inventory_From")
|
||||
inventoryTransfersTo InventoryTransfer[] @relation("Inventory_To")
|
||||
// productCharges ProductCharge[] @relation("Inventory_Product_Charges")
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
salesInvoices SalesInvoice[] @relation("Inventory_SalesInvoices")
|
||||
stockAdjustments StockAdjustment[] @relation("Inventory_Stock_Adjustments")
|
||||
stockBalances StockBalance[] @relation("StockBalance_inventory")
|
||||
counterStockMovements StockMovement[] @relation("StockMovement_CounterInventory")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Inventory")
|
||||
bankAccountId Int?
|
||||
bankAccounts BankAccount[] @relation("Bank_Accounts_inventoryId_fkey")
|
||||
posAccounts PosAccount[] @relation("Inventory_PosAccounts")
|
||||
inventoryBankAccounts InventoryBankAccount[] @relation("Inventory_Bank_Accounts_inventoryId_fkey")
|
||||
|
||||
@@map("Inventories")
|
||||
}
|
||||
|
||||
model InventoryTransfer {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
fromInventoryId Int
|
||||
toInventoryId Int
|
||||
items InventoryTransferItem[] @relation("InventoryTransfer_Items")
|
||||
fromInventory Inventory @relation("Inventory_From", fields: [fromInventoryId], references: [id])
|
||||
toInventory Inventory @relation("Inventory_To", fields: [toInventoryId], references: [id])
|
||||
|
||||
@@index([fromInventoryId], map: "Inventory_Transfers_fromInventoryId_fkey")
|
||||
@@index([toInventoryId], map: "Inventory_Transfers_toInventoryId_fkey")
|
||||
@@map("Inventory_Transfers")
|
||||
}
|
||||
|
||||
model InventoryTransferItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
productId Int
|
||||
transferId Int
|
||||
product Product @relation("InventoryTransferItem_Product", fields: [productId], references: [id])
|
||||
transfer InventoryTransfer @relation("InventoryTransfer_Items", fields: [transferId], references: [id])
|
||||
|
||||
@@index([productId], map: "Inventory_Transfer_Items_productId_fkey")
|
||||
@@index([transferId], map: "Inventory_Transfer_Items_transferId_fkey")
|
||||
@@map("Inventory_Transfer_Items")
|
||||
}
|
||||
|
||||
model InventoryBankAccount {
|
||||
inventoryId Int
|
||||
bankAccountId Int
|
||||
|
||||
inventory Inventory @relation("Inventory_Bank_Accounts_inventoryId_fkey", fields: [inventoryId], references: [id])
|
||||
bankAccount BankAccount @relation("Inventory_Bank_Accounts_bankAccountId_fkey", fields: [bankAccountId], references: [id])
|
||||
posAccounts PosAccount[] @relation("Pos_Accounts_inventoryBankAccountId_fkey")
|
||||
|
||||
@@id([inventoryId, bankAccountId])
|
||||
@@index([bankAccountId])
|
||||
@@map("Inventory_Bank_Accounts")
|
||||
}
|
||||
|
||||
model PosAccount {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
code String @unique() @db.VarChar(10)
|
||||
description String? @db.VarChar(500)
|
||||
bankAccountId Int?
|
||||
inventoryId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
inventory Inventory @relation("Inventory_PosAccounts", fields: [inventoryId], references: [id])
|
||||
inventoryBankAccount InventoryBankAccount? @relation("Pos_Accounts_inventoryBankAccountId_fkey", fields: [bankAccountId, inventoryId], references: [bankAccountId, inventoryId])
|
||||
bankAccount BankAccount? @relation(fields: [bankAccountId], references: [id])
|
||||
|
||||
@@map("Pos_Accounts")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
model Bank {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
shortName String @unique() @db.VarChar(3)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
bankBranches BankBranch[] @relation("bank_branches")
|
||||
|
||||
@@map("Banks")
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
model Supplier {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String @db.VarChar(255)
|
||||
lastName String @db.VarChar(255)
|
||||
email String? @db.VarChar(255)
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
address String? @db.Text
|
||||
city String? @db.VarChar(100)
|
||||
state String? @db.VarChar(100)
|
||||
country String? @db.VarChar(100)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
stockMovements StockMovement[] @relation("StockMovement_Supplier")
|
||||
supplierLedgers SupplierLedger[]
|
||||
|
||||
@@map("Suppliers")
|
||||
}
|
||||
|
||||
model SupplierLedger {
|
||||
id Int @id @default(autoincrement())
|
||||
description String? @db.Text
|
||||
debit Decimal @db.Decimal(10, 2)
|
||||
credit Decimal @db.Decimal(10, 2)
|
||||
balance Decimal @db.Decimal(10, 2)
|
||||
sourceType ledgerSourceType
|
||||
sourceId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
supplierId Int
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id])
|
||||
|
||||
@@index([supplierId], map: "Supplier_Ledger_supplierId_fkey")
|
||||
@@map("Supplier_Ledger")
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id Int @id @default(autoincrement())
|
||||
firstName String @db.VarChar(255)
|
||||
lastName String @db.VarChar(255)
|
||||
email String? @db.VarChar(255)
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
address String? @db.Text
|
||||
city String? @db.VarChar(100)
|
||||
state String? @db.VarChar(100)
|
||||
country String? @db.VarChar(100)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
orders Order[] @relation("Customer_Orders")
|
||||
salesInvoices SalesInvoice[] @relation("Customer_Sales_Invoices")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Customer")
|
||||
|
||||
@@map("Customers")
|
||||
}
|
||||
|
||||
model Order {
|
||||
id Int @id @default(autoincrement())
|
||||
orderNumber String @unique @db.VarChar(100)
|
||||
status OrderStatus @default(PENDING)
|
||||
paymentMethod payment_method_type @default(CARD)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
customerId Int
|
||||
customer Customer @relation("Customer_Orders", fields: [customerId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([customerId], map: "Orders_customerId_fkey")
|
||||
@@map("Orders")
|
||||
}
|
||||
|
||||
model SalesInvoice {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
customerId Int?
|
||||
inventoryId Int
|
||||
items SalesInvoiceItem[] @relation("SalesInvoice_Items")
|
||||
customer Customer? @relation("Customer_Sales_Invoices", fields: [customerId], references: [id])
|
||||
inventory Inventory @relation("Inventory_SalesInvoices", fields: [inventoryId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Sales_Invoices_inventoryId_fkey")
|
||||
@@index([customerId], map: "Sales_Invoices_customerId_fkey")
|
||||
@@map("Sales_Invoices")
|
||||
}
|
||||
|
||||
model SalesInvoiceItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
invoiceId Int
|
||||
productId Int
|
||||
invoice SalesInvoice @relation("SalesInvoice_Items", fields: [invoiceId], references: [id])
|
||||
product Product @relation("Product_SalesInvoiceItems", fields: [productId], references: [id])
|
||||
|
||||
@@index([invoiceId], map: "Sales_Invoice_Items_invoiceId_fkey")
|
||||
@@index([productId], map: "Sales_Invoice_Items_productId_fkey")
|
||||
@@map("Sales_Invoice_Items")
|
||||
}
|
||||
|
||||
model TriggerLog {
|
||||
id Int @id @default(autoincrement())
|
||||
message String @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
name String @db.Text
|
||||
|
||||
@@map("Trigger_Logs")
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
model ProductVariant {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
basePrice Decimal @db.Decimal(10, 2)
|
||||
salePrice Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
||||
imageUrl String? @db.VarChar(255)
|
||||
unit String? @db.VarChar(10)
|
||||
quantity Decimal? @default(0.00) @db.Decimal(10, 2)
|
||||
alertQuantity Decimal? @default(5.00) @db.Decimal(10, 2)
|
||||
isActive Boolean @default(true)
|
||||
isFeatured Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
productId Int
|
||||
product Product @relation("Product_Variant", fields: [productId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([productId], map: "Product_Variants_productId_fkey")
|
||||
@@map("Product_Variants")
|
||||
}
|
||||
|
||||
model Product {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
sku String? @unique(map: "products_sku_unique") @db.VarChar(100)
|
||||
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
brandId Int?
|
||||
categoryId Int?
|
||||
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
|
||||
// productCharges ProductCharge[] @relation("Product_Charges")
|
||||
variants ProductVariant[] @relation("Product_Variant")
|
||||
brand ProductBrand? @relation("Product_Brand", fields: [brandId], references: [id], onUpdate: NoAction)
|
||||
category ProductCategory? @relation("Product_Category", fields: [categoryId], references: [id], onUpdate: NoAction)
|
||||
purchaseReceiptItems PurchaseReceiptItem[] @relation("Product_PurchaseReceiptItems")
|
||||
salesInvoiceItems SalesInvoiceItem[] @relation("Product_SalesInvoiceItems")
|
||||
stockAdjustments StockAdjustment[] @relation("Product_Stock_Adjustments")
|
||||
stockBalances StockBalance[] @relation("StockBalance_Product")
|
||||
stockMovements StockMovement[] @relation("StockMovement_Product")
|
||||
|
||||
@@index([brandId], map: "Products_brandId_fkey")
|
||||
@@index([categoryId], map: "Products_categoryId_fkey")
|
||||
@@map("Products")
|
||||
}
|
||||
|
||||
model ProductBrand {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
imageUrl String? @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
products Product[] @relation("Product_Brand")
|
||||
|
||||
@@map("Product_brands")
|
||||
}
|
||||
|
||||
model ProductCategory {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
imageUrl String? @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
products Product[] @relation("Product_Category")
|
||||
|
||||
@@map("Product_categories")
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
model PurchaseReceipt {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique @db.VarChar(100)
|
||||
totalAmount Decimal @db.Decimal(10, 2)
|
||||
paidAmount Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
isSettled Boolean @default(false)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
supplierId Int
|
||||
inventoryId Int
|
||||
items PurchaseReceiptItem[] @relation("PurchaseReceipt_Items")
|
||||
inventory Inventory @relation(fields: [inventoryId], references: [id])
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id])
|
||||
purchaseReceiptPayments PurchaseReceiptPayments[]
|
||||
|
||||
@@index([inventoryId], map: "Purchase_Receipts_inventoryId_fkey")
|
||||
@@index([supplierId], map: "Purchase_Receipts_supplierId_fkey")
|
||||
@@map("Purchase_Receipts")
|
||||
}
|
||||
|
||||
model PurchaseReceiptItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
receiptId Int
|
||||
productId Int
|
||||
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
||||
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
||||
|
||||
@@index([productId], map: "Purchase_Receipt_Items_productId_fkey")
|
||||
@@index([receiptId], map: "Purchase_Receipt_Items_receiptId_fkey")
|
||||
@@map("Purchase_Receipt_Items")
|
||||
}
|
||||
|
||||
model PurchaseReceiptPayments {
|
||||
id Int @id @default(autoincrement())
|
||||
amount Decimal @db.Decimal(10, 2)
|
||||
paymentMethod payment_method_type
|
||||
bankAccountId Int?
|
||||
description String? @db.Text
|
||||
payedAt DateTime @db.Timestamp(0)
|
||||
receiptId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
purchaseReceipt PurchaseReceipt @relation(fields: [receiptId], references: [id])
|
||||
bankAccount BankAccount? @relation(fields: [bankAccountId], references: [id])
|
||||
|
||||
@@index([receiptId], map: "Purchase_Receipt_Payments_receiptId_fkey")
|
||||
@@index([bankAccountId], map: "Purchase_Receipt_Payments_bankAccountId_fkey")
|
||||
@@map("Purchase_Receipt_Payments")
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../../src/generated/prisma"
|
||||
moduleFormat = "cjs"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
model StockMovement {
|
||||
id Int @id @default(autoincrement())
|
||||
type MovementType
|
||||
quantity Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
totalCost Decimal @db.Decimal(10, 2)
|
||||
referenceType MovementReferenceType
|
||||
referenceId String
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
avgCost Decimal @db.Decimal(10, 2)
|
||||
supplierId Int?
|
||||
remainedInStock Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
counterInventoryId Int?
|
||||
customerId Int?
|
||||
counterInventory Inventory? @relation("StockMovement_CounterInventory", fields: [counterInventoryId], references: [id])
|
||||
customer Customer? @relation("StockMovement_Customer", fields: [customerId], references: [id])
|
||||
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
||||
supplier Supplier? @relation("StockMovement_Supplier", fields: [supplierId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Movements_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Movements_productId_fkey")
|
||||
@@index([counterInventoryId], map: "Stock_Movements_counterInventoryId_fkey")
|
||||
@@index([customerId], map: "Stock_Movements_customerId_fkey")
|
||||
@@index([supplierId], map: "Stock_Movements_supplierId_fkey")
|
||||
@@map("Stock_Movements")
|
||||
}
|
||||
|
||||
model StockBalance {
|
||||
quantity Decimal @default(0.000) @db.Decimal(14, 3)
|
||||
totalCost Decimal @default(0.00) @db.Decimal(14, 2)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
avgCost Decimal @default(0.00) @db.Decimal(14, 2)
|
||||
inventoryId Int
|
||||
productId Int
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
id Int @id @default(autoincrement())
|
||||
inventory Inventory @relation("StockBalance_inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockBalance_Product", fields: [productId], references: [id])
|
||||
|
||||
@@unique([productId, inventoryId])
|
||||
@@index([productId])
|
||||
@@index([inventoryId])
|
||||
@@map("Stock_Balance")
|
||||
}
|
||||
|
||||
model StockAdjustment {
|
||||
id Int @id @default(autoincrement())
|
||||
adjustedQuantity Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
productId Int
|
||||
inventoryId Int
|
||||
inventory Inventory @relation("Inventory_Stock_Adjustments", fields: [inventoryId], references: [id])
|
||||
product Product @relation("Product_Stock_Adjustments", fields: [productId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Adjustments_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Adjustments_productId_fkey")
|
||||
@@map("Stock_Adjustments")
|
||||
}
|
||||
+295
-102
@@ -1,111 +1,304 @@
|
||||
import { prisma } from '../src/lib/prisma'
|
||||
import { PurchaseReceiptsService } from '../src/purchase-receipts/purchase-receipts.service'
|
||||
|
||||
async function main() {
|
||||
if ((await prisma.role.count()) === 0) {
|
||||
await prisma.role.upsert({
|
||||
where: { id: 0, name: 'Admin' },
|
||||
update: {},
|
||||
create: {
|
||||
name: 'Admin',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.user.count()) === 0) {
|
||||
const adminRole = await prisma.role.findUnique({ where: { name: 'Admin' } })
|
||||
if (!adminRole) {
|
||||
return
|
||||
}
|
||||
await prisma.user.upsert({
|
||||
where: { id: 1, firstName: 'عباس', lastName: 'حسنی' },
|
||||
update: {},
|
||||
create: {
|
||||
firstName: 'عباس',
|
||||
lastName: 'حسنی',
|
||||
roleId: adminRole.id,
|
||||
mobileNumber: '09120258156',
|
||||
password: '12345678',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.inventory.count()) === 0) {
|
||||
await prisma.inventory.createMany({
|
||||
data: [
|
||||
{ name: 'انبار مرکزی', location: 'تهران', isPointOfSale: false, isActive: true },
|
||||
{
|
||||
name: 'فروشگاه حضوری',
|
||||
location: 'مرکز شهر',
|
||||
isPointOfSale: true,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: 'فروشگاه اینترنتی',
|
||||
location: 'مرکز شهر',
|
||||
isPointOfSale: true,
|
||||
isActive: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.productCategory.count()) === 0) {
|
||||
await prisma.productCategory.createMany({
|
||||
data: Array.from({ length: 10 }, (_, i) => ({ name: `دستهی ${i + 1}` })),
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.productBrand.count()) === 0) {
|
||||
await prisma.productBrand.createMany({
|
||||
data: Array.from({ length: 10 }, (_, i) => ({ name: `برند ${i + 1}` })),
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.supplier.count()) === 0) {
|
||||
await prisma.supplier.createMany({
|
||||
data: Array.from({ length: 9 }, (_, i) => ({
|
||||
firstName: 'تامین',
|
||||
lastName: `کننده ${i + 1}`,
|
||||
mobileNumber: `0912000000${i + 1}`,
|
||||
email: `supplier${i + 1}@example.com`,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.customer.count()) === 0) {
|
||||
await prisma.customer.createMany({
|
||||
data: Array.from({ length: 5 }, (_, i) => ({
|
||||
firstName: 'مشتری',
|
||||
lastName: `${i + 1}`,
|
||||
mobileNumber: `0913000000${i + 1}`,
|
||||
email: `customer${i + 1}@example.com`,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
if ((await prisma.product.count()) === 0) {
|
||||
const categories = await prisma.productCategory.findMany()
|
||||
const brands = await prisma.productBrand.findMany()
|
||||
await prisma.product.createMany({
|
||||
data: Array.from({ length: 100 }, (_, i) => ({
|
||||
name: `کالای ${i + 1}`,
|
||||
sku: `SKU-${1000 + i + 1}`,
|
||||
salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
|
||||
categoryId: categories[i % categories.length].id,
|
||||
brandId: brands[i % brands.length].id,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
// const products = await prisma.product.findMany()
|
||||
// for (const product of products) {
|
||||
// await prisma.product.update({
|
||||
// where: { id: product.id },
|
||||
// data: {
|
||||
// salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
|
||||
// if ((await prisma.role.count()) === 0) {
|
||||
// await prisma.role.upsert({
|
||||
// where: { id: 0, name: 'Admin' },
|
||||
// update: {},
|
||||
// create: {
|
||||
// name: 'Admin',
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.user.count()) === 0) {
|
||||
// const adminRole = await prisma.role.findUnique({ where: { name: 'Admin' } })
|
||||
// if (!adminRole) {
|
||||
// return
|
||||
// }
|
||||
// await prisma.user.upsert({
|
||||
// where: { id: 1, firstName: 'عباس', lastName: 'حسنی' },
|
||||
// update: {},
|
||||
// create: {
|
||||
// firstName: 'عباس',
|
||||
// lastName: 'حسنی',
|
||||
// roleId: adminRole.id,
|
||||
// mobileNumber: '09120258156',
|
||||
// password: '12345678',
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.inventory.count()) === 0) {
|
||||
// await prisma.inventory.createMany({
|
||||
// data: [
|
||||
// { name: 'انبار مرکزی', location: 'تهران', isPointOfSale: false, isActive: true },
|
||||
// {
|
||||
// name: 'فروشگاه حضوری',
|
||||
// location: 'مرکز شهر',
|
||||
// isPointOfSale: true,
|
||||
// isActive: true,
|
||||
// },
|
||||
// {
|
||||
// name: 'فروشگاه اینترنتی',
|
||||
// location: 'مرکز شهر',
|
||||
// isPointOfSale: true,
|
||||
// isActive: true,
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.productCategory.count()) === 0) {
|
||||
// await prisma.productCategory.createMany({
|
||||
// data: Array.from({ length: 10 }, (_, i) => ({ name: `دستهی ${i + 1}` })),
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.productBrand.count()) === 0) {
|
||||
// await prisma.productBrand.createMany({
|
||||
// data: Array.from({ length: 10 }, (_, i) => ({ name: `برند ${i + 1}` })),
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.supplier.count()) === 0) {
|
||||
// await prisma.supplier.createMany({
|
||||
// data: Array.from({ length: 9 }, (_, i) => ({
|
||||
// firstName: 'تامین',
|
||||
// lastName: `کننده ${i + 1}`,
|
||||
// mobileNumber: `0912000000${i + 1}`,
|
||||
// email: `supplier${i + 1}@example.com`,
|
||||
// })),
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.customer.count()) === 0) {
|
||||
// await prisma.customer.createMany({
|
||||
// data: Array.from({ length: 5 }, (_, i) => ({
|
||||
// firstName: 'مشتری',
|
||||
// lastName: `${i + 1}`,
|
||||
// mobileNumber: `0913000000${i + 1}`,
|
||||
// email: `customer${i + 1}@example.com`,
|
||||
// })),
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.product.count()) === 0) {
|
||||
// const categories = await prisma.productCategory.findMany()
|
||||
// const brands = await prisma.productBrand.findMany()
|
||||
// await prisma.product.createMany({
|
||||
// data: Array.from({ length: 100 }, (_, i) => ({
|
||||
// name: `کالای ${i + 1}`,
|
||||
// sku: `SKU-${1000 + i + 1}`,
|
||||
// salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
|
||||
// categoryId: categories[i % categories.length].id,
|
||||
// brandId: brands[i % brands.length].id,
|
||||
// })),
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.bank.count()) === 0) {
|
||||
// await prisma.bank.createMany({
|
||||
// data: [
|
||||
// {
|
||||
// name: 'آینده',
|
||||
// shortName: 'ain',
|
||||
// },
|
||||
// {
|
||||
// name: 'ایران زمین',
|
||||
// shortName: 'irz',
|
||||
// },
|
||||
// {
|
||||
// name: 'اقتصاد نوین',
|
||||
// shortName: 'eqn',
|
||||
// },
|
||||
// {
|
||||
// name: 'انصار',
|
||||
// shortName: 'ans',
|
||||
// },
|
||||
// {
|
||||
// name: 'پاسارگاد',
|
||||
// shortName: 'pas',
|
||||
// },
|
||||
// {
|
||||
// name: 'پارسیان',
|
||||
// shortName: 'prs',
|
||||
// },
|
||||
// {
|
||||
// name: 'پست بانک ایران',
|
||||
// shortName: 'pbi',
|
||||
// },
|
||||
// {
|
||||
// name: 'تجارت',
|
||||
// shortName: 'tej',
|
||||
// },
|
||||
// {
|
||||
// name: 'توسعه تعاون',
|
||||
// shortName: 'tav',
|
||||
// },
|
||||
// {
|
||||
// name: 'توسعه صادرات',
|
||||
// shortName: 'tes',
|
||||
// },
|
||||
// {
|
||||
// name: 'حکمت ایرانیان',
|
||||
// shortName: 'hek',
|
||||
// },
|
||||
// {
|
||||
// name: 'رفاه کارگران',
|
||||
// shortName: 'ref',
|
||||
// },
|
||||
// {
|
||||
// name: 'قرضالحسنه رسالت',
|
||||
// shortName: 'res',
|
||||
// },
|
||||
// {
|
||||
// name: 'قرضالحسنه مهر ایران',
|
||||
// shortName: 'meh',
|
||||
// },
|
||||
// {
|
||||
// name: 'قوامین',
|
||||
// shortName: 'qva',
|
||||
// },
|
||||
// {
|
||||
// name: 'کشاورزی',
|
||||
// shortName: 'kes',
|
||||
// },
|
||||
// {
|
||||
// name: 'کوثر',
|
||||
// shortName: 'kos',
|
||||
// },
|
||||
// {
|
||||
// name: 'دی',
|
||||
// shortName: 'diy',
|
||||
// },
|
||||
// {
|
||||
// name: 'صنعت و معدن',
|
||||
// shortName: 'san',
|
||||
// },
|
||||
// {
|
||||
// name: 'سینا',
|
||||
// shortName: 'sin',
|
||||
// },
|
||||
// {
|
||||
// name: 'سرمایه',
|
||||
// shortName: 'sar',
|
||||
// },
|
||||
// {
|
||||
// name: 'سپه',
|
||||
// shortName: 'sep',
|
||||
// },
|
||||
// {
|
||||
// name: 'شهر',
|
||||
// shortName: 'shr',
|
||||
// },
|
||||
// {
|
||||
// name: 'صادرات ایران',
|
||||
// shortName: 'sir',
|
||||
// },
|
||||
// {
|
||||
// name: 'سامان',
|
||||
// shortName: 'sam',
|
||||
// },
|
||||
// {
|
||||
// name: 'مرکزی',
|
||||
// shortName: 'mar',
|
||||
// },
|
||||
// {
|
||||
// name: 'مسکن',
|
||||
// shortName: 'mas',
|
||||
// },
|
||||
// {
|
||||
// name: 'ملت',
|
||||
// shortName: 'mel',
|
||||
// },
|
||||
// {
|
||||
// name: 'ملی ایران',
|
||||
// shortName: 'mli',
|
||||
// },
|
||||
// {
|
||||
// name: 'مهر اقتصاد',
|
||||
// shortName: 'meg',
|
||||
// },
|
||||
// {
|
||||
// name: 'کارآفرین',
|
||||
// shortName: 'kar',
|
||||
// },
|
||||
// {
|
||||
// name: 'تات',
|
||||
// shortName: 'tat',
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.bankBranch.count()) === 0) {
|
||||
// await prisma.bankBranch.createMany({
|
||||
// data: [
|
||||
// {
|
||||
// bankId: 1,
|
||||
// name: 'شعبه مرکزی',
|
||||
// code: '001',
|
||||
// },
|
||||
// {
|
||||
// bankId: 2,
|
||||
// name: 'شعبه مرکزی',
|
||||
// code: '002',
|
||||
// },
|
||||
// {
|
||||
// bankId: 1,
|
||||
// name: 'شعبه ونک',
|
||||
// code: '003',
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// }
|
||||
|
||||
// if ((await prisma.bankAccount.count()) === 0) {
|
||||
// await prisma.bankAccount.createMany({
|
||||
// data: [
|
||||
// {
|
||||
// branchId: 4,
|
||||
// accountNumber: '1234567890',
|
||||
// name: 'حساب اصلی آینده',
|
||||
// iban: 'IR000123456789012345678901',
|
||||
// },
|
||||
// {
|
||||
// branchId: 5,
|
||||
// accountNumber: '0987654321',
|
||||
// name: 'حساب اصلی ایران زمین',
|
||||
// iban: 'IR000987654321098765432109',
|
||||
// },
|
||||
// {
|
||||
// branchId: 6,
|
||||
// accountNumber: '1122334455',
|
||||
// name: 'حساب ونک آینده',
|
||||
// iban: 'IR000112233445566778899001',
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// }
|
||||
// // Seed purchase, transfer, and sales transactions
|
||||
const inventories = await prisma.inventory.findMany()
|
||||
const products = await prisma.product.findMany({ take: 5 }) // select 5 products for demo
|
||||
const supplier = await prisma.supplier.findFirst()
|
||||
const customers = await prisma.customer.findMany({ take: 2 })
|
||||
if (supplier && customers.length > 0) {
|
||||
PurchaseReceiptsService.prototype.create({
|
||||
code: '123123',
|
||||
inventoryId: inventories[0].id,
|
||||
supplierId: supplier.id,
|
||||
paidAmount: 0,
|
||||
totalAmount: products.reduce((acc, a) => (acc += Number(a.salePrice) * 10), 0),
|
||||
items: products.map(product => ({
|
||||
productId: product.id,
|
||||
count: 10,
|
||||
fee: Number(product.salePrice),
|
||||
total: 10 * Number(product.salePrice),
|
||||
})),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Auto-generated trigger dump
|
||||
DELIMITER 8488
|
||||
-- Trigger: 1
|
||||
8488
|
||||
DELIMITER ;
|
||||
@@ -1,17 +0,0 @@
|
||||
SELECT
|
||||
`sm`.`id` AS `id`,
|
||||
`sm`.`productId` AS `productId`,
|
||||
`sm`.`type` AS `type`,
|
||||
`sm`.`quantity` AS `quantity`,
|
||||
`sm`.`fee` AS `fee`,
|
||||
`sm`.`totalCost` AS `totalCost`,
|
||||
`sm`.`referenceId` AS `referenceId`,
|
||||
`sm`.`referenceType` AS `referenceType`,
|
||||
`sm`.`createdAt` AS `createdAt`,
|
||||
`sb`.`quantity` AS `current_stock`,
|
||||
`sb`.`avgCost` AS `current_avg_cost`
|
||||
FROM
|
||||
(
|
||||
`pos`.`Stock_Movements` `sm`
|
||||
LEFT JOIN `pos`.`stock_balance` `sb` ON((`sb`.`ProductId` = `sm`.`productId`))
|
||||
)
|
||||
@@ -1,8 +0,0 @@
|
||||
SELECT
|
||||
`pos`.`stock_balance`.`ProductId` AS `ProductId`,
|
||||
`pos`.`stock_balance`.`quantity` AS `stock_quantity`,
|
||||
`pos`.`stock_balance`.`avgCost` AS `avgCost`,
|
||||
`pos`.`stock_balance`.`totalCost` AS `totalCost`,
|
||||
`pos`.`stock_balance`.`updatedAt` AS `updatedAt`
|
||||
FROM
|
||||
`pos`.`stock_balance`
|
||||
@@ -1,18 +0,0 @@
|
||||
SELECT
|
||||
`sm`.`productId` AS `productId`,
|
||||
`sm`.`id` AS `movement_id`,
|
||||
`sm`.`type` AS `type`,
|
||||
`sm`.`quantity` AS `quantity`,
|
||||
`sm`.`fee` AS `fee`,
|
||||
`sm`.`totalCost` AS `totalCost`,
|
||||
`sb`.`quantity` AS `balance_quantity`,
|
||||
`sb`.`avgCost` AS `balance_avg_cost`,
|
||||
`sm`.`createdAt` AS `createdAt`
|
||||
FROM
|
||||
(
|
||||
`pos`.`Stock_Movements` `sm`
|
||||
LEFT JOIN `pos`.`stock_balance` `sb` ON((`sb`.`ProductId` = `sm`.`productId`))
|
||||
)
|
||||
ORDER BY
|
||||
`sm`.`productId`,
|
||||
`sm`.`createdAt`
|
||||
@@ -1,18 +0,0 @@
|
||||
SELECT
|
||||
`pos`.`Stock_Movements`.`productId` AS `productId`,
|
||||
`pos`.`Stock_Movements`.`inventoryId` AS `inventoryId`,
|
||||
sum(
|
||||
(
|
||||
CASE
|
||||
WHEN (`pos`.`Stock_Movements`.`type` = 'IN') THEN `pos`.`Stock_Movements`.`quantity`
|
||||
WHEN (`pos`.`Stock_Movements`.`type` = 'OUT') THEN -(`pos`.`Stock_Movements`.`quantity`)
|
||||
WHEN (`pos`.`Stock_Movements`.`type` = 'ADJUST') THEN `pos`.`Stock_Movements`.`quantity`
|
||||
ELSE 0
|
||||
END
|
||||
)
|
||||
) AS `stock`
|
||||
FROM
|
||||
`pos`.`Stock_Movements`
|
||||
GROUP BY
|
||||
`pos`.`Stock_Movements`.`productId`,
|
||||
`pos`.`Stock_Movements`.`inventoryId`
|
||||
Reference in New Issue
Block a user