<?php
session_start();
include("dbConfig.php");
if(ISSET($_POST['sav_btn'])){
    
$company_id = $_POST["company_id"];

$system_id='2222';

$company_id_sell = $_POST["company_id_sell"];
$dept_idd = $_POST["dept_idd"];
$employ_idd = $_POST["employ_idd"];
$add_user_id = $_POST["add_user_id"];

$maxamounttype = $_POST["maxamounttype"];
$maxamount = $_POST["maxamount"];
$maxcuttype = $_POST["maxcuttype"];
$maxcut = $_POST["maxcut"];

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 = "تمت التهيئه بنجاح";

 $sql_check = "SELECT * FROM hr_prepare_salf_tb where company_id='".$company_id_sell."'";
         $result_check = $conn->query($sql_check);
                if ($result_check->num_rows > 0) {
                    $prepare = "UPDATE hr_prepare_salf_tb SET maxamounttype='$maxamounttype',maxamount='$maxamount',maxcuttype='$maxcuttype',maxcut='$maxcut',createdDate='$created_date',add_user_id='$add_user_id' where company_id='".$company_id_sell."'" ; 
 
                    if ($conn->query($prepare) === TRUE ) {
                   
                   $_SESSION['message'] =$messag_add;
                   
                      header("Refresh:0; url=hr_prepare_advance.php?$link_lang&company_id=$company_id");
                   
                    }else {
                      echo "Error: " . $promo . "<br>" . $conn->error;
                    }
                }else{
                    $prepare = "INSERT INTO hr_prepare_salf_tb(company_id,maxamounttype,maxamount,maxcuttype,maxcut,type,createdDate,add_user_id)VALUES('$company_id_sell','$maxamounttype','$maxamount','$maxcuttype','$maxcut','salf','$created_date','$add_user_id')" ;

 
                    if ($conn->query($prepare) === TRUE ) {
                   
                   $_SESSION['message'] =$messag_add;
                   
                      header("Refresh:0; url=hr_prepare_advance.php?$link_lang&company_id=$company_id");
                   
                    }else {
                      echo "Error: " . $promo . "<br>" . $conn->error;
                    }
                }



}

?>

