

 INSERT INTO settings (category_id, name, code, type, value, default_value, is_active)
VALUES (1, 'Receipt Font Size', 'receipt_font_size', 'number', '16', '16', 1);

-- Table for Sale Returns (header)
CREATE TABLE IF NOT EXISTS sale_returns (
    id INT AUTO_INCREMENT PRIMARY KEY,
    sale_id INT NOT NULL,
    customer_id INT NOT NULL,
    return_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    total_amount DECIMAL(10,2) NOT NULL,
    remarks VARCHAR(255),
    created_by INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (sale_id) REFERENCES sales(id),
    FOREIGN KEY (customer_id) REFERENCES customers(id)
);

-- Table for Sale Return Items (details)
CREATE TABLE IF NOT EXISTS sale_return_items (
    id INT AUTO_INCREMENT PRIMARY KEY,
    sale_return_id INT NOT NULL,
    item_id INT NOT NULL,
    quantity INT NOT NULL,
    unit_price DECIMAL(10,2) NOT NULL,
    total_price DECIMAL(10,2) NOT NULL,
    tax_rate DECIMAL(5,2) DEFAULT 0.00,
    FOREIGN KEY (sale_return_id) REFERENCES sale_returns(id),
    FOREIGN KEY (item_id) REFERENCES items(id)
);


-- Table for Purchase Returns (header)
CREATE TABLE IF NOT EXISTS purchase_returns (
    id INT AUTO_INCREMENT PRIMARY KEY,
    purchase_id INT NOT NULL,
    vendor_id INT NOT NULL,
    return_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    total_amount DECIMAL(10,2) NOT NULL,
    remarks VARCHAR(255),
    created_by INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (purchase_id) REFERENCES purchases(id),
    FOREIGN KEY (vendor_id) REFERENCES vendors(id)
);

-- Table for Purchase Return Items (details)
CREATE TABLE IF NOT EXISTS purchase_return_items (
    id INT AUTO_INCREMENT PRIMARY KEY,
    purchase_return_id INT NOT NULL,
    item_id INT NOT NULL,
    quantity INT NOT NULL,
    unit_cost DECIMAL(10,2) NOT NULL,
    total_cost DECIMAL(10,2) NOT NULL,
    tax_rate DECIMAL(5,2) DEFAULT 0.00,
    FOREIGN KEY (purchase_return_id) REFERENCES purchase_returns(id),
    FOREIGN KEY (item_id) REFERENCES items(id)
);


INSERT INTO `settings` (
  `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`
) VALUES (
  1, 'Receipt Logo Width', 'receipt_logo_width', 'number', '100', '100', 'Width of the branch logo on printed receipts (in pixels)', 1
);



INSERT INTO setting_categories (name, code) VALUES ('Barcode Settings', 'barcode_settings');

INSERT INTO settings (
    category_id, name, code, type, value, default_value, description, is_active
) VALUES (
    5, -- replace with the actual ID from above
    'Barcode Logo Width',
    'barcode_logo_width',
    'number',
    '80', -- default value, you can change as needed
    '80',
    'Width of the branch logo on printed barcodes (in pixels)',
    1
);

INSERT INTO settings (
    category_id,
    name,
    code,
    type,
    value,
    default_value,
    description,
    is_active
) VALUES (
    5,
    'Display Barcode Logo',
    'barcode_logo_display',
    'boolean',
    '1',
    '1',
    'Show or hide the branch logo on printed barcodes',
    1
);

ALTER TABLE sales
  ADD COLUMN discount_type ENUM('percent', 'fixed') DEFAULT NULL,
  ADD COLUMN discount_value DECIMAL(10,2) DEFAULT 0;
