<?php

include 'load.php';
require_once 'db_connection.php'; 
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="robots" content="noindex, nofollow">

<title>Quotation Report | Eat More Resturant   | Pos & Invetory System | Dashboard
</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Quotation Report</h4>
<h6>Manage your Quotations</h6>
</div>
</div>

<div class="card">
<div class="card-body">
<div class="table-top">

</div>


<div class="card mb-0" id="filter_inputs" style="display: block;">
<div class="card-body pb-0">
<div class="row">
<div class="col-lg-12 col-sm-12">
<form method="POST" enctype="multipart/form-data">
<div class="row">
<div class="col-lg col-sm-3 col-12">
<div class="form-group">
<label for="date">From Date</label>
<input type="date" name="formdate" placeholder="DD-MM-YYYY" class="form-control">
</div>
</div>
<div class="col-lg-3 col-sm-3 col-12">
<div class="form-group">
<label for="todate">To Date</label>
<input type="date" name="todate" placeholder="DD-MM-YYYY" class="form-control">
</div>
</div>
<div class="col-lg-3 col-sm-3 col-12">
<div class="form-group">
<label for="customerid">Customer</label>
<select class="select" name="customerid">
<option value="0" selected>Select Customer</option>
<?php

										$stmt = $DB_con->prepare('SELECT * FROM mobilecustomers where status="1" ORDER BY coid');

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

?>
<option value="<?php echo $row['coid']; ?>"><?php echo $row['cname']; ?> | <?php echo $row['cemail']; ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-2 col-sm-6 col-12">
<div class="form-group">
<button type="submit" name="search" class="btn btn-block btn-outline-success active btn-md text-white" style="margin-top:33px;width:100%;">
<i class="fa fa-search" aria-hidden="true"></i> Search
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>

<div class="table-responsive">
<table class="table" id="betable">
<thead>
<tr>
	<th>#ID</th>
	<th>Action</th>
	<th>Quotation No</th>
	<th>Customer Name</th>
	<th>Address</th>
	<th>Contact Number</th>
	<th>Value</th>
	<th>Date/Time</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['search'])){
	
$count=0;	

$formdate=$_POST['formdate'];
$todate=$_POST['todate'];
$customerid=$_POST['customerid'];

	if($branch_id=='0'){

		if($customerid=='0'){
			$sql = "SELECT *  FROM quotations qu INNER JOIN tbl_quatation_other_details tqo ON qu.q_id=tqo.q_id WHERE DATE(qu.q_date) BETWEEN '$formdate' AND '$todate' ORDER BY qu.q_id DESC";
		}else{
			$sql = "SELECT *  FROM quotations qu INNER JOIN tbl_quatation_other_details tqo ON qu.q_id=tqo.q_id WHERE (DATE(qu.q_date) BETWEEN '$formdate' AND '$todate') AND q_customer='$customerid' ORDER BY qu.q_id DESC";
		}

	}else{

		if($customerid=='0'){
			$sql = "SELECT *  FROM quotations qu INNER JOIN tbl_quatation_other_details tqo ON qu.q_id=tqo.q_id WHERE tqo.branch_id='$branch_id' AND (DATE(qu.q_date) BETWEEN '$formdate' AND '$todate') ORDER BY qu.q_id DESC";
		}else{
			$sql = "SELECT *  FROM quotations qu INNER JOIN tbl_quatation_other_details tqo ON qu.q_id=tqo.q_id WHERE tqo.branch_id='$branch_id' AND (DATE(qu.q_date) BETWEEN '$formdate' AND '$todate') AND q_customer='$customerid' ORDER BY qu.q_id DESC";
		}
	}
        
        $rs=$conn->query($sql);
        $rowCount=0;
        while($row =$rs->fetch_array())
        {
            $q_id = $row[0];
            $q_customer = $row[1];
            $q_amount = $row[2];
            $q_user = $row[3];
            $q_date = $row[4];

            $rowCount += 1;


            $sql = "SELECT *  FROM mobilecustomers WHERE coid='$q_customer'";
	        $rs=$conn->query($sql);
	        if($row =$rs->fetch_array())
	        {
	            $CustomerName = $row[1];
	            $CustomerTP = $row[3];
	            $CustomerAddress = $row[4];
	        }
			
			$count++;
			
?>
<tr>
<td><?php echo number_format($count,0); ?></td>
<td><a target="_" href="quotations-view?id=<?php echo $q_id; ?>">View</a></td>
<td><?php echo $q_id; ?></td>
<td><?php echo $CustomerName; ?></td>
<td><?php echo $CustomerAddress; ?></td>
<td><?php echo $CustomerTP; ?></td>
<td><?php echo $q_amount; ?></td>
<td><?php echo $q_date; ?></td>
</tr>
<?php 
} 
}
?>
</tbody>
</table>
</div>
</div>
</div>

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

<?php require_once 'footerjs.php'; ?>

</body>
</html>