<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

$tablename='cf_reseller';

		if(isset($_REQUEST['save'])){
			if(isset($_POST['vendor_code'])){
			$vendorcode=addslashes($_POST['vendor_code']);
			}
			
			if(isset($_POST['vendor_name'])){
			$vendorname=addslashes($_POST['vendor_name']);
			}
			
			if(isset($_POST['consperson'])){
			$consperson=addslashes($_POST['consperson']);
			}
			
			if(isset($_POST['address'])){
			$address=addslashes($_POST['address']);
			}
			
			if(isset($_POST['phoneno'])){
			$phoneno=addslashes($_POST['phoneno']);
			}
			
			if(isset($_POST['tin_no'])){
			$tino=addslashes($_POST['tin_no']);
			}
			
			$addate = date('Y-m-d');
			
			$sqlObj->tablename=$tablename;
			//if($clientsubid!=''){
			$sqlObj->fieldname='(re_code,res_name,re_consperson,re_contactno,re_address,re_tino,re_addate,re_type)';
			$sqlObj->fieldvalue='"'.$vendorcode.'","'.$vendorname.'","'.$consperson.'","'.$phoneno.'","'.$address.'","'.$tino.'","'.$addate.'",2';
			
			$qsy= "insert into ".$tablename.$sqlObj->fieldname." values(".$sqlObj->fieldvalue.")";
									
			$CreateClient 	= mysql_query($qsy);
			
			$lastid = mysql_insert_id();
			
			$ledgername=$vendorname.'_'.$lastid;
			
			mysql_query("insert into cf_ledger (ledgername,ledgertype,empid,groupid,ledger_start_date) values('$ledgername','vendorledger','$lastid','21','".date('Y-m-d')."')");
			//}
			
			$lederid = mysql_insert_id();
			
			mysql_query("insert into cf_acountspayable(vendorid,ledgerid) values('$lastid','$lederid')");
			
			header("location:other-reseller-list.php?page=$page");
			
}

			$clientid= '';
			$res_name= '';
			$re_consperson= '';
			$re_location= '';
			$re_address= '';
			$re_phoneno= '';
			$ven_code='';
			$getdistrictid=array();
			if(isset($_REQUEST['resellerid'])){
			
				$id=$_REQUEST['resellerid'];
				$tablename='cf_reseller';
				$sqlObj->tablename="cf_reseller";
				$condition=" where 	reseller_id='$id'";
				$sqlObj->condition=$condition;
				$sqlObj->fieldvalue="*";
				$fieldvalue=$sqlObj->fieldvalue;
				$sql=$sqlObj->SelectTable();
				$res_name= $sql['res_name'];
				$re_consperson= $sql['re_consperson'];
				$re_address= $sql['re_address'];
				$re_phoneno= $sql['re_contactno'];
				$re_phoneno= $sql['re_contactno'];
				$ven_code= $sql['re_code'];
							
				
				if(isset($_POST['vendor_name'])){
				$vendorname=addslashes($_POST['vendor_name']);
				}			
				
				if(isset($_POST['consperson'])){
				$consperson=addslashes($_POST['consperson']);
				}
				
				if(isset($_POST['address'])){
				$address=addslashes($_POST['address']);
				}
				
				if(isset($_POST['phoneno'])){
				$phoneno=addslashes($_POST['phoneno']);
				}
				
				if(isset($_POST['tin_no'])){
				$tino=addslashes($_POST['tin_no']);
				}
			
				$sqlObj->tablename=$tablename;
				if(isset($_POST['vendor_code']))
				{
					$result=mysql_query("update cf_reseller set res_name ='$vendorname',re_consperson='$consperson',re_address ='$address',re_contactno='$phoneno',re_tino='$tino' where reseller_id ='$id'");
					
					
				//$ledgername=$vendorname.'_'.$id;
			
				//mysql_query("insert into cf_ledger (ledgername,ledgertype,empid,groupid,ledger_start_date) values('$ledgername','vendorledger','$id','21','".date('Y-m-d')."')");
				
				
				//$lederid = mysql_insert_id();
				
				//mysql_query("insert into cf_acountspayable(vendorid,ledgerid) values('$id','$lederid')");
					header("location:other-reseller-list.php");
				}
						
			}
		


?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>




<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function validation(){
if(document.frmname.clientid.value==''){
alert("Select the Client name");
document.frmname.clientid.focus();
return false;
}
if(document.frmname.resellername.value==''){
alert("Enter the Reseller name");
document.frmname.resellername.focus();
return false;
}
if(document.frmname.consperson.value==''){
alert("Enter the Concerned Person");
document.frmname.consperson.focus();
return false;
}

if(document.frmname.locationid.value==''){
alert("Enter the location");
document.frmname.locationid.focus();
return false;
}

if(document.frmname.phoneno.value==''){
alert("Enter the Phone No");
document.frmname.phoneno.focus();
return false;
}



/*var cnt=document.getElementById('divcnt').value;chasisnum1 enginenum1
for(i=1;i<=cnt;i++){alert(document.getElementById('vehiclenum'+i).value);
if(document.getElementById('vehiclenum'+i)){
if(document.getElementById('vehiclenum'+i).value==''){
alert("Enter the Vehicle Number");
document.getElementById('vehiclenum'+i).focus();
return false;
}
}
}*/
}
</script>


<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}
</style>
</head>

<body>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
 <div class="tabbedArea">
  
  <div class="tabBody">
   <h1>Add Other Vendor</h1>
   <form name="frmname" method="post" action="">
   <div class="addEmp" style="margin-bottom:0px; border-bottom:0px solid;width:1000px;">
        <table width="70%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td valign="top">
           
            <div class="form1">
            
          <div  class="select1">
             <p class="input1">Vendor Code<span style="color:#FF3300">*</span></p>
             <input type="text" name="vendor_code" class="input1 input3" value="<?=$ven_code?>"  >
             </div>
            
           <div>     
      			<p class="input1">Vendor Name<span style="color:#FF3300">*</span></p>
      			<input type="text" name="vendor_name" class="input1 input3" value="<?=$res_name?>"  >
     	   </div>
           
           <div>     
      			<p class="input1">Contact Person<span style="color:#FF3300">*</span></p><input type="text" name="consperson" class="input1 input3" value="<?=$re_consperson?>"  >
     	   </div>
           
           
     
            
          </div>
        </td>
            <td valign="top"><div class="form1">
             
         <div>     
      			<p class="input1">Contact Ph<span style="color:#FF3300">*</span></p>
                <input type="text" name="phoneno" class="input1 input3" value="<?=$re_phoneno?>" >
           </div>  
             
            
           <div>     
      			<p class="input1">Address</p><textarea name="address" class="input1"><?=$re_address?></textarea>
     	   </div>
           
           
           <div>     
      			<p class="input1">Tin No<span style="color:#FF3300">*</span></p>
                <input type="text" name="tin_no" class="input1 input3" value="<?=$re_phoneno?>" >
           </div>   
           <div>
            &nbsp;
            </div>
            </div></td>
          </tr>
           <tr>
            <td colspan="2"><div class="searchField1">
        
           <?php
	 	if(isset($_REQUEST['resellerid'])){
	  ?>
      <input name="edit" type="submit" class="input1" value="Edit" onClick="return validation();"/>
      <?php }else { ?>
     <input name="save" type="submit" class="input1" value="Save" onClick="return validation();"/>
     <?php } ?>

         <input type="button" class="input1" value="Cancel" >
        </div>
        </td>
          </tr>
        </table>
 

<div class="mand"><p>Fields marked <span style="color:#FF3300">*</span> are Mandatory</p></div>
</div>
   </form>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>


		






