feat: implement purchase receipt items management with create, update, find, and delete functionalities
feat: add purchase receipts management with create, update, find, and delete functionalities feat: implement sales invoice items management with create, update, find, and delete functionalities feat: add sales invoices management with create, update, find, and delete functionalities feat: implement stock adjustments management with create, update, find, and delete functionalities feat: add stock balance retrieval functionality feat: implement stock movements management with create, update, find, and delete functionalities
This commit is contained in:
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `createdAt` on table `Customers` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `updatedAt` on table `Customers` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `createdAt` on table `Product_Variants` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `updatedAt` on table `Product_Variants` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `createdAt` on table `Suppliers` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `updatedAt` on table `Suppliers` required. This step will fail if there are existing NULL values in that column.
|
||||
- Added the required column `updatedAt` to the `Users` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `Customers` MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
MODIFY `updatedAt` TIMESTAMP(0) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Inventories` ADD COLUMN `deletedAt` TIMESTAMP(0) NULL,
|
||||
MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Product_Variants` MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
MODIFY `updatedAt` TIMESTAMP(0) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Stores` ADD COLUMN `deletedAt` TIMESTAMP(0) NULL,
|
||||
MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Suppliers` MODIFY `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
MODIFY `updatedAt` TIMESTAMP(0) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `Users` ADD COLUMN `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
ADD COLUMN `deletedAt` TIMESTAMP(0) NULL,
|
||||
ADD COLUMN `updatedAt` TIMESTAMP(0) NOT NULL;
|
||||
|
||||
-- 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,
|
||||
|
||||
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`),
|
||||
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,
|
||||
`description` TEXT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL,
|
||||
`supplierId` INTEGER NOT NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
|
||||
UNIQUE INDEX `Purchase_Receipts_code_key`(`code`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Purchase_Receipt_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),
|
||||
`receiptId` INTEGER NOT NULL,
|
||||
`productId` INTEGER NOT NULL,
|
||||
|
||||
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,
|
||||
|
||||
UNIQUE INDEX `Sales_Invoices_code_key`(`code`),
|
||||
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,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Stock_Movements` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`type` ENUM('IN', 'OUT', 'ADJUST') NOT NULL,
|
||||
`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,
|
||||
`referenceId` VARCHAR(191) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`productId` INTEGER NOT NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `stock_balance` (
|
||||
`itemId` INTEGER NOT NULL,
|
||||
`quantity` DECIMAL(65, 30) NOT NULL,
|
||||
`totalCost` DECIMAL(65, 30) NOT NULL,
|
||||
`updatedAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
PRIMARY KEY (`itemId`)
|
||||
) 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`),
|
||||
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,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `StockMovementsView` (
|
||||
`id` INTEGER NULL,
|
||||
`type` VARCHAR(191) NULL,
|
||||
`productId` INTEGER NULL,
|
||||
`quantity` DECIMAL(65, 30) NULL,
|
||||
`fee` DECIMAL(65, 30) NULL,
|
||||
`totalCost` DECIMAL(65, 30) NULL,
|
||||
`referenceId` INTEGER NULL,
|
||||
`referenceType` VARCHAR(191) NULL,
|
||||
`createdAt` DATETIME(3) NULL
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Stock_Adjustments` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`adjustedQuantity` DECIMAL(10, 2) NOT NULL,
|
||||
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`productId` INTEGER NOT NULL,
|
||||
`inventoryId` INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `stock_movements_view` (
|
||||
`id` INTEGER NULL,
|
||||
`productId` INTEGER NULL,
|
||||
`type` VARCHAR(191) NULL,
|
||||
`quantity` DECIMAL(65, 30) NULL,
|
||||
`fee` DECIMAL(65, 30) NULL,
|
||||
`totalCost` DECIMAL(65, 30) NULL,
|
||||
`referenceId` VARCHAR(191) NULL,
|
||||
`referenceType` VARCHAR(191) NULL,
|
||||
`createdAt` DATETIME(3) NULL,
|
||||
`currentStock` DECIMAL(65, 30) NULL,
|
||||
`currentAvgCost` DECIMAL(65, 30) NULL
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Stock_View` (
|
||||
`productId` INTEGER NULL,
|
||||
`inventoryId` INTEGER NULL,
|
||||
`stock` DECIMAL(65, 30) NULL
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Total_Stock_View` (
|
||||
`productId` INTEGER NULL,
|
||||
`stock` DECIMAL(65, 30) NULL
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- 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_inventoryId_fkey` FOREIGN KEY (`inventoryId`) REFERENCES `Inventories`(`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_supplierId_fkey` FOREIGN KEY (`supplierId`) REFERENCES `Suppliers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- 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_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_Items` ADD CONSTRAINT `Purchase_Receipt_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`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_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 `Inventory_Transfers` ADD CONSTRAINT `Inventory_Transfers_fromInventoryId_fkey` FOREIGN KEY (`fromInventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Transfers` ADD CONSTRAINT `Inventory_Transfers_toInventoryId_fkey` FOREIGN KEY (`toInventoryId`) REFERENCES `Inventories`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Inventory_Transfer_Items` ADD CONSTRAINT `Inventory_Transfer_Items_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Products`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- 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 `Stock_Adjustments` ADD CONSTRAINT `Stock_Adjustments_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;
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `StockMovementsView` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `Stock_View` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `Total_Stock_View` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `stock_movements_view` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
DROP TABLE `StockMovementsView`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `Stock_View`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `Total_Stock_View`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `stock_movements_view`;
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
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 `itemId` on the `stock_balance` table. All the data in the column will be lost.
|
||||
- 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 `itemId`,
|
||||
ADD COLUMN `ProductId` INTEGER NOT NULL,
|
||||
ADD PRIMARY KEY (`ProductId`);
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `avgCost` 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 `avgCost` DECIMAL(10, 2) NOT NULL;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `avgCost` to the `stock_balance` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `stock_balance` ADD COLUMN `avgCost` DECIMAL(65, 30) NOT NULL;
|
||||
|
||||
+356
-85
@@ -1,23 +1,27 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
previewFeatures = ["views"]
|
||||
moduleFormat = "cjs"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
moduleFormat = "cjs"
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
mobileNumber String @unique @db.Char(11)
|
||||
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)
|
||||
|
||||
roleId Int
|
||||
role Role @relation("User_Role", fields: [roleId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([roleId], map: "Users_roleId_fkey")
|
||||
@@map("Users")
|
||||
}
|
||||
|
||||
@@ -29,8 +33,7 @@ model Role {
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
users User[] @relation("User_Role")
|
||||
users User[] @relation("User_Role")
|
||||
|
||||
@@map("Roles")
|
||||
}
|
||||
@@ -48,43 +51,39 @@ model ProductVariant {
|
||||
alertQuantity Decimal? @default(5.00) @db.Decimal(10, 2)
|
||||
isActive Boolean @default(true)
|
||||
isFeatured Boolean @default(false)
|
||||
createdAt DateTime? @db.Timestamp(0)
|
||||
updatedAt DateTime? @db.Timestamp(0)
|
||||
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)
|
||||
|
||||
product Product @relation("Product_Variant", fields: [productId], references: [id], onUpdate: NoAction)
|
||||
productId Int
|
||||
// is_stock_managed Boolean @default(true)
|
||||
// created_by Int?
|
||||
// collection_product collection_product[]
|
||||
// product_batches product_batches[]
|
||||
// product_stocks product_stocks[]
|
||||
// attachments attachments? @relation(fields: [attachment_id], references: [id], onUpdate: NoAction, map: "products_attachment_id_foreign")
|
||||
// purchase_items purchase_items[]
|
||||
// sale_items sale_items[]
|
||||
|
||||
@@index([productId], map: "Product_Variants_productId_fkey")
|
||||
@@map("Product_Variants")
|
||||
}
|
||||
|
||||
model Product {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
barcode String? @unique(map: "products_barcode_unique") @db.VarChar(100)
|
||||
sku String? @unique(map: "products_sku_unique") @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
// productType String? @default("simple") @db.VarChar(50)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
variants ProductVariant[] @relation("Product_Variant")
|
||||
|
||||
brand ProductBrand? @relation("Product_Brand", fields: [brandId], references: [id], onUpdate: NoAction)
|
||||
brandId Int?
|
||||
|
||||
category ProductCategory? @relation("Product_Category", fields: [categoryId], references: [id], onUpdate: NoAction)
|
||||
categoryId Int?
|
||||
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?
|
||||
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")
|
||||
|
||||
@@index([brandId], map: "Products_brandId_fkey")
|
||||
@@index([categoryId], map: "Products_categoryId_fkey")
|
||||
@@map("Products")
|
||||
}
|
||||
|
||||
@@ -96,8 +95,7 @@ model ProductBrand {
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
products Product[] @relation("Product_Brand")
|
||||
products Product[] @relation("Product_Brand")
|
||||
|
||||
@@map("Product_brands")
|
||||
}
|
||||
@@ -110,66 +108,339 @@ model ProductCategory {
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
updatedAt DateTime @updatedAt @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
|
||||
products Product[] @relation("Product_Category")
|
||||
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? @db.Timestamp(0)
|
||||
updatedAt DateTime? @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
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[]
|
||||
|
||||
@@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? @db.Timestamp(0)
|
||||
updatedAt DateTime? @db.Timestamp(0)
|
||||
deletedAt DateTime? @db.Timestamp(0)
|
||||
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")
|
||||
}
|
||||
|
||||
model Inventory {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @db.VarChar(255)
|
||||
location String? @db.VarChar(255)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @db.Timestamp(0)
|
||||
updatedAt DateTime @db.Timestamp(0)
|
||||
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)
|
||||
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")
|
||||
|
||||
@@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 @db.Timestamp(0)
|
||||
updatedAt DateTime @db.Timestamp(0)
|
||||
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)
|
||||
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 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?
|
||||
items SalesInvoiceItem[] @relation("SalesInvoice_Items")
|
||||
customer Customer? @relation("Customer_Sales_Invoices", fields: [customerId], references: [id])
|
||||
|
||||
@@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)
|
||||
inventory Inventory @relation("StockMovement_Inventory", fields: [inventoryId], references: [id])
|
||||
product Product @relation("StockMovement_Product", fields: [productId], references: [id])
|
||||
|
||||
@@index([inventoryId], map: "Stock_Movements_inventoryId_fkey")
|
||||
@@index([productId], map: "Stock_Movements_productId_fkey")
|
||||
@@map("Stock_Movements")
|
||||
}
|
||||
|
||||
model StockBalance {
|
||||
quantity Decimal
|
||||
totalCost Decimal
|
||||
updatedAt DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
ProductId Int @id
|
||||
avgCost Decimal
|
||||
|
||||
@@map("stock_balance")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
view stock_view {
|
||||
productId Int
|
||||
inventoryId Int
|
||||
stock Decimal? @db.Decimal(32, 2)
|
||||
}
|
||||
|
||||
enum OrderStatus {
|
||||
pending
|
||||
reject
|
||||
done
|
||||
}
|
||||
|
||||
enum paymentMethod {
|
||||
cash
|
||||
card
|
||||
}
|
||||
|
||||
enum MovementType {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum MovementReferenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
}
|
||||
|
||||
enum stock_cardex_type {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum stock_movements_view_type {
|
||||
IN
|
||||
OUT
|
||||
ADJUST
|
||||
}
|
||||
|
||||
enum stock_movements_view_referenceType {
|
||||
PURCHASE
|
||||
SALES
|
||||
ADJUSTMENT
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
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`))
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
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`
|
||||
@@ -0,0 +1,18 @@
|
||||
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`
|
||||
@@ -0,0 +1,18 @@
|
||||
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