<?php  
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************

include('Class_PickListEditor.php');
include("Class_Branch.php");
include("ClassRole.php");?>
<script type="text/javascript">
function ship_data()
{
var billing_add=document.getElementById("address1").value;
var e=document.getElementById("country");
var billing_country=e.options[e.selectedIndex].text;
var f=document.getElementById("state");
var state=f.options[f.selectedIndex].text;
var g=document.getElementById("city");
var city=g.options[g.selectedIndex].text;
var zipcode=document.getElementById("zipcode").value;
document.getElementById("Shipping_address").value=billing_add;
document.getElementById("Shipping_country").value=billing_country;
document.getElementById("Shipping_state").value=state;
document.getElementById("Shipping_city").value=city;
document.getElementById("Shipping_zipcode").value=zipcode;
}
</script>
<?php 
if($_REQUEST['Submit'] && $_REQUEST['action']!='Edit')
{
$datax['client_code']="AC-".$_REQUEST['AccountName'];
$datax['Zone']=$_REQUEST['Zone'];
$datax['pre_country']=$_REQUEST['country'];
$datax['pre_address1']=$_REQUEST['address1'];
$datax['pre_state']=$_REQUEST['state'];
$datax['pre_city']=$_REQUEST['city'];
$datax['pre_pincode']=$_REQUEST['zipcode'];
$cond2="id='".$_REQUEST['AccountName']."'";
$row3= $s->RecordEdit('clientmaster', $datax,$cond2);
//	       $chk_clientmst=$s->GetNumRecord('clientmaster',"id='".$_REQUEST['AccountName']."'");
$data['ledgertype']='leads';
$data['UnderGroup']=$s->GetFieldValue('accountgroupmaster',"GroupName='Sundry Creditor'  ",'GroupId');
$data['AccountName']=$_REQUEST['AccountName'];
$data['CompanyId']=$_SESSION['ACGCompanyId'];
$data['vender_client']=$_REQUEST['leadid'];
$chkaccountledger=$s->GetFieldValue('accountledger',"lower(AccountName)='".strtolower($_REQUEST['AccountName'])."'  or vender_client='".$_REQUEST['AccountName']."' ",'AccountsID');
//echo $_REQUEST['AccountName'];
//	echo		$s->GetLastRecord('accountledger',"lower(AccountName)='".strtolower($_REQUEST['AccountName'])."'",'AccountsID');
if($chkaccountledger==''){
$row= $s->RecordInsert('accountledger', $data);
$lastid=DB_Last_Insert_ID($db,'accountledger', 'AccountsID');
}else{
$lastid=$chkaccountledger;
}
$data_address['account_code']=$_REQUEST['branch'].'/Account-'.$lastid;
$data_address['mst_leadid']=$_REQUEST['leadid'];
$data_address['mst_accoutledgerid']=$lastid;
$data_address['groupid']=trim(implode(',',$_REQUEST['groupid']));
$data_address['address1']=$_REQUEST['address1'];
$data_address['country']=$_REQUEST['country'];
$data_address['Shipping_country']=$_REQUEST['Shipping_country'];
$data_address['Shipping_state']=$_REQUEST['Shipping_state'];
$data_address['state']=$_REQUEST['state'];
$data_address['city']=$_REQUEST['city'];
$data_address['zipcode']=$_REQUEST['zipcode'];
$data_address['Shipping_address']=$_REQUEST['Shipping_address'];
$data_address['Shipping_city']=$_REQUEST['Shipping_city'];
$data_address['Shipping_zipcode']=$_REQUEST['Shipping_zipcode'];
$data_address['description']=$_REQUEST['description'];						
$data_address['created_by']=trim($_SESSION['UserID']);;			
$data_address['created_date']=date('Y-m-d');									
$data_address['CompanyId']=trim($_SESSION['ACGCompanyId']);
$row= $s->RecordInsert('crm_accounts', $data_address);
$data1['Convert_IntoAccountStatus']='Y';
$data1['Convert_AccountId']=$lastid;
$cond="leadid='".$_REQUEST['leadid']."'";
$row= $s->RecordEdit('crm_leads', $data1,$cond);
$s->pageLocation("index.php?route=CRM/ViewAccounts".$rurl);
}

if($_REQUEST['Submit'] && $_REQUEST['action']=='Edit')
{
$datax['client_code']="AC-".$_REQUEST['AccountName'];
$datax['Zone']=$_REQUEST['Zone'];
$datax['pre_country']=$_REQUEST['country'];
$datax['pre_address1']=$_REQUEST['address1'];
$datax['pre_state']=$_REQUEST['state'];
$datax['pre_city']=$_REQUEST['city'];
$datax['pre_pincode']=$_REQUEST['zipcode'];
$cond2="id='".$_REQUEST['AccountName']."'";
$row3= $s->RecordEdit('clientmaster', $datax,$cond2);
$data_address['account_code']=$_REQUEST['branch'].'/Account-'.$_REQUEST['AccountId'];
$data_address['groupid']=trim(implode(',',$_REQUEST['groupid']));
$data_address['address1']=$_REQUEST['address1'];
$data_address['city']=$_REQUEST['city'];
$data_address['state']=$_REQUEST['state'];
$data_address['zipcode']=$_REQUEST['zipcode'];
$data_address['country']=$_REQUEST['country'];
$data_address['Shipping_address']=$_REQUEST['Shipping_address'];
$data_address['Shipping_state']=$_REQUEST['Shipping_state'];
$data_address['Shipping_city']=$_REQUEST['Shipping_city'];
$data_address['Shipping_zipcode']=$_REQUEST['Shipping_zipcode'];
$data_address['Shipping_country']=$_REQUEST['Shipping_country'];
$data_address['description']=$_REQUEST['description'];						
$data_address['created_by']=trim($_SESSION['UserID']);;			
$data_address['created_date']=date('Y-m-d');		
$cond="mst_leadid='".$_REQUEST['leadid']."' and mst_accoutledgerid='".$_REQUEST['AccountId']."'";
$row= $s->RecordEdit('crm_accounts', $data_address,$cond);
$s->pageLocation("index.php?route=CRM/ViewAccounts".$rurl);
}
		
if(isset($_REQUEST['AccountId']) && $_REQUEST['leadid'])
{

	$getlead=DB_query( "select A.*,B.company_name as company_name from crm_accounts A,crm_leads B  where A.mst_leadid='".$_REQUEST['leadid']."' and A.mst_accoutledgerid ='".$_REQUEST['AccountId']."' and A.mst_leadid=B.leadid",$db);
	while($row_lead=DB_fetch_array($getlead))
	{
	$leadcode=$row_lead['leadcode'];
	$company_name=$row_lead['company_name'];
	$address1=$row_lead['address1'];
	$groupid=$row_lead['groupid'];
	$city=$row_lead['city'];
	$zipcode=$row_lead['zipcode'];
	$country=$row_lead['country'];
	$state=$row_lead['state'];
	$Shipping_address=$row_lead['Shipping_address'];
	$Shipping_zipcode=$row_lead['Shipping_zipcode'];
	$Shipping_state=$row_lead['Shipping_state'];
	$Shipping_city=$row_lead['Shipping_city'];
	$Shipping_country=$row_lead['Shipping_country'];
	$Zone=$s->GetFieldValue('clientmaster',"id='".$company_name."'" ,'Zone');
	}
}
else if($_REQUEST['leadid'] )
{echo "Hii";
	echo "select * from crm_leads where leadid='".$_REQUEST['leadid']."'";
	$getlead=DB_query( "select * from crm_leads where leadid='".$_REQUEST['leadid']."'",$db);
	$row_lead=DB_fetch_array($getlead);
	$leadcode=$row_lead['leadcode'];
	$company_name=$row_lead['company_name'];
	$contact_name=$row_lead['contact_name'];
	$address1=$row_lead['address1'];
	$city=$row_lead['city'];
	$groupid=$row_lead['groupid'];
	$zipcode=$row_lead['zipcode'];
	$country=$row_lead['country'];
	$state=$row_lead['state'];
	$Shipping_address=$row_lead['Shipping_address'];
	$Shipping_zipcode=$row_lead['Shipping_zipcode'];
	$Shipping_city=$row_lead['Shipping_city'];
	$Shipping_country=$row_lead['Shipping_country'];
	echo $company_name;
	 $Zone=$s->GetFieldValue('clientmaster',"c_name='".$company_name."'" ,'Zone');
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Convert Into Account</h1>		
<form name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1">Account Name </td>
    <td width="77%"><input name="branch" type="hidden" value="<?php echo substr($leadcode,0,3);?>" />
<?php 	echo $s->GetFieldValue('clientmaster',"id='".$s->GetFieldValue('crm_leads',"leadid='".$_REQUEST['leadid']."' ",'company_name')."'",'c_name');
$client_site=$s->GetFieldValue('clientmaster',"id='".$s->GetFieldValue('crm_leads',"leadid='".$_REQUEST['leadid']."' ",'company_name')."' ",'Site');
?>
<input name="AccountName" type="hidden" value="<?php echo $s->GetFieldValue('crm_leads',"leadid='".$_REQUEST['leadid']."' ",'company_name');?>" size="40"></td>
</tr>
     <tr class="row1">
    <td class="tabledata1">Groups Name</td>
    <td width="29%"><?php echo $ClassRole->Role($groupid);?>	 </td> 
</tr>
     <tr class="row1">
   <td class="tabledata1">Zone</td>
    <td width="29%">	<?php //echo  $Zone; ?>
	<select name="Zone" id="Zone"   style="width:150px;" />
    <option value="0">--Select--</option>
    <?php echo $sql="Select * from zone_master where CompanyId='".$_SESSION['ACGCompanyId']."' and  status='Y' and Site='".$client_site."'";
	     $result_zone=DB_query($sql,$db);
	     while($rowdata=DB_fetch_array($result_zone)){?>
		<option value="<?php echo $rowdata['id']?>"<?php echo ( $Zone== $rowdata['id'])?'selected':'';?>><?php echo $rowdata['ZoneTitle'];?></option>
		<?php }?>
    </select></td> 
</tr>
 <tr class="row1"><td colspan="2">   
 
  
<?php /*?>
<br />
 <h1>Account  Billing  &  shipping  Address  Information:-</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
	<tr class="row1">
  	<td></td>
  		<td>
  		</td>
	<td>
		<input type="checkbox" name="shipping_data" id="shipping_data" onclick="ship_data()">
		</td><td>
  		</td>
</tr>   
  <tr class="row1">
    <td class="tabledata1">Billing Address</td>
    <td width="25%" nowrap="nowrap">
    <input type="text" name="address1" style="width:150px;" id="address1"  value="<?php  echo $address1;?>"/></td>
    <td class="tabledata1">Shipping Address</td>
    <td width="25%" id="CODE">
    <input type="text" id="Shipping_address" name="Shipping_address" style="width:150px;"   value="<?php echo $Shipping_address?>"/></td>
  </tr>
 <tr class="row1">
    <td class="tabledata1">Billing Country</td>
    <td nowrap="nowrap"> 
	<select name="country" id="country" onchange="ShowDiv(this.value,'state_id','emp_state.php')" style="width:150px;" />
    <option value="0">--Select--</option>
    <?php
    $country_sql="Select * from country_master";
	$country_res=DB_query($country_sql,$db);
	while($country_row=DB_fetch_array($country_res))
	{
 		?>
		<option value="<?php echo $country_row['id']?>"<?php echo ($country== $country_row['id'])?'selected':'';?>><?php echo $country_row['country'];?></option>
		<?php
}
    ?>
    
    </select></td>
    <td class="tabledata1">Shipping Country</td>
    <td>
    
    	
    	<input name="Shipping_country" id="Shipping_country" type="text"  style="width:150px;" value="<?php  echo $Shipping_country?>"/></td>
    </tr>
   <tr class="row1">
    <td class="tabledata1">Billing State</td>
    <td nowrap="nowrap">
    	<div id="state_id"><select name="state"  onchange="ShowDiv(this.value,'show_city','emp_city.php')" id="state" style="width:150px;" >
    <option value="o">---Select---</option>
  <?php 
  
 $state_sql=DB_query("select * from state_master where id='".$state."'",$db);
  while($state_row=DB_fetch_array($state_sql))
  {
  ?>
  <option value="<?php echo $state_row['id'];?>"<?php echo($state==$state_row['id'])?'selected':'';?>><?php echo $state_row['state'];?></option>
   <?php } ?>
  </select>
    		</div>
    	</td>
    <td class="tabledata1">Shipping State</td>
    <td nowrap="nowrap"><input name="Shipping_state"  id="Shipping_state" type="text" value="<?php echo $Shipping_state;?>"  style="width:150px;"/></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Billing city</td>
    <td nowrap="nowrap"> <div id='show_city'>
    	 	<select name="city"  id="city" style="width:150px;" >
    <option value="0">Select</option>
    <?php
    $city_sql=DB_query("select * from city_master where state='".$state."'",$db);
     while($city_row=DB_fetch_array($city_sql))
    {
  ?>
    <option value="<?php echo $city_row['id'];?>"<?php echo($city==$city_row['id'])?'selected':'';?>><?php echo $city_row['city'];?></option>
    <?php } ?>
</select>
    	
    	</div></td>
    <td class="tabledata1">shipping City</td>
    <td nowrap="nowrap"><input name="Shipping_city"  id="Shipping_city" type="text"  style="width:150px;" value="<?php  echo $Shipping_city?>"/></td>
  </tr>
  <tr class="row1">
    <td class="tabledata1">Billing Postal Code</td>
    <td nowrap="nowrap">
    <input type="text" name="zipcode" id="zipcode" style="width:150px;"  value="<?php  echo $zipcode?>" /></td>
    <td class="tabledata1">Shipping Postal Code</td>
    <td><input type="text" name="Shipping_zipcode" id="Shipping_zipcode" style="width:150px;"  value="<?php  echo $Shipping_zipcode?>" /></td>
    </tr>
</table><?php */?>

</td>
 </tr>
  <tr class="row1">
    <td colspan="4">
      <p align="center"><input type="submit" name="Submit" value="Save" class="search"></p>
     </td>
    <td>&nbsp;</td>
  </tr>
</table>
 </form>
</div>
</div>