<?php
$PageSecurity = 15;
$title = _('Store Types');
if (isset($_POST['SelectedType'])){
	$SelectedType = strtoupper($_POST['SelectedType']);
} elseif (isset($_GET['SelectedType'])){
	$SelectedType = strtoupper($_GET['SelectedType']);
}

if (isset($Errors)) {
	unset($Errors);
}
$Errors = array();
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<p align="left">
<a href="index.php?route=DealerDistrbutions/Setup/storetypenew&modid=<?php  echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>">
<input type="button" name="Add New Dealer" value="Add New Associate" class="search"  /></a></p>
<?php  
if (!isset($SelectedType))
{
   	$sql = "SELECT * FROM dbl_dealer where company='".$_SESSION['ACGCompanyId']."'";
	$result = DB_query($sql,$db);
?>
	<table width="100%" border="1" cellpadding="2" cellspacing="2" class="inborder" style="background:#dce6f2; margin-top:20px;">
	<tr class="row1">
	    <td width="5%" class="tabledata"><strong>Sr.No.</strong></td>
		<td width="13%" class="tabledata"><strong>Associate Code </strong></td>
		<td width="16%" class="tabledata"><strong>Associate Name </strong></td>
		<td width="10%" class="tabledata"><strong>Area Name</strong></td>
<!--		<td width="13%" class="tabledata"><strong>Engineer Code</strong></td>-->
		<td width="13%" class="tabledata"><strong>City </strong></td>
		<td width="13%" class="tabledata"><strong>State </strong></td>
		<td width="11%" class="tabledata"><strong>Country </strong></td>
		<td width="6%" class="tabledata"><strong>Edit</strong></td>
                <td width="6%" class="tabledata"><strong>Delete</strong></td>
		
	</tr><?php
	$i=1; //row colour counter
while ($myrow = DB_fetch_array($result))
 {
        $customer=$s->GetTotalRecordsTalbes('clientmaster',"dealer='".$myrow['id']."'");
		$enqiry=$s->GetTotalRecordsTalbes('dbl_enquiry_form',"dealer='".$myrow['id']."'");
		$salsorder=$s->GetTotalRecordsTalbes('dbl_process_sale_order',"dealer='".$myrow['id']."'");
		$dispatch=$s->GetTotalRecordsTalbes('dbl_dealer_dispatch',"dealer='".$myrow['id']."'");
		$associateStore=$s->GetTotalRecordsTalbes('dbl_dealer_store',"dealer='".$myrow['id']."'");
		$associateEngineer=$s->GetTotalRecordsTalbes('dbl_engineer_dealer_maste',"dealer='".$myrow['id']."'");
		
		if($enqiry<=0 && $salesorder<=0 && $dispatch<=0 && $customer<=0 && $associateStore<=0 && $associateEngineer<=0)
		{
		$status=0;
		}
		else
		{
		$status=1;
		}
?>
<tr class="row1">
<td><?php echo $i; ?></td>
<td><?php echo $myrow['dealer_code'];?></td>
<td><?php echo $myrow['dealer_name'];?></td>
<td><?php echo $s->getField('zone_master','id',$myrow['area_code'],'ZoneTitle');?></td>
<!--<td><?php echo $s->GetFieldValue('dbl_engineer_master',"id='".$myrow['engineer_code']."'",'engineer_code');?></td>-->
<td><?php echo $s->getField('city_master','id',$myrow['pre_city'],'city');?></td>
<td><?php echo $s->getField('state_master','id',$myrow['pre_state'],'state');?>`</td>
<td><?php echo $s->getField('country_master','id',$myrow['pre_country'],'country');?></td>

<td><a href="index.php?route=DealerDistrbutions/Setup/storetypenew&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&action=Edit"><img src="images/icon-edit.png"  width="10" height="10"/></a>

</td>
<td><?php if($status==0) { ?>
<a href='index.php?route=DealerDistrbutions/Setup/storetypenew&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&action=delete' onclick="return confirm('This Associate will be deleted. Are you sure?')"><img src="images/delete.Gif"  width="10" height="10"/></a>
<?php } else { ?>
<img src="images/delete.Gif"  width="10" height="10"  onclick="abc()" />
<?php } ?></td>
</tr>
<?php
	$i++;}?>
</table>
</div>
</div>
<?php }
include('includes/footer.inc');
?>

<script type="text/javascript">
function abc()
{
window.alert("Associate Used You Can Not Delete");
}
</script>