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

if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}



include("user.php");
$sub=1;
$dayBookDate2=date('Y-m-31');
$dayBookDate1=date('Y-m-01', strtotime($dayBookDate1. ' - 1 years'));

if (isset($_POST['day_submit'])) {
	$dayBookDate1=$_POST['date1'];
	$dayBookDate2=$_POST['date2'];
	$sub=2;
}




?>


<!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">

    <title>Invoice List</title>

    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">

    <!-- Styles -->
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/data-table/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/unix.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
</head>

<body>

    <?php include("sidebar.php"); ?>
	
	
    <!-- /# sidebar -->
     <?php include("top.php"); ?>
	<!-- /# topebar --> 




    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                
                <!-- /# row -->
                <section id="main-content">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
                                <div class="row">
                    <div class="col-lg-8 p-r-0 title-margin-right">
                        <div class="page-header">
                            <div class="page-title">
                                <h1>Invoice List</h1>
                            </div>
                        </div>
                    </div>
					
                    <!-- /# column -->
                    <div class="col-lg-4 p-l-0 title-margin-left">
                        <div class="page-header">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li>
                                    <li class="active">Invoice List</li>
                                </ol>
                            </div>
                        </div>
                    </div>
					            
	<div class="row-form clearfix">
	

	
	
					       <form action='pos_invoice_list_deleted.php'  method='POST'> 
                          
                                    <div class="col-sm-12"> 
						   
							<table>
							<tr>
							<td>
							From <input class="date" type="date" value="<?php echo $dayBookDate1; ?>" name="date1" id="datetimepicker2"/>
							</td>
							<td>
							To <input class="date" type="date"  value="<?php echo $dayBookDate2; ?>" name="date2" id="datetimepicker2"/>
							</td>
							
							
							<td> 
							<input class="submit" type="submit"  name="day_submit"  value="Search" /> 
							</td>
							
							</tr>
							</table>
						    
						   </div>
						     
</form>
</div>
                    <!-- /# column -->
                </div>
                                <hr>
								
								   
                                <div class="bootstrap-data-table-panel">
								
								
								
								
								
                                    <div class="table-responsive">
									
									
                                        <table id="bootstrap-data-table-export" class="table table-striped table-bordered">
                                            <thead> 
                                                <tr>
                                                    <th>Invoice No</th>
                                                    <th>Invoice Date</th>
                                                    <th>Customer</th>
													<th>Notes</th>
                                                    <th>Amount</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											
											
											<?php 
											$sl=0;
                                $sqlSelectedLG = "select t1.*,IFNULL(t4.paid,0) paid,(t1.inv_amount-IFNULL(t4.paid,0) ) as due, t2.id, t2.date, t2.customer_id,t2.notes, t2.added_at, t2.updated_at,t3.name c_name from (SELECT invoice_id, sum(total) inv_amount FROM `invoice_items_deleted` group by invoice_id order by invoice_id desc) as t1 left join invoices_deleted as t2 on t1.invoice_id=t2.inv_id left join bookings as t3 on t2.customer_id=t3.id left join (SELECT inv_id, sum(amount) paid FROM `transactions` where type=2 GROUP by inv_id) as t4 on t1.invoice_id=t4.inv_id where (date(t2.date) BETWEEN '$dayBookDate1' AND '$dayBookDate2' ) ";
								
								

                               $sqlSelectedLG = mysqli_query($connection, $sqlSelectedLG);


                               while ($list = mysqli_fetch_object($sqlSelectedLG)) {

                                 $invoice_id = $list->invoice_id;
								 $inv_amount = $list->inv_amount;
								 $paid_amount = $list->paid;
								 $due_amount = $list->due;
								 $idn = $list->id;
								 $date = $list->date;
								 $date = date("d-m-Y", strtotime($date));
								 $customer_id = $list->customer_id;
								 $customer_name = $list->c_name;
								 $added_at = $list->added_at;
								 $updated_at = $list->updated_at;
								 
								 
								 $notes = $list->notes;
								
								$inv_amount=IND_money_format($inv_amount);
								
									?>
                                              <tr  id="<?php echo $invoice_id ?>">
                                                     <td><?php echo  $invoice_id;  ?></td>
                                                    <td><?php echo  $date;  ?></td>
                                                    <td><?php echo $customer_name; ?></td>
                                                    <td><?php echo $notes;  ?></td>
                                                    <td><?php echo $inv_amount;  ?></td>
                                                </tr>
												
							   <?php }			?>
                                            </tbody>
                                        </table>
                                    </div>
									
								
									
									
                                </div>
                            </div>
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                    </div>
                  <?php include("footer.php"); ?>
                </section>
            </div>
        </div>
    </div>



    <div id="search">
        <button type="button" class="close">×</button>
        <form>
            <input type="search" value="" placeholder="type keyword(s) here" />
            <button type="submit" class="btn btn-primary">Search</button>
        </form>
    </div>
     <!-- jquery vendor -->

    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
   

    <script src="assets/js/scripts.js"></script>
    <!-- scripit init-->
    <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.dataTables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>
	

	
</body>

</html>