<?php 
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************
error_reporting(0);
include('functions.php');
include('Class_PickListEditor.php');
$s=new db_query();
global $db;
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');		 
$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($LowerDeptList);
$lowerlist[]=$_SESSION['UserID'];
if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist) ;
else
$lowerlist="'".$_SESSION['UserID']."'";
$user_ids1	=$lowerlist;
$id1=array();
//echo $user_ids;
$user_id = $_SESSION['ACG_DashBoard_User'];
//error_reporting(0);
//include('Class_PickListEditor.php');


if($_REQUEST['leadid'])
{
	
	$GetleadSQL=DB_query("select * from crm_leads where leadid='".$_REQUEST['leadid']."'",$db);
	$Getlead=DB_fetch_array($GetleadSQL);
	if(is_numeric($Getlead['company_name']))
	{
		$AccID=$s->GetFieldValue('accountledger',"AccountName='".$Getlead['company_name']."'",'AccountsID');
		$cond2="leadid='".$_REQUEST['leadid']."'";
		$datalead['Convert_AccountId']=$AccID;
		$datalead['Convert_IntoAccountStatus']='Y';
		$s->RecordEdit('crm_leads', $datalead,$cond2);
	}
$s->pageLocation("index.php?route=CRM/ViewAccounts".$rurl);
}







?>
<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Account Management</h1>
<div class="centre" id="slidingDiv">
<form action="" method="post" name="myform" >
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1">Search for:</td>
	<td><input name="searchtext" type="text"  /></td>
    <td class="tabledata1">In:</td>
	<td>
	<?php $lstatus=array('Account Code','Account Name');?>
	<select name="account_type"  style="width:150px;">
		<option value="0">--Select--</option>
	<?php for($k=0;$k<count($lstatus);$k++)
	{?>
	<option value="<?php  echo $lstatus[$k];?>" <?php  echo $lead_status==$lstatus[$k]?'selected':''?> ><?php  echo $lstatus[$k];?></option>
	<?php 
	}
	?>
	</select></td>
</tr>
<tr class="row1">
	<td colspan="4"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
</tr>
</table>
</form>

</div>
<?php $catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
 $table="crm_leads";?>
<script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}
</script>
<form action="" method="post" name="myform" >
<p align="left">
<?php if($_SESSION['frmAdd']==0){ ?> 
<input type="button" value="Create New Account" alt="Not Allowed" title="Not Allowed" class="search" />
<?php }else{?>
<a href="index.php?route=CRM/CreatenewAccount<?php echo $rurl; ?>"><input type="button" value="Create New Account" class="search" /></a>
<?php }?>
</p>

<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
  	<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"  />  </td>
	<td class="tabledata">Account No</td>
	<td class="tabledata">Account Name</td>
	<td class="tabledata">Contact Person Name</td>
	<td class="tabledata">Email</td>
	<td class="tabledata">Mobile</td>
	<td class="tabledata">Phone</td>
</tr>
<?php $i=1;
//*******OLD QUERY********echo "select * from crm_leads where (created_by IN(".$lowerlist.") OR FIND_IN_SET('$user_id',leaduserid)) and  deleted_status='N' and Convert_IntoAccountStatus='Y' and CompanyId='".$_SESSION['ACGCompanyId']."' and leadid not in(SELECT enquiryNo FROM quotation )";

$getlead=DB_query("select * from crm_leads where created_by IN(".$lowerlist.") and  deleted_status='N' and Convert_IntoAccountStatus='Y' and CompanyId='".$_SESSION['ACGCompanyId']."' AND Quotes_Status='N'",$db);
$DirSQL=DB_query("select * from crm_accounts_new",$db);
while($row_lead=DB_fetch_array($getlead)){?>
    <tr bgcolor="#dfdfdf">
    <td>
   <input name="leadid[]" type="checkbox" id="leadid_<?php echo $i; ?>"   value="<?php  echo $row_lead['leadid']?>" />
<!-- <a href="index.php?route=CRM/ConvertINToAccount&action=Edit&&AccountId=<?php echo $row_lead['Convert_AccountId']?>&leadid=<?php echo $row_lead['leadid'].$rurl;?>">
  <img src="images/icon_edit.gif" width="10px"  height="10" /></a></td>-->
<?php if($_SESSION['frmView']==0){ ?>
  <img src="images/search.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="10" />
   <?php }else{ ?>
   <a href="index.php?route=CRM/LeadView&action=View&leadid=<?php echo $row_lead['leadid'].$rurl;?>">
  <img src="images/search.gif" width="10px"  height="10" /></a>
   
   <?php } ?>
  </td>

	
	<td><?php  echo $s->GetFieldValue('clientmaster',"id='".$row_lead['company_name']."'",'client_code');?></td>
	<td><?php  echo $s->GetFieldValue('clientmaster',"id='".$row_lead['company_name']."'",'c_name'); ?></td>
	<td><?php  echo $s->GetFieldValue('contact_information_master',"master_code='".$row_lead['company_name']."'",'person');?></td>
	<td><?php  echo  $s->GetFieldValue('contact_information_master',"master_code='".$row_lead['company_name']."'",'email');?></td>
	<td><?php echo $s->GetFieldValue('contact_information_master',"master_code='".$row_lead['company_name']."'",'phone');?></td>
	<td><?php  echo  $s->GetFieldValue('clientmaster',"id='".$row_lead['company_name']."'",'pre_mobile');?></td>
   </tr>
   <?php $i++; } 

while($DirDetails=DB_fetch_array($DirSQL)){?>
<tr bgcolor="#dfdfdf">
	<td> <input name="leadid[]" type="checkbox" id="leadid_<?php echo $i; ?>"   value="<?php  echo $DirDetails['accid']?>" />
 <!--<a href="index.php?route=CRM/CreatenewAccountEdit&action=Edit&AccID=<?php echo $DirDetails['accid'].$rurl?>">
  <img src="images/icon_edit.gif" width="10px"  height="10" /></a>-->
  <?php if($_SESSION['frmView']==0){ ?>
  <img src="images/search.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="10" />
  <?php }else{ ?>
  <a href="index.php?route=CRM/CreatenewAccountView&action=View&AccID=<?php echo $DirDetails['accid'].$rurl;?>">
  <img src="images/search.gif" width="10px"  height="10" /></a>
  <?php } ?>
  </td>
	<td><?php echo $DirDetails['account_code']; ?></td>
	<td><?php echo $s->GetFieldValue('clientmaster',"id='".$DirDetails['client']."'",'c_name'); ?></td>
	<td><?php echo $DirDetails['contact_person']; ?></td>
	<td><?php echo $DirDetails['email_id']; ?></td>
	<td><?php echo $DirDetails['mobile']; ?></td>
	<td><?php echo $DirDetails['phonno']; ?></td>
</tr>

<?php } ?>
</table>
</form>
</div>
</div>