<?php include 'topmost.php';?>
<!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>My Outlet</title>
    <?php  include 'toplinks.php';  ?>
</head>
<body id="page-top"><div id="wrapper"><?php  include '../inc/menus.php';  ?>

        

<?php include 'top.php';   ?>
                <!-- End of Topbar -->

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

                    <!-- Page Heading -->
                   <?php  include 'greet.php'; include 'process.php';  ?>


<?php 



 if(isset($_GET['view_setItem'])){ 
if(isset($_POST['sendFilterInv'])){  
if(!empty($_POST['from'])){ 
    $selCrs =' and item_date BETWEEN "'.$_POST['from'].'" AND "'.$_POST['to'].'" ';
    $lucas =' and date_paid BETWEEN "'.$_POST['from'].'" AND "'.$_POST['to'].'" ';
    $range ='BETWEEN '.$_POST['from'].' AND '.$_POST['to'];
 }else{$selCrs=$lucas=$range='';}
$query ="SELECT * FROM storekeeper where id!='' $selCrs ORDER by item_name DESC";
}else{
$query ="SELECT * FROM storekeeper  ORDER by item_name DESC";$selCrs=$lucas=$range='';
}?>
<div class="card shadow mb-4">  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-warning text-white"><h6 class="m-0 font-weight-bold text-dark">#INVENTORY MANAGEMENT <?php echo $range; ?></h6><div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i></a>=<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink"><a class="dropdown-item" href="#" data-toggle="modal" data-target="#fInventory"><i class="fa fa-filter text-dark"> Filter</i></a><a class="dropdown-item" href="#" id="export"><i class="fa fa-file text-dark"> Export</i></a></div></div></div><div class="card-body"><div class="table-responsive">

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead><tr><th>#</th><th>Item Name</th><th>B/C</th><th>Cost</th><th>LStk</th><th>TStock</th><th>TS</th><th>BAL</th>
    <th>Action</th></tr></thead><tbody>

<?php
$kount=1; 
foreach(QueryDB($query)as $pd){ $stk=lastStock($pd['item_name'],$selCrs);
$pInfo = getProduct($pd['item_name']);
?>
<tr><td class="small text-dark"><?php echo $kount++; ?></td><td class="small text-dark"><b><?php echo $sized_by[$pInfo['size']];  ?> - <?php echo strtoupper(getProductName($pd['item_name']));  ?>,<?php echo $colored_by[$pInfo['color']];  ?> </b></td><td class="small text-dark">
    <?php echo $brand[$pInfo['brand']];  ?>,<?php echo $company[$pInfo['company']];  ?></td>
<td class="small text-dark"><?php echo number_format($pInfo['item_cost'],2);?></td>
<td class="small text-dark">
<?php echo @date('Y-m-d',$stk['item_time']);?>&nbsp;&nbsp; (<b><?php echo @$stk['item_qty'];?></b>)</td><td class="small"><?php echo totalStock($pInfo['id'],$selCrs);  ?></td><td class="small"><?php echo getQuantity($pInfo['id'],$lucas,'');  ?></td><td class="small"><?php echo totalStock($pInfo['id'],$selCrs)-getQuantity($pInfo['id'],$lucas,'');  ?></td>


   
<td class="small text-dark"><a  data-toggle="modal" class="btn btn-warning small text-dark" style="padding:3px;" data-target="#addReged<?php echo $kount; ?>"><i class="fa fa-edit text-dark"></i></a>&nbsp;&nbsp; <a href="" class="btn btn-dark small text-dark" style="padding:3px;"><i class="fa fa-eye text-white"></i></a></td></tr>

<?php  } ?></tbody></table>




                            </div></div></div> <!--end of card-->
<?php }else if(isset($_GET['view_load_hstory'])){ ?>
<div class="card shadow mb-4">  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-warning text-white"><h6 class="m-0 font-weight-bold text-danger"># <?php echo getProductName($_SESSION['sel_product']); ?> LOAD HISTORY</h6></div></div><div class="card-body"><div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead><tr><th>#</th><th>Item Name</th><th>B/C</th><th>Cost</th><th>date</th><th>QTY</th></tr></thead>
<?php $zip =1; 
$pI = getProduct($_SESSION['sel_product']);
foreach(QueryDB("SELECT * FROM branch_store where item_name ='{$_SESSION['sel_product']}' and branch_code='$my_branch_code' ORDER BY item_date ASC ")as $pop){
echo '<tr><td>'.$zip.'</td><td>'.$sized_by[$pI['size']].' - '.getProductName($pop['item_name']).','.$colored_by[$pI['color']].'</td>
<td>'.$brand[$pI['brand']].','.$company[$pI['company']].'</td>
<td>'.number_format($pI['item_cost'],2).'</td><td>'.($pop['item_date']).'</td><td>'.($pop['item_qty']).'</td>';?>

<?php echo '</tr>';?><?php $zip++;}?></table>

<?php }else if(isset($_GET['salesHistory'])){ 
    $pSales = getProduct($_SESSION['sel_product']);
if(isset($_POST['filterSalesHistory'])){
$newSalesFilter = "SELECT * FROM payment where date_paid BETWEEN '{$_POST['from']}' AND '{$_POST['to']}' and branchcode='$my_branch_code' GROUP BY receipt_id ORDER BY id DESC ";
}else{
    $newSalesFilter = "SELECT * FROM payment where branchcode='$my_branch_code' GROUP BY receipt_id ORDER BY id DESC ";
}
?>
<div class="card shadow mb-4">  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-primary text-white"><h6 class="m-0 font-weight-bold text-white"># <span style="color:yellow"><?php echo $sized_by[$pSales['size']].'-'.getProductName($_SESSION['sel_product']).','.$colored_by[$pSales['color']];  ?> </span>SALES HISTORY</h6>
    <div class="dropdown no-arrow">
<button data-toggle="modal" data-target="#filterSalesHistoryBranch" class="btn btn-warning btn-sm"><i class="fa fa-filter text-dark"> Filter</i></button>

</div></div><div class="card-body"><div class="table-responsive">

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<h3 class="m-0 font-weight-bold text-center text-dark"># <span style="color:black"><?php echo $sized_by[$pSales['size']].'-'.getProductName($_SESSION['sel_product']).','.$colored_by[$pSales['color']];  ?> </span></h3>

<thead><tr class="small"><th>#</th><th>Item Name</th><th>SCOST</th><th>QTY</th><th>BCOST</th><th>DATE</th><th>BY</th><th>BILLER</th></tr></thead>
<?php $konk=1; $addAll = 0; $allQty=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_)){
echo '<tr class="small"><td>'.$konk.'</td><td>'.$sized_by[$pSales['size']].'-'.getProductName($_SESSION['sel_product']).','.$colored_by[$pSales['color']].'</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>
</tr>';$konk++; $addAll+=$selTotal[$key]; $allQty+=$selQty[$key];
}
}?>
<tr><td></td><td></td><td></td><th>TOTAL QTY</th><td><?php echo $allQty; ?></td><td></td><th>TOTAL</th><td>&#8358;<?php echo number_format($addAll,2); ?></td></tr>
</table>
   <?php }else if(isset($_GET['staffs'])){?>
<div class="card shadow mb-4">  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-primary text-white"><h6 class="m-0 font-weight-bold text-white">#STAFF ARRAY</h6><div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i></a>=<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink"><a class="dropdown-item" href="#" data-toggle="modal" data-target="#fInventory"><i class="fa fa-filter text-dark"> Filter</i></a><a class="dropdown-item" href="#" id="export"><i class="fa fa-file text-dark"> Export</i></a></div></div></div><div class="card-body"><div class="table-responsive">

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead><tr><th>#</th><th>NAME</th><th>Acct Type</th><th>Gender</th><th>Llast</th><th>Acct Status</th><th>Action</th></tr></thead>

<?php
$stkk=1;  
foreach(QueryDB("SELECT * FROM login")as $stf){?>
<tbody><tr><td class="small text-dark"><?php echo $stkk++; ?></td><td class="small text-dark"><b><?php echo strtoupper($stf['name']);  ?></b></td><td class="small text-dark"><?php echo actType(strtoupper($stf['position']));  ?></td>
<td class="small text-dark">
    <?php echo (strtoupper($stf['sex']));  ?></td>
<td class="small text-dark"><?php echo date('d-m-Y h:i:s',$stf['lastlog']);?></td>
<td><?php if($stf['acct_status']==1){  echo 'Active'; }else{ echo 'Inactive';}?></td>
<td class="small text-dark"><a href="" data-toggle="modal" data-target="#viewStaff<?php echo $stkk; ?>"><i class="fa fa-edit"></i></a></td></tr>

<div class="modal fade" id="viewStaff<?php echo $stkk; ?>" 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 Staff</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="form-group col-md-12">
<input type="text" required name="username" id="username" readonly placeholder="username"  class="form-control" value="<?php echo $stf['username']; ?>"></div>
<input type="hidden" name="where" value="<?php echo $stf['id'];  ?>" readonly>
<div class="form-group col-md-12">
<input type="text" required name="name"   placeholder="Full Name"  class="form-control" value="<?php echo $stf['name']; ?>"></div><div class="form-group col-md-12">
<select name="act_type" class="form-control" required><option value="1" <?php if($stf['position']==1){ echo 'selected';} ?>>Attendant</option><option value="2" <?php if($stf['position']==2){ echo 'selected';} ?>>Manager/Admin</option></select></div>
<div class="form-group col-md-12">
<select name="gender" class="form-control" required><option value="M"
    <?php if($stf['sex']=='M'){ echo 'selected';} ?>>Male</option><option value="F" <?php if($stf['sex']=='F'){ echo 'selected';} ?>>Female</option></select></div>
    <div class="form-group col-md-12">
<select name="status" class="form-control" required><option value="1"
    <?php if($stf['acct_status']==1){ echo 'selected';} ?>>Active</option><option value="F" <?php if($stf['acct_status']==2){ echo 'selected';} ?>>Inactive</option></select></div>
<input type="submit" name="adStfedit" value="Edit" class="form-control btn btn-warning col-md-12"></form></div></div></div></div>

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



 <?php }else if(isset($_GET['view_cust_trans'])){?>
<div class="card shadow mb-4">  <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between bg-primary text-white"><h6 class="m-0 font-weight-bold text-white">#Customer Purchase History - <?php echo get_cus_Name($_SESSION['sel_cust']); ?></h6></div><div class="card-body"><div class="table-responsive">

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
    <div style="font-size:25px; text-align: center;">TOTAL PURCHASE:<b>&#8358;<?php echo  number_format(get_my_purchase($_SESSION['sel_cust'],'amt_paid',1) + get_my_purchase($_SESSION['sel_cust'],'out_standing',0)); ?></b> &nbsp; TOTAL PAYMENT: <strong><?php echo  number_format(get_my_purchase($_SESSION['sel_cust'],'amt_paid',1),2);?></strong>&nbsp; TOTAL DEBT: <?php echo  number_format(get_my_purchase($_SESSION['sel_cust'],'out_standing',0),2); ?></div>
<thead><tr><th>#</th><th>Date</th><th>Description</th><th>Total Amount</th><th>TPaid</th><th>TBAL</th><th>Biller</th></tr></thead>

<?php
$stkk=1; 
foreach(QueryDB("SELECT * FROM payment where cus_id ='{$_SESSION['sel_cust']}' GROUP BY receipt_id ORDER BY id DESC")as $cusView){?>
<tbody><tr><td class="small text-dark"><?php echo $stkk++; ?></td><td class="small text-dark"><b><?php echo $cusView['day'];  ?></b></td><td class="small text-dark">



<table class="table table-bordered">
    <?php for($k=0;$k<count(explode(',',$cusView['item']));$k++){
        echo '<tr><td>'.getProductName(explode(',',$cusView['item'])[$k]).'</td><td>'.explode(',',$cusView['qty'])[$k].'</td><td>'.explode(',',$cusView['s_price'])[$k].'</td><td>'.explode(',',$cusView['bulk_price'])[$k].'</td></tr>';
    }
?></table></td>
<td class="small text-dark">
    <?php echo number_format(strtoupper($cusView['amt']),2);  ?></td>
<td class="small text-dark"><?php echo number_format(get_total_payment($cusView['receipt_id'],'amt_paid',1));?></td><td class="small text-dark">
    <?php echo number_format(get_total_payment($cusView['receipt_id'],'out_standing',0));?></td>
<td><?php echo get_staff_name($cusView['onboarded']);?></td></tr>
<?php  } ?></tbody></table>
 </div></div></div>





 <?php }else{ $query ="SELECT * FROM products ORDER by item_name DESC";$selCrs=$lucas=$range='';?>
<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">#INVENTORY MANAGEMENT</h6><div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink"data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i></a>=<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink"><a class="dropdown-item" href="#" data-toggle="modal" data-target="#fInventory"><i class="fa fa-filter text-dark"> Filter</i></a><a class="dropdown-item" href="#" id="export"><i class="fa fa-file text-dark"> Export</i></a></div></div></div><div class="card-body"><div class="table-responsive">

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead><tr class="small"><th>#</th><th>Item Name</th><th>S/C</th><th>B/C</th><th>Cost</th><th>LStk</th><th>TStock</th><th>TS</th><th>BAL</th><th>Action</th></tr></thead><tbody>

<?php
$count=1; 
foreach(QueryDB($query)as $reg_std){ //$stk=lastStock($reg_std['id'],'');
$stk= lastStock_perBranch($reg_std['id'],'','',$my_branch_code);

?>
<tr><td class="small text-dark"><?php echo $count++; ?></td><td class="small text-dark"><b><?php echo strtoupper($reg_std['item_name']);  ?></b></td><td class="small text-dark"><?php echo $sized_by[$reg_std['size']];  ?>,<?php echo $colored_by[$reg_std['color']];  ?></td><td class="small text-dark">
    <?php echo $brand[$reg_std['brand']];  ?>,<?php echo $company[$reg_std['company']];  ?></td>
<td class="small text-dark"><?php echo number_format($reg_std['item_cost'],2);?></td>
<td class="small text-dark">
<?php echo @date('Y-m-d',$stk['item_time']);?>&nbsp;&nbsp; (<b><?php echo @$stk['item_qty'];?></b>)</td>
<td class="small"><?php echo totalStock_branch($reg_std['id'],'','',$my_branch_code);  ?></td><td class="small"><?php echo getQuantity_Branch($reg_std['id'],'','',$my_branch_code);  ?></td><td class="small"><?php echo totalStock_branch($reg_std['id'],'','',$my_branch_code)-getQuantity_Branch($reg_std['id'],'','',$my_branch_code);  ?></td>
<td class="small text-dark">
    
<a href="?view_sales_history=<?php echo $reg_std['id']; ?>" class="btn btn-primary small text-white">SlsHist</a>
    &nbsp;<a href="?sel_product=<?php echo $reg_std['id']; ?>" class="btn btn-dark btn-xs small text-light">StkHist</a></td></tr>





<?php  } ?></tbody></table>



 


 </div></div></div> <!--end of card-->
<?php  } ?>














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

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


<?php  include 'bottom_most.php'; ?>
</body>

</html>