<?php
require_once("../config/config.php");

?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title><?=siteTitle?></title>
 <script src="../js/jquery.min.js"></script>
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 <link rel="stylesheet" href="../css/jquery.dataTables.min.css">
 <script type="text/javascript" src="../js/jquery.dataTables.min.js"></script>
 <script>
	$(document).ready(function(){
        $("#frm1").validate();
		$('#myTable').dataTable({
    		paging: false,
			searching: false,
			ordering:  false,
			info: false
		});
    });
 </script>
 <script type="text/javascript" src="../js/jquery.validate.js"></script>
</head>
<body>
<div class="container-fluid">
	<div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
	<div class="col-sm-9">
    	<h2 align="center"><i class="fa fa-barcode fa-lg"></i> Single<?=$imeitag?>Track</h2><br/><br/>
   	  <div class="form-group"  id="page-wrap" style="margin-left:10px;">
          <form  name="frm1"  id="frm1" class="form-horizontal" action="" method="post" onSubmit="return validate() ">
          <div class="form-group">
            <div class="col-md-10"><label class="col-md-4 control-label">Enter Serial Number<span class="red_small">*</span></label>
              <div class="col-md-6">
                <input type="search" class="form-control alphanumeric required" placeholder=""  name="serial_no" value="<?=$_REQUEST["serial_no"]?>">
              </div>
              <div class="col-md-2">
           		<input type="submit" class="btn <?=$btncolor?>" name="SHOW" id="" value="SHOW">       
           	  </div>
            </div>
          </div>
        </form>
		  <?php
        	if($_POST['SHOW']){
		  		$sql = mysqli_query($link1,"SELECT * FROM billing_imei_data WHERE imei1 ='".$_POST['serial_no']."' or imei2 ='".$_POST['serial_no']."'");
		  		$num_rows = mysqli_num_rows($sql);
		  		if($num_rows > 0){
			?>
            <div class="alert alert-success alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                <strong>Success <i class="fa fa-check-circle fa-lg"></i></strong>&nbsp;&nbsp;Entered serial number details are showing below.
            </div>
		  <table  width="100%" id="myTable" class="table-striped table-bordered table-hover" align="center">
       		  <thead>
           		  <tr class="<?=$tableheadcolor?>" >  
                    <th><a href="#" name="entity_id" title="asc" ></a>From Location</th>
                    <th data-hide="phone"><a href="#" name="name" title="asc" class="not-sort"></a>To Location</th>
                    <th><a href="#" name="name" title="asc" ></a><?=$imeitag?></th>
                    <th data-hide="phone,tablet"><a href="#" name="phone" title="asc" class="not-sort"></a>Product Code</th>
                    <th data-hide="phone,tablet"><a href="#" name="email" title="asc" class="not-sort"></a>Document No.</th>
                    <th data-hide="phone,tablet"><a href="#" name="date" title="asc" class="not-sort"></a>Document Date</th>
           		  </tr>
       		  </thead>
       		  <tbody>
				  <?php
                    while($row = mysqli_fetch_assoc($sql)){
						////get document details
						$doc1 = mysqli_fetch_assoc(mysqli_query($link1,"SELECT entry_date FROM billing_master where challan_no='".$row['doc_no']."'"));
						if($doc1['entry_date']){
							$doc2 = mysqli_fetch_assoc(mysqli_query($link1,"SELECT entry_date FROM vendor_order_master where po_no='".$row['doc_no']."'"));
						}
                    ?>
                      <tr class="even pointer">
                          <td><?php $fromLocation = str_replace("~",",",getLocationDetails($row['from_location'],"name,city,state",$link1)); echo $fromLocation;?></td>
                          <td><?php $toLocation = str_replace("~",",",getLocationDetails($row['to_location'],"name,city,state",$link1)); echo $toLocation;?></td>
                          <td><?php echo $row['imei1'];?></td>
                          <td><?php echo $row['prod_code'];?></td>
                          <td><?php echo $row['doc_no'];?></td>
                          <td><?php if($doc2['entry_date']){ echo $doc2['entry_date'];}else{ echo $doc1['entry_date'];}?></td>
                      </tr>
                  <?php 
                    }
					?>
                  </tbody>  
			  </table>
              
             <!------------ warranty status panel start ------------------> 
             <div class="form-group" style="margin-top:30px;">
               <div class="col-md-4"></div>
                <div class="col-md-4">
                  <div class="panel-group">
                     <div class="panel panel-default table-responsive">
                      <div class="panel-heading heading1">Warranty Status</div>
                      <div class="panel-body" style="text-align:center;">
                      	  <?php 
						  $sql2 = mysqli_query($link1,"SELECT doc_no, prod_code FROM billing_imei_data WHERE imei1 ='".$_POST['serial_no']."' or imei2 ='".$_POST['serial_no']."' ORDER BY `billing_imei_data`.`id` DESC ");
						  $result2 = mysqli_fetch_array($sql2);
						  $tier1 = mysqli_fetch_assoc(mysqli_query($link1,"SELECT sale_date, productcode FROM imei_activation where imei1 ='".$_POST['serial_no']."' or imei2 ='".$_POST['serial_no']."'"));
						  $tier2 = mysqli_fetch_assoc(mysqli_query($link1,"SELECT entry_date FROM billing_master where challan_no='".$result2['doc_no']."'"));
						  $tier3 = mysqli_fetch_assoc(mysqli_query($link1,"SELECT entry_date FROM vendor_order_master where po_no='".$result2['doc_no']."'"));
						  
						  if($tier1['sale_date']!=""){ 
							  $prd = mysqli_fetch_array(mysqli_query($link1,"SELECT warranty_days FROM product_master WHERE productcode = '".$tier1['productcode']."' "));
							  if($prd[0]!=""){ $ws = $prd[0]; }else{ $ws = 0; }
							  if($tier1['sale_date']!=""){ $wsd = $tier1['sale_date']; }
							  $days_diference = daysDifference($today,$wsd);
						  }else if($tier2['entry_date']!=""){
							  $prd = mysqli_fetch_array(mysqli_query($link1,"SELECT warranty_days FROM product_master WHERE productcode = '".$result2['prod_code']."' "));
							  if($prd[0]!=""){ $ws = $prd[0]; }else{ $ws = 0; }
							  if($tier2['entry_date']!=""){ $wsd = $tier2['entry_date']; }
							  $days_diference = daysDifference($today,$wsd);
						  }else if($tier3['entry_date']!=""){
							  $prd = mysqli_fetch_array(mysqli_query($link1,"SELECT warranty_days FROM product_master WHERE productcode = '".$result2['prod_code']."' "));
							  if($prd[0]!=""){ $ws = $prd[0]; }else{ $ws = 0; }
							  if($tier3['entry_date']!=""){ $wsd = $tier3['entry_date']; }
							  $days_diference = daysDifference($today,$wsd);
						  }else{}
						  ?>
                          <?php if(($days_diference>0)&&($ws>0)){ ?>
                          <span style="color:#060;font-weight: 800;" >In Warranty</span>
                          <?php }else{ ?>
                          <span style="color:#C00;font-weight: 800;" >Out Warranty</span>
                          <?php } ?>
                          <br><br>
                          <span style="text-align:center;font-size: 12px;" >Product Warranty Days - <?=$ws?>.</span><br>
                          <span style="text-align:center;font-size: 12px;" >Days Difference - <?=$days_diference?>.</span><br>
                          <span style="text-align:center;font-size: 12px;" >Product Sale Date - <?=$wsd?>.</span><br>
                      </div><!--close panel body-->
                    </div><!--close panel-->
                  </div>
                </div>
                <div class="col-md-4"></div>
             </div> 
             <!------------ warranty status panel end ------------------>
              
              
			  <?php
				}
				else{
				?>
				   <div class="alert alert-danger alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                          </button>
                        <strong>Alert <i class="fa fa-exclamation fa-lg"></i></strong>&nbsp;&nbsp;Entered serial number does not exist in database.
        			</div>
				<?php
                }
			}
			?>
   	  </div>
	</div>
	</div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>
