<?php 
$PageSecurity = 2;
include('includes/DefineSuppTransClass.php');
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');

$function_filter[]=$_REQUEST['site'];
$function_filter[]=$_REQUEST['store'];
$data_date=date('Y-m-d');
$function_filter[]=$data_date;
							


   $data1='';
   $jobcarddate=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'date');


$data1.="<input name='issue_req_date' type='text' id='issue_req_date' style='width:100%;' value=".ConvertSQLDate($jobcarddate)." size='15' class='datepicker' />";

	
 $data2='';
 	$jobcardid=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'job_card_id');
	//$jobcardmao=$s->getFieldValue('job_card','id="'.$jobcardid.'"','mao');
   $jobcardsop=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'sop_no');

   	$jobcardsopno=$s->getFieldValue('prd_wo','id="'.$jobcardsop.'"','wo_no');
  


$data2.="<input name='work_order_no' type='hidden' id='work_order_no' style='width:100%;' value=".$jobcardsop." size='15' />";
$data2.="<input name='work_order_no1' type='text' id='work_order_no1' style='width:100%;' value='".$jobcardsopno."' size='15' />";


   $data3='';
   $jobcarditm=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'item_name');
   $jobcarditmid=$s->getFieldValue('item_master','item_name="'.$jobcarditm.'"','id');
   $size_id=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'size_id');
	$size_name=$s->getFieldValue('size_master','id="'.$size_id.'"','size');
$data3.="<input name='oderitem1' type='text' id='oderitem1' style='width:100%;' value='".$jobcarditm." --- ".$size_name."' size='15' />";
$data3.="<input name='size_id' type='hidden' id='size_id' style='width:100%;' value='".$size_id."' size='15' />";
$data3.="<input name='finished_item' type='hidden' id='oderitem' style='width:100%;' value='".$jobcarditmid."' size='15' />";

 $data4='';


$data5='';
$floor_sqlm=DB_query("Select * from material_job_item where material_slip_id='".$_REQUEST['jobid']."' order by id ASC",$db);
$r=0;
while($floor_rowm=DB_fetch_array($floor_sqlm)){
	$floor_sql1=DB_query("Select * from item_master where id='".$floor_rowm['mst_itemid']."'",$db);
	$floor_row1=DB_fetch_array($floor_sql1);
	
	
	$mitm_sql1=DB_query("Select sum(A.issueqty) AS isum from issueqty AS A RIGHT JOIN addissue AS B ON B.id=A.issue_id where A.mst_itemid='".$floor_row1['id']."' and B.issue_reg_no='".$_REQUEST['jobid']."'",$db);
	$mitm_row1=DB_fetch_array($mitm_sql1);
	if($mitm_row1['isum']==''){$mitm_row1['isum']=0;}
	if($mitm_row1['isum']<$floor_rowm['total_req_qty']){
	         $op=openingBalance($function_filter,$floor_row1['id']);
              //echo "openingBalance"."<br>";
 		      $in_1=receivedMRN($function_filter,$floor_row1['id']);
          //echo "receivedMRN"."<br>";
 		    $out_1=issueSlip($function_filter,$floor_row1['id']);
           // echo "issueSlip"."<br>";
		   $out_2=issueSiteToSite($function_filter,$floor_row1['id']);		
          // echo "issuesitetosite"."<br>";
		   $in_2=receivedSiteToSite($function_filter,$floor_row1['id']);
		// echo " receivesitetosite"."<br>";
		  $out_3=issueMatarialReturn($function_filter,$floor_row1['id']);
		 
		   $out_4=Rgpchallan($function_filter,$floor_row1['id']);
		   $out_5=Nrgp($function_filter,$floor_row1['id']);
		  $in_3=receivedReturn($function_filter,$floor_row1['id']);		 
		  //$in_4=return_rejection($function_filter,$myrow['id']);
		   $in_4=Rgpreturn($function_filter,$floor_row1['id']);
		     $in_5=FinishedMR($function_filter,$floor_row1['id']);
		    $invalue=($op+$in_1[0]+$in_2+$in_3+$in_4+$in_5);
		
		     $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		  $tot=trim($invalue)-trim($outvalue);
		
		
		 $total_current=$tot;
	
	$data5.="<tr bgcolor='#FFFFFF'>";
	$data5.="<td class='headercol1'><input name='delitem[]' type='checkbox' value=".$floor_row1['id']." id='delitem_".$r."' ></td>";
	$data5.="<td class='headercol2'><input  type='hidden'   readonly=''  id='itemdataid_".$r."'  name='itemdataid[]' value=".$floor_row1['id']." ></td>";
	$data5.="<td class='headercol3'><input type='text' value='".$floor_rowm['item_code']."'  id='itemcode_".$r."' name='itemcode[]' size='20' /></td>";
	$data5.="<td class='headercol4'><input type='text' name='desc[]'  id='descriptions_".$r."'  value='".$floor_rowm['item_name']."'></td>";
	$data5.="<td><input type='text' name='uom[]' id='uom_".$r."' value=".$floor_rowm['unit']." > </td>";
	$data5.="<td><input type='text' name='current_stock[]' id='Stockbalance_".$r."' size='10' value='".$total_current."' readonly='true'></td>";	
	$data5.="<td><input type='text' name='req_qty[]'  id='receive_".$r."' size='30'  value='".($floor_rowm['total_req_qty']-$mitm_row1['isum'])."'></td>";
	$data5.="<td><input type='text' name='issueqty[]' id='issueqty_".$r."' size='30'   
	value='' onkeyup='calamt(this.id,this.value)' ></td>";
	$data5.="<td><input type='text' name='issuerate[]' id='issuerate_".$r."' size='30'  value='".round($floor_row1['last_po_price'],2)."'></td>";
	$data5.="<td><input type='text' name='totalamt[]' id='totalamt_".$r."' size='30'  value='' readonly  ></td>";
	$data5.="</tr>";
	}
	$r++;
}

$data6='';
   $indentid=$s->getField('material_slip_against_job_card','id',$_REQUEST['jobid'],'indent_id');
   if($indentid==0){$indentid="";}
   $indentidno=$s->getFieldValue('prd_wo','id="'.$indentid.'"','wo_no');


$data6.="<input name='indent_id' type='hidden' id='indent_id' style='width:100%;' value='".$indentid."' size='15' />";
$data6.="<input name='indent_id1' type='text' id='indent_id1' style='width:100%;' value='".$indentidno."' size='15' />";

echo $data=$data1."__".$data2."__".$data3."__".$data4."__".$data5."__".$data6;
			
			
			
