diff --git a/app/Http/Controllers/LaporanController.php b/app/Http/Controllers/LaporanController.php index 603287a..052e03b 100644 --- a/app/Http/Controllers/LaporanController.php +++ b/app/Http/Controllers/LaporanController.php @@ -57,9 +57,13 @@ public function exportExcel(Request $request) try { $startDate = $request->input('start_date', Carbon::now()->startOfMonth()->format('Y-m-d')); $endDate = $request->input('end_date', Carbon::now()->endOfMonth()->format('Y-m-d')); - $laporan = LaporanModel::whereBetween('Tanggal', [$startDate, $endDate]) - ->orderBy('Tanggal', 'desc') - ->get(); + $sortOrder = $request->input('sort_order', 'asc'); + $laporanQuery = LaporanModel::whereBetween('Tanggal', [$startDate, $endDate]); + if ($sortOrder == 'desc') { + $laporan = $laporanQuery->orderBy('Tanggal', 'desc')->get(); + } else { + $laporan = $laporanQuery->orderBy('Tanggal', 'asc')->get(); + } $rows = []; $no = 1; @@ -141,8 +145,8 @@ public function exportExcel(Request $request) 'Kode Akun' => $kodeAkun, 'Nama Akun' => $namaAkun, 'Keterangan' => $item->keterangan . ' ' . $item->nama_karyawan, - 'Debit' => $rowDebit > 0 ? number_format($rowDebit, 0, ',', '.') : '-', - 'Kredit' => $rowKredit > 0 ? number_format($rowKredit, 0, ',', '.') : '-' + 'Debit' => $rowDebit > 0 ? $rowDebit : '', + 'Kredit' => $rowKredit > 0 ? $rowKredit : '' ]; } @@ -153,8 +157,8 @@ public function exportExcel(Request $request) 'Kode Akun' => '', 'Nama Akun' => '', 'Keterangan' => 'Total', - 'Debit' => number_format($totalDebit, 0, ',', '.'), - 'Kredit' => number_format($totalKredit, 0, ',', '.') + 'Debit' => $totalDebit, + 'Kredit' => $totalKredit ]; $export = new class($rows) implements FromCollection, WithHeadings { @@ -177,9 +181,13 @@ public function exportPDF(Request $request) try { $startDate = $request->input('start_date', Carbon::now()->startOfMonth()->format('Y-m-d')); $endDate = $request->input('end_date', Carbon::now()->endOfMonth()->format('Y-m-d')); - $laporan = LaporanModel::whereBetween('Tanggal', [$startDate, $endDate]) - ->orderBy('Tanggal', 'desc') - ->get(); + $sortOrder = $request->input('sort_order', 'asc'); + $laporanQuery = LaporanModel::whereBetween('Tanggal', [$startDate, $endDate]); + if ($sortOrder == 'desc') { + $laporan = $laporanQuery->orderBy('Tanggal', 'desc')->get(); + } else { + $laporan = $laporanQuery->orderBy('Tanggal', 'asc')->get(); + } $rows = ''; $no = 1; diff --git a/app/Http/Controllers/RekeningController.php b/app/Http/Controllers/RekeningController.php index 2c85145..48f429c 100644 --- a/app/Http/Controllers/RekeningController.php +++ b/app/Http/Controllers/RekeningController.php @@ -405,18 +405,36 @@ public function collection() // Tambahkan data transaksi $runningBalance = 0; + $transaksiPerHari = []; + + // Kelompokkan transaksi berdasarkan tanggal foreach ($items->sortBy('Tanggal') as $item) { - $accountType = substr($item->kode, 0, 3); - $runningBalance = $this->calculateBalance($runningBalance, $item->debit, $item->kredit, $accountType); - - $exportData->push([ - Carbon::parse($item->Tanggal)->format('d/m/Y'), - $item->keterangan, - '-', - $item->debit > 0 ? number_format($item->debit, 0, ',', '.') : '-', - $item->kredit > 0 ? number_format($item->kredit, 0, ',', '.') : '-', - number_format($runningBalance, 0, ',', '.') - ]); + $tanggalTransaksi = date('Y-m-d', strtotime($item->Tanggal)); + if (!isset($transaksiPerHari[$tanggalTransaksi])) { + $transaksiPerHari[$tanggalTransaksi] = []; + } + $transaksiPerHari[$tanggalTransaksi][] = $item; + } + + // Proses setiap transaksi per hari + foreach ($transaksiPerHari as $tanggal => $transaksis) { + $nomorUrut = 1; + foreach ($transaksis as $item) { + $accountType = substr($item->kode, 0, 3); + $runningBalance = $this->calculateBalance($runningBalance, $item->debit, $item->kredit, $accountType); + + // Format Ref + $ref = 'JU/' . date('Y-m-d', strtotime($tanggal)) . '/' . str_pad($nomorUrut++, 3, '0', STR_PAD_LEFT); + + $exportData->push([ + Carbon::parse($item->Tanggal)->format('d/m/Y'), + $item->keterangan, + $ref, + $item->debit > 0 ? $item->debit : '', + $item->kredit > 0 ? $item->kredit : '', + $runningBalance + ]); + } } // Tambahkan baris kosong setelah setiap kategori @@ -607,22 +625,39 @@ public function exportPDF(Request $request) $runningBalance = 0; $accountType = substr($kodeAkun, 0, 3); + // Kelompokkan transaksi berdasarkan tanggal + $transaksiPerHari = []; 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; + $tanggalTransaksi = date('Y-m-d', strtotime($item->Tanggal)); + if (!isset($transaksiPerHari[$tanggalTransaksi])) { + $transaksiPerHari[$tanggalTransaksi] = []; + } + $transaksiPerHari[$tanggalTransaksi][] = $item; + } + + // Proses setiap transaksi per hari + foreach($transaksiPerHari as $tanggal => $transaksis) { + $nomorUrut = 1; + foreach($transaksis 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; + } + + // Format Ref + $ref = 'JU/' . date('Y-m-d', strtotime($tanggal)) . '/' . str_pad($nomorUrut++, 3, '0', STR_PAD_LEFT); + + $html .= ' +