<?php
include('../config/config.php');
include('../classes/classStoreItem.php');
include('../classes/classStoreItemReceiveInvoice.php');


/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;*/
if(isset($_POST['save_exit'])&&$_POST['save_exit']=='Save & Exit')
{
	unset($_SESSION['temp']);
	header("Location:mgmtreceiving.php");
}

if(isset($_GET['recinvoice_id']))
{
	$_SESSION['temp']['invoice_id'] = base64_decode($_GET['recinvoice_id']);
	header("Location:storerecinvvw.php");
}

if(isset($_SESSION['temp']['invoice_id'])&&$_SESSION['temp']['invoice_id']!='')
{
	$invoice_id = $_SESSION['temp']['invoice_id'];
}

################## Retrieve Data Start ####################################

try
{
	if(isset($invoice_id)&&$invoice_id!='')
	{
		$retrieveInvoiceOb = new classStoreItemReceiveInvoice;
		$retrieveInvoiceOb->setReceiveInvoiceID($invoice_id);
		$invoice_array = $retrieveInvoiceOb->retrieveInvoiceByID();
		$invoice_items_array = $retrieveInvoiceOb->retrieveInvoiceItems();
	}
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	
		


/*echo '<pre>';
print_r($product_array);
echo '</pre>';
exit;
*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><!-- InstanceBegin template="/Templates/print.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link rel="shortcut icon" href="../images/favicon.png">
    <title>Med2TEC Hospital Management Information System</title> 
    <link href="../css/print.css" rel="stylesheet">
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >  
    <script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="../datepicker/jquery-ui.js"></script> 
</head>

<body> 
<div align="right"> 
 <SCRIPT LANGUAGE="JavaScript">  
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script></div>

<section class="wrapper">
<div style="background:#FFF; padding:0px 0px 0; height:auto;">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
    <tbody>
      <tr>
        <td align="left" style="background:#fff;"><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></td>
      </tr>
    </tbody>
  </table>
  
</br>

</div>

<div class="row">
          <section class="panel">
            <header class="panel-heading">
              <h2><!-- InstanceBeginEditable name="title" --><!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
<title>Med2TEC Hospital Management Information System</title>
  <section id="main-content">
    <section class="wrapper">

      <!-- page start-->
       <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <div class="panel-body invoice">
                    
                    
                        <div class="invoice-header">
                            <div class="invoice-title col-md-3 col-xs-12">
                            	<h2>RECEIVE INVOICE</h2>
                            </div>
                        </div>
                        <?php
						if(isset($error_message)&&$error_message!='')
						{
							?>
                            <table>
							<tr>
								<td><span class="message_red"><?php echo $error_message;?></span></td>
							</tr>
                            <tr><td>&nbsp;</td></tr>
                            </table>
							<?php
						}
						?>
                        
                       <?php
						if(isset($invoice_id)&&$invoice_id!='')
						{
							?>
							<div id="result"></div>
                            
							<table width="100%" border="0" align="left" cellspacing="0" cellpadding="0">
								<tbody>
									
									<tr>
										<td width="10%">Invoice # :</td>
										<td><?php echo $invoice_id;?></td>
									</tr>
                                    
                                    <tr>
										<td>Invoice Date :</td>
										<td><?php echo date('d M Y',$invoice_array[0]['recinvoice_date']);?></td>
									</tr>
								</tbody>
								</table>
								
							
							
							<table class="bottomBorder" cellpadding="0" cellspacing="0" width="100%" >
                            
								<thead>
									<tr>
										<th width="5%">ID</th>
										<th width="45%">Item</th>
                                        <th width="10%" align="left">Expiry Date</th>
										<th width="8%" align="right">Qty</th>
									</tr>
								</thead>
								<tbody>
                               
                                <?php
								if(isset($invoice_items_array[0]['recitems_id'])&&$invoice_items_array[0]['recitems_id']!='')
								{
									for($ri=0;$ri<count($invoice_items_array);$ri++)
									{
										$singleItemOb = new classStoreItem;
										$singleItemOb->setStoreItemID($invoice_items_array[$ri]['storeitem_id']);
										$single_item_detail = $singleItemOb->retrieveStoreItemByID();
										
										?>
										<tr>
                                            
												<td><?php echo $invoice_items_array[$ri]['storeitem_id'];?></td>
                                                
												<td>
                                                	<h4><?php echo ucwords($single_item_detail[0]['storeitem_name']);?></h4>
													<span><?php echo $single_item_detail[0]['category'];?></span>
												</td>
                                                
                                                <td><?php if($invoice_items_array[$ri]['expiry_date']!=''){echo date('Y-m-d',$invoice_items_array[$ri]['expiry_date']);}?></td>
                                                
												<td align="right"><?php echo $invoice_items_array[$ri]['qty_received'];?></td>
                                                
												
											</tr>
                                            
                                       
											
										<?php
									}
								}
								?>  
                                
								</tbody>
							</table>

							
							<?php
						}
						else
						{
							
						}
						?>
                        
                    </div>
                </section>
            </div>
        </div>
      <!-- page end-->
    </section>
  </section>
  


    
<!-- InstanceEndEditable -->
</section>
</div>

<!--<p align="center" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:260px;"><strong><!--317 A-1, Nursery Stop, Township, Lahore. 
Ph: 042-35151666</strong><br />
For Appointment call at 042-35151666 (bring your Patient ID Card) </p>-->

   <div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color: rgb(0, 0, 0); text-align: right; font-size: 10px; margin-top: 4px; position: absolute; right: 180px;">© Software by Softusion Inc. 0322 6155 219</div>   
    </div>
</div>

<!--<div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color:#000; text-align:right; font-size:9px;">© Software designed by Softusion Inc. Contact us at 0322 6155 219</div>   
    </div>
</div>-->


          
</body>
<!-- InstanceEnd --></html>

  	
  	<script>
	
	$(function() {
		$( ".datepicker" ).datepicker({
		showOn: "button",
		changeMonth: true,
		changeYear: true,
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		dateFormat: "yy-mm-dd",
		minDate:"Today"
		});
	});
	
	</script>


  