Commit 89449302 authored by Mahmoud Aglan's avatar Mahmoud Aglan

csv export

parent e9995b96
......@@ -369,6 +369,56 @@ class ReportController extends Controller
]);
}
public function balanceSheetExportCsv(): Response
{
$this->authorize('accounting.reports.balance_sheet');
$asOfDate = $_GET['as_of_date'] ?? date('Y-m-d');
$costCenterId = !empty($_GET['cost_center_id']) ? (int) $_GET['cost_center_id'] : null;
$branchId = !empty($_GET['branch_id']) ? (int) $_GET['branch_id'] : null;
$result = FinancialReportService::getBalanceSheet($asOfDate, $costCenterId, $branchId);
$filename = 'balance_sheet_' . $asOfDate . '.csv';
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
$output = fopen('php://output', 'w');
fwrite($output, "\xEF\xBB\xBF");
fputcsv($output, ['الميزانية العمومية حتى تاريخ ' . $asOfDate]);
fputcsv($output, []);
fputcsv($output, ['كود الحساب', 'اسم الحساب', 'الرصيد']);
fputcsv($output, ['--- الأصول ---', '', '']);
foreach ($result['assets'] as $acc) {
fputcsv($output, [$acc['account_code'], $acc['name_ar'], $acc['balance']]);
}
fputcsv($output, ['', 'إجمالي الأصول', $result['total_assets']]);
fputcsv($output, []);
fputcsv($output, ['--- الخصوم ---', '', '']);
foreach ($result['liabilities'] as $acc) {
fputcsv($output, [$acc['account_code'], $acc['name_ar'], $acc['balance']]);
}
fputcsv($output, ['', 'إجمالي الخصوم', $result['total_liabilities']]);
fputcsv($output, []);
fputcsv($output, ['--- حقوق الملكية ---', '', '']);
foreach ($result['equity'] as $acc) {
fputcsv($output, [$acc['account_code'], $acc['name_ar'], $acc['balance']]);
}
fputcsv($output, ['', 'إجمالي حقوق الملكية', $result['total_equity']]);
fputcsv($output, []);
fputcsv($output, ['', 'إجمالي الخصوم + حقوق الملكية', $result['total_liabilities_and_equity']]);
fputcsv($output, ['', 'متوازنة؟', $result['is_balanced'] ? 'نعم' : 'لا']);
fclose($output);
exit;
}
public function consolidatedBalanceSheet(): Response
{
$this->authorize('accounting.reports.consolidated');
......
......@@ -65,6 +65,7 @@ return [
['GET', '/accounting/reports/general-ledger', 'Accounting\Controllers\ReportController@generalLedger', ['auth'], 'accounting.reports.general_ledger'],
['GET', '/accounting/reports/income-statement', 'Accounting\Controllers\ReportController@incomeStatement', ['auth'], 'accounting.reports.income_statement'],
['GET', '/accounting/reports/balance-sheet', 'Accounting\Controllers\ReportController@balanceSheet', ['auth'], 'accounting.reports.balance_sheet'],
['GET', '/accounting/reports/balance-sheet/export-csv', 'Accounting\Controllers\ReportController@balanceSheetExportCsv', ['auth'], 'accounting.reports.balance_sheet'],
['GET', '/accounting/reports/consolidated-balance-sheet', 'Accounting\Controllers\ReportController@consolidatedBalanceSheet', ['auth'], 'accounting.reports.consolidated'],
['GET', '/accounting/reports/accounts-receivable', 'Accounting\Controllers\ReportController@accountsReceivable', ['auth'], 'accounting.reports.ar'],
['GET', '/accounting/reports/accounts-payable', 'Accounting\Controllers\ReportController@accountsPayable', ['auth'], 'accounting.reports.ap'],
......
......@@ -30,6 +30,7 @@
</select>
</div>
<button type="submit" class="btn btn-primary">عرض</button>
<a href="/accounting/reports/balance-sheet/export-csv?as_of_date=<?= e($as_of_date) ?>&branch_id=<?= (int)($filters['branch_id'] ?? 0) ?>&cost_center_id=<?= (int)($filters['cost_center_id'] ?? 0) ?>" class="btn btn-secondary" style="margin-right:5px;">تصدير CSV</a>
</form>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment