<?php
//insert.php
session_start();
ob_start();
if(!isset($_SESSION["user_id"])){header("location:../logout.php");}
include "../actions/dbPDO.php";
  $father = $_SESSION["user_id"];

if(isset($_POST["carid"])){
    if($_POST['contract_id'] !=""){
          $contract_id   = $_POST['contract_id'];
          $branch        = $_POST['branch'];
          $used_area     = $_POST['used_area'];
          $rent_days     = $_POST['rent_days'];
          $cust_id       = $_POST['cust_id'];
          $cust_id2      = $_POST['cust_id2'];
          $carid         = $_POST['carid'];

          $date_out      = $_POST['date_out'];
          $date_in       = $_POST['date_in'];
          $days_qty      = $_POST["days_qty"];
          $day_cost      = $_POST['day_cost'];
          $days_cost     = $_POST['days_cost'];

          $km_out       = $_POST['km_out'];
          $km_in        = $_POST['km_in'];
          $kilo_qty     = $_POST['kilo_qty'];
          $kilo_cost    = $_POST['kilo_cost'];
          $free_kilo    = $_POST['free_kilo'];
          $kilos_cost   = $_POST['kilos_cost'];

          $time_out      = $_POST['time_out'];
          $time_in       = $_POST['time_in'];
          $hour_qty      = $_POST["hour_qty"];
          $hour_cost     = $_POST['hour_cost'];
          $hours_cost    = $_POST['hours_cost'];

          $addtion_cost  = $_POST['addtion_cost'];
          $addtion_desc  = $_POST['addtion_desc'];
          $dept_comm     = $_POST['dept_comm'];
          $violations    = $_POST['violations'];
          $ins_claim     = $_POST["ins_claim"];
          $wanted        = $_POST["wanted"];

          $deduction     = $_POST["deduction"];
          $open_comm     = $_POST["open_comm"];
          $comm          = $_POST["comm"];


  $contract_id = $contract_id * -1 ;
  $cont_status = 3;
  if(!empty($date_in)){
    $contt=$db->prepare(" INSERT INTO  contracts(contract_id ,branch ,used_area ,rent_days , cust_id , cust_id2 , carid ,
    date_out ,date_in ,days_qty ,day_cost ,days_cost ,km_out ,km_in ,kilo_qty ,kilo_cost ,free_kilo , kilos_cost ,
  time_out ,time_in ,hour_qty,hour_cost , hours_cost , addtion_cost , addtion_desc , dept_comm ,violations ,
  ins_claim ,wanted , deduction , open_comm ,comm ,father , cont_status)
    VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
   $contt->bindParam(1,$contract_id);
   $contt->bindParam(2,$branch);
   $contt->bindParam(3,$used_area);
   $contt->bindParam(4,$rent_days);
   $contt->bindParam(5,$cust_id);
   $contt->bindParam(6,$cust_id2);
   $contt->bindParam(7,$carid);
   $contt->bindParam(8,$date_out);
   $contt->bindParam(9,$date_in);
   $contt->bindParam(10,$days_qty);
   $contt->bindParam(11,$day_cost);
   $contt->bindParam(12,$days_cost);
   $contt->bindParam(13,$km_out);
   $contt->bindParam(14,$km_in);
   $contt->bindParam(15,$kilo_qty);
   $contt->bindParam(16,$kilo_cost);
   $contt->bindParam(17,$free_kilo);
   $contt->bindParam(18,$kilos_cost);
   $contt->bindParam(19,$time_out);
   $contt->bindParam(20,$time_in);
   $contt->bindParam(21,$hour_qty);
   $contt->bindParam(22,$hour_cost);
   $contt->bindParam(23,$hours_cost);
   $contt->bindParam(24,$addtion_cost);
   $contt->bindParam(25,$addtion_desc);
   $contt->bindParam(26,$dept_comm);
   $contt->bindParam(27,$violations);
   $contt->bindParam(28,$ins_claim);
   $contt->bindParam(29,$wanted);
   $contt->bindParam(30,$deduction);
   $contt->bindParam(31,$open_comm);
   $contt->bindParam(32,$comm);
   $contt->bindParam(33,$father);
   $contt->bindParam(34,$cont_status);
   if($contt->execute()){
     echo "<div class='alert alert-success'>
            <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
            <b>تم حفظ العقد القديم بنجاح ...</b>
            </div>" ;
          }
 else{ echo "<div class='alert alert-danger'>
            <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
            <b>يوجد خطأ في تسجيل البيانات ... راجع  من فضلك</b>
            </div> " ; }
  }
}
}

?>
