From df6f9c7034295425fb3ea981d5bb06e2529e341e Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Sat, 8 Jun 2019 02:20:46 +0700 Subject: [PATCH] bayar spp done --- app/Http/Controllers/TabunganController.php | 15 +- app/Http/Controllers/TransaksiController.php | 124 +++++++ resources/views/dashboard/index.blade.php | 26 +- resources/views/keuangan/index.blade.php | 2 +- resources/views/shared/navbar.blade.php | 2 +- resources/views/siswa/index.blade.php | 2 +- resources/views/tabungan/index.blade.php | 2 +- resources/views/transaksi/index.blade.php | 321 +++++++++++++++++++ routes/api.php | 4 +- routes/web.php | 3 + 10 files changed, 472 insertions(+), 29 deletions(-) create mode 100644 app/Http/Controllers/TransaksiController.php create mode 100644 resources/views/transaksi/index.blade.php diff --git a/app/Http/Controllers/TabunganController.php b/app/Http/Controllers/TabunganController.php index e80ae57..74c73f2 100644 --- a/app/Http/Controllers/TabunganController.php +++ b/app/Http/Controllers/TabunganController.php @@ -25,14 +25,16 @@ class TabunganController extends Controller //api manabung public function menabung(Request $request, Siswa $siswa) { + $jumlah_bersih = preg_replace("/[,.]/", "", $request->jumlah); DB::beginTransaction(); $tabungan = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first(); if($tabungan != null){ - $menabung = Tabungan::make($request->input()); + $menabung = Tabungan::make($request->except('jumlah')); + $menabung->jumlah = $jumlah_bersih; if($request->tipe == 'in'){ - $menabung->saldo = $request->jumlah + $tabungan->saldo; + $menabung->saldo = $jumlah_bersih + $tabungan->saldo; }else if($request->tipe == 'out'){ - $menabung->saldo = $tabungan->saldo - $request->jumlah; + $menabung->saldo = $tabungan->saldo - $jumlah_bersih; } if($menabung->saldo >=0 ){ $menabung->save(); @@ -41,13 +43,14 @@ class TabunganController extends Controller $pesan = 'Transaksi gagal'; } }else{ - $menabung = Tabungan::make($request->input()); - $menabung->saldo = $request->jumlah; + $menabung = Tabungan::make($request->except('jumlah')); + $menabung->jumlah = $jumlah_bersih; + $menabung->saldo = $jumlah_bersih; $menabung->save(); $pesan = 'Berhasil melakukan transaksi'; } - //tambahkan tabungan ke transaksi + //tambahkan tabungan ke keuangan $keuangan = Keuangan::orderBy('created_at','desc')->first(); if($keuangan != null){ if($menabung->tipe == 'in'){ diff --git a/app/Http/Controllers/TransaksiController.php b/app/Http/Controllers/TransaksiController.php new file mode 100644 index 0000000..c2d3fd3 --- /dev/null +++ b/app/Http/Controllers/TransaksiController.php @@ -0,0 +1,124 @@ +orderBy('created_at','desc')->get(); + $transaksi = Transaksi::orderBy('created_at','desc')->paginate(10); + return view('transaksi.index', [ + 'siswa' => $siswa, + 'transaksi' => $transaksi, + ]); + } + + //pay tagihan + public function store(Request $request,Siswa $siswa) + { + DB::beginTransaction(); + //mulai transaksi, membersihkan request->jumlah dari titik dan koma + $jumlah = preg_replace("/[,.]/", "", $request->jumlah); + $jumlah = $jumlah - $request->diskon; + + //membuat transaksi baru + $transaksi = Transaksi::make([ + 'siswa_id' => $siswa->id, + 'tagihan_id' => $request->tagihan_id, + 'diskon' => $request->diskon, + 'is_lunas' => 1, + 'keterangan' => ($request->via == 'tabungan' ? 'dibayarkan melalui tabungan' : 'dibayarkan secara tunai, '). + ', '.$request->keterangan, + ]); + + //menyimpan transaksi + if($transaksi->save()){ + //tambahkan transaksi ke keuangan + $keuangan = Keuangan::orderBy('created_at','desc')->first(); + if($keuangan != null){ + $total_kas = $keuangan->total_kas + $jumlah; + }else{ + $total_kas = $jumlah; + } + $keuangan = Keuangan::create([ + 'transaksi_id' => $transaksi->id, + 'tipe' => 'in', + 'jumlah' => $jumlah, + 'total_kas' => $total_kas, + 'keterangan' => 'Pembayaran SPP oleh '.$transaksi->siswa->nama.' pada tanggal '.$transaksi->created_at.' dengan catatan : dibayarkan dengan '.$request->via. + ', '.$request->keterangan + ]); + } + + // jika pembayaran dilakukan melalui tabungan + if($request->via == 'tabungan'){ + $tabungan = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first(); + $menabung = Tabungan::create([ + 'siswa_id' => $siswa->id, + 'tipe' => 'out', + 'jumlah' => $jumlah, + 'saldo' => $tabungan->saldo - $jumlah, + 'keperluan' => 'penarikan dilakukan untuk pembayaran spp melalui tabungan', + ]); + + //tambahkan tabungan ke keuangan + $keuangan = Keuangan::orderBy('created_at','desc')->first(); + if($keuangan != null){ + $jumlah = $keuangan->total_kas + $menabung->jumlah; + }else{ + $jumlah = $menabung->jumlah; + } + $keuangan = Keuangan::create([ + 'tabungan_id' => $menabung->id, + 'tipe' => $menabung->tipe, + 'jumlah' => $menabung->jumlah, + 'total_kas' => $jumlah, + 'keterangan' => 'Transaksi tabungan oleh '. $menabung->siswa->nama."(".$menabung->siswa->kelas->nama.")". + 'melakukan pembayaran spp sebesar '. $menabung->jumlah + .' pada '.$menabung->created_at.' dengan total tabungan '.$menabung->saldo + ]); + } + + if($keuangan){ + DB::commit(); + return response()->json(['msg' => 'transaksi berhasil dilakukan']); + }else{ + DB::rollBack(); + return redirect()->route('spp.index')->with([ + 'type' => 'danger', + 'msg' => 'terjadi kesalahan' + ]); + } + + } + + //get list tagihan of siswa + public function tagihan(Siswa $siswa) + { + //wajib semua + $tagihan_wajib = Tagihan::where('wajib_semua','1')->get()->toArray(); + + //kelas only + $tagihan_kelas = Tagihan::where('kelas_id', $siswa->kelas->id)->get()->toArray(); + + //student only + $tagihan_siswa = []; + $tagihan_rolesiswa = $siswa->role; + foreach($tagihan_rolesiswa as $tag_siswa){ + $tagihan_siswa[] = $tag_siswa->tagihan->toArray(); + } + + $tagihan = array_merge($tagihan_wajib, $tagihan_kelas, $tagihan_siswa); + + return response()->json($tagihan); + } +} diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index bd62f3e..0899207 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -21,16 +21,8 @@
-
IDR {{ format_idr($total_uang_tabungan) }}
-
Total Uang Tabungan
-
-
-
-
-
-
-
IDR {{ format_idr($total_uang_spp) }}
-
Total Uang SPP
+
IDR {{ format_idr($total_uang_masuk) }}
+
Total Uang Masuk
@@ -45,18 +37,16 @@
-
IDR {{ format_idr($total_uang_masuk) }}
-
Total Uang Masuk
+
IDR {{ format_idr($total_uang_spp) }}
+
Total Uang SPP
-
+
-
-

Dashboard

-
-
-
Dashboard
+
+
IDR {{ format_idr($total_uang_tabungan) }}
+
Total Uang Tabungan
diff --git a/resources/views/keuangan/index.blade.php b/resources/views/keuangan/index.blade.php index 31e08cf..1291093 100644 --- a/resources/views/keuangan/index.blade.php +++ b/resources/views/keuangan/index.blade.php @@ -51,7 +51,7 @@