From 3a88fe8317587249e4e1ea8a2e5abe353e8f3003 Mon Sep 17 00:00:00 2001 From: dipta ikromi m Date: Sun, 21 Aug 2022 12:39:35 +0700 Subject: [PATCH] update code 21/08/2022 --- app/Helpers/Helperku.php | 26 +++++++++++ app/Http/Controllers/BarangController.php | 46 ++++++++++++++----- app/Http/Controllers/TransaksiController.php | 2 + resources/views/admin/barang/index.blade.php | 9 ++-- .../views/admin/barang/modal_edit.blade.php | 42 ++++++++++++++++- 5 files changed, 109 insertions(+), 16 deletions(-) diff --git a/app/Helpers/Helperku.php b/app/Helpers/Helperku.php index a0d6e55..8cda07b 100644 --- a/app/Helpers/Helperku.php +++ b/app/Helpers/Helperku.php @@ -54,6 +54,32 @@ public static function get_stok_barang($id_barang,$jenis_barang = '') } + + public function get_join_barang($id_barang,$table = '') + { + + $data = DB::table('tbl_barang') + ->where('id',$id_barang) + ->get(); + + $data_join = DB::table('tbl_barang') + ->join('tbl_satuan','tbl_satuan.id','=','tbl_barang.satuan_id') + ->join('tbl_jenis_barang','tbl_jenis_barang.id','=','tbl_barang.jenis_barang_id') + ->join('tbl_kategori_simak','tbl_jenis_barang.id','=','tbl_barang.kategori_simak_id') + ->where('id',$id_barang) + ->get(); + if($table == 'jenis'){ + + return $data_join[0]->nama_jenis; + }else if($table == 'kategori_simak'){ + + return $data_join[0]->nama_kategori; + }else if($table == 'satuan'){ + return $data_join[0]->nama_satuan; + } + + } + public static function get_image_barang($id_barang){ $data = DB::table('tbl_barang') diff --git a/app/Http/Controllers/BarangController.php b/app/Http/Controllers/BarangController.php index 78f7a97..944b93d 100644 --- a/app/Http/Controllers/BarangController.php +++ b/app/Http/Controllers/BarangController.php @@ -87,20 +87,20 @@ public function updates_barang(Request $request) $id_barang = $request->id; - - if(!$request->validate([ - 'image_barang' => 'required|mimes:png,jpg,jpeg|max:2048', - ])){ - return redirect('barang')->with('error', 'Pastikan File Berekstensi PNG,JPG,JPEG ..'); - } + if(!empty($request->file('image_barang'))){ - $file = $request->file('image_barang'); + if(!$request->validate([ + 'image_barang' => 'mimes:png,jpg,jpeg|max:2048', + ])){ + return redirect('barang')->with('error', 'Pastikan File Berekstensi PNG,JPG,JPEG ..'); + + } + + $file = $request->file('image_barang'); - $fileName = 'barang-'.time().'.'.$file->extension(); - - if($file->move(public_path('upload_image'), $fileName)){ - + $fileName = 'barang-'.time().'.'.$file->extension(); + $file->move(public_path('upload_image'), $fileName); $data_update = array( 'jenis_barang_id'=>$request->jenis_barang, 'satuan_id'=>$request->satuan_barang, @@ -128,8 +128,30 @@ public function updates_barang(Request $request) }else{ + $data_update = array( + 'jenis_barang_id'=>$request->jenis_barang, + 'satuan_id'=>$request->satuan_barang, + 'jumlah_barang'=>$request->jumlah, + 'lokasi'=>$request->lokasi, + 'tanggal_masuk'=>$request->tanggal_masuk, + 'keterangan'=>$request->keterangan, + 'kode_barang'=>$request->kode_barang, + 'kategori_simak_id'=>$request->kategori_simak, + 'harga'=>$request->harga_barang, + 'nup'=>$request->nup, - return redirect('barang')->with('error', 'Data File Gagal di Upload ..'); + ); + + $update = DB::table('tbl_barang')->where('id',$id_barang)->update($data_update); + if($update){ + + return redirect('barang')->with('sukses', 'Data Barang Berhasil di Update ..'); + + }else{ + + return redirect('barang')->with('error', 'Data Barang Gagal di Update ..'); + } + } diff --git a/app/Http/Controllers/TransaksiController.php b/app/Http/Controllers/TransaksiController.php index 20da6db..ea0e597 100644 --- a/app/Http/Controllers/TransaksiController.php +++ b/app/Http/Controllers/TransaksiController.php @@ -7,6 +7,7 @@ use App\Models\SatuanBarang; use App\Models\Pengguna; use App\Models\Transaksi; +use App\Models\KategoriSimak; use Illuminate\Support\Facades\DB; class TransaksiController extends Controller { @@ -41,6 +42,7 @@ public function index() $data['satuan_barang'] = SatuanBarang::all(); $data['jenis_barang'] = jenisBarang::all(); + $data['kategori_simak'] = KategoriSimak::all(); return view('admin.transaksi.index',$data); } diff --git a/resources/views/admin/barang/index.blade.php b/resources/views/admin/barang/index.blade.php index 1eca39a..3be5ef0 100644 --- a/resources/views/admin/barang/index.blade.php +++ b/resources/views/admin/barang/index.blade.php @@ -80,9 +80,9 @@ {{ $i->tanggal_masuk }} - - - + + + @@ -302,6 +302,9 @@ $("[name=keterangan]").val(obj[0].keterangan); $("[name=jumlah]").val(obj[0].jumlah_barang); $("[name=tanggal_masuk]").val(obj[0].tanggal_masuk); + $("[name=kategori_simak]").val(obj[0].kategori_simak_id); + $("[name=satuan_barang]").val(obj[0].satuan_id); + $("[name=jenis_barang]").val(obj[0].jenis_barang_id); } diff --git a/resources/views/admin/barang/modal_edit.blade.php b/resources/views/admin/barang/modal_edit.blade.php index ef2ba68..3616447 100644 --- a/resources/views/admin/barang/modal_edit.blade.php +++ b/resources/views/admin/barang/modal_edit.blade.php @@ -39,6 +39,23 @@ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
@@ -87,6 +104,29 @@ + +
+
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+
@@ -110,7 +150,7 @@
-
+