<?php 
if($_REQUEST['action']=='del' && $_REQUEST['id']!='')
{
$condition="parant_id='".$_REQUEST['id']."'";
$s->DeleteRecord('sale_budget_details', $condition);
$condition1="id='".$_REQUEST['id']."'";
$s->DeleteRecord('sale_budget', $condition1);
$s->pageLocation("index.php?route=CRM/sale_order_assignment_view".$rurl);
}
?>

<link rel="stylesheet" href="css/new_mxerp.css">

<div class="body_contain">
<div class="tab_div">
<h1>Sale Budget Preparations View</h1>
<div class="centre" id="slidingDiv">
<form method="post">
		<table width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
			<td>Branch</td>
			<td>
			<?php $site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode IN ('".$_SESSION['AssignedBranch']."')",$db); ?>
			<select name="branch" id="branch" style="width:150px;">
			<option value="0">Select Branch</option>
			<?php while($Branch=DB_fetch_array($site_sql)) {
			$sel='';
			if($_REQUEST['branch']==$Branch['loccode'])
			$sel='selected';
			?>
					<option value="<?php echo $Branch['loccode']; ?>"<?php echo $sel; ?>><?php echo $Branch['locationname']; ?></option>
					<?php } ?>
				</select>
			</td>
		<td class="tabledata1">Client</td>
		<td>
		<?php 		  $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site IN ('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].")";
		$ClientRes=DB_query($ClientSQL,$db); ?>
		<select style="width:150px;"  name="client">
		<option value="All">All</option>
		<?php
		while($ClientRow=DB_fetch_array($ClientRes))
		{
 		?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo ($_REQUEST['client']==$ClientRow['id']?'selected':'');?>><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
 	</select></td>
		</tr>

   <tr class="row1">
   <td class="tabledata1">Finacial Year</td>
   <td class="demo">
   <?php $FinY=DB_query("SELECT *,YEAR(BookPeriodStart) AS SYear,YEAR(BookPeriodEnd) AS EYEAR FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); ?>
   <select name="fin_year" id="fin_year" style="width:150px;">
   <option value="0">Select Finacial Year</option>
   <?php while($FinYRow=DB_fetch_array($FinY)) {?>
   	<option value="<?php echo $FinYRow['SYear']."-".$FinYRow['EYEAR']; ?>"<?php echo($_REQUEST['fin_year']==$FinYRow['SYear']."-".$FinYRow['EYEAR']?'selected':''); ?>><?php echo $FinYRow['SYear']."-".$FinYRow['EYEAR']; ?></option>
	<?php } ?>
   					</select>
   </td>
   <td class="tabledata1">Month</td>
   <td>
   <?php $month=array("Jan","Feb","March","Apr","May","June","July","Aug","Sept","Oct","Nov","Desc"); ?>
   <select name="month" id="month"  style="width:150px;">
   						<option month="All">All</option>
						<?php for($i=0;$i<count($month);$i++) { ?>
						<option value="<?php echo $i+1; ?>"<?php echo($_REQUEST['month']==$i+1?'selected':''); ?>><?php echo $month[$i]; ?></option>
						<?php } ?>
   					</select>
   </td>
  </tr>
  
   <tr class="row1">
   <td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search"></p></td>
  </tr>
  <tr class="row1">
   <td colspan="4"><p align="left">
   <?php if($_SESSION['frmAdd']==0){ ?> 
   <input type="button" value="Add Potentials" alt="Not Allowed" title="Not Allowed" class="search" />
   <?php }else{?>
    <a href="index.php?route=CRM/sale_order_assignment&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><input type="button" value="Add Potentials" class="search" /></a>
   <?php } ?>
   </p></td>
  </tr>
  
</table>
</form>
	</div>

<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr class="row1">
  <td class="tabledata"><center>Sr. No.</center></td>
    <td class="tabledata"><center>Finacial Year</center></td>
     <td class="tabledata"><center>Month</center></td>
     <td class="tabledata"><center>Client</center></td>
       <td class="tabledata"><center>Expected Order</center></td>
        <td class="tabledata"><center>Action</center></td>
  </tr>
<?php 
if($_REQUEST['Search']){
if($_REQUEST['branch']!='0')
{
	$filter[]="sale_budget.branch='".$_REQUEST['branch']."'";
}
if($_REQUEST['client']!='All')
{
	$filter[]="sale_budget.client_id='".$_REQUEST['client']."'";
}
if($_REQUEST['fin_year']!='0')
{
	$filter[]="sale_budget.fin_year='".$_REQUEST['fin_year']."'";
}
if($_REQUEST['month']!='All')
{
	$filter[]="sale_budget.month='".$_REQUEST['month']."'";
}
if($filter!='')
{
	$filter1=implode(" and ",$filter);
	$sql="SELECT * from sale_budget WHERE $filter1";
  $sql1=DB_query($sql,$db);
  $i=0;
  while($row=DB_fetch_array($sql1))
  {
  $sum=DB_query("select sum(expected_order) as AMT from sale_budget_details where parant_id='".$row['id']."'",$db);
  $GetSum=DB_fetch_array($sum);
  	 $timestamp = mktime(0, 0, 0, $row['month'], 1, $row['year']);
    
     
  ?>
  <tr class="row1">
  <td><center><?php echo $i+1; ?></center></td>
    <td><center><?php echo $row['fin_year']; ?></center></td>
    <td><center><?php echo date("M", $timestamp); ?></center></td>  
    <td><center><?php echo $s->getField('clientmaster','id',$row['client_id'],'c_name'); ?></center></td>
    <td><center><?php echo $GetSum['AMT']; ?></center></td>
    <td><center><a href="index.php?route=CRM/sale_order_assignment_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&id=<?php echo $row['id']; ?>&action=edit">Edit</a>&nbsp;&nbsp;&nbsp;
    	
    <a href="index.php?route=CRM/sale_order_assignment_view&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&id=<?php echo $row['id']; ?>&action=del">Delete</a></center></td>
  </tr>
  <?php $i++;} } }else {?>
  <tr>
  <td colspan="6" style="height:5px; color:#FF0000;">No Records</td>
  </tr>
  <?php } ?>
</table>




	
</div>
</div>


