<?php
session_start();
ob_start();
include("dbConfig.php");

include("../Function/hr_all_function_code.php");

include("../Function/level_salf.php");
if(ISSET($_POST['sav_btn'])){
  
$company_id = $_POST["company_id"];

$system_id='2222';

$company_id_sel = $_POST["company_id_sel"];

$amount = $_POST["amount"];
$details = $_POST["details"];
$add_user_id = $_POST["add_user_id"];

date_default_timezone_set("Asia/Riyadh");
  $created_date = date("Y-m-d");
  $createdDate_time = date("Y-m-d h:i:sa");
  
  $link_lang = $_POST["link_lang"];
 $messag_add = $_POST["messag_add"];
 $salf_id = $_POST["salf_id"];


$add_request = "INSERT INTO hr_salf_tbl(id,company_id,employ_id,details,maden,daen,detailsar,detailsen,employ_approval_id,level,type,createdDate,createdDate_time,add_user_id)VALUES('$salf_id','$company_id_sel','$add_user_id','$details','$amount','0','".getstatdetailsAR(1,$company_id_sel)."','".getstatdetailsEN(1,$company_id_sel)."','0','1','salf','$created_date','$createdDate_time','$add_user_id')" ;
$add_request_steps = "INSERT INTO hr_salf_steps_tbl(salf_id,maden,daen,detailsar,detailsen,employ_approval_id,level,type,createdDate,createdDate_time,add_user_id)VALUES('$salf_id','$amount','0','".getstatdetailsAR(1,$company_id_sel)."','".getstatdetailsEN(1,$company_id_sel)."','0','1','salf','$created_date','$createdDate_time','$add_user_id')" ;
   
$employ_id=$add_user_id;
 $attach_type='227285';
$connect_id=$salf_id;
echo fileadd_code($employ_id,$attach_type,$connect_id);


 
//==================العملايات==================================

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
 $user_id =$_SESSION['user_id'];
 $system_type='hr_marsa_system';
  $proccess_type='add_solf_request';
  $proccess_details_en='add solf request'.$add_user_id;
  $proccess_details='طلب سلفه الموظف رقم '.$add_user_id;
 $table_name='hr_salf_tbl';   
  date_default_timezone_set("Asia/Riyadh");
  $createdDate = date("Y-m-d h:i:sa");
   $sql_req = "INSERT INTO process_systems_tbl(system_type,user_id,user_ip,proccess_type,proccess_details,proccess_details_en,table_name,proccess_id,proccess_date,process_time,process_datetime,browser)values('$system_type','$add_user_id','$user_ip','$proccess_type','$proccess_details','$proccess_details_en','$table_name','$user_id',NOW(),NOW(),'$createdDate','$browserAgent')";
 //==================العملايات==================================
  
if ($conn->query($sql_req) === TRUE && $conn->query($add_request) === TRUE && $conn->query($add_request_steps) === TRUE) {
   
  $_SESSION['message'] =$messag_add;

   header("Refresh:0; url=Employee_Advance.php?$link_lang&company_id=$company_id");


} else {
  echo "Error: " . $sql_req . "<br>" . $conn->error;
}

}

?>

