<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
         $stdt=$_POST['stdt'];
         $enddt=$_POST['enddt'];
         $trn_ac=$_POST['trn_ac'];
         $dbarea=$_POST['dbarea'];
         $csadded=$_SESSION['murgibhai'];
         $getlog=f(q("SELECT * FROM tbl_login WHERE l_uid='$csadded'"));
         $ltype=$getlog['l_type'];
         $getdbarea=f(q("SELECT * FROM tbl_login WHERE l_uid='$dbarea'"));
         $getac=f(q("SELECT * FROM tbl_ledger WHERE lid='$trn_ac'"));
         //echo $ltype;
        //echo $trn_ac;
      //  echo $dbarea;
         if($trn_ac!=0){
            if($ltype==1){
               if($dbarea!='0'){
                  $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_ac='$trn_ac' AND trn_user='$dbarea' AND trn_date BETWEEN '$stdt' AND '$enddt'";

                  $title="Expense Report of " .$getac['lname']. " from ".$stdt." to ".$enddt." of ".$getdbarea['l_name'];
               }else{

                  $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_ac='$trn_ac' AND trn_date BETWEEN '$stdt' AND '$enddt'";
                  $title="Expense Report of " .$getac['lname']. " from ".$stdt." to ".$enddt;
               }
               

            }else{

               $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND  trn_user='$csadded' AND trn_ac='$trn_ac' AND trn_date BETWEEN '$stdt' AND '$enddt'";
               $title="Expense Report of " .$getac['lname']. " from ".$stdt." to ".$enddt." of ".$getlog['l_name'];
            }
            
           
         }else{
              // echo "tuki";
               $title="Expense Report from ".$stdt." to ".$enddt;
    
               if($ltype==1){

                  if($dbarea!='0'){
                    // $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_ac='$trn_ac' AND trn_user='$dbarea' AND trn_date BETWEEN '$stdt' AND '$enddt'";
                     $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_user='$dbarea' AND trn_date BETWEEN '$stdt' AND '$enddt'";
                     $title="Expense Report from ".$stdt." to ".$enddt." of ".$getdbarea['l_name'];
                  }else{
   
                     $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_date BETWEEN '$stdt' AND '$enddt'";
                     //$title="Expense Report from ".$stdt." to ".$enddt." of".$getdbarea['l_name'];
                     //echo "title";
                  }
                 
   
               }else{
   
                  $sql="SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC'  AND trn_user='$csadded' AND trn_date BETWEEN '$stdt' AND '$enddt'";
                  $title="Expense Report from ".$stdt." to ".$enddt." of ".$getlog['l_name'];
               }
              
         }

         //echo $sql;
         ?>
      <title><?=$title?></title>
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/jquery.dataTables.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/dataTables.bootstrap4.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/responsive.dataTables.css">
      <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
      <style type="text/css">
      table{

         width: 100%;
      }
      th{

      font-size: 14px !important;
      min-width: 60px;
      padding: 10px;
      text-align: center;
      background-color: #e5eef5;
      color: #5c5c5c;
      border-right: 1px solid white;
      -webkit-print-color-adjust: exact; 
    }
    td{

      font-size: 12px !important;
      text-align: center;
      border: 1px solid gray;

    }
    tr{

      width: 100%;

    }
    .trtot{

      background-color: #e5eef5;
      color: #5c5c5c;
    }
    .noborder{

      border:0px white;
    }
   </style>
   <style type="text/css" media="print">
  @page { size: landscape; }
</style>
   </head>
   <body style="padding: 3%;">
      <table>
         <tr>
            
            <td class="noborder" style="width: 25%"></td>
            <td class="noborder" style="width: 50%;">
                  
               <h5><?=$title?></h5>


            </td>
            <td class="noborder" style="width: 25%"></td>

         </tr>

   </table><br><br>
      <table class="stripe hover">
         <thead>
            <tr>
               <th class="table-plus datatable-nosort">Sl. No</th>
               <th>Login User</th>
               <th>Date</th>
               <th>AC</th>
               <th>Details</th>
               <th>Amount</th>
               
               
            </tr>
         </thead>
         <tbody>
            <?
               $query=mysqli_query($con,$sql);
               while($arrc=mysqli_fetch_array($query)){$c++;
                $getac=f(q("SELECT * FROM tbl_ledger WHERE lid='$arrc[trn_Ac]'"));
                     $totale=floatval($totale)+floatval($arrc['trn_amt']);
                     $getu=f(q("SELECT * FROM tbl_login WHERE l_uid='$arrc[trn_user]'"));
               ?>
            <tr>
               <td class="table-plus"><?=$c?></td>
               <td><?=$getu['l_name']?></td>
               <td><?=$arrc['trn_date']?></td>
               <td><?=$arrc['trn_name']?></td>
               <td><?=$arrc['trn_memo']?></td>
               <td><?=$arrc['trn_amt']?></td>
               
               
            </tr>
            <?}?>	
            <tr>
               <td class="table-plus"></td>
               <td></td>
               <td></td>
               <td></td>
               <td><b>Total: </b></td>
               <td><?=$totale?></td>
               
               
            </tr>
         </tbody>
        
      </table><br><br>
      <?php include('include/script.php'); ?>
      <script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
      <script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
      <!-- buttons for Export datatable -->
      <script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
      <script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
      <script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
      <script>
         $('document').ready(function(){
         	$('.data-table').DataTable({
         		scrollCollapse: true,
         		autoWidth: false,
         		responsive: true,
         		columnDefs: [{
         			targets: "datatable-nosort",
         			orderable: false,
         		}],
         		"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
         		"language": {
         			"info": "_START_-_END_ of _TOTAL_ entries",
         			searchPlaceholder: "Search"
         		},
         	});
         	$('.data-table-export').DataTable({
         		scrollCollapse: true,
         		autoWidth: false,
         		responsive: true,
         		columnDefs: [{
         			targets: "datatable-nosort",
         			orderable: false,
         		}],
         		"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
         		"language": {
         			"info": "_START_-_END_ of _TOTAL_ entries",
         			searchPlaceholder: "Search"
         		},
         		dom: 'Bfrtip',
         		buttons: [
         		'copy', 'csv', 'pdf', 'print'
         		]
         	});
         	var table = $('.select-row').DataTable();
         	$('.select-row tbody').on('click', 'tr', function () {
         		if ($(this).hasClass('selected')) {
         			$(this).removeClass('selected');
         		}
         		else {
         			table.$('tr.selected').removeClass('selected');
         			$(this).addClass('selected');
         		}
         	});
         	var multipletable = $('.multiple-select-row').DataTable();
         	$('.multiple-select-row tbody').on('click', 'tr', function () {
         		$(this).toggleClass('selected');
         	});
         });
      </script>
      <script type="text/javascript"></script>
   </body>
</html>

