<?php
session_start();
require("php_con.php");
//require("check_user.php");
if(isset($_COOKIE['user_id'])){
$head_user_qury=mysqli_query($connation,"SELECT * FROM user_details WHERE user_id='$_COOKIE[user_id]'");
$head_user_resalt=mysqli_fetch_array($head_user_qury);
}
else{
	echo "<script>window.location='logout';</script>";
	exit();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title><?php echo $system_name; ?></title>
<link rel="stylesheet" href="main_css.css">
	
<script src="data_table/js/jquery-3.5.1.js"></script>
<script src="data_table/js/jquery.dataTables.min.js"></script>
<script src="data_table/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="data_table/css/bootstrap.css">
<link rel="stylesheet" href="data_table/css/dataTables.bootstrap4.min.css">
	
<link rel="stylesheet" href="icon/css/font-awesome.css">
<link rel="stylesheet" href="icon/css/font-awesome.min.css">
	
<link rel="stylesheet" href="alert/sweetalert2.min.css">
<script src="alert/sweetalert2.min.js"></script>
<link rel="stylesheet" type="text/css" href="select2/core.css">
</head>

<body>
<script>
window.addEventListener("load",function(){
	var load_screen=document.getElementById('load_screen');
	document.body.removeChild(load_screen);
});
</script>

<div id="load_screen"><div id="loading"><img src="image/loading.gif" width="80px;"></div></div>
	
<?php require("header.php"); ?>
	
<div class="contaner">
	

	
<strong>Report</strong>

	
<div class="row mt-4">
	
<?php if($head_user_resalt['user_type']==1){ ?>
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Day End Report</b>	
<hr>
<form method="post" action="report-day-end" autocomplete="off" target="_blank">
	
<select name="user" required="required" class="form-control form-control-sm mb-2" id="user">
<option value="" hidden="yes">Select User</option>
<option value="all">All User</option>
<?php 
$user_qury=mysqli_query($connation,"SELECT * FROM user_details ORDER BY CONCAT(user_fname,' ',user_lname) ASC");
while($user_resalt=mysqli_fetch_array($user_qury)){
?>
<option value="<?php echo $user_resalt['user_id']; ?>"><?php echo $user_resalt['user_fname']; ?> <?php echo $user_resalt['user_lname']; ?></option>
<?php } ?>
</select>
	
<input name="end_date" type="date" required="required" class="form-control form-control-sm mb-2" id="end_date" value="<?php echo $current_date; ?>">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>
</div>	
</div>
<?php } ?>

<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Total Stock Report</b>	
<hr>
<form method="post" action="total-stock" autocomplete="off" target="_blank">
<select name="product_supplier" required="required" class="form-control form-control-sm mb-2" id="product_supplier1">
<option value="" hidden="yes">Select Supplier</option>
<option value="all">All Supplier</option>
<?php 
$supplier_qury=mysqli_query($connation,"SELECT * FROM supplier_details ORDER BY supplier_name");
while($supplier_resalt=mysqli_fetch_array($supplier_qury)){
?>
<option <?php if(isset($_GET['product_id'])){if($edit_resalt['product_supplier']==$supplier_resalt['supplier_id']){echo "selected";}} ?> value="<?php echo $supplier_resalt['supplier_id']; ?>"><?php echo $supplier_resalt['supplier_name']; ?> - <?php echo $supplier_resalt['supplier_company']; ?> <?php echo "0".(int)$supplier_resalt['supplier_mobile']; ?></option>
<?php } ?>
</select>
<input name="run_date" type="datetime-local" required="required" class="form-control form-control-sm mb-2" id="run_date" value="<?php echo date("Y-m-d\TH:i:s"); ?>">
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
<button type="button" class="btn btn-light btn-sm w-100 mt-2" onClick="all_stock_report_run();">Download CSV</button>
</form>
</div>	
</div>
<script>
function all_stock_report_run(){
	let product_supplier=document.getElementById('product_supplier1').value;
	if(product_supplier==""){
		alert('Please select supplier');
	}
	else{
	window.location='excle_all_stock.php?product_supplier='+product_supplier;
	}
}
</script>

<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Low Stock Report</b>	
<hr>
<form method="post" action="low-stock" autocomplete="off" target="_blank">
<select name="product_supplier" required="required" class="form-control form-control-sm mb-3" id="product_supplier2">
<option value="" hidden="yes">Select Supplier</option>
<option value="all">All Supplier</option>
<?php 
$supplier_qury=mysqli_query($connation,"SELECT * FROM supplier_details ORDER BY supplier_name");
while($supplier_resalt=mysqli_fetch_array($supplier_qury)){
?>
<option <?php if(isset($_GET['product_id'])){if($edit_resalt['product_supplier']==$supplier_resalt['supplier_id']){echo "selected";}} ?> value="<?php echo $supplier_resalt['supplier_id']; ?>"><?php echo $supplier_resalt['supplier_name']; ?> - <?php echo $supplier_resalt['supplier_company']; ?> <?php echo "0".(int)$supplier_resalt['supplier_mobile']; ?></option>
<?php } ?>
</select>
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
<button type="button" class="btn btn-light btn-sm w-100 mt-2" onClick="low_stock_report_run();">Download CSV</button>
</form>
</div>
</div>
<script>
function low_stock_report_run(){
	let product_supplier=document.getElementById('product_supplier2').value;
	if(product_supplier==""){
		alert('Please select supplier');
	}
	else{
	window.location='excle_low_stock.php?product_supplier='+product_supplier;
	}
}
</script>
	
<?php if($head_user_resalt['user_type']==1){ ?>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-warning">
<b>Main summary report</b>	
<hr>
	
<form method="post" action="report_month_summery" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Profit report</b>	
<hr>
	
<form method="post" action="report_sale_profit" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Product wise Profit report</b>	
<hr>
	
<form method="post" action="report_product_wise_sale" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">

<select name="product_id" required="required" id="product_id" class="form-control form-control-sm" style="border: none;">
<option value="" hidden="yes">Select</option>
<?php
$p_qury=mysqli_query($connation,"SELECT * FROM product_details
ORDER BY product_name");
while($p_resalt=mysqli_fetch_assoc($p_qury)){
?>
<option value="<?php echo $p_resalt['product_id']; ?>"><?php echo $p_resalt['product_barcode']; ?> - <?php echo $p_resalt['product_name']; ?></option>
<?php } ?>
</select>
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Outstanding Report</b>	
<hr>

<form method="post" action="report-customer-outstanding" target="_blank">	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Sale Report (Product Wise)</b>	
<hr>
	
<form method="post" action="report_sale_report_product" target="_blank">
<p>
  <input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
  <input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">

  <select name="product_catagory" required="required" class="form-control form-control-sm mb-3" id="product_supplier3">
    <option value="" hidden="yes">Select Category</option>
    <option value="all">All Category</option>
    <?php 
$supplier_qury=mysqli_query($connation,"SELECT * FROM catogary_list ORDER BY catogary_text");
while($supplier_resalt=mysqli_fetch_array($supplier_qury)){
?>
    <option value="<?php echo $supplier_resalt['catogary_id']; ?>"><?php echo $supplier_resalt['catogary_text']; ?></option>
    <?php } ?>
  </select>
</p>
<button type="submit" class="btn btn-success btn-sm w-100">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Sale Report (Invoice Wise)</b>	
<hr>
	
<form method="post" action="report_sale_report_invoice" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Sale Report (Customer Wise)</b>	
<hr>
	
<form method="post" action="report_sale_report_customer" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Expenses Report</b>	
<hr>
	
<form method="post" action="report-expenses" target="_blank">
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
	
<div class="col-lg-3 col-sm-12 mb-2">
<div class="card card-body h-100 alert-info">
<b>Return Report</b>	
<hr>
	
<form method="post" action="report_return" target="_blank">
	
<select name="user" required="required" class="form-control form-control-sm mb-2" id="user">
<option value="" hidden="yes">Select User</option>
<option value="all">All User</option>
<?php 
$user_qury=mysqli_query($connation,"SELECT * FROM user_details ORDER BY CONCAT(user_fname,' ',user_lname) ASC");
while($user_resalt=mysqli_fetch_array($user_qury)){
?>
<option value="<?php echo $user_resalt['user_id']; ?>"><?php echo $user_resalt['user_fname']; ?> <?php echo $user_resalt['user_lname']; ?></option>
<?php } ?>
</select>
	
<input name="st_date" type="date" required="required" class="form-control form-control-sm mb-2" id="st_date" value="<?php echo $current_date; ?>">
<input name="en_date" type="date" required="required" class="form-control form-control-sm mb-2" id="en_date" value="<?php echo $current_date; ?>">
	
<button type="submit" class="btn btn-success btn-sm w-100 mt-2">Run Report</button>
</form>

</div>
</div>
<?php } ?>
	
</div>
</div>
	

<script src="select2/core.js"></script>
<script src="select2/script.min.js"></script>
</body>
</html>
<?php @mysqli_close($connation); ?>