<?php 
$s=new db_query();
global $db;
if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['quotationid']);$i++)
	{
	$cond="jobid='".$_REQUEST['quotationid'][$i]."'";
	$row= $s->DeleteRecord('job_card_item_details', $cond);
	$cond2="jobid='".$_REQUEST['quotationid'][$i]."'";
	$row2= $s->DeleteRecord('job_process_details', $cond);
	
	$cond="id='".$_REQUEST['quotationid'][$i]."'";
	$row= $s->DeleteRecord('job_card', $cond);
	}	
}
?>

<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;">
	<option value="0">--All--</option>	
	<?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']."' and mao=1",$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>

<form method="post" name="myform">	
<p align="left">
<?php if($_SESSION['frmAdd']==0){ ?> 
<input type="button" name="Create" value="Add Job Card" alt="Not Allowed" title="Not Allowed" class="search" />

<?php }else{?>
<a href="<?php echo "index.php?route=Production/JobrouteCard/job_route_card_creation_mao".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add Job Card" class="search" /></a>


<?php }?>



<?php 
//echo  $_SESSION['frmDelete'];

 if($_SESSION['frmDelete']==0){ ?>
  <input type="button" name="Delete" value="Delete" alt="Not Allowed" title="Not Allowed"  class="search" />
<?php }else{?>
<input type="submit" name="Delete" value="Delete" class="search" />
<?php }?>
</p>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr class="row1">
		<td width="10%" class="tabledata"><input name="quotationid" type="checkbox"   id="quotationid" onclick="LeadData()"    /></td>
		<td width="12%" class="tabledata">Job Card No</td>
		<td width="9%" class="tabledata">Job Card  Date</td>
		<td width="15%" class="tabledata">Items Description</td>
		<td width="6%" class="tabledata"> Quantity</td>	
		<td width="9%" class="tabledata">Exp. Date</td>
		<td width="12%" class="tabledata">WO No</td>
		<td width="8%" class="tabledata">WO Date</td>
		<td width="6%" class="tabledata">Status</td>
		<td width="12%" 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 and mao=1";
	 $getlead=DB_query(  "select * from job_card where  CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 and mao=1 ",$db);
	}
}
else 
{
	
$i=1;
     $GetLead=  "select * from job_card where  CompanyId='".$_SESSION['ACGCompanyId']."' and mao=1";

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

$s=new db_query();

if(DB_num_rows($getlead)>0)
{
	 while($row_quotes=DB_fetch_array($getlead))
	 {
	  $SOURL="index.php?route=Production/JobrouteCard/job_route_creation_edit_mao&action=Edit&SID=".$row_quotes['id'].$rurl;
      $status=$row_quotes['status'];
?>
    <tr bgcolor="#dfdfdf">
     <td><?php if($status=='Close') { ?>
	 <input name="quotationid[]" disabled="disabled" type="checkbox" id="quotationid_<?php echo $i; ?>"   value="" />
	 <img src="images/icon_edit.gif" alt="No Permission" title="No Permission" width="10px"  height="10" /><?php } else { ?>
   <input name="quotationid[]" type="checkbox" id="quotationid_<?php echo $i; ?>"   value="<?php  echo $row_quotes['id']?>" />
   <a href="<?php echo $SOURL?>"><img src="images/icon_edit.gif" width="10px"  height="10" /></a><?php } ?>&nbsp;
   <a href="jobcard_mao_print.php?id=<?php echo $row_quotes['id']?>" target=_blank><img src="images/icon_print.jpg" height="25" width="25"></a>
   </td>
  <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;">
	     <?php
		 $sql1=DB_query("select mst_itemid from job_card_item_details where jobid='".$row_quotes['id']."'",$db);
		  $numrow=DB_num_rows($sql1);
		  $t=1;
		 while($row=DB_fetch_array($sql1))
		 {		 
		 ?>
		 <?php if($t==1) {
		   echo $s->getField('item_master','id',$row['mst_itemid'],'item_name');
		    }
		    else { echo $s->getField('item_master','id',$row['mst_itemid'],'item_name');
			 }
		 if($t<$numrow) { 
		   }?>
		  
		 <?php $t++; } ?>
	    </td>
		<td style="text-align:center;"> <?php
		
		 $sql1=DB_query("select prodqty from job_card_item_details where jobid='".$row_quotes['id']."'",$db);
		  $numrow=DB_num_rows($sql1);
		  $t=1;
		 while($row=DB_fetch_array($sql1))
		 {		 
		 ?>
		 <?php if($t==1) {
		   echo $s->getField('job_card_item_details ','jobid',$row_quotes['id'],'prodqty');
		    }
		    else { echo $s->getField('job_card_item_details ','jobid',$row_quotes['id'],'prodqty');
			 }
		 if($t<$numrow) { 
		   }?>
		  
		 <?php $t++; } ?></td>
	<td style="padding-left:5px; padding-right:5px;"><?php  echo ConvertSQLDate($row_quotes['delivery_date']); ?></td>	
 	<td><?php  
				$orderno=$s->GetFieldValue('salesorder',"id='".$row_quotes['wo_no']."'",'orderNo'); 
				if($orderno =='')
				{
					$orderno=$s->GetFieldValue('manufacturing_advice',"id='".$row_quotes['wo_no']."'",'advice_no');
				}
				echo $orderno; 
		?>
				
	</td>
 	<td><?php echo ConvertSQLDate($row_quotes['wo_date']); ?></td>
<?php /*?> 	<td><?php echo ConvertSQLDate($orderno=$s->GetFieldValue('salesorder',"id='".$row_quotes['wo_no']."'",'orderDate')); ?></td>
<?php */?> 	<td><?php if($status=='Pending') { echo "OPEN"; } else {  echo ucwords($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>
</form>
</div>
</div>