<?php require_once('../auth/auth.php');?>
<?php 
if(isset($_POST['sal_invoice'])){
   $invoice    = $_POST['sal_invoice'];
   $tdate      = $_POST['tdate'].' '.$time;
   $c_acid     = $_POST['c_acid'];
   $details    = $_POST['details'];
   $wh_id      = $_POST['wh_id'];
   $d_man      = $_POST['d_man'];
   $m_invoice  = $_POST['m_invoice'];


  if (isset($_POST['c_gsm'])) {
     $c_gsm     = $_POST['c_gsm'];
     $c_name    = $_POST['c_name'];
     $c_address = $_POST['c_address'];

     $chcus=mysqli_query($conn,"SELECT c_id FROM c_customer WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND c_gsm='$c_gsm' LIMIT 1");

     if (mysqli_num_rows($chcus)<1) {
        mysqli_query($conn,"INSERT INTO `c_customer`(`coid`, `bid`, `brid`, `c_name`, `c_gsm`, `c_address`) VALUES ('$coid','$bid','$brid','$c_name','$c_gsm','$c_address')") or die(mysqli_error($conn));
     }

     $c_cus=mysqli_fetch_assoc(mysqli_query($conn,"SELECT c_id FROM c_customer WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND c_gsm='$c_gsm' LIMIT 1"))['c_id'];
  }
  
  $c_id = @$c_cus?$c_cus:$c_acid;


mysqli_query($conn,"UPDATE order_list_edit SET acid='$c_id',m_invoice='$m_invoice',details='$details',wh_id='$wh_id',d_man='$d_man',userid='$uid',datetime='$tdate',order_type='SDRAFT' WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND invoice='$invoice'") or die(mysqli_error($conn));
}
 ?>