From c94e02fb46860cd64311ea57c87fa464fa6013ad Mon Sep 17 00:00:00 2001 From: Ahmad Safar Date: Sat, 27 Mar 2021 16:38:01 +0800 Subject: [PATCH] Review code --- app/Http/Controllers/LaporanController.php | 15 ++---- .../Controllers/ManagePemasukanController.php | 51 ++++++++++--------- .../ManagePengeluaranController.php | 24 ++++----- app/Http/Controllers/PemasukanController.php | 24 ++++----- app/ManagePemasukan.php | 12 +++++ app/ManagePengeluaran.php | 12 +++++ app/Pemasukan.php | 12 +++++ 7 files changed, 89 insertions(+), 61 deletions(-) create mode 100644 app/ManagePemasukan.php create mode 100644 app/ManagePengeluaran.php create mode 100644 app/Pemasukan.php diff --git a/app/Http/Controllers/LaporanController.php b/app/Http/Controllers/LaporanController.php index e39c653..9f9cd89 100644 --- a/app/Http/Controllers/LaporanController.php +++ b/app/Http/Controllers/LaporanController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\ManagePengeluaran; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -9,7 +10,7 @@ class LaporanController extends Controller { public function index() { - return view('Laporan.index'); + return view('laporan.index'); } public function cari(Request $request) @@ -30,15 +31,9 @@ public function cari(Request $request) // ->join('pemasukan as s', 'p.sumber_pemasukan', '=', 's.id') // ->whereBetween('tanggal', [$dari, $sampai])->sum('nominal'); + $pengeluaran = ManagePengeluaran::whereBetween('tanggal', [$dari, $sampai])->get(); + $total_pengeluaran = ManagePengeluaran::whereBetween('tanggal', [$dari, $sampai])->sum('nominal'); - $pengeluaran = DB::table('manage_pengeluaran') - ->whereBetween('tanggal', [$dari, $sampai])->get(); - - $total_pengeluaran = DB::table('manage_pengeluaran') - ->whereBetween('tanggal', [$dari, $sampai])->sum('nominal'); - - return view('Laporan.index', compact('pengeluaran','total_pengeluaran')); + return view('laporan.index', compact('pengeluaran', 'total_pengeluaran')); } - - } diff --git a/app/Http/Controllers/ManagePemasukanController.php b/app/Http/Controllers/ManagePemasukanController.php index bef0c47..e29b90a 100644 --- a/app/Http/Controllers/ManagePemasukanController.php +++ b/app/Http/Controllers/ManagePemasukanController.php @@ -2,23 +2,25 @@ namespace App\Http\Controllers; -use Faker\Provider\Uuid; +use App\ManagePemasukan; +use App\Pemasukan; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Webpatser\Uuid\Uuid; use Yajra\Datatables\Facades\Datatables; class ManagePemasukanController extends Controller { public function index() { - $data = \DB::table('manage_pemasukan as a')->join('pemasukan as b', 'a.sumber_pemasukan', '=', 'b.id')->get(); - return view('Pemasukan.index', compact('data')); + $data = DB::table('manage_pemasukan as a')->join('pemasukan as b', 'a.sumber_pemasukan', '=', 'b.id')->get(); + return view('pemasukan.index', compact('data')); } public function add() { - $sumbers = DB::table('pemasukan')->get(); - return view('Pemasukan.add', compact('sumbers')); + $sumbers = Pemasukan::get(); + return view('pemasukan.add', compact('sumbers')); } public function store(Request $request) @@ -30,8 +32,8 @@ public function store(Request $request) 'keterangan' => 'required', ]); - \DB::table('manage_pemasukan')->insert([ - 'pemasukan_id' => \Uuid::generate(4), + ManagePemasukan::insert([ + 'pemasukan_id' => Uuid::generate(4), 'sumber_pemasukan' => $request->sumber, 'nominal' => $request->nominal, 'tanggal' => date('Y-m-d', strtotime($request->tanggal)), @@ -43,9 +45,9 @@ public function store(Request $request) public function edit($id) { - $sumbers = DB::table('pemasukan')->get(); - $data = DB::table('manage_pemasukan')->where('pemasukan_id', $id)->first(); - return view('Pemasukan.edit', compact('data', 'sumbers')); + $sumbers = Pemasukan::get(); + $data = ManagePemasukan::where('pemasukan_id', $id)->first(); + return view('pemasukan.edit', compact('data', 'sumbers')); } public function update(Request $request, $id) @@ -57,7 +59,7 @@ public function update(Request $request, $id) 'keterangan' => 'required', ]); - \DB::table('manage_pemasukan')->where('pemasukan_id', $id)->update([ + ManagePemasukan::where('pemasukan_id', $id)->update([ 'sumber_pemasukan' => $request->sumber, 'nominal' => $request->nominal, 'tanggal' => date('Y-m-d', strtotime($request->tanggal)), @@ -69,21 +71,22 @@ public function update(Request $request, $id) public function delete($id) { - DB::table('manage_pemasukan')->where('pemasukan_id', $id)->delete(); - return redirect(route('manage.pemasukan')); + ManagePemasukan::where('pemasukan_id', $id)->delete(); + return redirect(route('manage.pemasukan')); } public function yajra(Request $request) { DB::statement(DB::raw('set @rownum=0')); - $pemasukan = \DB::table('manage_pemasukan as a')->join('pemasukan as b', 'a.sumber_pemasukan', '=', 'b.id')->select([ + $pemasukan = DB::table('manage_pemasukan as a')->join('pemasukan as b', 'a.sumber_pemasukan', '=', 'b.id')->select([ DB::raw('@rownum := @rownum + 1 AS rownum'), 'a.pemasukan_id', 'a.sumber_pemasukan', 'b.nama', 'a.nominal', 'a.tanggal', - 'a.keterangan']); + 'a.keterangan' + ]); $datatables = Datatables::of($pemasukan) ->addColumn('action', function ($ps) { $url_edit = route('pemasukan.edit', $ps->pemasukan_id); @@ -91,15 +94,15 @@ public function yajra(Request $request) return ' Edit Hapus'; })->editColumn('nominal', function ($ps) { - $nominal = $ps->nominal; - $nominal = 'Rp ' . number_format($nominal, 0); - $nominal = str_replace(',', '.', $nominal); - return $nominal; - })->editColumn('tanggal', function ($ps) { - $tanggal = $ps->tanggal; - $tanggal = date('d M Y', strtotime($tanggal)); - return $tanggal; - }); + $nominal = $ps->nominal; + $nominal = 'Rp ' . number_format($nominal, 0); + $nominal = str_replace(',', '.', $nominal); + return $nominal; + })->editColumn('tanggal', function ($ps) { + $tanggal = $ps->tanggal; + $tanggal = date('d M Y', strtotime($tanggal)); + return $tanggal; + }); if ($keyword = $request->get('search')['value']) { $datatables->filterColumn('rownum', 'whereRaw', '@rownum + 1 like ?', ["%{$keyword}%"]); diff --git a/app/Http/Controllers/ManagePengeluaranController.php b/app/Http/Controllers/ManagePengeluaranController.php index 208d4db..d0fd52d 100644 --- a/app/Http/Controllers/ManagePengeluaranController.php +++ b/app/Http/Controllers/ManagePengeluaranController.php @@ -2,21 +2,21 @@ namespace App\Http\Controllers; +use App\ManagePengeluaran; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -use Uuid; +use Webpatser\Uuid\Uuid; class ManagePengeluaranController extends Controller { public function index() { - $data = DB::table('manage_pengeluaran')->get(); - return view('Pengeluaran.index', compact('data')); + $data = ManagePengeluaran::all(); + return view('pengeluaran.index', compact('data')); } public function add() { - return view('Pengeluaran.add'); + return view('pengeluaran.add'); } public function store(Request $request) @@ -27,8 +27,8 @@ public function store(Request $request) 'keterangan' => 'required', ]); - DB::table('manage_pengeluaran')->insert([ - 'pengeluaran_id' => \Uuid::generate(4), + ManagePengeluaran::insert([ + 'pengeluaran_id' => Uuid::generate(4), 'nominal' => $request->nominal, 'tanggal' => date('Y-m-d', strtotime($request->tanggal)), 'keterangan' => $request->keterangan, @@ -39,32 +39,30 @@ public function store(Request $request) public function edit($id) { - $data = DB::table('manage_pengeluaran')->where('pengeluaran_id', $id)->first(); - return view('Pengeluaran.edit', compact('data')); + $data = ManagePengeluaran::where('pengeluaran_id', $id)->first(); + return view('pengeluaran.edit', compact('data')); } public function update(Request $request, $id) { - $this->validate($request, [ 'nominal' => 'required', 'tanggal' => 'required', 'keterangan' => 'required', ]); - DB::table('manage_pengeluaran')->where('pengeluaran_id', $id)->update([ + ManagePengeluaran::where('pengeluaran_id', $id)->update([ 'nominal' => $request->nominal, 'tanggal' => date('Y-m-d', strtotime($request->tanggal)), 'keterangan' => $request->keterangan, ]); return redirect(route('pengeluaran.index')); - } public function delete($id) { - DB::table('manage_pengeluaran')->where('pengeluaran_id', $id)->delete(); + ManagePengeluaran::where('pengeluaran_id', $id)->delete(); return redirect(route('pengeluaran.index')); } } diff --git a/app/Http/Controllers/PemasukanController.php b/app/Http/Controllers/PemasukanController.php index 9f80848..87ef5a4 100644 --- a/app/Http/Controllers/PemasukanController.php +++ b/app/Http/Controllers/PemasukanController.php @@ -2,14 +2,15 @@ namespace App\Http\Controllers; +use App\Pemasukan; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; +use Webpatser\Uuid\Uuid; class PemasukanController extends Controller { public function index() { - $data = \DB::table('pemasukan')->get(); + $data = Pemasukan::all(); return view('sumber.index', compact('data')); } @@ -24,11 +25,9 @@ public function store(Request $request) 'nama' => 'required', ]); - $nama = $request->nama; - - \DB::table('pemasukan')->insert([ - 'id' => \Uuid::generate(4), - 'nama' => $nama, + Pemasukan::insert([ + 'id' => Uuid::generate(4), + 'nama' => $request->nama, 'created_at' => date('Y-m-d-H:i:s'), 'updated_at' => date('Y-m-d-H:i:s'), ]); @@ -38,7 +37,7 @@ public function store(Request $request) public function edit($id) { - $data = \DB::table('pemasukan')->where('id', $id)->first(); + $data = Pemasukan::where('id', $id)->first(); return view('sumber.edit', compact('data')); } @@ -48,20 +47,17 @@ public function update(Request $request, $id) 'nama' => 'required', ]); - $nama = $request->nama; - - \DB::table('pemasukan')->where('id', $id)->update([ - 'nama' => $nama, + Pemasukan::where('id', $id)->update([ + 'nama' => $request->nama, 'updated_at' => date('Y-m-d-H:i:s'), ]); return redirect(route('sumber.pemasukan')); - } public function delete($id) { - \DB::table('pemasukan')->where('id', $id)->delete(); + Pemasukan::where('id', $id)->delete(); return redirect(route('sumber.pemasukan')); } } diff --git a/app/ManagePemasukan.php b/app/ManagePemasukan.php new file mode 100644 index 0000000..315d94e --- /dev/null +++ b/app/ManagePemasukan.php @@ -0,0 +1,12 @@ +