-- DentalCare v0.5.9.8.67
-- Cashier POS lock and payment reference integrity. Idempotent where run through System Setup.

CREATE TABLE IF NOT EXISTS `{{prefix}}payment_method_rules` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `method_code` VARCHAR(40) NOT NULL,
  `method_name` VARCHAR(100) NOT NULL,
  `requires_reference` TINYINT(1) NOT NULL DEFAULT 0,
  `allows_change` TINYINT(1) NOT NULL DEFAULT 0,
  `is_active` TINYINT(1) NOT NULL DEFAULT 1,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_payment_method_code` (`method_code`),
  KEY `idx_payment_method_active` (`is_active`,`method_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `{{prefix}}payment_method_rules` (`method_code`,`method_name`,`requires_reference`,`allows_change`,`is_active`,`created_at`)
VALUES
('cash','Cash',0,1,1,NOW()),
('card','Card',1,0,1,NOW()),
('gcash','GCash',1,0,1,NOW()),
('maya','Maya',1,0,1,NOW()),
('bank_transfer','Bank Transfer',1,0,1,NOW()),
('e-wallet','Other e-wallet',1,0,1,NOW()),
('cheque','Cheque',1,0,1,NOW()),
('mixed','Mixed Payment',1,1,1,NOW()),
('other','Other',1,0,1,NOW())
ON DUPLICATE KEY UPDATE
  `method_name`=VALUES(`method_name`),
  `requires_reference`=VALUES(`requires_reference`),
  `allows_change`=VALUES(`allows_change`),
  `is_active`=VALUES(`is_active`),
  `updated_at`=NOW();
