<?php class Party
	{
 		 function GetClientIDByLedger($pid)
			{
				global $db;
				$s=new db_query();
				$AccountSql=DB_query("Select vender_client,ledgertype from accountledger where AccountsID='".$pid."'",$db);
				$AccountRes=DB_fetch_array($AccountSql);
				if($AccountRes['ledgertype']=='leads')	{
				$clientids= $s->GetFieldValue('crm_leads',"leadid='".$AccountRes['vender_client']."'  ",'company_name'); 
				 $client_name=$clientids; }
				 else
				  $client_name= $AccountRes['vender_client'] ;
				  return( $client_name);
				
			}
		 
		 //**************************New ONE****************************************************************************
		 function ClientList($uid,$party)
		 {
		 
		 	global $db;
			$s=new db_query();
			$assigned_sites= $s->GetFieldValue('www_users',"id='".$uid."'",'assigned_sites');
 			//echo "Select * from clientmaster where  zone in ($assigned_sites)";
	 	   $client_sql=DB_query("Select * from clientmaster where  site in ('".$_SESSION['AssignedBranch']."')",$db);
		   while($client_row =DB_fetch_array($client_sql)){
		   ?>
		   <option value="<?php echo $client_row['id'];?>"<?php echo($party==$client_row['id']?'selected':'')?>><?php echo $client_row['c_name']?></option>
		   <?php }
		 }
		 
		 //**************************************************************************************************
 			function PartList($party)
			{
 				global $db;
				$s=new db_query();
			 	
				//echo "Select vender_client,AccountsID,AccountName,ledgertype from accountledger where ledgertype in('leads','client')";
					  $client_sql=DB_query("Select vender_client,AccountsID,AccountName,ledgertype from accountledger where ledgertype in('leads','client')",$db);
						  while($client_row=DB_fetch_array($client_sql))
						  {
							 if($client_row['ledgertype']=='client'){
							 $ClientSQL="Select Site,Zone from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site='".$_SESSION['AssignedBranch']."' 
							 and id='".$client_row['vender_client']."' and  Zone in(".$_SESSION['AssignedSites'].") ";
							 }
							 else  if($client_row['ledgertype']=='leads')
							 {
							 $ClientSQL="Select Site,Zone from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site='".$_SESSION['AssignedBranch']."' 
							 and id='".$client_row['AccountName']."' and  Zone in(".$_SESSION['AssignedSites'].") ";
							 }
							  $ClientRes=DB_query($ClientSQL,$db);
							   $rx=DB_fetch_array($ClientRes);
							      
							  if(DB_num_rows($ClientRes)>0)
							  {
						  ?>
							<option value="<?php echo $client_row['AccountsID'];?>"<?php echo($party==$client_row['AccountsID']?'selected':'')?>>
							
							
							<?php  
							if($client_row['ledgertype']=='leads')
							echo $s->GetFieldValue('clientmaster',"id='".$client_row['AccountName']."'",'c_name').$s->GetFieldValue('clientmaster',"id='".$client_row['AccountName']."'",'zone');
							else 
						    echo $client_row['AccountName']."--".$rx['Zone'] ;?></option>
						  <?php }
						  }
						  
			}
			
//********************************************************************************

		
	
	}
	
	$ClassParty=new Party();
	?>
