<?php
declare(strict_types=1);
ini_set('display_errors','0');
header('Cache-Control: private, no-store, max-age=0');
require_once __DIR__.'/../includes/console_shell.php';
require_login();
$pageLink='salary-config/additional-rate-configuration.php';
$acl=acl_for($pageLink);
if((int)(current_user()['role_id']??0)===1)$acl=array_merge($acl,['can_view'=>true,'can_add'=>true,'can_edit'=>true,'can_delete'=>true]);
if(empty($acl['can_view'])||empty($acl['can_add'])){http_response_code(403);exit('Access denied.');}
require_once __DIR__.'/additional-rate-configuration-common.php';
$errors=[];$record=[];$access=gsr_access($con);$options=arc_options($con,$access);
if($_SERVER['REQUEST_METHOD']==='POST'){
    $record=arc_post_values();
    if(!verify_csrf($_POST['_csrf']??null))$errors[]='Security token expired. Please refresh and try again.';
    else $errors=arc_validate($record,$options);
    if(!$errors){
        try{$id=arc_save($con,$record,0);if(function_exists('audit_log'))audit_log('additional_rate.create','jos_app_emp_eardeduction',(string)$id);$_SESSION['flash_additional_rate']='Additional Rate Configuration saved successfully.';redirect('/salary-config/additional-rate-configuration.php');}
        catch(Throwable $e){$errors[]='The Additional Rate Configuration could not be saved. No changes were committed.';}
    }
}
$formTitle='New Additional Rate Configuration';$submitLabel='Save';
console_header('Add Additional Rate Configuration',$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><span>Salary Config</span><i class="fa-solid fa-chevron-right text-[9px]"></i><a href="/salary-config/additional-rate-configuration.php">Additional Rate Configuration</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 Additional Rate Configuration</h1><p class="mt-1 text-sm text-slate-500">Enter the employee monthly OT or allowance rate details.</p></div>
<?php require __DIR__.'/additional-rate-configuration-form.php';console_footer();
