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) {
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 .= '</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;}
table{width:100%;border-collapse:collapse;margin-bottom:20px;}
table,th,td{border:1px solid #ddd;}
@ -284,7 +284,7 @@ public function exportPDF(Request $request)
.text-center{text-align:center;}
td{vertical-align:top;}
</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 .= '<table><thead><tr>
<th style="text-align:center">No</th>
@ -299,7 +299,7 @@ public function exportPDF(Request $request)
$html .= '</tbody></table></body></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) {
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)
{
try {
// Ambil parameter filter tanggal jika ada
// Ambil parameter filter tanggal
$startDate = $request->input('start_date', Carbon::now()->startOfMonth()->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;
$totalKredit = 0;
// Proses data seperti di fungsi index
// Proses data transaksi
foreach ($rawTransaksis as $transaksi) {
$processAkun = function($kode, $kategori, $debit, $kredit) use (&$totalsPerAkun) {
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->kode2, $transaksi->kategori2, $transaksi->uang_masuk2, $transaksi->uang_keluar2);
$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);
}
// Proses saldo untuk setiap akun
foreach ($totalsPerAkun as $kategori => $data) {
$kodeAwal = substr($data['kode'], 0, 3);
$saldo = $data['debit'] - $data['kredit'];
if (in_array($kodeAwal, ['111', '112']) || in_array($kodeAwal, ['251', '252'])) {
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $saldo > 0 ? abs($saldo) : 0,
'kredit' => $saldo < 0 ? abs($saldo) : 0
];
$totalDebit += $saldo > 0 ? abs($saldo) : 0;
$totalKredit += $saldo < 0 ? abs($saldo) : 0;
// Reset nilai debit dan kredit
$debit = 0;
$kredit = 0;
// Logika untuk menentukan posisi saldo
if (in_array($kodeAwal, ['111', '112', '251', '252'])) {
// Aktiva dan Beban
if ($saldo > 0) {
$debit = $saldo;
} else {
$kredit = abs($saldo);
}
} else {
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $saldo < 0 ? abs($saldo) : 0,
'kredit' => $saldo > 0 ? abs($saldo) : 0
];
$totalDebit += $saldo < 0 ? abs($saldo) : 0;
$totalKredit += $saldo > 0 ? abs($saldo) : 0;
// Pasiva dan Pendapatan
if ($saldo < 0) {
$kredit = abs($saldo);
} else {
$debit = $saldo;
}
}
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $debit,
'kredit' => $kredit
];
$totalDebit += $debit;
$totalKredit += $kredit;
}
}
// Tambahkan baris total
@ -227,13 +237,23 @@ public function exportExcel(Request $request)
'kredit' => $totalKredit
];
// Buat class export inline
// Buat class export inline dengan format yang diperbaiki
$export = new class($processedData) implements FromCollection, WithHeadings {
protected $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()
@ -302,32 +322,48 @@ public function exportPDF(Request $request)
$kodeAwal = substr($data['kode'], 0, 3);
$saldo = $data['debit'] - $data['kredit'];
if (in_array($kodeAwal, ['111', '112']) || in_array($kodeAwal, ['251', '252'])) {
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $saldo > 0 ? abs($saldo) : 0,
'kredit' => $saldo < 0 ? abs($saldo) : 0
];
$totalDebit += $saldo > 0 ? abs($saldo) : 0;
$totalKredit += $saldo < 0 ? abs($saldo) : 0;
// Reset nilai debit dan kredit
$debit = 0;
$kredit = 0;
// Logika untuk menentukan posisi saldo
if (in_array($kodeAwal, ['111', '112', '251', '252'])) {
// Aktiva dan Beban
if ($saldo > 0) {
$debit = $saldo;
} else {
$kredit = abs($saldo);
}
} else {
if ($saldo != 0) {
$processedData[] = [
'kode' => $data['kode'],
'kategori' => $kategori,
'debit' => $saldo < 0 ? abs($saldo) : 0,
'kredit' => $saldo > 0 ? abs($saldo) : 0
];
$totalDebit += $saldo < 0 ? abs($saldo) : 0;
$totalKredit += $saldo > 0 ? abs($saldo) : 0;
// Pasiva dan Pendapatan
if ($saldo < 0) {
$kredit = abs($saldo);
} else {
$debit = $saldo;
}
}
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 = '
<!DOCTYPE html>
<html>
@ -354,23 +390,25 @@ public function exportPDF(Request $request)
margin-bottom: 20px;
}
table, th, td {
border: 1px solid #ddd;
border: 1px solid #000;
}
th, td {
padding: 6px;
padding: 8px;
text-align: left;
font-size: 10px;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
.text-right {
text-align: right;
}
tfoot td {
.total-row td {
font-weight: bold;
background-color: #f9f9f9;
background-color: #f2f2f2;
}
.amount {
text-align: right;
white-space: nowrap;
}
</style>
</head>
@ -381,10 +419,10 @@ public function exportPDF(Request $request)
<table>
<thead>
<tr>
<th>Kode</th>
<th>Nama Akun</th>
<th class="text-right">Debit</th>
<th class="text-right">Kredit</th>
<th style="width: 15%;">Kode</th>
<th style="width: 45%;">Nama Akun</th>
<th style="width: 20%;" class="amount">Debit</th>
<th style="width: 20%;" class="amount">Kredit</th>
</tr>
</thead>
<tbody>';
@ -395,8 +433,8 @@ public function exportPDF(Request $request)
<tr>
<td>'.$data['kode'].'</td>
<td>'.$data['kategori'].'</td>
<td class="text-right">'.($data['debit'] > 0 ? 'Rp '.number_format($data['debit'], 0, ',', '.') : '-').'</td>
<td class="text-right">'.($data['kredit'] > 0 ? 'Rp '.number_format($data['kredit'], 0, ',', '.') : '-').'</td>
<td class="amount">'.($data['debit'] > 0 ? number_format($data['debit'], 0, ',', '.') : '-').'</td>
<td class="amount">'.($data['kredit'] > 0 ? number_format($data['kredit'], 0, ',', '.') : '-').'</td>
</tr>';
}
}
@ -404,10 +442,10 @@ public function exportPDF(Request $request)
$html .= '
</tbody>
<tfoot>
<tr>
<td colspan="2" class="text-right">Total:</td>
<td class="text-right">Rp '.number_format($totalDebit, 0, ',', '.').'</td>
<td class="text-right">Rp '.number_format($totalKredit, 0, ',', '.').'</td>
<tr class="total-row">
<td colspan="2" style="text-align: right;">Total:</td>
<td class="amount">'.number_format($totalDebit, 0, ',', '.').'</td>
<td class="amount">'.number_format($totalKredit, 0, ',', '.').'</td>
</tr>
</tfoot>
</table>

View File

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

View File

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