/*
Warnings:

- You are about to alter the column `count` on the `Inventory_Transfer_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `totalAmount` on the `Orders` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `basePrice` on the `Product_Variants` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `salePrice` on the `Product_Variants` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `quantity` on the `Product_Variants` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `alertQuantity` on the `Product_Variants` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `salePrice` on the `Products` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,0)`.
- You are about to alter the column `count` on the `Purchase_Receipt_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `fee` on the `Purchase_Receipt_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `total` on the `Purchase_Receipt_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `amount` on the `Purchase_Receipt_Payments` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to drop the column `isSettled` on the `Purchase_Receipts` table. All the data in the column will be lost.
- You are about to alter the column `totalAmount` on the `Purchase_Receipts` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `paidAmount` on the `Purchase_Receipts` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `count` on the `Sales_Invoice_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `fee` on the `Sales_Invoice_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `total` on the `Sales_Invoice_Items` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `totalAmount` on the `Sales_Invoices` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `adjustedQuantity` on the `Stock_Adjustments` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `quantity` on the `Stock_Movements` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `fee` on the `Stock_Movements` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `totalCost` on the `Stock_Movements` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `avgCost` on the `Stock_Movements` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `remainedInStock` on the `Stock_Movements` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(10,0)`.
- You are about to alter the column `debit` on the `Supplier_Ledger` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `credit` on the `Supplier_Ledger` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- You are about to alter the column `balance` on the `Supplier_Ledger` table. The data in that column could be lost. The data in that column will be cast from `Decimal(10,2)` to `Decimal(15,2)`.
- A unique constraint covering the columns `[iban]` on the table `Bank_Accounts` will be added. If there are existing duplicate values, this will fail.
- Made the column `bankAccountId` on table `Pos_Accounts` required. This step will fail if there are existing NULL values in that column.
- Added the required column `inventoryId` to the `Purchase_Receipt_Payments` table without a default value. This is not possible if the table is not empty.
- Added the required column `type` to the `Purchase_Receipt_Payments` table without a default value. This is not possible if the table is not empty.
- Made the column `bankAccountId` on table `Purchase_Receipt_Payments` required. This step will fail if there are existing NULL values in that column.

*/
-- DropForeignKey
ALTER TABLE `Pos_Accounts`
DROP FOREIGN KEY `Pos_Accounts_bankAccountId_fkey`;

-- DropForeignKey
ALTER TABLE `Pos_Accounts`
DROP FOREIGN KEY `Pos_Accounts_bankAccountId_inventoryId_fkey`;

-- DropForeignKey
ALTER TABLE `Pos_Accounts`
DROP FOREIGN KEY `Pos_Accounts_inventoryId_fkey`;

-- DropForeignKey
ALTER TABLE `Purchase_Receipt_Payments`
DROP FOREIGN KEY `Purchase_Receipt_Payments_bankAccountId_fkey`;

-- DropIndex
DROP INDEX `Pos_Accounts_bankAccountId_inventoryId_fkey` ON `Pos_Accounts`;

-- DropIndex
DROP INDEX `Purchase_Receipt_Payments_bankAccountId_fkey` ON `Purchase_Receipt_Payments`;

-- AlterTable
ALTER TABLE `Inventory_Transfer_Items`
MODIFY `count` DECIMAL(10, 0) NOT NULL;

-- AlterTable
ALTER TABLE `Orders` MODIFY `totalAmount` DECIMAL(15, 2) NOT NULL;

-- AlterTable
ALTER TABLE `Pos_Accounts` MODIFY `bankAccountId` INTEGER NOT NULL;

-- AlterTable
ALTER TABLE `Product_Variants`
MODIFY `basePrice` DECIMAL(15, 2) NOT NULL,
MODIFY `salePrice` DECIMAL(15, 2) NOT NULL,
MODIFY `quantity` DECIMAL(10, 0) NULL DEFAULT 0.00,
MODIFY `alertQuantity` DECIMAL(10, 0) NULL DEFAULT 5.00;

-- AlterTable
ALTER TABLE `Products`
MODIFY `salePrice` DECIMAL(15, 0) NOT NULL DEFAULT 0.00;

-- AlterTable
ALTER TABLE `Purchase_Receipt_Items`
MODIFY `count` DECIMAL(10, 0) NOT NULL,
MODIFY `fee` DECIMAL(15, 2) NOT NULL,
MODIFY `total` DECIMAL(15, 2) NOT NULL;

-- AlterTable
ALTER TABLE `Purchase_Receipt_Payments`
ADD COLUMN `inventoryId` INTEGER NOT NULL,
ADD COLUMN `type` ENUM('PAYMENT', 'REFUND') NOT NULL,
MODIFY `amount` DECIMAL(15, 2) NOT NULL,
MODIFY `bankAccountId` INTEGER NOT NULL;

-- AlterTable
ALTER TABLE `Purchase_Receipts`
DROP COLUMN `isSettled`,
ADD COLUMN `status` ENUM(
    'UNPAID',
    'PARTIALLY_PAID',
    'PAID'
) NOT NULL DEFAULT 'UNPAID',
MODIFY `totalAmount` DECIMAL(15, 2) NOT NULL,
MODIFY `paidAmount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00;

-- AlterTable
ALTER TABLE `Sales_Invoice_Items`
MODIFY `count` DECIMAL(10, 0) NOT NULL,
MODIFY `fee` DECIMAL(15, 2) NOT NULL,
MODIFY `total` DECIMAL(15, 2) NOT NULL;

-- AlterTable
ALTER TABLE `Sales_Invoices`
MODIFY `totalAmount` DECIMAL(15, 2) NOT NULL;

-- AlterTable
ALTER TABLE `Stock_Adjustments`
MODIFY `adjustedQuantity` DECIMAL(10, 0) NOT NULL;

-- AlterTable
ALTER TABLE `Stock_Movements`
MODIFY `quantity` DECIMAL(10, 0) NOT NULL,
MODIFY `fee` DECIMAL(15, 2) NOT NULL,
MODIFY `totalCost` DECIMAL(15, 2) NOT NULL,
MODIFY `avgCost` DECIMAL(15, 2) NOT NULL,
MODIFY `remainedInStock` DECIMAL(10, 0) NOT NULL DEFAULT 0.00;

-- AlterTable
ALTER TABLE `Supplier_Ledger`
MODIFY `debit` DECIMAL(15, 2) NOT NULL DEFAULT 0,
MODIFY `credit` DECIMAL(15, 2) NOT NULL DEFAULT 0,
MODIFY `balance` DECIMAL(15, 2) NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX `Bank_Accounts_iban_key` ON `Bank_Accounts` (`iban`);

-- AddForeignKey
ALTER TABLE `Pos_Accounts`
ADD CONSTRAINT `Pos_Accounts_inventoryId_bankAccountId_fkey` FOREIGN KEY (
    `inventoryId`,
    `bankAccountId`
) REFERENCES `Inventory_Bank_Accounts` (
    `inventoryId`,
    `bankAccountId`
) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Purchase_Receipt_Payments`
ADD CONSTRAINT `Purchase_Receipt_Payments_inventoryId_bankAccountId_fkey` FOREIGN KEY (
    `inventoryId`,
    `bankAccountId`
) REFERENCES `Inventory_Bank_Accounts` (
    `inventoryId`,
    `bankAccountId`
) ON DELETE RESTRICT ON UPDATE CASCADE;

-- RenameIndex
ALTER TABLE `Supplier_Ledger`
RENAME INDEX `Supplier_Ledger_supplierId_fkey` TO `Supplier_Ledger_supplierId_idx`;
