<?php
$permission  = explode(',',$_SESSION['permission_id']);
$sub_permission  	= explode(',',$_SESSION['sub_permission_id']);

if(!in_array(3,$permission) && !in_array(1,$permission)  ){

?>
<script>
window.location="starter.php";
</script>
<?php
}
?>
<style >
	tfoot {
    display: table-header-group !important;
	}

	.dataTable {
        font-size: 11.5px;
	}

	.thumb img:not(.media-preview) {
    height: 100px;
}

</style>

	
	<div id="loader_modal" class="modal fade" style="display: none;">
		<div class="modal-dialog modal-lg">
				<div class="modal-content">
					
					
					<div class="modal-body" >
						<h1>
							
							<i class="icon-spinner3 spinner position-left" style="font-size: 40px;"></i>
							<span id="loader_msg"></span>
						</h1>	
					</div>
				
					
				</div>
		</div>
	</div>
	


	<div class="row">
										
		<div class="col-sm-6 col-md-12">
			<div class="panel panel-body">
				<div class="media no-margin">
					<div class="media-body">
						<div class="col-sm-12">
							<h1 class="bg-info text-center">Report Options</h1>
						</div>
						<div class="col-sm-4">
								<label> First Date</label>
							
								<input class="form-control" type="date" name="first_date" id="first_date">

						</div>

						<div class="col-sm-4">
							<label> Second Date</label>
							
							<input class="form-control" type="date" name="second_date" id="second_date">
					
						</div>


						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Branch</label>
							<select name="branch_id_fk" id="branch_id_fk" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<?php if($_SESSION['profile_type'] > 0){ ?>
						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Category</label>
							<select name="category_id_fk" id="category_id_fk" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Customer</label>
							<select name="customer_id" id="customer_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Salesman</label>
							<select name="saleman_id" id="saleman_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Supplier</label>
							<select name="supplier_id" id="supplier_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Loaners</label>
							<select name="loaner_id" id="loaner_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>


						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Owners</label>
							<select name="owner_id" id="owner_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>

						<div class="form-group form-group-material1 col-sm-4" >

							<label class="control-label animate">Products</label>
							<select name="product_id" id="product_id" class="form-control"  data-live-search="true">
								
							</select>
						</div>

					<?php } ?>
						
					</div>

					<div class="row">

						<?php if(in_array(1,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="customer_filter_btn" type="button" class="btn bg-success-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Customer Account Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(2,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="product_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter" class="multi_lang">Products Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(3,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="purchase_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter" class="multi_lang">Purchase Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(4,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="supplier_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter" class="multi_lang">Supplier Payments Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(5,$sub_permission)  ){ ?>
						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="expenses_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter" class="multi_lang">Expenses Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(6,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="sell_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Sell Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(7,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="profit_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Profit Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(8,$sub_permission)  ){ ?>


						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="loaner_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Loan Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(9,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="assets_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Assets Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(10,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

							<button id="owner_filter_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Owner Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(11,$sub_permission)  ){ ?>
						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="safe_btn" type="button" class="btn bg-teal-400 btn-labeled btn-block"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Safe Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(12,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="sold_product_btn" type="button" class="btn bg-orange-400 btn-labeled btn-block" data-popup="tooltip" data-original-title="Filter Work with First Date, Second Date, Branch, Category, Customer, Saleman and Products"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Sold Product Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(13,$sub_permission)  ){ ?>
						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="saleman_btn" type="button" class="btn bg-orange-400 btn-labeled btn-block" data-popup="tooltip" data-original-title="Filter Work with First Date, Second Date, Branch, Saleman"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Saleman Recieved Payments Filter</span> </button>
							
						</div>

						<?php } ?>
						<?php if(in_array(14,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="sold_product_detail_btn" type="button" class="btn bg-danger-400 btn-labeled btn-block" data-popup="tooltip" data-original-title="Filter Work with First Date, Second Date, Branch, Category, Customer, Saleman and Products"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Sold Product Full Details Filter</span> </button>
							
						</div>

						<?php } ?>


						<?php if(in_array(15,$sub_permission)  ){ ?>

						<div class="col-sm-3" style="margin-top: 10px;">

						
							<button id="sold_return_detail_btn" type="button" class="btn bg-danger-400 btn-labeled btn-block" data-popup="tooltip" data-original-title="Filter Work with First Date, Second Date, Branch, Category, Customer, Saleman and Products"><b><i class="icon-filter4"> </i></b> <span id="inv_filter">Return Product Full Details Filter</span> </button>
							
						</div>

						<?php } ?>
						

						<div class="col-sm-3" style="margin-top: 10px;">

							

							<a href="index.php?p=report"  class="btn bg-pink-400 btn-labeled btn-block"><b><i class="icon-close2"> </i></b> <span id="inv_filter">ازالة الفلتر</span> </a>
							
						</div>

						



					</div>

					
				</div>
			</div>
		</div>
		
	</div>




	


	<!-- Individual column searching (text inputs) -->
	<div class="panel panel-flat">
		
		<table id="table1" style="display: none;" class="table datatable-column-search-inputs table-bordered ">
			<thead>
				<tr class="bg-blue-300">
	        		<th>ID</th>
					<th class="multi_lang">Invoice No.</th>
					<th class="multi_lang">Amount</th>
					<th class="multi_lang">Date</th>
					<th class="multi_lang">Transaction</th>
					<th class="multi_lang">Name</th>
					<th class="multi_lang">Saleman</th>
					<th class="multi_lang"> Branch </th>
					<th class="multi_lang"> Note </th>
	        		<!-- <th class="multi_lang" width="10%">Action</th> -->
	      		</tr>
			</thead>
			<tbody id="table_report">
				
			</tbody>
			<tfoot>
				<tr class="alpha-info">
	                <td></td>
	                <td class="multi_lang">Total Price</td>
	                <td id="total_invoice"></td>
	                <td></td>
	                <td></td>
	                
	                <td></td>
	                <td></td>
	                <td></td>
	                <td></td>
	                <!-- <td></td> -->
	                
	                
	            </tr>
			</tfoot>
		</table>


		<table id="table2" style="display: none;" class="table datatable-column-search-inputs table-bordered ">
			<thead>
				<tr class="bg-blue-300">
	        		<th>ID</th>
					<th class="multi_lang">Bill No.</th>
					<th class="multi_lang">Amount</th>
					<th class="multi_lang">Date</th>
					<th class="multi_lang">Transaction</th>
					<th class="multi_lang">Type</th>
					<th class="multi_lang">Staff</th>
					<th class="multi_lang"> Branch </th>
					<th class="multi_lang"> Note </th>
	        		<!-- <th class="multi_lang" width="10%">Action</th> -->
	      		</tr>
			</thead>
			<tbody id="table_report_safe">
				
			</tbody>
			<tfoot>
				<tr class="alpha-info">
	                <td></td>
	                <td class="multi_lang">Total In to Safe</td>
	                <td id="total_in"></td>
	               	<td class="multi_lang">Total Out from Safe</td>
	                <td id="total_out"></td>
	                
	                <td></td>
	                <td></td>
	                <td></td>
	                <td></td>
	                <!-- <td></td> -->
	                
	                
	            </tr>
			</tfoot>
		</table>
	</div>
	<!-- /individual column searching (text inputs) -->



<script type="text/javascript" src="controllers/report.js?random=<?php echo uniqid(); ?>"></script>