<?php include 'topmost.php';
if(isset($_SESSION['editProdInfo'])){
   $view_sel_prod =  getProduct($_SESSION['editProdInfo']);
}
?>
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="">
<meta name="author" content="">

    <title>Outlet App v2.0</title>
    <?php  include 'toplinks.php';  ?>
    <style>.hide{ display:none; } .smSize{font-size:10px;}</style>
</head>
<body id="page-top"><div id="wrapper"><?php  include 'menus.php';  ?>

        

<?php include 'top.php';   ?>



                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                <div class="container-fluid">

                    <!-- Page Heading -->
                    <div class="d-sm-flex align-items-center justify-content-between mb-4">
<?php  include 'greet.php';  ?><?php  include 'process.php';  ?>
<!-- <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>  -->
                    </div>

                   

                  

                    <div class="row">

  <?php 
  if(isset($_GET['view_load_hstory'])){ $pI = getProduct($_SESSION['sel_product']);
if(isset($_POST['loadHist'])){ 
    if(isset($_POST['itemBranch']) and !empty($_POST['itemBranch'])){
        $brch_code ="and branch_code='".$_POST['itemBranch']."'";
    }else{ $brch_code='';}

  $query = "SELECT * FROM storekeeper where item_name ='{$_SESSION['sel_product']}' and item_date BETWEEN '{$_POST['from']}' AND '{$_POST['to']}' $brch_code   ORDER BY item_date ASC";

$supply_historySet =$_POST['from'].'-'.$_POST['to'].' '.get_branch_name($_POST['itemBranch']).' '.$pI['item_name'].'-'.$colored_by[$pI['color']].'-'.$sized_by[$pI['size']].' '.$brand[$pI['brand']].' from '.$company[$pI['company']];

}else{
 $query ="SELECT * FROM storekeeper where item_name ='{$_SESSION['sel_product']}'  ORDER BY item_date ASC "; 
 $supply_historySet =$pI['item_name'].'-'.$colored_by[$pI['color']].'-'.$sized_by[$pI['size']].' '.$brand[$pI['brand']].' from '.$company[$pI['company']];
}
  ?>                 
<div class="col-xl-12 col-lg-12"><div class="card shadow mb-4">             
 <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-success text-white"><h5 class="m-0 font-weight-bold text-white">STOCK SUPPLY FOR <span class="text-dark"><?php echo $pI['item_name'].'-'.$colored_by[$pI['color']].','.$sized_by[$pI['size']].' '.$brand[$pI['brand']].' from '.$company[$pI['company']]; ?></h5>
<div class="dropdown no-arrow"> <button class="btn btn-dark btn-sm text-white" id="exportSupplyHist"><i class="fa fa-file-excel small"> Export CSV</i></button>&nbsp; &nbsp; <button class="btn btn-warning btn-sm text-white" data-toggle="modal" data-target="#load_history"><i class="fa fa-filter smSize"> Filter</i></button></div></div>             
<div class="card-body">

<div class="row d-block d-md-none">
<?php  $zip =1;;foreach(QueryDB($query)as $pop){?>
    <div class="col-md-12 mt-1 mb-2" style="box-shadow: 5px 4px 10px gray;min-height:80px;border-top:6px solid green;border-radius: 2px;padding-bottom:5px;">
        <div class="row">
<div class="col-8"><span style="font-size:20px;"><b><?php echo getProductName($pop['item_name']);  ?></b></span>
   <br> <b><?php  echo $sized_by[$pI['size']].','.$colored_by[$pI['color']];  ?></b>
</div>  <div class="col-4 mt-1">
<a href="" data-toggle="modal" data-target="#eStockV<?php echo $zip;  ?>" class="btn btn-warning small text-white btn-sm"><i class="fa fa-edit"></i></a>

    <span class="bg-dark text-white badge"><?php echo $zip;  ?></span></div>  
<div class="col-12"><?php  echo $company[$pI['company']].', '.$brand[$pI['brand']];  ?></div>
<div class="col-5 small"><b>Supply Date:</b> <?php  echo @$pop['item_date'];  ?></div>
<div class="col-2 small"><b>Qty:</b> <?php  echo @abs($pop['item_qty']);  ?></div>
<div class="col-5 small"><b>Branch:</b> <?php  if(empty(@get_branch_name($pop['branch_code']))){ echo 'WHS STOCK';}else{echo get_branch_name($pop['branch_code']);} ?></div>
<div class="col-12 small" style="font-size:17px;"><b>Total Cost of Supply:</b> <span class="text-danger"> &#8358;<?php  echo number_format($pI['item_cost']*abs($pop['item_qty']),2);  ?></span></div>

<div class="modal fade" id="eStockV<?php echo $zip;  ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog modal-center modal-sm" role="document"><div class="modal-content"><div class="modal-header bg-secondary text-white"><h5 class="modal-title small" id="exampleModalLabel">#Edit Supply Quantity</h5><button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body"><form action="" method="POST"><input type="hidden" name="where" value="<?php echo $pop['load_code']; ?>"><p class="text-center text-danger"><?php echo $sized_by[$pI['size']].' - '.getProductName($pop['item_name']).','.$colored_by[$pI['color']].' <br/>'.$brand[$pI['brand']].' from '.$company[$pI['company']];  ?></p>
    <div class="row"><div class="form-group col-md-12"><input type="text" name="Newsize" class="form-control" value="<?php echo abs($pop['item_qty']); ?>" required placeholder=""></div><div class="form-group col-md-12"><input type="submit" name="editLoaded" value="Add" class="form-control btn btn-secondary"></div></div></form></div></div></div></div>

</div></div><?php $zip++; } ?>
</div>







<div class="table-responsive d-none d-md-block">
<table class="table table-bordered std_table supplyHist" id="dataTable"width="100%" cellspacing="0"><thead><tr class="small"><th>#</th><th class="hide">Item Name</th><th class="hide">Size</th><th class="hide">Color</th><th class="hide">Category</th><th class="hide">Company</th><th>PRODUCT COST</th><th>SUPPLY DATE</th><th>QTY Supld</th><th>Branch Supplied</th><th>TOTAL</th><th class="noExl">Action</th></tr></thead>
<?php $zip =1; 
foreach(QueryDB($query)as $pop){
echo '<tr class="small"><td>'.$zip.'</td>
<td class="hide">'.getProductName($pop['item_name']).'</td>
<td class="hide">'.$sized_by[$pI['size']].'</td><td class="hide">'.$colored_by[$pI['color']].'</td>
<td class="hide">'.$brand[$pI['brand']].'</td><td class="hide">'.$company[$pI['company']].'</td>
<td>&#8358;'.number_format($pI['item_cost'],2).'</td><td>'.($pop['item_date']).'</td><td>'.abs($pop['item_qty']).'</td><td>';
if(empty(@get_branch_name($pop['branch_code']))){ echo 'WHS STOCK';}else{
    echo get_branch_name($pop['branch_code']);
}echo '</td><td>&#8358;'.number_format($pI['item_cost']*abs($pop['item_qty']),2).'</td>';?>

<td class="small noExl"><a href="" data-toggle="modal" data-target="#eStock<?php echo $zip;  ?>" class="btn btn-warning small text-white btn-sm"><i class="fa fa-edit"></i></a></td>

<div class="modal fade" id="eStock<?php echo $zip;  ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog modal-center modal-sm" role="document"><div class="modal-content"><div class="modal-header bg-secondary text-white"><h5 class="modal-title small" id="exampleModalLabel">#Edit Supply Quantity</h5><button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body"><form action="" method="POST">
    <input type="hidden" name="load_sel_code" value="<?php echo $pop['load_code']; ?>">
<input type="hidden" name="where" value="<?php echo $pop['id']; ?>">

    <p class="text-center text-danger"><?php echo $sized_by[$pI['size']].' - '.getProductName($pop['item_name']).','.$colored_by[$pI['color']].' <br/>'.$brand[$pI['brand']].' from '.$company[$pI['company']];  ?></p>
    <div class="row"><div class="form-group col-md-12"><input type="text" name="Newsize" class="form-control" value="<?php echo abs($pop['item_qty']); ?>" required placeholder=""></div><div class="form-group col-md-12"><input type="submit" name="editLoaded" value="Add" class="form-control btn btn-secondary"></div></div></form></div></div></div></div><?php echo '</tr>';?><?php $zip++;}?></table></div></div></div>
<?php }else if(isset($_GET['salesHistory'])){
$pSales = getProduct($_SESSION['sel_product']);
if(isset($_POST['filterSalesHistory'])){
if(isset($_POST['itemBranch']) and !empty($_POST['itemBranch'])){
        $brch_code ="and branchcode='".$_POST['itemBranch']."'";
    }else{ $brch_code='';}

$newSalesFilter = "SELECT * FROM payment where date_paid BETWEEN '{$_POST['from']}' AND '{$_POST['to']}' $brch_code GROUP BY receipt_id ORDER BY id DESC ";


$send_sales_hist =$_POST['from'].'-'.$_POST['to'].' '.get_branch_name($_POST['itemBranch']).' '.$pSales['item_name'].'-'.$colored_by[$pSales['color']].'-'.$sized_by[$pSales['size']].' '.$brand[$pSales['brand']].' from '.$company[$pSales['company']].' Sales';

}else{
    $newSalesFilter = "SELECT * FROM payment  GROUP BY receipt_id ORDER BY id DESC ";


$send_sales_hist =$pSales['item_name'].'-'.$colored_by[$pSales['color']].'-'.$sized_by[$pSales['size']].' '.$brand[$pSales['brand']].' from '.$company[$pSales['company']].' Sales';


}

?>
  <div class="col-xl-12 col-lg-12"><div class="card shadow mb-4">             
 <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-success text-white"><h6 class="m-0 font-weight-bold text-white small"># SALES HISTORY</h6>

<div class="dropdown no-arrow">
     <a  data-toggle="modal" class="btn btn-light small text-dark" style="padding:3px;" data-target="#rubOfNow"><i class="fa fa-edit text-dark"></i></a>

<button class="btn btn-dark btn-sm text-white" id="printSalesHist"><i class="fa fa-file-excel small"> Export CSV</i></button>
 <button class="btn btn-warning btn-sm text-white" data-toggle="modal" data-target="#filterSalesHistory"><i class="fa fa-filter " style="font-size:10px;"> Filter</i></button></div></div><div class="card-body">


<div class="row d-block d-md-none">
<h5 class="m-0 font-weight-bold text-center text-dark"># <span style="color:black"><?php echo getProductName($_SESSION['sel_product']).'-'.$sized_by[$pSales['size']].','.$colored_by[$pSales['color']].' '.$company[$pSales['company']].','.$brand[$pSales['brand']];  ?> </span></h5>
<?php  $ctD =1; $add_=0; $tQty=0; foreach(QueryDB($newSalesFilter)as $salesPl){
$sel_item_ = explode(',',$salesPl['item']);
    $selQty = explode(',',$salesPl['qty']);
    $selCost = explode(',',$salesPl['s_price']);
    $selTotal = explode(',',$salesPl['bulk_price']);
    $key = array_search ($_SESSION['sel_product'], $sel_item_);
if(in_array($_SESSION['sel_product'],$sel_item_)){ $add_+=$selTotal[$key];
$tQty+=$selQty[$key];
    ?>
    <div class="col-md-12 mt-1 mb-2" style="box-shadow: 8px 7px 10px gray;min-height:80px;border-radius: 2px;border-left:6px solid green;padding-bottom:5px;">
<div class="row">
   <div class="col-8"><span style="font-size:20px;"><b><?php echo strtoupper(getProductName($_SESSION['sel_product']));  ?></span></b><br> <b><?php  echo $sized_by[$pSales['size']].','.$colored_by[$pSales['color']];  ?></b></div>   
<div class="col-4 mt-1"><span class="bg-dark text-white badge"><?php echo $ctD;  ?></span></div>  
<div class="col-12"><?php  echo $company[$pSales['company']].', '.$brand[$pSales['brand']];  ?></div>
<div class="col-4 small"><b>Cost: </b><?php echo $pSales['item_cost'] ?></div>
<div class="col-3 small"><b>Qty:</b> <?php echo $selQty[$key];  ?></div>
<div class="col-5 small"><b>Total Cost:</b> <?php echo $selTotal[$key];  ?></div>
<div class="col-6">On: <?php echo $salesPl['day'];  ?></div>
<div class="col-6">By: <?php echo get_cus_Name($salesPl['cus_id']);  ?></div>
<div class="col-6">By: <?php echo get_staff_name($salesPl['onboarded']);  ?></div>
<div class="col-6">From: <?php echo get_branch_name($salesPl['branchcode']);  ?></div>
<div class="col-12 small float-right text-right">
</div>
</div></div><?php $ctD++; } } ?>

<div class="col-12"> <div class="col-md-12 row bg-dark text-white" style="box-shadow: 8px 7px 10px gray;min-height:20px;border-radius: 2px;padding-bottom:5px;">  <div class="col-8" style="font-size:20px;"><b>Total Exp: </b> &#8358;<?php echo number_format($add_,2); ?></div> <div class="col-4" style="font-size:20px;"><b>TQTY:</b> <?php echo $tQty; ?></div> </div>
  </div>
</div>











<div class="table-responsive d-none d-md-block">
<table class="table table-bordered std_table salesHist table-striped table-hover" id="dataTable"width="100%" cellspacing="0">
<h5 class="m-0 font-weight-bold text-center text-dark"># <span style="color:black"><?php echo getProductName($_SESSION['sel_product']).'-'.$sized_by[$pSales['size']].','.$colored_by[$pSales['color']].' '.$company[$pSales['company']].','.$brand[$pSales['brand']];  ?> </span></h5>
<thead><tr class="small"><th>#</th><th style="display: none;">Item Name</th><th>Category</th><th>SCOST</th><th>QTY</th><th>TCOST</th><th>DATE</th><th>BY</th><th>BILLER</th><th>Branch</th></tr></thead>
<?php $konk=1; $add_=0; $tQty=0; foreach(QueryDB($newSalesFilter)as $salesPl){
    $sel_item_ = explode(',',$salesPl['item']);
    $selQty = explode(',',$salesPl['qty']);
    $selCost = explode(',',$salesPl['s_price']);
    $selTotal = explode(',',$salesPl['bulk_price']);
    $key = array_search ($_SESSION['sel_product'], $sel_item_);
if(in_array($_SESSION['sel_product'],$sel_item_)){ $add_+=$selTotal[$key];
$tQty+=$selQty[$key];
echo '<tr class="small"><td>'.$konk.'</td><td style="display: none;">'.getProductName($_SESSION['sel_product']).'-'.$sized_by[$pSales['size']].','.$colored_by[$pSales['color']].' '.$company[$pSales['company']].'</td>
<td>'.$brand[$pSales['brand']].'</td>
<td>'.$pSales['item_cost'].'</td><td>'.$selQty[$key].'</td><td>'.$selTotal[$key].'</td><td>'.$salesPl['day'].'</td>
<td>'.get_cus_Name($salesPl['cus_id']).'</td>
<td>'.get_staff_name($salesPl['onboarded']).'</td>
<td>'.get_branch_name($salesPl['branchcode']).'</td>

</tr>';$konk++;
} }
echo '<tr class="small"><td></td><td></td><td></td><td><b>TOTAL EXP</b></td><td>'.number_format($add_,2).'</td><td></td><td></td><td>TQTY</td><td>'.$tQty.'</td><td></td></tr>'
?></table></div>


</div></div>
  <?php }else if(isset($_SESSION['editProdInfo']) and isset($_GET['new_edit_prod'])){?>  
<div class="col-md-12"><div class="card shadow mb-4"><div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-dark text-white"><h6 class="m-0 font-weight-bold text-white"># Edit Product </h6><div class="dropdown no-arrow">
<a  data-toggle="modal" class="btn btn-light small text-dark" style="padding:3px;" data-target="#rubOfNow"><i class="fa fa-edit text-dark">Edit Product</i></a>
</div></div>

<div class="card-body">

<div class="row d-block d-md-none">
<?php  $ctD =1; $counterAttack =1; foreach(QueryDB("SELECT * FROM products where id='{$_SESSION['editProdInfo']}'")as $reg_std){?>
    <div class="col-md-12 mt-1 mb-2" style="box-shadow: 8px 7px 10px gray;min-height:80px;border-radius: 2px;border-left:6px solid green;padding-bottom:5px;">
<div class="row">
   <div class="col-6"><span style="font-size:20px;"><b><?php echo strtoupper($reg_std['item_name']);  ?></span></b><br> <b><?php  echo $sized_by[$reg_std['size']].','.$colored_by[$reg_std['color']];  ?></b>


   </div>   
<div class="col-2 mt-1"><span class="bg-dark text-white badge"><?php echo $ctD;  ?></span></div>

<div class="col-4"><?php if(file_exists(explode(',',$reg_std['item_img'])[0])){
    $view_sel_img =explode(',',$reg_std['item_img'])[0];?> 
<img src="<?php echo $view_sel_img; ?>" class="img img-thumbnail" style="width:100%;height:100px"> <?php }?></div>

<div class="col-12"><?php  echo $company[$reg_std['company']].', '.$brand[$reg_std['brand']];  ?></div>
<div class="col-6 small"><b>Status: </b><?php if($reg_std['tm_status']==1){ echo '<span class="text-success"><b>Available</b></span>';}else{
    echo '<span class="text-danger"><b>Removed</b></span>';
}  ?></div>
<div class="col-6 small"><b>Added:</b> <?php echo date('d-m-Y',$reg_std['tm_added']);  ?></div>
<div class="col-10 small"><b>By:</b> <?php echo get_staff_name($reg_std['loader']);  ?></div>

<div class="col-2"></div>

<div class="col-12 small img img-thumbnail mb-2 mt-2"><span class="text-danger"><?php  echo $reg_std['item_desc']; ?></span></div>

<div class="col-12 small float-right text-right">

<a  data-toggle="modal" class="text-dark btn btn-primary" style="padding:3px;" data-target="#loadimgM1"><svg xmlns="http://www.w3.org/2000/svg" height="16" width="30" viewBox="0 0 512 512"><path d="M149.1 64.8L138.7 96H64C28.7 96 0 124.7 0 160V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V160c0-35.3-28.7-64-64-64H373.3L362.9 64.8C356.4 45.2 338.1 32 317.4 32H194.6c-20.7 0-39 13.2-45.5 32.8zM256 192a96 96 0 1 1 0 192 96 96 0 1 1 0-192z"/></svg></a>


<div class="modal fade" id="loadimgM1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog" role="document">
<div class="modal-content"><div class="modal-header bg-secondary text-white"><h5 class="modal-title " id="exampleModalLabel">#Product Image - <span class="text-white"><?php echo $reg_std['item_name']; ?></span></h5><button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body">
    <div class="row">
<?php  $getImg =QueryDB("SELECT item_img FROM products WHERE id='".$reg_std['id']."' ");
        $myrows =$getImg->fetch(PDO::FETCH_ASSOC);
    if($myrows['item_img']!='') {
        for($i=0;$i<count(explode(',',$myrows['item_img']));$i++) {
    
?>

<div class="col-4"><img src="<?php  echo explode(',',$myrows['item_img'])[$i];  ?>" class="img img-thumbnail">
<center><button title="<?php  echo $reg_std['id'];  ?>" id="<?php echo $i; ?>" class="remvImgMobile"><i class="fa fa-trash text-danger"></i></button></center>
</div><?php } }?></div>

<form method='post' action='' enctype="multipart/form-data">
<input type="file" id='filesM1' class="form-control" name="files[]" multiple><br>
<input type="hidden" id="whereasM1" value="<?php echo $reg_std['id'];  ?>">
<input type="hidden" id="prevImgsM1" value="<?php if(!empty($reg_std['item_img'])){echo $reg_std['item_img'];}  ?>">
<input type="button" id="submitM1" value='Upload' class="btn btn-secondary text-white form-control"></form><div id='previewM1' class="row"></div>
</div><div class="modal-footer"><button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button></div></div></div></div>

 <a href="whrs_itemView?view_sales_history=<?php echo $reg_std['id']; ?>" class="btn btn-dark small text-dark" style="padding:3px;"><i class="fa fa-eye text-white small"> Sales History</i></a>




</div>
</div></div><?php $ctD++; $counterAttack++; } ?></div>





</div>

<div class="table-responsive d-none d-md-block">
<table class="table table-bordered std_table" id="dataTable" width="100%" cellspacing="0">
    <!-- <p class="text-center text-dark"><strong>FILTER PRODUCTS BY</strong></p> -->
<thead><tr><th>#</th><th>Name</th><th>Size</th><th>Color</th><th>Company</th><th>Category</th><th>Cost</th><th>Status</th><th>Image</th><th>Date</th><th>By</th><th>Action</th></tr></thead>

<?php $count=1;
foreach(QueryDB("SELECT * FROM products where id='{$_SESSION['editProdInfo']}'")as $reg_std){?>
<tr><td class="small text-dark"><?php echo $count++; ?></td><td class="small text-dark"><b><?php echo strtoupper($reg_std['item_name']);  ?></b>&nbsp; 
<a  data-toggle="modal" class="text-dark" style="padding:3px;" data-target="#loadimgD<?php echo $count; ?>"><svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><path d="M149.1 64.8L138.7 96H64C28.7 96 0 124.7 0 160V416c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V160c0-35.3-28.7-64-64-64H373.3L362.9 64.8C356.4 45.2 338.1 32 317.4 32H194.6c-20.7 0-39 13.2-45.5 32.8zM256 192a96 96 0 1 1 0 192 96 96 0 1 1 0-192z"/></svg></a>


<div class="modal fade" id="loadimgD<?php echo $count; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog" role="document">
<div class="modal-content"><div class="modal-header bg-secondary text-white"><h5 class="modal-title " id="exampleModalLabel">#Product Image - <span class="text-warning"><?php echo $reg_std['item_name']; ?></span></h5><button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body">
    <div class="row">
<?php  $getImg =QueryDB("SELECT item_img FROM products WHERE id='".$reg_std['id']."' ");
        $myrows =$getImg->fetch(PDO::FETCH_ASSOC);
    if($myrows['item_img']!='') {
        for($i=0;$i<count(explode(',',$myrows['item_img']));$i++) {
    
?>
<div class="col-md-4"><img src="<?php  echo explode(',',$myrows['item_img'])[$i];  ?>" class="img img-thumbnail"><center><button title="<?php  echo $reg_std['id'];  ?>" id="<?php echo $i; ?>" class="remvImg"><i class="fa fa-trash text-danger"></i></button></center>
</div>
<?php } }?>        
    </div>
<form method='post' action='' enctype="multipart/form-data">
<input type="file" id='files1' class="form-control" name="files[]" multiple><br><input type="hidden" id="whereas1" value="<?php echo $reg_std['id'];  ?>">
<input type="hidden" id="prevImgs1" value="<?php if(!empty($reg_std['item_img'])){echo $reg_std['item_img'];}  ?>"><input type="button" id="submit1" value='Upload' class="btn btn-secondary text-white form-control"></form>
<div id='preview1' class="row"></div></div><div class="modal-footer"><button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button></div></div></div></div>


</td><td class="small text-dark">
<?php echo $sized_by[$reg_std['size']];  ?></td>
<td class="small text-dark"><?php echo $colored_by[$reg_std['color']];  ?></td>
<td class="small text-dark"><?php echo $company[$reg_std['company']];  ?></td>
<td class="small text-dark"><?php echo $brand[$reg_std['brand']];  ?></td>
<td class="small text-dark">&#8358; <?php echo $reg_std['item_cost'];  ?></td>
<td class="small"><?php if($reg_std['tm_status']==1){ echo '<span class="text-success"><b>Available</b></span>';}else{echo '<span class="text-danger"><b>Removed</b></span>';
}  ?></td>
<td><?php if(file_exists(explode(',',$reg_std['item_img'])[0])){
    $view_sel_img =explode(',',$reg_std['item_img'])[0];?> 

<img src="<?php echo $view_sel_img; ?>" class="img img-thumbnail" style="width:100%;height:100px"> <?php }?></td>

<td class="small"><?php echo date('d-m-Y',$reg_std['tm_added']);  ?></td><td class="small"><?php echo get_staff_name($reg_std['loader']);  ?></td>

<td class="small text-dark">
<a href="whrs_itemView?view_sales_history=<?php echo $reg_std['id']; ?>" class="btn btn-dark small text-dark" style="padding:3px;"><i class="fa fa-eye text-white"></i></a></td></tr>

<?php  } ?></table></div>


</div></div><!--end Col-md-12-->

  <?php } ?>                    
                       
                    </div>

                    <!-- Content Row -->
               

                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->

            <!-- Footer -->
        <?php  include 'bottom_most.php'; 
if(empty($send_sales_hist)){ $send_sales_hist='ABC';}
if(empty($supply_historySet)){ $supply_historySet='ABC';}


        ?>



<!--Edit Product Registratin-->
<div class="modal fade" id="rubOfNow" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header bg-secondary text-white"><h5 class="modal-title " id="exampleModalLabel">#Modify Product - <br/> <span class="text-white"><?php echo $view_sel_prod['item_name']; ?></span></h5><button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body">
<form action="" method="POST"><div class="row"><div class="form-group col-md-8"><input type="text" name="prodname" class="form-control" required placeholder="Product Name e.g. LK100 or 3.75KVA" value="<?php echo $view_sel_prod['item_name'];  ?>"></div>
<div class="form-group col-md-4"><input type="text" name="cost" class="form-control" required placeholder="cost" onkeypress="return isNumberKey(event)" value="<?php echo $view_sel_prod['item_cost'] ?>"></div>
<div class="col-md-12"><textarea class="form-control" placeholder="Product Description" name="item_desc" maxlength="160" minlength="10" required><?php  echo htmlspecialchars_decode($view_sel_prod['item_desc']);  ?></textarea></div>
<input type="hidden" name="where" value="<?php echo $view_sel_prod['id']; ?>">
  <div class="form-group col-md-6 mt-2"><select class="form-control" required name="company"><?php 
for($i=0;$i<count($company);$i++){?><option value="<?php  echo $i; ?>" <?php if($i==$view_sel_prod['company']){echo 'selected';}  ?>><?php echo $company[$i]; ?></option><?php }?></select></div><div class="form-group col-md-6 mt-2"><select class="form-control" required name="brand"><option value="">--Brand--</option> <?php for($i=0;$i<count($brand);$i++){?><option value="<?php  echo $i; ?>" <?php if($i==$view_sel_prod['brand']){echo 'selected';}  ?>><?php echo $brand[$i]; ?></option><?php }?></select></div>
<div class="form-group col-md-4"><select class="form-control" required name="size"><option value="">--Sized By-</option> <?php for($i=0;$i<count($sized_by);$i++){?>
<option value="<?php  echo $i; ?>" <?php if($i==$view_sel_prod['size']){echo 'selected';}  ?>><?php echo $sized_by[$i]; ?></option><?php }?><</select></div><div class="form-group col-md-4"><select class="form-control" required name="color"><option value="">--Colour--</option> <?php for($i=0;$i<count($colored_by);$i++){?>
<option value="<?php  echo $i; ?>" <?php if($i==$view_sel_prod['color']){echo 'selected';}  ?>><?php echo $colored_by[$i]; ?></option><?php }?></select></div>
<div class="form-group col-md-4"><select class="form-control" required name="tm_status"><option value="1" <?php  if($view_sel_prod['tm_status']==1){ echo 'selected';} ?>>Visible</option><option value="0" <?php  if($view_sel_prod['tm_status']==0){ echo 'selected';} ?>>Remove</option></select></div><div class="col-md-12 mt-2"><textarea class="form-control" rows="5" placeholder="Product Details" name="item_details" maxlength="160" minlength="10">
    <?php  echo htmlspecialchars_decode($view_sel_prod['item_details']); ?></textarea></div>
<div class="form-group col-md-12"><input type="submit" name="EditProduct" value="Edit Product" class="form-control btn btn-secondary"></div></div></form>
  </div><div class="modal-footer"><button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button></div></div></div></div>


<!--END-->



<script>
     var classVal = "<?php echo $send_sales_hist;   ?>";
$('#printSalesHist').on('click',function(){$(".salesHist").table2excel({exclude: ".noExl",name: "Excel Document Name",filename: classVal +'.xls',fileext:".xls",exclude_img: true,exclude_links: true,exclude_inputs: true});});


     var classVal = "<?php echo $supply_historySet;   ?>";
$('#exportSupplyHist').on('click',function(){$(".supplyHist").table2excel({exclude: ".noExl",name: "Excel Document Name",filename: classVal +'.xls',fileext:".xls",exclude_img: true,exclude_links: true,exclude_inputs: true});});
</script>

<script type="text/javascript">
//Desktop Keys
$('.remvImg').click(function(e){if(confirm('Are you Sure?')==true){e.preventDefault();
$id =$(this).attr('title'); $item =$(this).attr('id');
$.ajax({data: {item_id: $id,item_index:$item},type: "post",url: "ajaxpage",success: function(data){
    alert('Image Removed');
},error: function(jqXHR, textStatus, errorThrown) { 
$(function(){ setTimeout(function() { alert('There was an Error');}, 5000);})}
});
$(this).prop('disabled',true); $(this).html('removed');
}});

//Mobile keys
$('.remvImgMobile').click(function(e){if(confirm('Are you Sure?')==true){e.preventDefault();
$id =$(this).attr('title'); $item =$(this).attr('id');
$.ajax({data: {item_id: $id,item_index:$item},type: "post",url: "ajaxpage",success: function(data){
    alert('Image Removed');
},error: function(jqXHR, textStatus, errorThrown) { 
$(function(){ setTimeout(function() { alert('There was an Error');}, 5000);})}
});
$(this).prop('disabled',true); $(this).html('removed');
}});



$(document).ready(function(){
$('[id^=submit]').click(function(){ $id =$(this).attr('id').slice(6); var form_data = new FormData(); 
    // alert($id);
            
// Read selected files
var totalfiles = document.getElementById('files'+$id).files.length;
for (var index = 0; index < totalfiles; index++) {
form_data.append("files[]", document.getElementById('files'+$id).files[index]);}

whereAs =$('#whereas'+$id).val();   prevImgs =$('#prevImgs'+$id).val();
form_data.append('where',whereAs);  form_data.append('prevImg',prevImgs);

$.ajax({url: 'ajaxfile',type: 'post',data: form_data,dataType: 'html',contentType: false,
    processData: false,
success: function (response) { var array = response.split(",");        
for(var index = 0; index < array.length; index++) {var src = array[index];
$('#preview'+$id).append('<div class="col-md-6"><img src="'+src+'" width="90%" class="img img-thumbnail" height="250px"></div>');
}
alert('Upload was Successful');
},error: function(xhr, textStatus, error){ alert('There was a probem');
console.log(xhr.statusText);console.log(textStatus);console.log(error);
}
}); });     });


//Mobile
$(document).ready(function(){
$('[id^=submitM]').click(function(){ $id =$(this).attr('id').slice(7); 
    var form_data = new FormData(); 
            
// Read selected files
var totalfiles = document.getElementById('filesM'+$id).files.length;
for (var index = 0; index < totalfiles; index++) {
form_data.append("files[]", document.getElementById('filesM'+$id).files[index]);}

whereAs =$('#whereasM'+$id).val();   prevImgs =$('#prevImgsM'+$id).val();
form_data.append('where',whereAs);  form_data.append('prevImg',prevImgs);

$.ajax({url: 'ajaxfile',type: 'post',data: form_data,dataType: 'html',contentType: false,
    processData: false,
success: function (response) { var array = response.split(",");        
for(var index = 0; index < array.length; index++) {var src = array[index];
$('#previewM'+$id).append('<div class="col-6"><img src="'+src+'" width="90%" class="img img-thumbnail" height="250px"></div>');
}
alert('Upload was Successful');
},error: function(xhr, textStatus, error){ alert('There was a probem');
console.log(xhr.statusText);console.log(textStatus);console.log(error);
}
}); });     });

    </script>


</html>