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

session_name('CAKEPHP'); session_start();
if($_REQUEST['action']=='print'){
if($_REQUEST['fromdate']!="" && $_REQUEST['todate']!="")
	{
		$fromdate = str_replace('/', '-', $_REQUEST['fromdate']);
		$fromdate_convert= date('Y-m-d', strtotime($fromdate));
		$todate = str_replace('/', '-', $_REQUEST['todate']);
		$todate_convert= date('Y-m-d', strtotime($todate));
		if($_REQUEST['site']=='' && $_REQUEST['client']=='')
			{
				$search=DB_query("SELECT * FROM faberication_main where sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}
			}
		elseif($_REQUEST['site']!='' && $_REQUEST['client']=='')
			{
				$search=DB_query("SELECT * FROM faberication_main where site='".$_REQUEST['site']."' and  sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}			
			}
		elseif($_REQUEST['site']=='' && $_REQUEST['client']!='')
			{	
				$search=DB_query("SELECT * FROM faberication_main where client='".$_REQUEST['client']."' and  sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}
			}
		else
			{				
				$search=DB_query("SELECT * FROM `faberication_main` where site='".$_REQUEST[site]."' and client='".$_REQUEST[client]."' and sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}			
			}
	}
	else
	{	
			 $fromdate_convert=$_SESSION['financialYrStart'];
			 $todate_convert=$_SESSION['financialYrEnd'];
		
			if($_REQUEST['site']=='' && $_REQUEST['client']=='')
			{
				$search=DB_query("SELECT * FROM faberication_main where sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}
			}
		elseif($_REQUEST['site']!='' && $_REQUEST['client']=='')
			{
				$search=DB_query("SELECT * FROM faberication_main where site='".$_REQUEST['site']."' and  sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}			
			}
		elseif($_REQUEST['site']=='' && $_REQUEST['client']!='')
			{					
				$search=DB_query("SELECT * FROM faberication_main where client='".$_REQUEST['client']."' and  sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}
			}
		else
			{
				$search=DB_query("SELECT * FROM `faberication_main` where site='".$_REQUEST[site]."' and client='".$_REQUEST[client]."' and sheet_date BETWEEN '".$fromdate_convert."' AND '".$todate_convert."'",$db);
				while($search_result1=DB_fetch_assoc($search))
				{
					$search_result[]=$search_result1;
				}			
			}
	}
}
?>
<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>
<link rel="stylesheet" href="css/new_mxerp.css">
<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;">Fabrication Sheet Report</h2>
</center>
<center><h3 style="text-align:center; font-size:16px;">Showing Report From 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 id="foo"><p style="font-size:12px;" align="right"><a href="javascript:toggle_visibility('foo');">PRINT</a></p></div>			
<table width="100%" border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse;">
	<tr>
		<td align="left" bgcolor="#f2f2f2" class="f12"><b>Branch</b></td>
		<td colspan="2" bgcolor="#f2f2f2" class="f12" style="font-family:Arial; font-size:12px; color:#003399;">
		<?php   if($_REQUEST['site']=='') 
					echo "All Branch"; 
		    	else 
				{$loc_name=DB_fetch_assoc(DB_query("select locationname from `locations` where loccode='".$_REQUEST['site']."'",$db));
				echo $loc_name[locationname];
				} 
		?>		</td>
		<td bgcolor="#f2f2f2" class="f12"><b>Client</b></td>
		<td colspan="7" bgcolor="#f2f2f2" class="f12" style="font-family:Arial; font-size:12px; color:#003399;"><?php if($_REQUEST['client']=='') 
 					echo "All Client"; 
 				else
				{ 
					$c_name=DB_fetch_assoc(DB_query("select c_name from `clientmaster` where id='".$_REQUEST['client']."'",$db));
				echo $c_name[c_name];
				}
				 ?>		</td>
	</tr>
	<tr>
		<td width="4%" bgcolor="#f2f2f2" class="f12"><b>S.No</b></td>
		<td width="6%" bgcolor="#f2f2f2" class="f12"><b>Sheet Date</b></td>
		<td width="8%" bgcolor="#f2f2f2" class="f12"><b>Sheet No</b></td>
		<td width="15%" bgcolor="#f2f2f2" class="f12"><b>Client</b></td>
		<td width="10%" bgcolor="#f2f2f2" class="f12"><b>MMS No</b></td>
		<td width="5%" bgcolor="#f2f2f2" class="f12"><b>MMS Date</b></td>
		<td width="10%" bgcolor="#f2f2f2" class="f12"><b>Order Type</b></td>
		<td width="18%" bgcolor="#f2f2f2" class="f12"><b>Item Name</b></td>
		<td width="12%" bgcolor="#f2f2f2" class="f12"><b>Size</b></td>
		<td width="7%" bgcolor="#f2f2f2" class="f12">Quantity</td>
		<td bgcolor="#f2f2f2" class="f12">Unit</td>
	</tr>
	<?php 
	if(!(empty($search_result)) && count($search_result)>0)
	{	
		$i=1;
		foreach($search_result as $searched)
		{
		?>
	<tr>
		<td class="f11"><?php echo $i; ?></td>
		<td class="f11"><?php echo date("d-m-Y", strtotime($searched[sheet_date])) ; ?></td>
		<td class="f11"><?php echo $searched[sheet_no]; ?></td>
		<td class="f11"><?php $client=DB_fetch_assoc(DB_query("select c_name from clientmaster where id='".$searched[client]."'",$db)); echo $client['c_name'];?></td>
		<td class="f11"><?php $mms_detail=DB_fetch_assoc(DB_query("select mms_no,mms_date from `measurment_sheet_main` where id='$searched[against_indent]'",$db)); echo $mms_detail['mms_no'];  ?></td>
		<td class="f11"><?php echo date("d-m-Y", strtotime($mms_detail['mms_date'])); ?></td>
		<td class="f11"><?php echo $searched[type_of_sheet]; ?></td>
		<td colspan="4" style="padding:0px;">
		<table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#999999" style="border-collapse:collapse;">
  <?php $sheet_detail=DB_query("select * from `faberication_main_child_item` where parent_id='".$searched[id]."'",$db);
  		while($sheet_detail_row=DB_fetch_assoc($sheet_detail))
		{
    ?>
  <tr>
    <td width="235" class="f11"><?php $item_name=DB_fetch_assoc(DB_query("select item_name,mst_unitid from item_master where id='".$sheet_detail_row[itemid]."'",$db)); echo $item_name[item_name]; ?></td>
	<td width="156" class="f11"><?php $size=DB_fetch_assoc(DB_query("select size from size_master where id='".$sheet_detail_row[size]."'",$db)); echo $size[size]; ?></td>
    <td class="f11"><?php echo $sheet_detail_row[qty]; ?></td>
    <td class="f11"><?php $unit=DB_fetch_assoc(DB_query("select unitname from `unitsofmeasure` where unitid='".$item_name[mst_unitid]."'",$db)); echo $unit[unitname]; ?></td>
  </tr>
  <?php } ?>
  
</table>
		</td>
	</tr>
		<?php $i++;
		}}?>
</table>
<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>