export excel

This commit is contained in:
2024-09-30 16:09:29 +05:45
parent 60f4c75eb0
commit 4683fe67a7
21 changed files with 889 additions and 408 deletions

View File

@ -108,13 +108,15 @@ $BIBAccounts = new BIBAccounts();
min-height: 1px;
padding: 0;
}
table {
border: 1px solid #ddd;
border-collapse: collapse;
}
.text-bold{
font-weight: 900;
}
border: 1px solid #ddd;
border-collapse: collapse;
}
.text-bold {
font-weight: 900;
}
</style>
<div class="content-wrapper">
<div class="content">
@ -173,8 +175,14 @@ $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" onclick="exportTableToCSV('accounts_data.csv')" 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 class="dropdown-menu" role="menu">
<a href="#" class="dropdown-item">Export</a>
@ -194,9 +202,8 @@ $BIBAccounts = new BIBAccounts();
document.getElementById("showClosing").checked = <?php echo "false"; ?>;
document.getElementById("FilterForm").submit();
}
</script>
</div>
</div>
</div>
@ -222,7 +229,7 @@ $BIBAccounts = new BIBAccounts();
?>
<div class="col-6 p-0">
<div class="table-responsive">
<table class="table ">
<table id='myTable' class="table ">
<thead>
<tr>
<th class="group-name pl-1">Particulars</th>
@ -230,8 +237,8 @@ $BIBAccounts = new BIBAccounts();
</tr>
</thead>
<tbody>
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(3,$fiscalStart,$fiscalEnd); ?>
<?php
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(3, $fiscalStart, $fiscalEnd); ?>
<?php
// Initialize variables for column totals
$incomes_totalOpeningDr = 0;
$incomes_totalOpeningCr = 0;
@ -241,16 +248,16 @@ $BIBAccounts = new BIBAccounts();
$incomes_totalClosingCr = 0;
?>
<?php foreach ($AccountGroups as $group) : ?>
<tr>
<td colspan="2" class="p-0">
<div id="group_<?php echo $group->acgroup_id; ?>" class="">
<tr>
<td colspan="2" class="p-0">
<div id="group_<?php echo $group->acgroup_id; ?>" class="">
<?php $Accountcategories = $BIBAccounts->getRootCategoriesWithBalances($group->acgroup_id); ?>
<?php $BIBAccounts->renderAccountCategoriesTable($Accountcategories, $ReportOptions, false, array()); ?>
</div>
</td>
</tr>
<?php
</td>
</tr>
<?php
// Update column totals
$incomes_totalOpeningDr += ($group->posting_side == "DR") ? $group->opening_balance : 0;
$incomes_totalOpeningCr += ($group->posting_side == "CR") ? $group->opening_balance : 0;
@ -258,15 +265,15 @@ $BIBAccounts = new BIBAccounts();
$incomes_totalThisYearCr += ($group->posting_side == "CR") ? $group->regular_balance : 0;
$incomes_totalClosingDr += ($group->posting_side == "DR") ? $group->closing_balance : 0;
$incomes_totalClosingCr += ($group->posting_side == "CR") ? $group->closing_balance : 0;
?>
<?php endforeach; ?>
?>
<?php endforeach; ?>
</tbody>
<tfoot>
<?php $PL = $incomes_totalClosingCr - $incomes_totalClosingDr; ?>
<?php $PL = $incomes_totalClosingCr - $incomes_totalClosingDr; ?>
<tr>
<th class="p-1">Total Incomes</th>
<th class="cr closing-cr text-bold">
@ -275,7 +282,7 @@ $BIBAccounts = new BIBAccounts();
<?php else : ?>
<?php echo myCurrency($incomes_totalClosingCr + abs($PL)); ?>
<?php endif; ?>
</th>
</tr>
</tfoot>
@ -292,8 +299,8 @@ $BIBAccounts = new BIBAccounts();
</tr>
</thead>
<tbody>
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(4,$fiscalStart,$fiscalEnd); ?>
<?php
<?php $AccountGroups = $BIBAccounts->getAccountGroupsWithBalancesNew(4, $fiscalStart, $fiscalEnd); ?>
<?php
// Initialize variables for column totals
$totalOpeningDr = 0;
$totalOpeningCr = 0;
@ -303,16 +310,16 @@ $BIBAccounts = new BIBAccounts();
$totalClosingCr = 0;
?>
<?php foreach ($AccountGroups as $group) : ?>
<tr>
<td colspan="2" class="p-0">
<div id="group_<?php echo $group->acgroup_id; ?>" class="">
<tr>
<td colspan="2" class="p-0">
<div id="group_<?php echo $group->acgroup_id; ?>" class="">
<i> <?php $Accountcategories = $BIBAccounts->getRootCategoriesWithBalances($group->acgroup_id); ?>
<?php $BIBAccounts->renderAccountCategoriesTable($Accountcategories, $ReportOptions, false, array()); ?>
</i>
</div>
</td>
</tr>
<?php
</td>
</tr>
<?php
// Update column totals
$totalOpeningDr += ($group->posting_side == "DR") ? $group->opening_balance : 0;
$totalOpeningCr += ($group->posting_side == "CR") ? $group->opening_balance : 0;
@ -323,28 +330,28 @@ $BIBAccounts = new BIBAccounts();
?>
<?php endforeach; ?>
<?php $PL = $incomes_totalClosingCr - $totalClosingDr; ?>
<?php if ($incomes_totalClosingCr > $totalClosingDr) : ?>
<tr>
<!-- <th></th>
<?php if ($incomes_totalClosingCr > $totalClosingDr) : ?>
<tr>
<!-- <th></th>
<th></th> -->
<th class="pl-1">Total Profit</th>
<th class="cr closing-cr text-right text-bold"><?php echo myCurrency($PL); ?></th>
</tr>
<?php endif; ?>
<th class="pl-1">Total Profit</th>
<th class="cr closing-cr text-right text-bold"><?php echo myCurrency($PL); ?></th>
</tr>
<?php endif; ?>
</tbody>
<tfoot>
<th class="pl-1">Total Expenses</th>
<th class="dr closing-dr text-bold">
<?php if ($PL > 0) : ?>
<?php echo myCurrency($totalClosingDr + abs($PL)); ?>
<th class="pl-1">Total Expenses</th>
<th class="dr closing-dr text-bold">
<?php if ($PL > 0) : ?>
<?php echo myCurrency($totalClosingDr + abs($PL)); ?>
<?php else : ?>
<?php echo myCurrency($totalClosingDr); ?>
<?php else : ?>
<?php echo myCurrency($totalClosingDr); ?>
<?php endif; ?>
</th>
<?php endif; ?>
</th>
</tfoot>
</table>
</div>
@ -436,6 +443,42 @@ function footerfunctions()
});
</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
}
?>