export excel
This commit is contained in:
@ -103,10 +103,11 @@ $BIBAccounts = new BIBAccounts();
|
||||
min-height: 1px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
border: 1px solid #ddd;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
border: 1px solid #ddd;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
</style>
|
||||
<div class="content-wrapper">
|
||||
<section class="content">
|
||||
@ -115,7 +116,7 @@ $BIBAccounts = new BIBAccounts();
|
||||
<div class="card-header">
|
||||
<h3 class="card-title mt-1"><?php echo $pageTitle; ?> </h3>
|
||||
<div class="card-tools">
|
||||
<form method="post" action=<?php echo base_url('accounts/reports/balance_sheet') ;?> id="FilterForm">
|
||||
<form method="post" action=<?php echo base_url('accounts/reports/balance_sheet'); ?> 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">
|
||||
@ -160,8 +161,11 @@ $BIBAccounts = new BIBAccounts();
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="submit" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
|
||||
<!-- <button type="submit" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
|
||||
Export
|
||||
</button> -->
|
||||
<button type="submit" id="downloadCsv" class="btn btn-warning btn-sm ">
|
||||
Export csv
|
||||
</button>
|
||||
|
||||
</div>
|
||||
@ -194,20 +198,20 @@ $BIBAccounts = new BIBAccounts();
|
||||
<div class="card-body pl-2 ">
|
||||
|
||||
<div class="row">
|
||||
<?php
|
||||
// echo $_POST['showClosing'];
|
||||
$ReportOptions = array(
|
||||
'showZeroBalances' => false,
|
||||
'showOB' => false,
|
||||
'showClosing' => true,
|
||||
'showPeriod' => false,
|
||||
);
|
||||
?>
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(2,$fiscalStart,$fiscalEnd); ?>
|
||||
<?php $Side1Total = 0; ?>
|
||||
<?php
|
||||
// echo $_POST['showClosing'];
|
||||
$ReportOptions = array(
|
||||
'showZeroBalances' => false,
|
||||
'showOB' => false,
|
||||
'showClosing' => true,
|
||||
'showPeriod' => false,
|
||||
);
|
||||
?>
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(2, $fiscalStart, $fiscalEnd); ?>
|
||||
<?php $Side1Total = 0; ?>
|
||||
<div class="col-6 p-0 m-0 gy-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table mb-0 pb-0">
|
||||
<table id='myTable' class="table mb-0 pb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="group-name pl-1">Particulars</th>
|
||||
@ -215,10 +219,10 @@ $BIBAccounts = new BIBAccounts();
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(2,$fiscalStart,$fiscalEnd); ?>
|
||||
<?php $Side1Total = 0; ?>
|
||||
<?php
|
||||
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(2, $fiscalStart, $fiscalEnd); ?>
|
||||
<?php $Side1Total = 0; ?>
|
||||
<?php
|
||||
// Initialize variables for column totals
|
||||
$incomes_totalOpeningDr = 0;
|
||||
$incomes_totalOpeningCr = 0;
|
||||
@ -245,8 +249,8 @@ $BIBAccounts = new BIBAccounts();
|
||||
$Side1Total += $group->closing_balance;
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(5,$fiscalStart,$fiscalEnd); ?>
|
||||
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(5, $fiscalStart, $fiscalEnd); ?>
|
||||
|
||||
<?php
|
||||
// Initialize variables for column totals
|
||||
$incomes_totalOpeningDr = 0;
|
||||
@ -274,10 +278,10 @@ $BIBAccounts = new BIBAccounts();
|
||||
$Side1Total += $group->closing_balance;
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
</tbody>
|
||||
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@ -291,8 +295,8 @@ $BIBAccounts = new BIBAccounts();
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(1,$fiscalStart,$fiscalEnd); ?>
|
||||
|
||||
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(1, $fiscalStart, $fiscalEnd); ?>
|
||||
|
||||
<?php
|
||||
// Initialize variables for column totals
|
||||
$totalOpeningDr = 0;
|
||||
@ -325,40 +329,40 @@ $BIBAccounts = new BIBAccounts();
|
||||
$totalClosingCr += ($group->posting_side == "CR") ? $group->closing_balance : 0;
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
</tbody>
|
||||
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
// pre($BIBAccounts->getAccountGroupsWithBalances(4));
|
||||
$TotalIncomes = ($BIBAccounts->getAccountGroupsWithBalancesNew(3,$fiscalStart,$fiscalEnd)[0]->closing_balance) ?? 0;
|
||||
$TotalExpenses = ($BIBAccounts->getAccountGroupsWithBalancesNew(4,$fiscalStart,$fiscalEnd)[0]->closing_balance) ?? 0;
|
||||
$PL = $TotalIncomes - $TotalExpenses;
|
||||
$Side1Total += $PL;
|
||||
// pre($BIBAccounts->getAccountGroupsWithBalances(4));
|
||||
$TotalIncomes = ($BIBAccounts->getAccountGroupsWithBalancesNew(3, $fiscalStart, $fiscalEnd)[0]->closing_balance) ?? 0;
|
||||
$TotalExpenses = ($BIBAccounts->getAccountGroupsWithBalancesNew(4, $fiscalStart, $fiscalEnd)[0]->closing_balance) ?? 0;
|
||||
$PL = $TotalIncomes - $TotalExpenses;
|
||||
$Side1Total += $PL;
|
||||
?>
|
||||
|
||||
<div class="col-6 p-0 m-0 gy-0">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><b> Profit/Loss</b></td>
|
||||
<td class="cr closing-cr"><?php echo myCurrency($PL); ?></td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="p-0">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th class="pl-1">Total Amount</th>
|
||||
<th class="cr closing-cr">
|
||||
<?php echo myCurrency($Side1Total); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><b> Profit/Loss</b></td>
|
||||
<td class="cr closing-cr"><?php echo myCurrency($PL); ?></td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="p-0">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th class="pl-1">Total Amount</th>
|
||||
<th class="cr closing-cr">
|
||||
<?php echo myCurrency($Side1Total); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
@ -423,94 +427,131 @@ $BIBAccounts = new BIBAccounts();
|
||||
</tr>
|
||||
</table>
|
||||
</div> -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
function footerfunctions()
|
||||
{
|
||||
?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Prevent the dropdown from closing when clicking inside
|
||||
$('.dropdown-menu').on('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
</div>
|
||||
<?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>
|
||||
$(document).ready(function() {
|
||||
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");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
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");
|
||||
}
|
||||
});
|
||||
var exportButton = document.getElementById("exportButton");
|
||||
exportButton.addEventListener("click", function() {
|
||||
exportTableToCSV("table.csv");
|
||||
});
|
||||
|
||||
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(","));
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$("#fromDate").nepaliDatePicker({
|
||||
dateFormat: "%y-%m-%d",
|
||||
closeOnDateSelect: true,
|
||||
minDate: $('#fromDate').data('start'),
|
||||
maxDate: $('#fromDate').data('end'),
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$("#toDate").nepaliDatePicker({
|
||||
dateFormat: "%y-%m-%d",
|
||||
closeOnDateSelect: true,
|
||||
minDate: $('#toDate').data('start'),
|
||||
maxDate: $('#toDate').data('end'),
|
||||
});
|
||||
</script>
|
||||
});
|
||||
var exportButton = document.getElementById("exportButton");
|
||||
exportButton.addEventListener("click", function() {
|
||||
exportTableToCSV("table.csv");
|
||||
});
|
||||
|
||||
<?php
|
||||
}
|
||||
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(","));
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$("#fromDate").nepaliDatePicker({
|
||||
dateFormat: "%y-%m-%d",
|
||||
closeOnDateSelect: true,
|
||||
minDate: $('#fromDate').data('start'),
|
||||
maxDate: $('#fromDate').data('end'),
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$("#toDate").nepaliDatePicker({
|
||||
dateFormat: "%y-%m-%d",
|
||||
closeOnDateSelect: true,
|
||||
minDate: $('#toDate').data('start'),
|
||||
maxDate: $('#toDate').data('end'),
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- 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-->
|
||||
|
||||
<?php
|
||||
}
|
||||
|
Reference in New Issue
Block a user