INSERT IGNORE INTO permissions (code, name, module, created_at) VALUES
('addon.nota.view', 'Lihat Hitungan Nota NCR', 'addon_nota', NOW()),
('addon.nota.manage', 'Kelola Hitungan Nota NCR', 'addon_nota', NOW()),
('addon.nota.master.view', 'Lihat Master Nota NCR', 'addon_nota', NOW()),
('addon.nota.master.edit', 'Ubah Master Nota NCR', 'addon_nota', NOW()),
('addon.nota.delete', 'Hapus Histori Hitungan Nota NCR', 'addon_nota', NOW());

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id
FROM roles r
JOIN permissions p ON p.code IN (
  'addon.nota.view',
  'addon.nota.manage',
  'addon.nota.master.view',
  'addon.nota.master.edit',
  'addon.nota.delete'
)
WHERE r.code IN ('owner', 'admin', 'kepala_toko');
