<?php
include('../config/config.php');
include('../classes/classProduct.php');
include('../classes/classReceiveInvoice.php');
include('../classes/classProductClosingReconcilation.php');

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







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

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



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

try
{
	$retrieveOb = new classProduct;
	
	///////////// retrieve supplliers ////////////////////////////////////////
	
	$retrieveOb->setLocationID($_SESSION['security']['location_id']);
	$suppliers_array = $retrieveOb->retrieveSuppliers();
	
	///////////// retrieve suppllier products ///////////////////////////////
	
	if(isset($supplier_id)&&$supplier_id!='')
	{
		$retrieveOb->setSupplierID($supplier_id);
		$product_array = $retrieveOb->retrieveProductSupplierDataBySupplierID();
		$supplier_single_detail = $retrieveOb->retrieveSupplierBySupplierID($supplier_id);
	}
	
	if(isset($invoice_id)&&$invoice_id!='')
	{
		$retrieveInvoiceOb = new classReceiveInvoice;
		$retrieveInvoiceOb->setReceiveInvoiceID($invoice_id);
		$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetail();
		$invoice_items_array = $retrieveInvoiceOb->retrieveInvoiceItemsDetail();
	}
	
}
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"><!-- 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" -->RECEIVE INVOICE<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->


                    
                        <?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($_SESSION['temp']['supplier_id'])&&$_SESSION['temp']['supplier_id']!='')
						{
							?>
							<div id="result"></div>
                            
							<table width="100%" border="0" align="left" cellspacing="0" cellpadding="0">
								<tbody>
									<tr>
										<td width="10%">Company :</td>
										<td width="90%"><?php echo $supplier_single_detail[0]['supplier_name']?></td>
									</tr>
									<tr>
										<td>Address :</td>
										<td><?php echo $supplier_single_detail[0]['supplier_address']?></td>
									</tr>
									<tr>
										<td>Phone :</td>
										<td><?php echo $supplier_single_detail[0]['company_phone']?></td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
									</tr>
									<tr>
										<td>Invoice # :</td>
										<td><?php echo $invoice_id;?></td>
									</tr>
								</tbody>
								</table>
								
							<table width="100%" border="0">
								<tr>
									<td width="47%">&nbsp;</td>
									<td width="9%"></td>
								</tr>
							</table>
							
							<table  class="bottomBorder" cellpadding="0" cellspacing="0" width="100%">
								<thead>
									<tr>
										<th width="5%">ID</th>
										<th width="20%">Product</th>
                                        <th width="9%" class="text-center">Expiry Date</th>
										<th width="11%" class="text-center">Packing</th>
                                        <th width="17%" class="text-center">Trade Price per Unit</th>
										<th width="8%" class="text-center">Qty</th>
										<th width="10%" class="text-center">Total</th>
										<th width="10%"class="text-center">Discount</th>
										<th width="10%" class="text-center">Net Total</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++)
									{
										$singleProdOb = new classProduct;
										$singleProdOb->setProductID($invoice_items_array[$ri]['product_id']);
										$single_prod_detail = $singleProdOb->retrieveProductByProductID();
										
										?>
											<tr>
                                            
												<td><?php echo $invoice_items_array[$ri]['product_id'];?></td>
                                                
												<td>
                                                	<h4><?php echo $single_prod_detail[0]['product_name'];?></h4>
													<p><?php echo $single_prod_detail[0]['medicine_type'];?></p>
												</td>
                                                
                                                <td><?php if($invoice_items_array[$ri]['expiry_date']!=''){echo date('Y-m-d',$invoice_items_array[$ri]['expiry_date']);}?></td>
                                                
												<td class="text-center"><?php echo $invoice_items_array[$ri]['packing_type'];?></td>
                                                
												<td class="text-right"><?php echo "Rs. ".number_format($invoice_items_array[$ri]['trade_price'],2);?></td>
                                                
												<td class="text-center"><?php echo $invoice_items_array[$ri]['qty_received'];?></td>
                                                
												<td class="text-right">
													<?php 
                                                    if ($invoice_items_array[$ri]['packing_type']=='Unit/Tablets') 
                                                    { 
                                                        $total = $invoice_items_array[$ri]['trade_price']*$invoice_items_array[$ri]['qty_received'];
                                                    } 
                                                    elseif ($invoice_items_array[$ri]['packing_type']=='Leaf') 
                                                    {  
                                                        $total = $invoice_items_array[$ri]['trade_price']*$invoice_items_array[$ri]['qty_received'];
                                                    } 
                                                    elseif ($invoice_items_array[$ri]['packing_type']=='Box/Pack') 
                                                    { 
                                                        $total = $invoice_items_array[$ri]['trade_price']*$invoice_items_array[$ri]['qty_received'];
                                                    }
                                                    else
                                                    {
                                                        $total = 0;
                                                    }
                                                    
                                                   ?><?php echo "Rs. ".number_format($total,2);?></td>
                                                
												<td class="text-center"><?php echo $invoice_items_array[$ri]['discount']." %";?></td>
                                                
												<td class="text-right"><?php echo "Rs. ".number_format($invoice_items_array[$ri]['net_total'],2);?></td>
                                                
											</tr>
                                            
                                            
                                            
                                            <input name="product_id[]" class="product_id" id="product_id_<?php echo $ri;?>" value="<?php echo $single_prod_detail[0]['product_id'];?>" type="hidden" size="5"/>
                                            
                                            <input name="recitems_id[]" class="recitems_id" id="recitems_id_<?php echo $ri;?>" value="<?php echo $invoice_items_array[$ri]['recitems_id'];?>" type="hidden" size="5"/>
											
										<?php
									}
								}
								?>  
                                
								</tbody>
							</table>
                           
							
								
								<div style="float:right; text-align:right;">
									<ul>
										<li>Sub-Total: Rs. <span id="invoice_amount"><?php echo number_format($invoice_array[0]['invoice_amount'],2);?></span></li>
										<li>Discount: <?php echo $invoice_array[0]['discount']." %";?>
                                        </li>
										<!--<li>TAX (15%) ----- </li>-->
										<li class="grand-total">Grand Total: Rs. <span id="amount_payable"><?php echo number_format($invoice_array[0]['amount_payable'],2);?></span></li>
									</ul>
								</div>
						
						  
							
                            
                            <!--<div class="col-md-9 payment-method">
									<h4>Payment Details</h4>
									<p>1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
									<p>2. Pellentesque tincidunt pulvinar magna quis rhoncus.</p>
									<p>3. Cras rhoncus risus vitae congue commodo.</p>
									<br>
									<h3 class="inv-label itatic">Thank you for your business</h3>
								</div>-->
							
							<?php
						}
						else
						{
							?>
                            
                            <?php
						}
						?>
                        


            <div class="col-md-9 payment-method" style="font-size:12px;">
            <h4>Payment Details</h4>
            <p>1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
            <p>2. Pellentesque tincidunt pulvinar magna quis rhoncus.</p>
            <p>3. Cras rhoncus risus vitae congue commodo.</p>
            <br>
            <h3 class="inv-label itatic">Thank you for your business</h3>
            </div>        
      <!-- page end-->
  <!-- page end-->

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