update tgl 22 april

This commit is contained in:
whywdd 2025-04-22 00:26:27 +07:00
parent 70aadac250
commit dbc6d467aa
5 changed files with 229 additions and 137 deletions

View File

@ -140,7 +140,7 @@ public function index(Request $request)
$lastMonthTransaksis = DB::table('laporan_transaksis') $lastMonthTransaksis = DB::table('laporan_transaksis')
->whereBetween('Tanggal', [$lastMonthStart, $lastMonthEnd]) ->whereBetween('Tanggal', [$lastMonthStart, $lastMonthEnd])
->get(); ->get();
$lastMonthUangMasuk = 0; $lastMonthUangMasuk = 0;
$lastMonthUangKeluar = 0; $lastMonthUangKeluar = 0;
@ -185,22 +185,22 @@ public function index(Request $request)
}) })
)->values(); )->values();
// Get monthly totals for chart // Get monthly totals for chart
$monthlyTotals = DB::table('laporan_transaksis') $monthlyTotals = DB::table('laporan_transaksis')
->select( ->select(
DB::raw('DATE_FORMAT(Tanggal, "%Y-%m") as periode'), DB::raw('DATE_FORMAT(Tanggal, "%Y-%m") as periode'),
DB::raw('SUM(uang_masuk) + SUM(COALESCE(uang_masuk2, 0)) + SUM(COALESCE(uang_masuk3, 0)) + SUM(COALESCE(uang_masuk4, 0)) + SUM(COALESCE(uang_masuk5, 0)) as total_debit'), DB::raw('SUM(uang_masuk) + SUM(COALESCE(uang_masuk2, 0)) + SUM(COALESCE(uang_masuk3, 0)) + SUM(COALESCE(uang_masuk4, 0)) + SUM(COALESCE(uang_masuk5, 0)) as total_debit'),
DB::raw('SUM(uang_keluar) + SUM(COALESCE(uang_keluar2, 0)) + SUM(COALESCE(uang_keluar3, 0)) + SUM(COALESCE(uang_keluar4, 0)) + SUM(COALESCE(uang_keluar5, 0)) as total_kredit') DB::raw('SUM(uang_keluar) + SUM(COALESCE(uang_keluar2, 0)) + SUM(COALESCE(uang_keluar3, 0)) + SUM(COALESCE(uang_keluar4, 0)) + SUM(COALESCE(uang_keluar5, 0)) as total_kredit')
) )
->groupBy('periode') ->groupBy('periode')
->orderBy('periode') ->orderBy('periode')
->get(); ->get();
// Get recent transactions // Get recent transactions
$recentTransactions = DB::table('laporan_transaksis') $recentTransactions = DB::table('laporan_transaksis')
->orderBy('Tanggal', 'desc') ->orderBy('Tanggal', 'desc')
->limit(10) ->limit(10)
->get(); ->get();
// Debug log untuk memeriksa nilai // Debug log untuk memeriksa nilai
Log::info("Total Uang Masuk: " . $totalUangMasuk); Log::info("Total Uang Masuk: " . $totalUangMasuk);
@ -209,19 +209,19 @@ public function index(Request $request)
Log::info("Laba Rugi Total: " . $labaRugiTotal); Log::info("Laba Rugi Total: " . $labaRugiTotal);
Log::info("Laba Rugi Bulan Ini: " . $labaRugiBulanIni); Log::info("Laba Rugi Bulan Ini: " . $labaRugiBulanIni);
return view('home', compact( return view('home', compact(
'startDate', 'startDate',
'endDate', 'endDate',
'totalUangMasuk', 'totalUangMasuk',
'totalUangKeluar', 'totalUangKeluar',
'currentMonthUangMasuk', 'currentMonthUangMasuk',
'currentMonthUangKeluar', 'currentMonthUangKeluar',
'totalSaldo', 'totalSaldo',
'growthPercentage', 'growthPercentage',
'labaRugiTotal', 'labaRugiTotal',
'labaRugiBulanIni', 'labaRugiBulanIni',
'monthlyTotals', 'monthlyTotals',
'categoryTotals', 'categoryTotals',
'recentTransactions', 'recentTransactions',
'pendapatan', 'pendapatan',
'beban' 'beban'

View File

@ -10,77 +10,70 @@ class NeracasaldoController extends Controller
public function index() public function index()
{ {
$rawTransaksis = NeracasaldoModel::orderBy('kode', 'asc')->get(); $rawTransaksis = NeracasaldoModel::orderBy('kode', 'asc')->get();
$transaksis = collect(); $totalsPerAkun = [];
foreach ($rawTransaksis as $transaksi) { foreach ($rawTransaksis as $transaksi) {
// Menambahkan baris untuk kode utama // Fungsi untuk menambahkan atau memperbarui total per akun
if ($transaksi->kode) { $processAkun = function($kode, $kategori, $debit, $kredit) use (&$totalsPerAkun) {
$transaksis->push([ if (!empty($kode) && !empty($kategori)) {
'kode' => $transaksi->kode, if (!isset($totalsPerAkun[$kategori])) {
'kategori' => $transaksi->kategori, $totalsPerAkun[$kategori] = [
'keterangan' => $transaksi->keterangan, 'kode' => $kode,
'nama_karyawan' => $transaksi->nama_karyawan, 'kategori' => $kategori,
'debit' => $transaksi->uang_masuk, 'debit' => 0,
'kredit' => $transaksi->uang_keluar, 'kredit' => 0
'id' => $transaksi->id ];
]); }
} $totalsPerAkun[$kategori]['debit'] += floatval($debit ?? 0);
$totalsPerAkun[$kategori]['kredit'] += floatval($kredit ?? 0);
}
};
// Menambahkan baris untuk kode2 // Proses untuk semua kategori
if ($transaksi->kode2) { $processAkun($transaksi->kode, $transaksi->kategori, $transaksi->uang_masuk, $transaksi->uang_keluar);
$transaksis->push([ $processAkun($transaksi->kode2, $transaksi->kategori2, $transaksi->uang_masuk2, $transaksi->uang_keluar2);
'kode' => $transaksi->kode2, $processAkun($transaksi->kode3, $transaksi->kategori3, $transaksi->uang_masuk3, $transaksi->uang_keluar3);
'kategori' => $transaksi->kategori2, $processAkun($transaksi->kode4, $transaksi->kategori4, $transaksi->uang_masuk4, $transaksi->uang_keluar4);
'keterangan' => $transaksi->keterangan, $processAkun($transaksi->kode5, $transaksi->kategori5, $transaksi->uang_masuk5, $transaksi->uang_keluar5);
'nama_karyawan' => $transaksi->nama_karyawan, }
'debit' => $transaksi->uang_masuk2,
'kredit' => $transaksi->uang_keluar2,
'id' => $transaksi->id
]);
}
// Menambahkan baris untuk kode3 // Hitung saldo akhir dan atur posisi debit/kredit sesuai jenis akun
if ($transaksi->kode3) { $finalTransaksis = [];
$transaksis->push([ foreach ($totalsPerAkun as $kategori => $data) {
'kode' => $transaksi->kode3, $kodeAwal = substr($data['kode'], 0, 3);
'kategori' => $transaksi->kategori3, $saldo = $data['debit'] - $data['kredit'];
'keterangan' => $transaksi->keterangan,
'nama_karyawan' => $transaksi->nama_karyawan, // Tentukan posisi saldo (debit/kredit) berdasarkan jenis akun
'debit' => $transaksi->uang_masuk3, if (in_array($kodeAwal, ['111', '112']) || in_array($kodeAwal, ['251', '252'])) {
'kredit' => $transaksi->uang_keluar3, // Aktiva dan Beban: saldo normal di debit
'id' => $transaksi->id if ($saldo != 0) {
]); $finalTransaksis[] = [
} 'kode' => $data['kode'],
'kategori' => $kategori,
// Menambahkan baris untuk kode4 'debit' => $saldo,
if ($transaksi->kode4) { 'kredit' => 0
$transaksis->push([ ];
'kode' => $transaksi->kode4, }
'kategori' => $transaksi->kategori4, } else {
'keterangan' => $transaksi->keterangan, // Pasiva dan Pendapatan: saldo normal di kredit
'nama_karyawan' => $transaksi->nama_karyawan, if ($saldo != 0) {
'debit' => $transaksi->uang_masuk4, $finalTransaksis[] = [
'kredit' => $transaksi->uang_keluar4, 'kode' => $data['kode'],
'id' => $transaksi->id 'kategori' => $kategori,
]); 'debit' => 0,
} 'kredit' => -$saldo
];
// Menambahkan baris untuk kode5 }
if ($transaksi->kode5) {
$transaksis->push([
'kode' => $transaksi->kode5,
'kategori' => $transaksi->kategori5,
'keterangan' => $transaksi->keterangan,
'nama_karyawan' => $transaksi->nama_karyawan,
'debit' => $transaksi->uang_masuk5,
'kredit' => $transaksi->uang_keluar5,
'id' => $transaksi->id
]);
} }
} }
// Mengurutkan berdasarkan kode // Urutkan berdasarkan kode
$transaksis = $transaksis->sortBy('kode'); usort($finalTransaksis, function($a, $b) {
return $a['kode'] <=> $b['kode'];
});
// Konversi ke collection setelah selesai
$transaksis = collect($finalTransaksis);
return view('Neracasaldo', compact('transaksis')); return view('Neracasaldo', compact('transaksis'));
} }

View File

@ -30,35 +30,54 @@ public function index(Request $request)
// Kelompokkan data berdasarkan kategori // Kelompokkan data berdasarkan kategori
$groupedLaporan = collect(); $groupedLaporan = collect();
// Kelompokkan berdasarkan kategori 1-5 // Proses semua data transaksi
for ($i = 1; $i <= 5; $i++) { foreach ($laporan as $item) {
$kategoriField = $i === 1 ? 'kategori' : "kategori{$i}"; // Proses untuk kategori utama
$uangMasukField = $i === 1 ? 'uang_masuk' : "uang_masuk{$i}"; if (!empty($item->kategori)) {
$uangKeluarField = $i === 1 ? 'uang_keluar' : "uang_keluar{$i}"; $kategori = $item->kategori;
if (!isset($groupedLaporan[$kategori])) {
$groupedLaporan[$kategori] = collect();
}
$groupedLaporan[$kategori]->push((object)[
'id' => $item->id,
'Tanggal' => $item->Tanggal,
'keterangan' => $item->keterangan,
'kode' => $this->generateKode($kategori),
'debit' => $item->uang_masuk ?? 0,
'kredit' => $item->uang_keluar ?? 0
]);
}
$filteredLaporan = $laporan->filter(function ($item) use ($kategoriField) { // Proses untuk kategori tambahan (2-5)
return !empty($item->$kategoriField); for ($i = 2; $i <= 5; $i++) {
}); $kategoriField = "kategori{$i}";
$uangMasukField = "uang_masuk{$i}";
foreach ($filteredLaporan->groupBy($kategoriField) as $kategori => $items) { $uangKeluarField = "uang_keluar{$i}";
if (!empty($kategori)) {
$groupedLaporan[$kategori] = $items->map(function ($item) use ($kategoriField, $uangMasukField, $uangKeluarField) { if (!empty($item->$kategoriField)) {
// Gunakan kode yang sesuai dengan nama kategori $kategori = $item->$kategoriField;
$kode = $this->generateKode($item->$kategoriField); if (!isset($groupedLaporan[$kategori])) {
$groupedLaporan[$kategori] = collect();
return (object)[ }
'id' => $item->id,
'Tanggal' => $item->Tanggal, $groupedLaporan[$kategori]->push((object)[
'keterangan' => $item->keterangan, 'id' => $item->id,
'kode' => $kode, 'Tanggal' => $item->Tanggal,
'debit' => $item->$uangMasukField ?? 0, 'keterangan' => $item->keterangan,
'kredit' => $item->$uangKeluarField ?? 0 'kode' => $this->generateKode($kategori),
]; 'debit' => $item->$uangMasukField ?? 0,
}); 'kredit' => $item->$uangKeluarField ?? 0
]);
} }
} }
} }
// Urutkan transaksi berdasarkan tanggal untuk setiap kategori
foreach ($groupedLaporan as $kategori => $items) {
$groupedLaporan[$kategori] = $items->sortBy('Tanggal');
}
// Hitung total untuk setiap kategori // Hitung total untuk setiap kategori
$totals = []; $totals = [];
foreach ($groupedLaporan as $kategori => $items) { foreach ($groupedLaporan as $kategori => $items) {

View File

@ -24,45 +24,40 @@
<thead> <thead>
<tr class="bg-gray-100 text-gray-600 uppercase text-sm leading-normal"> <tr class="bg-gray-100 text-gray-600 uppercase text-sm leading-normal">
<th class="py-3 px-4 text-left">Kode</th> <th class="py-3 px-4 text-left">Kode</th>
<th class="py-3 px-4 text-left">Kategori</th> <th class="py-3 px-4 text-left">Nama Akun</th>
<th class="py-3 px-4 text-left">Keterangan</th>
<th class="py-3 px-4 text-right">Debit</th> <th class="py-3 px-4 text-right">Debit</th>
<th class="py-3 px-4 text-right">Kredit</th> <th class="py-3 px-4 text-right">Kredit</th>
<th class="py-3 px-4 text-center">Aksi</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php
$totalDebit = 0;
$totalKredit = 0;
@endphp
@foreach($transaksis as $transaksi) @foreach($transaksis as $transaksi)
<tr class="border-b border-gray-200 hover:bg-gray-100"> <tr class="border-b border-gray-200 hover:bg-gray-100">
<td class="py-3 px-4">{{ $transaksi['kode'] }}</td> <td class="py-3 px-4">{{ $transaksi['kode'] }}</td>
<td class="py-3 px-4">{{ $transaksi['kategori'] }}</td> <td class="py-3 px-4">{{ $transaksi['kategori'] }}</td>
<td class="py-3 px-4">{{ $transaksi['keterangan'] }}</td>
<td class="py-3 px-4 text-right"> <td class="py-3 px-4 text-right">
@if($transaksi['debit'] > 0) @php $totalDebit += $transaksi['debit']; @endphp
{{ number_format($transaksi['debit'], 2) }} {{ $transaksi['debit'] != 0 ? ($transaksi['debit'] < 0 ? '-' : '') . number_format(abs($transaksi['debit']), 0, ',', '.') : '-' }}
@endif
</td> </td>
<td class="py-3 px-4 text-right"> <td class="py-3 px-4 text-right">
@if($transaksi['kredit'] > 0) @php $totalKredit += $transaksi['kredit']; @endphp
{{ number_format($transaksi['kredit'], 2) }} {{ $transaksi['kredit'] != 0 ? ($transaksi['kredit'] < 0 ? '-' : '') . number_format(abs($transaksi['kredit']), 0, ',', '.') : '-' }}
@endif
</td>
<td class="py-3 px-4 text-center">
<div class="flex item-center justify-center">
<a href="{{ route('neracasaldo.edit', $transaksi['id']) }}" class="w-4 mr-2 transform hover:text-purple-500 hover:scale-110">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('neracasaldo.destroy', $transaksi['id']) }}" method="POST" class="inline">
@csrf
@method('DELETE')
<button type="submit" class="w-4 mr-2 transform hover:text-red-500 hover:scale-110" onclick="return confirm('Apakah Anda yakin ingin menghapus data ini?')">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td> </td>
</tr> </tr>
@endforeach @endforeach
<!-- Total Row -->
<tr class="bg-gray-50 font-bold">
<td class="py-3 px-4" colspan="2">Total</td>
<td class="py-3 px-4 text-right">
{{ $totalDebit != 0 ? ($totalDebit < 0 ? '-' : '') . number_format(abs($totalDebit), 0, ',', '.') : '-' }}
</td>
<td class="py-3 px-4 text-right">
{{ $totalKredit != 0 ? ($totalKredit < 0 ? '-' : '') . number_format(abs($totalKredit), 0, ',', '.') : '-' }}
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -1,6 +1,45 @@
@extends('Core.Sidebar') @extends('Core.Sidebar')
@section('content') @section('content')
@php
function getAccountTypePHP($kodeAkun) {
$kode = (string)$kodeAkun;
if (str_starts_with($kode, '111') || str_starts_with($kode, '112')) {
return 'AKTIVA';
} else if (str_starts_with($kode, '121') || str_starts_with($kode, '122') || str_starts_with($kode, '131')) {
return 'PASIVA';
} else if (str_starts_with($kode, '241') || str_starts_with($kode, '242')) {
return 'PENDAPATAN';
} else if (str_starts_with($kode, '251') || str_starts_with($kode, '252')) {
return 'BEBAN';
}
return 'UNKNOWN';
}
function calculateBalancePHP($previousBalance, $debit, $kredit, $accountType) {
$balance = $previousBalance;
switch($accountType) {
case 'AKTIVA':
// Aktiva: bertambah di debit, berkurang di kredit
$balance = $balance + $debit - $kredit;
break;
case 'PASIVA':
case 'PENDAPATAN':
// Pasiva & Pendapatan: bertambah di kredit, berkurang di debit
$balance = $balance - $debit + $kredit;
break;
case 'BEBAN':
// Beban: bertambah di debit, berkurang di kredit
$balance = $balance + $debit - $kredit;
break;
default:
$balance = $balance + $debit - $kredit;
}
return $balance;
}
@endphp
<title>Buku Besar Perusahaan Dagang</title> <title>Buku Besar Perusahaan Dagang</title>
<!-- Tailwind CSS --> <!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
@ -22,6 +61,7 @@
@php @php
$kodeAkun = $items->first()->kode ?? '-'; $kodeAkun = $items->first()->kode ?? '-';
$runningBalance = 0; $runningBalance = 0;
$accountType = substr($kodeAkun, 0, 3);
@endphp @endphp
<div class="mb-8"> <div class="mb-8">
@ -50,14 +90,15 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($items as $item) @php
@php $runningBalance = 0;
$runningBalance += ($item->debit - $item->kredit); $accountType = getAccountTypePHP($kodeAkun);
@endphp @endphp
@foreach($items->sortBy('Tanggal') as $item)
<tr class="border-b border-gray-200 hover:bg-gray-50"> <tr class="border-b border-gray-200 hover:bg-gray-50">
<td class="py-3 px-4">{{ date('d/m/Y', strtotime($item->Tanggal)) }}</td> <td class="py-3 px-4">{{ date('d/m/Y', strtotime($item->Tanggal)) }}</td>
<td class="py-3 px-4">{{ $item->keterangan }}</td> <td class="py-3 px-4">{{ $item->keterangan }}</td>
<td class="py-3 px-4 text-center">-</td> <td class="py-3 px-4 text-center">{{ $item->kode }}</td>
<td class="py-3 px-4 text-right"> <td class="py-3 px-4 text-right">
@if($item->debit > 0) @if($item->debit > 0)
{{ number_format($item->debit, 0, ',', '.') }} {{ number_format($item->debit, 0, ',', '.') }}
@ -72,7 +113,13 @@
- -
@endif @endif
</td> </td>
<td class="py-3 px-4 text-right">{{ number_format($runningBalance, 0, ',', '.') }}</td> <td class="py-3 px-4 text-right">
@php
$runningBalance = calculateBalancePHP($runningBalance, $item->debit ?? 0, $item->kredit ?? 0, $accountType);
$displayBalance = $runningBalance < 0 ? '-' . number_format(abs($runningBalance), 0, ',', '.') : number_format($runningBalance, 0, ',', '.');
@endphp
{{ $displayBalance }}
</td>
<td class="py-3 px-4 text-center"> <td class="py-3 px-4 text-center">
<div class="flex justify-center space-x-2"> <div class="flex justify-center space-x-2">
<button class="text-blue-600 hover:text-blue-800" title="Edit"> <button class="text-blue-600 hover:text-blue-800" title="Edit">
@ -142,6 +189,44 @@
</style> </style>
<script> <script>
function getAccountType(kodeAkun) {
const kode = kodeAkun.toString();
if (kode.startsWith('111') || kode.startsWith('112')) {
return 'AKTIVA';
} else if (kode.startsWith('121') || kode.startsWith('122') || kode.startsWith('131')) {
return 'PASIVA';
} else if (kode.startsWith('241') || kode.startsWith('242')) {
return 'PENDAPATAN';
} else if (kode.startsWith('251') || kode.startsWith('252')) {
return 'BEBAN';
}
return 'UNKNOWN';
}
function calculateBalance(previousBalance, debit, kredit, accountType) {
let balance = previousBalance;
switch(accountType) {
case 'AKTIVA':
// Aktiva: bertambah di debit, berkurang di kredit
balance = balance + debit - kredit;
break;
case 'PASIVA':
case 'PENDAPATAN':
// Pasiva & Pendapatan: bertambah di kredit, berkurang di debit
balance = balance - debit + kredit;
break;
case 'BEBAN':
// Beban: bertambah di debit, berkurang di kredit
balance = balance + debit - kredit;
break;
default:
balance = balance + debit - kredit;
}
return balance;
}
function hapusData(id) { function hapusData(id) {
if (confirm('Apakah Anda yakin ingin menghapus data ini?')) { if (confirm('Apakah Anda yakin ingin menghapus data ini?')) {
fetch(`/laporan/${id}`, { fetch(`/laporan/${id}`, {