<?php
/* $Revision: 1.73 $ */
$PageSecurity = 11;
$title = _('Show Client');
include('includes/SQL_CommonFunctions.inc');
if($_GET['action']=='del' && $_GET['id'] != '')
{
	$sql2 = "DELETE FROM contact_information_master WHERE master_code='".$_GET['id']."' and master_prefix='C'";
	$del2 = DB_query($sql2,$db,$ErrMsg,$DbgMsg);
	prnMsg(_('Client Record has been deleted') ,'success');
	
	
	$sql2 = "DELETE FROM clientmaster_consignee_address WHERE client_id='".$_GET['id']."'";
	$del2 = DB_query($sql2,$db,$ErrMsg,$DbgMsg);
	prnMsg(_('Client Record has been deleted') ,'success');
	
	
	$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);
	
	echo "<script>location.href='index.php?route=Show_client&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<link rel="stylesheet" href="css/jquery.ui.all.css" />
<script src="js/jquery-1.5.1.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>


<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function(){


    $(".slidingDiv").hide();
	$(".show_hide").show();
	
	$('.show_hide').click(function(){
	$(".slidingDiv").slideToggle();
	});

});

</script>
<style>

body{
font-family:Verdana, Geneva, sans-serif;
font-size:14px;}

.slidingDiv {
	height:184px;
	background-color: #FFFFFF;
	padding:10px;
	margin-top:10px;
    border-bottom:2px solid #666666;
}

.show_hide {
	display:none;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Client Master</h1>
<p align="left">
<a href="index.php?route=Client_Master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" value="ADD CLIENT" class="search" /></a>
<a href="#" class="show_hide"><input type="button" value="SEARCH" class="search" /></a></p>
<div class="slidingDiv">
<div align="center">
<form action="" method="post">
<table width="50%" cellpadding="3" cellspacing="0">	
<tr class="row1">
	<td class="tabledata1"><strong>Site</strong>
	<?php $result=DB_query('SELECT locationname, loccode FROM locations', $db); ?>
	<td><select name="site" style="width:150px;">
	<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 }?> 
	</option>
	</select></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Client Code</strong></td>
	<td><input type="text"  name="vendor_code" style="width:150px;"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Client Name</strong></td>
	<td><input type="text"  name="vendor_name" style="width:150px;"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Approved Item</strong></td>
	<td><Select name="item" id="item" style="width:150px;">
		<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>Category</strong></td><td><select name="category">
	<option value="0">Select</option>
	<option value="SiteVendor">SiteVendor</option>
	<option value="HeadOfficeVendor">HeadOfficeVendor</option>
	<option value="Expenses">Expenses</option>
	</select></td></tr>-->
<tr class="row1">
	<td class="tabledata1"><strong>Country</strong></td>
	<td><Select name="country" id="country" style="width:150px;">
		<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>
<tr class="row1">
	<td class="tabledata1" colspan="2" style="text-align:center;"><input type="submit" name="submit" class="search" value="Search" /></td>
</tr>
   </table>
</form>
</div>
</div>
<!--<?php	
		if(isset($_POST['Submit']))
			{
				$filter = array();
				$SQL = "select id,client_code,c_name,short_name,ccategory,Store 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 from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name ASC";
		}
		//echo "===".$SQL;
		 $PC_OpeningResult = DB_query($SQL,$db);
		if (isset($PC_OpeningResult)) {
	?>-->
	<?php
	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,ccategory,Store from clientmaster where 1 ";
		}
		else 
		{
		$sql_search = "select id, client_code,c_name,short_name,ccategory,Store from clientmaster where 0 ";
		}
		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="3" cellspacing="0" border="1" width="100%">
<tr class="row1">
	<td class="tabledata"><strong>Client Code</strong></td>
	<td class="tabledata"><strong>Client Name</strong></td>
	<td class="tabledata"><strong>Zone</strong></td>
	<td class="tabledata"><strong>Dealer</strong></td>
	<td class="tabledata"><strong>Category</strong></td>
	<td class="tabledata"><strong>View</strong></td>
	<td class="tabledata"><strong>Edit</strong></td>
	<td class="tabledata"><strong>Delete</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)) { ?>
<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('storetype',"id='".$res['Store']."'" ,'StoreName');?></td>
		<td><?php echo $res['ccategory'];?></td>
		<td><a href="index.php?route=view_client&action=view&id=<?php echo $res['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" height="16" width="16" /></a></td>
		<td><a href="index.php?route=Client_Master&action=editRec&id=<?php echo $res['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon_edit.gif" /></a></td>
		<td><a href="index.php?route=Show_client&action=del&id=<?php echo $res['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>" onclick="return confirm('This client will be deleted. Are you sure?')"><img src="images/Icon_Delete3.gif" /></a></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 
	}	
?>
</table></td>
  </tr>
</table>
<?php 
include('includes/footer.inc');
?>