162 lines
6.1 KiB
PHP
162 lines
6.1 KiB
PHP
<?php
|
|
$IncomeAccounts = $this->acc->getAccountsByGroup(3);
|
|
$ExpenseAccounts = $this->acc->getAccountsByGroup(4);
|
|
$IncomesTotal = $this->acc->getAccountBalanceByGroup(3);
|
|
$ExpensesTotal = $this->acc->getAccountBalanceByGroup(4);
|
|
$PL = $IncomesTotal - $ExpensesTotal;
|
|
|
|
?>
|
|
<div class="content-wrapper">
|
|
|
|
<div class="content">
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col">
|
|
<div class="card card-primary card-outline">
|
|
<div class="card-header">
|
|
<h5 class="m-0"><?php echo $pageTitle; ?> </h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<table id='myTable'class="table table-bordered table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th colspan="4">Profit & Loss Statement</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="bg-dark">
|
|
|
|
<th>Incomes</th>
|
|
<th>Amount</th>
|
|
<th>Expenses</th>
|
|
<th>Amount</th>
|
|
</tr>
|
|
|
|
<tr class="bg-light">
|
|
<td colspan="2">
|
|
<?php showTable($IncomeAccounts); ?>
|
|
</td>
|
|
<td colspan="2">
|
|
<?php showTable($ExpenseAccounts); ?>
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
</tbody>
|
|
<tfoot>
|
|
<?php if($PL<0): ?>
|
|
<tr class="bg-light">
|
|
|
|
<th>Net Loss:</th>
|
|
<th><?php echo myCurrency($PL); ?></th>
|
|
<th></th>
|
|
<th></th>
|
|
</tr>
|
|
<?php else: ?>
|
|
<tr class="bg-light">
|
|
<th></th>
|
|
<th></th>
|
|
<th>Net Profit:</th>
|
|
<th><?php echo myCurrency($PL); ?></th>
|
|
|
|
</tr>
|
|
<?php endif; ?>
|
|
|
|
<?php if($PL<0): ?>
|
|
<tr class="bg-light">
|
|
|
|
<th>Total Loss:</th>
|
|
<th><?php echo myCurrency($PL + $IncomesTotal); ?></th>
|
|
<th>Total: </th>
|
|
<th><?php echo myCurrency($IncomesTotal); ?></th>
|
|
</tr>
|
|
<?php else: ?>
|
|
<tr class="bg-light">
|
|
<th>Total:</th>
|
|
<th><?php echo myCurrency($IncomesTotal); ?></th>
|
|
<th>Total:</th>
|
|
<th><?php echo myCurrency($PL + $ExpensesTotal); ?></th>
|
|
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tfoot>
|
|
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
function showTable($Accounts)
|
|
{
|
|
$total = 0;
|
|
?>
|
|
<table id='myTable' class="table table-bordered table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Account</th>
|
|
<th>Balance</th>
|
|
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($Accounts as $Account) : $total += abs($Account->balance) ?>
|
|
<tr>
|
|
<td><?php echo $Account->account_name; ?></td>
|
|
<td><?php echo myCurrency(abs($Account->balance)); ?></td>
|
|
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
|
|
</tbody>
|
|
<!-- <tfoot>
|
|
<tr>
|
|
<th>Total</th>
|
|
<th><?php echo myCurrency($total); ?></th>
|
|
|
|
</tr>
|
|
</tfoot> -->
|
|
</table>
|
|
<!-- 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
|
|
}
|