<?php
if(isset($_POST['state'])){
  require_once('../../assets/config/config.php');
  $obj=new Database();
  if($_POST['state']=='add'){
      $batch_no=$_POST['batch_no'];
      $student_id=$_POST['student_id'];
      $student_name=$_POST['student_name'];
      $course=$_POST['course'];
      $duration=$_POST['duration'];
      $fee=$_POST['fee'];
      $shift_time=$_POST['shift_time'];
      $start_date=date("d-M-Y",strtotime($_POST['start_date']));
      $end_date=date("d-M-Y",strtotime($_POST['end_date']));  
      $date=date('d-M-Y');
      $obj->select('setting','*',null,null,null,null);
      $result=$obj->getResult();
      $f_id=$result[0]['f_id']+1;
          $state=$obj->insert('students_course',['f_id'=>$f_id,'date'=>$date,'batch_no'=>$batch_no,'student_id'=>$student_id,'student_name'=>$student_name,'end_date'=>$end_date,'start_date'=>$start_date,'shift_time'=>$shift_time,'course_fee'=>$fee,'course_duration'=>$duration,'course_name'=>$course,'status'=>'Active']);
          if($state==1)
          {
            $state=$obj->update('setting',['f_id'=>$f_id]);  
            echo $obj->insert('txn_details',['date'=>$date,'f_id'=>$f_id,'batch_no'=>$batch_no,'student_id'=>$student_id,'debit'=>$fee,'voucher_type'=>$course]);
          }
  }
  if($_POST['state']=='edit'){
    $id=$_POST['id'];
    $id="f_id='".$id."'";
    $shift_time=$_POST['shift_time'];
    $status=$_POST['status'];

      echo $obj->update('students_course',['shift_time'=>$shift_time,'status'=>$status],$id);

  }
}
?>