File "create.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/fee_structure/create.php
File size: 1.39 KiB (1425 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once '../../config/config.php';
require_once '../helper/audit_log.php';
header('Content-Type: application/json');
try {
    $course_id=(int)($_POST['course_id']??0);
    $fee_type_id=(int)($_POST['fee_type_id']??0);
    $amount=(float)($_POST['amount']??0);
    $effective_from=trim($_POST['effective_from']??'');
    $effective_to=trim($_POST['effective_to']??'');
    $errors=[]; if($course_id<=0)$errors[]='Course required.'; if($fee_type_id<=0)$errors[]='Fee Type required.'; if($amount<=0)$errors[]='Amount must be > 0.'; if($effective_from==='')$errors[]='Effective From required.'; if($errors){ echo json_encode(['status'=>'error','message'=>$errors]); exit; }
    $stmt=$pdo->prepare('INSERT INTO course_fee_structure (course_id, fee_type_id, amount, effective_from, effective_to) VALUES (?,?,?,?,?)');
    $stmt->execute([$course_id,$fee_type_id,$amount,$effective_from,$effective_to?:null]);
    write_audit_log($pdo, ['module'=>'Fee Management','action'=>'create','entity_table'=>'course_fee_structure','entity_id'=>$pdo->lastInsertId(),'after_data'=>compact('course_id','fee_type_id','amount','effective_from','effective_to'),'message'=>'Fee structure created']);
    echo json_encode(['status'=>'success','message'=>'Fee structure created successfully.']);
} catch(Throwable $e){ http_response_code(500); echo json_encode(['status'=>'error','message'=>$e->getMessage()]); }
?>


PHP File Manager