<?php 
require('../db/db.php');
/*echo '<pre>';
print_r($_POST);
echo '</pre>';*/

$dateto=$_SESSION['dateto'];
$datefrom=$_SESSION['datefrom'];

?>

<!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" -->SALE INVOICES<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <div class="content">
   <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
   <p 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>  
            </p>
  <tr>
    <td align="right"><table width="100%" border="0" cellspacing="1" cellpadding="0" class="bottomBorder">
      <tr>
        <td valign="bottom"><h1>PHARMACY CASH REPORT</h1></td>
        <td align="right" valign="top">&nbsp;</td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td width="511"><table width="100%">
    
      <tr>
        <td>
        Date To:
        <?php echo $dateto;?>
        </td>
        
      </tr>
      <tr>
      <td>
         Date From:
       <?php echo $datefrom;?>
        </td>
      </tr>
      <tr>
        <td><table width="100%" border="0" class="rounded_corners">
         <?php 
		  $raw_result2 = mysql_query("SELECT * FROM accheads WHERE acchead_id=3") or die(mysql_error()); 
	 		while($row2 = mysql_fetch_array($raw_result2))
			{	
				$accheadid=$row2['acchead_id'];	  
				?>
				  <tr>
					<td><h2><?php echo $row2['acchead_id']."000 - ".$row2['acchead_name'];?></h2>
					</td>
				  </tr>
				  <tr>
					<td><table width="100%" border="0" class="bottomBorder">
					  <tr>
						<td width="5%"><h3>ID</p></h3></td>
						<td width="35%"><h3>Account</p></h3></td>
						<td width="20%" align="center"><h3>Expense</br>(Rs.)</h3></td>
						<td width="20%" align="center"><h3>Income</br>(Rs.)</h3></td>
						<td width="20%" align="center"><h3>Balance</br>(Rs.)</h3></td>
						</tr>
					  </table></td>
					</tr>
				  <tr>
					<td><table width="100%" border="0">
					<tr>
						<td><table width="100%" border="0" class="bottomBorder">
                        <tr>
                            <td width="5%"></td>
                            <td width="35%">OPENING BALANCE<p></td>
                            <td width="20%" align="center"></td>
                            <td width="20%" align="center"></td>
                            <td width="20%" align="right">0.00</td>
                        </tr>
                        <?php 
                        $raw_result3 = mysql_query("SELECT * FROM accounts WHERE acchead_id='$accheadid'") or die(mysql_error()); 
                        while($row3 = mysql_fetch_array($raw_result3))
                        {
                            $accountid=$row3['account_id']; 
                            ?>
                            <tr>
                            <td width="5%"><?php echo $row2['acchead_id']."00".$row3['account_id'];?></td>
                            <td width="35%"><?php echo $row3['account_name'];?></td>
                            
                            <?php 
							$raw_result4 = mysql_query("SELECT sum(payment) FROM transactions WHERE account_id='$accountid' AND transact_type='Expense' AND date(transact_time) between date('$dateto') and date('$datefrom')") or die(mysql_error()); 
                            while($row4 = mysql_fetch_array($raw_result4))
                            {
                                ?>
                                <td width="20%" align="center"><?php echo number_format($row4['sum(payment)'],2); ?></td>
                                
                                <td width="20%" align="center">
                                    <?php 
                                    $accountid=$row3['account_id'];
                                    $raw_result5 = mysql_query("SELECT sum(payment) FROM transactions WHERE account_id='$accountid' AND transact_type='Income' AND date(transact_time) between date('$dateto') and date('$datefrom') ") or die(mysql_error()); 
                                    while($row5 = mysql_fetch_array($raw_result5))
                                    {  
                                        echo number_format($row5['sum(payment)'],2); 
                                    }
                                    ?>
                                </td>
                                <?php
                            }
                            ?>
                            </tr>
                            <?php
                        }
                        ?>
                        </table></td>
					</tr>
					<tr>
					<td><table width="100%" border="0" class="topline_table">
					<tr>
                        <td width="5%">&nbsp;</td>
                        <td width="35%" align="right"><strong>TOTAL</strong></td>
                        
                        <?php
                        $raw_result6 = mysql_query("SELECT sum(payment) FROM transactions WHERE acchead_id='$accheadid' AND transact_type='Expense' AND date(transact_time) between date('$dateto') and date('$datefrom') ") or die(mysql_error()); 
                        while($row6 = mysql_fetch_array($raw_result6))
                        {
                            ?>
                            <td width="20%" align="center"><strong> <?php echo number_format($row6['sum(payment)'],2); ?></strong></td>
                            
                            <td width="20%" align="center"><strong>
                                <?php
                                $raw_result7 = mysql_query("SELECT sum(payment) FROM transactions WHERE acchead_id='$accheadid' AND transact_type='Income' AND date(transact_time) between date('$dateto') and date('$datefrom')") or die(mysql_error()); 
                                while($row7 = mysql_fetch_array($raw_result7))
                                {
                                    echo number_format($row7['sum(payment)'],2);  
                                }
                                ?>
                            </strong></td>
                            <?php
                        }
                        ?>
                    </tr>
					<tr>
                        <td width="5%"></td>
                        <td width="35%"><p>CLOSING BALANCE<p></td>
                        <td width="20%" align="center"></td>
                        <td width="20%" align="center"></td>
                        <td width="20%" align="right">0.00</td>
					</tr>
					</table></td>
					</tr>
				   	</table></td>
				</tr>
            	<?php 
			}
			?>
          </table></td>
      </tr>
    
      </table></td>
  </tr>
  </table>
  </div>
  	<script src="../js/jquery-1.9.1.js"></script>
	<script src="../js/jquery-ui.js"></script>
      
    <script>
    $("#datepickerreport1").datepicker({
    showOn: "button",
    buttonImage: "../images/calendar.png",
    buttonImageOnly: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
   /* showButtonPanel: true, */
    });
	$("#datepickerreport2").datepicker({
    showOn: "button",
    buttonImage: "../images/calendar.png",
    buttonImageOnly: true,
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
   /* showButtonPanel: true, */
    });
	</script>
  <!-- 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>
