update tgl 19 mei

This commit is contained in:
whywdd 2025-05-19 22:59:01 +07:00
parent e9b5d56ed0
commit ae63ac1618
4 changed files with 192 additions and 119 deletions

View File

@ -166,7 +166,7 @@ public function headings(): array {
} }
}; };
return Excel::download($export, 'laporan-keuangan-'.date('Y-m-d').'.xlsx'); return Excel::download($export, 'jurnal-umum-'.date('Y-m-d').'.xlsx');
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->back()->with('error', 'Gagal mengekspor Excel: ' . $e->getMessage()); return redirect()->back()->with('error', 'Gagal mengekspor Excel: ' . $e->getMessage());
} }
@ -273,7 +273,7 @@ public function exportPDF(Request $request)
$rows .= '<td style="text-align:right">'.number_format($totalKredit, 0, ',', '.').'</td>'; $rows .= '<td style="text-align:right">'.number_format($totalKredit, 0, ',', '.').'</td>';
$rows .= '</tr>'; $rows .= '</tr>';
$html = '<!DOCTYPE html><html><head><title>Laporan Keuangan</title><style> $html = '<!DOCTYPE html><html><head><title>Jurnal Umum</title><style>
body{font-family:Arial,sans-serif;font-size:12px;} body{font-family:Arial,sans-serif;font-size:12px;}
table{width:100%;border-collapse:collapse;margin-bottom:20px;} table{width:100%;border-collapse:collapse;margin-bottom:20px;}
table,th,td{border:1px solid #ddd;} table,th,td{border:1px solid #ddd;}
@ -284,7 +284,7 @@ public function exportPDF(Request $request)
.text-center{text-align:center;} .text-center{text-align:center;}
td{vertical-align:top;} td{vertical-align:top;}
</style></head><body>'; </style></head><body>';
$html .= '<h2 style="text-align:center">Laporan Keuangan</h2>'; $html .= '<h2 style="text-align:center">Jurnal Umum</h2>';
$html .= '<p style="text-align:center">Periode: '.date('d/m/Y', strtotime($startDate)).' - '.date('d/m/Y', strtotime($endDate)).'</p>'; $html .= '<p style="text-align:center">Periode: '.date('d/m/Y', strtotime($startDate)).' - '.date('d/m/Y', strtotime($endDate)).'</p>';
$html .= '<table><thead><tr> $html .= '<table><thead><tr>
<th style="text-align:center">No</th> <th style="text-align:center">No</th>
@ -299,7 +299,7 @@ public function exportPDF(Request $request)
$html .= '</tbody></table></body></html>'; $html .= '</tbody></table></body></html>';
$pdf = PDF::loadHTML($html); $pdf = PDF::loadHTML($html);
return $pdf->download('laporan-keuangan-'.date('Y-m-d').'.pdf'); return $pdf->download('jurnal-umum-'.date('Y-m-d').'.pdf');
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->back()->with('error', 'Gagal mengekspor PDF: ' . $e->getMessage()); return redirect()->back()->with('error', 'Gagal mengekspor PDF: ' . $e->getMessage());
} }

View File

@ -153,7 +153,7 @@ public function show($id)
public function exportExcel(Request $request) public function exportExcel(Request $request)
{ {
try { try {
// Ambil parameter filter tanggal jika ada // Ambil parameter filter tanggal
$startDate = $request->input('start_date', Carbon::now()->startOfMonth()->format('Y-m-d')); $startDate = $request->input('start_date', Carbon::now()->startOfMonth()->format('Y-m-d'));
$endDate = $request->input('end_date', Carbon::now()->endOfMonth()->format('Y-m-d')); $endDate = $request->input('end_date', Carbon::now()->endOfMonth()->format('Y-m-d'));
@ -166,7 +166,7 @@ public function exportExcel(Request $request)
$totalDebit = 0; $totalDebit = 0;
$totalKredit = 0; $totalKredit = 0;
// Proses data seperti di fungsi index // Proses data transaksi
foreach ($rawTransaksis as $transaksi) { foreach ($rawTransaksis as $transaksi) {
$processAkun = function($kode, $kategori, $debit, $kredit) use (&$totalsPerAkun) { $processAkun = function($kode, $kategori, $debit, $kredit) use (&$totalsPerAkun) {
if (!empty($kode) && !empty($kategori)) { if (!empty($kode) && !empty($kategori)) {
@ -183,6 +183,7 @@ public function exportExcel(Request $request)
} }
}; };
// Proses semua kolom transaksi
$processAkun($transaksi->kode, $transaksi->kategori, $transaksi->uang_masuk, $transaksi->uang_keluar); $processAkun($transaksi->kode, $transaksi->kategori, $transaksi->uang_masuk, $transaksi->uang_keluar);
$processAkun($transaksi->kode2, $transaksi->kategori2, $transaksi->uang_masuk2, $transaksi->uang_keluar2); $processAkun($transaksi->kode2, $transaksi->kategori2, $transaksi->uang_masuk2, $transaksi->uang_keluar2);
$processAkun($transaksi->kode3, $transaksi->kategori3, $transaksi->uang_masuk3, $transaksi->uang_keluar3); $processAkun($transaksi->kode3, $transaksi->kategori3, $transaksi->uang_masuk3, $transaksi->uang_keluar3);
@ -190,33 +191,42 @@ public function exportExcel(Request $request)
$processAkun($transaksi->kode5, $transaksi->kategori5, $transaksi->uang_masuk5, $transaksi->uang_keluar5); $processAkun($transaksi->kode5, $transaksi->kategori5, $transaksi->uang_masuk5, $transaksi->uang_keluar5);
} }
// Proses saldo untuk setiap akun
foreach ($totalsPerAkun as $kategori => $data) { foreach ($totalsPerAkun as $kategori => $data) {
$kodeAwal = substr($data['kode'], 0, 3); $kodeAwal = substr($data['kode'], 0, 3);
$saldo = $data['debit'] - $data['kredit']; $saldo = $data['debit'] - $data['kredit'];
if (in_array($kodeAwal, ['111', '112']) || in_array($kodeAwal, ['251', '252'])) { // Reset nilai debit dan kredit
if ($saldo != 0) { $debit = 0;
$processedData[] = [ $kredit = 0;
'kode' => $data['kode'],
'kategori' => $kategori, // Logika untuk menentukan posisi saldo
'debit' => $saldo > 0 ? abs($saldo) : 0, if (in_array($kodeAwal, ['111', '112', '251', '252'])) {
'kredit' => $saldo < 0 ? abs($saldo) : 0 // Aktiva dan Beban
]; if ($saldo > 0) {
$totalDebit += $saldo > 0 ? abs($saldo) : 0; $debit = $saldo;
$totalKredit += $saldo < 0 ? abs($saldo) : 0; } else {
$kredit = abs($saldo);
} }
} else { } else {
if ($saldo != 0) { // Pasiva dan Pendapatan
$processedData[] = [ if ($saldo < 0) {
'kode' => $data['kode'], $kredit = abs($saldo);
'kategori' => $kategori, } else {
'debit' => $saldo < 0 ? abs($saldo) : 0, $debit = $saldo;
'kredit' => $saldo > 0 ? abs($saldo) : 0
];
$totalDebit += $saldo < 0 ? abs($saldo) : 0;
$totalKredit += $saldo > 0 ? abs($saldo) : 0;
} }
} }
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $debit,
'kredit' => $kredit
];
$totalDebit += $debit;
$totalKredit += $kredit;
}
} }
// Tambahkan baris total // Tambahkan baris total
@ -227,13 +237,23 @@ public function exportExcel(Request $request)
'kredit' => $totalKredit 'kredit' => $totalKredit
]; ];
// Buat class export inline // Buat class export inline dengan format yang diperbaiki
$export = new class($processedData) implements FromCollection, WithHeadings { $export = new class($processedData) implements FromCollection, WithHeadings {
protected $data; protected $data;
public function __construct($data) public function __construct($data)
{ {
$this->data = collect($data); // Format data untuk Excel
$formattedData = collect($data)->map(function ($item) {
return [
'kode' => $item['kode'],
'kategori' => $item['kategori'],
'debit' => $item['debit'] > 0 ? $item['debit'] : 0,
'kredit' => $item['kredit'] > 0 ? $item['kredit'] : 0
];
});
$this->data = $formattedData;
} }
public function collection() public function collection()
@ -302,32 +322,48 @@ public function exportPDF(Request $request)
$kodeAwal = substr($data['kode'], 0, 3); $kodeAwal = substr($data['kode'], 0, 3);
$saldo = $data['debit'] - $data['kredit']; $saldo = $data['debit'] - $data['kredit'];
if (in_array($kodeAwal, ['111', '112']) || in_array($kodeAwal, ['251', '252'])) { // Reset nilai debit dan kredit
if ($saldo != 0) { $debit = 0;
$processedData[] = [ $kredit = 0;
'kode' => $data['kode'],
'kategori' => $kategori, // Logika untuk menentukan posisi saldo
'debit' => $saldo > 0 ? abs($saldo) : 0, if (in_array($kodeAwal, ['111', '112', '251', '252'])) {
'kredit' => $saldo < 0 ? abs($saldo) : 0 // Aktiva dan Beban
]; if ($saldo > 0) {
$totalDebit += $saldo > 0 ? abs($saldo) : 0; $debit = $saldo;
$totalKredit += $saldo < 0 ? abs($saldo) : 0; } else {
$kredit = abs($saldo);
} }
} else { } else {
if ($saldo != 0) { // Pasiva dan Pendapatan
$processedData[] = [ if ($saldo < 0) {
'kode' => $data['kode'], $kredit = abs($saldo);
'kategori' => $kategori, } else {
'debit' => $saldo < 0 ? abs($saldo) : 0, $debit = $saldo;
'kredit' => $saldo > 0 ? abs($saldo) : 0
];
$totalDebit += $saldo < 0 ? abs($saldo) : 0;
$totalKredit += $saldo > 0 ? abs($saldo) : 0;
} }
} }
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $debit,
'kredit' => $kredit
];
$totalDebit += $debit;
$totalKredit += $kredit;
}
} }
// Generate PDF // Tambahkan baris total
$processedData[] = [
'kode' => '',
'kategori' => 'Total',
'debit' => $totalDebit,
'kredit' => $totalKredit
];
// Generate PDF dengan style yang diperbaiki
$html = ' $html = '
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -354,23 +390,25 @@ public function exportPDF(Request $request)
margin-bottom: 20px; margin-bottom: 20px;
} }
table, th, td { table, th, td {
border: 1px solid #ddd; border: 1px solid #000;
} }
th, td { th, td {
padding: 6px; padding: 8px;
text-align: left; text-align: left;
font-size: 10px;
} }
th { th {
background-color: #f2f2f2; background-color: #f2f2f2;
font-weight: bold;
} }
.text-right { .text-right {
text-align: right; text-align: right;
} }
tfoot td { .total-row td {
font-weight: bold; font-weight: bold;
background-color: #f9f9f9; background-color: #f2f2f2;
}
.amount {
text-align: right;
white-space: nowrap;
} }
</style> </style>
</head> </head>
@ -381,10 +419,10 @@ public function exportPDF(Request $request)
<table> <table>
<thead> <thead>
<tr> <tr>
<th>Kode</th> <th style="width: 15%;">Kode</th>
<th>Nama Akun</th> <th style="width: 45%;">Nama Akun</th>
<th class="text-right">Debit</th> <th style="width: 20%;" class="amount">Debit</th>
<th class="text-right">Kredit</th> <th style="width: 20%;" class="amount">Kredit</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
@ -395,8 +433,8 @@ public function exportPDF(Request $request)
<tr> <tr>
<td>'.$data['kode'].'</td> <td>'.$data['kode'].'</td>
<td>'.$data['kategori'].'</td> <td>'.$data['kategori'].'</td>
<td class="text-right">'.($data['debit'] > 0 ? 'Rp '.number_format($data['debit'], 0, ',', '.') : '-').'</td> <td class="amount">'.($data['debit'] > 0 ? number_format($data['debit'], 0, ',', '.') : '-').'</td>
<td class="text-right">'.($data['kredit'] > 0 ? 'Rp '.number_format($data['kredit'], 0, ',', '.') : '-').'</td> <td class="amount">'.($data['kredit'] > 0 ? number_format($data['kredit'], 0, ',', '.') : '-').'</td>
</tr>'; </tr>';
} }
} }
@ -404,10 +442,10 @@ public function exportPDF(Request $request)
$html .= ' $html .= '
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr class="total-row">
<td colspan="2" class="text-right">Total:</td> <td colspan="2" style="text-align: right;">Total:</td>
<td class="text-right">Rp '.number_format($totalDebit, 0, ',', '.').'</td> <td class="amount">'.number_format($totalDebit, 0, ',', '.').'</td>
<td class="text-right">Rp '.number_format($totalKredit, 0, ',', '.').'</td> <td class="amount">'.number_format($totalKredit, 0, ',', '.').'</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>

View File

@ -507,34 +507,55 @@ public function exportPDF(Request $request)
<head> <head>
<title>Buku Besar</title> <title>Buku Besar</title>
<style> <style>
@page {
margin: 20px;
}
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 12px; font-size: 12px;
margin: 0;
padding: 0;
}
.main-container {
margin: 0;
padding: 0;
}
.header-content {
page-break-inside: avoid;
page-break-after: avoid;
}
.header {
margin-bottom: 10px;
} }
h2 { h2 {
text-align: center; text-align: center;
margin-bottom: 5px; margin: 0 0 5px 0;
padding: 0;
font-size: 16px;
} }
p.periode { p.periode {
text-align: center; text-align: center;
margin-top: 0; margin: 0;
margin-bottom: 20px; padding: 0;
font-size: 11px; font-size: 12px;
}
.account-section {
page-break-inside: avoid;
margin-top: 10px;
} }
.account-info { .account-info {
background-color: #f2f2f2; background-color: #f2f2f2;
padding: 8px; padding: 8px;
margin-bottom: 10px; margin: 0 0 10px 0;
border-radius: 4px; border-radius: 4px;
} }
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
margin-bottom: 20px; margin: 0;
page-break-inside: avoid;
} }
table, th, td { table, th, td {
border: 1px solid #ddd; border: 1px solid #000;
} }
th, td { th, td {
padding: 6px; padding: 6px;
@ -551,63 +572,67 @@ public function exportPDF(Request $request)
.text-center { .text-center {
text-align: center; text-align: center;
} }
.page-break {
page-break-after: always;
}
</style> </style>
</head> </head>
<body> <body>
<h2>Buku Besar</h2> <div class="main-container">
<p class="periode">Periode: ' . date('F Y', strtotime($startDate)) . '</p>'; <div class="header-content">
<div class="header">
<h2>Buku Besar</h2>
<p class="periode">Periode: ' . date('F Y', strtotime($startDate)) . '</p>
</div>';
foreach($groupedLaporan as $kategori => $items) { foreach($groupedLaporan as $kategori => $items) {
$kodeAkun = $items->first()->kode ?? '-'; $kodeAkun = $items->first()->kode ?? '-';
$html .= ' $html .= '
<div class="account-info"> <div class="account-section">
<strong>Nama Akun:</strong> ' . $kategori . ' <div class="account-info">
<span style="float: right;"><strong>Kode Akun:</strong> ' . $kodeAkun . '</span> <strong>Nama Akun:</strong> ' . $kategori . '
</div> <span style="float: right;"><strong>Kode Akun:</strong> ' . $kodeAkun . '</span>
</div>
<table>
<thead> <table>
<tr> <thead>
<th>Tanggal</th> <tr>
<th>Keterangan</th> <th>Tanggal</th>
<th class="text-center">Ref</th> <th>Keterangan</th>
<th class="text-right">Debit</th> <th class="text-center">Ref</th>
<th class="text-right">Kredit</th> <th class="text-right">Debit</th>
<th class="text-right">Saldo</th> <th class="text-right">Kredit</th>
</tr> <th class="text-right">Saldo</th>
</thead> </tr>
<tbody>'; </thead>
<tbody>';
$runningBalance = 0;
$accountType = substr($kodeAkun, 0, 3); $runningBalance = 0;
$accountType = substr($kodeAkun, 0, 3);
foreach($items->sortBy('Tanggal') as $item) {
if (in_array($accountType, ['111', '112']) || in_array($accountType, ['251', '252'])) { foreach($items->sortBy('Tanggal') as $item) {
$runningBalance = $runningBalance + $item->debit - $item->kredit; if (in_array($accountType, ['111', '112']) || in_array($accountType, ['251', '252'])) {
} else { $runningBalance = $runningBalance + $item->debit - $item->kredit;
$runningBalance = $runningBalance - $item->debit + $item->kredit; } else {
$runningBalance = $runningBalance - $item->debit + $item->kredit;
}
$html .= '
<tr>
<td>' . date('d/m/Y', strtotime($item->Tanggal)) . '</td>
<td>' . $item->keterangan . '</td>
<td class="text-center">-</td>
<td class="text-right">' . ($item->debit > 0 ? number_format($item->debit, 0, ',', '.') : '-') . '</td>
<td class="text-right">' . ($item->kredit > 0 ? number_format($item->kredit, 0, ',', '.') : '-') . '</td>
<td class="text-right">' . number_format($runningBalance, 0, ',', '.') . '</td>
</tr>';
} }
$html .= ' $html .= '
<tr> </tbody>
<td>' . date('d/m/Y', strtotime($item->Tanggal)) . '</td> </table>
<td>' . $item->keterangan . '</td> </div>';
<td class="text-center">-</td>
<td class="text-right">' . ($item->debit > 0 ? number_format($item->debit, 0, ',', '.') : '-') . '</td>
<td class="text-right">' . ($item->kredit > 0 ? number_format($item->kredit, 0, ',', '.') : '-') . '</td>
<td class="text-right">' . number_format($runningBalance, 0, ',', '.') . '</td>
</tr>';
}
$html .= '
</tbody>
</table>';
} }
$html .= ' $html .= '
</div>
</body> </body>
</html>'; </html>';

View File

@ -1,6 +1,7 @@
@extends('Core.Sidebar') @extends('Core.Sidebar')
@section('content') @section('content')
<title>Data Akun User</title> <title>Data Akun User</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- SweetAlert2 CSS --> <!-- SweetAlert2 CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
<!-- SweetAlert2 JS --> <!-- SweetAlert2 JS -->
@ -248,20 +249,29 @@ function deleteUser(id) {
cancelButtonText: 'Batal' cancelButtonText: 'Batal'
}).then((result) => { }).then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
fetch(`/User/${id}`, { fetch(`/User/${id}`, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'X-CSRF-TOKEN': token,
'Accept': 'application/json',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} },
credentials: 'same-origin'
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
}) })
.then(response => response.json())
.then(data => { .then(data => {
if (data.success) { if (data.success) {
Swal.fire({ Swal.fire({
icon: 'success', icon: 'success',
title: 'Berhasil!', title: 'Berhasil!',
text: 'Data user berhasil dihapus', text: data.message || 'Data user berhasil dihapus',
confirmButtonText: 'OK' confirmButtonText: 'OK'
}).then(() => { }).then(() => {
loadUsers( loadUsers(