<?php
/* $Revision: 1.73 $ */
$PageSecurity = 11;
$title = _('Show Client');
include('includes/SQL_CommonFunctions.inc');
if($_GET['action']=='del' && $_GET['id'] != '')
{
	$sql = "DELETE FROM clientmaster WHERE id='".$_GET['id']."'";
	$del = DB_query($sql,$db,$ErrMsg,$DbgMsg);
	$get_code=DB_query("Select client_code from clientmaster where id='".$_GET['id']."'",$db);
	$code_res=DB_fetch_array($get_code);
	$sql2 = "DELETE FROM contact_information_master WHERE master_code='".$code_res['client_code']."' and master_prefix='C'";
	$del2 = DB_query($sql2,$db,$ErrMsg,$DbgMsg);
	prnMsg(_('Customer Record has been deleted') ,'success');
	echo "<script>location.href='index.php?route=DealerDistrbutions/Show_client&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>


<script type="text/javascript">
function showSlidingDiv(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 700 });
}
</script>
<style>
#slidingDiv {
    display: none;
	height:130px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<p align="left"><a href="index.php?route=DealerDistrbutions/Client_Master&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="AddNew" value="AddNew"  class="search"/></a></p>
<div class="body_contain">
<div class="tab_div">
<h3 align="center"><strong>Customer Master</strong></h3>

<div align="center"><a href="#" onClick="showSlidingDiv(); return false;"><input type="button" class="search" value="SEARCH" /></a></div>
<div id="slidingDiv" class="centre" >
<form action="" method="post">
<table  width="50%" border="0" cellspacing="1" cellpadding="2" align="center">	
	<tr><td><strong>Site</strong></td>
	<?php
		 $result=DB_query('SELECT locationname, loccode FROM locations', $db);
		  ?>
	   <td><select name="site" style="width:100%">
	   <option value="">select</option>
	   <?php
		while($myrow = DB_fetch_array($result))
		 {
	 	$p='';
		if($_POST['site']==$myrow['loccode'])
		$p="selected";
		 ?>
		<option VALUE="<?php echo $myrow['loccode'];?>"<?php echo $p;?>><?php echo $myrow['locationname'];?></option>
		 <?php }?> 
		</select></td></tr>
	<tr><td><strong>Client Code</strong></td><td><input type="text"  name="vendor_code" style="width:100%"/></td></tr>
	<tr><td><strong>Client Name</strong></td><td><input type="text"  name="vendor_name" style="width:100%"/></td></tr>
	<tr><td><strong>Approved Item</strong></td><td><Select name="item" id="item" style="width:100%">
		<option value="">--Select--</option>
		<?php $itemdata=DB_query("select * from item_master",$db);
		while($itemdata1=DB_fetch_array($itemdata))
		{
			?>
		<option value="<?php echo $itemdata1['id']; ?>"><?php echo $itemdata1['item_name']; ?></option>
		<?php } ?>
		
	</Select></td></tr>
		<tr><td><strong>Country</strong></td><td>
		<Select name="country" id="country" style="width:100%">
		<option value="">--Select--</option>
		<?php $countrydata=DB_query("select * from country_master",$db);
		while($countrydata1=DB_fetch_array($countrydata))
		{
			?>
		<option value="<?php echo $countrydata1['id']; ?>"><?php echo $countrydata1['country']; ?></option>
		<?php } ?>
		
	</Select>
	</td></tr>
	
   </table>
   <p align="center"><input type="submit" name="submit" value="Search" /></p>
  </form>
</div>


<?php	
		if(isset($_POST['Submit']))
			{
				$filter = array();
				$SQL = "select id,client_code,c_name,short_name,ccategory,Store,dealer from clientmaster order by c_name ASC";
				
				if(isset($_POST['code']) && $_POST['code'] != '')
				$filter[]="client_code like '%".$_POST['code']."%' ";
				if(isset($_POST['name']) && $_POST['name'] != '')
				$filter[]="c_name like '%".$_POST['name']."%' ";
				
				if($filter != '')
				{
					$SQL=$SQL." where CompanyId='".$_SESSION['ACGCompanyId']."' and ".implode(" and ",$filter);
				}
		    } 
		else
		{
  		   $SQL="select id, client_code,c_name,Zone,ccategory,Store,cust_cate,dealer from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name ASC";
		}
		//echo "===".$SQL;
		 $PC_OpeningResult = DB_query($SQL,$db);
		
	
	if(isset($_REQUEST['submit']))
	{
		$sql_search='';
		$vendor_code1=$_REQUEST['vendor_code'];
		$vendor_name1=$_REQUEST['vendor_name'];
		$category1=$_REQUEST['category'];
		$site1=$_REQUEST['site'];
		$item=$_REQUEST['item'];
		$country=$_REQUEST['country'];
		if(empty($vendor_code1) && empty($vendor_name1) && empty($category1) && empty($site1) )
		{
		$sql_search = "select id, client_code,c_name,short_name,dealer,ccategory,Store from clientmaster 
		where CompanyId='".$_SESSION['ACGCompanyId']."' ";
		}
		else 
		{
		$sql_search = "select id, client_code,c_name,short_name,dealer,ccategory,Store from clientmaster 
		where CompanyId='".$_SESSION['ACGCompanyId']."' ";
		}
		if(!empty($vendor_code1))
		{
		$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' OR client_code  LIKE '".$vendor_code1."%'";
		} 
		if(!empty($vendor_name1))
		{
		$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' OR c_name LIKE '".$vendor_name1."%'";
		}
		if(!empty($category1))
		{
			$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' OR category LIKE '".$category1."%'";
		}
		if(!empty($site1))
		{
			$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' OR site LIKE '".$site1."%'";
		}
		if(!empty($item))
		{
		$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' AND  assigned_items in ('".$item."')";	
		}
		
		if(!empty($country))
		{
		$sql_search .=" and CompanyId='".$_SESSION['ACGCompanyId']."' AND  pre_country ='".$country."'";	
			
		}
		//echo $sql_search;
			//$search_result = DB_query($sql_search, $db);
			$PC_OpeningResult = DB_query($sql_search,$db);
	}

$i=0;

	?>
	
	
		<table cellpadding="2" cellspacing="2" colspan=7  border="1" width=100%>
		<tr class="row1">
		<td class="tabledata1"><strong>Customer Code</strong></td>
		<td class="tabledata1"><strong>Customer Name</strong></td>
		<td class="tabledata1"><strong>Area</strong></td>
		<td class="tabledata1"><strong>Associate</strong></td>
		<td class="tabledata1"><strong>Category</strong></td>
		<td class="tabledata1" colspan="3"><strong>Action</strong></td>
		</tr><?php 
		$j = 1;
		$k=0; //row colour counter
	   if(DB_num_rows($PC_OpeningResult)>0)
		 {
		while ($res=DB_fetch_array($PC_OpeningResult))
		{
		
		
		$enqiry=$s->GetTotalRecordsTalbes('dbl_enquiry_form',"customer='".$res['id']."'");
		$salsorder=$s->GetTotalRecordsTalbes('dbl_process_sale_order',"customer='".$res['id']."'");
		$dispatch=$s->GetTotalRecordsTalbes('dbl_dealer_dispatch',"customer='".$res['id']."'");
		
		if($enqiry<=0 && $salesorder<=0 && $dispatch<=0)
		{
		$status=0;
		}
		else
		{
		$status=1;
		}
		
		
	
		?>
		<tr class="row1">	
		<td><div align="center"><?php echo $j;?></div></td>
		<td><?php echo $res['c_name'];?></td>
		<td><?php echo $s->GetFieldValue('zone_master',"id='".$res['Zone']."'" ,'ZoneTitle');?></td>
		<td><?php echo $s->GetFieldValue('dbl_dealer',"id='".$res['dealer']."'" ,'dealer_name');?></td>
		<td><?php echo $s->GetFieldValue('customer_category',"id='".$res['cust_cate']."'" ,'cust_cate');?></td>
		<td><a href="index.php?route=DealerDistrbutions/view_client&amp;action=view&amp;id=<?php echo $res['id'];?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif"  width="10" height="10"/></a>&nbsp;<a href="index.php?route=DealerDistrbutions/Client_Master&amp;action=editRec&amp;id=<?php echo $res['id'];?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon-edit.png"  width="10" height="10"/></a>&nbsp;<?php if($status==0) { ?>		
		<a href="index.php?route=DealerDistrbutions/Show_client&amp;action=del&amp;id=<?php echo $res['id'];?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>" onclick="return confirm('This client will be deleted. Are you sure?')"><img src="images/delete1.Gif"  width="10" height="10"/></a>
		<?php } else { ?>
		<a href='#' onclick="abc()"><img src="images/delete1.Gif"  width="10" height="10"/></a>
		<?php } ?>
		
		</td>
		</tr> <?php 
			$j++;   
	}
	}else{?>
	 <tr><td colspan=6><div align="center"><font color="#FF0000">NO RECORD FOUND</font></div></td></tr><?php 
	}?>
	</table>

<?php 
include('includes/footer.inc');
?>
<script type="text/javascript">
function abc()
{
window.alert("Customer Used You Can Not Delete");
}
</script>