<?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;
*/

$retrieveInvoiceOb = new classReceiveInvoice;
if(isset($_SESSION['print']['search_invoice_by_date'])&&$_SESSION['print']['search_invoice_by_date']!='')
{
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByDate($_SESSION['print']['search_invoice_by_date'],$_SESSION['security']['location_id']);
}
elseif(isset($_SESSION['print']['view'])&&$_SESSION['print']['view']=='all')

{
	$retrieveInvoiceOb->setLocationID($_SESSION['security']['location_id']);
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByLocationID();	
}
else
{
	$date = date('Y-m-d',time());
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByDate($date,$_SESSION['security']['location_id']);
}

$total_invoices = 0;
$total_payables = 0;
$total_payments = 0;
  
if(isset($invoice_array[0]['recinvoice_id'])&&$invoice_array[0]['recinvoice_id']!='')
{
 	for($int=0;$int<count($invoice_array);$int++)
	{
	  $total_invoices ++;
	  $total_payables += $invoice_array[$int]['amount_payable'];
	  $total_payments += $invoice_array[$int]['payment'];
	}
}

try
{
	$tranOb = new classTransaction;
	$account_data = $tranOb->retrieveAccountHeadAndAccountByID(3,4);	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}
/*echo '<pre>';
print_r($account_data);
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" -->INCOMING INVOICES<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
  
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td> <h1><?php echo date('d F Y',time());?></h1>
    <span>Time: <?php echo date('h:i A',time());?></span><br>
    <span>Total Invoices: <?php echo $total_invoices;?></span><br />
    <span>Total Payables: Rs. <?php echo number_format($total_payables,2);?></span></br>
    <span>Total Payments: Rs. <?php echo number_format($total_payments,2);?></span></td>
                 
  </tr>
</table>
<br>
<br>
           <?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
			}
			?><br />

                 <table  class="bottomBorder" cellpadding="0" cellspacing="0" width="100%">
                  <thead>
                    <tr>
                      <th width="7%" align="center">ID</th>
                      <th width="12%" align="center">Date</th>
                      <th width="16%" align="left">Supplier Name</th>
                      <th width="15%">Invoice Total</th>
                      <th width="5%">Discount</th>
                      <th width="18%" align="right">Amount Payable</th>
                      <th width="14%" align="right">Payment</th>
                      <th width="13%" align="right">Balance</th>
                      <th width="20%" align="center" class="hidden-phone">Status</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
				  if(isset($invoice_array[0]['recinvoice_id'])&&$invoice_array[0]['recinvoice_id']!='')
				  {
					  for($inv=0;$inv<count($invoice_array);$inv++)
					  {
						  if($inv%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
						  
						  $suppOb = new classProduct;
						  $supp_info = $suppOb->retrieveSupplierBySupplierID($invoice_array[$inv]['supplier_id']);
						  $supplier_name = $supp_info[0]['company_name'];
						 
						?>
						<tr class="<?php echo $class;?>">
                        
						  
                          
						  <td align="center"><?php echo $invoice_array[$inv]['recinvoice_id'];?></td>
                          
						  <td align="center"><?php echo date('d M Y',$invoice_array[$inv]['recinvoice_date']);?></td>
                          
						  <td><?php echo $supplier_name;?></td>
                          
                           <td align="right">Rs. <?php if($invoice_array[$inv]['invoice_amount']!=0){echo number_format($invoice_array[$inv]['invoice_amount'],2);}else{echo 0; }?></td>
                          
						  <td align="right"><?php echo $invoice_array[$inv]['discount'];?>%</td>
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['amount_payable']!=0){ echo number_format($invoice_array[$inv]['amount_payable'],2);}else{echo 0;}?></td>
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['payment']!=0){ echo number_format($invoice_array[$inv]['payment'],2);}else{echo 0;}?></td>
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['balance']!=0){echo number_format($invoice_array[$inv]['balance'],2);}else{echo 0;}?></td>
                          
						  <td align="center">
							<?php
                            if($invoice_array[$inv]['payment_status']=="paid") 
                            {
								?>
                                <span>Paid</span>
                                <?php 
                            }
							else
                            {
								?>
                                <p id="<?php echo $inv;?>"><span>Make Payment</span></p>
                                <?php 
                            }
                            ?>
                          
                          </td>
                          
						  
						</tr>
                        
                        <input type="hidden" name="recinvoice_id" class="set_to_pop" id="recinvoice_id_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['recinvoice_id'];?>">
                        <input type="hidden" name="supplier_id" class="set_to_pop" id="supplier_id_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['supplier_id'];?>">
                        <input type="hidden" name="amount_payable" class="set_to_pop" id="amount_payable_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['amount_payable'];?>">
						
						<?php
					  }
				  }
					else
					{
						?>
						<tr>
							<table>
								<tr>
									<td>No entries found.</td>
								</tr>
							</table>
						</tr>
						<?php
					}
				  ?>
                    
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>

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