<?php require_once('../auth/auth.php');require_once('../auth/function.php'); ?>
<?php 
 if (isset($_GET['pro_id'])) {
     $item_id = $_GET['pro_id'];
       $invoice = $_GET['invoice'];
       $order_type  = $_GET['order_type'];
      $op_row= mysqli_fetch_assoc(mysqli_query($conn,"SELECT item_name,item_details FROM item WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  pro_id='$item_id' LIMIT 1"));
            $item_name = $op_row['item_name'];
            $item_details = $op_row['item_details'];

        $order_row= mysqli_fetch_assoc(mysqli_query($conn,"SELECT eoid,pu_price,sale_price FROM order_list_edit WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  pro_id='$item_id' AND invoice='$invoice' LIMIT 1"));
        $Get_eoid   = $order_row['eoid'];
        $pu_price   = $order_row['pu_price'];
        $sale_price = $order_row['sale_price'];
 }

  $custom_field= mysqli_query($conn,"SELECT purchase FROM custom_field WHERE coid='$coid' LIMIT 1 ") or die(mysqli_error($conn));
  $rowcf= mysqli_fetch_assoc ($custom_field);

  @$p=$rowcf['purchase'];
  function input_check($ap)
  {
   if (strpos($GLOBALS['p'], $ap) !== false) { return 1;} 
  }
?>


<section class="content">
  <div class="row">
    <div class="col-md-12">
      <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
        <div class="card-header" style="padding: 3px 8px;">
          <h3 class="card-title mt-1"> <?php echo language(8);?> <?php echo language(386);?> <strong class="ml-3 text-danger"> <?php echo @$item_name.@$item_details; ?>  >>  <?php echo @$invoice; ?> </strong>
          </h3>
          <div class="card-tools mt-1">
            <button type="button" class="btn btn-tool"  data-card-widget="remove" data-dismiss="modal">
            <i class="fas fa-times"></i>
            </button>
          </div>
        </div>




        <?php if(input_check('item_scan_status')==1){ ?>
                    <form id="pur_sub" action="#" method="post" autocomplete="off">
                   <?php } ?>
                      <div class="row">
                        <div class="col-md-3"></div>
                        <div class="col-md-6">
                          <div class="form-group">
                            <label> <?php echo language(138);?></label>
                            <input type="text" id="item_imei" class="form-control form-control-sm inputselect" required="true" autofocus="true">
                          </div>
                        </div>
                        <div class="col-md-3"></div>
                        <div class="col-md-12">
                          <hr style="margin-top:-5px;margin-bottom: 7px;">
                        </div>
                      </div>
        <?php if(input_check('item_scan_status')==1){ ?>
                    </form>
        <?php } ?>
            <table class="ttable" cellpadding="0" cellspacing="0">
                <thead>
                  <tr class="sticky-top">
                 <th class="text-center w-5"><?php echo language(15)?></th>
                      <th class="w-20"><?php echo language(97)?></th>
                      <th class="text-center w-10"><?php echo language(387);?></th>
                      <th class="text-center w-10"><?php echo language(388);?></th>
                      <th class="text-center w-10"><?php echo language(389);?></th>
                      <th class="text-center w-10"><?php echo language(390);?></th>
                      <th class="text-center w-10"><?php echo language(131);?></th>
                      <th class="text-center w-5"><?php echo language(90);?></th>
                      <th class="text-center w-5">#</th>
                  </tr>
                </thead>
                      <tbody >
                          
                        <?php
                            $order= mysqli_query($conn,"SELECT *,item.item_name,item.item_details FROM imei_tracker_edit LEFT JOIN item ON item.pro_id=imei_tracker_edit.pro_id WHERE imei_tracker_edit.coid='$coid' AND imei_tracker_edit.bid='$bid' AND imei_tracker_edit.brid='$brid' AND imei_tracker_edit.invoice='$invoice' AND imei_tracker_edit.active=0 ORDER BY imei_tracker_edit.edit_imei_id ASC") or die(mysqli_error($conn));
                            $i=0;
                            while($orw= mysqli_fetch_assoc($order)){
                        ?>
                        <tr>
                            <td class="text-center"><?php echo ++$i;?></td>
                            <td><?php echo $orw['item_name'].' '.$orw['item_details'] ;?></td>
                            <td><?php echo $orw['imei_code'] ;?></td>
                            <td><?php echo $orw['imei_color'] ;?></td>
                            <td class="text-center"><?php echo $orw['mfg_date'];?></td>
                            <td class="text-center" title="<?php echo $orw['exp_date'];?>">
                            <?php 
                                $difference = strtotime($orw['mfg_date']) - strtotime($orw['exp_date']);
                                 $days = abs($difference/(60 * 60)/24);
                                echo " ".$days." days.";
                            ?>
                        </td>
                        <td class="text-center"><?php echo $date;?></td>

                        <?php if($orw['active'] == 1  ){ ?>
                        <td  class="text-center " > <i class="fa fa-check-circle text-success" aria-hidden="true"></i> </td>
                        <?php } else if($orw['active'] == 0) { ?>
                        <td class="text-center bg-danger" > <i class="fa fa-times-circle-o" aria-hidden="true"></i>  </td>
                        <?php  } ?>



                        <td class="text-center" onclick="odelete(<?php echo $orw['edit_imei_id'];?>)"><i class="fas fa-trash"></i></td>


                        </tr>
<?php } ?>



<script>
    function odelete(edit_imei_id) {
        $.post("../imei_tracking/sales_o_list_delete.php",
            {edit_imei_id : edit_imei_id,Get_eoid:'<?php echo $Get_eoid;?>',pro_id:'<?php echo $item_id;?>',oinvoice:'<?php echo $invoice;?>'},
         function(data){
                      pagecall('../sales/order_list.php?invoice=<?php echo $invoice?>','#row_show<?php echo $invoice;?>',0);

         pagecall('../imei_tracking/sales_imei_index.php?pro_id='+<?php echo $item_id ;?>+'&invoice='+'<?php echo $invoice; ?>'+'&eoid='+'<?php echo $Get_eoid;?>'+'&order_type='+'<?php echo $order_type;?>','#xlmdview');   
        });     
    }
</script>


                      </tbody>
                    </table>




<script>


  $(function() {
    $( "#item_imei" ).autocomplete({
        minLength: 2,
       source: '../imei_tracking/select_imei_tracking_code.php?item_id=<?php echo $item_id?>',
       autoFocus: true,
       delay:500,
   //  scroll: true,
       // focus: function( event, ui ) {
       //    $( "#item_details" ).val( ui.item.label );
       //       return false;
       // },
       select: function( event, ui ) {
          $( "#item_imei" ).val( ui.item.label );
          $.post("../imei_tracking/sales_imei_db.php",
            {item_imei : ui.item.value,invoice:'<?php echo $invoice;?>',eoid:'<?php echo $Get_eoid;?>',pro_id:'<?php echo $item_id;?>',order_type:'<?php echo $order_type;?>'},
         function(data){
          pagecall('../sales/order_list.php?invoice=<?php echo $invoice?>','#row_show<?php echo $invoice;?>',0);

          toastr.success(Successfully, yourdata);

         pagecall('../imei_tracking/sales_imei_index.php?pro_id='+<?php echo $item_id ;?>+'&invoice='+'<?php echo $invoice; ?>'+'&eoid='+'<?php echo $Get_eoid;?>'+'&order_type='+'<?php echo $order_type;?>','#xlmdview');   

        });  
        $( "#item_imei" ).val('');        
          return false;
       }
    });
  });
</script>








              
             </div>
        </div>

   </div>
<!-- fdsfsdfsdf -->


</div>
<!-- fsdfsdf -->
    </div>
</div>

</section>




