<?php 

if($_REQUEST['action']=='Edit')
{
	
    $getlead=DB_query( "select * from daily_visit_entry where id='".$_REQUEST['VisitId']."'",$db);
	 while($row_lead=DB_fetch_array($getlead))
	 {
	    $SrNo=$row_lead['SrNo'];
		$DailyVisitDate=ConvertSQLDate($row_lead['DailyVisitDate']);
  	     $EmpName=$row_lead['EmpName'];
		$Department=$row_lead['Department'];
		$Designation=$row_lead['Designation'];
		$Site=$row_lead['Site'];
	    $ClientName=$row_lead['ClientName'];
		$ClientLocation=$row_lead['ClientLocation'];
		$ClientCity=$row_lead['ClientCity'];
		$ContactPerson=$row_lead['ContactPerson'];
		$MobileNo=$row_lead['MobileNo'];
		$OfficeNo=$row_lead['OfficeNo'];
		
		
		$Email=$row_lead['Email'];
		$Website=$row_lead['Website'];
		$MeetingType=$row_lead['MeetingType'];
		$PurposeAssigned=$row_lead['PurposeAssigned'];
		$MeetingDes=$row_lead['MeetingDes'];
		$ExpenseFrom=ConvertSQLDate($row_lead['ExpenseFrom']);
		$ExpenseTo=ConvertSQLDate($row_lead['ExpenseTo']);
		$Mode=$row_lead['Mode'];
		$TotalKM=$row_lead['TotalKM'];
		$Rate=$row_lead['Rate'];
		$TotalTA=$row_lead['TotalTA'];
		$Fooding=$row_lead['Fooding'];
		$OtherCharges=$row_lead['OtherCharges'];
		$TotalAmt=$row_lead['TotalAmt'];
		$ReportTo=$row_lead['ReportTo'];
		$PaidStatus=$row_lead['PaidStatus'];
		$Narration=$row_lead['Narration'];
		
		}
}
$table="daily_visit_entry";
if($_REQUEST['save']!='')
{
	$DepartmentID=$s->getField('deptmaster','deptname',$_REQUEST['Department'],'deptcode');
	$DesignationID=$s->getField('desigmaster','designame',$_REQUEST['Designation'],'desigcode');
	$BranchID=$s->getField('locations','locationname',$_REQUEST['Site'],'loccode');
	
	
    $data['DailyVisitDate']=ConvertSQLDate($_REQUEST['DailyVisitDate']);
	$data['EmpName']=$_REQUEST['EmpName'];
	$data['Department']=$DepartmentID;
	$data['Designation']=$DesignationID;
	$data['Site']=$BranchID;
	$data['ClientName']=$_REQUEST['ClientName'];
	$data['ClientLocation']=$_REQUEST['ClientLocation'];
	$data['ClientCity']=$_REQUEST['ClientCity'];
	$data['ContactPerson']=$_REQUEST['ContactPerson'];
	$data['MobileNo']=$_REQUEST['MobileNo'];
	$data['OfficeNo']=$_REQUEST['OfficeNo'];
	$data['Email']=$_REQUEST['Email'];
	$data['Website']=$_REQUEST['Website'];
	
	
	$data['PurposeAssigned']=$_REQUEST['PurposeAssigned'];
	$data['MeetingDes']=$_REQUEST['MeetingDes'];
	$data['ExpenseFrom']=ConvertSQLDate($_REQUEST['ExpenseFrom']);
	$data['ExpenseTo']=ConvertSQLDate($_REQUEST['ExpenseTo']);
	$data['Mode']=$_REQUEST['Mode'];
	$data['TotalKM']=$_REQUEST['TotalKM'];
	
	
	$data['Fooding']=$_REQUEST['Fooding'];
	$data['OtherCharges']=$_REQUEST['OtherCharges'];
	$data['TotalAmt']=$_REQUEST['TotalAmt'];
	$data['ReportTo']=$_REQUEST['ReportTo'];
	$data['PaidStatus']=$_REQUEST['PaidStatus'];
	$data['Narration']=$_REQUEST['Narration'];
	
	$cond="id='".$_REQUEST['VisitId']."'";
	$row= $s->RecordEdit($table, $data,$cond);
	prnMsg(_('Updated Successfuly'),'Success');
	echo "<script>location.href='index.php?route=CRM/field_visit_report&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}






?>







<script type="text/javascript">
function Cal_TotalTA()
{
	var KM= document.getElementById("KM").value;
	var Rate= document.getElementById("Rate").value;
	var TotalTa=parseFloat(KM)*parseFloat(Rate);
	document.getElementById("TotalTA").value=TotalTa;
	
}
function Cal_TotalAmt()
{
	var TotalTA= document.getElementById("TotalTA").value;
	var Fooding= document.getElementById("Fooding").value;
	var OtherCharges=document.getElementById("OtherCharges").value;
	var TotalAmt=parseFloat(TotalTA)+parseFloat(Fooding)+parseFloat(OtherCharges);
	document.getElementById("TotalAmt").value=TotalAmt;
	
}
</script>

<div style="width:800px; margin-right:auto; margin-left:auto;">
<fieldset style="margin:0px;text-align:left;">
<h2 align="center">DAILY FIELD MARKETING</h2>

<form method="post" action="">
	<!--Table 1 Start --><div style="width:650px;">
	<h3>General Info</h3>
	

		<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
  	 
  	<th>Sr No.</th>
    <td><input name="SrNo" type="text" style="width:auto;"  value="<?php echo $SrNo;?>" readonly /></td>
    <th style="padding-left:30px;">Date</th>
    <td>
    	<input type="text" style="width:auto;" name="DailyVisitDate"  class="datepicker"   value="<?php echo $DailyVisitDate;?>" />
	</td>
    <th>Emp. Name</th>
    <td>
    	<?php 
    		$EmpSql="SELECT * FROM empmaster where id='".$EmpName."'";
			$EmpRes=DB_query($EmpSql,$db);
			$EmpRow=DB_fetch_array($EmpRes);
			
			
    		?>
			
			<?php ?>
			<select style="width:107px;;" name="EmpName" onchange="ShowDiv(this.value,'hid_EDetails','disp_EmpDetails.php')">
    	    		<option id="0">--Select--</option>
    		<?php 
    		$EmpSql="SELECT * FROM empmaster";
			$EmpRes=DB_query($EmpSql,$db);
			while($EmpRow=DB_fetch_array($EmpRes))
			{
    		?>
			<option value="<?php echo $EmpRow['id']?>"<?php echo $EmpName==$EmpRow['id']?'selected':''?>><?php echo $EmpRow['emp_name']?></option>
			<?php }?>
			
	
	</select>
		
		
		
		</td>
 </tr>
 </table>

		<div id="hid_EDetails" align="left">
  	<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
  	 
  	<th>Dept.</th>
    <td>
   <?php $DepartmenName=$s->getField('deptmaster','deptcode',$Department,'deptname')?> 	
   <input type="text" name="Department" value="<?php echo $DepartmenName?>" style="width:auto;" ></td>
    <th>Designation</th>
    <td>
    	
    	
    	<?php $DesignationName=$s->getField('desigmaster','desigcode',$Designation,'designame'); ?>
    	<input type="text" name="Designation" value="<?php echo $DesignationName?> " style="width: auto;">
	</td>
    <th>Branch</th>
    <td>
    	<?php $BranchName=$s->getField('locations','loccode',$Site,'locationname');?><input type="text" name="Site" value="<?php echo $BranchName?>" style="width:auto;" /></td>
 </tr></table>
 	</div>

</div><!--Table 1 Start -->

	

<!--Table 1 Start --><div style="width:650px;">
<h3>Field Vist Report</h3>
	
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <th>Client Name</th>
    <td><input type="text" style="width:auto;" name="ClientName" value="<?php echo  $ClientName ?>" />
</td>
    <th>Location</th>
    <td><input type="text" style="width:auto"  name="ClientLocation"  value="<?php echo $ClientLocation?>"  /></td>
    <th>City</th>
    <td><input type="text" style="width:auto" name="ClientCity"  value="<?php echo $ClientCity?>"   /></td>
  </tr>

  <tr>
    <th>Contact Person</th>
    <td><input type="text" style="width:auto" name="ContactPerson"  value="<?php echo $ContactPerson?>"   /></td>
    <th>Mob. No</th>
    <td><input type="text" style="width:auto" name="MobileNo"  value="<?php echo $MobileNo?>"   /></td>
    <th>Off. No.</th>
    <td><input type="text" style="width:auto" name="OfficeNo"   value="<?php echo $OfficeNo?>" /></td>
  </tr>
  <tr>
    <th>Email</th>
    <td><input type="text" style="width:auto" name="Email"  value="<?php echo $Email?>"   /></td>
    <th>Website</th>
    <td><input type="text" style="width:auto"  name="Website"  value="<?php echo $Website?>"   /></td>
    <th>Meeting Type</th>
    <td>
    	<select style="width:107px;" name="MeetingType">
			<option value="0">--Select--</option>
			<option value="S"<?php echo ($MeetingType =='S' ? 'selected':'')?>>Successful</option>
			<option value="C"<?php echo ($MeetingType =='C' ? 'selected':'')?>>Cold</option>
			<option value="H"<?php echo ($MeetingType =='H' ? 'selected':'')?>>Hot</option>
	
	</select>
    	
    	
    	
			
	
	</td>
  </tr>
  <tr>
    <th>Purpose Assigned</th>
    <td colspan="5"><input type="text" style="width:310px;" name="PurposeAssigned"  value="<?php echo $PurposeAssigned?>"   /></td>
  </tr>
	<tr>
    <th>Meeting Description</th>
    <td colspan="5"><input type="text" style="width:310px;"  name="MeetingDes"  value="<?php echo  $MeetingDes?>"  /></td>
	</tr>

</table>
	</div><!--Table 2 Start -->
<div style="clear:both;"></div>
	<!--Table 1 Start --><div style="width:650px;">
	<h3>Expense Information</h3>
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <th>From</th>
    <td><input type="text" style="width:auto;"  class="datepicker" name="ExpenseFrom"  value="<?php echo $ExpenseFrom?>"   />
</td>
    <th>To</th>
    <td><input type="text" style="width:auto;" class="datepicker"  name="ExpenseTo"   value="<?php echo  $ExpenseTo?>"   /></td>
    <th>Mode</th>
    <td>
    	
    	<select style="width:107px;" name="Mode">
			<option value="0">--Select--</option>
			<option value="B"<?php echo ($Mode =='B' ? 'selected':'')?>>Bus</option>
			<option value="T"<?php echo ($Mode =='T' ? 'selected':'')?> >Train</option>
			<option value="BI"<?php echo ($Mode =='BI' ? 'selected':'')?>>Bike</option>
	
	</select>
			
	
	</td>
  </tr>

  <tr>
    <th>Total Km</th>
    <td><input type="text" name="KM" id="KM" style="width:auto;"    value="<?php echo $TotalKM ?>"  /></td>
    <th>Rate/Unit</th>
    <td><input type="text" style="width:auto;" name="Rate" id="Rate"  value="<?php echo $Rate?>"   /></td>
    <th>Total Ta</th>
    <td><input type="text" style="width:auto;" id="TotalTA"  name="TotalTA" value="<?php echo $TotalTA?>"  onfocus="Cal_TotalTA();"  /></td>
  </tr>
  <tr>
    <th>Fooding</th>
    <td><input type="text" style="width:auto;"  name="Fooding"  id="Fooding"   value="<?php echo $Fooding?>"  /></td>
    <th>Other Charges</th>
    <td><input type="text" style="width:auto;" name="OtherCharges" id="OtherCharges"  value="<?php echo $OtherCharges?>"   /></td>
    <th>Total Amt</th>
    <td><input type="text" style="width:auto;" name="TotalAmt" id="TotalAmt"   value="<?php echo $TotalAmt?>"   onfocus="Cal_TotalAmt();"  /></td>
  </tr>
  <tr>
    <th>Report To</th>
    <td colspan="2"><input type="text"  name="ReportTo"  value="<?php echo $ReportTo?>" style="width:200px;" >
			
	
	</td>
    <th>Paid Status</th>
    <td colspan="2">
    	
    	
    	
    	<select  style="width:107px;"  name="PaidStatus" id="PaidStatus">
    	<option value="0">--Select--</option>
    	<option value="Y"<?php echo($PaidStatus=='Y'?'selected':'')?>>Yes</option>
    	<option value="N"<?php echo($PaidStatus=='N'?'selected':'')?>>No</option>
    	</select>
    	</td>
  </tr>
  
  <tr>
    <th>Narration</th>
    <td colspan="2"> <input type="text" style="width:200px;" name="Narration" value="<?php echo $Narration?>"  /></td>
	<td colspan="3"></td>
  </tr>

</table>

	</div><!--Table 2 Start -->

	<div style="clear:both;"></div>

<br />
	
		<input name="save" type="submit" value="Save" class="bottonsview" />&nbsp;&nbsp;&nbsp;		<input name="save" type="submit" value="Cancel" class="bottonsview" />
	</form>

	

</fieldset>
</div>

