function($q){ $q->with('Attachment','Barcode')->orderBy('created_at','DESC'); }])->where('no_siri',$no_siri)->first(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($file->ItemInventory as $i) { $n1 = ''; $reg_time = $i->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $lokasi = '-'; if($i->lokasi_gudang != '-'){ $lokasi = $i->lokasi_gudang; } array_push($nested_data, array( 'tarikh' => $i->created_at->format('d/m/Y'), 'masa' => $i->created_at->format('h:i a'), 'jenis' => $i->jenis, 'bilangan' => $i->bilangan, 'harga' => $i->harga, 'lokasi' => $lokasi, 'status' => $i->status, 'tindakan' => $i->_id )); } return \DataTables::of($nested_data)->make(true); } public function getDetail(Request $request){ $empty_attach = false; $empty_barcode = false; $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first(); if(!empty($itemI)){ $data = [ '_id' => $itemI->_id, 'kategori' => $itemI->kategori, 'jenis' => $itemI->jenis, 'bilangan' => $itemI->bilangan, 'harga' => $itemI->harga, 'lokasi' => $itemI->lokasi_gudang, 'status' => $itemI->status ]; return response()->json(['status' => 'true', 'desc' => $data]); }else{ return response()->json(['status' => 'false', 'desc' => 'Rekod item ( '.$itemI->jenis.' ) tidak ditemui']); } } public function deleteItem(Request $request){ $empty_attach = false; $empty_barcode = false; $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first(); if(!empty($itemI)){ $user = Staff::with('StaffDetail')->where('_id', $request->_id)->first(); $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); if(!empty($itemI->Attachment)){ foreach($itemI->Attachment as $a){ $a->delete(); } $empty_attach = true; }else{ $empty_attach = true; } if(!empty($itemI->Barcode)){ foreach($itemI->Barcode as $b){ $b->delete(); } $empty_barcode = true; }else{ $empty_barcode = true; } if($empty_attach == true && $empty_barcode == true){ $itemI->delete(); $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Pembuangan item inventori", 'huraian' => "Rekod Item inventori telah dibuang 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 response()->json(['status' => 'true', 'desc' => 'Berjaya buang rekod item ( '.$itemI->jenis.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Tidak berjaya buang rekod item ( '.$itemI->jenis.' )']); } }else{ return response()->json(['status' => 'false', 'desc' => 'Rekod item tidak ditemui']); } } /** * Create generate kpd number controller. * * @return value */ public function iventoryListMobile(Request $request){ $nested_data = array(); $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(!empty($staff)){ $file = ConfidentialFile::with(['ItemInventory' => function($q){ $q->with('Attachment','Barcode')->orderBy('created_at','DESC'); }])->where('no_siri',$request->no_siri)->first(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($file->ItemInventory as $i) { $n1 = ''; $reg_time = $i->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $lokasi = '-'; if($i->lokasi_gudang != '-'){ $lokasi = $i->lokasi_gudang; } array_push($nested_data, array( 'tarikh' => $i->created_at->format('d/m/Y'), 'masa' => $i->created_at->format('h:i a'), 'jenis' => $i->jenis, 'bilangan' => $i->bilangan, 'harga' => $i->harga, 'lokasi' => $lokasi, 'status' => $i->status, 'tindakan' => $i->_id )); } return $this->sendResponse($nested_data, 'Berjaya dapatkan senarai inventori'); }else{ return $this->sendError('', 'Tidak ada rekod ditemui'); } } public function addItemMobile(Request $request){ $data = array(); $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(!empty($staff)){ $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); if(!empty($compound)){ $item = [ 'kategori' => 'alih', 'jenis' => $request->get('jenis'), 'bilangan' => $request->get('bilangan'), 'harga' => $request->get('harga'), 'lokasi_gudang' => $request->get('lokasi'), 'status' => 'simpan' ]; $itemI = ItemInventory::create($item); array_push($data, $itemI); $compound->ConfidentialFile->iteminventory()->save($itemI); if($request->has('barcode')) { $temp_barcode = explode(',', $request->barcode); foreach ($temp_barcode as $key => $b) { $this->dispatch(new GenerateBarcode($request->kpd, $b, $itemI)); } } $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 penguatkuasa", 'huraian' => "Item inventori telah ditambah oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->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 $this->sendResponse($data, 'Berjaya simpan item'); }else{ return $this->sendError('', 'Tiada rekod ditemui'); } } else{ return $this->sendError('', 'Kakitangan tidak ditemui'); } } public function addItemPictureMobile(Request $request){ $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(!empty($staff)){ $itemI = ItemInventory::where('_id', $request->_id)->first(); if(!empty($itemI)){ $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); if(!empty($compound)){ $success_upload = 0; $count_upload = 0; if($request->hasFile('file')) { $i = 1; $destinationGambarItem = 'document/'.$compound->ConfidentialFile->no_siri.'/item'; $uploaded = public_path().'/'.$destinationGambarItem; if(!File::isDirectory($destinationGambarItem)){ File::makeDirectory($destinationGambarItem, 0777, true, true); } $allowedfileExtension = ['jpg','jpeg']; $destinationPathPicture = array(); $count_upload = count($request->file('file')); foreach($request->file('file') as $f){ $extension = $f->getClientOriginalExtension(); $check=in_array($extension,$allowedfileExtension); if($check) { $name = 'Item-'.$i++.'.'.$f->getClientOriginalExtension(); $destinationPathPicture[] = '/'.$destinationGambarItem.'/'.$name; $f->move($destinationGambarItem, $name); $attach = new Attachment(); $attach->path = '/'.$destinationGambarItem.'/'.$name; $itemI->attachment()->save($attach); $i++; } } return $this->sendResponse($destinationPathPicture, $success_upload.'/'.$count_upload.' picture compound successfully been uploaded'); }else{ return $this->sendError('', 'Tidak ada fail dimuatnaik'); } }else{ return $this->sendError('', 'Tidak ada rekod ditemui'); } }else{ return $this->sendError('', 'Tidak ada rekod ditemui'); } } else{ return $this->sendError('', 'Tidak ada rekod ditemui'); } } public function deleteItemMobile(Request $request){ $empty_attach = false; $empty_barcode = false; $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(!empty($staff)){ $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first(); $itemI = ItemInventory::with('Attachment','Barcode')->where('_id',$request->id)->first(); if(!empty($itemI)){ if(!empty($itemI->Attachment)){ foreach($itemI->Attachment as $a){ $a->delete(); } $empty_attach = true; }else{ $empty_attach = true; } if(!empty($itemI->Barcode)){ foreach($itemI->Barcode as $b){ $b->delete(); } $empty_barcode = true; }else{ $empty_barcode = true; } if($empty_attach == true && $empty_barcode == true){ $itemI->delete(); $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Pembuangan item inventori", 'huraian' => "Rekod Item inventori telah dibuang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->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 $this->sendResponse('','Buang rekod item ( '.$itemI->jenis.' )'); }else{ return $this->sendError('','Buang rekod item ( '.$itemI->jenis.' )'); } }else{ return $this->sendError('','Rekod item tidak ditemui'); } } } public function getDetailMobile(Request $request){ $data = array(); $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(!empty($staff)){ $barcode = Barcode::where('barcode_id',$request->barcode)->first(); if(!empty($barcode)){ $itemI = ItemInventory::with('Attachment')->where('_id',$barcode->item_inventory_id)->first(); if(!empty($itemI)){ array_push($data, $itemI); return $this->sendResponse($data, 'Rekod item ditemui'); }else{ return $this->sendError('','Rekod item ditemui'); } }else{ return $this->sendError('','Barcode tidak ditemui'); } }else{ return $this->sendError('','Kakitangan tidak ditemui'); } } }