

CREATE TABLE IF NOT EXISTS tax_rates (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  rate DECIMAL(5,2) NOT NULL,
  is_active TINYINT(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO tax_rates (name, rate, is_active) VALUES
('KDV %1', 1.00, 1),
('KDV %10', 10.00, 1),
('KDV %20', 20.00, 1)
ON DUPLICATE KEY UPDATE name=VALUES(name);

CREATE TABLE IF NOT EXISTS number_sequences (
  id INT AUTO_INCREMENT PRIMARY KEY,
  key_name VARCHAR(50) NOT NULL UNIQUE,
  prefix VARCHAR(50) NOT NULL,
  year INT NOT NULL,
  last_number INT NOT NULL DEFAULT 0,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO number_sequences (key_name, prefix, year, last_number)
VALUES
('quote', 'TEK-', YEAR(CURDATE()), 0),
('invoice', 'FAT-', YEAR(CURDATE()), 0)
ON DUPLICATE KEY UPDATE key_name=key_name;
