<?php require_once('../auth/auth.php');require_once('../auth/acid_balance.php');require_once('../auth/item_qty.php'); ?>
<?php
	if (isset($_POST['invoice'])) {
	 	$invoice       = $_POST['invoice'];
	 	$litem         = $_POST['item_id'];
	 	$Geteoid           = $_POST['eoid'];
	 	$imei_code     = $_POST['imei_code'];
	 	$imei_color    = $_POST['imei_color'];
	 	$p_price       = $_POST['pu_price'];
	 	$u_price       = $_POST['pu_price'];
	 	$mrp_sales     = $_POST['sale_price'];
	 	$mfg_date      = $_POST['mfg_date'];
	 	$exp_date      = $_POST['exp_date'];
	 	$op_qty        = 1;
	 	$op_date       = $date.' '.$time;
        $op_val    = $op_qty * $p_price;


	    $op_row= mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM item WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  pro_id='$litem' LIMIT 1"));
           $item_code = $op_row['item_code'];
       
		$war_id = mysqli_fetch_assoc(mysqli_query($conn,"SELECT bwid FROM business_w_house WHERE coid='$coid' AND bid='$bid' AND   brid='$brid' AND active=1 AND default_set='primary' LIMIT 1"))['bwid'];


        $ch_imei_one=mysqli_query($conn,"SELECT imei_code FROM imei_tracker WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND imei_code='$imei_code' LIMIT 1");
        $ch_imei=mysqli_query($conn,"SELECT imei_code FROM imei_tracker_edit WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND imei_code='$imei_code' LIMIT 1");

if (mysqli_num_rows($ch_imei_one ) > 0 ) {
    
    echo "Al Ready Have IMEI Purchase.";
}else{


				if (mysqli_num_rows($ch_imei ) > 0 ) {
					echo "Al Ready Have IMEI EXIT.";
			}else {
                 
		        mysqli_query($conn,"INSERT INTO `imei_tracker_edit`(`coid`, `bid`, `brid`, `acid`, `invoice`, `order_type`, `wh_id`, `pro_id`, `imei_code`, `imei_color`, `mfg_date`, `exp_date`, `plus`, `pu_price`, `sale_price`, `date`, `active`) 
			        VALUES ('$coid','$bid','$brid','0','$invoice', 'EPUR','0','$litem','$imei_code','$imei_color','$mfg_date','$exp_date','+','$p_price','$mrp_sales','$op_date','0')") or die(mysqli_error($conn));

                // Load Order List Row By Item Id
                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 invoice='$invoice' AND pro_id='$litem' AND eoid='$Geteoid'")or die(mysqli_error($conn));


	    } // imei code Duplicate Check Close
	    
	    
}
	}  // isset Close
?>