id(); $user = Staff::with('StaffDetail')->find($id); $validator = Validator::make($request->all(), [ 'jumlah_kompaun' => 'numeric', ]); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $save = false; $compound = Compound::with('CompoundInvestigation')->where('kpd',$request->kpd)->first(); $file = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first(); $now = Carbon::now(); $gDate = $now->format('F Y'); if(!empty($compound->CompoundInvestigation)){ $compound->CompoundInvestigation->nama = $request->full_name; $compound->CompoundInvestigation->identity = $request->ic; $compound->CompoundInvestigation->nama_syarikat = $request->nama_syarikat; $compound->CompoundInvestigation->no_daftar_syarikat = $request->no_syarikat; $compound->CompoundInvestigation->alamat = $request->alamat; $compound->CompoundInvestigation->save(); if($request->has('jumlah_kompaun')){ $compound->jumlah_kemaskini_kompaun = $request->jumlah_kompaun; $compound->save(); } $save = true; }else{ $compoundData = [ 'nama' => $request->full_name, 'identity' => $request->ic, 'nama_syarikat' => $request->nama_syarikat, 'no_daftar_syarikat' => $request->no_syarikat, 'alamat' => $request->alamat, ]; $compound->compoundinvestigation()->create($compoundData); if($request->has('jumlah_kompaun')){ $compound->jumlah_kemaskini_kompaun = $request->jumlah_kompaun; $compound->save(); } $save = true; } if($save == true){ $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $file->ConfidentialFile->no_siri, 'tajuk' => $user->StaffDetail->roles_access." ".$user->StaffDetail->full_name." mengemaskini data kompaun ".$request->kpd, 'huraian' => "Data kompaun ".$request->kpd." dikemaskini oleh ".$user->StaffDetail->roles_access." _id."/profile'>".$user->StaffDetail->full_name." di bawah kategori modul Kertas Siasatan", ]; $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 kompaun berjaya dikemaskini untuk siasatan'); } } public function addAttachInvestigation(Request $request){ $id = Auth::guard('sadmin')->id(); $user = Staff::with('StaffDetail')->find($id); $validator = Validator::make($request->all(), [ 'attachment' => 'mimes:pdf|max:2048', ]); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $now = Carbon::now(); $gDate = $now->format('F Y'); $file = ConfidentialFile::where('no_siri', $request->nosiri)->first(); if(!empty($file)){ if($request->hasFile('attachment')) { $upload = []; $a = $request->file('attachment'); $upload[] = [ 'name' => 'attachment', 'contents' => fopen( $a->getPathname(), 'r' ), 'filename' => $a->getClientOriginalName() ]; $upload [] = [ 'name' => 'no_siri', 'contents' => $request->nosiri ]; $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ]; $client = new \GuzzleHttp\Client(); $result = $client->request('POST', 'https://files.sipadu.my/api/upload/investigation/file', [ 'multipart' => $upload ]); $response = json_decode($result->getBody()->getContents()); if($response->success == true){ $investigationData = [ 'subjek' => $request->subjek, 'kategori' => $request->kategori, ]; $invest = $file->investigation()->create($investigationData); $attach = new Attachment(); $attach->path = $response->data; $invest->attachment()->save($attach); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $file->no_siri, 'tajuk' => $user->StaffDetail->roles_access." ".$user->StaffDetail->full_name." memuat naik lampiran SSM / JPJ", 'huraian' => "Lampiran SSM/JPJ telah dimuat naik 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); $file->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $file->history()->attach($history); } return redirect()->back()->with('success_msg', 'Berjaya! Rekod lampiran berjaya di simpan'); }else if($response->success == false){ return redirect()->back()->withInput()->with('error_msg', 'Tidak Berjaya! '.$response->message); } }else { return redirect()->back()->withInput()->with('error_msg', 'Tidak Berjaya! Sila pastikan anda muat naik pdf sebelum hantar data'); } }else{ return redirect()->back()->withInput()->with('error_msg', 'Tidak Berjaya! Rekod kompaun '.$request->kpd.' tidak ditemui'); } } public function attachmentView($_id){ $attach = Investigation::with('Attachment')->where('_id',$_id)->first(); if(!empty($attach->Attachment)){ $path = $attach->Attachment->first()->path; return \Response::make(file_get_contents($path), 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename=""' ]); } } }