<?php require_once('../auth/auth.php');require_once('../auth/function.php');?>
<?php
$productid = $_GET['pro_id'];
$product_query= mysqli_query($conn,"SELECT *,item.pro_batchid,item.pro_id FROM item  LEFT JOIN order_list ON order_list.pro_id =item.pro_id  WHERE item.coid='$coid' AND item.pro_id='$productid ' ") or die(mysqli_error($conn));
$prow= mysqli_fetch_assoc($product_query);
$pro_id       = $prow['pro_id'];
$item_name    = $prow['item_name'];
$p_pic1       = $prow['p_pic1'];
// $g_name= mysqli_fetch_assoc(mysqli_query($conn,"SELECT ac_g_cat_name FROM ac_sub_g_category WHERE coid='$coid' AND ac_g_catid='$gcatid' LIMIT 1"))['ac_g_cat_name'];
?> 

<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"> <?php echo language(211); ?> </h3>
        <div class="card-tools m-0">
          <button type="button" class="btn btn-tool" data-card-widget="remove" data-dismiss="modal">
            <i class="fas fa-times"></i>
          </button>
        </div>
      </div>
      <div style="display: flex;">
       <div class="col-md-2 pt-1" style="border-right:1px solid #969c9d;">
        <div class="card-body box-profile">
         <div class="text-center">
           <span style="float:right;position: relative;margin-left: -12px;cursor:pointer;">    
             <input type="file" id="new_img" accept="image/*" style="position: absolute;opacity: 0;"><i class="fa fa-edit new_Btn"></i>
           </span>
           <?php if($p_pic1 != ""): ?>
             <img id="img_data" class="profile-user-img img-fluid img-circle" src="data:image/gif;base64,<?php echo $p_pic1;?>" alt="User profile picture">
           <?php else : ?>
             <img id="img_data" class="profile-user-img img-fluid img-circle" src="../../dist/img/no_img.jpg" alt="User profile picture">
           <?php endif; ?>
         </div>


         <h6 class="text-center pt-1 m-0"><dt><?php echo $item_name;?></dt></h6>
         <p class="text-muted text-center m-0 text-xsm"><?php echo $prow['item_details'].$prow['item_weight']  ;?></p>
         <hr class="m-0 pt-1">
         <?php if ($prow['item_qty'] >= 0) { ?>
           <h6 class="marksc text-center m-0 p-1"><dt><?php echo money($prow['item_qty'],true);?> PCS</dt></h6>
         <?php } else { ?>
           <h6 class="mark1 text-center m-0 p-1"><dt><?php echo money($prow['item_qty'],true);?> PCS</dt></h6>
         <?php } ?>
         <hr class="mb-0 mt-1">
         <strong><i class="fas fa-barcode mr-1"></i> <?php echo $prow['item_code'];?></strong>
         <hr>
         <strong><i class="fas fa-code mr-1"></i> <?php echo $prow['item_sku'];?></strong>
         <hr>
         <strong style="font-size:" ><i class="fas fa-tasks mr-1"></i> <?php 
         echo $batch_number = mysqli_fetch_assoc(mysqli_query($conn,"SELECT batch_no FROM batch_no  WHERE batid='".$prow['pro_batchid']."' LIMIT 1"))['batch_no'];?></strong>
         <hr>
          <strong><i class="fa-solid fa-bell"></i> <?php echo $prow['item_notif'];?> ........
                <i class="fa-solid fa-bullhorn"> </i>   <?php echo $prow['item_disc'];?>%
          </strong>   
         <hr>

      <strong>  <i class="fa-solid fa-cart-arrow-down" style="color:red"> </i> COST:   <?php echo $prow['mrp_purchase'];?></strong>  
       <hr>
       <strong>  <i class="fa-solid fa-cart-plus" style="color:#23549d"> </i> MRP:   <?php echo $prow['mrp_sales'];?></strong>  
       <hr>
       <strong style="font-size:10px;"><i class="fa-solid fa-calendar-days"></i> <?php echo date('d/m/y h:i:s a', strtotime($prow['item_op_date']));?> </strong>
       <hr>
      <strong>
      <i class="fas fa-warehouse mr-1"></i>
      <?php  // $war_location = mysqli_fetch_assoc(mysqli_query($conn,"SELECT war_location FROM business_w_house  WHERE bwid='".$prow['wh_id']."' LIMIT 1"))['war_location'];
       
      //  echo $war_location ? $war_location :0;
       
      ?>
     </strong>
     <hr>
     <strong><i class="fas fa-certificate mr-1"></i> <?php if ($prow['war_type']=='N') {echo "No warrenty";}else if ($prow['war_type']=='D'){echo $prow['wa_dmy'].'-'."Days";}else if ($prow['war_type']=='M'){echo $prow['wa_dmy'].'-'. "Months";}else if ($prow['war_type']=='Y'){echo $prow['wa_dmy'].'-'."Years";}else if ($prow['war_type']=='L'){echo "Life Time";}  ?>
     </strong>
   </div>
 </div>

 <div class="col-md-10 p-0">
   <ul class="nav nav-pills" style="background-color: honeydew;padding: 2px 0;border-bottom:1px solid #dee2e6;margin-left: 2px;">
     <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/item_ledger_search.php?pro_id=<?php echo $pro_id?>','#pview');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(212); ?> </a></li>|
     <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/item_dashboard.php?pro_id=<?php echo $pro_id ?>','#pview');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(1); ?> </a></li>|

     <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/item_profile_update.php?pro_id=<?php echo $pro_id ?>','#pview');"><i class="fa fa-fw fa-edit"></i> <?php echo language(25); ?> </a></li>|
<?php if (@$prow['imei_status']==1) { ?>
       <li class="nav-item" ><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../imei_tracking/opening_imei_index.php?pro_id=<?php echo $pro_id ?>','#pview');"><i title="Tax Group" class="fa fa-fw fa-calculator"></i> <?php echo language(386); ?> </a></li>|
<?php }else {  ?>
        <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemadjust/adjust_index.php?g_itemid=<?php echo $productid;?>','#pview');"><i class="fa-solid fa-plus-minus"></i> <?php echo language(199); ?> </a></li>|
<?php } ?>
     <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/item_tax.php?pro_id=<?php echo $pro_id ?>','#pview');"><i title="Tax Group" class="fa fa-fw fa-calculator"></i> <?php echo language(196); ?> </a></li>|

 <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/wharehousestock.php?pro_id=<?php echo $pro_id ?>','#pview');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(331); ?></a></li>     <!--<li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../itemstock/re_voucher_index.php?pro_id=<?php echo $pro_id ?>','#pview');"><i class="fa fa-fw fa-calculator"></i> Batch Stock  </a></li>|-->
   </ul>
   <div id="pview" class="pt-1"></div>
 </div>

</div>

</div>
</div>
</div>
</section>

<script type="text/javascript">
 $("#new_img").on('change', function (e) {
  var ac_img_id = '<?php echo $pro_id;?>';
  if (e.target.files) {
   let imageFile = e.target.files[0];
   var reader = new FileReader();
   reader.onload = function (e) {
     var img = document.createElement("img");
     img.onload = function (event) {
      var canvas = document.createElement("canvas");
      var MAX_WIDTH = 300;
      var MAX_HEIGHT = 300;
      var width = img.width;
      var height = img.height;

      if (width > height) {
        if (width > MAX_WIDTH) {
         height *= MAX_WIDTH / width;
         width = MAX_WIDTH;
       }
     } else {
       if (height > MAX_HEIGHT) {
        width *= MAX_HEIGHT / height;
        height = MAX_HEIGHT;
      }
    }
    canvas.width = width;
    canvas.height = height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, width, height);
    var dataurl = canvas.toDataURL(imageFile.type);
    $.ajax({
     type: "POST",
     url: "../itemstock/item_db.php",
     data: ({ac_img_id: ac_img_id,dataurl:dataurl}),
     cache:false,
     success:function(data){

     }
   });

    document.getElementById("img_data").src = dataurl;
  }
  img.src = e.target.result;
}
reader.readAsDataURL(imageFile);

}
});

 $('.new_Btn').click(function() {
   $('#new_img').click();
 });
</script>