<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');

$title = _('Job Work List');

$PageName ='Job Work';	

if(isset($_REQUEST['item_popup']))

{

	$_SESSION['site']=$_REQUEST['site'];

	$_SESSION['vendor']=$_REQUEST['vendor'];

	$_SESSION['jobDate']=$_REQUEST['jobDate'];

	$_SESSION['jobPrefix']=$_REQUEST['jobPrefix'];

	$_SESSION['jobDigit']=$_REQUEST['jobDigit'];

	$_SESSION['partyJWNo']=$_REQUEST['partyJWNo'];

}

if(isset($_REQUEST['Cancel']))

{

	unset($_SESSION['site']);

	unset($_SESSION['siteName']);

	unset($_SESSION['vendor']);

	unset($_SESSION['vendorName']);

	unset($_SESSION['jobDate']);

	unset($_SESSION['jobPrefix']);

	unset($_SESSION['jobDigit']);

	unset($_SESSION['partyJWNo']);

	unset($_SESSION['JWitemlist']);

}

if(isset($_REQUEST['Save']))
{

 $prefix=$s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'company_code');
	$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."'",$db);
	$prefix_row=DB_fetch_array($prefix_sql);
	$prefix1=$prefix_row['prefix_code'];
	
	$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
	  $sql="Select jobNumber from job_work where site='".$_REQUEST['site']."' 
	and INSTR(`jobNumber`, '$financial') > 0 order by jobNumber desc limit 0,1";

	$result=DB_query($sql,$db);
	$myrow=DB_fetch_array($result);
	//echo DB_num_rows($result);
	if(DB_num_rows($result)>0)
	{
	
         if($prefix!='')
			{
			$ExplBill=explode("/",$myrow['jobNumber']);
			$maxval = $ExplBill[4];
		    }
		    else
		    {
		    $ExplBill=explode("/",$myrow['jobNumber']);
			$maxval = $ExplBill[3];
		    }			
	//$ExplBill=explode("/",$myrow['Reqno']);
	//$maxval = $ExplBill[3];
	//echo $req_part1;
	$req_final=$maxval+1;
	}else
	{
	$req_final="1";
	}
	        if($prefix!='')
			 $string=$prefix."/".$_REQUEST['site']."/".$financial."/".$prefix1."/";
		     else
		     $string=$_REQUEST['site']."/".$financial."/".$prefix1."/";

	//$string=$prefix."/".$_REQUEST['site']."/".$financial."/";
	   $final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);

		
	 $insertSql1="Insert into job_work set
							 site             ='".$_REQUEST['site']."',   							 
							 vendor           ='".$_REQUEST['vendor']."',
							 jobNumber        ='".$final_string."',  
							 jobDate          ='".FormatDateForSQL($_REQUEST['jobDate'])."',
							 partyJWNo        ='".$_REQUEST['partyJWNo']."',                                                             
                             job_type         ='".$_REQUEST['jobtype']."',                                                              
                             quotid           ='".$_REQUEST['quotid']."', 
							 remarks          ='".$_REQUEST['remarks']."',
							 basicAmount      ='".$_REQUEST['basic_amt']."',                                                               
                             STaxPerc         ='".$_REQUEST['serviceTaxRate']."', 
							 STaxValue        ='".$_REQUEST['serviceTaxValue']."',  
							 SEduPerc         ='".$_REQUEST['ecessRate']."', 
							 SEduValue        ='".$_REQUEST['ecessValue']."',
							 SShePerc         ='".$_REQUEST['sheRate']."',  
							 SSheValue        ='".$_REQUEST['sheValue']."',                                                             
                             totalTax         ='".$_REQUEST['totalTax']."',
                             abtmntRate       ='".$_REQUEST['abtmntRate']."',
                             abtmntValue1     ='".$_REQUEST['abtmntValue1']."',
                             abtmntValue2     ='".$_REQUEST['abtmntValue2']."',
                             wctRate          ='".$_REQUEST['wctRate']."',
                             wctValue         ='".$_REQUEST['wctValue']."',
                             tdsEcessRate     ='".$_REQUEST['tdsEcessRate']."',
                             tdsEcessValue    ='".$_REQUEST['tdsEcessValue']."',
                             tdshEcessRate    ='".$_REQUEST['tdshEcessRate']."',
                             tdshEcessValue   ='".$_REQUEST['tdshEcessValue']."',
                             pluMin           ='".$_REQUEST['pluMin']."',
                             roundVal         ='".$_REQUEST['roundVal']."',
          					 TDSPerc          ='".$_REQUEST['tdsRate']."',  
							 TDSValue         ='".$_REQUEST['tdsValue']."',  
							 service_nature   ='".$_REQUEST['nature_service']."',
							 grandTotal       ='".$_REQUEST['GrandTotal']."',
							 SHE_id           ='".$_REQUEST['sheid']."',
							 Ecess_id         ='".$_REQUEST['ecessid']."',
                             types            ='Process', 
                             quotDate         ='".FormatDateForSQL($_REQUEST['quotDate'])."',
							 created_by       ='".$_SESSION['UserID']."',  
							 created_date     ='".FormatDateForSQL(date('d/m/Y'))."',
							 CompanyId        ='".$_SESSION['ACGCompanyId']."' ";  

							

	$insertResult1=DB_query($insertSql1,$db); 

	$LastId=DB_Last_Insert_ID($db,'job_work','id');

	if(isset($LastId))
	{

		for($str=0;$str<count($_REQUEST['itemID']);$str++)
		{
			$insertSql2="Insert into job_work_details set
									masterId       ='".$LastId."', 
									mst_itemId     ='".$_REQUEST['itemID'][$str]."',  
									quantity       ='".$_REQUEST['qty'][$str]."',                                                                             
                                    price          ='".$_REQUEST['price'][$str]."',                                                                            
                                    Discount       ='".$_REQUEST['Discount'][$str]."',
								    DiscountType   ='".$_REQUEST['DiscountType'][$str]."',
                                    currency       ='".$_REQUEST['currency'][$str]."',
									rate           ='".$_REQUEST['rate'][$str]."', 
									totalAmount    ='".$_REQUEST['totalAmount'][$str]."'";
			$insertResult2=DB_query($insertSql2,$db); 		
                if($_REQUEST['qty'][$str]>=$_REQUEST['pending_qty'][$str])
					{
						$updatePO=DB_query("Update vendorquotationdetails set status='received' where 
						parant_id='".$_REQUEST['quotid']."' and mst_itemid='".$_REQUEST['itemID'][$str]."'",$db);					
					}
                
                }
                
                $get_num_rows=DB_query("Select * from vendorquotationdetails where parant_id='".$_REQUEST['quotid']."'",$db);
				$num_rows=DB_num_rows($get_num_rows);				
				$check_item_stat=DB_query("Select * from vendorquotationdetails where parant_id='".$_REQUEST['quotid']."' and status='received'",$db);
				$received_num_rows=DB_num_rows($check_item_stat);
				
				if($num_rows==$received_num_rows)
				{
					$updatePOStat=DB_query("Update venderquotations set job_work_status='Receive' where 
					id='".$_REQUEST['quotid']."'",$db);
				}

	}

prnMsg( _('Record Inserted Successfully'),'success');

echo "<script>location.href='index.php?route=JobWorkList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";

	unset($_SESSION['site']);
	unset($_SESSION['siteName']);
	unset($_SESSION['vendor']);
	unset($_SESSION['vendorName']);
	unset($_SESSION['jobDate']);
	unset($_SESSION['jobPrefix']);
	unset($_SESSION['jobDigit']);
	unset($_SESSION['partyJWNo']);
	unset($_SESSION['JWitemlist']);

}

?>
<script type="text/javascript" language="javascript">
$.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var site=document.getElementById("site").value;
		
		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#PickedItems").dialog({
				title:'Item List',
				modal: true,
				resizable: false,
				width:900,
				height:400,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO(site);
		});
	});
	
	function GetitemListForDirectPO(str)
{
	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("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","popup_item_list.php?site="+str,true);
	xmlhttp.send();
}

function getItemsList(id,code,shade,itemunit,ctr,itemDesc)
{  

	var dup='empty';
	var itemcount=parseInt(document.getElementById('rowcount1').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	//alert(edit_cnt);
	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;
	}
	
	
	
	
	//alert(counter);
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
	    
		if(document.getElementById('itemid') && document.getElementById('itemid').value=='')
		{
			if(edit_cnt=='')
			{
				var counter=0;
			}
		
			for(var j=0; j<counter; j++)
			{
				if(document.getElementById('itemid_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
			
			if(dup=='empty')
			{	
				//var data=addRow('dataTable');
				document.getElementById('itemid').value = id;
				document.getElementById('itemcode').value = code;
				document.getElementById('itemdesc').value = shade;	
				document.getElementById('itemunit').value =itemunit ;		
							
			}
		} 
		
		else
		{
		
		
			for(var i=counter; i<=itemcount; i++)
			{	
			
			
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{}
				if(document.getElementById('itemid'))
				{
				if(document.getElementById('itemid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(document.getElementById('itemid_'+i))
				{
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				
				if(dup=='empty')
				{
				if(!document.getElementById('itemid_'+i))
				{	
					
				var data= addRow('dataTable');	
				}
					if(document.getElementById('itemid_'+i))
					{	
					
					if(document.getElementById('itemid_'+i).value=='')
					{	
							document.getElementById('itemid_'+i).value = id;
						 	document.getElementById('itemcode_'+i).value = code;
							document.getElementById('itemdesc_'+i).value = shade;	
							document.getElementById('itemunit_'+i).value =itemunit ;		
							
												
						break;
					}
					}
					else
					{
						continue;
					}
				}
			}
		}
	}
	
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************END HERE******************************************


//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************START HERE******************************************
	else
	{
		if(document.getElementById('itemid').value==document.getElementById("row_id_"+ctr).value)
		{
				document.getElementById('itemid').value = '';
				document.getElementById('itemcode').value = '';
				document.getElementById('itemdesc').value = '';	
				document.getElementById('itemunit').value ='' ;		
				
		}
		else
		{
			for(var i=counter; i<itemcount; i++)
			{
				if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
							document.getElementById('itemid_'+i).value = '';
						 	document.getElementById('itemcode_'+i).value = '';
							document.getElementById('itemdesc_'+i).value = '';	
							document.getElementById('itemunit_'+i).value ='' ;		
							
				}
			}
		}
	}
//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
}
function addRow(tableID) 
{
		
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	document.getElementById("edit_cnt").value=rr;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	//newcell.className='tabledata';
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	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;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	//newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	//newcell.childNodes[0].name = newcell.childNodes[0].name;
	
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
	
}
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=(rowCount);		}
	catch(e) 
	{
	alert(e);
	}
}	

function calcAmt(id)
{
 var aa=id.split("_");
 i=aa[1];
 var totAmt=0;
 var counter=document.getElementById("hiditemcount").value;
 if(i==undefined)
 {
 var qty=document.getElementById("quantity").value;
 var rate=document.getElementById("rate").value;
 if(qty=='') { qty=0; }
 if(rate=='') { rate=0; }
 
 var itemAmt=parseFloat(qty)*parseFloat(rate);
 document.getElementById("totalAmount").value=itemAmt.toFixed(2);
 
 var firstrow= document.getElementById("totalAmount").value;
 if(firstrow=='') { firstrow=0;}
 	for(var j=1; j<=counter; j++)
	{
	var totalAmt=document.getElementById("totalAmount_"+j).value;
	if(totalAmt=='') { totalAmt=0; }

	var totAmt=parseFloat(totalAmt)+parseFloat(totAmt);
	}
	var finalAmt=parseFloat(firstrow)+parseFloat(totAmt);
 }
 else
 {
 var qty=document.getElementById("quantity_"+i).value;
 var rate=document.getElementById("rate_"+i).value;
 if(qty=='') { qty=0; }
 if(rate=='') { rate=0; }
 
 var itemAmt=parseFloat(qty)*parseFloat(rate);
 document.getElementById("totalAmount_"+i).value=itemAmt.toFixed(2);
 
 var firstrow= document.getElementById("totalAmount").value;
 if(firstrow=='') { firstrow=0;}
 	for(var j=1; j<=counter; j++)
	{
	var totalAmt=document.getElementById("totalAmount_"+j).value;
	if(totalAmt=='') { totalAmt=0; }
	var totAmt=parseFloat(totalAmt)+parseFloat(totAmt);
	}
	var finalAmt=parseFloat(firstrow)+parseFloat(totAmt);
 }
 
 document.getElementById("basicAmount").value=finalAmt.toFixed(2);
 calculateGrandTotal();

}

function cal_tax(str){

var ba=document.getElementById('basicAmount').value;
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)
    {
	var data=xmlhttp.responseText.split('__');
    document.getElementById("STaxValue").value=data[0];
	calculateGrandTotal();
    }

  }
xmlhttp.open("GET","check_data_bsm.php?section=cal_servicetax&tax_id="+str+"&ba="+ba,true);
xmlhttp.send();
}
</script>
<script language="javascript" type="text/javascript">

function open_items()

{

	window.open("JobWorkItems.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");

}

function calculateAmount(a)

{

	var quantity = document.getElementById("quantity_"+a).value;

	var rate = document.getElementById("rate_"+a).value;

	var total=quantity*rate;

	document.getElementById("totalAmount_"+a).value=total;

}

function calculateBasic()

{

	var basic=0;

	var count=document.getElementById("itemCount").value;

	for(var b=0;b<count;b++)

	{

		var amount=document.getElementById("totalAmount_"+b).value;

		basic=parseFloat(basic)+parseFloat(amount);

	}

	document.getElementById("basicAmount").value=basic.toFixed(2);

}

function calculateServiceTax()

{

	var spercentage=document.getElementById("STaxPerc").value;

	var BasicAmt=document.getElementById("basicAmount").value;

	var totval=BasicAmt*(spercentage/100);

	document.getElementById("STaxValue").value=totval.toFixed(2);

}

function calculateSEdu()

{

	var STaxValue=document.getElementById("STaxValue").value;

	var SEduPerc=document.getElementById("SEduPerc").value;

	var totalval2=STaxValue*(SEduPerc/100);

	document.getElementById("SEduValue").value=totalval2.toFixed(2);

}

function calculateSShe()

{

	var STaxValue=document.getElementById("STaxValue").value;

	var SShePerc=document.getElementById("SShePerc").value;

	var totalval3=STaxValue*(SShePerc/100);

	document.getElementById("SSheValue").value=totalval3.toFixed(2);

}

function calculateTDS()

{

	var TDSPerc=document.getElementById("TDSPerc").value;

	var basicamt=document.getElementById("basicAmount").value;

	var totalval4=basicamt*(TDSPerc/100);

	document.getElementById("TDSValue").value=totalval4.toFixed(2);
	
	calculateGrandTotal();

}	

function calculateGrandTotal()

{

	var basicAmount=document.getElementById("basicAmount").value;

	var STax=document.getElementById("STaxValue").value;

	var SEdu=document.getElementById("SEduValue").value;

	var SShe=document.getElementById("SSheValue").value;

	var TDS=document.getElementById("TDSValue").value;

	var freight=document.getElementById("freight").value;

	if(basicAmount=='')basicAmount=0;

	if(STax=='')STax=0;

	if(SEdu=='')SEdu=0;

	if(SShe=='')SShe=0;

	if(TDS=='')TDS=0;

	if(freight=='')freight=0;

	var TOTAL=parseFloat(basicAmount)+parseFloat(STax)+parseFloat(SEdu)+parseFloat(SShe)-parseFloat(TDS)+parseFloat(freight);

	document.getElementById("grandTotal").value=TOTAL.toFixed(2);

}

function generateJobNumber(str){

	if (str.length==0)
  {
  document.getElementById("store").innerHTML="";
  document.getElementById("vendor").innerHTML="";
  return;
  }

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)

    {
	//alert(xmlhttp.responseText);
	var data=xmlhttp.responseText.split('__');
    document.getElementById("store").innerHTML=data[0];
  	document.getElementById("vendor").innerHTML=data[1];
    }

  }

xmlhttp.open("GET","JobNumber.php?branch="+str,true);

xmlhttp.send();

}


function cal_cess(str){
var ba=document.getElementById('basicAmount').value;
var stv=document.getElementById('STaxValue').value;

if (str.length==0)
  {
  document.getElementById("SEduValue").value="";
  return;
  }

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)

    {
	var data=xmlhttp.responseText.split('__');
    document.getElementById("SEduValue").value=data[0];
	calculateGrandTotal();
    }

  }

xmlhttp.open("GET","check_data_bsm.php?section=cal_educess&tax_id="+str+"&stv="+stv+"&ba="+ba,true);

xmlhttp.send();
}

function cal_she(str){
var ba=document.getElementById('basicAmount').value;
var stv=document.getElementById('STaxValue').value;
var ecess=document.getElementById('SEduValue').value;
if (str.length==0)
  {
  document.getElementById("SSheValue").value="";
  return;
  }

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)

    {
	var data=xmlhttp.responseText.split('__');
    document.getElementById("SSheValue").value=data[0];
	calculateGrandTotal();
    }

  }

xmlhttp.open("GET","check_data_bsm.php?section=cal_shecess&tax_id="+str+"&stv="+stv+"&ecess="+ecess+"&ba="+ba,true);

xmlhttp.send();


}

function calcAbtValue1(totalamt)
  {
      //var taxAmt=document.getElementById("totalTax").value;
      if(totalamt=='') {totalamt='';}
      //alert(totalamt);
      var abtRate=document.getElementById("abtmntRate").value;
      if(abtRate=='') {abtRate='';}
      //alert(abtRate);
      var finalAmt=parseFloat(abtRate*totalamt/100);
      //alert(finalAmt);
      document.getElementById("abtmntValue1").value=finalAmt.toFixed(2);
  }
  
  function calcAbtValue2(totalamt)
  {
      var abt1=document.getElementById("abtmntValue1").value;
      if(abt1=='') {abt1='';}
      var tax=document.getElementById("totalTax").value;
      if(totalamt=='') {totalamt='';}
      var finalAmt=parseFloat(totalamt-abt1);
      document.getElementById("abtmntValue2").value=finalAmt.toFixed(2);
  }


function calcTotAmt(str,i)
{ 
    var totalamt=0;
    var rate=document.getElementById("rate_"+i).value;
    var quantity=document.getElementById("qty_"+i).value;
    if(quantity==''){quantity=0;}
    if(rate==''){rate=0;}
    //alert(quantity);
    var finalAmt=parseFloat(rate)*parseFloat(quantity);
    //alert(finalAmt);
    document.getElementById("price_"+i).value=finalAmt.toFixed(2);
    document.getElementById("basic_"+i).value=finalAmt.toFixed(2);
    //document.getElementById("TotalSpecial_"+i).value=finalAmt.toFixed(2);
    var countcharges = document.getElementById("hiditemcount").value;
    
        for(var l=0;l<countcharges;l++)
        {
        if(document.getElementById("basic_"+l).value!='')
        var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
        }
        //alert(totalamt);
        document.getElementById("total_item_amount").value=totalamt.toFixed(2);	
        
        
         var rate=document.getElementById("serviceTaxRate").value;
    
    var totalAmount=document.getElementById("total_item_amount").value;
   if(totalAmount=='') { totalAmount='';}
    var finalAmts=parseFloat(rate*totalAmount/100);
    document.getElementById("serviceTaxValue").value=finalAmts.toFixed(2);
    
    
    
    var rate=document.getElementById("ecessRate").value;
    
    var totalAmounts=document.getElementById("serviceTaxValue").value;
   if(totalAmounts=='') { totalAmounts='';}
    var finalAmtss=parseFloat(rate*totalAmounts/100);
    document.getElementById("ecessValue").value=finalAmtss.toFixed(2);
    
    
     var totalAmountBsic=document.getElementById("total_item_amount").value;
    var totalamtss=parseFloat(totalAmounts)+parseFloat(totalAmountBsic)+parseFloat(finalAmtss);
    
    var rate=document.getElementById("sheRate").value;
    
    var totalAmount=document.getElementById("serviceTaxValue").value;
   if(totalAmount=='') { totalAmount='';}
    var finalAmt=parseFloat(rate*totalAmount/100);
    document.getElementById("sheValue").value=finalAmt.toFixed(2);
    
    
     var totalAmountBsic=document.getElementById("total_item_amount").value;
     var totalEcess=document.getElementById("ecessValue").value;
    var totalamt=parseFloat(totalAmount)+parseFloat(totalAmountBsic)+parseFloat(totalEcess)+parseFloat(finalAmt);
    document.getElementById("totalTax").value=totalamt.toFixed(2);
    
    calcAbtValue1(totalamt);
    calcAbtValue2(totalamt);
    
    var abt2=document.getElementById("abtmntValue2").value;
       if(abt2==''){ abt2=0;}
       var wctRate=document.getElementById("wctRate").value;
       
      var finalAmt=parseFloat(wctRate*abt2/100);
      document.getElementById("wctValue").value=finalAmt.toFixed(2);
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
       var totalamt=parseFloat(finalAmt)+parseFloat(tax);
    
    var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      var totTax=parseFloat(tax)+parseFloat(wctValue);
      var tdsRate=document.getElementById("tdsRate").value;
      
      var finalAmt=parseFloat(tdsRate*totTax/100);
      document.getElementById("tdsValue").value=finalAmt.toFixed(2);
      
      
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+finalAmt;
      
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      
      var tdsEcessRate=document.getElementById("tdsEcessRate").value;
      var tdsValue=document.getElementById("tdsValue").value;
      var finalAmt=parseFloat(tdsEcessRate*tdsValue/100);
      document.getElementById("tdsEcessValue").value=finalAmt.toFixed(2);
      
      
     
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+parseFloat(finalAmt)+parseFloat(tdsValue);
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      var tdsValue=document.getElementById("tdsValue").value;
       if(tdsValue==''){ tdsValue=0;}
       
        var tdsecessValue=document.getElementById("tdsEcessValue").value;
       if(tdsecessValue==''){ tdsecessValue=0;}
      
      var tdsSEcessRate=document.getElementById("tdshEcessRate").value;
      var finalAmt=parseFloat(tdsSEcessRate*tdsecessValue/100);
      document.getElementById("tdshEcessValue").value=finalAmt.toFixed(2);
      
      
     
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+parseFloat(tdsValue)+parseFloat(tdsecessValue)+parseFloat(finalAmt);
    //alert(totalamt);
   

                  
         document.getElementById("GrandTotal").value=totalamt.toFixed(2);
         
	document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
        
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
 }
 
 function calcServtax()
{
    var rate=document.getElementById("serviceTaxRate").value;
    
    var totalAmount=document.getElementById("total_item_amount").value;
   if(totalAmount=='') { totalAmount='';}
    var finalAmt=parseFloat(rate*totalAmount/100);
    document.getElementById("serviceTaxValue").value=finalAmt.toFixed(2);
    
    var totalamt=parseFloat(totalAmount)+parseFloat(finalAmt);
     document.getElementById("GrandTotal").value=totalamt.toFixed(2);
     document.getElementById("totalTax").value=totalamt.toFixed(2);
	document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}
function calcWct()
   {
       var abt2=document.getElementById("abtmntValue2").value;
       if(abt2==''){ abt2=0;}
       var wctRate=document.getElementById("wctRate").value;
       
      var finalAmt=parseFloat(wctRate*abt2/100);
      document.getElementById("wctValue").value=finalAmt.toFixed(2);
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
       var totalamt=parseFloat(finalAmt)+parseFloat(tax);
        document.getElementById("GrandTotal").value=totalamt.toFixed(2);
       document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}

function validation()
{
    if(document.getElementById("partyJWNo").value=='')
        {
            alert('Enter Party Job Work No.');
            document.getElementById("partyJWNo").focus();
            return false;
        }
        
    if(document.getElementById("jobtype").value==0)
        {
            alert('Enter Job Type');
            document.getElementById("jobtype").focus();
            return false;
        }
        return true;
}
function DiscountAmounts(DA,id)
{
    
	//numeric(DA,id);
        id1=id.split("_");
	i=id1[1];
        
		var totValue = document.getElementById("price_"+i).value;
		var discType = document.getElementById("PerAmo_"+i).value;
		var disct = document.getElementById("Discount_"+i).value;
                
                if(parseFloat(disct)>parseFloat(totValue))
                    {
                        alert('Discount Cannot Be Greater Than Total Amount');
                        document.getElementById("Discount_"+i).value='';
                        document.getElementById("Discount_"+i).focus();
                        
                        document.getElementById("basic_"+i).value='';
                        return false;
                    }
                    
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=0;l<countcharges;l++){
			if(document.getElementById("basic_"+l)!=null){
			if(document.getElementById("basic_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=0;l<countcharges;l++)
			{
			if(document.getElementById("basic_"+l)!=null){
			if(document.getElementById("basic_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
			}}
			
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);		
		}
                
       var rate=document.getElementById("serviceTaxRate").value;
    
    var totalAmount=document.getElementById("total_item_amount").value;
   if(totalAmount=='') { totalAmount='';}
    var finalAmts=parseFloat(rate*totalAmount/100);
    document.getElementById("serviceTaxValue").value=finalAmts.toFixed(2);
    
    
    
    var rate=document.getElementById("ecessRate").value;
    
    var totalAmounts=document.getElementById("serviceTaxValue").value;
   if(totalAmounts=='') { totalAmounts='';}
    var finalAmtss=parseFloat(rate*totalAmounts/100);
    document.getElementById("ecessValue").value=finalAmtss.toFixed(2);
    
    
     var totalAmountBsic=document.getElementById("total_item_amount").value;
    var totalamtss=parseFloat(totalAmounts)+parseFloat(totalAmountBsic)+parseFloat(finalAmtss);
    
    var rate=document.getElementById("sheRate").value;
    
    var totalAmount=document.getElementById("serviceTaxValue").value;
   if(totalAmount=='') { totalAmount='';}
    var finalAmt=parseFloat(rate*totalAmount/100);
    document.getElementById("sheValue").value=finalAmt.toFixed(2);
    
    
     var totalAmountBsic=document.getElementById("total_item_amount").value;
     var totalEcess=document.getElementById("ecessValue").value;
    var totalamt=parseFloat(totalAmount)+parseFloat(totalAmountBsic)+parseFloat(totalEcess)+parseFloat(finalAmt);
    document.getElementById("totalTax").value=totalamt.toFixed(2);
    
    calcAbtValue1(totalamt);
    calcAbtValue2(totalamt);
    
    var abt2=document.getElementById("abtmntValue2").value;
       if(abt2==''){ abt2=0;}
       var wctRate=document.getElementById("wctRate").value;
       
      var finalAmt=parseFloat(wctRate*abt2/100);
      document.getElementById("wctValue").value=finalAmt.toFixed(2);
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
       var totalamt=parseFloat(finalAmt)+parseFloat(tax);
    
    var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      var totTax=parseFloat(tax)+parseFloat(wctValue);
      var tdsRate=document.getElementById("tdsRate").value;
      
      var finalAmt=parseFloat(tdsRate*totTax/100);
      document.getElementById("tdsValue").value=finalAmt.toFixed(2);
      
      
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+finalAmt;
      
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      
      var tdsEcessRate=document.getElementById("tdsEcessRate").value;
      var tdsValue=document.getElementById("tdsValue").value;
      var finalAmt=parseFloat(tdsEcessRate*tdsValue/100);
      document.getElementById("tdsEcessValue").value=finalAmt.toFixed(2);
      
      
     
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+parseFloat(finalAmt)+parseFloat(tdsValue);
      
      var tax=document.getElementById("totalTax").value;
      if(tax=='') {tax='';}
      
      var wctValue=document.getElementById("wctValue").value;
      if(wctValue==''){ wctValue=0;}
      
      var tdsValue=document.getElementById("tdsValue").value;
       if(tdsValue==''){ tdsValue=0;}
       
        var tdsecessValue=document.getElementById("tdsEcessValue").value;
       if(tdsecessValue==''){ tdsecessValue=0;}
      
      var tdsSEcessRate=document.getElementById("tdshEcessRate").value;
      var finalAmt=parseFloat(tdsSEcessRate*tdsecessValue/100);
      document.getElementById("tdshEcessValue").value=finalAmt.toFixed(2);
      
      
     
      var totalamt=parseFloat(tax)+parseFloat(wctValue)+parseFloat(tdsValue)+parseFloat(tdsecessValue)+parseFloat(finalAmt);
    //alert(totalamt);
   

                  
         document.getElementById("GrandTotal").value=totalamt.toFixed(2);
         
	document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);
var GrandTotAmt = document.getElementById("GrandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
        
	document.getElementById("GrandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("GrandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}




</script>

<?php 
$fetchDta="select * from comprative where id='".$_REQUEST['CPID']."'";
$fetchDtaExec=DB_query($fetchDta,$db); 
$row=DB_fetch_array($fetchDtaExec);


$quotId=$s->GetFieldValue("comprative_detail","parant_id='".$_REQUEST['CPID']."'","quotationid");
$quotNo=$s->GetFieldValue("venderquotations","id='".$quotId."'","quotation_no");


$VendorId=$_REQUEST['SupplierId'];
$vendorType=$s->GetFieldValue('suppliers',"id='".$VendorId."'",'vendor_type');
?>

<div class="body_contain">

<div class="tab_div">



<div id="PickedItems" style="display:none">
</div>



<form action="" method="post" onsubmit="return validation();">
<input type="hidden" name="quotid" id="quotNO" value="<?php echo $quotId;?>" class="cap" style="width:46%" />
<h1><strong><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></strong> </h1>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">

  <tr>
    <td class="tabledata3">Branch</td>
    <td>
	<?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
  $ss="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$row['site']."')";
 $site_sql=DB_query($ss,$db);
  }
 else
 {
$ss="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$row['site']."')";
$site_sql=DB_query($ss,$db);
 }

?>

<select name="site" id="site" style="width:100%" >

<?php 
while($Row=DB_fetch_array($site_sql)){?>
<option value="<?php echo $Row['loccode']?>"<?php echo($_SESSION['Site']==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
<?php  } ?>
</select></td>
<td class="tabledata3">Job Work No.</td>
<td id="jobid"><input name="jobPrefix" type="text" id="jobPrefix" value="Auto Generated" style="width:100%" readonly="true"/></td>
 <td class="tabledata3">Job Work Date </td>

    <td><input type="text" name="jobDate" id="jobDate" value="<?php if(isset($_SESSION['jobDate']))echo $_SESSION['jobDate']; else echo date('d/m/Y');?>" style="width:100%" class="datepicker" />    </td>
  </tr> 
  <tr>
    <td class="tabledata3">Vendor</td>
    <td><?php
     $venQry="Select id,vendor_name from suppliers where id='".$_REQUEST['SupplierId']."' AND CompanyId='".$_SESSION['ACGCompanyId']."'";
    ?>
    <select name="vendor" id="vendor" style="width:100%" onchange="vendorname(this.value)">        
    <?php 	$vend_sql=DB_query($venQry,$db);
	       while($vend_row=DB_fetch_array($vend_sql))
	{ ?>
        <option value="<?php echo $vend_row['id'];?>"><?php echo $vend_row['vendor_name'];?></option>

        <?php }	?>
    </select></td>
    <td class="tabledata3">Quotation No.</td>
	<td><input type="text" name="partyJWNo" id="partyJWNo" value="<?php echo $s->GetFieldValue('venderquotations'," id ='".$quotId."' " ,'party_Quo_no');?>" readonly class="cap" style="width:100%" /></td>
   <td class="tabledata3">Job Type <font style="color:red;">*</font></td>

   <td><select name="jobtype" id="jobtype" style="width:100%;">
     <option value='0'>Select</option>
     <option value='S'>Service</option>
     <option value='J'>Job Work Process</option>
    </select>   </td> 
  </tr>
  
  <tr>

       <td class="tabledata3">Quotation Date</td>

	<td><input type="text" readonly name="quotDate" id="quotDate" value="<?php echo ConvertSQLDate($s->GetFieldValue('venderquotations'," id ='".$quotId."' " ,'party_Quo_date'));?>" class="cap" style="width:100%;" /></td>
         <td colspan="4">    </td>
    </tr>
</table>



<div style="overflow:auto; width:100%;"> 
  
    
    <?php //echo $vendorType;
if(($vendorType=='Domestic'))
{ ?>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style=" border:1px solid #333333;">
        <tr class="row1">
	<td colspan="10" style="text-align:left">
	<h3><strong>Item Details</strong></h3>
	</td>
        </tr>
	<tr bgcolor="#d4d4d4">
	<td class="tabledata">Sr No.</td>
	<td class="tabledata">Item Name</td>
	<td class="tabledata">UOM</td>
	<td class="tabledata">Qty.</td>
	<td class="tabledata">Quoted Rate </td>
	<td class="tabledata">Total Price</td>
	<td class="tabledata" colspan="2" width="15%">Discount</td>  
	<td class="tabledata">Basic Amount</td>
	<td class="tabledata">Currency</td>
	</tr>
        <?php
        $i=0;
$itemDetails="select * from vendorquotationdetails where parant_id='".$quotId."'  and status is null";
$itemDetailsExec = DB_query($itemDetails, $db);
while($detailsDta=DB_fetch_array($itemDetailsExec))
{
   $itemCode= $s->GetFieldValue('item_master',"id='".$detailsDta['mst_itemid']."'",'StockID');
   $itemName= $s->GetFieldValue('item_master',"id='".$detailsDta['mst_itemid']."'",'item_name');
   $unitId= $s->GetFieldValue('item_master',"id='".$detailsDta['mst_itemid']."'",'mst_unitid');
   $unitName= $s->GetFieldValue('unitsofmeasure',"unitid='".$unitId."'",'unitname');
   
   $check_last_mrn="Select Quantity from vendorquotationdetails where parant_id='".$quotId."' and mst_itemid='".$detailsDta['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
         $last_mrn_row['Quantity'];
        
        $check_last_mrn1="Select sum(quantity) from job_work_details inner join job_work on job_work.id=job_work_details.masterId where job_work.quotid='".$quotId."' and job_work_details.mst_itemId='".$detailsDta['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
        
         
        $last_mrn_row1=DB_fetch_array($last_mrn_res1);
	  $last_mrn_row1['sum(quantity)'];
	if($last_mrn_row['Quantity']>=$last_mrn_row1['sum(quantity)'])
	{
		$pending_qty=$last_mrn_row['Quantity']-($last_mrn_row1['sum(quantity)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['Quantity'];
	}
        
            ?>
       <tr bgcolor="#d4d4d4">
        <td ><?php echo ($i+1).'.'; ?></td>
        
        <td ><input type="hidden" name="itemID[]" id="itemID_<?php echo $i; ?>" value="<?php echo $detailsDta['mst_itemid']; ?>"/>
            <?php echo $itemName; ?></td>
        
        <td ><?php echo $unitName; ?></td>
        
        <td ><input readonly type='hidden' name='pending_qty[]' id='pending_qty_<?php echo $i; ?>' value='<?php echo $pending_qty;?>' /><input type="text" name="qty[]" id="qty_<?php echo $i; ?>" value="<?php echo $pending_qty; ?>" autocomplete="off" onkeyup="calcTotAmt(this.value,'<?php echo $i; ?>');"/></td>
        
        <td ><input type="text" autocomplete="off" name="rate[]" id="rate_<?php echo $i; ?>"  onkeyup="calcTotAmt(this.value,'<?php echo $i; ?>');" readonly value="<?php echo $detailsDta['Rate']; ?>"/></td>
        
        <td ><input type="text" readonly name="price[]" id="price_<?php echo $i; ?>" value="<?php echo $detailsDta['totalPrice']; ?>"/></td>
        
        <td ><input type="text" style="width:50px;" name="Discount[]" onkeyup="DiscountAmounts(this.value,this.id)" autocomplete="off" id="Discount_<?php echo $i; ?>" value="<?php echo $detailsDta['Discount']; ?>"/>
			</td>
                        
     <td><select style="width:50px;" name="DiscountType[]" id="PerAmo_<?php echo $i; ?>" onchange="DiscountAmounts(this.value,this.id)">
            <option value="Amount" <?php echo ($detailsDta['DiscountType']=='Amount')?'selected':''?>>Amt</option>
            <option value="PercentAmt"<?php echo ($detailsDta['DiscountType']=='PercentAmt')?'selected':''?>>%</option>
          </select></td>
          
          <td ><input type="text" style="width:100%;" id="basic_<?php echo $i; ?>" name="totalAmount[]" readonly value="<?php echo $detailsDta['basic_Amt']; ?>"/></td>
          
          <td><select style="width:100%;" name="currency[]" id="currency">
			<?php $curr_sql=DB_query("Select * from currency_master order by id DESC",$db);
			while($curr_row=DB_fetch_array($curr_sql))
			{  ?>
            <option value="<?php echo $curr_row['id']; ?>"<?php echo ($detailsDta['currency']==$curr_row['id'])?'selected':''?>><?php echo $curr_row['abbreviation']; ?></option>
			<?php } ?>
          </select></td>
          
       </tr>
   <?php $i++; } ?>
       <input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>"  />
       <tr class="row1">
    
	<td colspan="10">
        
		<table width="100%" cellspacing="0" cellpadding="3">
			<tr class="row1">
                            <td width="50%" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="12%"><strong>Remarks :</strong></td>
    <td><textarea name="remarks" id="remarks" style="width:70%; height:50px;" ></textarea></td>
  </tr>
</table>

							


                  </td>
				<td width="10%"></td>
                                
				<td width="50%">
				<table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr class="row1">
                    <?php

                  $servicenature=$s->GetFieldValue('venderquotations',"id='".$quotId."'",'service_nature');
                   $wctRate1=$s->GetFieldValue('venderquotations',"id='".$quotId."'",'wctRate');
                  $abutment=$s->GetFieldValue('servise_tax_ledger_map',"ledger_id='".$servicenature."'",'abt');
                  $service_id1=$s->GetFieldValue('servise_tax_ledger_map',"ledger_id='".$servicenature."'",'service_id');
                  $ecess_id1=$s->GetFieldValue('servise_tax_ledger_map',"ledger_id='".$servicenature."'",'ecess_id');
                  $she_id1=$s->GetFieldValue('servise_tax_ledger_map',"ledger_id='".$servicenature."'",'she_cess_id');

                  ?>
                  <td class="tabledata1"><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" readonly name="basic_amt" id="total_item_amount" style="width:150px;" onfocus="cal_totalamount()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'basic_amt'); ?>"/></td>
               </tr>
               <tr class="row1">
                  <td class="tabledata1"><strong>Nature Of Service</strong> </td>
                  <td > <select name="nature_service" id="nature_service" style="width:150px;" onchange="calcServtax_ledger(this.value)">
                      <option value="0">Select</option>
                      <?php             

                      $sel_ledg=DB_query("select * from accountledger where AccountsID='".$servicenature."'",$db); 
                      while($sel_ledgRow=DB_fetch_array($sel_ledg))
                      {

                      $p12='';
                      if($servicenature==$sel_ledgRow['AccountsID'])
                      $p12="selected";

                      ?>
                      <option value="<?php echo $sel_ledgRow['AccountsID']; ?>" <?php echo $p12; ?> ><?php echo $sel_ledgRow['AccountName']; ?></option>
                      <?php }?>
                     </select></td>
               </tr>
               <tr class="row1">
                  <td class="tabledata1"><strong>Abt. %</strong> </td>
                  
                  <td><input type="text" readonly name="abtmntRate" onfocus="calcAbtValue1()" id="abtmntRate" value="<?php echo $abutment; ?>" style="width:50px;"/>
                  <input type="text" readonly name="abtmntValue1" id="abtmntValue1" style="width:50px;" onfocus="calcShetax()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'abtmntValue1'); ?>"/>
                  <input type="text" readonly name="abtmntValue2" id="abtmntValue2" onfocus="calcAbtValue2()" style="width:50px;" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'abtmntValue2'); ?>"/>
                  </td>
               </tr>
               <tr class="row1">
                  <td class="tabledata1"><strong>Service Tax</strong> </td>
                  <?php
                 $serviceRate="select taxrate,tax_code from service_tax_master where id='".$service_id1."'";
                  $serviceExec = DB_query($serviceRate,$db);
                 
                  ?>
                  <td ><select name="serviceTaxRate" id="serviceTaxRate" style="width:50px;" onchange="calcServtax()">
                          <?php
                           while($serviceRow = DB_fetch_array($serviceExec))
                           {
                          ?>
                          <option value="<?php echo $serviceRow['taxrate']; ?>"><?php echo $serviceRow['tax_code']; ?></option>
                           <?php } ?>
                      </select>
                     
                  <input type="text" readonly name="serviceTaxValue" id="serviceTaxValue" style="width:100px;" onfocus="calcServtax()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'serviceTaxValue'); ?>"/>
                  </td>
               </tr>
               
               <tr class="row1">
                  <td class="tabledata1"><strong>E-cess</strong> </td>
                  <?php
                  $serviceRate2="select taxrate,id from service_tax_master where  id='".$ecess_id."'";
                  $serviceExec2 = DB_query($serviceRate2,$db);
                  $serviceRow2 = DB_fetch_array($serviceExec2);
                  $servRate2=$serviceRow2['taxrate'];
                  ?>
                   <td > <input type="hidden" readonly name="ecessid" id="ecessid" value="<?php echo  $serviceRow2['id']; ?>" style="width:50px;"/>
                  <input type="text" readonly name="ecessRate" id="ecessRate" value="<?php echo $servRate2; ?>" style="width:50px;"/>
                  <input type="text" readonly name="ecessValue" id="ecessValue" style="width:100px;" onfocus="calcEcesstax()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'ecessValue'); ?>"/>
                  </td>
               </tr>
               
               <tr class="row1">
                  <td class="tabledata1"><strong>SHE-cess</strong> </td>
                  <?php
                  $serviceRate3="select taxrate,id from service_tax_master where  id='".$s_ecess_id."'";
                  $serviceExec3 = DB_query($serviceRate3,$db);
                  $serviceRow3 = DB_fetch_array($serviceExec3);
                  $servRate3=$serviceRow3['taxrate'];
                  ?>
                  <td>
                  <input type="hidden" readonly name="sheid" id="sheid" value="<?php echo  $serviceRow3['id']; ?>" style="width:50px;"/>
                  <input type="text" readonly name="sheRate" id="sheRate" value="<?php echo $servRate3; ?>" style="width:50px;"/>
                  <input type="text" readonly name="sheValue" id="sheValue" style="width:100px;" onfocus="calcShetax()"value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'sheValue'); ?>"/>
                  </td>
               </tr>
               
                              
               <tr class="row1">
                  <td class="tabledata1"><strong>Taxable Amount</strong> </td>
                  <td><input type="text" readonly name="totalTax" id="totalTax" style="width:150px;" 
                  	value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'totalTax'); ?>"/>
                  </td>
               </tr>
              
		
               
               <tr class="row1">
                  <td class="tabledata1"><strong>WCT</strong> </td>
                  <?php
                  $wctRate="select taxrate,tax_code from sales_tax_master where tax_code='Wct'";
                  $wctRateExec = DB_query($wctRate,$db);
                  
                  ?>
                  <td>
                      <select name="wctRate" id="wctRate" style="width:50px;" onchange="calcWct()">
                      <option value="0">Select</option>
                          <?php
                           while($wctRow = DB_fetch_array($wctRateExec))
                           {

                           	$p2='';
                           	if($wctRate1==$wctRow['taxrate'])
                           		$p2="selected";
                          ?>
                          <option value="<?php echo $wctRow['taxrate']; ?>" <?php echo $p2; ?> ><?php echo $wctRow['tax_code']; ?></option>
                           <?php } ?>
                      </select>
                         <input type="text" readonly name="wctValue" id="wctValue" style="width:100px;" onfocus="calcWct()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'wctValue'); ?>"/>
                  </td>
               </tr>
               
               <tr class="row1">
                  <td class="tabledata1"><strong>TDS</strong> </td>
                  <?php
                  $tdsRate=$s->GetFieldValue('suppliers',"id='".$VendorId."'",'tds_rate');
                  ?>
                  <td>
           <input type="text" readonly name="tdsRate" id="tdsRate" value="<?php echo $tdsRate; ?>" style="width:50px;"/>
                  <input type="text" readonly name="tdsValue" id="tdsValue" style="width:100px;" onfocus="calcTds()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'tdsValue'); ?>"/>
                  <br/>
                  <?php
                  $tdsEcessRate=$s->GetFieldValue('suppliers',"id='".$VendorId."'",'tds_ECess_rate');
                  ?>
                  <input type="text" readonly name="tdsEcessRate" id="tdsEcessRate" value="<?php echo $tdsEcessRate; ?>" style="width:50px;"/>
                  <input type="text" readonly name="tdsEcessValue" id="tdsEcessValue" style="width:100px;" onfocus="calcTdsEcess()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'tdsEcessValue'); ?>"/>
                  <br/>
                  <?php
                  $tdssEcessRate=$s->GetFieldValue('suppliers',"id='".$VendorId."'",'tds_SHECess_rate');
                  ?>
                  <input type="text" readonly name="tdshEcessRate" id="tdshEcessRate" value="<?php echo $tdssEcessRate; ?>" style="width:50px;"/>
                  <input type="text" readonly name="tdshEcessValue" id="tdshEcessValue" style="width:100px;" onfocus="calcTdsSEcess()" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'tdshEcessValue'); ?>"/>
                  </td>
               </tr>
               
               <tr class="row1">
		<td class="tabledata1"><strong>Round Off</strong></td>
        <td><input type="text" name="pluMin" readonly id="pluMin" style="width:50px;" 
        	value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'pluMin'); ?>"/>
		<input type="text" name="roundVal" readonly  id="roundVal" style="width:100px;"
		value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'roundOff'); ?>"/>
		</td>
    		</tr>
               
     <tr class="row1">
		<td class="tabledata1"><strong>Grand Total</strong></td>
        <td><input type="text" name="GrandTotal" readonly id="GrandTotal" onfocus="cal_grandamount()" style="width:150px;" value="<?php echo $s->GetFieldValue('venderquotations',"id='".$quotId."'",'grand_total'); ?>"/>
		<input type="hidden"  id="orig_grand_tot" />
		</td>
    		</tr>
   </table>
				</td>
			</tr>
                        
		</table>
	</td>
</tr>
    </table>
<?php } ?>
    
</div>







<p align="center"><input type="submit" name="Save" value="Save" class='search' /><input type="submit" name="Cancel" value="Cancel" class='search' /></p>

</form>





</div></div>





<?php 

//include('includes/footer.inc');

?>