<?php    include_once('../config/db.php');  include_once('../config/check.php'); 

if (filter_has_var(INPUT_POST, "deleteinv")) 
try{
    //   $deleteinv =        htmlspecialchars ( strtoupper($_POST['deleteinv']));
      
    //     $transtype =       10; 
    //     $transaction =     1; 
    //     $transmode =      3 ;
    //     $lastid =  $deleteinv;

    //     $stmt = $conn->prepare("DELETE FROM acctransactions  WHERE id=?   ");
    //     $stmt->execute([$deleteinv]);

    //     $stmt = $conn->prepare("DELETE FROM acctransactionsdetails  WHERE transid=?   ");
    //     $stmt->execute([$deleteinv]);

        
    //     audittrail($conn,$lastid,$transtype,$transaction,$transmode,$uid,$storeID);
    
      header("location:invoices.php"); 

  } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}




?>


<!DOCTYPE html>
<html>
<head>
 
<?php include_once('../inc/slink.php');   ?>  

</head>


<body <?php include_once('../inc/snav.php');  ?>>
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
       <?php include_once('../inc/sbrand.php');   ?>

    <!-- Header Navbar -->
    <?php include_once('../inc/snavbar.php');   ?>

  </header>
 
  <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
     <?php include_once('../inc/smenu.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
   

        <section class="content-header">
          <!-- <div class="col-md-12 "> -->
            <div class="col-md-3"><p  class="listheader" > <i class="fa fa-calendar" ></i>  ITEMS SOLD </p></div>  
            <div class="col-md-3" class="mybtn" id="mybtn"  ></div>  
            <div class="col-md-6">
                 <div class="col-md-6" id="mysearchbox"></div>   
                 <div class="col-md-2">
                    <input type="text" id="min" name="min" placeholder="start date" class="form-control" >
                 </div>               
                 <div class="col-md-2">
                  <input type="text" id="max" name="max"  placeholder="End date" class="form-control" >
                 </div> 

            </div>
        </section>

        <!-- Main content -->
        <section class="content container-fluid">
          <div class="col-md-12">
              <div class="box  box-xs">
                <div class="box-body">
                  <table id="customer_data" width="100%" class="table display compact  table-small table-responsive ">
                    <thead >
                      <tr >
                      <th >  </th>
                      <th >  </th>
                      <!-- <th >  </th>  
                      <th >  </th>   -->
                      <th > Branch_Name </th>                  
                      <th > Sale_Type </th>                  
                      <th > Sale_Date  </th>
                      <th > Doc_No  </th>
                      <th > Memo </th>
                      <th > Customer_Full_Name </th>
                      <th > Product_Full_Name </th>
                      <th > UOM </th>
                      <th > Units </th>
                      <th > Price </th>
                      <th > Total </th>
                   
                     
                      </tr>
                    </thead>                      
                  </table>
                </div>
              </div>
          </div>
        </section>
      <!-- END Main content -->

  
  
</div>
  <!-- /.content-wrapper -->
  
  <!-- Main Footer -->
  <footer class="main-footer">
    <?php  include_once('../inc/sfooter.php'); ?>
  </footer>
  
</div>
                         
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->
<?php  include_once('../inc/slinkjs.php') ?>


</body>
</html>

<script>


   var minDate, maxDate;
 
// Custom filtering function which will search data in column between two values
$.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
        var min = minDate.val();
        var max = maxDate.val();
        var date = new Date( data[4] );
 
        if (
            ( min === null && max === null ) ||
            ( min === null && date <= max ) ||
            ( min <= date   && max === null ) ||
            ( min <= date   && date <= max )
        ) {
            return true;
        }
        return false;
    }
);

$(document).ready(function() {

   minDate = new DateTime($('#min'), {
        format: 'MMMM Do YYYY'
    });
    maxDate = new DateTime($('#max'), {
        format: 'MMMM Do YYYY'
    });
    


                    var table= $('#customer_data').DataTable( {
                         "scrollX": true,
                         "language": {
                                             searchPlaceholder: "Search here",
                                             search: "" },
                         "dom": '<"top"f>rt<"bottom"ilp><"clear">',
                         ajax: {
                              url: '../filter/sale/itemsold.php'
                         }
                    } );

                    // Refilter the table on date search
                         $('#min, #max').on('change', function () {
                              table.draw();
                         });

                    codeListTable = $("#customer_data").DataTable();
                         new $.fn.dataTable.Buttons( codeListTable, {
                         buttons: [
                         
                              {
                              extend:    'excel',
                              text:      '<i class="fa fa-files-o"></i> Excel',
                              titleAttr: 'Excel',
                              className: 'btn btn-default btn-sm',
                              exportOptions: {
                                   columns: ':visible'
                              }
                              },
                              {
                              extend:    'pdf',
                              text:      '<i class="fa fa-file-pdf-o"></i> PDF',
                              titleAttr: 'PDF',
                              className: 'btn btn-default btn-sm',
                              exportOptions: {
                                   columns: ':visible'
                              }
                              },               
                              {
                              extend:    'print',
                              text:      '<i class="fa fa-print"></i> Print',
                              titleAttr: 'Print',
                              className: 'btn btn-default btn-sm',
                              exportOptions: {
                                   columns: ':visible'
                              }
                              },  
                         ]
                    } );
                    
                    codeListTable.buttons().container().appendTo('#mybtn');    
                    $(".dataTables_filter").detach().appendTo("#mysearchbox");
                    $(".dataTables_length").detach().appendTo("#mylength");


     });
</script>





