<?php include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
date_default_timezone_set('Asia/Calcutta');
$today = date("d/m/Y");
$today2 = date("Y-m-d");
$today1 = date("d/m");
$currentmonth = date(m);
?>
 <?php 

$query = "select * from users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
//echo $query;
$result = mysql_query($query,$conn);
while($row=mysql_fetch_array($result))
	                                              	{
													  $staff_name = $row['full_name'];
													  $full_name = $row['full_name'];
													  $avatar = $row['avatar'];
													  $department_name = $row['department_name'];
													  $staff_id  = $row['staff_id'];
													  $username = $row['username'];
													   $designation = $row['designation'];
													  //echo $Branch;
													  }	
													   ?>	
<?php $querylogin = "select * from staff_login where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysql_query($querylogin,$conn);
while($row=mysql_fetch_array($resultlogin))
{
$Designation = $row['designation'];
$staff_name = $row['staff_name'];

}
?>
<?php
	require_once("../perpage.php");	
	require_once("../dbcontroller.php");
	$db_handle = new DBController();
	
	$final_quotation_no = "";
	$datepicker = "";
	$datepicker1 = "";
	$datepicker2 = "";
	$datepicker3 = "";
	$bcity = "";
	$customer_name = "";
	$leadtype = "";
	$contact_person_1 = "";
	$currency = "";
	$description = "";
	$asign = "";
	$sstatus = "";
	$qtnCreated = "";
	$inv_no ="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("final_quotation_no","datepicker","datepicker1","datepicker2","datepicker3","customer_name","leadtype","contact_person_1","currency","asign","sstatus","qtnCreated","inv_no");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "final_quotation_no":
						$final_quotation_no = $v;
						$queryCondition .= "final_quotation_no LIKE '" . $v . "%'";
						break;
						
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "STR_TO_DATE(inv_date,'%d-%m-%Y') BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
												
						case "contact_person_1":
						$contact_person_1 = $v;
						$queryCondition .= "contact_person_1 LIKE '" . $v . "%'";
						break;
						
						case "customer_name":
						$customer_name = $v;
						$queryCondition .= "customer_name LIKE '" . $v . "%'";
						break;
						
						case "leadtype":
						$leadtype = $v;
						$queryCondition .= "leadtype LIKE '" . $v . "%'";
						break;
						
						case "description":
						$description = $v;
						$queryCondition .= "description LIKE '" . $v . "%'";
						break;
						
						case "currency":
						$currency = $v;
						$queryCondition .= "currency LIKE '" . $v . "%'";
						break;
						
						case "asign":
						$asign = $v;
						$queryCondition .= "asign LIKE '" . $v . "%'";
						break;
						
						case "sstatus":
						$sstatus = $v;
						$queryCondition .= "sstatus LIKE '" . $v . "%'";
						break;
						
						case "qtnCreated":
						$qtnCreated = $v;
						$queryCondition .= "qtnCreated LIKE '" . $v . "%'";
						break;
						
						case "inv_no":
						$inv_no = $v;
						$queryCondition .= "inv_no LIKE '" . $v . "%'";
						break;
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	$orderby = " ORDER BY inv_id ASC"; 
	$sql = "SELECT * FROM customer_invoice_details" . $queryCondition ." and customer_id='".$_REQUEST['customer_id']."' " ;
	} else { 
	$sql= "SELECT * FROM customer_invoice_details where customer_id='".$_REQUEST['customer_id']."' ORDER BY STR_TO_DATE(inv_date,'%d-%m-%Y') DESC,inv_id DESC";	
	//echo $sql;
	}
	$num_rows2 = mysql_num_rows($result2);
	//echo $sql ;
	$href = 'view_all_dispatched.php';					

	$perPage = 50; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Warpp Engineers</title>
  <!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
  <script type="text/javascript" src="../css/CalendarPopup.js"></script>
   <script type="text/javascript" src="../jquery.min.js"></script>
   <script src="../jquery-ui.js"></script>
  <style>
  table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
  table-layout: fixed;
}
table caption {
  font-size: 1.2em;
  margin: .5em 0 .75em;
}
table tr {
  
  border: 1px solid #ddd;
  padding: .35em;
}
table th,
table td {
  padding: .625em;
  
}
table th {
  font-size: 13px;;
  letter-spacing: 0em;
  text-transform: capitalize; margin-right:5px;
}
@media screen and (max-width: 600px) {
  table {
    border: 0;
  }
  table caption {
    font-size: 1.8em;
  }
  table thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  table tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: .625em;
  }
  table td {
    border-bottom: 1px solid #ddd;
    display: block;
    font-size: .9em;
    
  }
  table td:before {
    /*
    * aria-label has no advantage, it won't be read inside a table
    content: attr(aria-label);
    */
    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  table td:last-child {
    border-bottom: 0;
  }
}

  .style1 {color: #FF0000}
  </style>
<script src="../jquery.min.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
 <link rel="stylesheet" href="../jquery-ui.css">
<div class="wrapper">
  <?php include 'header.php';?>

<script type="text/javascript" src="../jquery.min.js"></script>
   <script src="../jquery-ui.js"></script>

	
<div class="content-wrapper">
    <!-- Content Header (Page header) --->


   
	
			
<section class="content"> 
<div class="row">
 <div>
		
					
			<div class="col-sm-12" id="squareboxcontent1" style="">
				<div class="filter-view">
					<div class="table-responsive">
						<form name="frmSearch" method="post" action="view_all_dispatched.php">
						<div class="search-box">
			
						<table class="table table-striped table-bordered table-hover">
						    <tbody>
							<div class="col-xs-12" style="background:#3C8DBC;">
							<h5 style="color:#FFFFFF"><span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Search View - Invoice &nbsp;</h5>
					  </div>
						      <tr>
								<td><div class="form-group"><label for="acccode">Order No. </label><br />
<input type="text" placeholder="INV No." name="search[inv_no]" class="form-control" value="<?php echo $inv_no; ?>"	/></div>
			</td>
			<td><div class="form-group"><label for="acccode"> Date</label><br />
			<input type="text" placeholder="From Date" name="search[datepicker]"  class="datepicker_y form-control" value="<?php echo $datepicker; ?>"	/>
			
			
			&nbsp;&nbsp;<input type="text" placeholder="To Date" name="search[datepicker1]"  class="datepicker_y form-control" value="<?php echo $datepicker1; ?>"	/>
			<script>$( ".datepicker_y").datepicker({
  inline: true,
  
  nextText: '&rarr;',
  prevText: '&larr;',
  showOtherMonths: true,
  changeMonth: true,
        changeYear: true,
  dateFormat: 'yy-mm-dd',
  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
      showAnim: "slide"
 });</script> 
			
			</div></td>
			
					
			<td><div class="form-group"><label for="acccode">Account Name</label><br />
		<input type="text" placeholder="Account Name" name="search[customer_name]" class="form-control" value="<?php echo $customer_name; ?>"	/></div></td>
		 
		
												
			</tr>
	 
		
		
		<tr>
						      	<td colspan="3" class="center">
			
			<input type="submit" name="go" class="btnSearch btn bg-btn-view-access" value="Search">&nbsp;&nbsp;<input type="reset" class="btnSearch btn bg-btn-view-access" value="Reset" onClick="window.location='view_all_dispatched.php'"></td></tr></tbody>
			<table class="table table-striped table-bordered table-hover">
			<div class="search-header" style="padding-top:3px;">
						<div><?php echo $pagination;?>
						
						<div class="col-xs-12" style="background:#3C8DBC;">
							<h5 style="color:#FFFFFF"><span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Search View  &nbsp;</h5>
					  </div>
						
							
						</div>
				  </div>
			
      <thead>
	  <?php 
if(isset($result["perpage"])) {
					?>
					<tr>
					<td colspan="24" align=right> <?php echo $result["perpage"]; ?></td>
					</tr>
					<?php } ?>
  <tr>
								       <th colspan="3">Order No</th>
								       <th colspan="2">Date</th>
									   <th colspan="3">Customer</th>
								       <th colspan="5">Products</th>
								       <th colspan="4">Dispatched</th>
									   <th colspan="5">Serial No. Update</th>
									   <th colspan="2">Active</th>
										
                </tr></thead>
				<tbody>
					<?php
						foreach($result as $k=>$v) {
						if(is_numeric($k)) {

?>
<?php
if($result[$k]["serial_no_updated"] ==''){
$interval = 0;
$inv_date01 = $result[$k]["inv_date"];
$return_filled_date1=date('Y-m-d', strtotime($result[$k]["inv_date"]));
$date1=date_create("$return_filled_date1");
$date2=date_create("$today2");
$diff=date_diff($date1,$date2);
}
?>				
					
<tr>
<? 
$customer_id =  $result[$k]["customer_id"];
$call_follow_up_id =  $result[$k]["call_follow_up_id"];
$final_quotation_no =  $result[$k]["final_quotation_no"];
$order_pro = $result[$k]["order_pro"];
$cust_PO_type = $result[$k]["cust_PO_type"];
$inv_make = $result[$k]["inv_make"];
$inv_id = $result[$k]["inv_id"];
$inv_no = $result[$k]["inv_no"];

?>
	
		<td colspan="3"><div align="left" style="padding:3px;"><?php echo $inv_no?><br>
		<?php if($result[$k]["serial_no_updated"] ==''){ echo $datediff = $diff->format('%R%a days');
		if($datediff >= 30) { ?>
			  <h5 style="color:#FF0000; font-size:22px;"><i class="fa fa-bell "></i></h5>
			  <?php } }?>
		</div></td>
   		<td colspan="2"><div align="left" style="padding:3px;"><?php echo $result[$k]["inv_date"]; ?></div></td>
	    <td colspan="3"><div align="left" style="padding:3px;"><?php echo $result[$k]["customer_name"]; ?>
	     <?php if($result[$k]["receipt_no"] !=''){?><span class="style1">( 
	   <?php  echo "With receipt no"; ?> 
	    )</span><?php } ?></div></td>
    <td colspan="5"><div align="left" style="padding:3px;">
<?php 
if($result[$k]["prod_type"]=='Spare') {
echo $result[$k]["prod_type"];
}
?>
<?php 
$query6 = "select * from dispatched_product_details where inv_no = '".$result[$k]["inv_no"]."' AND customer_id = '".$result[$k]["customer_id"]."'";
//echo $query6;
$result6 = mysql_query($query6) or die(mysql_error());
while($row=mysql_fetch_array($result6))
	                                              	{
													$machine_name = $row['machine_name'];
													$qty = $row['qty'];
													$serial_no_warpp = $row['serial_no_warpp'];
													$serial_no_updated = $row['serial_no_updated'];
													
													?>
													<?php echo $machine_name;?> (Qty: <?php echo $qty?>)<br>
	<span class="style1">Sr. No.: <?php if($serial_no_updated=='Done'){?> - <?php echo $serial_no_updated; }?></span>
													
													<div style="border-bottom:1px #666666 dotted; margin-bottom:3px;"></div><?php } ?></div></td>
	
     <td colspan="4"><div align="left" style="padding:3px;">
	
	 Dispached by : <?php echo $result[$k]["dispatched_by"]?><br>
	 <div style="border-bottom:1px #666666 dotted; margin-bottom:3px;"></div>
	 Docket No.: <?php echo $result[$k]["docket_no"]?> <br>
	 <div style="border-bottom:1px #666666 dotted; margin-bottom:3px;"></div>
	 Dispached Date : <?php echo $result[$k]["dispatched_date"]?> 
	
	 </div></td>
	 <td colspan="5"><div align="left" style="padding:3px;">
	 
	 <div align="left" style="padding:3px;">
<?php 
$query7 = "select * from dispatched_product_details where inv_no = '' AND Forward_by = '".$result[$k]["customer_id"]."' and serial_no !=''";
//echo $query7;
$result7 = mysql_query($query7) or die(mysql_error());
while($row=mysql_fetch_array($result7))
	                                              	{
													$machine_name = $row['machine_name'];
													$serial_no = $row['serial_no'];
													$update_date = $row['update_date'];
													$customer_name = $row['customer_name'];
													
													?>
													<?php echo $machine_name;?> - <span class="style1"><?php echo $serial_no?><br>
													(<?php echo $update_date?>)</span> - <?php echo $customer_name?><br>
						  <div style="border-bottom:1px #666666 dotted; margin-bottom:3px;"></div><?php } ?></div>
	 </div></td>
	 <td colspan="2"><div align="left" style="padding:3px;"><?php echo $result[$k]["Active"]?>
	 <?php if($result[$k]["Active"]=='NO' and $result[$k]["cust_request"]=='') { ?>
	 <a href="mail.php?inv_id=<?php echo $inv_id?>&&customer_id=<?php echo $customer_id?>" class="btnSearch btn bg-btn-view-access">Request<br>Activate</a>
	 <?php } if($result[$k]["cust_request"]=='YES' and $result[$k]["till_date"]=='') {?> <br>
	 <span class="style1">Request Send</span> 
	 <?php } else { ?> <br>till date : <?php echo $result[$k]["till_date"]; }?>
	 
	 
	 </div></td>
	     
</tr>
        
					<?php
						}
						}
				
					?>
				  <?php
					if(isset($result["perpage"])) {
					?>
					
					<tr>
					<td colspan="24" align=right> <?php echo $result["perpage"]; ?></td>
					</tr>
					<?php } ?>
				<tbody>
			</table>
			</form>
					</div>
				</div>
			</div>
</div>
	</div></section></div>
<script type="text/javascript" src="../js/date-time-picker.js"></script>
    <? include'footer.php'; ?>
