<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$addurl="make-payment.php";
if($_SESSION['role_id']==1){
$result=$con->query("SELECT save_order.vendor_id,SUM(save_order.grand_total)-SUM(save_order.commission) as total,save_order.payment_mode
FROM save_order WHERE save_order.payment_mode='basispay' and save_order.job_status='2' GROUP BY save_order.vendor_id");
}else{
$vendor_id=$_SESSION['userid'];    
$result=$con->query("SELECT save_order.id,save_order.vendor_id,sum(order_item.service_total) as total,save_order.payment_mode
FROM save_order LEFT JOIN order_item on save_order.id = order_item.order_id
WHERE vendor_id IN($vendor_id) and save_order.payment_mode='basispay' and save_order.job_status='2' GROUP BY save_order.vendor_id");    
}
?>
<!-- Datatable CSS -->
<link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' /> <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="#">Online Payment</a></li>           
                    </ol>                
            </section>
            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Online Payment</h3>
                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                                <i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                                <i class="fa fa-times"></i></button>
                        </div>
                    </div>
                    <?php if(isset($_SESSION["vensucc_msg"])) {?>
                 <div class="alert alert-success">
                 <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                 <?php echo $_SESSION["vensucc_msg"];  unset($_SESSION["vensucc_msg"]);?>
                 </div>
                <?php }?>   
                <?php if(isset($_SESSION["venerr_msg"])) {?>
                <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
                <?php echo $_SESSION["venerr_msg"]; unset($_SESSION["venerr_msg"]);?>
                </div>
<?php }?>		
                    <div class="box-body">    
                        <!-- Table -->
                        <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
							    <th>S.No</th>
                                <th>Vendor Name</th>                        
                                <th>Payment Mode</th>              
                                <th>Total</th>  
                                <th>Action</th>
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                            $vendor_id=$row['vendor_id'];
                            $result_child=$con->query("SELECT SUM(vendor_payment.amount) as amount FROM vendor_payment WHERE vendor_payment.vendor_id='$vendor_id' GROUP BY vendor_payment.vendor_id");
                            $venrow=mysqli_fetch_array($result_child);
                            ?>
						   <tr>
						   <td><?php echo $i;?></td>
						   <td><?php echo $row['vendor_id'];?></td>
						   <td><?php echo $row['payment_mode'];?></td>
						   <td><?php echo ($row['total']-$venrow['amount']);?></td>
						   <td><a href="<?php echo $base_url.$addurl;?>?vendor_id=<?php echo $row['vendor_id'];?>"" class="btn btn-success">Make Payment</a></td>
						    </tr>								  
							 <?php $i++;}}?>
                           </tbody>							
                        </table>
                    </div>
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src="js/datatables.js"></script>    
<script src="<?php echo $base_url;?>js/lobibox.js"></script>  
<?php require_once('includes/footer.php'); ?>