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

try
{	
	$retrieveBalanceTrxOb = new classTransaction;

	if(isset($_SESSION['print']['search_trx_by_date'])&&$_SESSION['print']['search_trx_by_date']!='')
	{
		
		$trx_array = $retrieveBalanceTrxOb->retrieveTransactionDetailByDateAndPurpose($_SESSION['print']['search_trx_by_date'],'balance',$_SESSION['security']['location_id']);
	}
	else
	{
		$retrieveBalanceTrxOb = new classTransaction;
		$retrieveBalanceTrxOb->setTransactionPurpose('balance');
		$retrieveBalanceTrxOb->setLocationID($_SESSION['security']['location_id']);
		$trx_array = $retrieveBalanceTrxOb->retrieveTransactionByPurpose();
	}
	$total_trx = 0;
	$total_balance_received = 0;
	$total_balance_remaining = 0;
	
	if(isset($trx_array[0]['transact_id'])&&$trx_array[0]['transact_id']!='')
	{
	  
	  for($int=0;$int<count($trx_array);$int++)
	  {
		  $total_trx ++;
		  $total_balance_received += $trx_array[$int]['payment'];
		  $total_balance_remaining += $trx_array[$int]['balance'];
	  }
	}

}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}

/*echo '<pre>';
print_r($_POST);
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" -->BALANCE PAYMENTS<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
  
            <table width="100%" border="0" cellspacing="5" cellpadding="5">
              <tr>
              <td width="40%" align="right">

          		</td>
                <td width="10%" align="right">

                <div class="profile-nav alt">
                  <section class="panel">
                    <div class="user-heading alt clock-row terques-bg">
                      <h1><?php echo date('d F Y',time());?></h1>
                      <p class="text-left"><?php echo date('h:i A',time());?></p></br>
                      <p class="text-left"></p>
                      <span>Total Transactions: <div style="float:right;"><?php echo $total_trx;?></div></span></br>
                      <span>Balance Received: <div style="float:right;">Rs. <?php echo $total_balance_received;?></div></span></br>
                      <span>Balance Remaining: <div style="float:right;">Rs. <?php echo $total_balance_remaining;?></div></span>
                    </div>
                  </section>
                </div>

          		</td>
                
              </tr>
            </table>
            <br>
            <br>

                <table class="bottomBorder" cellpadding="0" cellspacing="0" width="100%">
                  <thead>
                    <tr>

           			 <th width="10%" align="center">Date</th>
            		 <th width="5%" align="center">ID</th>
            		 <th width="20%" align="left">Party Name</th>
           		 	 <th width="20%" align="left">Account</th>
            		 <th width="15%" align="center">Amount Payable</th>
            		 <th width="15%" align="center">Payment</th>
                     <th width="10%" align="center">Balance</th>
                    </tr>
                  </thead>
                  <tbody>
					<?php
                    if(isset($trx_array[0]['transact_id'])&&$trx_array[0]['transact_id']!='')
                    {
						for($trx=0;$trx<count($trx_array);$trx++)
						{
							if($trx%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
							 
							$tranOb = new classTransaction;
							$tranOb->setAccountID($trx_array[$trx]['account_id']);
							$account_data = $tranOb->retrieveAccountByID();	
							$acc_name = $account_data[0]['account_name'];
							
							if($trx_array[$trx]['supplier_id']!=0)
							{
								$supplier_id = $trx_array[$trx]['supplier_id'];
								
								$suppOb = new classProduct;
								$supp_info = $suppOb->retrieveSupplierBySupplierID($supplier_id);
								$name = $supp_info[0]['company_name'];
								
								$supplier_id = (base64_encode($supplier_id));
								
								$history = "<a href='patientsupplierbalance.php?supplier_id=$supplier_id'>Payment History</a>";
							}
							else
							{
							
								if($trx_array[$trx]['patient_id']!=0)
								{
									$patient_id = $trx_array[$trx]['patient_id'];
									$retrievePatientOb =  new classPatient;
									$retrievePatientOb->setPatientAutoID($patient_id);
									$patient_single_detail = $retrievePatientOb->retrievePatientByPatientID();
									
									$name = $patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname'];
									
									$patient_id = (base64_encode($patient_id));
								
									$history = "<a href='patientsupplierbalance.php?patient_id=$patient_id'>Payment History</a>";
								}
								else
								{
									$name = 'Out Door';
									$history = '';
								}
							}
							
							?>
							<tr class="<?php echo $class;?>">

								<td align="center"><?php echo date('d M Y',$trx_array[$trx]['transact_time']);?></td>
								<td align="center"><?php echo $trx_array[$trx]['transact_id'];?></td>
								<td align="left"><?php echo $name;?></td>
								<td align="left"><?php echo $acc_name;?></td>
								<td align="right" >Rs. <?php echo $trx_array[$trx]['amount_payable'];?></td>
								<td align="right" >Rs. <?php echo $trx_array[$trx]['payment'];?></td>
								<td align="right">Rs. <?php echo $trx_array[$trx]['balance'];?></td>
							</tr>
							<?php
						}
                    }
					else
				  	{
					?>
					<tr>
                        
					</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>