<?php 	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<!--	<script src="js1/jquery-1.7.2.js"></script>-->
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>
<?php
if($_REQUEST['action']=='AddNew')
{
	if(($_REQUEST['Save']))
	{
	$prefix_sql=DB_query("Select prefix from locations where loccode='".$_REQUEST['Site']."' ",$db);
    $prefix_row=DB_fetch_array($prefix_sql);
    $branchPrefix=$prefix_row['prefix'];

   $orderNo_sql="Select id,orderNo from salesorder where branch='".$_REQUEST['Site']."'";
   $orderResult=DB_query($orderNo_sql,$db);


   if(DB_num_rows($orderResult)>0)
    {
	$GetMxSql=DB_query("SELECT MAX(orderNo) AS MAXON FROM salesorder where branch='".$_REQUEST['Site']."'",$db);
	$GetMaxId=DB_fetch_array($GetMxSql);
	$MaxOrdNo=substr($GetMaxId['MAXON'],-2);
	$FinalMaxOrdNo=$MaxOrdNo+1;
	
	$GetMaxCN=DB_query("SELECT MAX(cost_center) AS MAXCCN FROM salesorder where branch='".$_REQUEST['Site']."'",$db);
	$GetMaxCN1=DB_fetch_array($GetMaxCN);
	$MaxCCNO=substr($GetMaxCN1['MAXCCN'],-2);
	$FinalMaxCCNO=$MaxCCNO+1;
	
	

	$FinalOrdNo=$branchPrefix."/"."SO/".str_pad($FinalMaxOrdNo,5,"0",STR_PAD_LEFT);
	$FinalCostCeNo="CostCenter/".$branchPrefix."/".str_pad($FinalMaxCCNO,5,"0",STR_PAD_LEFT);
	
  }
  else
  {
	$FinalOrdNo=$branchPrefix."/SO/00001";
	$FinalCostCeNo="CostCenter/".$branchPrefix."/00001";

  }	
	
		
 	 $sql1="Insert into salesorder set
					branch='".$_REQUEST['Site']."', 
					store='".$_REQUEST['dealer']."',
					orderDate='".FormatDateForSQL($_REQUEST['TelephonicDate'])."',
					orderNo='".$FinalOrdNo."', 
					cost_center='".$FinalCostCeNo."',
					client='".$_REQUEST['Client']."',
					Sale_Key_Exec='".$_REQUEST['Sale_Key_Exec']."',  
			        PORefNo='".$_REQUEST['PONo']."',  
					customerPODate='".FormatDateForSQL($_REQUEST['PODate'])."',  
			        SalesOrderType='Tel',
					DeliveryDate='".FormatDateForSQL($_REQUEST['DelieveryDate'])."',
					RoadPermit='".$_REQUEST['RoadPermit']."',
					Transport='".$_REQUEST['Transport']."',
					freight='".$_REQUEST['freight']."',
					PendingPayment='".$_REQUEST['PendingPayment']."', 
					TelStatus= '".$_REQUEST['Status']."',
					ContactPerson='".$_REQUEST['ContactPerson']."',
					basicAmount='".$_REQUEST['basicAmount']."',
					exciseDuty='".$_REQUEST['EDBillRate']."',
					TotalExciseValue='".$_REQUEST['totalDiscountedPrice']."',
					taxableAmount='".$_REQUEST['taxableAmount']."',
					ECessPercentage='".$_REQUEST['ECessPercentage']."',
					ECessId='".$_REQUEST['ECessID']."',
					ECessValue='".$_REQUEST['ECessValue']."',
					SHECessId='".$_REQUEST['SHECessId']."',
					VatCst='".$_REQUEST['VatCst']."',
					VatCstValue='".$_REQUEST['VatCstValue']."',
 			        SAHCessPercentage='".$_REQUEST['SAHCessPercentage']."',  
					SAHCessValue='".$_REQUEST['SAHCessValue']."',
					order_type='".$_REQUEST['order_type']."',
					grandTotal='".$_REQUEST['grandTotal']."', 
					createdBy='".$_SESSION['UserID']."',
					CompanyId='".$_SESSION['ACGCompanyId']."'
 				    ,cate='".$_REQUEST['cate']."' ";
					
	$result1=DB_query($sql1,$db);
	 $SalesId=DB_Last_Insert_ID($db,'salesorder','id');

	
	

	
	if(isset($SalesId))
	{

for($i=0;$i<count($_REQUEST['item_code']);$i++)
{
 	if($_REQUEST['item_code'][$i]!=''){
	$data_arr['masterId']=$SalesId;
	$data_arr['ItemCode']=$_REQUEST['item_code'][$i];
 	$data_arr['Quantity']=$_REQUEST['Qty'][$i];
	$data_arr['Rate']=$_REQUEST['price'][$i];
	$data_arr['pricePer']=1;
	$data_arr['Amount']=$_REQUEST['stock_qty'][$i];
	$data_arr['EDRate']=$_REQUEST['EDRate'][$i];
	$data_arr['EDAmt']=$_REQUEST['EDAmt'][$i];
	$data_arr['mrp_unit']=$_REQUEST['mrp_per'][$i];
	$data_arr['ass_price']=$_REQUEST['ass_price'][$i];
	$data_arr['total_ass_price']=$_REQUEST['total_ass_price'][$i];
	$data_arr['remarks']=$_REQUEST['remarks'][$i];
	$data_arr['ApprovalStatus']="1";
 	
	$rowinsert= $s->RecordInsert('salesorder_details', $data_arr);
		if(!$rowinsert)
		{
		   die('Error'.DB_error());
		}
		}
}
	}
	
	
	
	if(isset($SalesId))
	{
		$sql_comment="insert into salesorder_comments set
					  sopno='".$SalesId."',
					  user='".$_SESSION['UserID']."',
					  comment='".$_REQUEST['comt']."',
					  posted_date=now()";
					  if($_REQUEST['comt']!='')
					  {
		$res_comment=DB_query($sql_comment,$db);
		}			  
	}
echo "<script>location.href='index.php?route=CRM/ViewSalesOrder&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Sales Order inserted successfully'),'success');}
}
unset($_POST);
?>
<script type="text/javascript">

function validation()
{
if(document.getElementById('Site').value=='0')
{alert('Please Select a branch');
document.getElementById('Site').focus();
return false;
}
if(document.getElementById('dealer').value=='')
{alert('Please Select a Delear');
document.getElementById('dealer').focus();
return false;
}
	
if(document.getElementById("TelephonicDate").value=='')
{
alert('Please enter the memo date');
document.getElementById('TelephonicDate').focus();
return false;
}

if(document.getElementById('po_no').value==''){
alert('PO No cannot be empty');
document.getElementById('po_no').focus();
return false;
}
	
if(document.getElementById('Client').value=='0'){
alert('Please choose a client');
document.getElementById('Client').focus();
return false;}
	
if(document.getElementById('Sale_Key_Exec').value=='0'){
alert('Please choose a Sales Executive');
document.getElementById('Sale_Key_Exec').focus();
return false;}


if(document.getElementById('PODate').value==''){
alert('Please enter PO Date');
document.getElementById('PODate').focus();
return false;
}

if(document.getElementById('cat').value=='0'){
alert('Please choose a category');
document.getElementById('cat').focus();
return false;}		
		
if(document.getElementById('basicAmount').value==''){
alert('Basic Amount cannot be empty');
document.getElementById('basicAmount').focus();
return false;
}
	
if(document.getElementById('taxableAmount').value==''){
alert('Taxable AMount cannot be empty');
document.getElementById('taxableAmount').focus();
return false;
}

if(document.getElementById('grandTotal').value==''){
alert('Grand Total cannot be empty');
document.getElementById('grandTotal').focus();
return false;
}
return true;
}	

function getContactName(str)
{
	
if(str.length==0)
{
	document.getElementById("ContactName").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("ContactName").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","getContact.php?Client="+str,true);
xmlhttp.send();	
	
	
} 
function getPhoneNo(str)
{
	
if(str.length==0)
{
	document.getElementById("PhoneNo").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("PhoneNo").innerHTML=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","getPhone.php?Contact="+str,true);
xmlhttp.send();	
	
	
} 
function openPopupProfile2()
{
	window.open("TelephonicItems.php?modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>");
}
function calculateTotalAmt(val,id)
{
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			var qty=document.getElementById("qty_"+i).value;
			var tot_amt=qty*val;
			document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			var qty=document.getElementById("qty").value;
			var tot_amt=qty*val;
			document.getElementById("totalamt").value=tot_amt.toFixed(2);
		}
}

function calassprice(val,id)
{
	
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price").value=tot_amt.toFixed(2);
		}
}

function calass_amount(id)
{
	var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{ 
			
			var qty=document.getElementById("qty_"+i).value;
			var ass_value=document.getElementById("ass_price_"+i).value;
			var tot_amt=ass_value*qty;
			document.getElementById("totalassamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var qty=document.getElementById("qty").value;
			var ass_value=document.getElementById("ass_price").value;
			var tot_amt=ass_value*qty;
			
			document.getElementById("totalassamt").value=tot_amt.toFixed(2);
		}
	
}

function calculateEDAmt(i)
{

    
 		
	var EDRate = document.getElementById("EDRate_"+i).value;
	alert("EDRate");
	if(EDRate=='0')
	{
		
		//var stock_price = document.getElementById("stock_qty_"+i).value;
		//alert(stock_price);
		document.getElementById("EDAmt_"+i).value='0.00';
		
	}
	else{
		
	
	 
 	var stock_price = document.getElementById("stock_qty_"+i).value;
 
	var EDAmt=((parseFloat(EDRate)*parseFloat(stock_price) )/100);
 	 document.getElementById("EDAmt_"+i).value=EDAmt.toFixed(2);
 	}
	 
 
}


function calculateBasic()
{
	var totalBasic=0;
	var first_row=document.getElementById("totalamt").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalBasic1=document.getElementById("totalamt_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	  document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
}

function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
       for(var i=0;i<cnt;i++)
      {
 	    var totalDiscounted1=document.getElementById("EDAmt_"+i).value;
 	    
 	    var totalDiscounted=(parseFloat(totalDiscounted)+parseFloat(totalDiscounted1)).toFixed(2);
  	 }
	 if(totalDiscounted1!=='0')
	 {
 	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
	}
	else{
		var total=document.getElementById("basicAmount").value;
		
		var Edrate=document.getElementById("EDRate_"+i).value;
		var discountEdrate=((parseFloat(Edrate)*parseFloat(total) )/100);
		document.getElementById("totalDiscountedPrice").value=discountEdrate.toFixed(2);
	}
}

function calculateECess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}

function calculateSAHCess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function calculateTaxable()

{
	var Basic=document.getElementById("basicAmount").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	
	
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}

function calculateVATCST(str)
{
	
	if (str.length==0)
  		{
  			document.getElementById("rate").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("rate").value=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?salesId="+str,true);
		xmlhttp.send();
}

function calculateGrand()
{
	
	
	var a=document.getElementById("totalDiscountedPrice").value;
	var b=document.getElementById("taxableAmount").value;
	var c=document.getElementById("VatCstValue").value;
	
	
	
	
	if(b==''){b=0;}
	if(c==''){c=0;}
	
	var GRAND=parseFloat(b)+parseFloat(c);
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	
}
 </script>
<blockquote>&nbsp;</blockquote>
<div class="body_contain">
<h1><?php echo $title; ?></h1>
<div class="insideclass">
<div style="z-index:-1000em;">
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Order Details</a></li>
<li><a href="#tabs-2">More Information</a></li>
</ul>
<div id="tabs-1">
<div class="tab_div">
<form action="" method="post"  >
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td>Branch</td>
    <td><select style="width:206px;" name="Site" id="Site"  onchange="showstorecode(this.value)"  >
                                <option value="0">Select Branch</option>
                                <?php
					$SQL="Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$Res=DB_query($SQL,$db);
					while($Row=DB_fetch_array($Res))
					{
					
					?>
                                <option value="<?php echo $Row['loccode']?>"<?php echo($_SESSION['Site']==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
                                <?php  } ?>
                              </select>
							  <div id="hid-Godown-div"><select name="store"  style="width:150px;" id="store">
		<?php $store_sql = "SELECT id, StoreName,StoreCode FROM storetype where Store_Site = '".$_GET['site']."'";
		
		$store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{
				;
				$p='';
				if($store_row['id'] == $_POST['store'])
				$p="selected";
				?>
				<option value="<?php echo $store_row['id']; ?>"<?php echo $p; ?>><?php echo $store_row['StoreName']; ?></option>
	<?php } ?>
		</select>
		</div></td>
    <td>SOP No<label><font color="#FF0000">*</font></label></td>
    <td><div id="orderid"> <input type="text" name="orderNo" id="orderNo" value="<?php  if($_REQUEST['orderNo']=='') echo "Auto Generated"; else $_REQUEST['orderNo'] ;?>" style="width:206px;" readonly=""></div></td>
    <td>Date<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="TelephonicDate" id="TelephonicDate" value="<?php if(isset($_SESSION['Telephonic'])){echo $_SESSION['TelephonicDate'];}else {echo date('d/m/Y');}?>"  class="datepicker" style="width:206px;"></td>
  </tr>
  <tr class="row1">
    <td>Client</td>
    <td><?php 
	$ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].") order by c_name ASC"  ;?>
	<select style="width:206px;" name="Client" id="Client" onchange="ShowDiv(this.value,'ContactName','getContact.php')">
	<option value="0">--Select--</option>
	<?php 
	$ClientRes=DB_query($ClientSQL,$db);
	while($ClientRow=DB_fetch_array($ClientRes))
	{
	?>
	<option value="<?php echo $ClientRow['id']?>" <?php echo($_SESSION['Client']==$ClientRow['id']?'selected':'')?>  ><?php echo $ClientRow['c_name']?></option>
	<?php  } ?>
	</select></td>
    <td>Contact</td>
    <td><?php 
	//$SQL="Select * from contact_information_master where master_code='".$_SESSION['Client']."'";
	$SQL="Select * from contact_information_master where master_code='".$_SESSION['Client']."'";
	?>
	<select style="width:206px;" name="ContactPerson" onchange="getPhoneNo(this.value)">
	<option value="0">--Select--</option>
	<?php
	
	$Res=DB_query($SQL,$db);
	while($Row=DB_fetch_array($Res))
	{
	?>
	<option value="<?php echo $Row['id']?>" <?php echo($_SESSION['ContactPerson']==$Row['id']?'selected':'')?>><?php echo $Row['person']?></option>
	<?php  } ?>
	</select></td>
    <td>Mobile No.</td>
    <td><div id="PhoneNo">
	<input type="text" style="width:206px;" name="Telephone" id="Telephone" value="<?php echo $_SESSION['Telephone']?>"  >
	</div></td>
  </tr>
  <tr class="row1">
    <td>Address 1</td>
    <td><input type="text"  style="width:206px;" name="Address1"  value="<?php echo $_SESSION['Address1']?>"/></td>
    <td>Address 2</td>
    <td><input type="text" name="Address2" id="Address2" style="width:206px;" value="<?php echo $_SESSION['Address2']?>"  ></td>
    <td>Address 3</td>
    <td><input type="text" name="Address3" id="Address3" style="width:206px;" value="<?php echo $_SESSION['Address3']?>"  ></td>
  </tr>
  <tr class="row1">
    <td>Client P.O. No.
	<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="PONo" id="po_no" style="width:206px;"  value="<?php echo $_REQUEST['PONo']?>" /></td>
    <td>P.O. Date<label><font color="#FF0000">*</font></label></td>
    <td><input type="text" name="PODate" id="PODate" style="width:206px;" class="datepicker"  value="<?php echo $_SESSION['PODate']?>"  ></td>
    <td>Delivery Date</td>
    <td><input type="text" name="DelieveryDate" id="DelieveryDate" style="width:206px;" class="datepicker" value="<?php echo $_SESSION['DelieveryDate']?>"   ></td>
  </tr>
  <tr class="row1">
    <td>Transport</td>
    <td><select style="width:206px;" name="Transport">
	<option value="0">--Select--</option>
	<?php
	$SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."'";
	$Res=DB_query($SQL,$db);
	while($Row=DB_fetch_array($Res))
	{					
	?>
	<option value="<?php echo $Row['id']?>" <?php echo($_SESSION['Transport']==$Row['id']?'selected':'' );?>  ><?php echo $Row['TransportName']?></option>
	<?php  } ?>
	</select></td>
    <td>Road Permit</td>
    <td><input name="RoadPermit" type="text"   style="width:206px;"   value="<?php echo $_SESSION['RoadPermit']?>"  /></td>
    <td>Freight Type</td>
    <td><select style="width:206px;" name="freight">
	<option value="0">Select</option>
	<option value="Paid">Paid</option>
	<option value="topay">To Pay</option>
	<option value="Nill">Nill</option>
	</select></td>
  </tr>
  <tr class="row1">
    <td>Category</td>
    <td><select name="cate" id="cat" style="width:206px;">
	<option value="0">Select</option>
	<option value="Urgent"<?php if($_SESSION['cate']=='Urgent'){ ?> selected="selected" <?php } ?> >Urgent</option>
	<option value="Normal" <?php if($_SESSION['cate']=='Normal'){ ?> selected="selected" <?php } ?>>Normal</option>
	</select></td>
    <td>Sales Key Executive <font color='red'>*</font></td>
    <td><?php 
	//echo "SELECT id FROM deptmaster WHERE deptcode='MKT' OR deptcode='sal'";
	$Dept=DB_query("SELECT id FROM deptmaster WHERE deptcode='MKT' OR deptcode='sal'",$db);
	if(DB_num_rows($Dept)>0)
	{
	while($DeptRow=DB_fetch_array($Dept))
	{
	$DCode[]=$DeptRow['id'];
	}
	$Dept_id=implode(',',$DCode);
	$Sale_key_Exe=DB_query("select * from www_users where companyid='".$_SESSION['ACGCompanyId']."' and department in($Dept_id)",$db);
	
	?>
	<select name="Sale_Key_Exec" id="Sale_Key_Exec" style="width:206px;">
	<option value="0">Select</option>
	<?php while($Sale_keyRow=DB_fetch_array($Sale_key_Exe))
	{
	?>
	<option value="<?php echo $Sale_keyRow['id'] ?>"<?php echo ($_SESSION['Sale_Key_Exec']==$Sale_keyRow['id']?'selected':'')?>><?php echo $Sale_keyRow['userid']; ?></option>
	<?php } }?>
	</select></td>
    <td>Pending Payments (if any)</td>
    <td><input type="text" name="PendingPayment" id="PendingPayment" value="<?php echo $_SESSION['PendingPayment'];?>"></td>
  </tr>
  <tr class="row1">
	<td colspan="6" style="background-color:#e7e7e7"><p align="left" style="padding-top:5px; padding-bottom:5px;">
	<input type="button" onclick="addRow('dataTable')" value="Add Rows" class="search" />
	&nbsp;&nbsp;
	<input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" />
	&nbsp;&nbsp;
	<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />
	</p></td>
</tr>
</table>

<div id="showdata">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border:#666666 solid 1px;">
<tr class="row1">
	<td class="tabledata">S.No</td>
	<td class="tabledata"></td>
	<td class="tabledata" style="width:40px;">Item Code</td>
	<td class="tabledata">Shade/Item Name. </td>
	<td class="tabledata" style="width:250px;">Item Desc. </td>
	<td class="tabledata">Stock Bal</td>
	<td class="tabledata">Qty</td>
	<td class="tabledata">Price</td>
	<td class="tabledata">Total Amt</td>
	<td class="tabledata">Excise Duty Rate</td>
	<td class="tabledata">ED Amt</td>
	<td class="tabledata">Remarks</td>
</tr>
<tbody id="dataTable">
<tr class="row1">
	<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
	</td>
	<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" /></td>
	<td class="tabledata"><input type="text" name="" value="" id="itemcode" size="6" /></td>
	<td class="tabledata" style="white-space:nowrap"><input type="text" name="" size="12" value="" id="itemname" /></td>
	<td class="tabledata"><input type="text" name="" value="" id="itemdesc" size="25"/></td>
	<td class="tabledata"><input type="text" name="stock[]" value="" id="total_stock" size="6" /></td>
	<td class="tabledata"><input type="text" name="Qty[]" value="" id="qty" size="6" onkeyup="calcValue1(this.value,this.id)" /></td>
	<td class="tabledata"><input type="text" name="price[]" value="" id="price" onkeyup="calculateTotalAmt(this.value,this.id)" size="6"/></td>
	<td class="tabledata"><input type="text" name="stock_qty[]" value="" id="totalamt" readonly="true" size="9"/></td>
	<td class="tabledata"><select name="EDRate[]" id="exciserate" style="width:107px" 
	onchange="calculateExcise(this.value,this.id)">
	<option value="0">--Select--</option>
	<?php
	$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
	$ServiceRes=DB_query($ServiceSql,$db);
	while($ServiceRow=DB_fetch_array($ServiceRes))
	{
	?>
	<option value="<?php echo $ServiceRow['id']?>" <?php echo($edit_EDRate==$ServiceRow['id']?'selected':'') ?>><?php echo $ServiceRow['caption'];?></option>
	<?php	
	}
	?>
	</select></td>
	<td class="tabledata"><input type="text" name="EDAmt[]" value="" id="excisevalue" size="5"/></td>
	<td class="tabledata"><textarea  name="remarks[]" value="" id="remarks" size="5"></textarea></td>
	<input type="hidden" name="ApprovalStatus[]" value="Pending">
</tr>
</tbody>
</table>
</div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="" id="edit_cnt" />
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td style="width:50%" align="left"></td>
	<td style="width:50%" align="right">
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr class="row1">
		<td class="tabledata1" colspan="2"><h1 style="border-width: 0 0 0 0px;">Amount And Taxes</h1></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Value Of Goods
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="basicAmount" type="text"  style="width:107px;" onfocus="calculateBasic()" id="basicAmount"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Excise Duty</td>
		<td><select name="EDBillRate" id="EDRate" style="width:107px" onchange="calculateBillExcise(this.value)"  >
		<option value="0">--Select--</option>
		<?php
		$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
		$ServiceRes=DB_query($ServiceSql,$db);
		while($ServiceRow=DB_fetch_array($ServiceRes))
		{
		?>
		<option value="<?php echo $ServiceRow['id']?>"><?php echo $ServiceRow['caption']?></option>
		<?php	
		}
		
		?>
		</select>
		<input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text"  style="width:107px;" onfocus="calculateTotalExcise()"/>
		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">E-Cess</td>
		<td><?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%Edu Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<input type="hidden" name="ECessID" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>"  readonly style="width:107px" />
		<input name="ECessValue" id="ECessValue" type="text"   readonly onfocus="calculateECess()" style="width:107px"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">SHE Cess </td>
		<?php  $SQl=DB_query("SELECT * FROM excise_tax WHERE caption LIKE '%SHE Cess%'",$db);
		$RESULT=DB_fetch_array($SQl);
		
		
		?>
		<td><input type="hidden" name="SHECessId" value="<?php echo $RESULT['id']?>" style="width:107px;">
		<input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $RESULT['def_rate'];?>" style="width:107px;" readonly/>
		<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:107px;" readonly onfocus="calculateSAHCess()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Taxable Amount
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="taxableAmount" id="taxableAmount" type="text" style="width:107px;" onfocus="calculateTaxable()"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">VAT/CST</td>
		<td><select name="VatCst" id="value3" onchange="calculateVATCST(this.value)" style="width:107px;">
		<option value="" >Select</option>
		<?php 
		$salesSql=DB_query("Select * from sales_tax_master",$db);
		while($salesRow=DB_fetch_array($salesSql))
		{?>
		<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
		<?php 	
		}
		?>
		</select>
		<div id="VATId">
		<input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:107px;" readonly  onfocus="calculateEditVATCST()" />
		</div>
		<input type="hidden" name="" id="rate" value="<?php echo $rate;?>" />
		</td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Grand Total</strong>
		<label><font color="#FF0000">*</font></label></td>
		<td><input name="grandTotal" id="grandTotal" type="text"  style="width:107px;" onfocus="calculateGrand()" readonly="readonly"  /></td>
		</tr>
		</table>
	</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td colspan="11">
		<p align="center">
			<input type="submit" name="Save" value="Save" class="search" onclick="return validation();"/>
                    <a href="index.php?route=CRM/ViewSalesOrder&modid=12&frmid=322" onclick="return confirm('Are you sure?');">
                    <input type="button" name="Cancel" value="Cancel" class="search"  />
                    </a>            <!-- Tab 1 Close -->
		</p>
	
	</td>
</tr>
</table>

 
<div id="tabs-2">
<div style="width:auto;">
<p style="margin:0px; padding:0px; text-align:left; font-weight:bold">Comment 1</p>
<p style="margin:0px; padding:0px; text-align:left;">
<textarea name="comt" style="width:700px;" ></textarea>
</p>
<p style="margin:0px; padding:0px; text-align:left; color:#003366">User Name 1</p>
</div>
</div>
            <!-- Tab 2 Close -->
          </form>
		  </div>
 </div>
        </div>
      </div>
    </div>
  </div>
  <!-- inside div close -->
</div>
<!-- Main div close -->
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

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

				case "hidden":

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

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

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

				break;

				case "button":

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

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

				break;

				case "checkbox":

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

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
	
	
function open_items()
{
if(document.getElementById("order_type").value=='')
{
alert("Must Select Order Type First");	
}
else
{	
var site=document.getElementById("Site").value;
var store=document.getElementById("store").value;
var date=document.getElementById("TelephonicDate").value;
	window.open("TelephonicItems.php?site="+site+"&store="+store+"&date="+date+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");}}
function calculateExcise(str,id)
{
	
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 
	
function calculateExcise1(str,id)	
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 	
	
function calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").value;
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("totalDiscountedPrice").value=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	}
function calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}

/*function validate()
{
	if(document.getElementById("Site").value=='0')
	{alert('Please choose a branch before saving'); document.getElementById("Site").focus();  return false;}
	
	if(document.getElementById("orderNo").value=='')
	{alert('SOP No. cannot be empty'); document.getElementById("orderNo").focus(); return false;}
	
	if(document.getElementById("Client").value=='0')
	{alert('Please choose a client before saving'); document.getElementById("Client").focus(); return false;}
	
	if(document.getElementById("PONo").value=='')
	{alert('Client PO No. cannot be empty'); document.getElementById("PONo").focus(); return false;}
		
	return false;
}*/

function getorder(str)
{
	if(str!='Consolidate')
	document.getElementById("EDRate").setAttribute('disabled',true);
	else
	document.getElementById("EDRate").removeAttribute('disabled');
	if(str.length==0)
	{
	document.getElementById("showdata").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("showdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","gettelephonicdata.php?id="+str,true);
	xmlhttp.send();
}

function showstore(str)
{

if(str.length==0)
  		{
  			document.getElementById("dealer").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("dealer").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","dealercode.php?salesId="+str,true);
		xmlhttp.send();



}

function showstorecode(str)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("hid-Godown-div").innerHTML=data[0];
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","lead_storecode.php?site="+str,true);
	xmlhttp.send();
}
function calcValue1(str,id)
{

	var brk=id.split('_');
	if(brk.length==1)
	{
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty").value='';
	   return false;
	   }
       
	}
	else
	{
	  if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[1]).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty_"+brk[1]).value='';
	   return false;
	   }
		
	}
}


</script>
