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 @@