<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>
<script type="text/javascript">
 
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>
      <div class="page-wrapper">
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body" id="printableArea">
 

<form method="post">
		<div class="panel">
			<div class="panel-heading" style="font-style: bold">Trial Balance </div>
				<p>&nbsp;</p>
                    <table width="100%" class="table table-bordered">
                     <tr height="32" align="left">
			            <th nowrap="nowrap" width="35%" rowspan="2">Particular</th>
						<th nowrap="nowrap" width="17%" colspan="2" style="text-align: center;">Closing Balance</th>
					</tr>
                    <tr>
                        
                        <th nowrap="nowrap" width="35%" colspan="1">Debit(Amount)</th>
                        <th nowrap="nowrap" width="35%" colspan="1">Credit(Amount)</th>
                    </tr>
<?php  
// 
$sql_tri = "SELECT sum(Cr_Amt) as Cr_amt FROM tbl_account
WHERE session_login_id = '".$_SESSION['login_id']."' and  Cash_type='Debit';
";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$cash = $row["Cr_amt"];
?>
<?php
 $sql_cash_sale="select sum(dr_amount) as cash_amount from cash_detail where session_login_id = '".$_SESSION['login_id']."' and sales_type='sale'";
$res_cash_sale=mysql_query($sql_cash_sale);
$rows=mysql_fetch_assoc($res_cash_sale);
$sale_amt=$rows["cash_amount"];
$sale_der=$cash+$sale_amt;

?>
<?php 
$sql_bank_pay="SELECT sum(dr_amount) as dr_amount from supplier_details where session_login_id = '".$_SESSION['login_id']."' and sales_type='Payment_creditor'";
$res_bank_pay=mysql_query($sql_bank_pay);
$count=mysql_fetch_assoc($res_bank_pay);
$bank_account=$count["dr_amount"]; 
?>
<?php
$sql_cash_on_hand="select sum(Cr_Amt) as Cr_Amt from tbl_account where session_login_id = '".$_SESSION['login_id']."' and sales_type='Sales' and payment_mode='cash'";
$res_cash_on_hand=mysql_query($sql_cash_on_hand);
$count_on=mysql_fetch_assoc($res_cash_on_hand);
$cash_on=$count_on["Cr_Amt"];

$sql_cash_on_hand1="select sum(Dr_Amt) as Dr_Amt from tbl_account where session_login_id = '".$_SESSION['login_id']."' and sales_type='Purchase' and payment_mode='cash'";
$res_cash_on_hand1=mysql_query($sql_cash_on_hand1);
$count_on1=mysql_fetch_assoc($res_cash_on_hand1);
$cash_on1=$count_on["Cr_Amt1"];

$sale_der1=$sale_der+$cash_on1+$cash_on;

?>


                    <tr height="32">
                        <td nowrap="nowrap" width="6%">Current Assets</td>
                        <td nowrap="nowrap" width="6%"><?php echo $sale_der1
                        ; ?></td>
                        <td nowrap="nowrap" width="6%"><?php echo $bank_account; ?></td>
                    </tr>
<?php  
 $sql_tri = "SELECT sum(cr_amount) as Cr_amt FROM supplier_details
WHERE session_login_id = '".$_SESSION['login_id']."' and sales_type IN (SELECT sales_type FROM tbl_account WHERE session_login_id = '".$_SESSION['login_id']."' and sales_type='Purchase');
";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$cash1 = $row["Cr_amt"];

 $sql_tri1 = "SELECT sum(Cr_Amt) as Cr_amt FROM tbl_account
WHERE session_login_id = '".$_SESSION['login_id']."' and sales_type='Purchase Return';
";
$res_tri1 = mysql_query($sql_tri1);
$row1 = mysql_fetch_assoc($res_tri1);
$cash31 = $row1["Cr_amt"];

$lib_total=$cash1+$cash31;
?>


                    <tr height="32">
                        <td nowrap="nowrap" width="6%">Current Liablities</td>
                        <td nowrap="nowrap" width="6%"></td>
                        <td nowrap="nowrap" width="6%"><?php echo $lib_total; ?></td>
                    </tr>

<?php  
$sql_tri = "SELECT * FROM tbl_account WHERE sales_type='Purchase' and session_login_id = '".$_SESSION['login_id']."'";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$sales_type = $row["sales_type"];

?>

					<tr height="32">
            			<td nowrap="nowrap" width="6%"><?php echo $sales_type; ?></td>
<?php  
 $sql_tri = "SELECT sum(Dr_Amt) as Dr_amt FROM tbl_account
WHERE session_login_id = '".$_SESSION['login_id']."' and sales_type='Purchase';
";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$cash3 = $row["Dr_amt"];

 $sql_tri1 = "SELECT sum(Cr_Amt) as Cr_amt FROM tbl_account
WHERE session_login_id = '".$_SESSION['login_id']."' and sales_type='Purchase Return';
";
$res_tri1 = mysql_query($sql_tri1);
$row1 = mysql_fetch_assoc($res_tri1);
$cash32 = $row1["Cr_amt"];

$P_Total=$cash3+$cash32;
?>

            			<td nowrap="nowrap" width="6%"><?php echo $P_Total; ?></td>
                        <td nowrap="nowrap" width="6%"></td>
            		</tr>

 <?php  
 // here sale account shown
$sql_tri = "SELECT * FROM tbl_account WHERE sales_type='Sales' and session_login_id = '".$_SESSION['login_id']."'";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$sales_type1 = $row["sales_type"];
?>
              
                    <tr height="32">
                        <td nowrap="nowrap" width="6%"><?php echo $sales_type1; ?></td>
<?php  
 $sql_tri = "SELECT sum(Dr_Amt) as  Dr_Amt FROM tbl_account
WHERE session_login_id = '".$_SESSION['login_id']."' and  Cash_type='Debit';
";
$res_tri = mysql_query($sql_tri);
$row = mysql_fetch_assoc($res_tri);
$cash2 = $row["Dr_Amt"];

 $sql_sal = "SELECT sum(dr_amount) as  dr_amount FROM cash_detail where sales_type='sale' and session_login_id = '".$_SESSION['login_id']."'";
$res_sal = mysql_query($sql_sal);
$rowsal = mysql_fetch_assoc($res_sal);
$cashsal = $rowsal["dr_amount"];

$sal_tot=$cash2+$cashsal;
?>

                        <td nowrap="nowrap" width="6%"></td>
                        <td nowrap="nowrap" width="6%"><?php echo $sal_tot; ?></td>
                    </tr>
   <?php $d_total= $P_Total+$sale_der1?>
  <?php $sales_credit = $bank_account+$sal_tot+$lib_total; ?>
  <?php $sale_difference=$d_total-$sales_credit ?>
  <?php $after_diff=$sale_difference+$sales_credit ?>
                    <tr height="32">
                        <td colspan="2" width="18%" style="font-weight: bold; text-align: right">Difference in Opening Balance</td>
                        <td nowrap="nowrap" width="6%"><?php echo $sale_difference; ?></td>
                    </tr>
                    <tr height="32">
                        <td nowrap="nowrap" width="6%" style="font-weight: bold">Ground Total</td>
                        <td nowrap="nowrap" width="6%"><?php echo  $d_total; ?></td>
                        <td nowrap="nowrap" width="6%"><?php echo  $after_diff; ?></td>
                    </tr>
            	</table>
</form>
</div>
<br />
<br /><br /><br /><br />
<div align="center"><span class="btn btn-info" onClick="printDiv('printableArea')">Print</span></div>

  </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>
 <script src="../js/lib/datatables/datatables.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="../js/lib/datatables/cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <script src="../js/lib/datatables/datatables-init.js"></script>