ALTER TABLE products ADD COLUMN min_stock DECIMAL(18,6) NULL,ADD COLUMN max_stock DECIMAL(18,6) NULL;
CREATE TABLE inventory_counts(id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,business_id BIGINT UNSIGNED NOT NULL,branch_id BIGINT UNSIGNED NOT NULL,user_id BIGINT UNSIGNED NOT NULL,status ENUM('draft','posted','cancelled') NOT NULL DEFAULT 'draft',notes VARCHAR(500) NULL,created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,posted_at DATETIME NULL,KEY idx_counts(business_id,branch_id,status));
CREATE TABLE inventory_count_items(id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,count_id BIGINT UNSIGNED NOT NULL,product_id BIGINT UNSIGNED NOT NULL,variant_id BIGINT UNSIGNED NULL,system_qty DECIMAL(18,6) NOT NULL,counted_qty DECIMAL(18,6) NOT NULL,difference_qty DECIMAL(18,6) NOT NULL,reason VARCHAR(255) NULL,KEY idx_count_items(count_id));
INSERT INTO permissions(code,name,module) VALUES('inventory.adjust','Ajustar inventario','inventory'),('inventory.count','Realizar conteos','inventory') ON DUPLICATE KEY UPDATE name=VALUES(name);