id(); $user = Staff::with('StaffDetail')->find($id); $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); if(!empty($compound)){ $item = [ 'kategori' => $request->get('kategori'), 'jenis' => $request->get('jenis'), 'bilangan' => $request->get('bilangan'), 'harga' => $request->get('harga'), 'lokasi_gudang' => $request->get('lokasi'), 'status' => 'simpan' ]; $itemI = ItemInventory::create($item); $compound->ConfidentialFile->iteminventory()->save($itemI); $l = 0; while($l != $request->get('bilangan')) { $name = ''; do { $name = $this->generateBR('BR', 5); } while (Barcode::where("barcode_id", "=", $name)->first() instanceof Barcode); $this->dispatch(new GenerateBarcode($request->kpd, $name, $itemI)); $l++; } $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Ada penambahan item inventori dari 'dashboard'", 'huraian' => "Item inventori telah ditambah oleh ".$user->StaffDetail->roles_access." _id."/profile'>".$user->StaffDetail->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($history); } return redirect()->back()->with('success_msg', 'Berjaya! Rekod item inventori berjaya ditambah'); }else{ return redirect()->back()->with('error_msg', 'Tidak Berjaya! Rekod kertas kompaun tidak ditemui'); } } public function editItem(Request $request){ $id = Auth::guard('sadmin')->id(); $user = Staff::with('StaffDetail')->find($id); $data_barcode_empty = false; $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->_id)->first(); if(!empty($itemI)){ if($request->has('lokasi')){ $itemI->jenis = $request->get('jenis'); $itemI->bilangan = $request->get('bilangan'); $itemI->harga = $request->get('harga'); $itemI->lokasi_gudang = $request->get('lokasi'); $itemI->save(); }else{ $itemI->jenis = $request->get('jenis'); $itemI->bilangan = $request->get('bilangan'); $itemI->harga = $request->get('harga'); $itemI->save(); } if(!empty($itemI->Barcode)){ foreach ($itemI->Barcode as $b) { $b->forceDelete(); } $data_barcode_empty = true; } if($data_barcode_empty == true){ $l = 0; while($l != $request->get('bilangan')) { $name = $this->generateBR('BR', 5); $this->dispatch(new GenerateBarcode($request->kpd, $name, $itemI)); $l++; } } $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Item inventori dikemaskini", 'huraian' => "Item inventori diekmaskini oleh ".$user->StaffDetail->roles_access." _id."/profile'>".$user->StaffDetail->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($history); } return redirect()->back()->with('success_msg', 'Berjaya! Kemaskini Rekod item inventori'); }else{ return redirect()->back()->with('error_msg', 'Tidak Berjaya! Rekod item tidak ditemui'); } } public function requestViewInventoryPdf($kpd) { $compound = Compound::with('ConfidentialFile')->where('kpd', $kpd)->first(); $file = ConfidentialFile::with(['ItemInventory' => function($q){ $q->with('Attachment','Barcode')->orderBy('created_at','DESC'); }])->where('no_siri',$compound->ConfidentialFile->no_siri)->first(); $now = Carbon::now()->format('d/m/Y h:i:s A'); $site = SiteSetting::first(); $pdf = PDF::loadView('pdf.inventory', compact('compound','file','now','site')); $pdf->setPaper('A4', 'potrait'); return $pdf->stream(); } }