<?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');

$data1='';
$data2='';
$data3='';
$data4='';
$data5='';
$data6='';
$data7='';
$data8='';
$data9='';

$arrayItem=explode(",",$_REQUEST['q']);
$newString=implode("','",$arrayItem);

foreach($arrayItem as $singleID)
{
$challanNo[]=$s->getField('job_work_return','id',$singleID,'returnSlipNo');
}
$stringChallan=implode(', ',$challanNo);

$data1.='<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">';
$data1.='<tr>';
$data1.='<td class="tabledata"><strong>Item Code</strong></td>';
$data1.='<td class="tabledata"><strong>Item Name </strong></td>';
$data1.='<td class="tabledata"><strong>Item Description</strong></td>';
$data1.='<td class="tabledata"><strong>UOM</strong></td>';
$data1.='<td class="tabledata"><strong>Received Quantity</strong></td>';
$data1.='<td class="tabledata"><strong>Rate</strong></td>';
$data1.='<td class="tabledata"><strong>Total Amount</strong></td>';
$data1.='<td class="tabledata"><strong>Process</strong></td>';
$data1.='</tr>';
  $mainQry = "SELECT *, SUM(receivedQty) as totRecieve FROM job_return_details WHERE masterId IN ('".$newString."') 
GROUP BY mst_itemId, rate, PROCESS";
$item_sql=DB_query($mainQry,$db);
if(!$item_sql)
{
die('Error.'.DB_error_msg($db));
}
$j=0;
while($details_row2=DB_fetch_array($item_sql))
{ 

$data1.='<input type="hidden" name="mst_itemid['.$j.']" id="mst_itemId" value="'.$details_row2['mst_itemId'].'" />';
$data1.='<input type="hidden" name="rate['.$j.']" id="rate" value="'.$details_row2['rate'].'" />';
$data1.='<input type="hidden" name="receivedQty['.$j.']" id="receivedQty" value="'.$details_row2['totRecieve'].'" />';
$data1.='<input type="hidden" name="totalAmount['.$j.']" id="totalAmount" value="'.$details_row2['totRecieve']*$details_row2['rate'].'" />';
$data1.='<input type="text" name="process['.$j.']" id="process" value="'.$details_row2['process'].'" />';

		//$item_result=DB_query($item_sql,$db);
		//$item_row=DB_fetch_array($item_result);
		$itemCode=$s->getField('item_master','id',$details_row2['mst_itemId'],'StockID');
		$itemName=$s->getField('item_master','id',$details_row2['mst_itemId'],'item_name');
		$itemDesc=$s->getField('item_master','id',$details_row2['mst_itemId'],'item_desc');
		$unitId=$s->getField('item_master','id',$details_row2['mst_itemId'],'mst_unitid');
		
		$unitnames=$s->getField('unitsofmeasure','unitid',$unitId,'unitname');
		$processName=$s->getField('job_work_master','id',$details_row2['process'],'jobwork_name');
		$s->getField('job_work_return','id',$details_row2['challanNo'],'returnSlipNo');
$data1.='<tr bgcolor="#c1c1c1">';
$data1.='<td>'.$itemCode.'</td>';
$data1.='<td>'.$itemName.'</td>';
$data1.='<td>'.$itemDesc.'</td>';
$data1.='<td>'.$unitnames.'</td>';
$data1.='<td>'.$rte=$details_row2['rate'].'</td>';
$data1.='<td>'.$qty=$details_row2['totRecieve'].'</td>';
$data1.='<td>'.$totAmt[]=$rte*$qty.'</td>';
$data1.='<td>'.$processName.'</td>';
$data1.='</tr>';
$totalBasic=array_sum(array_filter($totAmt));
$j++; } // While Loop Ends 
$data1.='<input type="hidden" name="countItems" id="countItems" value="'.$j.'" />';
$data1.='</table>';
    
$data2.=$totalBasic;

$sql_tax=DB_query("SELECT taxrate FROM service_tax_master where type='ST'",$db);
	$row1=DB_fetch_array($sql_tax);
	
	$data3.=round($totalBasic*($row1['taxrate']/100),2); 
	
	
	$sql_tax=DB_query("SELECT taxrate FROM service_tax_master where type='E'",$db);
	$row1=DB_fetch_array($sql_tax);
	if($data3==''){
	$stv=0;
	}else{
	$stv=$data3;
	}
	
	$data4=round($stv*($row1['taxrate']/100),2);
	
	
	$sql_tax=DB_query("SELECT taxrate FROM service_tax_master where type='S'",$db);
	$row1=DB_fetch_array($sql_tax);
	if($stv==''){
	$stv=0;
	}else{
	$stv=$stv;
	}
	if($data4==''){
	$ecess=0;
	}else{
	$ecess=$data4;
	}
	
	$data5=round($stv*($row1['taxrate']/100),2); 
	
	$data7=round($totalBasic*($_REQUEST['tdsPerc']/100),2); 
	
	$data8=round($data7*($_REQUEST['ecesPerc']/100),2); 
	
	$data9=round($data7*($_REQUEST['secesPerc']/100),2); 
	$totalTDS=round($data7+$data8+$data9,2);
	
	$data6=round($data2+$data3+$data4+$data5-$totalTDS,2);
	
echo $data=$data1.'__'.$data2.'__'.$data3.'__'.$data4.'__'.$data5.'__'.$data6.'__'.$data7.'__'.$data8.'__'.$data9;

?>