<?php require_once('../auth/auth.php');require_once('../auth/acid_balance.php');require_once('../auth/item_qty.php'); ?>
<?php
if (isset($_POST['invoice'])) {
	$item_imei  = $_POST['item_imei'];
	 $pro_id  = $_POST['pro_id'];
	 $invoice = $_POST['invoice'];
	 $eoid    = $_POST['eoid'];
	 $order_type = $_POST['order_type'];
 


echo $imei_code_status=mysqli_fetch_assoc(mysqli_query($conn,"SELECT imei_code FROM imei_tracker WHERE  coid='$coid' AND bid='$bid' AND brid='$brid' AND imei_id='$item_imei'  LIMIT 1"))['imei_code'];

  $chinvoice=mysqli_query($conn,"SELECT imei_code FROM imei_tracker_edit WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND invoice='$invoice' AND imei_code='$imei_code_status'  LIMIT 1");
    if (mysqli_num_rows($chinvoice)>0 ) {
    	echo "Already Exists ";
    }else {
   mysqli_query($conn,"INSERT INTO imei_tracker_edit (`coid`, `bid`, `brid`,`invoice`,`order_type`,`wh_id`, `pro_id`, `imei_code`, `imei_color`, `mfg_date`, `exp_date`, `plus`, `pu_price`, `sale_price`, `date`, `active`)
SELECT `coid`, `bid`, `brid`, '$invoice','$order_type', `wh_id`, `pro_id`, `imei_code`, `imei_color`, `mfg_date`, `exp_date`, '-', `pu_price`, `sale_price`, `date`,'0' FROM imei_tracker WHERE imei_id= '$item_imei' AND coid='$coid' AND bid='$bid' AND brid='$brid' AND pro_id='$pro_id'  ")or die(mysqli_error($conn));

     mysqli_query($conn,"UPDATE order_list_edit LEFT JOIN pro_unit ON (order_list_edit.pro_unit=pro_unit.puid) SET qty =(qty+1),t_amount=(amount*qty*unit_convart),net_amount=(t_amount-dis_amount) WHERE order_list_edit.coid='$coid' AND order_list_edit.bid='$bid' AND order_list_edit.brid='$brid' AND invoice='$invoice' AND pro_id ='$pro_id' AND eoid='$eoid'")or die(mysqli_error($conn));

    }



}

?>