<?php
@session_start();
@ob_start();
include "header.php";
?>

<!-- Page wrapper  -->
        <div class="page-wrapper">
           
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
							
							<h3 style=" margin-bottom:-50px;">Sale List <span style="float:right"><a href="sales_alter.php" class="btn btn-block btn-primary" name="add_ward" style="width:100px; float:right; margin-bottom:0px;">Add</a></span>&nbsp;</h3>
	 
                              
                                <div class="table-responsive m-t-40">

  
 <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
		 <thead>
  <tr>
    <th><strong>Sales Date</strong></th>
    <th><strong>Invoice No. </strong></th>
	 <th><strong>Client Name </strong></th>
     <th><strong>Client Contact No. </strong></th>
     <th ><strong>Cancel Invoice</strong> </th>
     <th><strong>Return</strong></th>
     
     <th ><strong>Print 1st Reciept Only </strong></th>
    
   </tr>
  </thead>
  <tbody>
  <?php 
    $q = "SELECT * FROM view_sales_master where session_login_id = '".$_SESSION['login_id']."' order by id desc";
	 $query = mysql_query($q);
  while($row=mysql_fetch_array($query)){  
     
	$salesmas_id=$row["id"];
	 $sqlact="select actual_amt,count(id) as cont from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and (sales_type= 'Sales'  or sales_type= 'Sales_Due')  order by id";
	$exeact=mysql_query($sqlact);
	$rsact=mysql_fetch_array($exeact);
	 $act_amt=$rsact["actual_amt"];			
  ?>
  <tr>
    <td><?php echo $objIms->IntToDate($row["stampdate"]);?></td>
	<td><?php echo $row["sale_no"];?></td>
    <td><?php echo $row["client_name"];?></td>
	 <td><?php echo $row["contact_no"];?></td>
	 <td style="width:2px" ><?php if($rsact["cont"]==1){?><a href="sales_cancel.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-danger">Cancel Invoice</a><?php }?></td>
	 <td style="width:2px" ><a href="sales_return.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-success">Return</a></td>
	
	 <td style="width:2px" ><a href="sales_reciept.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-primary">Print</a></td>
	 
	<?php  $sqlpaid="select sum(Dr_Amt) as paid_amt from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales'";
	$exepaid=mysql_query($sqlpaid);
	$rspaid=mysql_fetch_array($exepaid);
	 $totamt=$rspaid["paid_amt"];
	
	?>
	 
    </tr>

	<?php }?>
	 </tbody>
</table>
</div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>
 <script src="../js/lib/datatables/datatables.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="../js/lib/datatables/cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <script src="../js/lib/datatables/datatables-init.js"></script>		