-- Migrasi: tambah tabel payment_methods (jalankan SEKALI saja di phpMyAdmin untuk DB yang sudah ada)
CREATE TABLE IF NOT EXISTS payment_methods (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  type VARCHAR(20) NOT NULL DEFAULT 'cash',
  bank_name VARCHAR(100) NULL,
  account_name VARCHAR(100) NULL,
  account_number VARCHAR(50) NULL,
  is_active TINYINT NOT NULL DEFAULT 1,
  sort_order INT NOT NULL DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO payment_methods (name, type, bank_name, account_name, account_number, is_active, sort_order)
SELECT 'Cash', 'cash', NULL, NULL, NULL, 1, 1
WHERE NOT EXISTS (SELECT 1 FROM payment_methods WHERE name = 'Cash');

INSERT INTO payment_methods (name, type, bank_name, account_name, account_number, is_active, sort_order)
SELECT 'QRIS', 'qris', NULL, NULL, NULL, 1, 2
WHERE NOT EXISTS (SELECT 1 FROM payment_methods WHERE name = 'QRIS');

INSERT INTO payment_methods (name, type, bank_name, account_name, account_number, is_active, sort_order)
SELECT 'Transfer Bank', 'transfer', NULL, NULL, NULL, 1, 3
WHERE NOT EXISTS (SELECT 1 FROM payment_methods WHERE name = 'Transfer Bank');