<?
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_client';

		if(isset($_POST['cilentsubmit'])){
		
			if(isset($_POST['client_name'])){
			$clientname=addslashes($_POST['client_name']);
			}
			
			if(isset($_POST['client_code'])){
			$clientcode=addslashes($_POST['client_code']);
			}	
						
				
				if(isset($_POST['client_address'])){
				$address=addslashes($_POST['client_address']);
				}
		
				if(isset($_POST['client_phoneno'])){
				$phoneno=addslashes($_POST['client_phoneno']);
				}
				
				if(isset($_POST['client_consperson'])){
				$consperson=addslashes($_POST['client_consperson']);
				}
				
				if(isset($_POST['client_tin_no'])){
				$csttinno=addslashes($_POST['client_tin_no']);
				}
								
				$addate = date('Y-m-d');
				
				$sql2 = mysql_query("insert into cf_client (client_name,client_code,client_address,client_phno,client_conper,client_csttinno,client_date,client_type) values ('$clientname','$clientcode','$address','$phoneno','$consperson','$csttinno','$addate','1')");
				
				$lastid = mysql_insert_id();
			
				$ledgername=$clientname.'_'.$lastid;
			
				mysql_query("insert into cf_ledger (ledgername,ledgertype,empid,groupid,ledger_start_date) values('$ledgername','clientledger','$lastid','22','".date('Y-m-d')."')");	
			$lederid = mysql_insert_id();	
				
			mysql_query("insert into cf_accountsreceivable(clientid,ledgerid) values('$lastid','$lederid')");					
			
			header("location:client-list.php");
}
			
			
			
			$clientcode='';
			$clientname= '';			
			$cont_person= '';
			$clientphno= '';				
			$client_address='';
			$client_tinno= '';
		
		if(empty($_REQUEST['clientid']))
		{
		$sqlclientauto = mysql_query("select max(client_code) as clientnewcode from cf_client");	
		$rows5 = mysql_fetch_array($sqlclientauto);	
		$clientautos =  $rows5['clientnewcode'];
		$newclientno = $clientautos + 1;	
		}
			
		if(isset($_REQUEST['clientid'])){
			
				$id=$_REQUEST['clientid'];
				$tablename='cf_client';
				$sqlObj->tablename="cf_client";
				$condition=" where 	client_id='$id'";
				$sqlObj->condition=$condition;
				$sqlObj->fieldvalue="*";
				$fieldvalue=$sqlObj->fieldvalue;
				$sql=$sqlObj->SelectTable();
				$clientname= $sql['client_name'];
				$newclientno= $sql['client_code'];
				$client_address= $sql['client_address'];
				$clientphno= $sql['client_phno'];
				$cont_person= $sql['client_conper'];
				$client_tinno= $sql['client_csttinno'];
				//$newclientno =  $sql['clientnewcode'];
				
				
				
				if(isset($_POST['client_name'])){
				$clientname=addslashes($_POST['client_name']);
				}			
				
				if(isset($_POST['client_address'])){
				$client_address=addslashes($_POST['client_address']);
				}
				
				if(isset($_POST['client_phoneno'])){
				$phoneno=addslashes($_POST['client_phoneno']);
				}	
				
				if(isset($_POST['client_consperson'])){
				$cont_person=addslashes($_POST['client_consperson']);
				}	
				
				if(isset($_POST['client_tin_no'])){
				$client_tinno=addslashes($_POST['client_tin_no']);
				}
				
				
				
			
				$sqlObj->tablename=$tablename;
				if(isset($_POST['client_name']))
				{
					$result=mysql_query("update cf_client
 set client_name ='$clientname',client_conper='$cont_person',client_address ='$client_address',client_phno='$phoneno',client_csttinno='$client_tinno' where client_id ='$id'");
 
 					//$ledgername=$clientname.'_'.$id;
 					//mysql_query("update cf_ledger set  ledgername='$ledgername' where empid=$id and ledgertype = 'clientledger' ");	
					
					/*$sqlclientchk = mysql_query("select* from cf_accountsreceivable where clientid =  $id");	
					if(mysql_num_rows(sqlclientchk)==0)
					{
						$sqlledger = mysql_query("select* from cf_ledger where empid=$id and ledgertype = 'clientledger'");	
						$rws = mysql_fetch_array($sqlledger);
						$ledgerIDs = $rws['ledgerid'];
						mysql_query("insert into cf_accountsreceivable(clientid,ledgerid) values('$id','$ledgerIDs')");		
					}*/
					
					//$ledgername=$clientname.'_'.$id;
			
					//mysql_query("insert into cf_ledger (ledgername,ledgertype,empid,groupid,ledger_start_date) values('$ledgername','clientledger','$id','22','".date('Y-m-d')."')");	
					//$lederid = mysql_insert_id();	
				
					//mysql_query("insert into cf_accountsreceivable(clientid,ledgerid) values('$id','$lederid')");	
					
					
					header("location:client-list.php");
				}
						
			}
			
			
		
		/*if(empty($_REQUEST['clientid']))
		{
		$sqlclientauto = mysql_query("select max(client_code) as clientnewcode from cf_client");	
		$rows5 = mysql_fetch_array($sqlclientauto);	
		$clientautos =  $rows5['clientnewcode'];
		$newclientno = $clientautos + 1;	
		}
		else
		{
			$clientid = $_REQUEST['clientid'];
			$sqlclientauto = mysql_query("select max(client_code) as clientnewcode from cf_client where client_id =  $clientid");	
			$rows5 = mysql_fetch_array($sqlclientauto);	
			$newclientno =  $rows5['clientnewcode'];
		}*/
			
			


?>
<!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 Client </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">Client Code<span style="color:#FF3300">*</span></p>
         <input type="text" name="client_code" class="input1 input3" value="<?=$newclientno?>" readonly="readonly"  >
         </div>
            
       <div>     
            <p class="input1">Client Name<span style="color:#FF3300">*</span></p>
            <input type="text" name="client_name" class="input1 input3" value="<?=$clientname?>"  >
       </div>
       
       <div>     
            <p class="input1">Contact Person<span style="color:#FF3300">*</span></p><input type="text" name="client_consperson" class="input1 input3" value="<?=$cont_person?>"  >
       </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="client_phoneno" class="input1 input3" value="<?=$clientphno?>" >
           </div>  
             
            
           <div>     
      			<p class="input1">Address</p><textarea name="client_address" class="input1"><?=$client_address?></textarea>
     	   </div>
           
           
           <div>     
      			<p class="input1">Tin No<span style="color:#FF3300">*</span></p>
                <input type="text" name="client_tin_no" class="input1 input3" value="<?=$client_tinno?>" >
           </div>   
           <div>
            &nbsp;
            </div>
            </div></td>
          </tr>
           <tr>
            <td colspan="2"><div class="searchField1">
        
           <?php
	 	if(isset($_REQUEST['clientid'])){
	  ?>
      <input name="edit" type="submit" class="input1" value="Edit" onClick="return validation();"/>
      <?php }else { ?>
     <input name="cilentsubmit" 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>


		






