<?php 

//include('functions.php');
//include('functionsgetdep.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/Class_Client.php');
//include('Class_PickListEditor.php');
$date=date('Y-m-d');
//$back_days=calculateBackDate($_SESSION['ACGRoleId']);
$back_date=date('Y-m-d', strtotime('-'.$back_days.' day', strtotime($date)));
?>
 
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Indent Report</h1>
<form action="" method="post" name="myform"  >
<div class="centre" id="slidingDiv" style="padding-bottom:7px;">
<table width="40%" align="center" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1">Branch</td>
	<td class="tabledata1">
	<select name="site"  style="width:150px;">
	<option value="0">--All--</option>	
	<?php
	$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode IN ('".$_SESSION['AssignedBranch']."')";
	$SiteRes=DB_query($Sitesql,$db);
	while($SiteRow=DB_fetch_array($SiteRes))
	{?>
	<option value="<?php echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> ><?php  echo $SiteRow['locationname'];?></option>
	<?php 
	}
	?>
	</select>
	<td class="tabledata1">Client</td>
	<td class="tabledata1">
	<select name="client"  style="width:150px;">
	<option value="0">--All--</option>	
	<?php
	$client=DB_query("SELECT c_name,id FROM `clientmaster` WHERE CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($client_row=DB_fetch_assoc($client))
	{ ?>
		<option value='<?php echo $client_row[id]; ?>' <?php echo $_REQUEST['client']==$client_row['id']?'selected':''?> ><?php echo $client_row['c_name']; ?></option>
	<?php }
	?>
	</select>
	</td>
	</tr>
	 <tr class="row1">
	<td class="tabledata1">From:</td>
	<td class="tabledata1">
	<input name="fromdate" value="<?php echo $_REQUEST['fromdate']; ?>" type="text" style="width:150px;"  class="datepicker"/></td>
	<td class="tabledata1">To:</td>
	<td class="tabledata1">
	<input name="todate" value="<?php echo $_REQUEST['todate']; ?>" type="text" style="width:150px;"  class="datepicker"/></td>
	</tr>
	<tr class="row1">
	<td colspan="4"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
  </tr>
</table> 
	
<?php 
$s=new db_query();

if($_REQUEST['Search'])
	{
	$todate=FormatDateForSQL1($_REQUEST['todate']);
	$todate = str_replace('/', '-', $todate);
	$fromdate=FormatDateForSQL1($_REQUEST['fromdate']);
	$fromdate = str_replace('/', '-', $fromdate);
	$site=$_REQUEST['site'];
	$client=$_REQUEST['client'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
	$filter[]="indent_date between '".$fromdate."' and '".$todate."'";
	}
	if($_REQUEST['site']!='0')
	{
	$filter[]="site='".$site."'";
	}
	if($_REQUEST['client']!='0')
	{
	$filter[]="client='".$client."'";
	}
	if($_REQUEST['site']=='0')
	{
	$GetSales= "select * from Indent_so_main";
	$getlead=DB_query("select * from Indent_so_main where CompanyID='".$_SESSION['ACGCompanyId']."'
	  order by id desc ",$db);
	}
	if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	 $GetSales="select * FROM Indent_so_main where CompanyID='".$_SESSION['ACGCompanyId']."'  and $filter1 ";

	$getlead=DB_query($GetSales,$db);
	}else{
	$i=1;
	
	  $GetSales="SELECT * FROM Indent_so_main where CompanyID='".$_SESSION['ACGCompanyId']."' ORDER BY id DESC";
		  
	$getlead=DB_query($GetSales,$db);
	}



  
$lop=0;
 if(DB_num_rows($getlead)>0)
{
	
	
    
	 ?>
	  <tr>
  	<td align="right" colspan="8" style="text-align:right; padding-bottom:15px; padding-top:15px;"><a href="indent_print.php?action=print&site=<?php echo $_REQUEST['site']; ?>&client=<?php echo $_REQUEST['client']; ?>&fromdate=<?php echo $_REQUEST['fromdate']; ?>&todate=<?php echo $_REQUEST['todate']; ?>" target="_blank"><font size="-1">Print</font></a></td>
  </tr>
<tr style="border:1px thin;">
    <td style="white-space:nowrap;" valign="top">
	<div style="width:980px; overflow:auto; margin:auto;" id="hide1" >
	
<table width="980" align="center" border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;">

  <tr>
    <td width="32" class="tabledata"><strong>Sr.No</strong></td>
	<td width="80" class="tabledata"><strong>Indent Date</strong></td>
	<td width="32" class="tabledata"><strong>Indent No</strong></td>
    <td class="tabledata" width="60"><strong>Client</strong></td>
	<td class="tabledata" width="150"><strong>Work Order No</strong></td>
	<td class="tabledata" width="40"><strong>Order Date</strong></td>
	<td class="tabledata" width="40"><strong>P.O. No.</strong></td>	
	<td class="tabledata" width="40"><strong>Po Date</strong></td>
	<td class="tabledata" width="60"><strong>Consignee</strong></td>
	<td class="tabledata" width="40"><strong>Type of Order</strong></td>	
	<td class="tabledata" width="40"><strong>Fabrication No</strong></td>
	<td class="tabledata" width="160"><strong>MMS No</strong></td>
	<td class="tabledata" width="160"><strong>Action</strong></td>
	
</tr>

  <?php
  $t=1;
	while($row=DB_fetch_array($getlead))
	{
	$a = $row['id'];
	?>
<tr>
     <td><?php echo $t; ?></td>
	 <td><?php echo ConvertSQLDate($row['indent_date']); ?></td>
	<td><?php echo  $row['indent_no']; ?></td>
	<td><?php  echo $s->getField('clientmaster','id',$row['client'],'c_name');  ?></td>
	<td><?php echo $row['work_order_no']; ?> </td>
	<td><?php echo ConvertSQlDate($row['order_date']); ?></td>
	<td><?php echo $row['po_no']; ?></td>
	<td><?php echo ConvertSQlDate($row['po_date']); ?></td>
	<td><?php echo $row['consignee']; ?></td>
	<td><?php echo $row['order_type']; ?></td>
	<td><?php  echo $s->getField('faberication_main','id',$row['faberication'],'sheet_no');  ?></td>
	<td><?php  echo $s->getField('measurment_sheet_main','id',$row['mms'],'mms_no');  ?></td>
	<td align="center" style="text-align:center;"><a href="indentprint.php?action=View&SOrderId=<?php echo $row['id'];?>" target="_blank"><img src="images/icon_print.jpg" width="20px" height="20"></a></td>
	<td colspan="7" style="padding:0px;">
	</td>
	
	</tr> 
	<?php
	$t++;}
	?> 
	<?php 
	}}?>
	</table>
	</div>
	
<script>
function showdata()
{
document.getElementById("show1").style.display='block';
document.getElementById("hide1").style.display='none';
}
</script>
	

	 