<?php
ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);
	
	 $sql = $_SESSION['data1'];
	//unset($_SESSION['trf_req_rep']);
	$sql=DB_query($sql,$db);

	$s=new db_query();
?>
	  <div style="50px; float:left; margin-left:30px;margin-top:12px;"><img src="Setup/CompanyLogo/mx-erp.PNG" width="139" height="46" /></div>
<div> <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="text-align:center; border-width:0 0 0 0;">
        <tr>
          <!--<td colspan="3" style="height:30px;font-size:30px; padding-left:0px;"><img src="images/logo1.png" width="160" height="23" /></td>-->
        </tr>
        <tr>
          <td colspan="3"><div style="text-align:center; margin:0px;">
              <?php 
		
		if($companyRow['CompanyName']!="") {echo "<br>".$companyRow['CompanyName']; } else { echo "";}
		if($companyRow['Address1']!="") {echo "<br>".$companyRow['Address1']; } else { echo "";}
		if($companyRow['Address2']!="") {echo "<br>".$companyRow['Address2']; } else { echo "";}
		if($companyRow['Address3']!="") {echo "<br>".$companyRow['Address3']; } else { echo "";}
		if($companyRow['City']!="") {echo "<br>".$companyRow['City']; } else { echo "";}
		if($companyRow['State']!="") {echo "<br>".$companyRow['State']; } else { echo "";}
		if($companyRow['Country']!="") {echo "<br>".$companyRow['Country'];
		if($companyRow['Zipcode']!="") {echo " - ".$companyRow['Zipcode']; } else { echo "";}

		 } else { echo "";}
		echo "<br>"."<strong>Phone No</strong>.".$companyRow['Phone'].",   <strong>Fax No.</strong> ".$companyRow['fax'].",   <strong>Email ID.</strong> ".$companyRow['email'].",   <strong>Website</strong> ".$companyRow['website'];	
	?>
          </div></td>
        </tr>
      </table>

</div>
<div style="margin-top:20px;">
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#666666 1px solid;">
  <tr>
    <td width="10%" style="font-family:Arial; font-size:12px;" class="tabledata"><strong>Branch</strong></td>
    <td width="15%"><?php echo $s->getField('locations','loccode',$_REQUEST['site'],locationname); ?></td>
    <td width="10%" style="font-family:Arial; font-size:12px;" class="tabledata"><strong>From Date</strong></td>
    <td width="15%"><?php echo $_REQUEST['fromdate']; ?></td>
    <td width="10%" style="font-family:Arial; font-size:12px;" class="tabledata"><strong>To Date</strong></td>
    <td width="15%"><?php echo $_REQUEST['todate']; ?></td>
    <td width="10%" style="font-family:Arial; font-size:12px;" class="tabledata"><strong>Vendor</strong></td>
    <td><?php echo $s->getField('suppliers','id',$_REQUEST['vendor'],vendor_name); ?></td>
  </tr>
</table>
	
</div>
<br />

<div id="foo">
  <p align="center"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<br />


<table width="100%"  cellpadding="0" cellspacing="0" border="0">
<tr class="row1">
	<td colspan="6" class="tabledata1">
	<table width="100%"  border="1" cellspacing="0" cellpadding="3">
  	<tr class="row1">
  		<th >S. No. </th>
    <th >PO No. </th>
    <th>PO Date </th>
  <th width="10%">Vendor Name</th>
    <th>Contact Person </th>
    <th>Approval status</th>
    <th style="width:100px;">Part Code</th>
    <th style="width:75px;">Part name </th>
    <th  style="width:50px;">UOM </th>
    <th >PO  Qty</th>
	<th>Received Qty</th>
	<th>Pending Qty</th>
   	</tr>
<?php 
$i=1;
$num=DB_num_rows($sql);
if($num>0)
{
while($myrow=DB_fetch_array($sql))
{

?>
<tr class="row1">
	<td style="font-family:Arial; font-size:11px;"> <?php echo $i; ?></td>
	 <td style="font-family:Arial; font-size:11px;"><?php echo $myrow['pr_no'];?></td>
	<td style="font-family:Arial; font-size:11px;"><?php echo ConvertSQLDate($myrow['pr_date']); ?></td>
	<td style="font-family:Arial; font-size:11px;"><?php 
	  $vendorname=$s->getField('suppliers','id',$myrow['vender_id'],'vendor_name');
	  echo $vendorname;?></td>
	<td style="font-family:Arial; font-size:11px;"><?php echo $myrow['contact_person']; ?></td>
	<td style="font-family:Arial; font-size:11px;"><?php if($myrow['Approval_status']=="0")
		{
		echo 'Pending';
		}else
		{
		echo 'Approved';
		}
		?></td>
	  
	  
	<td colspan="6" style="padding:0px;">
		<table width="100%" border="1" style="border-bottom-color:#000000">
	<?php  $details_sql="Select * from direct_po_details where parent_id='".$myrow['parent_id']."'";
	//$details_sql="Select * from purchorderdetails where orderno='".$myrow['orderno']."' 
	//and mst_itemid='".$_REQUEST['itemCode']."'";
	$details_res=DB_query($details_sql,$db);
	$issueqty[]='';
	$req_qty[]='';
	$numrow1=DB_num_rows($details_res);
	if(DB_num_rows($details_res)>0){
	while($details_row=DB_fetch_array($details_res)){?>
				<tr bgcolor="">
            <td style="width:103px;" class="jjrs_tabledata1" ><?php echo  $s->getField('item_master','id',$details_row['mst_itemid'],'StockID'); ?></td>
            <td class="jjrs_tabledata1" style="width:90px;"><?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'item_name'); ?> </td>
            <td class="jjrs_tabledata1" style="width:62px;"><?php  $unut = $s->getField('item_master','id',$details_row['mst_itemid'],'mst_unitid');
		echo $s->getField('unitsofmeasure','unitid',$unut,'unitname');
		 ?>            </td>
            <td width="11%"  class="jjrs_tabledata1" style="width:22px;"><?php  
		echo $myrow['qty']; ?>            </td>
            <td class="jjrs_tabledata1"  style="width:82px;"><span class="jjrs_tabledata1">
              <?php
		  echo $isu_qty = $s->getField('addmrnqty','mst_itemid',$details_row['mst_itemid'],'sum(reciveqty)');
		$pendingQty = $isu_qty-$myrow['qty']; 
		//echo $details_row['qty'];?>
            </span></td>
            <td  class="jjrs_tabledata1"><?php echo $pendingQty; ?></td>
          </tr>
		<?php	}
		}
	?>
	
	</table>
		

<?php $i++; }} else { ?>
	<tr><td colspan="10" style="text-align: center;"><font color="#FF0000"><?php echo "No records found"; ?></font></td></tr>	 
	<?php  }?> 
</table>
	</td>
</tr> 
</table>
</div>
</div>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
  var msg=confirm("Please Use Mozilla Firefox And Print In Landscape Mode");
  if(msg){
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
	}
</script>

