<?php
declare(strict_types=1);ini_set('display_errors','0');require_once __DIR__.'/../includes/console_shell.php';require_login();$pageLink='salary-config/salary-components.php';$acl=require_acl('can_add',$pageLink);require_once __DIR__.'/salary-component-common.php';require_once __DIR__.'/salary-component-form.php';$errors=[];$types=scm_types($con);$components=scm_components($con);$v=scm_defaults();if($_SERVER['REQUEST_METHOD']==='POST'){$v=scm_post();if(!verify_csrf($_POST['_csrf']??null))$errors[]='Security token expired. Please refresh and try again.';else{$errors=scm_validate($con,$v,0,$types,$components);if(!$errors)try{$id=scm_save($con,$v,0);audit_log('salary_component.create','jos_app_salarycomponentmaster',(string)$id);$_SESSION['flash_salary_component']='Salary component added successfully.';redirect('/salary-config/salary-components.php');}catch(Throwable $e){$errors[]='The salary component could not be saved. No changes were committed.';}}}console_header('Add Salary Component',$pageLink);?>
<div class="mb-6"><div class="mb-2 flex items-center gap-2 text-xs font-semibold text-slate-500"><a href="/dashboard.php">Dashboard</a><i class="fa-solid fa-chevron-right text-[9px]"></i><a href="/salary-config/salary-components.php">Salary Component Master</a><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Add</span></div><h1 class="text-2xl font-bold text-slate-900">Add Salary Component</h1><p class="mt-1 text-sm text-slate-500">Create a salary component using the existing payroll calculation rules.</p></div><?php if($errors):?><div class="mb-5 rounded-xl border border-red-100 bg-red-50 px-5 py-4 text-sm font-semibold text-red-700"><?=h(implode(' ',$errors))?></div><?php endif;?><?php scm_render_form($v,$types,$components,'Submit');console_footer();
