<?php
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');

    $sql="SELECT * From addmrn Where `id`='".$_GET['mrnid']."'";
  $result = DB_query($sql, $db);
  $myrow = DB_fetch_array($result);
  if($myrow['Cancel_Status']=='Y')
  {
  $cancel_status="Cancelled";
  }

$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);
  $s=new db_query();

?>
<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>

<!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>Direct Material Receipt Note</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: portrait; margin:10px;}

@media print{
*{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;}

h1{
  font-size: 20px; line-height: 28px;
  font-weight:bold;
  text-transform: uppercase;
}
h2{
  font-size: 18px; line-height: 26px;
  font-weight:normal;
}
.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;
}
 .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, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{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: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;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
/*.div_forth 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:8px; width:96%;}
.mt27{margin-top:4px; width:66%;}
.mt28{margin-top:0px; width:100%;}
.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: 28px;
  font-weight:bold;
  text-transform: uppercase;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal; 
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  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-bottom: #000000 1px solid;*/
  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 0px 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;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
/*.div_forth 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:16px; line-height: 22px; font-weight: bold;}
.mt26{margin-top:4px; width:96%;}
.mt27{margin-top:4px; width:56%;}
.mt28{margin-top:0px; width:90%;}
.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>

 </head>
 <body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<div class="wrapper">
  <!-- <div class="div_first">
  <?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'ssmh-logo.jpeg':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php //echo $logoImage;  ?>" class="mt26" /></div>
      <div class="left"><img src="images/ssmh-logo.jpeg" class="mt26" /></div>
      <div class="middle"><h1>Shekhar Sharraf Memorial Hospital</h1>
        <div class="f14">RUSA Medical Centre (Aligarh)</div>
        <div class="f12">6Km. Milestone, Agra Road, Aligarh - 202001, U.P. (India)</div>
        <div class="f12">Email : info@rusamedicalcentre.com</div>
        <div class="full"><h2>Purchase Requisition</h2>
        </div>
      </div>
      <div class="right"><img src="images/rusa-logo.jpeg" vspace="10" class="mt27" /></div>
</div>-->

    <div class="div_first">
        <?php echo $s->print_header(); ?>
        <h3 style="text-transform:uppercase;text-align:center;padding:5px;">Material Receipt Note</h3>
    </div>
      
        <div class="div_second">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="13%"  class="f12" >Branch</td>
    <td width="20%" class="f11">: <?php echo $s->GetFieldValue('locations','loccode="'.$myrow['site'].'"','locationname')?></td>
    <td width="13%"  class="f12" >GRN No.</td>
    <td width="20%" class="f11">: <?php echo $myrow['MRNNo']?></td>
    <td width="13%"  class="f12" >GRN Date</td>
    <td class="f11">: <?php echo ConvertSQLDate($myrow['MRNVoucherDate']);?></td>
  </tr>
  <tr>
    <td  class="f12" >Store</td>
    <td class="f11">: <?php echo $s->GetFieldValue('storetype','id="'.$myrow['StoreCode'].'"','StoreName')?></td>
    <td  class="f12" >Receved Against</td>
    <td class="f11">: <?php echo $myrow['ReceivedAgainst']?></td>
    <td  class="f12" >Recevied From</td>
    <td class="f11">: <?php echo $s->GetFieldValue('suppliers','id="'.$myrow['ReceivedFrom'].'"','vendor_name')?></td>
  </tr>
  <tr>
    <td  class="f12" >PO Type</td>
    <td class="f11">: 
  <?php 
  if($myrow['Type'] == 'IO'){ echo "Import Order"; }
  else if($myrow['Type'] == 'DO'){ echo "Domestic Order"; }
  else if($myrow['Type'] == 'SO'){ echo "Service Order"; }
  else if($myrow['Type'] == 'AO'){ echo "Asset Order"; }
  ?>&nbsp;
  </td>
    <td  class="f12" >PO Category</td>
    <td class="f11">: 
  <?php 
  if($myrow['Po_category'] == 'AT'){ echo "Asset"; }
  else if($myrow['Po_category'] == 'MT'){ echo "Material"; }
  else if($myrow['Po_category'] == 'SV'){ echo "Service"; }
  ?>&nbsp;
  </td>
  <td  class="f12" >&nbsp;</td>
    <td class="f11">&nbsp;
    
  </td>
  </tr>
   <tr>
    <td  class="f12" >Document Type</td>
    <td class="f11">: 
  <?php 
  if($myrow['DocumentType'] == 'Challan'){ echo "Challan"; }
  else if($myrow['DocumentType'] == 'Bill'){ echo "Bill"; }
  ?>
  </td>
    <td  class="f12" >Document No.</td>
    <td class="f11">: <?php echo $myrow['BillNo']?></td>
    <td  class="f12" >Challan / Bill Date</td>
    <td class="f11">: <?php echo ConvertSQLDate($myrow['MRNVoucherDate']);?></td>
  </tr>
  <tr>
    <td  class="f12" >Gate Entry No.</td>
    <td class="f11">: <?php echo $myrow['GetPassNo']?></td>
    <td  class="f12" >Gate Entry Date</td>
    <td class="f11">: <?php echo ConvertSQLDate($myrow['gatepassdate']);?></td>
  <td  class="f12" >Vehicle No.</td>
    <td class="f11">: <?php echo $myrow['VehicleNo']?></td>
  </tr>
  <tr>
    <td  class="f12" >Receiving Time</td>
    <td class="f11">: 
  <?php 
  if($myrow['TimeIn'] == 'Day'){ echo "Day"; }
  else if($myrow['TimeIn'] == 'Night'){ echo "Night"; }
  ?>&nbsp;<?php echo $myrow['Timeout'];?>
  </td>
    <td  class="f12" >L R No.</td>
  <td class="f11">: <?php echo $myrow['LRno']?></td>
    <td  class="f12" >L R Date</td>
  <td class="f11">: <?php echo ConvertSQLDate($myrow['LRdate']);?></td>
  </tr>
  <tr>
    <td  class="f12">Form Type</td>
    <td class="f11">: <?php echo $myrow['form_type'];?></td>
    <td  class="f12" >Form No.</td>
  <td class="f11">: <?php echo $myrow['form_no']?></td>
    <td class="f12" >&nbsp;</td>
  <td class="f11">&nbsp;</td>
  </tr>
</table>
      </div>
      <div class="div_third">
        <table  width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <th width="4%" align="left" class="f12">S. No.</th>
    <th align="left" class="f12">Item Description</th>
    <th width="10%" align="left" class="f12">Item Code</th>
    <th width="6%" align="left" class="f12">UOM</th>
    <th width="8%" align="left" class="f12">Order Qty.</th>
    <th width="7%" align="left" class="f12">Bill Qty.</th>
    <th width="8%" align="left" class="f12">Received Qty.</th>
    <th width="9%" align="left" class="f12">Free Received</th>
    <th width="7%" align="left" class="f12">PO Rate</th>
    <th width="6%" align="left" class="f12">MRP</th>
    <th width="10%" align="left" class="f12">Short Qty. (if any)</th>
  </tr>
  <?php 
  $i=1;
  
  $excise='';
  $MRNDetails_Query=DB_query("select * from addmrnqty where issue_id='".$_REQUEST['mrnid']."'",$db);
 while($MrnDet_Row=DB_fetch_array($MRNDetails_Query))
 { 
 if($MrnDet_Row['reciveqty']!='0')
 {
 $excise=$excise+$MrnDet_Row['excise_val']+$MrnDet_Row['e_cess_val']+$MrnDet_Row['sah_val'];
 
 $basic=$basic+$MrnDet_Row['basic'];
 $po_rate = $s->GetFieldValue('purchorderdetails','parantId = "'.$myrow['order_no'].'" AND mst_itemid ="'.$MrnDet_Row['mst_itemid'].'"','Rate');
 ?> 
  <tr>
    <td class="f11"><?php echo $i;?></td>
    <td class="f11"><?php echo $s->GetFieldValue('item_master','id="'.$MrnDet_Row['mst_itemid'].'"','item_name');?></td>
    <td class="f11"><?php echo $s->GetFieldValue('item_master','id="'.$MrnDet_Row['mst_itemid'].'"','StockID');?></td>
    <td class="f11"><?php $unit= $s->getField('item_master','id',$MrnDet_Row['mst_itemid'],'mst_unitid');
  echo  $s->getField('unitsofmeasure','unitid',$unit,'unitname');?></td>
    <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['POQty'];?></td>
     <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['qty_as_per_bill'];?></td>
    <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['reciveqty']?></td>
    <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['free_qty']?></td>
    <td class="f11" style="text-align:right;"><?php echo ($po_rate!='')?$po_rate:$MrnDet_Row['purchase_rate']; ?></td>
    <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['mrprate']?></td>
    <td class="f11" style="text-align:right;"><?php echo $MrnDet_Row['short_accessid']?></td>
  </tr>
<?php $i++;} } ?>

	 <?php echo renderPOItemsTable($myrow['id']);
	 function renderPOItemsTable($poId) {
		   global $db;
           $html = '';
		   
		   $sql="SELECT IFNULL(NULLIF(total_Item_Amount,''),0) total_Item_Amount,IFNULL(NULLIF(tot_freight,''),0) tot_freight,IFNULL(NULLIF(vat_cst_val,''),0) vat_cst_val,IFNULL(NULLIF(insurancecharges_amt,''),0) insurancecharges_amt,IFNULL(NULLIF(othercharges,''),0) othercharges, round_off,IFNULL(NULLIF(grandtotal,''),0) grandtotal FROM addmrn WHERE id='$poId'";
		   $res=DB_query($sql,$db);$mresult=DB_fetch_assoc($res);
				
   	       $data2 = '';
   		   $data2 .= '<tr><td colspan="10" class="f11" align="right">Basic Amount</td><td class="f11" align="right">' . $mresult['total_Item_Amount'] . '</td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr >';
   		   $data2 .= '<td colspan="10"  class="f11" align="right">Freight And P&amp;S</td>';
   		   $data2 .= '<td class="f11" align="right">' . $mresult['tot_freight'] . '</td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr >';
   		   $data2 .= '<td colspan="10"  class="f11"align="right">GST</td>';
   		   $data2 .= '<td class="f11" align="right">' . $mresult['vat_cst_val'] . '</td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr >';
   		   $data2 .= '<td colspan="10"  class="f11"align="right">Insurance</td>';
   		   $data2 .= '<td class="f11" align="right">' . $mresult['insurancecharges_amt'] . '</td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr >';
   		   $data2 .= '<td colspan="10"  class="f11" align="right">Miscellaneous</td>';
   		   $data2 .= '<td class="f11"  align="right">' . $mresult['othercharges'] . '</td>';
   		   $data2 .= '</tr>';
   			
   			$data2 .= '<tr >';
   			$data2 .= '<td colspan="10"  class="f11" align="right">Round Off</td>';
   			$data2 .= '<td class="f11"  align="right">';
			$rf = ($mresult['round_off']!='')?explode('0.',$mresult['round_off']):array('+',0.0);
   			$data2 .= '' . $rf[0] . '' . $rf[1] . '</td></tr>';
   			
   			$data2 .= '<tr >';
   			$data2 .= '<td colspan="10" class="f11" align="right">Grand Total</td>';
   			$data2 .= '<td class="f11"  align="right">' . $mresult['grandtotal'] . '</td>';
   			$data2 .= '</tr>';
   			
   		    $html .= $data2;
   
           
           return $html;
       }?> </table>
        </div>
        <div class="div_forth">
          <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="50%"  class="f12">Qty. Checked by</td>
    <td  class="f12">Qty. Checked by</td>
  </tr>
  <tr>
    <td height="50" class="f11">Name</td>
    <td class="f11">Name</td>
  </tr>
  <tr>
    <td height="50" class="f11">Sign</td>
    <td class="f11">Sign</td>
  </tr>
  <tr>
    <td height="50" class="f11">Prepared by</td>
    <td class="f11">&nbsp;</td>
  </tr>
  <tr>
    <td height="50" class="f11">Checked by</td>
    <td class="f11">Approved by</td>
  </tr>
</table>

      </div>
</div>


</body>
</html>