<?php
$PageSecurity = 1;
include('includes/DefinePaymentClass.php');
$title = _('Invoice');
include('includes/SQL_CommonFunctions.inc');
?>
 <?php 
 if($_REQUEST['Save']&& $_REQUEST['action']=='add')
 {
	$data['salesman_type'] =$_REQUEST['salesman_type'];
	//$data['glcode'] =$_REQUEST['glcode'];
	$data['sales_name'] =$_REQUEST['sales_name'];
	$data['sales_alias_name'] =$_REQUEST['sales_alias_name'];
	$data['branch_name'] =$_REQUEST['branch_name'];
	$data['address'] =$_REQUEST['address'];
	$data['city'] =$_REQUEST['city'];
	$data['state'] =$_REQUEST['state'];
	$data['phone'] =$_REQUEST['phone'];
	$data['email'] =$_REQUEST['email'];
	$data['zipcode'] =$_REQUEST['zipcode'];
	$data['fax'] =$_REQUEST['fax'];
	$data['cellno'] =$_REQUEST['cellno'];
	$data['pan'] =$_REQUEST['pan'];
	$data['rate_of_commision'] =$_REQUEST['rate_of_commision'];
	$data['commision_calculation'] =$_REQUEST['commision_calculation'];
 	$insert_salesman_master=	$s->insertRecord('salesman_master', $data);
 	$insertResult = DB_query($insert_salesman_master,$db,$ErrMsg); 
		if(!$insertResult)
			{
			  die("Not Inserted".DB_error_msg($db));
			}
		$s->pageLocation('index.php?route=View_SalesManMaster&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
   }
   
   
 if($_REQUEST['Save']&& $_REQUEST['action']=='edit')
 {
	$data['salesman_type'] =$_REQUEST['salesman_type'];
	//$data['glcode'] =$_REQUEST['glcode'];
	$data['sales_name'] =$_REQUEST['sales_name'];
	$data['sales_alias_name'] =$_REQUEST['sales_alias_name'];
	$data['branch_name'] =$_REQUEST['branch_name'];
	$data['address'] =$_REQUEST['address'];
	$data['city'] =$_REQUEST['city'];
	$data['state'] =$_REQUEST['state'];
	  $data['phone'] =$_REQUEST['phone'];
	$data['email'] =$_REQUEST['email'];
	$data['zipcode'] =$_REQUEST['zipcode'];
	$data['fax'] =$_REQUEST['fax'];
	$data['cellno'] =$_REQUEST['cellno'];
	$data['pan'] =$_REQUEST['pan'];
	$data['rate_of_commision'] =$_REQUEST['rate_of_commision'];
	$data['commision_calculation'] =$_REQUEST['commision_calculation'];

	$cond="id='".$_REQUEST['id']."'";
 	$update_salesman_master=$s->EditRecord('salesman_master', $data,$cond);
 	$updateResult = DB_query($update_salesman_master,$db,$ErrMsg); 
		if(!$updateResult)
			{
			  die("Not Inserted".DB_error_msg($db));
			}
			$s->pageLocation('index.php?route=View_SalesManMaster&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
   }
   
   else if(!$_REQUEST['Save']&& $_REQUEST['action']=='edit'){
   
   $cond="id='".$_REQUEST['id']."'";
   $GetRecord=$s->GetRecord("salesman_master",$cond);
   $result=DB_query($GetRecord,$db,$ErrMsg); 
   $row=DB_fetch_array($result);
   	$salesman_type=$row['salesman_type'];
	//$glcode=$row['glcode'];
	$sales_name=$row['sales_name'];
	$sales_alias_name=$row['sales_alias_name'];
	$branch_name=$row['branch_name'];
	$address=$row['address'];
	$city=$row['city'];
	$state=$row['state'];
	  $phone=$row['phone'];
   	$email=$row['email'];
	$zipcode=$row['zipcode'];
	$fax=$row['fax'];
	$cellno=$row['cellno'];
	$pan=$row['pan'];
	  $rate_of_commision=$row['rate_of_commision'];
	  $commision_calculation=$row['commision_calculation'];
	  

   
   }
?>
<h2 align="center">SaleExecutive Master</h2>
<form action="" method="post">
<table width="70%" border="0" cellspacing="2" cellpadding="2" align="center" >
<tr>
<td colspan="4" ></td>
</tr>
  <tr>
    <td width="20%"><strong>TYPE</strong></td>
    <td width="26%"> 
	<select name="salesman_type" >
	<option  value="Broker" <?php echo ($salesman_type=='Broker'?"selected":"")?>>Broker</option>
		<option  value="Salesman" <?php echo ($salesman_type=='Salesman'?"selected":"")?>>Salesman</option>
	</select>	 </td>
    <!--<td width="24%">GLCode</td>
    <td width="30%">
	
	<?php
	// 	$SQL_chartmaster=DB_query("SELECT accountname,id   from chartmaster Where 1=1",$db);
	?>
	<select  name="glcode" style="width:140px;" tabindex="1">
	<option >--GLCode--</option>
	<?php /*
	while($row_chartmaster=DB_fetch_array($SQL_chartmaster))
	{
	$p='';
	  if($row_chartmaster['id']==$glcode)
	  $p="selected";
	 ?>
	 <option value="<?php  echo $row_chartmaster['id']?>" <?php echo $p; ?>><?php  echo $row_chartmaster['accountname']?></option>
		 <?php } */?>
	</select>
      </td>-->
  </tr>
  <tr>
    <td><strong>NAME</strong></td>
    <td colspan="3"><input name="sales_name" type="text" value="<?php echo $sales_name ?>">&nbsp;</td>
  </tr>
  <tr>
    <td><strong>ALIAS</strong></td>
    <td  colspan="3"><input name="sales_alias_name" type="text" value="<?php echo $sales_alias_name ?>"></td>
   </tr>
   
   <tr>
   <td ><strong>BRANCH MASTER </strong></td>
      <td colspan="3">
	  
	   <?php 
	$result_location = DB_query("SELECT loccode,locationname FROM  locations  WHERE 1=1",$db);
  			?>
			
			<select name="branch_name" style="width:200px;"   tabindex="1">
			<option value="000">Please Select BranchID Name</option>
			<?php 			
 			while($myrow_location = DB_fetch_row($result_location))
			{
			
			  $p='';
			  if($myrow_location[0]==$branch_name)
			  $p="selected";
			?>
			<option value="<?php echo $myrow_location[0]; ?>" <?php echo $p;?>><?php echo $myrow_location[1]; ?></option>
			<?php }?>
			</select>	  </td>
   </tr>
   
   
    <tr>
   <td><strong>ADDRESS</strong></td>
      <td colspan="3">
	  <textarea name="address" cols="50" rows="2"><?php  echo $address?></textarea>      </td>
   </tr>
    <tr>
      <td height="27"  ><strong>CITY</strong></td>
      <td><input name="city" type="text" value="<?php echo $city ?>"></td>
	    <td><strong>STATE</strong></td>
      <td><input name="state" type="text" value="<?php echo $state ?>"></td>
    </tr>
    <tr>
      <td><strong>PHONE</strong></td>
      <td><input name="phone" type="text" value="<?php echo $phone ?>"></td>
	    <td><strong>ZIPCODE</strong></td>
      <td><input name="zipcode" type="text" value="<?php echo $zipcode ?>"></td>
    </tr>
    <tr>
      <td><strong>E-MAIL</strong></td>
      <td><input name="email" type="text" value="<?php echo $email ?>"></td>
	    <td><strong>FAX</strong></td>
      <td><input name="fax" type="text" value="<?php echo $fax ?>"></td>
    </tr>
 	<tr>
      <td colspan="2"><strong>MOBILE</strong></td>
      <td  colspan="2"><input name="cellno" type="text" value="<?php echo $cellno ?>"></td>
    </tr>
    <tr>
      <td colspan="2"><strong>PAN</strong></td>
      <td  colspan="2"><input name="pan" type="text" value="<?php echo $pan ?>"></td>
    </tr>
	  <tr>
      <td><strong>RATE OF COMMISSION </strong></td>
      <td><input name="rate_of_commision" type="text" value="<?php echo $rate_of_commision ?>"></td>
	   <td><strong>COMMISSION COLUMN </strong></td>
	   <td><input name="commision_calculation" type="radio"  value="Quantity"<?php echo ($commision_calculation=='Quantity'?"checked":"") ?>>
	     Quantity
	   <input name="commision_calculation" type="radio"  value="Amount" <?php echo ($commision_calculation=='Amount'?"checked":"") ?>>
	   Amount </td>
    </tr>
	  <tr>
	    <td>&nbsp;</td>
	    <td>&nbsp;</td>
	    <td> 
	      <input type="submit" name="Save" value="<?php echo ucfirst($_REQUEST['action'])?>"> 	    </td>
	    <td>&nbsp;</td>
  </tr>
</table>
</form>
<?php
include('includes/footer.inc');
?>