<?php 
  require_once ("../var/res.php");
  ##### ADD BOQ  ####

  $typeid = $_REQUEST['typeid'];
  $matid = $_REQUEST['matid'];
  $qty = $_REQUEST['qty'];
  $itmid = $_REQUEST['itmid']; 

  $dt = date('Y-m-d');
  $dtrm = date('Y-m-d H:s:i');
  $sts = 4;
  
  $queCheck = $db->prepare('SELECT qtyboq AS lqty FROM tbl_boqcon WHERE itmid="'.$itmid.'" AND typecon="'.$typeid.'" AND matid="'.$matid.'"
  AND sttscon=4 ORDER BY boqcon_id DESC LIMIT 1');
  $queCheck->execute();
  if($queCheck->rowCount() >0){
  $upd = $conn->prepare("UPDATE tbl_boqcon SET qtyboq='".$qty."' WHERE itmid='".$itmid."' AND typecon='".$typeid."' AND matid='".$matid."' AND sttscon=4");
  $upd->execute();
  $msg="Changes Saved Successfully";
  }else{
  
  $stmt = $db->prepare("INSERT INTO tbl_boqcon (itmid,typecon,matid, qtyboq, bcon_date, trmcon, sttscon)
  VALUES (:itmid,:typecon,:matid, :qtyboq, :bcon_date, :trmcon, :sttscon)");
  //if-else statement in executing our prepared statement
  $stmt->execute(array(':itmid' => $itmid ,':typecon' => $typeid ,':matid' => $matid , ':qtyboq' => $qty , ':bcon_date' => $dt ,':trmcon' => $dtrm, ':sttscon' => $sts));
  $msg = 1;
 }

?>