diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 1858fd1..1e0a239 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -173,17 +173,21 @@ public function index(Request $request)
}
}
- // Get monthly totals for chart
+ // Get daily totals for chart
$monthlyTotals = DB::table('laporan_transaksis')
->select(
- DB::raw('DATE_FORMAT(Tanggal, "%Y-%m") as periode'),
- DB::raw('SUM(CASE WHEN LEFT(kategori, 3) IN ("241", "242") THEN uang_masuk ELSE 0 END) as total_debit'),
- DB::raw('SUM(CASE WHEN LEFT(kategori, 3) IN ("251", "252") THEN uang_keluar ELSE 0 END) as total_kredit')
+ DB::raw('DATE_FORMAT(Tanggal, "%Y-%m-%d") as periode'),
+ DB::raw('SUM(uang_masuk) as total_debit'),
+ DB::raw('SUM(uang_keluar) as total_kredit')
)
+ ->whereBetween('Tanggal', [$startDate, $endDate])
->groupBy('periode')
->orderBy('periode')
->get();
+ // Debug untuk memastikan data terisi
+ Log::info('Daily Totals:', ['data' => $monthlyTotals->toArray()]);
+
// Get category totals for distribution chart
$categoryTotals = DB::table('laporan_transaksis')
->select(
@@ -242,6 +246,63 @@ public function index(Request $request)
(($currentMonthLabaRugi - $lastMonthLabaRugi) / abs($lastMonthLabaRugi)) * 100 :
100;
+ // Ambil data neraca saldo untuk pie chart
+ $rawTransaksis = DB::table('laporan_transaksis')
+ ->whereBetween('Tanggal', [$startDate, $endDate])
+ ->orderBy('kode', 'asc')
+ ->get();
+ $totalsPerAkun = [];
+ foreach ($rawTransaksis as $transaksi) {
+ $processAkun = function($kode, $kategori, $debit, $kredit) use (&$totalsPerAkun) {
+ if (!empty($kode) && !empty($kategori)) {
+ if (!isset($totalsPerAkun[$kategori])) {
+ $totalsPerAkun[$kategori] = [
+ 'kode' => $kode,
+ 'kategori' => $kategori,
+ 'debit' => 0,
+ 'kredit' => 0
+ ];
+ }
+ $totalsPerAkun[$kategori]['debit'] += floatval($debit ?? 0);
+ $totalsPerAkun[$kategori]['kredit'] += floatval($kredit ?? 0);
+ }
+ };
+ $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);
+ $processAkun($transaksi->kode4, $transaksi->kategori4, $transaksi->uang_masuk4, $transaksi->uang_keluar4);
+ $processAkun($transaksi->kode5, $transaksi->kategori5, $transaksi->uang_masuk5, $transaksi->uang_keluar5);
+ }
+ $finalTransaksis = [];
+ 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) {
+ $finalTransaksis[] = [
+ 'kode' => $data['kode'],
+ 'kategori' => $kategori,
+ 'debit' => $saldo,
+ 'kredit' => 0
+ ];
+ }
+ } else {
+ if ($saldo != 0) {
+ $finalTransaksis[] = [
+ 'kode' => $data['kode'],
+ 'kategori' => $kategori,
+ 'debit' => 0,
+ 'kredit' => -$saldo
+ ];
+ }
+ }
+ }
+ $neracaTransaksis = collect($finalTransaksis);
+ $pieLabels = $neracaTransaksis->pluck('kategori')->toArray();
+ $pieData = $neracaTransaksis->map(function($item) {
+ return abs($item['debit']) + abs($item['kredit']);
+ })->toArray();
+
return view('home', compact(
'startDate',
'endDate',
@@ -254,7 +315,9 @@ public function index(Request $request)
'categoryTotals',
'recentTransactions',
'pendapatan',
- 'beban'
+ 'beban',
+ 'pieLabels',
+ 'pieData'
));
} catch (\Exception $e) {
diff --git a/app/Http/Controllers/LabarugiController.php b/app/Http/Controllers/LabarugiController.php
index 94a5ab2..ea45836 100644
--- a/app/Http/Controllers/LabarugiController.php
+++ b/app/Http/Controllers/LabarugiController.php
@@ -134,4 +134,202 @@ public function filter(Request $request)
{
return $this->index($request);
}
+
+ 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'));
+
+ // Inisialisasi array untuk menyimpan data
+ $pendapatan = [];
+ $beban = [];
+
+ // Ambil semua transaksi dalam periode
+ $transaksis = DB::table('laporan_transaksis')
+ ->whereBetween('Tanggal', [$startDate, $endDate])
+ ->get();
+
+ foreach ($transaksis as $transaksi) {
+ // Proses kategori1
+ if (!empty($transaksi->kategori)) {
+ $this->prosesKategori(
+ $transaksi->kategori,
+ $transaksi->uang_masuk ?? 0,
+ $transaksi->uang_keluar ?? 0,
+ $pendapatan,
+ $beban
+ );
+ }
+
+ // Proses kategori2-5
+ for ($i = 2; $i <= 5; $i++) {
+ $kategori = $transaksi->{"kategori$i"};
+ if (!empty($kategori)) {
+ $this->prosesKategori(
+ $kategori,
+ $transaksi->{"uang_masuk$i"} ?? 0,
+ $transaksi->{"uang_keluar$i"} ?? 0,
+ $pendapatan,
+ $beban
+ );
+ }
+ }
+ }
+
+ // Hitung total
+ $total_pendapatan = array_sum(array_column($pendapatan, 'nominal'));
+ $total_beban = abs(array_sum(array_column($beban, 'nominal')));
+ $laba_rugi = $total_pendapatan - $total_beban;
+
+ // Siapkan data untuk Excel
+ $rows = [];
+
+ // Header
+ $rows[] = ['Laporan Laba Rugi'];
+ $rows[] = ['Periode: ' . date('F Y', strtotime($startDate))];
+ $rows[] = []; // Baris kosong
+
+ // Pendapatan
+ $rows[] = ['Pendapatan'];
+ foreach ($pendapatan as $item) {
+ $rows[] = [
+ ucwords($item['kategori']),
+ number_format(abs($item['nominal']), 0, ',', '.')
+ ];
+ }
+ $rows[] = ['Total Pendapatan', number_format(abs($total_pendapatan), 0, ',', '.')];
+ $rows[] = []; // Baris kosong
+
+ // Beban
+ $rows[] = ['Beban'];
+ foreach ($beban as $item) {
+ $rows[] = [
+ ucwords($item['kategori']),
+ number_format(abs($item['nominal']), 0, ',', '.')
+ ];
+ }
+ $rows[] = ['Total Beban', number_format($total_beban, 0, ',', '.')];
+ $rows[] = []; // Baris kosong
+
+ // Laba/Rugi
+ $rows[] = ['Laba/Rugi Bersih', number_format($laba_rugi, 0, ',', '.')];
+
+ $export = new class($rows) implements \Maatwebsite\Excel\Concerns\FromArray {
+ protected $rows;
+ public function __construct($rows) { $this->rows = $rows; }
+ public function array(): array { return $this->rows; }
+ };
+
+ return \Maatwebsite\Excel\Facades\Excel::download($export, 'laporan-laba-rugi-'.date('Y-m-d').'.xlsx');
+ } catch (\Exception $e) {
+ return redirect()->back()->with('error', 'Gagal mengekspor Excel: ' . $e->getMessage());
+ }
+ }
+
+ 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'));
+
+ // Inisialisasi array untuk menyimpan data
+ $pendapatan = [];
+ $beban = [];
+
+ // Ambil semua transaksi dalam periode
+ $transaksis = DB::table('laporan_transaksis')
+ ->whereBetween('Tanggal', [$startDate, $endDate])
+ ->get();
+
+ foreach ($transaksis as $transaksi) {
+ // Proses kategori1
+ if (!empty($transaksi->kategori)) {
+ $this->prosesKategori(
+ $transaksi->kategori,
+ $transaksi->uang_masuk ?? 0,
+ $transaksi->uang_keluar ?? 0,
+ $pendapatan,
+ $beban
+ );
+ }
+
+ // Proses kategori2-5
+ for ($i = 2; $i <= 5; $i++) {
+ $kategori = $transaksi->{"kategori$i"};
+ if (!empty($kategori)) {
+ $this->prosesKategori(
+ $kategori,
+ $transaksi->{"uang_masuk$i"} ?? 0,
+ $transaksi->{"uang_keluar$i"} ?? 0,
+ $pendapatan,
+ $beban
+ );
+ }
+ }
+ }
+
+ // Hitung total
+ $total_pendapatan = array_sum(array_column($pendapatan, 'nominal'));
+ $total_beban = abs(array_sum(array_column($beban, 'nominal')));
+ $laba_rugi = $total_pendapatan - $total_beban;
+
+ $html = '
Laporan Laba Rugi';
+
+ $html .= 'Laporan Laba Rugi
';
+ $html .= 'Periode: ' . date('F Y', strtotime($startDate)) . '
';
+
+ $html .= '';
+
+ // Header
+ $html .= 'Keterangan | Nominal |
';
+
+ // Pendapatan
+ $html .= 'Pendapatan |
';
+ foreach ($pendapatan as $item) {
+ $html .= '';
+ $html .= '' . ucwords($item['kategori']) . ' | ';
+ $html .= '' . number_format(abs($item['nominal']), 0, ',', '.') . ' | ';
+ $html .= '
';
+ }
+ $html .= 'Total Pendapatan | ' . number_format(abs($total_pendapatan), 0, ',', '.') . ' |
';
+
+ // Beban
+ $html .= 'Beban |
';
+ foreach ($beban as $item) {
+ $html .= '';
+ $html .= '' . ucwords($item['kategori']) . ' | ';
+ $html .= '' . number_format(abs($item['nominal']), 0, ',', '.') . ' | ';
+ $html .= '
';
+ }
+ $html .= 'Total Beban | ' . number_format($total_beban, 0, ',', '.') . ' |
';
+
+ // Laba/Rugi
+ $html .= 'Laba/Rugi Bersih | ';
+ if ($laba_rugi < 0) {
+ $html .= '-Rp ' . number_format(abs($laba_rugi), 0, ',', '.');
+ } else {
+ $html .= 'Rp ' . number_format($laba_rugi, 0, ',', '.');
+ }
+ $html .= ' |
';
+
+ $html .= '
';
+
+ $pdf = \Barryvdh\DomPDF\Facade\Pdf::loadHTML($html);
+ return $pdf->download('laporan-laba-rugi-'.date('Y-m-d').'.pdf');
+ } catch (\Exception $e) {
+ return redirect()->back()->with('error', 'Gagal mengekspor PDF: ' . $e->getMessage());
+ }
+ }
}
diff --git a/app/Http/Controllers/LaporanController.php b/app/Http/Controllers/LaporanController.php
index 2a54644..5df338e 100644
--- a/app/Http/Controllers/LaporanController.php
+++ b/app/Http/Controllers/LaporanController.php
@@ -52,54 +52,117 @@ public function filter(Request $request)
return $this->index($request);
}
- public function exportExcel()
+ public function exportExcel(Request $request)
{
try {
- // Buat class export inline
- $export = new class implements FromCollection, WithHeadings, WithMapping {
- public function collection()
- {
- return LaporanModel::orderBy('Tanggal', 'desc')->get();
+ $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();
+
+ $rows = [];
+ $no = 1;
+ $totalDebit = 0;
+ $totalKredit = 0;
+
+ foreach ($laporan as $item) {
+ // Cek apakah semua nilai adalah debit
+ $allDebit = true;
+ $debitValues = [
+ $item->uang_masuk,
+ $item->uang_masuk2,
+ $item->uang_masuk3,
+ $item->uang_masuk4,
+ $item->uang_masuk5
+ ];
+
+ $validDebitValues = array_filter($debitValues, function($value) {
+ return $value !== null && $value > 0;
+ });
+
+ if ($item->uang_keluar > 0 ||
+ ($item->uang_keluar2 ?? 0) > 0 ||
+ ($item->uang_keluar3 ?? 0) > 0 ||
+ ($item->uang_keluar4 ?? 0) > 0 ||
+ ($item->uang_keluar5 ?? 0) > 0) {
+ $allDebit = false;
}
- public function headings(): array
- {
- return [
- 'ID',
- 'Tanggal',
- 'Kode',
- 'Kategori',
- 'Keterangan',
- 'Uang Masuk',
- 'Uang Keluar'
- ];
+ // Proses data untuk setiap baris
+ $rowDebit = 0;
+ $rowKredit = 0;
+
+ if ($allDebit) {
+ $lastDebitValue = end($validDebitValues);
+ $firstDebitValue = reset($validDebitValues);
+
+ if (count($validDebitValues) > 1) {
+ $rowDebit = $firstDebitValue;
+ $rowKredit = $lastDebitValue;
+ } else {
+ $rowDebit = $firstDebitValue;
+ $rowKredit = $firstDebitValue;
+ }
+ } else {
+ $rowDebit = $item->uang_masuk +
+ ($item->uang_masuk2 ?? 0) +
+ ($item->uang_masuk3 ?? 0) +
+ ($item->uang_masuk4 ?? 0) +
+ ($item->uang_masuk5 ?? 0);
+
+ $rowKredit = $item->uang_keluar +
+ ($item->uang_keluar2 ?? 0) +
+ ($item->uang_keluar3 ?? 0) +
+ ($item->uang_keluar4 ?? 0) +
+ ($item->uang_keluar5 ?? 0);
}
- public function map($laporan): array
- {
- // Hitung total uang masuk untuk baris ini
- $totalUangMasuk = $laporan->uang_masuk +
- ($laporan->uang_masuk2 ?? 0) +
- ($laporan->uang_masuk3 ?? 0) +
- ($laporan->uang_masuk4 ?? 0) +
- ($laporan->uang_masuk5 ?? 0);
+ $totalDebit += $rowDebit;
+ $totalKredit += $rowKredit;
- // Hitung total uang keluar untuk baris ini
- $totalUangKeluar = $laporan->uang_keluar +
- ($laporan->uang_keluar2 ?? 0) +
- ($laporan->uang_keluar3 ?? 0) +
- ($laporan->uang_keluar4 ?? 0) +
- ($laporan->uang_keluar5 ?? 0);
+ // Gabungkan semua kode akun
+ $kodeAkun = $item->kode;
+ if (!empty($item->kode2)) $kodeAkun .= "\n" . $item->kode2;
+ if (!empty($item->kode3)) $kodeAkun .= "\n" . $item->kode3;
+ if (!empty($item->kode4)) $kodeAkun .= "\n" . $item->kode4;
+ if (!empty($item->kode5)) $kodeAkun .= "\n" . $item->kode5;
- return [
- $laporan->id,
- $laporan->Tanggal,
- $laporan->kode,
- $laporan->kategori,
- $laporan->keterangan,
- $totalUangMasuk,
- $totalUangKeluar
- ];
+ // Gabungkan semua nama akun
+ $namaAkun = $item->kategori;
+ if (!empty($item->kategori2)) $namaAkun .= "\n" . $item->kategori2;
+ if (!empty($item->kategori3)) $namaAkun .= "\n" . $item->kategori3;
+ if (!empty($item->kategori4)) $namaAkun .= "\n" . $item->kategori4;
+ if (!empty($item->kategori5)) $namaAkun .= "\n" . $item->kategori5;
+
+ $rows[] = [
+ 'No' => $no++,
+ 'Tanggal' => date('d/m/Y', strtotime($item->Tanggal)),
+ '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, ',', '.') : '-'
+ ];
+ }
+
+ // Tambahkan baris total
+ $rows[] = [
+ 'No' => '',
+ 'Tanggal' => '',
+ 'Kode Akun' => '',
+ 'Nama Akun' => '',
+ 'Keterangan' => 'Total',
+ 'Debit' => number_format($totalDebit, 0, ',', '.'),
+ 'Kredit' => number_format($totalKredit, 0, ',', '.')
+ ];
+
+ $export = new class($rows) implements FromCollection, WithHeadings {
+ protected $rows;
+ public function __construct($rows) { $this->rows = $rows; }
+ public function collection() { return collect($this->rows); }
+ public function headings(): array {
+ return ['No', 'Tanggal', 'Kode Akun', 'Nama Akun', 'Keterangan', 'Debit', 'Kredit'];
}
};
@@ -109,132 +172,132 @@ public function map($laporan): array
}
}
- public function exportPDF()
+ public function exportPDF(Request $request)
{
try {
- $laporan = LaporanModel::orderBy('Tanggal', 'desc')->get();
-
- // Hitung total uang masuk
- $totalUangMasuk = LaporanModel::selectRaw('SUM(uang_masuk) +
- COALESCE(SUM(uang_masuk2), 0) +
- COALESCE(SUM(uang_masuk3), 0) +
- COALESCE(SUM(uang_masuk4), 0) +
- COALESCE(SUM(uang_masuk5), 0) as total')
- ->value('total') ?? 0;
+ $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();
- // Hitung total uang keluar
- $totalKredit = LaporanModel::selectRaw('SUM(uang_keluar) +
- COALESCE(SUM(uang_keluar2), 0) +
- COALESCE(SUM(uang_keluar3), 0) +
- COALESCE(SUM(uang_keluar4), 0) +
- COALESCE(SUM(uang_keluar5), 0) as total')
- ->value('total') ?? 0;
+ $rows = '';
+ $no = 1;
+ $totalDebit = 0;
+ $totalKredit = 0;
- $saldo = $totalUangMasuk - $totalKredit;
-
- // Generate PDF
- $html = '
-
-
-
- Laporan Keuangan
-
-
-
- Laporan Keuangan
- Tanggal: '.date('d-m-Y').'
+ foreach ($laporan as $item) {
+ // Cek apakah semua nilai adalah debit
+ $allDebit = true;
+ $debitValues = [
+ $item->uang_masuk,
+ $item->uang_masuk2,
+ $item->uang_masuk3,
+ $item->uang_masuk4,
+ $item->uang_masuk5
+ ];
-
-
-
- No |
- Tanggal |
- Kode |
- Kategori |
- Keterangan |
- Uang Masuk |
- Uang Keluar |
-
-
- ';
+ $validDebitValues = array_filter($debitValues, function($value) {
+ return $value !== null && $value > 0;
+ });
+
+ if ($item->uang_keluar > 0 ||
+ ($item->uang_keluar2 ?? 0) > 0 ||
+ ($item->uang_keluar3 ?? 0) > 0 ||
+ ($item->uang_keluar4 ?? 0) > 0 ||
+ ($item->uang_keluar5 ?? 0) > 0) {
+ $allDebit = false;
+ }
+
+ // Proses data untuk setiap baris
+ $rowDebit = 0;
+ $rowKredit = 0;
+
+ if ($allDebit) {
+ $lastDebitValue = end($validDebitValues);
+ $firstDebitValue = reset($validDebitValues);
- foreach($laporan as $index => $item) {
- // Hitung total uang masuk untuk baris ini
- $rowUangMasuk = $item->uang_masuk +
- ($item->uang_masuk2 ?? 0) +
- ($item->uang_masuk3 ?? 0) +
- ($item->uang_masuk4 ?? 0) +
- ($item->uang_masuk5 ?? 0);
-
- // Hitung total uang keluar untuk baris ini
- $rowUangKeluar = $item->uang_keluar +
- ($item->uang_keluar2 ?? 0) +
- ($item->uang_keluar3 ?? 0) +
- ($item->uang_keluar4 ?? 0) +
- ($item->uang_keluar5 ?? 0);
-
- $html .= '
-
- '.($index + 1).' |
- '.$item->Tanggal.' |
- '.$item->kode.' |
- '.$item->kategori.' |
- '.$item->keterangan.' |
- Rp '.number_format($rowUangMasuk, 0, ',', '.').' |
- Rp '.number_format($rowUangKeluar, 0, ',', '.').' |
-
';
+ if (count($validDebitValues) > 1) {
+ $rowDebit = $firstDebitValue;
+ $rowKredit = $lastDebitValue;
+ } else {
+ $rowDebit = $firstDebitValue;
+ $rowKredit = $firstDebitValue;
}
-
- $html .= '
-
-
-
-
-
Ringkasan
-
-
- Total Uang Masuk |
- Rp '.number_format($totalUangMasuk, 0, ',', '.').' |
-
-
- Total Uang Keluar |
- Rp '.number_format($totalKredit, 0, ',', '.').' |
-
-
- Saldo |
- Rp '.number_format($saldo, 0, ',', '.').' |
-
-
-
-
- ';
-
+ } else {
+ $rowDebit = $item->uang_masuk +
+ ($item->uang_masuk2 ?? 0) +
+ ($item->uang_masuk3 ?? 0) +
+ ($item->uang_masuk4 ?? 0) +
+ ($item->uang_masuk5 ?? 0);
+
+ $rowKredit = $item->uang_keluar +
+ ($item->uang_keluar2 ?? 0) +
+ ($item->uang_keluar3 ?? 0) +
+ ($item->uang_keluar4 ?? 0) +
+ ($item->uang_keluar5 ?? 0);
+ }
+
+ $totalDebit += $rowDebit;
+ $totalKredit += $rowKredit;
+
+ // Gabungkan semua kode akun
+ $kodeAkun = $item->kode;
+ if (!empty($item->kode2)) $kodeAkun .= "
" . $item->kode2;
+ if (!empty($item->kode3)) $kodeAkun .= "
" . $item->kode3;
+ if (!empty($item->kode4)) $kodeAkun .= "
" . $item->kode4;
+ if (!empty($item->kode5)) $kodeAkun .= "
" . $item->kode5;
+
+ // Gabungkan semua nama akun
+ $namaAkun = $item->kategori;
+ if (!empty($item->kategori2)) $namaAkun .= "
" . $item->kategori2;
+ if (!empty($item->kategori3)) $namaAkun .= "
" . $item->kategori3;
+ if (!empty($item->kategori4)) $namaAkun .= "
" . $item->kategori4;
+ if (!empty($item->kategori5)) $namaAkun .= "
" . $item->kategori5;
+
+ $rows .= '';
+ $rows .= ''.$no++.' | ';
+ $rows .= ''.date('d/m/Y', strtotime($item->Tanggal)).' | ';
+ $rows .= ''.$kodeAkun.' | ';
+ $rows .= ''.$namaAkun.' | ';
+ $rows .= ''.$item->keterangan.' '.$item->nama_karyawan.' | ';
+ $rows .= ''.($rowDebit > 0 ? number_format($rowDebit, 0, ',', '.') : '-').' | ';
+ $rows .= ''.($rowKredit > 0 ? number_format($rowKredit, 0, ',', '.') : '-').' | ';
+ $rows .= '
';
+ }
+
+ // Tambahkan baris total
+ $rows .= '';
+ $rows .= 'Total | ';
+ $rows .= ''.number_format($totalDebit, 0, ',', '.').' | ';
+ $rows .= ''.number_format($totalKredit, 0, ',', '.').' | ';
+ $rows .= '
';
+
+ $html = 'Laporan Keuangan';
+ $html .= 'Laporan Keuangan
';
+ $html .= 'Periode: '.date('d/m/Y', strtotime($startDate)).' - '.date('d/m/Y', strtotime($endDate)).'
';
+ $html .= '
+ No |
+ Tanggal |
+ Kode Akun |
+ Nama Akun |
+ Keterangan |
+ Debit |
+ Kredit |
+
';
+ $html .= $rows;
+ $html .= '
';
+
$pdf = PDF::loadHTML($html);
return $pdf->download('laporan-keuangan-'.date('Y-m-d').'.pdf');
} catch (\Exception $e) {
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 3876d7a..4602472 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -62,10 +62,9 @@ public function store(Request $request)
]);
if ($validator->fails()) {
- return response()->json([
- 'success' => false,
- 'message' => $validator->errors()->first()
- ], 422);
+ return redirect()->back()
+ ->with('error', $validator->errors()->first())
+ ->withInput();
}
try {
@@ -76,22 +75,24 @@ public function store(Request $request)
'tipe_pengguna' => $request->tipe_pengguna
]);
- return response()->json([
- 'success' => true,
- 'message' => 'User berhasil ditambahkan'
- ]);
+ return redirect()->route('User.index')
+ ->with('success', 'User berhasil ditambahkan!');
} catch (\Exception $e) {
- return response()->json([
- 'success' => false,
- 'message' => 'Gagal menambahkan user: ' . $e->getMessage()
- ], 500);
+ return redirect()->back()
+ ->with('error', 'Gagal menambahkan user: ' . $e->getMessage())
+ ->withInput();
}
}
public function edit($id)
{
- $user = User::findOrFail($id);
- return view('EditAkun', compact('user'));
+ try {
+ $user = User::findOrFail($id);
+ return view('EditAkun', compact('user'));
+ } catch (\Exception $e) {
+ return redirect()->route('User.index')
+ ->with('error', 'User tidak ditemukan');
+ }
}
public function update(Request $request, $id)
@@ -104,10 +105,9 @@ public function update(Request $request, $id)
]);
if ($validator->fails()) {
- return response()->json([
- 'success' => false,
- 'message' => $validator->errors()->first()
- ], 422);
+ return redirect()->back()
+ ->with('error', $validator->errors()->first())
+ ->withInput();
}
try {
@@ -125,15 +125,12 @@ public function update(Request $request, $id)
$user->update($data);
- return response()->json([
- 'success' => true,
- 'message' => 'User berhasil diperbarui'
- ]);
+ return redirect()->route('User.index')
+ ->with('success', 'Data user berhasil diperbarui!');
} catch (\Exception $e) {
- return response()->json([
- 'success' => false,
- 'message' => 'Gagal memperbarui user: ' . $e->getMessage()
- ], 500);
+ return redirect()->back()
+ ->with('error', 'Gagal memperbarui user: ' . $e->getMessage())
+ ->withInput();
}
}
@@ -145,7 +142,7 @@ public function destroy($id)
return response()->json([
'success' => true,
- 'message' => 'User berhasil dihapus'
+ 'message' => 'User berhasil dihapus!'
]);
} catch (\Exception $e) {
return response()->json([
diff --git a/resources/views/Home.blade.php b/resources/views/Home.blade.php
index 467cdbf..f0af9fc 100644
--- a/resources/views/Home.blade.php
+++ b/resources/views/Home.blade.php
@@ -1,6 +1,10 @@
@extends('Core.Sidebar')
@section('content')
+
+
+
+
@endsection
diff --git a/resources/views/Laporan.blade.php b/resources/views/Laporan.blade.php
index c60cd3e..f8e41ed 100644
--- a/resources/views/Laporan.blade.php
+++ b/resources/views/Laporan.blade.php
@@ -121,7 +121,7 @@
Keterangan |
Debit |
Kredit |
- Aksi |
+ Aksi |
@@ -310,7 +310,7 @@
@endif
-
+ |
@@ -453,6 +453,9 @@
.ml-8 {
margin-left: 8px !important;
}
+ .aksi-col, .aksi-col * {
+ display: none !important;
+ }
}
diff --git a/resources/views/Login.Blade.php b/resources/views/Login.Blade.php
index fddc4b0..18442a5 100644
--- a/resources/views/Login.Blade.php
+++ b/resources/views/Login.Blade.php
@@ -5,6 +5,10 @@
Login Page
+
+
+
+
|