<?php 
$title = _('Purchase Order');
if($_REQUEST['save'])
{



	$prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$_REQUEST['frmid']."' and module_id='".$_REQUEST['modid']."' ",$db);
	
	$prefix_row=DB_fetch_array($prefix_sql);
	$prefix1=$prefix_row['prefix_code'];
	$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
	   	$sql="Select purchase_ordNo from purchorders where site='".$_REQUEST['site']."' and INSTR(`purchase_ordNo`, '$financial') > 0 order by id 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)
	{
	//$Reqno=$myrow['Reqno'];
	//$req_part1=substr($Reqno,-4);
	$ExplBill=explode("/",$myrow['purchase_ordNo']);
	$maxval = $ExplBill[3];
	//echo $req_part1;
	$req_final=$maxval+1;
	//echo "<br>".$req_final;
	}
	else
	{
	$req_final="1";
	}
	
	$string=$_REQUEST['site']."/".$prefix1."/".$financial."/";
	
	//$string=$_REQUEST['site']."/".$financial."/".$_REQUEST['purch_ord_type']."/".$_REQUEST['purch_ord_category']."/".$prefix."/";
	     $final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
	//echo '<pre>';
	//print_r($_REQUEST);
	//exit;
	

    //***************************  Document Uploading ************************//

	   $FinempCode1=rand(0,9999);
	    if($_FILES['file_attach']['name']!='')
	    {
        $name=$_FILES['file_attach']['name'];
		$tmp_name=$_FILES['file_attach']['tmp_name'];
		$name_brk=explode('.',$name);
		$type=$name_brk[1];
		$new_name=$FinempCode1.'.'.$type;
		$path="uploaded_docs/".$new_name;
		$file_copy=copy($tmp_name,$path);		
		}

		

	//************************************************************************//

	$data['purchase_ordNo']=$final_string;
	$data['po_date']=FormatDateForSQL($_REQUEST['po_date']);
	$data['vendorId']=$_REQUEST['vendor_id'];
	$data['contact_person']=$_REQUEST['contact_person'];
	$data['indentPRno']=$_REQUEST['indentno'];
	$data['quotationId']=$_REQUEST['quote_No'];
	$data['qutation_date']=FormatDateForSQL($_REQUEST['quote_date']);
	$data['mobileNo']=$_REQUEST['mobile_no'];
	$data['purchase_ord_Type']=$_REQUEST['purch_ord_type'];
	$data['po_category']=$_REQUEST['purch_ord_category'];
	$data['site']=$_REQUEST['site'];
	$data['biiling_Address']=$_REQUEST['billing_Address'];
	$data['biiling_Address1']=$_REQUEST['billing_Address1'];
	$data['biiling_Address2']=$_REQUEST['billing_Address2'];
	$data['biiling_Country']=$_REQUEST['billing_country'];
	$data['biiling_State']=$_REQUEST['billing_state'];
	$data['biiling_City']=$_REQUEST['billing_city'];
	$data['biiling_PostalCode']=$_REQUEST['biiling_PostalCode'];
	$data['sippiling_Address']=$_REQUEST['sippiling_Address'];
	$data['sippiling_Address1']=$_REQUEST['sippiling_Address1'];
	$data['sippiling_Address2']=$_REQUEST['sippiling_Address2'];
	$data['sippiling_Country']=$_REQUEST['shipping_country'];
	$data['sippiling_State']=$_REQUEST['shipping_state'];
	$data['sippiling_City']=$_REQUEST['shipping_city'];
	$data['sippiling_PostalCode']=$_REQUEST['sippiling_PostalCode'];
	$data['delivery_place']=$_REQUEST['delivery_place'];
	$data['mod_of_transport']=$_REQUEST['mod_of_transport'];
	$data['delivery_date']=FormatDateForSQL($_REQUEST['delivery_date']);
	$data['valid_till']=FormatDateForSQL($_REQUEST['valid_till']);
	$data['delivery_time']=$_REQUEST['delivery_time'];
	$data['payment_terms']=$_REQUEST['PaymentTerm'];
	$data['payment_mod']=$_REQUEST['payment_mod'];
	$data['remarks']=$_REQUEST['remarks'];
/* Purchase  order Rate details */

	$data['total_amount']=$_REQUEST['basic_amt'];
	$data['discount_amt']=$_REQUEST['discount_amt'];
	$data['discounted_amt']=$_REQUEST['discounted_amt'];
	$data['pkg_per']=$_REQUEST['pkg_per'];
	$data['pkg_charges']=$_REQUEST['pkg_charges'];  
	$data['non_tax_insurance']=$_REQUEST['insurance_non_taxable'];  
	$data['total_amt']=$_REQUEST['total_amt'];
	$excise_id=explode('**',$_REQUEST['excise']);
	$data['excise']=$excise_id[0];
	$data['excise_amt']=$_REQUEST['excise_amt'];
	$ecess=explode('**',$_REQUEST['ecess']);
	$data['ecess']=$ecess[0];
	$data['ecess_amt']=$_REQUEST['ecess_amt'];
	$secess=explode('**',$_REQUEST['shecess']);
	$data['shecess']=$secess[0];
	$data['shecess_amt']=$_REQUEST['shecess_amt'];
	$data['tot_tax_amt']=$_REQUEST['tot_tax_amt'];
	$vat_cst=explode('**',$_REQUEST['vat_cst']);
	$data['vatcst']=$vat_cst[0];
	$data['vat_amt']=$_REQUEST['vat_amt'];
	$data['surcharge_per']=$vat_cst[2];
	$data['surcharge_amt']=$_REQUEST['sur_amt'];
	$data['entry_tax_amt']=$_REQUEST['entry_tax_amt'];
	$data['insurancecharges_amt']=$_REQUEST['insr_amt'];
	
	$data['Freight']=$_REQUEST['Freight'];
	$data['other_amt']=$_REQUEST['other_amt'];
	$data['total_po_amt']=$_REQUEST['total_po_amt'];
	$data['roundVal']=$_REQUEST['roundVal'];
    $data['pluMin']=$_REQUEST['pluMin'];
	$data['GrandTotal']=$_REQUEST['GrandTotal'];
	$data['ordertype']='I';
	$data['uploaded_file']        =$new_name;
	$data['doc_name']             =$_REQUEST['docname'];
	
	//echo "<pre>";
	//print_r($data);
	
	$s->RecordInsert('purchorders',$data);		
	//INSERT INTO PARANT TABLE
	$last_id=DB_Last_Insert_ID($db,'purchorders','id');// GET LAST INSERT ID
	
	//print_r($_REQUEST['mst_itemid']);
	
	foreach($_REQUEST['mst_itemid'] as $key=>$val)
	{
		
			$dataArr['parantId']=$last_id;
			$dataArr['mst_itemid']=$val;
			$dataArr['itemgrade']=$_REQUEST['itemgrade'][$key];
			$dataArr['itemsize']=$_REQUEST['itemsize'][$key];
			$dataArr['Quantity']=$_REQUEST['Quantity'][$key];
			$dataArr['Rate']=$_REQUEST['Rate'][$key];
			$dataArr['currnecy']=$_REQUEST['currency'][$key];
			$dataArr['totalPrice']=$_REQUEST['totalPrice'][$key];
			$dataArr['DiscountType']=$_REQUEST['DiscountType'][$key];
			//$dataArr['unitwisedis']=$_REQUEST['unitdiscount'][$i];
			$dataArr['Discount']=$_REQUEST['Discount'][$key];
			$dataArr['discounted_amount']=$_REQUEST['discounted_amount'][$key];
			//$dataArr['NetRate']=$_REQUEST['NetRate'][$i];
			$dataArr['mst_unitid']=$_REQUEST['mstunitid'][$key];
			$dataArr['basic_Amt']=$_REQUEST['TotalAmount'][$key];
			//$dataArr['Excise_type']=$_REQUEST['Excise_type'][$i];
			//$dataArr['Excise_Duty']=$_REQUEST['Excise_Duty'][$i];
			//$dataArr['exciseValue']=$_REQUEST['exciseValue'][$i]; 
			//$dataArr['Cess_ID']=$_REQUEST['Cess_ID'][$i]; 
			//$dataArr['ECessValue']=$_REQUEST['ECessValue'][$i]; 
			//$dataArr['SHECess_ID']=$_REQUEST['SHECess_ID'][$i]; 
			//$dataArr['SAHCessValue']=$_REQUEST['SAHCessValue'][$i];
			//$dataArr['taxable_amt']=$_REQUEST['taxable_amt'][$i];
			//$dataArr['cuntomDuty_Flag']=$_REQUEST['cuntomDuty_Flag'][$i];
			//$dataArr['Custon_Duty']=$_REQUEST['Custon_Duty'][$i];
			//$dataArr['CustomDutyAmt']=$_REQUEST['CustomDutyAmt'][$i];
			//$dataArr['TotalAmount']=$_REQUEST['basic_Amt'][$key];
			//echo "<pre>";
			//print_r($dataArr);
			
			$s->RecordInsert('purchorderdetails',$dataArr);//INSERT INTO CHIELD TABLE
		
	}
        for($k=0;$k<count($_REQUEST['Terms_Condition']);$k++)
						{
							if($_REQUEST['Terms_Condition'][$k]!='')
							{
								
							$dataterm['parant_id']    =$last_id;
							$dataterm['termsid']      =$_REQUEST['terms'][$k];
							$dataterm['condid']       =$_REQUEST['Terms_Condition'][$k];
							$dataterm['frm_id']       =$_REQUEST['frmid'];
							$dataterm['company_id']   =$_SESSION['ACGCompanyId'];
							//$dataterm['type']         ="quotation";
							$s->RecordInsert('po_terms_cond',$dataterm);
							}
						}

				
						$p=0;
					foreach($_SESSION['data'] as $key=>$value)	
                     {
                     $$reqid='';                   
                      foreach($value['reqid'] as $key1=>$val)
                      $reqid=$key1;
                      $flag=0;


                	// echo ($_SESSION['data'][$p]['reqid'][$key]);
       // echo "update requisitionorderdetails set po_status='1' where requsitionno='".$reqid."' and mst_itemid='".$_SESSION['data'][$p]['itemid']."'";
                   DB_query("update requisitionorderdetails set po_status='1' where requsitionno='".$reqid."'
                    and mst_itemid='".$_SESSION['data'][$p]['itemid']."'",$db);
                   $sqlDetails = DB_query("SELECT po_status FROM requisitionorderdetails WHERE requsitionno='".$reqid."'",$db);
                   $num=DB_num_rows($sqlDetails);
                 
                   while($rowDetails=DB_fetch_array($sqlDetails))
	                { 
		                   if($rowDetails['po_status']=='1')
		                   {
		                   $flag++;
		                   }
                    }
                  
                    if($num>0 && $num==$flag){
                  DB_query("update materialrequisitions set po_status='1' where requisitionno='".$reqid."'",$db);
              
                  }
              $p++;  }
         
             
//$update=DB_query("update materialrequisitions set po_status=1 where requisitionno='".$_REQUEST['indentno']."'",$db);
	//unset($_SESSION['data']);

	$s->pageLocation("index.php?route=POModule/view_purchase_order".$rurl);
        
}
?>
<script src="POModule/po_calculation.js" type="text/javascript" language="javascript"></script>
<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 claculateExcise(id,val)
//{
//	$("#div_id").dialog({
//	modal: true,
//	resizable: false,
//	width:300,
//	height:150,
//	closeText: 'fechar',
//	draggable: true,
//	show: 'fade',
//	hide: 'fade',
//	dialogClass: 'main-dialog-class',
//	buttons: {
//		//Save: function()
////		{
////		$("#myform").closest("form").submit();
////		},
//		//Exit: function()
////		{
////			$(this).dialog("close");
////		}
//	}
//	});
//	$(".ui-dialog-titlebar").hide();
//	calculateExcisejq(id,val)
//}







function closediolgebox(exval,id)
{
	if(id=='')
	{
		document.getElementById("exciseValue").value=exval;
	}
	else
	{
		document.getElementById("exciseValue_"+id).value=exval;
	}
	$('#div_id').dialog("close");
}


function calculateExcisejq(id,val)
{
	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("div_id").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","GetCalExcisejqe.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}



function calecessjq(id,val)
{
	$("#div_idEcess").dialog({
	modal: true,
	resizable: false,
	width:300,
	height:150,
	closeText: 'fechar',
	draggable: true,
	show: 'fade',
	hide: 'fade',
	dialogClass: 'main-dialog-class',
	buttons: {
		//Save: function()
//		{
//		$("#myform").closest("form").submit();
//		},
		//Exit: function()
//		{
//			$(this).dialog("close");
//		}
	}
	});
	$(".ui-dialog-titlebar").hide();
	calculateEcessjq(id,val)
}


function calculateEcessjq(id,val)
{
	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("div_idEcess").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","GetCalEcessjqe.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function closediolgeboxEcess(exval,id)
{
	if(id=='')
	{
		document.getElementById("ECessValue").value=exval;
	}
	else
	{
		document.getElementById("ECessValue_"+id).value=exval;
	}
	$('#div_idEcess').dialog("close");
}










function calSheecessjq(id,val)
{
	$("#div_idEcess").dialog({
	modal: true,
	resizable: false,
	width:300,
	height:150,
	closeText: 'fechar',
	draggable: true,
	show: 'fade',
	hide: 'fade',
	dialogClass: 'main-dialog-class',
	buttons: {
		//Save: function()
//		{
//		$("#myform").closest("form").submit();
//		},
		//Exit: function()
//		{
//			$(this).dialog("close");
//		}
	}
	});
	$(".ui-dialog-titlebar").hide();
	calculateSHEcessjq(id,val)
}


function calculateSHEcessjq(id,val)
{
	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("div_idEcess").innerHTML=xmlhttp.responseText;
	}
	}
	var id1=id.split("_");
	var i=id1[2];
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","GetCalSHEcessjqe.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}


function closediolgeboxSHEcess(exval,id)
{
	if(id=='')
	{
		document.getElementById("SAHCessValue").value=exval;
	}
	else
	{
		document.getElementById("SAHCessValue_"+id).value=exval;
	}
	$('#div_idEcess').dialog("close");
}













 

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","direct_po_items.php?site="+str,true);
	xmlhttp.send();
}


function VendorAddressContactpeson(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)
	{       // alert(xmlhttp.responseText);
		var data=xmlhttp.responseText.split("__");
		document.getElementById("ordType").innerHTML=data[0];
                document.getElementById("CPerson").innerHTML=data[4];
                document.getElementById("mobile_no").value=data[5];
		document.getElementById("divordertype").innerHTML=data[1];
		document.getElementById("basicamtdetails").innerHTML=data[2];
		document.getElementById("term_condition").innerHTML=data[6];
		//document.getElementById("billing_state").value=data[3];
		//document.getElementById("billing_state1").value=data[4];
		//document.getElementById("billing_country").value=data[5];
		//document.getElementById("billing_country1").value=data[6];
	}
	}
	xmlhttp.open("GET","GetVenAddressContactPoIndent.php?VID="+str+"&frmid="+<?php echo $_REQUEST['frmid'] ?>,true);
	xmlhttp.send();
}

function VendorAddressContactpeson1(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)
	{
		var data=xmlhttp.responseText.split("__");
		//document.getElementById("CPerson").innerHTML=data[0];
		document.getElementById("billing_Address").value=data[1];
		document.getElementById("billing_Address1").value=data[7];
		document.getElementById("billing_Address2").value=data[8];
		document.getElementById("billing_city").value=data[2];
		document.getElementById("billing_state").value=data[3];
		document.getElementById("billing_state1").value=data[4];
		document.getElementById("billing_country").value=data[5];
		document.getElementById("billing_country1").value=data[6];
		document.getElementById("zipcode").value=data[9];
	}
	}
	xmlhttp.open("GET","GetVenAddressContact1.php?VID="+str,true);
	xmlhttp.send();
}


function GetMobileNo(id)
{
	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("mobile_no").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","GetContactNo.php?contactId="+id,true);
	xmlhttp.send();
}


function claculateExcise(id,val)
{
	
	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("__");
		var k=data[0];
		if(data[0]=='')
		{
			document.getElementById("exciseValue").value=data[1];
		}
		else
		{
			document.getElementById("exciseValue_"+k).value=data[1];
		}
	}
	}
	var id1=id.split("_");
	var i=id1[1];
	if(i==undefined)
	{
		var basicamt=document.getElementById("basic").value;
	}
	else
	{
		var basicamt=document.getElementById("basic_"+i).value;
	}
	xmlhttp.open("GET","ajax_getexcisevalue.php?ids="+id+"&vls="+val+"&bamt="+basicamt,true);
	xmlhttp.send();
}



function calEcessonchange(id,val)
{
	var id1=id.split("_");
	var i=id1[2];
	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("__");
      //alert(data);
		var k=data[0];
		if(i==undefined)
		{
			document.getElementById("ECessValue").value=data[1];
		}
		else
		{
			document.getElementById("ECessValue_"+i).value=data[1];
		}
	}
	}
	
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
        
	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}



function calSHEcessonchange(id,val)
{
	var id1=id.split("_");
	var i=id1[2];
	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("__");
		var k=data[0];
		if(i==undefined)
		{
			document.getElementById("SAHCessValue").value=data[1];
		}
		else
		{
			document.getElementById("SAHCessValue_"+i).value=data[1];
		}
	}
	}
	
	if(i==undefined)
	{
		var ecessval=document.getElementById("exciseValue").value;
	}
	else
	{
		var ecessval=document.getElementById("exciseValue_"+i).value;
	}
	xmlhttp.open("GET","ajax_ecesscalculation1.php?ids="+id+"&vls="+val+"&Ecessval="+ecessval,true);
	xmlhttp.send();
}
     
</script>
<?php 

$sql=DB_query("select sitecode from materialrequisitions where requisitionno ='".$_SESSION['data'][0]['reqid']."'",$db);
$row=DB_fetch_array($sql);
//echo "Select deladd1,deladd2,deladd3,city,state,country,pincode from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') and loccode ='".$row['sitecode']."'";
$address=DB_query("Select deladd1,deladd2,deladd3,city,state,country,pincode from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') and loccode ='".$_SESSION['indentsite']."'",$db);
$address_row=DB_fetch_array($address);
//extract($row);
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Indent Purchase Order Approval</h1>	
<form action="" method="post" enctype="multipart/form-data">

<!-----------------GENERAL DETAILS------------------------------------------------------------------------------------>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td colspan="6"><h3 style="border-bottom:none;"><strong>General Details</strong></h3></td>
    </tr>
  <tr class="row1">
    <td width="13%" align="left"><strong>Branch</strong></td>
    <td width="20%" align="left"><?php 
	  $ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'
	 and loccode in ('".$_SESSION['AssignedBranch']."') and loccode ='".$_SESSION['indentsite']."'";
	$site_sql=DB_query($ss1,$db);?>
	<select name="site" id="site" style="width:100%;" onchange="VendorAddressContactpeson1(this.value)"><!-- onchange="generate_reqno(this.value)"-->
<!--<option value="0">Select</option>-->
	<?php while($site_row=DB_fetch_array($site_sql)){?>
	<option value="<?php echo $site_row['loccode'];?>"><?php echo $site_row['locationname'];?></option>
	<?php } ?>
	</select></td>
    <td width="13%" align="left"><strong>PO No.</strong></td>
    <td width="20%" align="left"><input type="text" style="width:100%;" value="Auto Generated" disabled="disabled"/></td>
    <td width="13%" align="left"><strong> Date</strong></td>
    <td align="left"><input type="text" name="po_date" id="po_date" value="<?php  echo date('d/m/Y');?>" style="width:100%;" class="datepicker" /></td>
  </tr>
  <tr class="row1">
    <td align="left"><strong>Vendor </strong></td>
    <td align="left"><?php
	$str1=''; 
	 foreach($_SESSION['data'] as $key=> $val){
	 	$str1[]=$val['itemid'];
	 }
	// print_r($str1);
	// echo count($str1);
	 $str1=array_unique($str1);
	  $SQLV="Select id,vendor_name,assigned_items from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."' and site='".$_SESSION['indentsite']."' ";

	$VDetails1=DB_query($SQLV,$db);?>
	<select name="vendor_id" id="vendor_id" style="width:100%;" onchange="VendorAddressContactpeson(this.value)" >
	<option value="000">---Select---</option>
	<?php while($VDetails=DB_fetch_array($VDetails1)){ 
		$i=0;
		$ven_item=explode(',',$VDetails['assigned_items']);
		foreach($ven_item as $k=>$val1)
		{
			if(in_array($val1,$str1))
			{	
				$i++;		
			 }
		}
		if($i==count($str1)){ 
		?>

	<option value="<?php echo $VDetails['id'];?>"><?php echo $VDetails['vendor_name'];?></option>
	<?php }  } ?>
	</select></td>
    <td align="left"><strong>Quote No.</strong></td>
    <td align="left"><input type="text" name="quote_No" id="quote_No" style="width:100%;" /></td>
    <td align="left"><strong>Quote Date</strong></td>
    <td align="left"><input type="text" name="quote_date" id="quote_date" class="datepicker" style="width:100%;" /></td>
  </tr>
  <tr class="row1">
    <td align="left"><strong>P O Type<font style="color:red;">*</font></strong></td>
    <td align="left" id="ordType"><select name="purch_ord_type" id="purch_ord_type" style="width:100%" onChange="GetOrderType(this.value)">
		<option value="0">Select</option>
	        <option value='IO'>Import Order</option>
		<option value='DO'>Domestic Order</option>
		
	</select></td>
    <td align="left"><strong> Category <font style="color:red;">*</font></strong></td>
    <td align="left"><select name="purch_ord_category" id="purch_ord_category" style="width:100%">
      <option value="0">Select</option>
      <option value='AT'>Asset</option>
      <option value='MT'>Material</option>
      <option value='SV'>Service</option>
    </select></td>
    <td align="left"><strong>Delivery Date</strong></td>
    <td align="left"><input type="text" name="delivery_date" id="delivery_date" value="" style="width:100%;" class="datepicker"  onchange="checkvalidate()"   /></td>
  </tr>
  <tr class="row1">
    <td align="left"><strong>Payment Terms</strong></td>
    <td align="left"><select name="PaymentTerm" id="PaymentTerm" style="width:100%;">
		<option value="000">---Select Payment Terms---</option>
		<?php 
		$sql="select * from paymentterms";
		$result=DB_query($sql, $db);
		while($myrow = DB_fetch_array($result))
		{ 
		$p='';
		if($_POST['PaymentTerm']==$myrow['termsindicator'])
		$p="selected";
		?>
		<option value="<?php echo $myrow['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow['terms'];?></option>
		<?php } ?>
			      </select></td>
    <td align="left"><strong>Payment Mode</strong></td>
    <td align="left"><select name="payment_mod" id="payment_mod" style="width:100%;">
			      <option value="000">---Select Payment Mode---</option>
			      <?php 
					$sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($_POST['PayMode'] == $myrow['paymentid'])
							$p="selected";
						?>
			      <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
			      <?php 	} ?>
			      </select></td>
    <td align="left"><strong>Valid Upto</strong></td>
    <td align="left"><input type="text"  class="datepicker" name="valid_till" id="valid_till" value="" style="width:100%;"  onchange="checktilldate()"   /></td>
  </tr>

  <tr class="row1">
    <td align="left"><strong>Contact Person</strong></td>
    <td align="left" id="CPerson"><select name="contact_person" id="contact_person" style="width:100%">
	<option value="">Select</option>
	</select></td>
    <td align="left"><strong>Mobile No</strong></td>
    <td align="left"><input type="text" name="mobile_no" id="mobile_no" style="width:100%"></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
  </tr>
  <tr class="row1">
    <td align="left"><h3 style="border-bottom:none;"><strong>Address Details</strong></h3></td>
    <td colspan="5" align="left"><strong>Check If both Address are Same</strong> <input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()"></td>
    </tr>
  <tr class="row1">
    <td colspan="6" align="left">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="row1">
    <td colspan="3" style="text-align:center;"><strong>Billing Address</strong></td>
    <td style="text-align:center;"><strong>City</strong></td>
    <td style="text-align:center;"><strong>State</strong></td>
    <td style="text-align:center;"><strong>Country</strong></td>
    <td style="text-align:center;"><strong>Postal Code</strong></td>
  </tr>
  <tr class="row1">
    <td><input type="text" name="billing_Address" style="width:100%;" id="billing_Address" value="<?php echo $address_row['deladd1']?>"/></td>
    <td><input type="text" name="billing_Address1" style="width:100%;" id="billing_Address1" value="<?php echo $address_row['deladd2']?>"/></td>
    <td><input type="text" name="billing_Address2" style="width:100%;" id="billing_Address2" value="<?php echo $address_row['deladd3']?>"/></td>
    <td><select name="billing_city" id="billing_city" style="width:100%;" onchange="GetSatateCountry(this.value)">
			<option value="">Select</option>
			  <?php 
			  $city_sql=DB_query("select * from city_master",$db);
			  while($city_row=DB_fetch_array($city_sql)) { ?>
			  <option value="<?php echo $city_row['id'];?>"<?php echo($address_row['city']==$city_row['id']?'selected':''); ?>><?php echo $city_row['city'];?></option>
			  <?php } ?>
	</select></td>
    <td><input type="hidden" name="billing_state" id="billing_state" value="<?php echo $address_row['state']; ?>" style="width:100%;" />
					<?php $STname=$s->GetFieldValue('state_master',"id='".$address_row['state']."'",'state'); ?>
					<input type="text" name="billing_state1" id="billing_state1" value="<?php echo $STname; ?>" style="width:100%;" /></td>
    <td><input type="hidden" name="billing_country" id="billing_country" value="<?php echo $address_row['country']; ?>" style="width:100%;" />
					 <?php $Conname=$s->GetFieldValue('country_master',"id='".$address_row['country']."'",'country'); ?>
					 <input type="text" name="billing_country1" id="billing_country1" value="<?php echo $Conname; ?>" style="width:100%;" /></td>
    <td><input type="text" name="biiling_PostalCode" id="zipcode" style="width:100%;" value="<?php echo $address_row['pincode']?>"/></td>
  </tr>
  <tr class="row1">
    <td colspan="3" style="text-align:center;"><strong>Delivery Address </strong></td>
    <td style="text-align:center;"><strong>City</strong></td>
    <td style="text-align:center;"><strong>State</strong></td>
    <td style="text-align:center;"><strong>Country</strong></td>
    <td style="text-align:center;"><strong>Postal Code</strong></td>
  </tr>
  <tr class="row1">
    <td id="CODE"><input type="text" id="Shipping_address" name="sippiling_Address" style="width:100%;" /></td>
    <td id="CODE"><input type="text" id="Shipping_address1" name="sippiling_Address1" style="width:100%;" /></td>
    <td id="CODE"><input type="text" id="Shipping_address2" name="sippiling_Address2" style="width:100%;" /></td>
    <td><select name="shipping_city" id="shipping_city" style="width:100%;" onchange="GetSatateCountry1(this.value)">
			<option value="">Select</option>
			  <?php 
			  $city_sql=DB_query("select * from city_master",$db);
			  while($city_row=DB_fetch_array($city_sql))
			  { 
			  	$p = "";
				if($query_edit_result['sippiling_City'] == $city_row['id'])
					$p = "selected";	
			  ?>
			  <option value="<?php echo $city_row['id'];?>" <?php echo $p; ?>><?php echo $city_row['city'];?></option>
			  <?php 
			  } 
			  ?>
	</select></td>
    <td><input type="hidden" name="shipping_state" id="shipping_state" value="<?php echo $state; ?>" style="width:100%;" />
					<?php $STname=$s->GetFieldValue('state_master',"id='".$state."'",'state'); ?>
					<input type="text" name="shipping_state1" id="shipping_state1" value="<?php echo $STname; ?>" style="width:100%;" />	</td>
    <td><input type="hidden" name="shipping_country" id="shipping_country" value="<?php echo $country; ?>" style="width:100%;" />
					 <?php $Conname=$s->GetFieldValue('country_master',"id='".$country."'",'country'); ?>
					 <input type="text" name="shipping_country1" id="shipping_country1" value="<?php echo $Conname; ?>" style="width:100%;" /></td>
    <td><input type="text" name="sippiling_PostalCode" id="Shipping_zipcode" style="width:100%;" /></td>
  </tr>
</table>

    </td>
    </tr>

</table>


<!-----------------OTHER DETAILS------------------------------------------------------------------------------------>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1" colspan="6" style="font-size:12px; font-weight:bold;">Items Details:</td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="6">
	<!--<input type="button" onClick="addRow('dataTable')" value="Add More" class="search" />-->&nbsp;
	
	
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="6" style="padding:0px;">
		<div id="divordertype" style="width:100%; overflow:auto;">
			
		</div>
	</td>
</tr>				<input type="hidden" name="" id="hiditemcount" value="<?php echo count($_SESSION['data']); ?>" />
				<input type="hidden" name="" id="count1"  />
<tr class="row1">
<td class="tabledata1" colspan="6">
	<table border="0" width="100%" cellpadding="3" cellspacing="0">
	<tr class="row1">
		<td width="50%"><div id="term_condition"></div></td>
		<td width="50%">
		<div id="basicamtdetails">
			<!--<table width="100%" border="0" cellspacing="0" cellpadding="3">
            <tr class="row1">
            	<td class="tabledata1"><strong>Basic Amount </strong> </td>
                <td><input name='basic_amt' id='total_item_amount' style='width:100%;' readonly ></td>
               </tr>
               <tr class='row1'><td class='tabledata1'><strong>Discount</strong></td><td><select name='' id='disc_type' style='width:100%;' onchange='javascript:cal_global_discount(this,type)' ><option value='amt'>Amt</option><option value='prcnt'>%</option></select> <input name='' onkeyup='javascript:cal_global_discount(this,type)' value='0' id='discount_value' style='width:100%;' ></td></tr>
               <tr class='row1'>
	<td class='tabledata1'><strong>Discounted Amount</strong></td>
	<td><input name='' id='discnted_amt' style='width:100%;' ></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;" /><input type="text" name="roundVal" readonly  id="roundVal" style="width:100px;" readonly/></td>
            </tr>		
            <tr class="row1">
	    <td class="tabledata1"><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal"  style="width:100%;" readonly/></td>
                </tr>
              </table>-->
		</div>
		</td>
	</tr>
	<tr class="row1">
	<td class="tabledata1"><strong>Doc Name:</strong> <input type="text" name="docname"><input type="file" name="file_attach" value="Attach File"  id="filename" onchange="Checkfiles()" /></td>

</tr>
	</table>
</td>
</tr>
<tr class="row1">
<td height="63" colspan="6" class="tabledata1"  style="text-align:center;"><input name="save" type="submit" value="Generate Direct Order" class="search"  onclick="return validate();"/></td>
</tr>
</table>
<?php //echo '<pre>'; print_r( $_SESSION['data']);
foreach ($_SESSION['data'] as $key => $value) {
	foreach($value['reqid'] as $k=>$v)
	{
	$req_no[]=$k;
	}
}
$req_no = array_unique($req_no, SORT_REGULAR);
$req=implode(',',$req_no);

 ?>
<input type="hidden" name="indentno" value="<?php echo $req; ?>">
 </form>
 </div>
 </div>
 
<script language="JavaScript">

function calcTotAmt1(str,id)
{ 
     id1=id.split("_");
	i=id1[1];
        var totalamt=0;

            var quantity=document.getElementById("Quantity_"+i).value;
            var rate=document.getElementById("Rate_"+i).value;
            if(quantity==''){quantity=0;}
             if(rate==''){rate=0;}
            //alert(quantity);
            var finalAmt=parseFloat(rate)*parseFloat(quantity);
            //alert(finalAmt);
            document.getElementById("totalValue_"+i).value=finalAmt.toFixed(2);
            document.getElementById("basic_"+i).value=finalAmt.toFixed(2);
            
            var countcharges = document.getElementById("hiditemcount").value;
       // var FirstRow=document.getElementById("basic").value;
        //if(FirstRow==''){ FirstRow=0;}
        
        for(var l=1;l<=countcharges;l++)
        {

        if(document.getElementById("basic_"+l).value!='')
        var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("basic_"+l).value);
        }
        //alert(totalamt);
        var totalamt=parseFloat(totalamt);
        document.getElementById("total_item_amount").value=totalamt.toFixed(2);	
        document.getElementById("discnted_amt").value=totalamt.toFixed(2);
		document.getElementById("total_po_amt").value=totalamt.toFixed(2);
     
        
         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 DiscountAmounts1(DA,id)
{
    
	var totalamt=0;
        id1=id.split("_");
	i=id1[1];
        
       //alert(i)
                var totValue = document.getElementById("totalValue_"+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;}
                    
                    if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                        document.getElementById("discounted_amount_"+i).value=parseFloat(disct).toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;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);
			}}
                    
                       // var FirstRow=document.getElementById("basic").value;
                       // if(FirstRow==''){ FirstRow=0;}
                        
			var totalamt=parseFloat(totalamt);
			document.getElementById("total_item_amount").value=totalamt.toFixed(2);
             document.getElementById("discnted_amt").value=totalamt.toFixed(2); 
			 document.getElementById("total_po_amt").value=totalamt.toFixed(2); 
                        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';
                            }
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("basic_"+i).value=subTotal.toFixed(2);
                         document.getElementById("discounted_amount_"+i).value=parseFloat(parseFloat(disct*totValue)/100).toFixed(2);
                        //document.getElementById("TotalSpecial_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;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);
			}}
			
                        //var FirstRow=document.getElementById("basic").value;
                        //if(FirstRow==''){ FirstRow=0;}
                        
			var totalamt=parseFloat(totalamt);
                        document.getElementById("total_item_amount").value=totalamt.toFixed(2);	
                        document.getElementById("discnted_amt").value=totalamt.toFixed(2);
						 document.getElementById("total_po_amt").value=totalamt.toFixed(2);
                        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';
                                    }
		}
                
            
        
		
       
    //alert(totalamt);
   

                  
         
}

function checkvalidate()
{
	
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del=document.getElementById("delivery_date").value;	
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
//document.getElementById("delivery_date").value='';
document.getElementById("delivery_date").focus;	
return false;	
}


}
function checktilldate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}	
var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
	
	
}	
	
	
	
	
function validate()
{
if(document.getElementById("purch_ord_type").value=='0')
{
alert("Plz Select Purchase Order Type");
document.getElementById("purch_ord_type").focus();
return false;
}
if(document.getElementById("purch_ord_category").value=='0')
{
alert("Plz Select Purchase Order Category");
document.getElementById("purch_ord_category").focus();

return false;
}

if(document.getElementById("total_item_amount").value=='')
{
alert("Plz enter Total Item Amount First");
document.getElementById("total_item_amount").focus();
return false;
}
if(document.getElementById("VatcstVal").value=='')
{
alert("Plz enter Vat Cst Amount First");
document.getElementById("VatcstVal").focus();
return false;
}


if(document.getElementById("GrandTotal").value=='')
{
alert("Plz enter Grand Total Amount First");
document.getElementById("GrandTotal").focus();
return false;
}


return true;

}	
	
function showdata(str)
{
if (str=='')
  {
  document.getElementById("divdata").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)
    {
    	document.getElementById("divdata").style.display='block';
    document.getElementById("divdata").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","geteditdatapo.php?site="+str,true);
xmlhttp.send();
}	








function ship_data()
{

	if(document.getElementById("shipping_data").checked==true)
	{
		document.getElementById('Shipping_address').value = document.getElementById('billing_Address').value;
		document.getElementById('Shipping_address1').value = document.getElementById('billing_Address1').value;
		document.getElementById('Shipping_address2').value = document.getElementById('billing_Address2').value;
		document.getElementById('shipping_city').value = document.getElementById('billing_city').value;
		document.getElementById('shipping_state').value = document.getElementById('billing_state').value;
		document.getElementById('shipping_country').value = document.getElementById('billing_country').value;
		document.getElementById('shipping_state1').value = document.getElementById('billing_state1').value;
		document.getElementById('shipping_country1').value = document.getElementById('billing_country1').value;
		document.getElementById('Shipping_zipcode').value = document.getElementById('zipcode').value;
		
	}else{
		document.getElementById('Shipping_address').value = '';
		document.getElementById('Shipping_address1').value = '';
		document.getElementById('Shipping_address2').value = '';
		document.getElementById('shipping_state').value = '';
		document.getElementById('shipping_city').value = '';
		document.getElementById('shipping_country').value = '';
		document.getElementById('shipping_state1').value = '';
		document.getElementById('shipping_country1').value = '';
		document.getElementById('Shipping_zipcode').value='';
	}
}







function claculateExcisetotal(id,str)
{  
		var b=document.getElementById("total_item_amount").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("rateval").value=data[0];
				document.getElementById("custondutyval").value=data[1];
    		}
  		}
		xmlhttp.open("GET","ajax_calculate_customduty.php?quotTaxId="+str+"&data="+b,true);
		xmlhttp.send();


}



function GetSatateCountry(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)
    {
		var data=xmlhttp.responseText.split("__");
    	document.getElementById("billing_state").value=data[0];
		document.getElementById("billing_country").value=data[1];
		document.getElementById("billing_state1").value=data[2];
		document.getElementById("billing_country1").value=data[3];
    }
  	}
	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
	xmlhttp.send();
}


function GetSatateCountry1(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)
    {
		var data=xmlhttp.responseText.split("__");
    	document.getElementById("shipping_state").value=data[0];
		document.getElementById("shipping_country").value=data[1];
		document.getElementById("shipping_state1").value=data[2];
		document.getElementById("shipping_country1").value=data[3];
    }
  	}
	xmlhttp.open("GET","SateCountryName.php?CityId="+str,true);
	xmlhttp.send();
}



function GetOrderType(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)
	{
		var data=xmlhttp.responseText.split("__");
		document.getElementById("divordertype").innerHTML=data[0];
		document.getElementById("basicamtdetails").innerHTML=data[1];
	}
	}
	var requisitionno=document.getElementById("indentno").value;
	xmlhttp.open("GET","ajax_grn_order_type_po_indent.php?OrderType="+str+"&requisitionno="+requisitionno,true);
	xmlhttp.send();
}
function Checkfiles()
        {
        var fup = document.getElementById('filename');
        var fileName = fup.value;
        var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
        if(ext == "pdf" || ext=="txt" || ext=="docx")
        {
        return true;
        } 
        else
        {
        alert("Upload pdf/text/word  files only");
        fup.value='';
        fup.focus();
        return false;
        }
        }
</script>