-- Full module parity: petty cash workflow + extra roles + workflow settings

ALTER TABLE `petty_cash`
  MODIFY `status` enum('pending','approved','issued','reconciliation','closed','rejected') NOT NULL DEFAULT 'pending';

ALTER TABLE `petty_cash`
  ADD COLUMN IF NOT EXISTS `issued_by` int(10) UNSIGNED DEFAULT NULL AFTER `approved_at`,
  ADD COLUMN IF NOT EXISTS `issued_at` datetime DEFAULT NULL AFTER `issued_by`,
  ADD COLUMN IF NOT EXISTS `reconciled_by` int(10) UNSIGNED DEFAULT NULL AFTER `issued_at`,
  ADD COLUMN IF NOT EXISTS `reconciled_at` datetime DEFAULT NULL AFTER `reconciled_by`,
  ADD COLUMN IF NOT EXISTS `closed_at` datetime DEFAULT NULL AFTER `settled_at`;

UPDATE `petty_cash` SET `status` = 'closed' WHERE `status` = 'settled';

INSERT IGNORE INTO `roles` (`name`, `display_name`, `created_at`) VALUES
('property_manager', 'Property Manager', NOW()),
('supervisor', 'Supervisor', NOW()),
('qa_inspector', 'QA Inspector', NOW());

INSERT IGNORE INTO `system_settings` (`setting_key`, `setting_value`) VALUES
('wf_require_supervisor_approval', '1'),
('wf_require_qa_on_complete', '1'),
('wf_require_client_approval', '1'),
('wf_require_invoice_before_close', '1'),
('wf_require_labor_or_material', '1'),
('wf_auto_invoice_on_client_approve', '1');
