<?php include('includes/Class_Client.php');

include('functions.php');
//echo $_SESSION['ACG_DashBoard_User'];
$Prefix['prefix']="TaDa";
?>
<script language="javascript" >
function validate(){
	if(document.getElementById("branch").value=='')
	{
		alert("Please select Branch");
		return false;
	}
	if(document.getElementById("bill_date").value=='')
	{
		alert("Please select bill date");
		return false;
	}
	if(document.getElementById("client").value=='')
	{
		alert("Please select client");
		return false;
	}
	if(document.getElementById("client_loc").value=='')
	{
		alert("Please enter client location");
		return false;
	}
	if(document.getElementById("employee").value=='')
	{
		alert("Please select employee ");
		return false;
	}
	if(document.getElementById("emp_department").value=='')
	{
		alert("Please select department ");
		return false;
	}

}


/*function caltotal()
{
	//grand_total='';
	var count = document.getElementById("hiditemcount").value;
	
	if(document.getElementById("totalamt"))
	var total = parseInt(document.getElementById("totalamt").value);
	else
	var total=0;
	for(var i=0; i<=count; i++){
	if(document.getElementById("totalamt_"+i))
		total = total+parseInt(document.getElementById("totalamt_"+i).value);
	}
	
		document.getElementById("grand_total").value=total;
	
}
function frowtotal(str)
{
	
var id = str.split("_");
	
	if(id[1]){
	//alert("other_amt_"+id[1]);
	 if(document.getElementById("other_"+id[1]).value!='')
		var otheramt=document.getElementById("other_"+id[1]).value;
		else
		var otheramt=0;
		if(document.getElementById("hotel_"+id[1]).value!='')
		var hotel=document.getElementById("hotel_"+id[1]).value;
		else
		var hotel=0;
		if(document.getElementById("conveyance_"+id[1]).value!='')
		var conveyance=document.getElementById("conveyance_"+id[1]).value;
		else
		var conveyance=0;
		if(document.getElementById("da_"+id[1]).value!='')
		var da=document.getElementById("da_"+id[1]).value;
		else
		var da=0;
	
		
	
	var	total =parseInt(otheramt)+parseInt(hotel)+parseInt(conveyance)+parseInt(da);
		document.getElementById("totalamt_"+id[1]).value=total;
		}else{
		
		if(document.getElementById("other").value!='')
		var otheramt=document.getElementById("other").value;
		else
		var otheramt=0;
		if(document.getElementById("hotel").value!='')
		var hotel=document.getElementById("hotel").value;
		else
		var hotel=0;
		if(document.getElementById("conveyance").value!='')
		var conveyance=document.getElementById("conveyance").value;
		else
		var conveyance=0;
		if(document.getElementById("da").value!='')
		var da=document.getElementById("da").value;
		else
		var da=0;
		
		var	total =parseInt(otheramt)+parseInt(hotel)+parseInt(conveyance)+parseInt(da);
	
		document.getElementById("totalamt").value=total;
		
		
		}
	
}
	*/
  
  
  

function showClientCity(str,option)
{
	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;	
	
	//alert(xmlhttp.responseText);
	document.getElementById("client_loc").value=data;
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","clientcity.php?city_id="+str+"&option="+option,true);
	xmlhttp.send();
}
function showEmpdepart(str,option)
{
	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;	
	
	document.getElementById("emp_department").value=data;
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","clientcity.php?emp_id="+str+"&option="+option,true);
	xmlhttp.send();
}



/*function addRow(tableID) 
{
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	 
	var newcell = row.insertCell(i);
	newcell.style.background='#ffffff';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	//alert(newcell.childNodes[0].type);
	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 addRow(tableID) 
{
	
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	if(document.getElementById("hiditemcount").value=='')
	r =1;
	else
	{

	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1)+1;
	}
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=r;
	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;
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	newcell.childNodes[0].id = nod_id[0]+'_'+r;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	//document.getElementById("stock_perunit_"+rowCount).value='1';
}

function deleteRow(tableID) 
{
	try {
	var table = document.getElementById(tableID);
	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--;
	}
	}
	}catch(e) {
	alert(e);
	}
}
 function toggle() {
	var ele = document.getElementById("addnewTaDaFrom");

	if(ele.style.display == "block") {    	
	}
	else {
		ele.style.display = "block";
		document.getElementById("showdata").style.display = "none";
		document.getElementById("Addnew").style.display = "none";		
	}
}
 function toggle_new(urls) {
 
    window.location = "index.php?route=CRM/TA_DA_Claim_form&action=update&tada_id="+urls;	
	
	document.getElementById("showdata").style.display = "none";
	document.getElementById("Addnew").style.display = "none";	
	//alert(urls);	
}
</script>

<?php
if($_GET['action']=='update'){
	$id = $_GET['tada_id'];
	$TADAMain_Sql = DB_query("select * from crm_ta_da_claim_form_main where id=".$id,$db);
	$TADAMain_Data = DB_fetch_array($TADAMain_Sql);
	//echo "SELECT * FROM crm_ta_da_claim_form WHERE crm_ta_da_claim_form_main_id='".$id."'";
	$TADADetail_Sql = DB_query("SELECT * FROM crm_ta_da_claim_form WHERE crm_ta_da_claim_form_main_id=".$id,$db);
	
}

if($_GET['action']=='delete' && $_GET['tada_id']){
	$TaDa_id = $_GET['tada_id'];
	$rtn = DB_query("delete from crm_ta_da_claim_form where crm_ta_da_claim_form_main_id=".$TaDa_id,$db);
	if($rtn){
		DB_query("delete from crm_ta_da_claim_form_main where id=".$TaDa_id,$db);
		$s->pageLocation('index.php?route=CRM/ta_da_index&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
	}	
}

if($_REQUEST['tigger_Action'])
{
	$tada_data['branch']=$_REQUEST['branch'];
	$tada_data['bill_date']= ConvertSQLDate($_REQUEST['bill_date']);
	$tada_data['cost_center']=$_REQUEST['cost_center_text'];
	$tada_data['client_name']=$_REQUEST['client'];
	$tada_data['client_loc']=$_REQUEST['client_loc'];
	$tada_data['employee']=$_REQUEST['employee']; 
	$tada_data['grand_total']=$_REQUEST['grand_total'];  
	$tada_data['prepared_by']=$_SESSION['UserID'];
	$tada_data['approved_by']=$_REQUEST['approved_by'];
	$tada_data['emp_department']=$_REQUEST['emp_department'];
	$tada_data['assigned_by']=$_REQUEST['assigned_by'];  
	$tada_data['frmdate']=ConvertSQLDate($_REQUEST['frmdate']); 
	$tada_data['todate']=ConvertSQLDate($_REQUEST['todate']); 
	$tada_data['purpose']=$_REQUEST['purpose'];
        
	if($_REQUEST['tigger_Action'] == 'Save'){
	
		$chkbill=DB_query("SELECT * FROM crm_ta_da_claim_form_main",$db);
	
		if(DB_num_rows($chkbill)>0)
		{
		   $GetMxSQL=DB_query("SELECT MAX(bill_no) as bill_num FROM crm_ta_da_claim_form_main",$db);
			$GetMAXID=DB_fetch_array($GetMxSQL);
			$Explode=explode("/",$GetMAXID['bill_num']);
			$FinalMaxId=$Explode[1]+1;
			$FinalCode=$Prefix['prefix']."/".str_pad($FinalMaxId,5,0,STR_PAD_LEFT);
			$tada_data['bill_no']=$FinalCode;
		}
		else
		{
			$FinalCode=$Prefix['prefix']."/"."00001";
			$tada_data['bill_no']=$FinalCode;
		}
		//echo '<pre>';print_r($tada_data); exit;
                $tada_data['created_date']=date('Y-m-d');
                $tada_data['CompanyId']=$_REQUEST['purpose'];
		$row_insert= $s->RecordInsert('crm_ta_da_claim_form_main', $tada_data );
		$lastid=DB_Last_Insert_ID($db,'crm_ta_da_claim_form_main','id');
	}
	if($_REQUEST['tigger_Action'] == 'update'){
		$cond="id='".$_REQUEST['tada_id']."'";		
		$s->RecordEdit('crm_ta_da_claim_form_main', $tada_data,$cond);	
		$lastid=$_REQUEST['tada_id'];
	}
	//echo '<pre>'; print_r( $_REQUEST);exit;
	
	if($_REQUEST['tigger_Action'] == 'update'){
	$delete=DB_query("delete from crm_ta_da_claim_form where crm_ta_da_claim_form_main_id='".$_REQUEST['tada_id']."'",$db);
	}
   	for($i=0;$i<count($_REQUEST['total_amt']);$i++)
	{	
		$data_exp['from_location']=$_REQUEST['from_location'][$i];
		$data_exp['to_location']=$_REQUEST['to_location'][$i];
		$data_exp['travelmode']=$_REQUEST['travelmode'][$i];
		$data_exp['total_km']=$_REQUEST['total_km'][$i];
		$data_exp['rate_unit']=$_REQUEST['rate_unit'][$i];
		$data_exp['other_amt']=$_REQUEST['other_amt'][$i];
		$data_exp['da']=$_REQUEST['da'][$i];
		$data_exp['hotel']=$_REQUEST['hotel'][$i];
		$data_exp['conveyance']=$_REQUEST['conveyance'][$i];
		$data_exp['total_amt']=$_REQUEST['total_amt'][$i];
		$data_exp['narration']=$_REQUEST['narration'][$i];
		$data_exp['cost_center']=$_REQUEST['cost_center'][$i];
		$data_exp['user_id']=$_SESSION['UserID'];
		$data_exp['crm_ta_da_claim_form_main_id'] =$lastid;
                $row_insert= $s->RecordInsert('crm_ta_da_claim_form', $data_exp );
	}
	
$s->pageLocation('index.php?route=CRM/ta_da_index&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}

echo $_REQUEST['VisitId'];
if($_REQUEST['action']=='update' && $_REQUEST['VisitId']!='')
{
	//$Report=DB_query("select * from crm_mst_daily_visit_entry where id")
}



?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
 <div id="addnewTaDaFrom">
<h1>TA DA CLAIM FORM</h1>
<div style="width:auto; margin-right:auto; margin-left:auto; overflow:auto;">

<table width="100%" border="0" cellpadding="3" cellspacing="0">
<?php
	if(count($msgErr)>0)
	{?>
		<tr>
	<td colspan="4">
		<?php 
		for($i=0;$i<count($msgErr);$i++)
		{
		echo "<div class='error'>".$msgErr[$i]."</div>";	
		}?>
		</td>
		</tr>
		<?php
	}
	
	?>
</table>

	<!--Table 1 Start -->
    
      <form method="post" action="" id="tada_form" onsubmit="return validate();">
        <!--Table 2 Start -->
        <h3>Expense Information</h3>
		
		<h3>General Details</h3>
<table width="100%" align="center" border="0" cellpadding="3" style="border-collapse:collapse;" cellspacing="0">
  <tr class="row1">
    <td width="13%" align="right"><strong>Branch</strong> <font color="#FF0000">*</font></td>
    <td width="20%">
	<select style="width:98%;" name="branch" id="branch">
		<option value="000">Select Branch</option>
		
			<?php 
			$sql_state=DB_query("SELECT loccode,locationname FROM  locations ",$db); 
			while($SiteName=DB_fetch_array($sql_state)) {?>
			<option value="<?php echo $SiteName['loccode']; ?>"  <?php // echo($TADAMain_Data['branch']==$SiteRow['loccode']?'selected':'');?>><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
    </select>
    </td>
    <td width="13%" align="right"><strong>Bill No.</strong></td>
    <td width="20%"><input type="text" class="" name="bill_no" value="Auto Generated" id="bill_no" style="width:98%;" readonly="true" />
    </td>
    <td width="13%" align="right"><strong>Bill Date</strong> <font color="#FF0000">*</font></td>
    <td><input name="bill_date"  readonly id="bill_date" value="<?php echo date('d/m/Y'); ?>" type="text" class="datepicker" style="width:98%;" /></td>
  </tr>
  <tr class="row1">   
    <td align="right"><strong>Client</strong> <font color="#FF0000">*</font></td>
    <td><select style="width:98%;" name="client" id="client" onchange="showClientCity(this.value,'show_location')">
	<option value="0">Select</option>
      <?php
		$ClientSQL="Select * from clientmaster  where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name";
		$ClientRes=DB_query($ClientSQL,$db);
		while($ClientRow=DB_fetch_array($ClientRes))
		{
 		?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo($TADAMain_Data['client_name']==$ClientRow['id']?'selected':'');?> ><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
    </select></td>
    <td align="right"><strong>Location</strong> <font color="#FF0000">*</font></td>
    <td><input name="client_loc" id="client_loc" type="text" class="" value="<?php echo $TADAMain_Data['client_loc'];  ?>" style="width:98%;" /></td>
	<td align="right"><strong>Purpose</strong></td>
    <td><input name="purpose" id="purpose" type="text" value="<?php echo $TADAMain_Data['purpose']; ?>" class="" style="width:98%;" /></td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>Employee</strong> <font color="#FF0000">*</font></td>
    <td>
	<select style="width:98%;" name="employee" id="employee" onchange="showEmpdepart(this.value,'show_department');">
	<option value="0">Select</option>
      <?php 
		$sql_employee=DB_query("SELECT * FROM  empmaster where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); 
		while($emp=DB_fetch_array($sql_employee)) {?>
		<option value="<?php echo $emp['id']; ?>" <?php echo($TADAMain_Data['employee']==$emp['id']?'selected':'');?>><?php echo $emp['emp_name']; ?></option>
		<?php }?>
    </select></td>
    <td align="right"><strong>Department</strong> <font color="#FF0000">*</font></td>
    <td><input name="emp_department" id="emp_department" type="text" class=""  value="<?php echo $TADAMain_Data['emp_department']; ?>" style="width:98%;"/></td>
	<td align="right"><strong>Assigned by</strong></td>
    <td><input name="assigned_by" id="assigned_by" type="text" class="" value="<?php echo $TADAMain_Data['assigned_by']; ?>" style="width:98%;"/></td>   
  </tr>
  <tr class="row1">   
    <td align="right"><strong>From Date</strong></td>
    <td><input name="frmdate" id="frmdate" type="text" class="datepicker" value="<?php // echo ConvertSQLDate($TADAMain_Data['frmdate']); ?>" style="width:98%;"/></td>
    <td align="right"><strong>To Date</strong></td>
    <td><input name="todate" id="todate" type="text" value="<?php // echo ConvertSQLDate($TADAMain_Data['todate']); ?>" class="datepicker" style="width:98%;" /></td>
    <td colspan="2"></td>
  </tr>
</table>
<p align="left">
          <input name="button" type="button" onclick="addRow('dataTable1')" value="Add Row" title="Add Row" class="search"/>
          <input name="button2" type="button" onclick="deleteRow('dataTable1')" value="Delete Row" title="Delete Row" class="search"/>
        </p>
        <!--Table 1 Start -->
		<div style="width:100%; overflow:auto;">

          <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
            <tr>
              <th width="3%"></th>
              <th width="7%">From</th>
              <th width="7%">To</th>
              <th>Mode</th>
              <th width="7%">Total km</th>
              <th width="7%">Rate/Unit</th>
              <th width="7%">Conveyance</th>
              <th width="7%">DA</th>
              <th width="7%">Hotel</th>
              <th width="7%">Other Amount </th>
              <th width="7%">Total Amount </th>
              <th width="7%">Narration</th>
              <th width="7%">Cost Center</th>
            </tr>
            <tbody id="dataTable1" >
			<?php			
			 if($_GET['action']=='update'){
			 $i=0;
			 while($TADADetail_Data = DB_fetch_array($TADADetail_Sql)){
			 //echo '<pre>'; print_r($TADADetail_Data); exit;
			?>
              <tr bgcolor="#fff">
                <td><input type="checkbox" name="chk"/></td>
                <td><input style="width:100%;" type="text" name="from_location[]"  value="<?php echo $TADADetail_Data['from_location']; ?>"  /></td>
                <td><input style="width:100%;" type="text" name="to_location[]" value="<?php echo $TADADetail_Data['to_location']; ?>"  /></td>
                <td><select  name="travelmode[]"   style="width:100%;">
                    <option value="bus">BY Bus</option>
                    <option value="Bike">BY Bike</option>
                    <option value="Rail">BY Rail</option>
                    <option  value="Air">BY Air</option>
                    <option value="other">Other</option>
                  </select>
                </td>
                <td><input style="width:100%;" type="text" name="total_km[]" value="<?php echo $TADADetail_Data['total_km']; ?>"  id="total_km"  /></td>
                <td><input style="width:100%;" type="text" name="rate_unit[]" value="<?php echo $TADADetail_Data['rate_unit']; ?>" id="rate_unit"   /></td>
                <td><input style="width:100%;" type="text" name="conveyance[]" value="<?php echo $TADADetail_Data['conveyance']; ?>" id="conveyance_<?php echo $i; ?>" onkeyup="frowtotal(this.id)" /></td>                
                <td><input style="width:100%;" type="text" name="da[]"  value="<?php echo $TADADetail_Data['da']; ?>" id="da_<?php echo $i; ?>" onkeyup="frowtotal(this.id)" /></td>
                <td><input style="width:100%;" type="text" name="hotel[]" value="<?php echo $TADADetail_Data['da']; ?>" id="hotel_<?php echo $i; ?>" onkeyup="frowtotal(this.id)" /></td>
                <td><input style="width:100%;" type="text" name="other_amt[]" value="<?php echo $TADADetail_Data['other_amt']; ?>"  id="other_<?php echo $i; ?>" onkeyup="frowtotal(this.id)" /></td>
                <td><input style="width:100%;" type="text" name="total_amt[]" value="<?php echo $TADADetail_Data['total_amt']; ?>" id="totalamt_<?php echo $i; ?>"  onfocus="frowtotal(this.id);" /></td>
                <td><input style="width:100%;" type="text" name="narration[]" value="<?php echo $TADADetail_Data['narration']; ?>" id="narration" /></td>
                <td><select style="width:100%" name="cost_center[]" >
                    <option value="000">---</option>
                    <?php
		$CostSQL="Select cost_center from salesorder ";
		$CostRes=DB_query($CostSQL,$db);
		while($CostRow=DB_fetch_array($CostRes))
		{
 		?>
                    <option value="<?php echo $CostRow['cost_center']?>" <?php echo ($_REQUEST['cost_center']==$CostRow['cost_center']?'selected':'');?> ><?php echo $CostRow['cost_center']?></option>
                    <?php  } ?>
                  </select>
				  <input type="hidden" name="detail_id[]" value="<?php echo $TADADetail_Data['id']; ?>" />
                </td>
              </tr>
			  <?php $i++; }} else { ?>
			   <tr bgcolor="#fff">
                <td><input type="checkbox" name="chk"/>
                </td>
                <td><input style="width:100%;" type="text" id="fromlocation" name="from_location[]" value="<?php echo $TADADetail_Data['from_location']; ?>" /></td>
                <td><input style="width:100%;" type="text" id="tolocation" name="to_location[]" value="<?php echo $TADADetail_Data['to_location']; ?>" /></td>
                <td><select name="travelmode[]" style="width:100%">
                    <option value="bus"> Bus</option>
                    <option value="Bike"> Bike</option>
                    <option value="Car"> Car</option>
                    <option value="Rail"> Rail</option>
                    <option value="Air"> Air</option>
                    <option value="other">Other</option>
                  </select>
                </td>
                <td><input style="width:100%;" type="text" name="total_km[]" onkeypress="javascript:return isNumberKey1(event)" value="" maxlength="5"  id="totalkm"  /></td>
                <td><input style="width:100%;" type="text" name="rate_unit[]" value="" id="rateunit" onkeyup="javascript:calc_total_conveyance(this)"  onkeypress="javascript:return isNumberKey1(event)" /></td>
                <td><input style="width:100%;" type="text" name="conveyance[]" value="" onkeypress="javascript:return isNumberKey1(event)" readonly id="conveyance" /></td>
                <td><input style="width:100%;" type="text" name="da[]" onkeyup="javascript:calc_total_allowance(this,'da')" onkeypress="javascript:return isNumberKey1(event)" value="" id="da" /></td>
                <td><input style="width:100%;" type="text" onkeyup="javascript:calc_total_allowance(this,'hotel')"  onkeypress="javascript:return isNumberKey1(event)" name="hotel[]" value="" id="hotel" /></td>                
                <td><input style="width:100%;" type="text" name="other_amt[]" onkeyup="javascript:calc_total_allowance(this,'other')"  onkeypress="javascript:return isNumberKey1(event)" value="" id="other" /></td>
                <td><input style="width:100%;" readonly type="text" name="total_amt[]" value="" id="totalamt" /></td>
                <td><input style="width:100%;" type="text" name="narration[]" value="" id="narration" /></td>
                <td><select style="width:100px" name="cost_center[]" >
                    <option value="000">---</option>
                    <?php
		$CostSQL="Select cost_center from salesorder ";
		$CostRes=DB_query($CostSQL,$db);
		while($CostRow=DB_fetch_array($CostRes))
		{
 		?>
                    <option value="<?php echo $CostRow['cost_center']?>" <?php echo ($_REQUEST['cost_center']==$CostRow['cost_center']?'selected':'');?> ><?php echo $CostRow['cost_center']?></option>
                    <?php  } ?>
                  </select>
				  <input type="hidden" name="detail_id[]" value="<?php echo $TADADetail_Data['id']; ?>" />
                </td>
              </tr>
			  <?php } ?>
			  
            </tbody>
			<input type="hidden" name="hiditemcount" id="hiditemcount" value="0" />
          </table>
		  
        </div>
		<br />
		<table width="50%" align="right" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td width="40%"><strong>Total</strong></td>
    <td><input style="width:100%;" type="text" id="grand_total" name="grand_total" value="<?php echo $TADAMain_Data['grand_total']; ?>"  /></td>
    </tr>
</table>
<br />
<?php 
$dept=$s->getField('www_users','id',$_SESSION['UserID'],'mst_dpt_heirarchy');
$upper=GETUpperDeptUser($dept,$_SESSION['UserID'],$_SESSION['ACGCompanyId']);
?>
<table width="100%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td width="20%"><strong>Prepared By</strong></td>
    <td width="30%"><input name="prepared_by" readonly id="prepared_by" type="text" class="" value="<?php echo trim($_SESSION['UsersRealName']); ?>" style="width:98%;" />
    </td>
    <td width="20%"><strong>Approved By</strong></td>
    <td width="30%">
        <select  name="approved_by" id="approved_by" style="width:98%"> 
 <?php    foreach($upper as $val)
{ if($val!='0') { ?>
        <option value="<?php echo $val; ?>"><?php echo $s->getField('www_users','id',$val,'realname'); ?></option>
   
<?php } } ?>
    </select>        
    </td>    
  </tr>  
</table>
        <!--Table 2 Start -->

        <p align="center">
		<?php if($_REQUEST['action']=='update'){ ?>
        	<input name="tigger_Action" type="submit" value="update" class="search"   />
		<?php }else { ?>
			<input name="tigger_Action" type="submit" value="Save" class="search"  />
			
		<?php  } ?>
		  
          <input name="cancel" type="reset" value="Cancel" class="search" />
        </p>
      </form>

<?php if($_REQUEST['action']!='update'){ ?> 
<!--<div align="left">
          <input name="Addnew" id="Addnew" type="button" value="Addnew"   onclick="toggle()" class="search"  />
          
        </div>
		<br />

		<?php } ?>
		<div id="showdata" style="<?php if($_REQUEST['action']=='update'){ ?>   display:none; <?php }else{ ?> display:block; <?php } ?>">
<table align="center" width="100%;" border="1" cellpadding="3" cellspacing="0">
<tr class="row1"><th style="text-align:center;" colspan="11"><strong>TA DA CLAIM DETAILS</strong></th></tr>
<tr class="row1">
	<th>Sr. No.</th>
        <th>Bill No </th>
        <th>Bill Date </th>
        <th>Client</th>
        <th>Employee</th>
	<th>Edit</th>
        <th>Delete</th>
        <th>Print</th>
</tr>
  <tbody id="dataTable" >
  <?php $TADASQL="Select * from crm_ta_da_claim_form_main ";
		$TADADATA=DB_query($TADASQL,$db);
		$count=0;
		while($TADARow=DB_fetch_array($TADADATA))
		{ $count++; ?>
  	<tr class="row1">
<td style="white-space:nowrap;" ><?php echo $count; ?>
</td>

<td ><?php echo $TADARow['bill_no'] ?> </td>
<td ><?php echo $TADARow['bill_date'] ?></td>
<td  style="white-space:nowrap"><?php echo $s->getField('clientmaster','id',$TADARow['client_name'],'c_name'); ?></td>
<td ><?php echo $s->getField('empmaster','id',$TADARow['employee'],'emp_name'); ?></td>
<td > <a href="#">
  <img src="images/icon_edit.gif" width="10px"  height="10" onclick="toggle_new('<?php echo $TADARow['id'].$rurl;?>');" /></a></td>
<td > <a href="index.php?route=CRM/TA_DA_Claim_form&action=delete&tada_id=<?php echo $TADARow['id'].$rurl;?>" >
  <img src="images/delete.Gif" width="10px"  height="10"  /></a></td>
<td ><a href="#" onclick="popup('bill_report.php?id=<?php echo $TADARow['id']; ?>',1200,600)">Print</a></td>

</tr>

<?php } ?>

</tbody>
 </table>

 </div>-->
 </div>
 </div>
 </div>
 </div>
    
<script>
function isNumberKey1(evt)
 {
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
    return false;
else
 return true;
 }                        
                        
function calc_total_conveyance(str)
{
    var id=str.id.split("_");
    
    if(id[1]==undefined)
        {
            if(document.getElementById('totalkm').value!='' && str.value!=''){
            var convey=parseFloat(document.getElementById('totalkm').value) * parseFloat(str.value);
            document.getElementById('conveyance').value=convey.toFixed(2);
            document.getElementById('totalamt').value=convey.toFixed(2);
            }  
        }
     else
         {
             if(document.getElementById('totalkm_'+id[1]).value!='' && str.value!=''){
            var convey=parseFloat(document.getElementById('totalkm_'+id[1]).value) * parseFloat(str.value);
            document.getElementById('conveyance_'+id[1]).value=convey.toFixed(2);
            document.getElementById('totalamt_'+id[1]).value=convey.toFixed(2);
         }
         }
          var fnl=parseFloat(grand_tot());
         document.getElementById('grand_total').value=fnl.toFixed(2) ;
}

function calc_total_allowance(str,type)
{
    
    var id=str.id.split("_");
    
    if(id[1]==undefined)
        {
        if(document.getElementById('da').value=='')
        {
        var da=0; 
         // document.getElementById('da').value=0;
        }
        else
        {
         var da=document.getElementById('da').value; 
        } 
        if(document.getElementById('hotel').value=='')
        {
          document.getElementById('hotel').value=0;
        }
        if(document.getElementById('other').value=='')
        {
          document.getElementById('other').value=0;
        }
        if(document.getElementById('conveyance').value=='')
        {
          document.getElementById('conveyance').value=0;
        }

    
       var row1= parseFloat(da)+parseFloat(document.getElementById('hotel').value)+parseFloat(document.getElementById('other').value)+parseFloat(document.getElementById('conveyance').value);
        document.getElementById('totalamt').value=row1.toFixed(2)
        }
        else
         {
             if(document.getElementById('da_'+id[1]).value=='')
        {
        var da=0; 
         // document.getElementById('da').value=0;
        }
        else
        {
         var da=document.getElementById('da_'+id[1]).value; 
        } 
        if(document.getElementById('hotel_'+id[1]).value=='')
        {
          document.getElementById('hotel_'+id[1]).value=0;
        }
        if(document.getElementById('other_'+id[1]).value=='')
        {
          document.getElementById('other_'+id[1]).value=0;
        }
        if(document.getElementById('conveyance_'+id[1]).value=='')
        {
          document.getElementById('conveyance_'+id[1]).value=0;
        }
        var row=parseFloat(da)+parseFloat(document.getElementById('hotel_'+id[1]).value)+parseFloat(document.getElementById('other_'+id[1]).value)+parseFloat(document.getElementById('conveyance_'+id[1]).value);
        document.getElementById('totalamt_'+id[1]).value=row.toFixed(2)
         }
         var fnl=parseFloat(grand_tot());
         document.getElementById('grand_total').value=fnl.toFixed(2) ;
}
function grand_tot()
{ 
   var tot=0;
   var row_tot;
   if(document.getElementById('totalamt'))
    {
      tot+=parseFloat(document.getElementById('totalamt').value);
    }
    var count = document.getElementById("hiditemcount").value;
  
    for(var j=1;j<=parseInt(count);j++)
    {
        if(document.getElementById('totalamt_'+j))
        {
            if(document.getElementById('totalamt_'+j).value=='')
                {
                    row_tot=0;
                }
                else
                    {
                        row_tot=document.getElementById('totalamt_'+j).value;
                    }
             tot+=parseFloat(row_tot);
        }
    }

    return tot;
}
</script>