<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>


<?php

/*************************** new *****************************/
						
						function openingBalance($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];								
								if($site!='')
								$filter[]="site = '".$site."'";
								if($store!='')
								$filter[]="store = '".$store."'";
								if($from!='--' && $to!='--')
								$filter[]="reveive_date <= '".$from."'";
								if($item!='')
								$filter[]="itemcode = '".$item."'";
								
								$filter=implode(' and ',$filter);
								 $sql1="Select stock, rate from opening_stockitemwise where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								return $myrow1['stock'];
							}
                      
					   

						
                    function receivedMRN($function_filter,$item)
						{
							global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							if($site!='')
							$filter[]="addmrn.site = '".$site."'";
							if($store!='')
							$filter[]="addmrn.StoreCode = '".$store."'";
							if($item!='')
							$filter[]="addmrnqty.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							 $sql1="Select SUM(addmrnqty.reciveqty) from addmrn left join addmrnqty 
							       on(addmrn.id=addmrnqty.issue_id) where Cancel_status='N' and $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(addmrnqty.reciveqty)'];
						}
						

							
			               function issueSlip($function_filter,$item)
							{
								global $db;
								$site=$function_filter[0];
								$store=$function_filter[1];
								$from=$function_filter[2];
								if($site!='')
								$filter[]="addissue.site = '".$site."'";
								if($store!='')
								$filter[]="addissue.mst_storeid = '".$store."'";
								if($item!='')
								$filter[]="issueqty.mst_itemid = '".$item."'";
								
								
								$filter=implode(' and ',$filter);
							
							 	$sql1="Select SUM(issueqty.issueqty) from addissue left join 
								 issueqty on(addissue.id=issueqty.issue_id) where $filter";
								$result1=DB_query($sql1,$db);
								$myrow1=DB_fetch_array($result1);
								
								return $myrow1['SUM(issueqty.issueqty)'];
							}




				function receivedReturn($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="material_return.site = '".$site."'";
					if($store!='')
					$filter[]="material_return.store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="material_return.returndate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="material_return_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					  $sql1="Select SUM(material_return_details.receiveqty) 
					  from material_return left join material_return_details    
					  on(material_return.id=material_return_details.parentId) where $filter";
				 
					
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(material_return_details.receiveqty)'];
				}



				function receivedSiteToSite($function_filter,$item)
				{
					global $db;
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="transfer_receipt.Received_to = '".$site."'";
					if($store!='')
					$filter[]="transfer_receipt.Received_store = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="transfer_receipt.MRNDate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="transfer_receipt_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
					
					 $sql1="Select SUM(transfer_receipt_details.reciveqty)
					  from transfer_receipt left join transfer_receipt_details 
					  on(transfer_receipt.id=transfer_receipt_details.transfer_receipt_id) where $filter";
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					return $myrow1['SUM(transfer_receipt_details.reciveqty)'];
				}

				function issueSiteToSite($function_filter,$item)
				{
					global $db;
				 
					$site=$function_filter[0];
					$store=$function_filter[1];
					$from=$function_filter[2];
					$to=$function_filter[3];
					
					if($site!='')
					$filter[]="transfer_issue.sitecode = '".$site."'";
					if($store!='')
					$filter[]="transfer_issue.fromstore = '".$store."'";
					if($from!='--' && $to!='--')
					$filter[]="transfer_issue.issuedate between '".$from."' and '".$to."'";
					if($item!='')
					$filter[]="transfer_issue_details.itemid = '".$item."'";
					
					$filter=implode(' and ',$filter);
						 $sql1="Select SUM(transfer_issue_details.issueqty)  from
						  transfer_issue left join transfer_issue_details  
						  on(transfer_issue.id=transfer_issue_details.transfer_issue_id) where $filter";
					$result1=DB_query($sql1,$db);
					$myrow1=DB_fetch_array($result1);
					$return_array=$myrow1['SUM(transfer_issue_details.issueqty)'];
					//$avg_rate=$myrow1['SUM(transfer_issue_details.rate)'];
					//$return_array[]=$avg_rate;
					return $return_array;
					
				}
					function issueMatarialReturn($function_filter,$item)
					{
						global $db;
						$site=$function_filter[0];
						$store=$function_filter[1];
						$from=$function_filter[2];
						$to=$function_filter[3];						
						if($site!='')
						$filter[]="inv_material_return.sitecode = '".$site."'";
						if($store!='')
						$filter[]="inv_material_return.storecode = '".$store."'";
						if($from!='--' && $to!='--')
						$filter[]="inv_material_return.MRNDate between '".$from."' and '".$to."'";
						if($item!='')
						$filter[]="inv_material_return_details.itemid = '".$item."'";
						
						$filter=implode(' and ',$filter);
						
					  $sql1="Select SUM(inv_material_return_details.ReturnQty) 
					  from inv_material_return left join inv_material_return_details   
					   on(inv_material_return.id=inv_material_return_details.parentId) where $filter";
						$result1=DB_query($sql1,$db);
						$myrow1=DB_fetch_array($result1);
						return $myrow1['SUM(inv_material_return_details.ReturnQty)'];
					}


                     function Rgpchallan($function_filter,$item)
					  {
					  
					      global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							
							if($site!='')
							$filter[]="rgp_tab.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_tab.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_tab.date between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="rgp_tab_details.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							  $sql1="Select SUM(rgp_tab_details.qty) 
							  from rgp_tab left join rgp_tab_details 
							  on(rgp_tab.id=rgp_tab_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_tab_details.qty)'];
					  
					  
					  		
					  }	
					  function Rgpreturn($function_filter,$item)
					    {
					  
					      global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							
							if($site!='')
							$filter[]="rgp_return.branch = '".$site."'";
							if($store!='')
							$filter[]="rgp_return.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="rgp_return.return_date between '".$from."' and '".$to."'";
							if($item!='')
							$filter[]="rgp_return_details.item_id = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							  $sql1="Select SUM(rgp_return_details.qty) 
							  from rgp_return left join rgp_return_details 
							  on(rgp_return.id=rgp_return_details.parent_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(rgp_return_details.qty)'];
					  
					  
					  		
					  }	
					  
					  
					  function Nrgp($function_filter,$item)
					    {					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
							$to=$function_filter[2];
							
							if($site!='')
							$filter[]="nrgp_challan.branch = '".$site."'";
							if($store!='')
							$filter[]="nrgp_challan.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="nrgp_challan.date <= '".$from."' ";
							if($item!='')
							$filter[]="nrgp_challan_details.item_code = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							  $sql1="Select SUM(nrgp_challan_details.qty) 
							  from nrgp_challan left join nrgp_challan_details 
							  on(nrgp_challan.id=nrgp_challan_details.parant_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(nrgp_challan_details.qty)'];
					  
					  
					  		
					  }	
					  
					  function FinishedMR($function_filter,$item)
					    {					  
					        global $db;
							$site=$function_filter[0];
							$store=$function_filter[1];
							$from=$function_filter[2];
														
							if($site!='')
							$filter[]="finished_recieved.site = '".$site."'";
							if($store!='')
							$filter[]="finished_recieved.store = '".$store."'";
							if($from!='--' && $to!='--')
							$filter[]="finished_recieved.recieved_date <= '".$from."' ";
							if($item!='')
							$filter[]="finished_recieved_details.mst_itemid = '".$item."'";
							
							$filter=implode(' and ',$filter);
							
							   $sql1="Select SUM(finished_recieved_details.reciveqty) 
							  from finished_recieved left join finished_recieved_details 
							  on(finished_recieved.id=finished_recieved_details.finished_recieved_id) where $filter";
							$result1=DB_query($sql1,$db);
							$myrow1=DB_fetch_array($result1);
							return $myrow1['SUM(finished_recieved_details.reciveqty)'];
					  
					  
					  		
					  }	



					
									



if($_REQUEST['Save'])
{
	$data['document_typ']=$_REQUEST['doc_type'];
	$data['date']=FormatDateForSQL($_REQUEST['date']);
	$data['remove_date']=FormatDateForSQL($_REQUEST['removedate']);
	$data['remove_time']=$_REQUEST['removetime'];
	$data['form_no']=$_REQUEST['formname'];
	$data['vehicle_no']=$_REQUEST['vehicle'];
	$data['expected_time']=$_REQUEST['expected_time'];
	$data['appox_value']=$_REQUEST['appox_value'];
	$data['remarks']=$_REQUEST['remarks'];
	$cond="id='".$_REQUEST['ID']."'";
	$s->RecordEdit('rgp_tab', $data, $cond);
	
	for($i=0;$i<count($_REQUEST['itemdataid']);$i++)
	{
		if($_REQUEST['itemdataid'][$i]!='' )
		{			
		$data_arr['batch_no']= $_POST['batch_no'][$i];
		$data_arr['job_process']= $_POST['job_process'][$i];
		$data_arr['qty']= $_REQUEST['qty'][$i];
		$data_arr['stock_qty']= $_REQUEST['stock_qty'][$i];
		$data_arr['job_rate']= $_REQUEST['job_rate'][$i];
		$data_arr['jobvalue']= $_REQUEST['job_value'][$i];
		$cond="id='".$_REQUEST['itemdataid'][$i]."'";
		$s->RecordEdit('rgp_tab_details', $data_arr, $cond);
		
		               $data_date=explode('/',$_REQUEST['date']);
                      $date51=$data_date[2].'-'.$data_date[1].'-'.$data_date[0];	
			          $date12= strtotime(date("Y-m-d", strtotime($date51)) . " +0 day");					
                        $date= date("Y-m-d",$date12);
					$qty=$_REQUEST['qty'][$i]-$_REQUEST['oldqty'][$i];
					
					 $check_current_opening="Select * from stock_summary where date='".$date."'
					 and site='".$_REQUEST['sitecode']."' and store='".$_REQUEST['store']."'
					  and item='".$_REQUEST['itemcode'][$i]."'";
					
					$check_current_op_result=DB_query($check_current_opening,$db);
					//echo DB_num_rows($check_current_op_result);
					
					if(DB_num_rows($check_current_op_result)=='0')
					{
						$get_previous_closing="Select * from stock_summary where site='".$_REQUEST['sitecode']."'
						 and store='".$_REQUEST['store']."' and item='".$_REQUEST['itemcode'][$i]."' 
						 and date<'".$date."' ORDER BY DATE DESC LIMIT 0,1";
						$previous_closing_result=DB_query($get_previous_closing,$db);
						$previous_closing_row=DB_fetch_array($previous_closing_result);
						if(DB_num_rows($previous_closing_result)=='0')
						{
							$check_opening_entry="Select * from opening_stockitemwise 
													where site='".$_REQUEST['sitecode']."' 
													and store='".$_REQUEST['store']."' 
													and itemcode='".$_REQUEST['itemcode'][$i]."'
													and reveive_date<'".$date."'  ";
							$check_opening_entry_result=DB_query($check_opening_entry,$db);
							$check_opening_entry_row=DB_fetch_array($check_opening_entry_result);
							if(DB_num_rows($check_opening_entry_result)>0){
							$opening_qty=$check_opening_entry_row['stock'];
							$opening_rate=$check_opening_entry_row['rate'];
							$opening_value=$check_opening_entry_row['amount'];}else
							{$opening_qty='';
							$opening_rate='';
							$opening_value='';}
						}
						else
						{
							$opening_qty=$previous_closing_row['closing_qty'];
							$opening_rate=$previous_closing_row['closing_rate'];
							$opening_value=$previous_closing_row['closing_value'];
						}
							$outwards_qty=$_REQUEST['issueqty'][$i]; 
							$outwards_value=$_REQUEST['totalamt'][$i];
							$outwards_rate=$outwards_value/$outwards_qty;
							
							$closing_qty=$opening_qty-$outwards_qty;
							$closing_value=$opening_value-$outwards_value;
							$closing_rate=round($closing_value/$closing_qty);
							$insert_first_summary="Insert into stock_summary set 
													site='".$_REQUEST['sitecode']."',     
													store='".$_REQUEST['store']."',    
													item='".$_REQUEST['itemcode'][$i]."',
													opening_qty='".$opening_qty."',  
													opening_rate='".$opening_rate."',    
													opening_value='".$opening_value."',    
													outwards_qty='".$outwards_qty."',    
													outwards_rate='".round($outwards_rate,2)."',    
													outwards_value='".$outwards_value."',    
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."',    
													date='".$date."' 	";
							$result1=DB_query($insert_first_summary,$db);
						
					}
					else
					{
						$check_current_op_row=DB_fetch_array($check_current_op_result);
						$id=$check_current_op_row['id'];
						$outwards_qty=$check_current_op_row['outwards_qty']+$qty; 
						$outwards_value=$check_current_op_row['outwards_value']+($qty*$_REQUEST['jobrate'][$i]); 
						$outwards_rate=$outwards_value/ $outwards_qty;
						$closing_qty=$check_current_op_row['opening_qty']+$check_current_op_row['inwards_qty']-$outwards_qty;
					$closing_value=$check_current_op_row['opening_value']+$check_current_op_row['inwards_value']-$outwards_value;
						$closing_rate= round($closing_value/$closing_qty);
							 $update_summary="Update  stock_summary set 
													outwards_qty='".$outwards_qty."',    
													outwards_rate='".round($outwards_rate,2)."',    
													outwards_value='".$outwards_value."',    
													closing_qty='".$closing_qty."',    
													closing_rate='".$closing_rate."',    
													closing_value='".$closing_value."' where id=$id ";
						$result2=DB_query($update_summary,$db);
						
						
					}
					
					          $data_date1=explode('/',$_REQUEST['date']);
                             $date52=$data_date1[2].'-'.$data_date1[1].'-'.$data_date1[0];	 
					          $date2= strtotime(date("Y-m-d", strtotime($date52)) . " +1 day");
                              $date1= date("Y-m-d",$date2);
							   if($date1<=date('Y-m-d'))
							   {
 	get($_REQUEST['sitecode'],$_REQUEST['store'],$date1,$_REQUEST['itemcode'][$i],$closing_qty,$closing_rate,$closing_value);
								}		
					              
								    }
								  
		
		$s->pageLocation("index.php?route=Inventory/transation/Rgp_index".$rurl);

		
		}		
	
	//$s->pageLocation("index.php?route=Inventory/transation/Rgp_index".$rurl);
	
} 
$SQLGet=DB_query("select * from rgp_tab where id='".$_REQUEST['ID']."'",$db);
$Rec=DB_fetch_array($SQLGet);
extract($Rec);
$function_filter[]=$Rec['branch'];
$function_filter[]=$Rec['store'];
$function_filter[]=$Rec['date'];
				
?>







	
<h2 align="center"><strong>RGP</strong></h2>
<form name="form1" action="" method="post" >


<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
    <th><strong>Branch</strong></th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname');?>
	<input type="hidden" name="sitecode" value="<?php echo $branch;?>">
	<input type="hidden" name="store" value="<?php echo $store; ?>" />
	</td>
    <th>RGP No </th>
    <td style="width: 250px;"><?php echo $rgp_no;?></td>
</tr>

<tr> <th><strong>Document Type .</strong></th>
    <td>
      <select name="doc_type" style="width:100%" >
        <option value="0">Select</option>
		<option value="57 F4 Challan"<?php echo($document_typ=='57 F4 Challan'?'selected':''); ?>>57 F4 Challan</option>
      </select>
    </td>
    <th>Date</th>
    <td><input type="text"size="20" name="date"  style="width:100%" value="<?php echo ConvertSQLDate($date); ?>" readonly="readonly" class="datepicker"/>	</td>
</tr>

<tr>
    <th><strong>Supplier</strong></th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('suppliers',"id='".$supplier."'",'vendor_name'); ?>
	<input type="hidden" name="vendor" value="<?php echo $supplier;?>">
		</td>
    <th>Remove Date & Time</th>
    <td style="width:250px;">
    	<div id="dept"><input type="text" id="removedate" name="removedate" value="<?php echo ConvertSQLDate($remove_date); ?>" size="20" style="width:49%" readonly="readonly" class="datepicker"/>&nbsp;<input  id="roundTimeExample" type="text" class="time" name="removetime"    size="20" style="width:49%" readonly="readonly"  value="<?php echo $remove_time; ?>"/>
    	</div>	</td>
</tr>

<tr>
    <th><strong>Form No </strong></th>
    <td style="width:250px;"><span style="margin-bottom:15px;">
      <input name="formname" id="formname" type="text" value="<?php echo $form_no; ?>" style="width:100%"size="20" />
    </span></td>
    <th>Vehicle No.</th>
    <td> <input type="text"size="20" name="vehicle" value="<?php echo $vehicle_no; ?>" id="vehicle"   style="width:100%" />	</td>
</tr>

<tr></tr>
</table> 
	
<p align="left" style="padding-left:10px;">
<!--<input type="button" onclick="addRow('dataTable')" value="Add Rows" class="search" />-->
 <!--<input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" />-->  </p>  
    <div id="itemdata">
      <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
		<th><strong>S.R.</strong></th>
		 <th></th>
          <th><strong>Part Code</strong></th>
          <th><strong>Part Name</strong></th>
          <th><strong>Unit</strong></th>
		  <th><strong>Batch No.</strong></th>
		  <th><strong>Stock Qty.</strong></th>
          <th><strong>Qty</strong></th>
          <th><strong>Reason</strong></th>
		   <th><strong>Job Rate</strong></th>
		    <th><strong>Job Value</strong></th>
		   
        </tr>
        <tbody id="dataTable">
<?php $i=0; $Getde=DB_query("SELECT * FROM rgp_tab_details where parent_id='".$_REQUEST['ID']."'",$db); 
while($GetRecord=DB_fetch_array($Getde)){
$Item_code=$s->GetFieldValue('item_master',"id='".$GetRecord['mst_itemid']."'",'StockID');
$ItemName=$s->GetFieldValue('item_master',"id='".$GetRecord['mst_itemid']."'",'item_name');
$unit=$s->GetFieldValue('item_master',"id='".$GetRecord['mst_itemid']."'",'unit');
$unit_name=$s->GetFieldValue('unitsofmeasure',"unitid='".$unit."'",'unitname');

       
		
		    $op=openingBalance($function_filter,$GetRecord['mst_itemid']);
            //  echo "openingBalance"."<br>";
 		      $in_1=receivedMRN($function_filter,$GetRecord['mst_itemid']);
          //echo "receivedMRN"."<br>";
 		    $out_1=issueSlip($function_filter,$GetRecord['mst_itemid']);
           // echo "issueSlip"."<br>";
		   $out_2=issueSiteToSite($function_filter,$GetRecord['mst_itemid']);		
          // echo "issuesitetosite"."<br>";
		   $in_2=receivedSiteToSite($function_filter,$GetRecord['mst_itemid']);
		// echo " receivesitetosite"."<br>";
		  $out_3=issueMatarialReturn($function_filter,$GetRecord['mst_itemid']);
		 
		    $in_4=Rgpreturn($function_filter,$GetRecord['mst_itemid']);
		
		   $out_4=Rgpchallan($function_filter,$GetRecord['mst_itemid']);
		 
		 	 
		  //$in_4=return_rejection($function_filter,$myrow['id']);
		   $invalue=($op+$in_1+$in_2+$in_3+$in_4);
		   $outvalue=($out_1+$out_2+$out_3+$out_4); 
		  //$in_4=return_rejection($function_filter,$myrow['mst_itemid']);
		 // $invalue=($op+$in_1+$in_2+$in_3);
		  //$outvalue=($out_1+$out_2+$out_3);
		  $tot=$invalue-$outvalue;
		  $total_current=$tot;
		





?>
           <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="" id="delitem" /></td>
            <td><input  type="hidden"   readonly=""  id="itemdataid"  name="itemdataid[]" value="<?php echo $GetRecord['id'];?>" /></td>
            <td><?php echo $Item_code; ?><input type="hidden" tabindex=""  value="<?php echo $GetRecord['mst_itemid']; ?>" readonly id="itemcode" name="itemcode[]"size="20" 
			onkeyup="opendata(this.value,this.id)"/>
            </td>
            <td><?php echo $ItemName; ?><input type="hidden" name="desc[]"  id="descriptions" size="25" readonly  value="<?php echo $ItemName; ?>"/></td>
            <td><?php echo $unit_name; ?><input type="hidden" name="uom[]" id="uom" size="5" value="<?php echo $unit_name; ?>" readonly />
            </td>
              <td><input type="text" name="batch_no[]" value="<?php echo $GetRecord['batch_no']; ?>"  id="batchno"  size="10"  /></td>
			  <td><input type="text" name="stock_qty[]"  id="stock_qty_<?php echo $i; ?>" value="<?php echo $total_current; ?>"  size="10"  /></td>
            <td>
			<input type="hidden" id="oldqty_<?php echo $i; ?>" name="oldqty[]" value="<?php echo  $GetRecord['qty'];?>" />
			<input  type="text" name="qty[]"  id="qty_<?php echo $i; ?>" size="15" onkeyup="chkstockqty(<?php echo $i; ?>)"  value="<?php echo $GetRecord['qty']; ?>"/></td>
            <td><select name="job_process[]" id="jobprocess" >
			<option value="0">Select</option>
			<?php $sql_process=DB_query("select * from job_work_master",$db);
			while($row1=DB_fetch_array($sql_process)){
			$sel='';
			if($GetRecord['job_process']==$row1['id'])
			$sel='selected';
			?>
			<option value="<?php echo $row1['id']; ?>"<?php echo $sel; ?>><?php echo $row1['jobwork_name']; ?></option>
			<?php } ?>
			</select>
			</td>
           <td><input  type="text" name="job_rate[]"  id="jobrate_<?php echo $i; ?>" size="15" value="<?php echo $GetRecord['job_rate']; ?>"    onkeyup="caltotal(this.id)"/></td>
		    <td><input  type="text" name="job_value[]"  id="jobvalue_<?php echo $i; ?>" value="<?php echo $GetRecord['jobvalue']; ?>" size="15"   /></td>
</tr>
<?php $i++;} ?>
<input type="hidden" name="count" id="count" value="<?php echo $i; ?>" />
        </tbody>
      </table>
    </div>
    <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden"  value="" id="edit_cnt" />
  <p style="margin-bottom:15px;"></p>
  <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
 

<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Remarks </strong></th>
<td colspan="3"><textarea name="remarks"  style="width:100%" id="remark"><?php echo $remarks; ?></textarea></td>
</tr>
<tr>
<th><strong>Expected time</strong></th>
<td style="width:150px;"><input type="text" id="expected_time" value="<?php echo $expected_time; ?>" name="expected_time"  style="width:100%"  /></td>
<th><strong>Appox. Value </strong></th>
<td style="width:150px;"><input type="text" id="appox_value" name="appox_value" value="<?php echo $appox_value; ?>"   style="width:100%" 
onfocus="GrabdTotal()"  /></td>
</tr>
</table>
<p align="center">
  <input type="submit" name="Save" value="Save"  />
</p>
</form>
<script language="javascript" type="text/javascript">
function opendata(str,id)
{
 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","showpopup1.php?site="+str+"&data="+id,true);
	xmlhttp.send();

}
function getItemsList1(id,code,shade,rate,ctr)
{ 
     
	 var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	
	if(ctr1[1]==undefined)
	{
	//if(document.getElementById('itemdataid').value=='')
	//{
	
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = rate;
	
	//}
	}
	else
	{
	//if(document.getElementById('itemdataid_'+i).value=='')
	//{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = rate;
	
	//}	
	}	
	document.getElementById("lightbox").style.display='none';
	//var data= addRow('dataTable')
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}
 
 function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

function caltotal(str)
{

var id=str.split("_");
var i=id[1];
if(id[1]==undefined)
{
var jobvalue1= parseFloat(document.getElementById("qty").value)*parseFloat(document.getElementById("jobrate").value);
document.getElementById("jobvalue").value=jobvalue1.toFixed(2);

}
else
{
var jobvalue1= parseFloat(document.getElementById("qty_"+i).value)*parseFloat(document.getElementById("jobrate_"+i).value);
document.getElementById("jobvalue_"+i).value=jobvalue1.toFixed(2);
}


}


function calculateTotalExcise()
{
	alert("jobvalue");
	var rete=document.getElementById("jobvalue").value;
	alert(rete);
}

function addRow(tableID) 
{	
	if(document)
		var table = document.getElementById(tableID);
		
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			//  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
										
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
 
 
 function calculateapprox()
{
	var totalBasic=0;
	var first_row=document.getElementById("jobvalue").value;
	if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalBasic1=document.getElementById("jobvalue_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	  document.getElementById("appox_value").value=parseFloat(totalBasic)+parseFloat(first_row);
}


function GrabdTotal()
{
	var Total=0;
	count1=document.getElementById("count").value;
	for(var i=0;i<count1;i++)
	{
		var q=parseFloat(document.getElementById("jobvalue_"+i).value);
		//alert(q);
		var Total=Total+q;
		//alert(Total);
	}
	document.getElementById("appox_value").value=Total;
}
 
 
function chkstockqty(i)
{
		var StockQty2=parseFloat(document.getElementById("stock_qty_"+i).value);
		var oldqty=parseFloat(document.getElementById("oldqty_"+i).value);
		var StockQty1=StockQty2+oldqty;
		var Qty1=parseFloat(document.getElementById("qty_"+i).value);
		if(Qty1>StockQty1)
		{
			alert("You Can't Take Greater Qty Than Available Stock");
			document.getElementById("qty_"+i).value='';
			document.getElementById("qty_"+i).focus();
			return false;
		}
} 
</script>
