<?php
$PageSecurity = 3;
include ('includes/session.inc');
include ('includes/function_lib.php');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  <title>Purchase Order Register Report</title>
<style type="text/css" media="print">
  @page port {size: portrait;}
@page land {size: landscape;}
 .portrait {page: port;}
.wrapper {page: land;}

</style>

<style type="text/css"> 
@page {size: landscape; margin:10px;}

@media print{
  *{box-sizing:border-box;}
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px; line-height: 28px;
  font-weight:bold;
  text-transform: uppercase;  
}
h2{
  font-size: 18px; line-height: 26px;
  font-weight:normal;
}
thead{display: table-header-group;}
.wrapper{width:99%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  float: left; position: relative;
}
 .div_first .left
  {
    width:16%; text-align:center; height:auto; vertical-align:middle; height:auto; padding: 1% 0; float: left;
  }
  .div_first .middle
  {
    width:68%; text-align:center; padding: 1% 0; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:16%;text-align:center; padding: 1% 0; float: left;
  }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  float: left;
}
.div_second{border-top:0;}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left; border-top:#000 1px solid;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:96%;}
.mt27{margin-top:4px; width:66%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
}

@media screen{
/* CSS Document */
*{box-sizing:border-box;}
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 30px;
  font-weight:bold;
  text-transform: uppercase;    
}
h2{
  font-size: 18px; line-height: 28px;
  font-weight:normal;
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
        {
          width:16%; text-align:center; height:auto; vertical-align:middle; padding: 1% 0; 
        }
        .div_first .middle
        {
          width:68%; text-align:center; padding: 1% 0; position: relative; margin:0 auto;
        }
        .div_first .right
        {
          width:16%; text-align:center; padding:1% 0; 
        }
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
/*.div_second table tr:last-child td{border-bottom:0;}*/
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
/*.div_third table tr:last-child td{border-bottom:none;}*/

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:96%;}
.mt27{margin-top:4px; width:56%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
}
</style>

<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>
 </head>
 <body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<?php 
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$CompamiesRow = DB_fetch_array($sqlres);

$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);

?>
<div class="wrapper">
	<!-- <div class="div_first">
    <?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'Final_Logo_RM.png':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
      <div class="middle"><?php 
    if($CompamiesRow['CompanyName']!="") {echo "<h1>".$CompamiesRow['CompanyName']."</h1>"; } else { echo "";}
    
    if($InoRow['deladd1']!="") { echo $InoRow['deladd1']; } else { echo "";}
    if($InoRow['deladd2']!="") { echo ", ". $InoRow['deladd2']; } else { echo "";}
    if($InoRow['deladd3']!="") { echo ", ". $InoRow['deladd3']; } else { echo "";}
    if($InoRow['city']!="") { echo ", ". $s->getFieldValue("city_master", "id='".$InoRow['city']."'", "city"); } else { echo "";}
    if($InoRow['pincode']!="") { echo " - ".$InoRow['pincode']; } else { echo "";}
    if($InoRow['state']!="") { echo ", ". $s->getFieldValue("state_master", "id='".$InoRow['state']."'", "state"); } else { echo "";}
    if($InoRow['country']!="") { echo ", ". $s->getFieldValue("country_master", "id='".$InoRow['country']."'", "country");
    
     } else { echo "";}
    ?>
     <div class="full"><span class="f11"><?php echo "Phone No.:".$CompamiesRow['Phone'].",   Fax No.: ".$CompamiesRow['fax'].", Email ID.: ".$CompamiesRow['email'].",   Website: ".$CompamiesRow['website']; ?><br>
    <?php  echo $_SESSION['mess']; ?>
    </span></div>
      <h2>Purchase Order Register Report</h2>
      </div>
      <div class="right"></div>
  </div> -->
      <div class="div_first">
        <?php echo $s->print_header(); ?>
        <h3 style="text-transform:uppercase;text-align:center;padding:5px;">Purchase Order Register Report</h3>
    </div>
    <div class="div_second">
    <table width="100%" cellpadding="3" cellspacing="0" border="0">
    <thead>
 	<tr>
    <th width="3%" class="f12">S. No.</th>
    <th width="4%" class="f12">Date</th>
    <th width="8%" class="f12">PO No.</th>
    <th width="6%" class="f12">PO Type</th>
     <?php if($_REQUEST['vendor']=='') {?> <th width="12%" class="f12">Vendor Name</th>
     <?php } ?>
    <th width="8%" class="f12">Quotation No.</th>
	  <th width="7%" class="f12">Delivery Date</th>
    <th width="80" class="f12">Part code</th>
    <th class="f12">Part Name</th>
    <th width="50" class="f12">UOM</th>
	  <th width="70" class="f12">PO Qty.</th>
    <th width="70" class="f12">Received Qty.</th>
    <th width="70" class="f12">Pending Qty.</th>
  </tr>
  </thead>
  <?php 
  $sql =$_SESSION['vendor_po'];
   //echo $sql =$_SESSION['data1'];
  $sno=1;
  $result=DB_query($sql,$db);
  if(DB_num_rows($result)>0){
  while($myrow=DB_fetch_array($result))
  {
  	//echo $myrow['id'];
  ?>
  <tr>
    <td class="f11"><?php echo $sno;?></td>
    <td class="f11"><?php echo $myrow['po_date'];?></td>
    <td class="f11"><?php echo $myrow['purchase_ordNo']; ?></td>
	<td class="f11"><?php echo $myrow['purchase_ord_Type'];?></td>
   <?php if($_REQUEST['vendor']=='') {?> <td class="f11"><?php 
	  $vendorname=$s->getField('suppliers','id',$myrow['vendorId'],'vendor_name');
	  echo $vendorname;?></td>
   <?php } ?>
	 
    <td class="f11">&nbsp;<?php echo $vernder_quotation=$s->getField('venderquotations','id',$myrow['quotationId'],'quotation_no');?></td>
	
	<td class="f11"><?php echo $myrow['delivery_date'];?></td>
	<?php
	?>
	<td colspan="6" style="padding:0px;" valign="top">
	<?php 
		 $query = "select * from purchorderdetails where parantId='".$myrow['parantId']."'";
		$res = DB_query($query,$db) or die(DB_error());
	?>
		<table width="100%" cellpadding="3" cellspacing="0" border="0">
		<?php 
		if(DB_num_rows($res)>0){
		while($result_order = DB_fetch_array($res))
		{ 
    //print_r($result_order);  
     //echo "select * from item_master where id='".$result_order['mst_itemid']."'";
			 $itemname1=DB_query("select StockID,item_name,mst_unitid from item_master where id='".$result_order['mst_itemid']."'",$db);
		$itemname2=DB_fetch_array($itemname1);
		?>
			<tr>
				<td width="80" class="f11" style="word-break:break-all;"><?php echo $itemname2['StockID'];?></td>
		    <td class="f11"><?php echo $itemname2['item_name']; ?></td>
			  <td width="50" class="f11"><?php echo $s->GetFieldValue('unitsofmeasure',"unitid='".$itemname2['mst_unitid']."'",'unitname'); ?></td>
			  <td width="70" class="f11" style="text-align:right;"><?php echo $result_order['Quantity']; ?></td>
			  <td width="70" class="f11" style="text-align:right;"><?php 
       /* echo "SELECT SUM(reciveqty) as rec
        FROM addmrn a,addmrnqty b
        WHERE a.id=b.issue_id AND a.order_no='".$myrow['purchId']."' AND b.mst_itemid='".$result_order['mst_itemid']."'"; */

				$rec=DB_fetch_assoc(DB_query($str="SELECT SUM(reciveqty) as rec
        FROM addmrn a,addmrnqty b
        WHERE a.id=b.issue_id AND a.order_no='".$myrow['parantId']."' AND b.mst_itemid='".$result_order['mst_itemid']."'",$db));
        //echo $str;
				echo $reciveQty=$rec['rec'];
				$poQty= $result_order['Quantity'];
                              //  $parentIDD = $s->GetFieldValue('addmrn',"order_no='".$myrow['purchId']."'",'id'); 
			//	echo $reciveQty = $s->GetFieldValue('addmrnqty',"issue_id='".$parentIDD."'",'reciveqty');
				//$poQty = $s->GetFieldValue('addmrnqty',"issue_id='".$parentIDD."'",'POQty'); ?></td>
				<td width="70" class="f11" style="text-align:right;"><?php echo number_format((float)($poQty-$reciveQty),2,'.',','); ?></td>
			</tr>
			<?php } }
			else { ?>
			<tr>
			<td colspan="6">No Record Found</td>
			</tr>
			<?php } ?>
		</table></td>
  </tr>
  <?php  $sno++; }
  }else{?>
  <tr  style="height: 25px">
    <td colspan="13" align="center"><strong>No Records</strong></td>
  </tr>
  <?php } ?>
</table>
  </div>
</div>

</body>
</html>