CREATE TABLE IF NOT EXISTS `pharmacy_lpos` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `supplier_id` INT NOT NULL,
    `lpo_date` DATE NOT NULL,
    `status` ENUM('Draft', 'Sent', 'Received', 'Cancelled') DEFAULT 'Draft',
    `total_amount` DECIMAL(10, 2) DEFAULT 0.00,
    `notes` TEXT NULL,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (`supplier_id`) REFERENCES `suppliers`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `pharmacy_lpo_items` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `lpo_id` INT NOT NULL,
    `drug_id` INT NOT NULL,
    `quantity` INT NOT NULL,
    `cost_price` DECIMAL(10, 2) NOT NULL,
    `total_cost` DECIMAL(10, 2) NOT NULL,
    FOREIGN KEY (`lpo_id`) REFERENCES `pharmacy_lpos`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`drug_id`) REFERENCES `drugs`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
