<?php
include('config.php');
include('includes/ConnectDB.inc');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');

session_name('CAKEPHP'); session_start();
?> 

<link rel="stylesheet" href="css/new_mxerp.css">
<style>
.border1{border:#666666 1px solid; border-left:none; border-top:none; font-family:Arial; font-size:12px; color:#000000;}
.border_bottom{border-bottom:#666666 1px solid; font-family:Arial; font-size:12px; color:#000000;}
.f12{font-family:Arial; font-size:12px; color:#000000; font-weight:bold;}
.f11{font-family:Arial; font-size:11px; color:#000000;}
</style>
<center><h3 style="text-align:center; font-size:18px;"><u><?php //echo"<pre>"; print_r($_SESSION);
$company_name=DB_fetch_assoc(DB_query("select CompanyName from companies where CompanyId='".$_SESSION[ACGCompanyId]."'",$db)); 
echo strtoupper($company_name[CompanyName]);?></u></h3></center>
<center> <h2 style="font-family:Arial; font-size:18px; color:#003399;">Measurement Sheet Report</h2>
</center>
<center><h3 style="text-align:center; font-size:16px;"> Date : <span style="font-family:Arial; font-size:16px; color:#003399;"> <?php if($_REQUEST['fromdate']!="" && $_REQUEST['todate']!="") 
 					echo $_REQUEST['fromdate'] . " to " .$_REQUEST['todate']; 
	 		  else 
 					echo date("d/m/Y", strtotime($_SESSION['financialYrStart'])) . " to " .date("d/m/Y", strtotime($_SESSION['financialYrEnd'])); ?></span> </h3></center>
		<br />
<div class="body_contain">
<div class="tab_div">
<div id="foo"><p style="font-size:12px;" align="right"><a href="javascript:toggle_visibility('foo');">PRINT</a></p></div>
<div style="width:980px; overflow:auto; margin:auto;" id="hide1" >			
<table width="100%" border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;">
<?php 
//$s=new db_query();

if($_REQUEST['action']=='print'){
	$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[]="mms_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 measurment_sheet_main";
	$getlead=DB_query("select * from measurment_sheet_main where CompanyID='".$_SESSION['ACGCompanyId']."'
	  order by id desc ",$db);
	}
	if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	 $GetSales="select * FROM measurment_sheet_main where CompanyID='".$_SESSION['ACGCompanyId']."'  and $filter1 ";

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



  
$lop=0;
 if(DB_num_rows($getlead)>0)
{
	
	
    
	 ?>
<tr style="border:1px thin;">
    <td style="white-space:nowrap;" valign="top">
	<table width="100%" border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;">
  <tr>
  
	<td width="15" class="tabledata f12"><strong>Sr .No</strong></td>
	<td width="70" class="tabledata f12"><strong>MMS No</strong></td>
	<td class="tabledata f12" width="60" ><strong>MMS Date</strong></td>
	<td class="tabledata f12" width="80"><strong>Client</strong></td>
	<td class="tabledata f12" width="40"><strong>Type</strong></td>
	<td class="tabledata f12" width="60"><strong>Order No.</strong></td>
	<td class="tabledata f12" width="60"><strong>Order Date</strong></td>
	<td class="tabledata f12" width="40"><strong>P.O. No.</strong></td>	
	<td class="tabledata f12" width="40"><strong>Po Date</strong></td>
	<td class="tabledata f12" width="160"><strong>Item Name</strong></td>
	<td width="60" class="tabledata f12"><strong>Size</strong></td>
	<td width="50" class="tabledata f12"><strong>Width</strong></td>
	<td class="tabledata f12"><strong>Height</strong></td>
	<td width="40" class="tabledata f12"><strong>Qty</strong></td>
	<td class="tabledata f12"><strong>Unit</strong></td>
	
	
</tr>
  <?php
  $t=1;
	while($row=DB_fetch_array($getlead))
	{
	$a = $row['id'];
	?>
<tr>
    <td class="f11"><?php echo $t; ?></td>	
	<td class="f11"><?php echo  $row['mms_no']; ?></td>
	<td class="f11"><?php echo ConvertSQLDate($row['mms_date']); ?></td>
	<td class="f11"><?php  
	$cl_sql=DB_query("select c_name from clientmaster where id='".$row['client']."'",$db);
	$cl_res=DB_fetch_array($cl_sql);
	
	echo $cl_res['c_name'];  ?></td>
	<td class="f11"><?php echo $row['mms_type']; ?> </td>
	<td class="f11"><?php echo $row['order_no']; ?></td>
	<td class="f11"><?php echo ConvertSQlDate($row['order_date']); ?></td>
	<td class="f11"><?php echo $row['po_no']; ?></td>
	<td class="f11"><?php echo ConvertSQlDate ($row['po_date']); ?></td>
	<td colspan="7" style="padding:0px;">
	<?php
	
	  $sql=DB_query("select * from measurment_sheet_details  where parent_id='".$a."'",$db);
		$numrow=DB_num_rows($sql);
		while($row1=DB_fetch_array($sql))
		{
		?>
		<table cellpadding="2" cellspacing="0" width="100%" border="1" style="border-collapse:collapse;">
		<tr>
		<td width="149" align="left" class="f11"><?php 
		$it_sql=DB_query("select item_name from item_master where id='".$row1['itemid']."'",$db);
	$it_res=DB_fetch_array($it_sql);
	
	echo $it_res['item_name'];
		
	 ?></td>
		<td width="62" align="left" class="f11"><?php 
		$sz_sql=DB_query("select size from size_master where id='".$row1['size']."'",$db);
	$sz_res=DB_fetch_array($sz_sql);
	
	echo $sz_res['size'];
		
		 ?></td>
		<td width="54" align="left" class="f11"><?php echo $row1['width']; ?></td>
		<td width="42"  align="left" class="f11"><?php echo $row1['height']; ?></td>
		<td width="43"  align="left" class="f11"><?php echo $row1['qty'];  $qtydata[]=$row1['qty'];?></td>
		<td align="left" class="f11"><?php echo $row1['unit']; ?></td>
</tr>
		 </table>
		<?php
		 }
		 ?>
		
	
	</td>		
	</tr> 
	<?php
	$t++;}
	?> 
	<?php 
	}}?>
	</table>
</td>
</tr>
</table>
	</div>
	</div>
	</div>
	
<script>
function toggle_visibility(id) {
  var msg=confirm("Please Use Mozilla Firefox For Better Print");
  if(msg)
  {
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
	}
    }
</script>
	

	 