<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

$active_cus=501;

 // Common Information

$page_title="All Customers Information";
$page="41_customer_add.php?active_id=".$active_cus."&menu_id=".$menu_id."";
$table='accounts_reference';	
$unique='ref_no';

// End Common Information


?>




<!DOCTYPE html>
<html lang="en">

<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->

<body>

  <!-- ======= Header ======= -->
  <?php 
  require_once('inc_files/inc_header.php');
  ?><!-- End Header -->

  <!-- ======= Sidebar ======= -->
   <?php  require_once('inc_files/inc_menu.php'); ?>
   <!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">Sales Management</li>
          <li class="breadcrumb-item active"><?php echo $page_title?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section">
      <div class="row">
	  
	  
	  <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
             
			 <br>

              <!-- No Labels Form -->
              <form class="row g-3" action="" method="post" name="codz" id="codz">
                
       
                <div class="col-md-5"><strong><?php echo $page_title;?></strong></div>
                
				<div class="col-md-2">&nbsp;</div>
				
				<div class="col-md-3">&nbsp;</div>
				
				<div class="col-md-2" align="right">
				<a href="41_customer_add.php?active_id=501&menu_id=5"><button type="button" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i> New Customer&nbsp;&nbsp;&nbsp;</button></a>
				</div>
                
              </form><!-- End No Labels Form -->

            </div>
          </div>
		
		</div>
	  
	  
        <div class="col-lg-12">

          <div class="card">
            <div class="card-body">
             
			 <br>
			  
			

              <!-- Multi Columns Form -->
             
			  
			  
			  
			  <table class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; font-size:12px; color:#012970;  background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="13%" scope="col">Code</th>
                    <th width="29%" scope="col"> <span role="heading" aria-level="2">Customer Name </span><span data-dojo-attach-point="_betaButton"> </span> <span data-qbo-bind="visible:!zeroStateEnabled">
                    <div data-dojo-attach-point="_pagePrimaryActions">
                      <div data-dojo-attach-point="_customersGuidedTour"></div>
                      <div> </div>
                      <div>
                        <div data-dojo-attach-point="page-primary-action" data-extension-point="general-extension/page-primary-action"></div>
                      </div>
                      <div> </div>
                      <div> </div>
                      <div id="taxReportsButton" data-dojo-attach-point="taxReportsButton"></div>
                      <div> </div>
                    </div>
                    </span> </th>
                    <th width="20%" scope="col">Mobile</th>
                    <th width="18%" scope="col">Type</th>
                    <th width="20%" scope="col"><div style="text-align:right">Balance</div></th>
                  </tr>
                </thead>
                <tbody>
		<?php
		
		$_POST['tdate'] = date('Y-m-d');
		
		 $sql = "select ledger_id, ref_no, sum(dr_amt-cr_amt) as closing_amt from journal where jv_date <='".$_POST['tdate']."' group by ledger_id, ref_no";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $closing_amt[$info->ledger_id][$info->ref_no]=$info->closing_amt;
		 }
					
					//if($_POST['item_type']!='')
					//$con=" and item_type='".$_POST['item_type']."'";
					
					//if($_POST['item_category']!='')
					//$con=" and item_category='".$_POST['item_category']."'";
					
		$sql = "select id, customer_type from customer_type where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $customer_type[$info->id]=$info->customer_type;
		 }
					
						$sql = 'select * from accounts_reference where ref_type=2 '.$con.' order by ref_type,ref_no';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
				
                 <tr>
                   <td><a href="<?php echo $page;?>&<?php echo $unique;?>=<?php echo $data->ref_no;?>" style="color:#000000"><?php echo $data->ref_no;?></a></td>
                   <td><?php echo $data->display_name;?></td>
                   <td><?php echo $data->mobile_no;?></td>
     			   <td><?php echo $customer_type[$data->customer_type];?></td>
 				   <td align="right">
				   <a href="61_sales_07.php?show=show&tdate=<?=$_POST['tdate']?>&acc_reference=<?=$data->ref_no.' :: '.$data->display_name?>" target="_blank" style="text-decoration:none; ">
				   <?php 
				    $closing_balance=$closing_amt[$data->ledger_id][$data->ref_no]; $tot_closing_amt +=$closing_amt[$data->ledger_id][$data->ref_no];
				    if($closing_balance>0) echo number_format($closing_balance,2).' (Dr)'; elseif($closing_balance<0) echo number_format(((-1)*$closing_balance),2).' (Cr)';else echo "0.00";
				   ?></a>
				   </td>
                 </tr>
				  <?php }?>
				  
				  <tr>
                   <td>&nbsp;</td>
                   <td><strong>TOTAL</strong></td>
                   <td>&nbsp;</td>
     			   <td>&nbsp;</td>
 				   <td align="right">
				   <strong>
				   <?php if($tot_closing_amt>0) echo number_format($tot_closing_amt,2).' (Dr)'; elseif($tot_closing_amt<0) echo number_format(((-1)*$tot_closing_amt),2).' (Cr)';else echo "0.00";?>
				   </strong>
				   </td>
                 </tr>
                </tbody>
              </table>
                
				
		
			
				
				
				
                
		
			
            
                
                
                
              <!-- End Multi Columns Form -->

            </div>
          </div>

        </div>

        
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
 <?php require_once('inc_files/inc_footer.php'); ?>
<!-- ======= Footer ======= -->

</body>

</html>