<?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 '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>

                    <!-- Content Row -->


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

                    <div class="row d-block d-md-none">

                        
                            <div class="card shadow mb-4 col-md-12">
                                <!-- Card Header - Dropdown -->
 <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">LAST FIVE ONLINE TRANSACTION (PAID AND UNPAID)</h6></div></div>
                            
<?php $addAmt=0; foreach(QueryDB("SELECT * FROM payment WHERE type=2 order by id desc limit 5")as $tycom){
            $item = explode(',',$tycom['item']);
            $sPrice = explode(',',$tycom['s_price']);
            $bulkPrice = explode(',',$tycom['bulk_price']);
            $qty = explode(',',$tycom['qty']);
            $biller =@getBiller($tycom['id']);
            $bill_org =@explode(',',$biller['organization']);
    ?>
<div class="col-md-4">
<div class="card shadow mb-4" style="box-shadow:5px 5px 30px gray;">
  <div class="card-header <?php if($tycom['pay_status']==1){ echo 'bg-secondary'; }else{
    echo 'bg-danger';
  }  ?> text-white" style="height:70px;">
<div class="row">
<div class="col-md-8 small"><h6 class="m-0 font-weight-bold text-white">  
 <i class="fa fa-user"></i> <?php  echo get_cus_Name($tycom['cus_id']); echo '<br/>'.date('d, M Y h:i:s A',$tycom['time_paid']);  ?></h6></div> 
  <div class="col-md-4 small"><p><b>Status: </b>
<?php   if($tycom['pay_status']==1){  echo '<span class="text-white">Paid</span>';
}else{echo '<span class="text-warning">Pending</span><br/>';
echo $tycom['day'];} ?></p></div></div></div>
<div class="card-body">
<div class="row">
<?php  for($a=0;$a<count($item);$a++){ $viewProduct = getProduct($item[$a]);?>
<div class="col-md-12 font-weight-bold"><?php  echo getProductName($item[$a]).' '.$sized_by[$viewProduct['size']].' '.$colored_by[$viewProduct['color']].','.$company[$viewProduct['company']].' - '.$brand[$viewProduct['brand']];  ?></div> 
<div class="col-md-6"><b>Price: </b><?php echo $sPrice[$a]; ?></div>
<div class="col-md-6"><b>Qty: </b><?php echo $qty[$a]; ?>x</div>
<div class="col-md-12"><b>Total: &#8358;</b><?php echo number_format($bulkPrice[$a],2);
$addAmt+=$bulkPrice[$a];
 ?></div>
<div style="height:1px;border:1px solid gray;width:100%;" class="mb-2 mt-2 col-md-12"></div>
<?php  } ?>
<div class="col-md-12 text-right text-danger"><span><b>TOTAL: &#8358;</b></span><?php echo number_format($addAmt,2);  $addAmt=0;?>  </div>
</div>
<div class="row">
    <div class="col-md-12 text-success"><strong>WAYBILL</strong></div>
<div class="col-md-12"><b>Receiver:</b> <?php  echo @$bill_org[0];  ?> (<?php  echo @$bill_org[3];  ?>)</div>
<div class="col-md-6"><?php  echo @$bill_org[1];  ?></div>
<div class="col-md-6"><?php  echo @$bill_org[2];  ?></div>
<div class="col-md-12"><?php  echo @$bill_org[7].' '.@$bill_org[6].' '.@$bill_org[5].','.@$bill_org[4];?></div>
<div class="col-md-12"><strong>Notes:</strong> <?php  echo @$bill_org[8];  ?></div>    
</div>

</div>  

<div class="card-footer bg-success">
    <div class="row">
<div class="col-md-12"><h5 class="text-white">Trnx ID: <?php echo $tycom['receipt_id'];  ?></h5></div>
<div class="col-md-9 col-9"><p class="text-white">Method: <?php echo @pay_MTH($tycom['pay_mth']);  ?> </p> </div>

<div class="col-md-3 col-3"><?php if($tycom['pay_status']==1){
echo '<a href="../receeipts?no='.$tycom['receipt_id'].'"><i class="fa fa-print text-white"></i></a></td>
';}else{?>
<a class="text-white btn btn-primary btn-sm" href="?apprPay=<?php echo $tycom['id']; ?>&rep_id=<?php echo $tycom['receipt_id']; ?>" onclick="return confirm('Are you sure of this payment?');">Appr</a>
<?php }  ?></div>

    </div>
   
 
</div>



</div></div><!--/col-md-4-->


<?php  } ?>     

</div><!-- Content Row Mobile-->

<div class="row d-none d-md-block"><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">#LAST FIVE TRANSACTIONS</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="#filterPay"><i class="fa fa-filter text-dark"> Filter</i></a>
<button class="dropdown-item" id="export"><i class="fa fa-file text-dark"> Export</i></button>
</div></div></div>
<div class="card-body">


<?php 
if(isset($_POST['search'])){ 
$debt_status =1;
extract($_POST);

if(empty($list_month)){$month='';}else{$month='and month='.$_POST['list_month'];}
if(empty($pchs_type)){$pchs_type='';}else{$pchs_type='and type='.$_POST['pchs_type'];}
if(empty($biller)){$biller='';}else{$biller='and branchcode="'.$_POST['biller'].'"';}
if(empty($date_paid)){$date_paid='';}else{
    $date_paid='and date_paid="'.$_POST['date_paid'].'"';}
if(empty($yr)){$yr='';}else{$yr='and year='.$_POST['yr'];}

 $query = ("SELECT * FROM payment where id!=''  $yr $pchs_type $month $biller $date_paid  and type=2 ORDER BY id DESC LIMIT 5  ");

$totalPay=QueryDB("SELECT SUM(amt_paid) as tPay FROM payment where id!=''  $yr $pchs_type $month $biller $date_paid and type=2   ");
$row = $totalPay->fetch(PDO::FETCH_ASSOC);$endPay =  $row['tPay'];

$msg ='MONTH: <b class="text-danger">'.monthName($_POST['list_month']).'</b> YEAR: <b class="text-danger">'.$_POST['yr'].'</b> Customer Type: <b class="text-danger">'.@get_cus_type($_POST['pchs_type']).'</b> Billed By: <b class="text-danger">'.@get_staff_name($_POST['biller']).'</b> DATE: <b class="text-danger">'.$_POST['date_paid'].'</b>';

}else{
$query = ("SELECT * FROM payment  where  type=2 ORDER BY id DESC LIMIT 5 ");
$totalPay=QueryDB("SELECT SUM(amt_paid) as tPay FROM payment where type=2");
$row = $totalPay->fetch(PDO::FETCH_ASSOC);
$endPay =  $row['tPay'];
     $msg ='General';
     $debt_status =1;
}


    ?>
<table class="table table-bordered table2excel table-responsive" id="dataTable" width="100%" cellspacing="0">
    <h5 class="text-center text-dark"><?php  echo @$msg; ?></h5>
    <h4 class="text-center mt-3">ALL TIME PAYMENT: <strong> &#8358;<?php echo number_format($endPay,2);  ?></strong></h4>
    <thead ><tr class="small"><th>S/N</th><th>NAME</th><th>ITEM</th><th>SCOST</th><th>TCOST</th><th>TAMT</th><th>PAID</th><th>MTH</th><th>DATE</th><th class="small">Spl Branch</th><th>Print</th></tr></thead>
    
<?php  $count= 1;
foreach(QueryDB($query) as $rows){
echo '<tr class="small" style="font-weight:bolder"><td>'.$count.'</td>
<td >'.get_cus_Name($rows['cus_id']).' </td><td>';
for($k=0;$k<count(explode(',',$rows['item']));$k++){ 
    $thisP = getProduct(explode(',',$rows['item'])[$k]);
echo $sized_by[$thisP['size']].'-'.getProductName(explode(',',$rows['item'])[$k]).','.$colored_by[$thisP['color']].' '.$company[$thisP['company']].','.$brand[$thisP['brand']].'
 ('.explode(',',$rows['qty'])[$k].')<br/>';
}echo '</td><td>';for($k=0;$k<count(explode(',',$rows['qty']));$k++){
echo (explode(',',$rows['s_price'])[$k]).'<br/>';
}echo '</td><td>';
for($k=0;$k<count(explode(',',$rows['item']));$k++){
echo (explode(',',$rows['bulk_price'])[$k]).'<br/>';
}echo '</td>';


echo '<td>'.number_format($rows['amt'],2).'</td><td>'.number_format($rows['amt_paid'],2).'</td><td>'.@pay_MTH($rows['pay_mth']).'</td><td>'.($rows['date_paid']).'</td>
<td>'.get_branch_name($rows['branchcode']).'</td>
<td>'; if($rows['pay_status']==1){
echo '<a href="../receeipts?no='.$rows['receipt_id'].'"><i class="fa fa-print"></i></a></td>
';}else{?>
<a href="?apprPay=<?php echo $rows['id']; ?>&rep_id=<?php echo $rows['receipt_id']; ?>" onclick="return confirm('Are you sure of this payment?');">Appr</a>
<?php } $count++;}

echo '</tr>';
?></tbody></table>


</div><!--/card body-->

</div>
  </div><!--col-md-12--></div>
               

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

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

            <!-- Footer -->
        <?php  include 'bottom_most.php'; ?>

<div class="modal fade" id="filterPay" 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 " id="exampleModalLabel">#Filter Payment</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 col-12 mt-3"><select class="form-control" name="pchs_type">
<?php foreach(QueryDB("SELECT * FROM category where status =1 and id=2 ") as $rows){
  echo '<option value='.$rows['id'].'>'.$rows['type'].'</option>'; } ?>
</select></div>
<div class="form-group col-md-12 col-12 mt-3"><select class="form-control" name="list_month"><option value="">-Select-</option><option value="1">January</option><option value="2">February</option><option value="3">March</option><option value="4">April</option><option value="5">May</option><option value="6">June</option><option value="7">July</option><option value="8">August</option><option value="9">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select></div>
<div class="form-group col-md-12 col-12 mt-3"><input type="text" placeholder="Year" name="yr" class="form-control" maxlength="4" minlength="4" onkeypress="return isNumberKey(event)"></div>
<div class="form-group col-md-12 col-12 mt-3"><input type="date" placeholder="date Paid" name="date_paid" class="form-control" ></div>
<div class="form-group col-md-12 col-12 mt-3"><select class="form-control" name="biller"><option value="">-Supplied Branch-</option><?php foreach(QueryDB("SELECT * FROM branch ") as $rows){echo '<option value="'.$rows['id'].'">'.$rows['shrt_name'].'</option>'; } ?></select></div><div class="form-group col-md-12 col-12 mt-3"><input type="submit" value="Filter" name="search" class="form-control btn btn-primary"></div>
</form></div></div></div></div>


</body>

</html>