Register:

- firstname
- lastname
- username
- email
- password
- confirm password
- contact number
- role (admin, Staff Member , Manager)

Vendor
- Vendor Name
- Contact Number
- Email
- Address
- Description(optional)

Customer
- Customer Name
- Contact Number
- Email
- Address
- Description(optional)

Unit:-
- Name:*

Brand:
- Name 
- Description

Category
- Category name:*
- Description:

Product

- Product Name:*
- SKU:
- Unit:*
- Brand
- Category
- Bussiness Location
- Product Description
- product Images(Ask by client)
- Purchase price
- selling price

Payment Method

- payment Method Name

Purchase:

- Select Vendor name
(Vendor Id)
- Purchase Date (editable)
- Purchase Status (Pending, Recieved, Ordered)
- Address(automaticall fetch from Vendor Name and can be change )
- Attach Document (file just like as GDPR Agreement)
(document can accept pdf, docx, xlsx, png, jpg, jpeg)
then we will select a product by searching (Purchase Order Detail)
==> product Name
==> Product unit (prefill from product and should be disable)
==> purchase quantity 
==> Unit Cost 
==> Line Total


================= (For Frontend Only)================
(Bottom-right-down)
	Total Items: 10
	Net Total Amount: 500/=

================= (For Frontend Only)================

- Additional Notes
- Shipping Details

Payment Details
- Amount
- Paid on Date
- payment Method Name
- Payment Notes


================= (For Frontend Only)================
(Bottom-right-down)
	Payment due: 0.00

================= (For Frontend Only)================






- payment Status(Pending, Partial, paid)(this is only for display listing time)
- purchase order listing columns as same as Techsurge POS









//purchase reutrn 
=========== PURCHASE RETURN (UI idea from techsurge POS) ===========
- purchase order dropdown (purchase order id) (only available if Purchase order status wil be recieved)
- bussiness location (prefill against purchase order id)
- date
- attach document 

- products lisitng (coming from an API against  purchase order id)
	=> quantity could be editable and all other fields would be disable

//inventory management

get things about it from techsurge POS










//external queries

ALTER TABLE users ADD COLUMN contact_number VARCHAR(255) NOT NULL UNIQUE;

ALTER TABLE users
ADD COLUMN address VARCHAR(255) NULL,
ADD COLUMN country VARCHAR(255) NULL,
ADD COLUMN state VARCHAR(255) NULL,
ADD COLUMN city VARCHAR(255) NULL,
ADD COLUMN postal_code VARCHAR(255) NULL;



ALTER TABLE vendor
ADD COLUMN image VARCHAR(255) NULL AFTER address;


//add created_by column in purchase order table
ALTER TABLE purchase_orders
ADD COLUMN created_by INT NOT NULL;


ALTER TABLE users
ADD COLUMN status INT NOT NULL DEFAULT 1;


CREATE TABLE IF NOT EXISTS `purchase_order_backups` (`id` INTEGER auto_increment , `is_status` ENUM('edited', 'deleted') NOT NULL, `backup_data` JSONB NOT NULL, `created_at` DATETIME DEFAULT NOW(), `updated_at` DATETIME DEFAULT NOW(), PRIMARY KEY (`id`)) ENGINE=InnoDB;,
  



--deleted by refers to change by or any user who is changing po or delete po 

  ALTER TABLE `purchase_order_backups`
ADD COLUMN `deleted_by` INT NULL AFTER `updated_at`,
ADD FOREIGN KEY (`deleted_by`) REFERENCES `users`(`id`);




//payment model Id for payment module
payment_details.model_id for purchase order
155 , 











DROP TABLE IF EXISTS purchase_return;
CREATE TABLE purchase_return (
    id INT AUTO_INCREMENT PRIMARY KEY,
    vendor_id INT NOT NULL,
    purchase_return_date DATE NOT NULL,
    status VARCHAR(50) NOT NULL,
    title VARCHAR(255),
    address VARCHAR(255),
    additional_details TEXT,
    purchase_order_id INT NOT NULL,
    created_by INT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

DROP TABLE IF EXISTS purchase_return_details;


CREATE TABLE purchase_return_details (
    id INT AUTO_INCREMENT PRIMARY KEY,
    purchase_order_return_id INT NOT NULL,
    product_id INT NOT NULL,
    product_name VARCHAR(255) NOT NULL,
    unit_id INT NOT NULL,
    quantity DECIMAL(10, 2) NOT NULL,
    unit_cost DECIMAL(15, 2) NOT NULL,
    product_sku VARCHAR(255),
    line_total DECIMAL(15, 2) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (purchase_order_return_id) REFERENCES purchase_return(id) ON DELETE CASCADE
);






















//custoemr side
ALTER TABLE purchase_order_detail_customer
DROP FOREIGN KEY purchase_order_detail_customer_ibfk_1;

ALTER TABLE purchase_order_detail_customer
ADD CONSTRAINT purchase_order_detail_customer_ibfk_1
FOREIGN KEY (purchase_order_id)
REFERENCES Purchase_Order_Customer(id)
ON DELETE CASCADE;

