BBnepal-Accounts/account/application/views/accounts/cash_flow.php

514 lines
28 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<?php
$this->load->library("BIBAccounts");
$BIBAccounts = new BIBAccounts();
?>
<?php
$IncomeAccounts = $this->acc->getAccountsByGroup(3);
$ExpenseAccounts = $this->acc->getAccountsByGroup(4);
$IncomesTotal = $this->acc->getAccountBalanceByGroup(3);
$ExpensesTotal = $this->acc->getAccountBalanceByGroup(4);
$PL = $IncomesTotal - $ExpensesTotal;
?>
<style>
table,
td,
tr {
padding: 0px;
margin: 0px;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.group-name {
width: 40%;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.group-total {
width: 10%;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.table-gray {
background-color: #eee;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.table td,
.table th {
padding: 0px;
margin: 0px;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.bg-darker {
background-color: #ddd;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
td .table {
border: 0px !important;
margin-bottom: 0rem;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
table td:first-child {
padding-left: 5px;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.table-bordered.vertical-borders td,
.table-bordered.vertical-borders th {
border-left: 1px solid #dee2e6;
border-right: 1px solid #dee2e6;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.table-bordered.vertical-borders thead th {
padding: 0.25rem;
border-top: none;
border-bottom: 2px solid #dee2e6;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.table-bordered.vertical-borders tfoot th {
padding: 0.25rem;
border-top: 2px solid #dee2e6;
border-bottom: none;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.currency {
font-weight: normal !important;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.underline {
text-decoration: underline;
}
2024-08-14 15:54:12 +00:00
2024-07-10 12:43:19 +00:00
.form-control {
display: block;
width: 100%;
height: calc(1.5rem + 1px);
padding: 0.375rem 0.75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
box-shadow: inset 0 0 0 transparent;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
2024-08-26 07:51:59 +00:00
.table1 {
border: 0px !important;
padding: 0;
margin: 10 !important;
width: 100%;
vertical-align: middle;
}
.table-responsive {
overflow-x: auto;
}
.card-body {
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
min-height: 1px;
padding: 0;
}
2024-09-30 10:24:29 +00:00
2024-08-26 07:51:59 +00:00
table {
2024-09-30 10:24:29 +00:00
border: 1px solid #ddd;
border-collapse: collapse;
}
.card-body.p-0 .table tbody>tr>td:last-of-type,
.card-body.p-0 .table tbody>tr>th:last-of-type,
.card-body.p-0 .table tfoot>tr>td:last-of-type,
.card-body.p-0 .table tfoot>tr>th:last-of-type,
.card-body.p-0 .table thead>tr>td:last-of-type,
.card-body.p-0 .table thead>tr>th:last-of-type {
padding-right: 0 !important;
}
.text-bold {
font-weight: 900;
}
2024-07-10 12:43:19 +00:00
</style>
<div class="content-wrapper">
<section class="content">
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-header ">
2024-08-08 12:39:25 +00:00
<h3 class="card-title mt-1">Cash Flow<?php //echo $pageTitle;
2024-08-14 15:54:12 +00:00
?> </h3>
2024-07-10 12:43:19 +00:00
<div class="card-tools">
2024-09-30 10:24:29 +00:00
<form method="post" action=<?php echo base_url('accounts/reports/cash_flow'); ?> id="FilterForm">
<!-- button with a dropdown -->
<div class="btn-group">
<button type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown" data-offset="-52">
Filters
</button>
<div class="dropdown-menu" role="menu">
<div class="form-group p-2 pb-0">
<div class="col">
<div class="form-group">
<label for="fromDate"><?php myLang("Starting Period"); ?></label>
2024-08-14 15:54:12 +00:00
<input type="text" class="form-control " name="fromDate" value="<?php echo (isset($_POST['fromDate'])) ? $_POST['fromDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_from); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="fromDate" aria-describedby="helpId_fromDate" placeholder="Starting Period">
</div>
<div class="form-group">
<label for="toDate"><?php myLang("Ending Period"); ?></label>
2024-08-14 15:54:12 +00:00
<input type="text" class="form-control " name="toDate" value="<?php echo (isset($_POST['toDate'])) ? $_POST['toDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_to); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="toDate" aria-describedby="helpId_toDate" placeholder="Ending Period">
</div>
</div>
<div class="dropdown-divider"></div>
2024-08-14 15:54:12 +00:00
<!-- <div class="form-check">
<input class="form-check-input" type="checkbox">
<label class="form-check-label">Select
All</label>
2024-08-14 15:54:12 +00:00
</div> -->
<div class="form-check">
2024-08-14 15:54:12 +00:00
<!-- <input type="hidden" name="showOB" value="not"> -->
<input type="checkbox" class="form-check-input " name="showOB" id="showOB" aria-describedby="helpId_showOB" placeholder="Show Opening Balance" <?php echo (isset($_POST['showOB'])) ? "CHECKED" : ""; ?>>
<!-- <input class="form-check-input" type="checkbox"> -->
2024-08-14 15:54:12 +00:00
<label class="form-check-label" for="showOB">Opening</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox"> -->
<input type="checkbox" class="form-check-input " name="showClosing" id="showClosing" aria-describedby="helpId_showClosing" placeholder="Show Closing Balance" <?php echo (isset($_POST['showClosing'])) ? "CHECKED" : ""; ?>>
2024-08-14 15:54:12 +00:00
<label class="form-check-label" for="showClosing">Closing</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox" checked> -->
<input type="checkbox" class="form-check-input" name="showPeriod" id="showPeriod" aria-describedby="helpId_showPeriod" placeholder="Show Periodic Balance" <?php echo (isset($_POST['showPeriod'])) ? "CHECKED" : "CHECKED"; ?>>
2024-08-14 15:54:12 +00:00
<label class="form-check-label" for="showPeriod">Period</label>
</div>
</div>
<div class="dropdown-divider"></div>
2024-08-14 15:54:12 +00:00
<div class="form-group p-2 pb-0 text-right">
<button type="button" class="btn btn-info btn-sm " style="width:60px;height:30px;" onclick="resetForm()">Reset</button>
<button type="submit" class="btn btn-primary mr-2 btn-sm" style="width:60px;height:30px;">Search </button>
2024-08-08 12:39:25 +00:00
</div>
</div>
</div>
<div class="btn-group">
2024-09-30 10:24:29 +00:00
<!-- <button type="submit" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
Export
2024-09-30 10:24:29 +00:00
</button> -->
<button type="submit" id="downloadCsv" class="btn btn-warning btn-sm ">
Export csv
</button>
<!-- <div class="dropdown-menu" role="menu">
<a href="#" class="dropdown-item">Export</a>
<a href="#" class="dropdown-item">Pdf</a>
<div class="dropdown-divider"></div>
<a href="#" class="dropdown-item">View calendar</a>
</div> -->
</div>
2024-08-14 08:11:37 +00:00
<button class="btn btn-secondary toggle-collapse btn-sm" id="toggleShowAll">Toggle Collapse</button>
2024-08-08 12:39:25 +00:00
<!-- <button type="button" class="btn btn-warning btn-sm" onclick="resetForm()">Reset</button> -->
<!-- <button class="btn btn-secondary toggle-collapse btn-sm" id="toggleShowAll">Toggle Collapse</button> -->
</form>
<script>
function resetForm() {
document.getElementById("fromDate").value = "<?php echo NepaliDate($this->session->FiscalYear->fiscalyear_from); ?>";
document.getElementById("toDate").value = "<?php echo NepaliDate($this->session->FiscalYear->fiscalyear_to); ?>";
document.getElementById("showOB").checked = <?php echo "false"; ?>;
document.getElementById("showClosing").checked = <?php echo "false"; ?>;
document.getElementById("FilterForm").submit();
}
</script>
2024-07-10 12:43:19 +00:00
</div>
<!-- /.card-tools -->
</div>
<!-- <div class="card-body">
2024-07-10 12:43:19 +00:00
<form method="post" action="" id="FilterForm">
<div class="row align-items-end">
<div class="col-2">
<div class="form-group">
<label for="fromDate"><?php myLang("Starting Period"); ?></label>
<input type="text" class="form-control nepaliDatePicker" name="fromDate" value="<?php echo (isset($_POST['fromDate'])) ? $_POST['fromDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_from); ?>" id="fromDate" aria-describedby="helpId_fromDate" placeholder="Starting Period">
</div>
</div>
<div class="col-2">
<div class="form-group">
<label for="toDate"><?php myLang("Ending Period"); ?></label>
<input type="text" class="form-control nepaliDatePicker" name="toDate" value="<?php echo (isset($_POST['toDate'])) ? $_POST['toDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_to); ?>" id="toDate" aria-describedby="helpId_toDate" placeholder="Ending Period">
</div>
</div>
<div class="col-1 text-center">
<div class="form-group">
<label for="showOB"><?php myLang("Opening"); ?></label>
<input type="checkbox" class="form-control " name="showOB" id="showOB" aria-describedby="helpId_showOB" placeholder="Show Opening Balance" <?php echo (isset($_POST['showOB'])) ? "CHECKED" : "CHECKED"; ?>>
2024-07-10 12:43:19 +00:00
</div>
</div>
<div class="col-1 text-center">
<div class="form-group">
<label for="showClosing"><?php myLang("Closing"); ?></label>
<input type="checkbox" class="form-control " name="showClosing" id="showClosing" aria-describedby="helpId_showClosing" placeholder="Show Closing Balance" <?php echo (isset($_POST['showClosing'])) ? "CHECKED" : "CHECKED"; ?>>
2024-07-10 12:43:19 +00:00
</div>
</div>
<div class="col-1 text-center">
<div class="form-group">
<label for="showPeriod"><?php myLang("Period"); ?></label>
<input type="checkbox" class="form-control " name="showPeriod" id="showPeriod" aria-describedby="helpId_showPeriod" placeholder="Show Periodic Balance" <?php echo (isset($_POST['showPeriod'])) ? "CHECKED" : "CHECKED"; ?>>
</div>
</div>
<div class="col">
<div class="form-group d-flex justify-content-end">
<button class="btn btn-secondary toggle-collapse mr-2" id="toggleShowAll">Toggle Collapse</button>
<button type="submit" class="btn btn-primary mr-2">Filter</button>
<button type="submit" class="btn btn-success mr-2">Export</button>
<button type="button" class="btn btn-warning" onclick="resetForm()">Reset</button>
</div>
</div>
</div>
</form>
<script>
function resetForm() {
document.getElementById("fromDate").value = "2078-4-1";
document.getElementById("toDate").value = "2079-3-32";
document.getElementById("showOB").checked = false;
document.getElementById("showClosing").checked = false;
document.getElementById("FilterForm").submit();
}
</script>
</div> -->
2024-07-10 12:43:19 +00:00
</div>
2024-08-14 15:54:12 +00:00
<!-- <button class="btn btn-secondary toggle-collapse btn-sm" id="toggleShowAll">Toggle Collapse</button> -->
<div class="card card-primary card-outline">
<!-- <div class="card-header">
2024-07-10 12:43:19 +00:00
<h4 class="card-title">Cash Flow</h4>
</div> -->
2024-07-10 12:43:19 +00:00
<div class="card-body table-responsive p-0">
2024-09-30 10:24:29 +00:00
<?php $IncomesExpenses = $BIBAccounts->prepareIncomeExpenses($fiscalStart, $fiscalEnd);
2024-09-29 11:14:27 +00:00
// echo "<pre>";print_r($IncomesExpenses); die();
2024-09-30 10:24:29 +00:00
?>
2024-08-26 07:51:59 +00:00
2024-09-30 10:24:29 +00:00
<table id='myTable' class="table table-bordered p-0 ">
2024-07-10 12:43:19 +00:00
<thead>
<tr>
2024-08-08 13:22:57 +00:00
<th class="" width="30%"><?php myLang("Cash inflow"); ?></th>
<th class="text-right" width="10%"></th>
2024-08-26 07:51:59 +00:00
<th class="text-right pr-1" width="10%"><?php myLang("Amount"); ?></th>
2024-08-08 13:22:57 +00:00
<th class="pl-2" width="30%"><?php echo myLang("Cash outflow"); ?></th>
<th class="text-right" width="10%"></th>
2024-08-26 07:51:59 +00:00
<th class="text-right pr-1" width="10%"><?php myLang("Amount"); ?></th>
2024-07-10 12:43:19 +00:00
</tr>
</thead>
<tbody>
<tr>
<td colspan=3 class="p-0">
<table class="table g-0">
<?php $total1 = 0;
2024-08-14 15:54:12 +00:00
$counter = 0;
$index = 0;
2024-07-10 12:43:19 +00:00
foreach ($IncomesExpenses['Incomes'] as $Incomes) { ?>
<?php if ($Incomes['account'] == "GROUP TOTAL") : ?>
<!-- <tr>
<td class="" width="70%"><b><?php echo $Incomes['group']; ?></b></td>
<td width="15%"></td>
<td class="text-right" width="15%"><u><?php echo myCurrency($Incomes['amount']); ?></u></td>
</tr> -->
<?php elseif ($Incomes['account'] == "CATEGORY TOTAL") : ?>
2024-08-14 08:11:37 +00:00
<tr class="parent-row" class="group-heading" data-toggle="collapse" data-target="#group_<?php echo $index; ?>">
2024-08-26 07:51:59 +00:00
<td class="" width="60%"><b><?php echo $Incomes['category']; ?></b></td>
2024-08-25 12:52:52 +00:00
<td width="20%"></td>
2024-08-26 07:51:59 +00:00
<td class="text-right " width="20%"><?php echo myCurrency($Incomes['amount']); ?></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php else : ?>
<?php $total1 += $Incomes['amount']; ?>
2024-08-14 08:11:37 +00:00
<tr class="collapse" data-target="#group_<?php echo $index; ?>">
2024-08-26 07:51:59 +00:00
<td class="" width="60%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $Incomes['account']; ?></td>
<td class="text-right " width="20%"><?php echo myCurrency($Incomes['amount']); ?></td>
2024-08-25 12:52:52 +00:00
<td width="20%"></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php endif; ?>
2024-08-14 08:11:37 +00:00
<?php $counter = $index ?>
2024-07-10 12:43:19 +00:00
<?php }; ?>
</table>
</td>
<td colspan=3 class="p-0">
2024-08-26 07:51:59 +00:00
<table class="table p-0">
2024-07-10 12:43:19 +00:00
<?php $total = 0;
foreach ($IncomesExpenses['Expenses'] as $Expenses) {
if ($Expenses['account'] == "GROUP TOTAL") : ?>
<!-- <tr>
<td class="" width="70%"><b><?php echo $Expenses['group']; ?></b></td>
<td width="15%"></td>
<td class="text-right" width="15%"><u><?php echo myCurrency($Expenses['amount']); ?></u></td>
</tr> -->
<?php elseif ($Expenses['account'] == "CATEGORY TOTAL") : ?>
2024-08-14 08:11:37 +00:00
<tr data-toggle="collapse" data-target="#group_<?php echo $counter; ?>">
2024-08-25 12:52:52 +00:00
<td class="" width="60%"><b><?php echo $Expenses['category']; ?></b></td>
<td width="20%"></td>
2024-08-26 07:51:59 +00:00
<td class="text-right " width="20%"><?php echo myCurrency($Expenses['amount']); ?></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php else : ?>
<?php $total += $Expenses['amount']; ?>
2024-08-14 08:11:37 +00:00
<tr class="collapse" data-target="#group_<?php echo $counter; ?>">
2024-08-25 12:52:52 +00:00
<td class="" width="60%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $Expenses['account']; ?></td>
<td class="text-right" width="20%"><?php echo myCurrency($Expenses['amount']); ?></td>
<td width="20%"></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php endif; ?>
<?php }; ?>
</table>
</td>
</tr>
</tbody>
<tr>
2024-08-26 07:51:59 +00:00
<th class="p-1">Total</th>
2024-07-10 12:43:19 +00:00
<td></td>
2024-08-26 07:51:59 +00:00
<td class="text-right text-bold"><?php echo myCurrency($total1); ?></td>
<th class="p-1">Total</th>
2024-07-10 12:43:19 +00:00
<td></td>
2024-08-26 07:51:59 +00:00
<td class="text-right text-bold"><?php echo myCurrency($total); ?></td>
2024-07-10 12:43:19 +00:00
</tr>
<tr>
<th></th>
<td></td>
<td class="text-right"></td>
2024-08-26 07:51:59 +00:00
<th class="pl-1">Net Inflow</th>
2024-07-10 12:43:19 +00:00
<td></td>
2024-08-26 07:51:59 +00:00
<td class="text-right text-bold"><?php echo myCurrency($total1 - $total); ?></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php $Bank = $BIBAccounts->getAccountCategoriesWithBalances(null, 2); ?>
<?php foreach ($Bank->accounts as $account) : ?>
<tr>
<th></th>
<td></td>
<td class="text-right"></td>
2024-08-26 07:51:59 +00:00
<th class="pl-1"><?php echo $account->account_name; ?></th>
2024-07-10 12:43:19 +00:00
<td></td>
2024-08-26 07:51:59 +00:00
<td class="text-right text-bold"><?php echo myCurrency($account->balances['dr_total'] - $account->balances['cr_total']); ?></td>
2024-07-10 12:43:19 +00:00
</tr>
<?php endforeach; ?>
<?php $Cash = $BIBAccounts->getAccountCategoriesWithBalances(null, 3); ?>
<?php foreach ($Cash->accounts as $account) : ?>
<tr>
<th></th>
<td></td>
<td class="text-right"></td>
2024-08-26 07:51:59 +00:00
<th class="pl-1"><?php echo $account->account_name; ?></th>
<td></td>
2024-08-26 07:51:59 +00:00
<td class="text-right text-bold"><?php echo myCurrency($account->balances['dr_total'] - $account->balances['cr_total']); ?></td>
</tr>
<?php endforeach; ?>
2024-07-10 12:43:19 +00:00
</table>
<?php //pre($IncomesExpenses);
?>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
2024-08-14 15:54:12 +00:00
<?php function footerFunctions()
{ ?>
<script>
$(document).ready(function() {
// Prevent the dropdown from closing when clicking inside
$('.dropdown-menu').on('click', function(event) {
event.stopPropagation();
});
});
</script>
<script>
// var exportButton = document.getElementById("exportButton");
// exportButton.addEventListener("click", function() {
// exportTableToCSV("table.csv");
// });
document.addEventListener("DOMContentLoaded", function() {
// Trigger click event on page load
document.getElementById("toggleShowAll").click();
});
document.getElementById("toggleShowAll").addEventListener("click", function(e) {
e.preventDefault();
var nestedRows = document.getElementsByClassName("collapse");
for (var i = 0; i < nestedRows.length; i++) {
if (nestedRows[i].classList.contains("show")) {
nestedRows[i].classList.remove("show");
} else {
nestedRows[i].classList.add("show");
}
2024-08-14 08:11:37 +00:00
}
2024-08-14 15:54:12 +00:00
});
2024-08-14 08:11:37 +00:00
2024-08-14 15:54:12 +00:00
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("table tr:not(.hide)");
for (var i = 0; i < rows.length; i++) {
var row = [];
var cols = rows[i].querySelectorAll("td:not(.hide), th:not(.hide)");
// Check if the parent row is collapsed or hidden
var parentRow = rows[i].closest(".collapse");
var isParentCollapsed = parentRow && (!parentRow.classList.contains("show"));
if (isParentCollapsed) {
continue; // Skip child table rows if parent is collapsed
}
for (var j = 0; j < cols.length; j++) {
var cellValue = cols[j].innerText.replace(/,/g, ""); // Remove commas from the cell value
row.push(cellValue);
}
csv.push(row.join(","));
2024-08-14 08:11:37 +00:00
}
2024-08-14 15:54:12 +00:00
// Create a CSV file
var csvContent = "data:text/csv;charset=utf-8," + csv.join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", filename);
document.body.appendChild(link);
link.click();
2024-08-14 08:11:37 +00:00
}
</script>
2024-08-14 15:54:12 +00:00
<script>
$("#fromDate").nepaliDatePicker({
dateFormat: "%y-%m-%d",
closeOnDateSelect: true,
minDate: $('#fromDate').data('start'),
maxDate: $('#fromDate').data('end'),
});
</script>
<script>
2024-08-14 15:54:12 +00:00
$("#toDate").nepaliDatePicker({
dateFormat: "%y-%m-%d",
closeOnDateSelect: true,
minDate: $('#toDate').data('start'),
maxDate: $('#toDate').data('end'),
});
</script>
2024-09-30 10:24:29 +00:00
<!-- pdf document -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
document.getElementById('downloadCsv').addEventListener('click', function() {
const table = document.getElementById('myTable');
const rows = Array.from(table.rows);
const data = [];
rows.forEach((row) => {
const cells = Array.from(row.cells);
const rowData = [];
cells.forEach((cell) => {
// Handle colspan
const colspan = cell.colSpan || 1;
for (let i = 0; i < (colspan - 1); i++) {
rowData.push(''); // Fill empty cells for merged columns
}
for (let i = 0; i < 1; i++) {
rowData.push(cell.innerText.trim());
}
// Fill empty cells for colspan
});
data.push(rowData);
});
// Create a worksheet
const worksheet = XLSX.utils.aoa_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// Export to Excel
XLSX.writeFile(workbook, 'table.xlsx');
});
</script>
<!-- pdf document ends-->
2024-08-14 15:54:12 +00:00
<?php } ?>