<?php 
$s=new db_query();
global $db;

?>

<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
<script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["quotationid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('quotationid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('quotationid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('quotationid_'+i).checked=true;	
	}	
	}
	else
	{

	if(t==undefined)		
		document.getElementById('quotationid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('quotationid_'+i).checked=false;	
	}
	}
	

	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php  echo $page_title;?></h1>
<div class="centre" id="slidingDiv">
<form action="" method="post"  >
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
  <tr class="row1">
    <td class="tabledata1">Branch</td>
	<td>
	<select name="site"  style="width:150px;">
		
	<?php
	$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode IN ('".$_SESSION['AssignedBranch']."') ";
	$SiteRes=DB_query($Sitesql,$db);
	while($SiteRow=DB_fetch_array($SiteRes))
	{?>
	<option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> ><?php  echo $SiteRow['locationname'];?></option>
	<?php 
	}
	?>
	</select></td>
	<td class="tabledata1">From:</td>
	<td colspan="3"><input name="fromdate" type="text"  class="datepicker" style="width:150px;"/></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">To:</td>
	<td><input name="todate" type="text"  class="datepicker" style="width:150px;"/></td>
	<td class="tabledata1">W/O No</td>
	<td>

	<select name="workorder" id="workorder" style="width:150px;">  
					   <option value="0">-Select-</option>	
					   <?php 
					   $sql=DB_query("select * from salesorder where  companyid ='".$_SESSION['ACGCompanyId']."'
					    and branch in('".$_SESSION['AssignedBranch']."') ",$db);
					   while($row1=DB_fetch_array($sql))
					   {					   
					   ?>
					   <option value="<?php echo $row1['id']; ?>" <?php if($_POST['workorder']==$row1['id']) { ?> selected="selected" <?php } ?>><?php echo $row1['orderNo']; ?></option>
					   	<?php } ?>			   
					   </select>
	
	
	</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">Job Card No:</td>
	<td><select name="jobcard" id="jobcard" style="width:150px;">  
					   <option value="0">-Select-</option>	
					   <?php 
					   $sql=DB_query("select * from job_card where  CompanyId ='".$_SESSION['ACGCompanyId']."'",$db);
					   while($row1=DB_fetch_array($sql))
					   {					   
					   ?>
					   <option value="<?php echo $row1['id']; ?>" <?php if($_POST['jobcard']==$row1['id']) { ?> selected="selected" <?php } ?>><?php echo $row1['job_card_no']; ?></option>
					   	<?php } ?>			   
					   </select></td>
	<td class="tabledata1"></td>
	<td>

	
	
	
	</td>
	</tr>
	<tr class="row1">
	<td colspan="4"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
  </tr>
</table> 
</form>
</div>



<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr class="row1">
		
		<td width="10%" class="tabledata">Job Card No</td>
		<td width="13%" class="tabledata">Job Date</td>
		<td width="29%" class="tabledata">Items</td>	
		<td width="16%" class="tabledata">Exp. Date</td>
		<td width="6%" class="tabledata">WO No</td>
		<td width="4%" class="tabledata">WO Date</td>
		<td width="8%" class="tabledata">Close Job </td>
		<td width="9%" class="tabledata">Created By</td>
	
	</tr>
<?php 
if($_REQUEST['Search'])
{
	
$todate=ConvertSQLDate($_REQUEST['todate']);
$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
$site=$_REQUEST['site'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
		$filter[]="job_date between '".$todate."' and '".$fromdate."'";
	}
 	if($_REQUEST['site']!='0')
	{
		$filter[]="site='".$site."'";
	}
	if($_REQUEST['workorder']!='0')
	{
		$filter[]="wo_no='".$_REQUEST['workorder']."'";
	}
	if($_REQUEST['jobcard']!='0')
	{
		$filter[]="id='".$_REQUEST['jobcard']."'";
	}
	
if($filter!='')
{
	$filter1=implode(" and ",$filter);
     $GetLead="select * from job_card where  $filter1 ";
	 $getlead=DB_query(  "select * from job_card where  CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ",$db);
	}
}
else 
{
	
$i=1;
     $GetLead=  "select * from job_card where  CompanyId='".$_SESSION['ACGCompanyId']."'    ";

    $getlead=DB_query(  "select * from job_card where  CompanyId='".$_SESSION['ACGCompanyId']."'     order by id desc",$db);
}
//}

$s=new db_query();

if(DB_num_rows($getlead)>0)
{
	 while($row_quotes=DB_fetch_array($getlead))
	 {
	  if($row_quotes['status']=='Pending')
	  {
	  $status="";
	  }
	  else
	  {
	   $status="Job card Close";
	  }
	  
 $SOURL="index.php?route=Production/JobrouteCard/job_route_close&action=Edit&SID=".$row_quotes['id'].$rurl;
?>
    <tr bgcolor="#dfdfdf">
    
  <td style="padding-left:5px; padding-right:5px;"><?php  echo $row_quotes['job_card_no'];?></td>
  <td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['job_date']); ?></td>
  	<td style="padding-left:5px; padding-right:5px;"><div style="overflow:auto; width:270px; height:40px;">
	     <?php
		 $sql1=DB_query("select mst_itemid,item_qty
		  from job_card_item_details where jobid='".$row_quotes['id']."'",$db);
		  $numrow=DB_num_rows($sql1);
		  $t=1;
		 while($row=DB_fetch_array($sql1))
		 {		 
		 ?>
		  <strong><?php if($t==1) {
		   echo ">> ".$s->getField('item_master','id',$row['mst_itemid'],'item_name')."   "."<<"."   Qty :  ".
		   $row['item_qty']; }
		    else { echo $s->getField('item_master','id',$row['mst_itemid'],'item_name')."   "."<<"."   Qty :  ".
		   $row['item_qty']; }
		 if($t<$numrow) { 
		  echo "<br>".">>";  }?></strong>
		  
		 <?php $t++; } ?>
	    </div></td>
	<td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['delivery_date']); ?></td>	
 	<td><?php echo $orderno=$s->GetFieldValue('salesorder',"id='".$row_quotes['wo_no']."'",'orderNo'); ?></td>
 	<td><?php echo ConvertSQLDate($orderno=$s->GetFieldValue('salesorder',"id='".$row_quotes['wo_no']."'",'orderDate')); ?></td>
 	 <td>
    <?php if($status=='') { ?>
   <a href="<?php echo $SOURL; ?>" ><img src="images/delete_1.gif" height="15" width="15"></a>
   <?php } else echo $status; ?>
   </td>
		<td style="padding-left:5px; padding-right:5px;"><?php  
			$Sql1=DB_query("Select * from www_users where id='".$row_quotes['createdBy']."'",$db);
	$Res1=DB_fetch_array($Sql1);
		
	echo $Res1['userid'];
			?></td>
			
   <?php $i++; }  }
   else
   {?>
   	<tr>
   	<td colspan="8">
   	<font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
  <?php }?>
</table>

</div>
</div>