<?php include("sass/icon_for_datepicker_and_datatable.php");?>
        
      
 
        
        
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>

            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Client Setup</li>
                    </ol>
                </section>
                 <section class="content">
                 <!---Main Content--->
                 
                     <div class="row">
                     
                 
                         
                         
                         <div class="col-md-12">
                         
                         
                         <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">Client list with due</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Client Name</th>
                                                <th>Address</th>
                                                <th>Due</th>
                                                <th>Apply</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?php
                                                
                                                $query = "SELECT * FROM customer_setup";
                                                $result = mysqli_query($connection,$query);
                                                $total_due=0;
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $customer_setup_id = $row['customer_id'];
                                                $customer_name = $row['customer_name'];
                                                $address = $row['address'];
												$due = $row['due'];
										
														
			$result_for_previous = mysqli_query($connection,"SELECT SUM(debit) as cusomer_due FROM transaction WHERE customer_id ='$customer_setup_id' AND ledger='9' and payment_type='due' ");
			
		$test_for_previous = mysqli_fetch_array($result_for_previous);
				
				$cusomer_due=$test_for_previous['cusomer_due'];
				
			
				
				
					$result_for_previous = mysqli_query($connection,"SELECT SUM(debit) as cusomer_due_payment FROM transaction WHERE customer_id ='$customer_setup_id' AND ledger='7' ");
			
		$test_for_previous = mysqli_fetch_array($result_for_previous);
				
				$cusomer_due_payment=$test_for_previous['cusomer_due_payment'];
				
				$this_customer_due = $cusomer_due - $cusomer_due_payment ;
				
					$total_due=$total_due+$this_customer_due;
                                                
                                                echo "<tr>";
                                                echo "<td>$customer_name</td>";
                                                echo "<td>$address</td>";
                                                echo "<td>$this_customer_due</td>";
                                                echo "<td>
												<a href='cus_due_payment.php?customer_setup_id=$customer_setup_id'>  <button type='button' class='btn btn-success' ><i class='fa fa-dollar'></i> Due Payment</button></a>
												</td>";
                                                echo "</tr>";
                                                }
                                                
                                                ?>
                                         
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Client Name</th>
                                                <th>Address</th>
                                                <th><?php echo $total_due ; ?></th>
                                                <th>Apply</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div><!-- /.box-body -->
                            </div>
                         
                         </div>
                     </div>
                 
                 
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
<script>
function EditProduct(id) {
    window.open('edit_customer.php?id='+id,'logos','width=500,height=500');}
</script>
  <?php include("sass/footer_for_datatable.php");?>

    </body>
</html>