<link rel="stylesheet" href="css/new_mxerp.css">
<?php extract($_POST);
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Job Route Card Report');
include('includes/SQL_CommonFunctions.inc');
?><div class="body_contain">
<div class="tab_div">

   <h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></h1>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

   <tr>
		<td><div align="center">
			<form  action="" method="post">
			<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
			<tr>
				<td width="17%" class="tabledata">Branch</td>
				<td width="28%"><select name="site" id="site" style="width:100%">
				   <option value="0">---Select---</option>
				  <?php 		
		$site_sql=DB_query("Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		while($site_row=DB_fetch_array($site_sql)){
				?>
				  <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
				  <?php } ?>
				</select></td>
				<td width="12%" class="tabledata">From/To date</td>
			    <td width="21%"><input type="text" name='frmdate' id='frmdate' class="datepicker" style="width:190px;"
				 value="<?php  echo $_REQUEST['fromdate']?>"  /></td>
			    <td width="22%"><input type="text" name="todate" id="todate" class="datepicker" style="width:190px;"
				value="<?php  echo $_REQUEST['todate']?>" /></td>
			</tr>	
			  <tr>
				<td class="tabledata">Job Card No</td>
				<td><select name="jobcard" id="jobcard" style="width:100%">
				   <option value="0">---Select---</option>
				  <?php 		
		$site_sql=DB_query("Select id,job_card_no from job_card where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
		while($site_row=DB_fetch_array($site_sql)){
				?>
				  <option value="<?php echo $site_row['id'];?>"<?php echo ($_REQUEST['jobcard']==$site_row['id']?'selected':'')?>><?php echo $site_row['job_card_no'];?></option>
				  <?php } ?>
				</select></td>
				
			  </tr>	 
		  </table>
		  <p align="left" style="padding-left:10px;"><input type="Submit" name="Proceed" value="Proceed" /></p>
		  </form>
	  </div></td>
	</tr>    
     <tr>
    	<td>&nbsp;</td>
    </tr>
   
	</table>

	
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    	  <tr>
    	    <td width="5%" rowspan="2" class="tabledata">S.No.</td>
    	    <td width="5%" rowspan="2" class="tabledata">job card no.</td>
    	    <td width="4%" rowspan="2" class="tabledata">Date</td>
    	     <td width="5%" rowspan="2" class="tabledata">Batch no.</td>
    	    <td width="6%" rowspan="2" class="tabledata">W.O. No.</td>
    	    <td width="8%" rowspan="2" class="tabledata">W.O.date</td>
    	    <td width="15%" rowspan="2" class="tabledata">Item Desc.</td>
    	     <td colspan="3" rowspan="2" class="tabledata"><div style="width:57PX;">Process</div></td>
    	<td colspan="5" align="center" class="tabledata" style="text-align:center;"><strong>Quantity</strong></td>
		 	  </tr>
    	  <tr>
    	    <td class="tabledata" style="width:50PX;">Allowed </td>
  	        <td class="tabledata" style="width:50PX;">Production </td>
  	        <td class="tabledata" style="width:50PX;">WIP</td>
			<td  align="center" class="tabledata" style="width:50PX;">Machine</td>
			<td  align="center" class="tabledata">Operator</td>
   	    </tr>
    	  <?php 
    	 if(isset($_POST['Proceed']))
		 {
		 	$fromdate=$_REQUEST['frmdate'];
			$todate=$_REQUEST['todate'];
		 $fromdate_brk=explode('/',$fromdate);
		$from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
		$todate_brk=explode('/',$todate);
		$to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
		
    	$filter=array();		
		if($_REQUEST['jobcard']!='0')
		$filter[]="A.id='".$_REQUEST['jobcard']."'";
		if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	     $filter[]="A.job_date BETWEEN '$from' and '$to'";		
		if($_REQUEST['site']!='0')
		$filter[]="A.site = '".$_REQUEST['site']."'"; 
		 if($filter!='')
		{
			
			$filter2=implode(" and ",$filter);
		}			
				
		if(!empty($filter2))
		{
	  $sql="Select A.*,A.id as iddata  from job_card  A  where  A.CompanyId='".$_SESSION['ACGCompanyId']."'  and $filter2 
	  group by A.id";
		}
		else{
		  $sql="Select A.*,A.id as iddata from job_card A where  A.CompanyId='".$_SESSION['ACGCompanyId']."'   group by A.id "; }
		$result=DB_query($sql,$db);
		$i=1;
		//echo $sql;
		 $mmm=DB_num_rows($result);
		if(DB_num_rows($result)>0)
		{			
		while($myrow=DB_fetch_array($result))
			{				
          ?>
 <tr bgcolor="#c1c1c1">
    	    <td><?php echo $i;?></td>
    	     <td><?php echo $myrow['job_card_no'];?></td>
    	    <td><?php echo ConvertSQLDate($myrow['job_date']);?></td>
    	    <td><?php echo $myrow['batch_no'];?></td>
    	    <td><?php if($myrow['order_type']==1) { 
			echo $s->getField('manufacturing_advice','id',$myrow['wo_no'],'advice_no'); 
			$data1=$s->getField('manufacturing_advice','id',$myrow['wo_no'],'advice_date');
			
			}
			else
			{
			echo $s->getField('salesorder','id',$myrow['wo_no'],'orderNo');
			$data1=$myrow['wo_date']; 
			}
			
			
			;?></td>
    	    <td><?php echo ConvertSQLDate($data1) ;?></td>
    	      <td><?php echo $s->getField('item_master','id',$myrow['work_itemid'],'item_name'); ?></td>
    	      <td colspan="8"><table width="100%" border="1" cellpadding="0" cellspacing="0">
          <?php 
	  $details_sql="Select * from job_process_details where jobid='".$myrow['iddata']."'";
	$details_res=DB_query($details_sql,$db);
	$numrow1=DB_num_rows($details_res);
	if(DB_num_rows($details_res)>0){
	$contain_qty='';
	$moveqty='';
	$pendingqty='';
	$t=0;
	while($details_row=DB_fetch_array($details_res))
	{
	
	$check=DB_query("select * from daily_process_qty_maintain where jobcard='".$myrow['iddata']."'",$db);
	$numrow=DB_num_rows($check);
	if($numrow==0)
	{
		$totalproduct=DB_query("select sum(prodqty) as prodqty from job_card_item_details
	     where jobid='".$myrow['iddata']."' ",$db);
		$row_productqty=DB_fetch_array($totalproduct);
		if($t==0)
		{
		$contain_qty[$details_row['process']]=$row_productqty['prodqty'];
	    $moveqty[$details_row['process']]=0;
	    $pendingqty[$details_row['process']]=$row_productqty['prodqty'];
		}
		else
		{
		$contain_qty[$details_row['process']]=0;
	    $moveqty[$details_row['process']]=0;
	    $pendingqty[$details_row['process']]=0;
		}
		
		
	
	}
	else
	{
	
	while($row5=DB_fetch_array($check))
	{
	$contain_qty[$row5['from_process']]=$row5['contain_qty'];
	$moveqty[$row5['from_process']]=$row5['move_qty'];
	$pendingqty[$row5['from_process']]=$row5['pending_qty'];
	$check1=DB_query("select * from daily_process_qty_maintain where jobcard='".$myrow['iddata']."' 
	               and  from_process='".$row5['to_process']."' ",$db);
	 $numrow1=DB_num_rows($check1);
	if($numrow1>0)
	{			   
	while($row6=DB_fetch_array($check1))
	{
	$contain_qty[$row6['from_process']]=$row6['contain_qty'];
	$moveqty[$row6['from_process']]=$row6['move_qty'];
	$pendingqty[$row6['from_process']]=$row6['pending_qty'];
	}
	}
	else
	{
	$contain_qty[$row5['to_process']]=$row5['move_qty'];
	$moveqty[$row5['to_process']]=0;
	$pendingqty[$row5['to_process']]=$row5['move_qty'];
	
	}
	 
	
	
	}
	 
	 
	 
	 
	
	
	}
	
	//print_r($contain_qty);
		
	?>
          <tr bgcolor="#FFFFFF">
            <td class="jjrs_tabledata1" style="width:110px;">
			<?php echo $s->getField('production_process_master','id',$details_row['process'],'manuf_process_name'); ?></td>
            <td class="jjrs_tabledata1" style="width:50px;"><?php echo  $contain_qty[$details_row['process']]; ?> </td>
            <td class="jjrs_tabledata1" style="width:50px;">
			<?php echo $moveqty[$details_row['process']]; ?></td>
            <td class="jjrs_tabledata1" style="width:50px;"><?php echo  $pendingqty[$details_row['process']]; ?></td>
			<td align="center" style="width:60px; text-align:center;"><?php echo $s->getField('machine_center','id',$details_row['machine'],'name'); ?> </td>
		<td align="center" style="text-align:center;"><?php echo $s->getField('production_operator_master','id',$details_row['operator'],'operator_name'); ?></td>
          </tr>
          <?php $t++; } ?>
       
          <?php } ?>
        </table></td>
		
		
		
    	    	       </tr>
    	  
  	  <?php $i++; }  }else
		{?>
		<tr bgcolor="#c1c1c1">
		   <td colspan="14"><font color="#FF0000">No Record Found</font></td></tr>
		<?php 	
		}
		}
	?></table>

</div></div>

     
<?php
//include('includes/footer.inc');
?>