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

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



################## Create Invoice Start ####################################

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']);
	header("Location:pharmsupplierrefund.php");
}

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 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();
		$sumOfRefundItems = $retrieveInvoiceOb->retrieveSumOfRefundItems();
		$amount_payable = $sumOfRefundItems-($sumOfRefundItems*$invoice_array[0]['discount']/100);
		$invoice_items_array = $retrieveInvoiceOb->retrieveInvoiceItemsDetail();
	}
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	
		
try
{
	$tranOb = new classTransaction;
	$account_data = $tranOb->retrieveAccountHeadAndAccountByID(3,4);	
}
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" -->REFUND PRODUCT INVOICE<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
              <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
              <span class="message_red"><?php echo $error_message;?></span>
              <?php
			}
			?>

<section class="wrapper">

      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
            <div class="panel-body">
              
              				<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tbody>
									<tr>
										<td width="14%">Company :</td>
										<td width="86%"><?php echo $supplier_single_detail[0]['company_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>Invoice # :</td>
										<td><?php echo $invoice_id;?></td>
									</tr>
								</tbody>
								</table>
								
							<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bottomBorder">
								<thead>
									<tr>
										<th width="5%">ID</th>
										<th width="27%">Product</th>
                                       	<th width="10%" class="text-center">Packing</th>
                                        <th width="12%" class="text-center">Trade Price per Unit</th>
										<!--<th width="8%" class="text-center">Qty</th>-->
                                        <th width="8%" class="text-center">Refund 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();
										
										$remaining_qty = $invoice_items_array[$ri]['qty_received']-$invoice_items_array[$ri]['refund_qty'];
										if($remaining_qty==0)
										{
											$style = "text-decoration:line-through;";
										}
										else
										{
											$style='';
										}
										
										?>
                                        <tr style=" <?php echo $style;?> ">
                                        
                                        <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 class="text-center"><?php echo $invoice_items_array[$ri]['packing_type'];?></td>
                                        
                                        <td class="text-center"> Rs. <?php echo $invoice_items_array[$ri]['trade_price'];?></td>
                                        
                                        <?php /*?><td class="text-center"><?php echo $remaining_qty;?></td><?php */?>
                                        
                                        <td class="text-center"><?php echo $invoice_items_array[$ri]['refund_qty'];?></td>
                                        
                                        <td class="text-center">
                                        <?php $total = $invoice_items_array[$ri]['trade_price']*$invoice_items_array[$ri]['refund_qty'];?>Rs. <span id="refund_total_<?php echo $ri;?>"><?php echo $total;?></span> 
                                        </td>
                                        
                                        <td class="text-center"><?php echo $invoice_items_array[$ri]['discount'].'%';?></td>
                                        
                                        <td class="text-right">
                                        <?php
                                        
										if(isset($invoice_items_array[$ri]['refund_amount'])&&$invoice_items_array[$ri]['refund_amount']!='')
										{ 
											$net_total = number_format($invoice_items_array[$ri]['refund_amount'],2);
										
										}
										else
										{
											$net_total=0;
										}
										?>
                                        Rs. <span id="refund_net_total_<?php echo $ri;?>"><?php echo $net_total;?></span></td>
                                        
                                        </tr>
                                            
                                        <?php
									}
								}
								?>  
                                
								</tbody>
							</table>
                           
							<div class="row" style="float:right;">
							<div class="col-md-3 invoice-block pull-right">
                                <ul class="unstyled amounts">
                                
                                    <li>Sub-Total: Rs. <span id="invoice_amount_static"><?php if($sumOfRefundItems!=''){ echo number_format($sumOfRefundItems,2);}?></span></li>
                                    
                                    <li>Discount Returns: <?php echo $invoice_array[0]['discount'].'%';?></li>
                                   
                                    <li class="grand-total">Grand Total: Rs. <span id="amount_payable"><?php if($invoice_array[0]['amount_payable']!=''){echo number_format($amount_payable,2);}?></span></li>
                                    
                                </ul>
                            </div>
							</div>
                
              
            </div>
          </section>
        </div>
      </div>
      <!-- page end-->
    </section>
  <!-- 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>