123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
-
- namespace App\Http\Controllers\Main;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Validator;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\User;
- use App\Model\UserDetail;
- use App\Model\Module\Roles;
- use App\Model\Module\Department;
- use App\Model\Module\DeedLaw;
- use App\Model\Module\Faulty;
- use App\Model\Module\Compound;
- use App\Model\Module\CompoundInvestigation;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Investigation;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- class InvestigationController extends Controller
- {
-
- /**
- * Create compound list interface controller.
- *
- * @return json
- */
-
- public function updateCompoundInvestigation(Request $request){
-
- $id = Auth::guard('sadmin')->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." <a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a> di bawah kategori modul <b>Kertas Siasatan</b>",
- ];
-
- $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', '<strong>Berjaya!</strong> 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." <b><a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a></b>",
- ];
-
- $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', '<strong>Berjaya!</strong> Rekod lampiran berjaya di simpan');
-
- }else if($response->success == false){
- return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> '.$response->message);
- }
-
- }else {
- return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Sila pastikan anda muat naik pdf sebelum hantar data');
- }
-
- }else{
- return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> 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=""'
- ]);
- }
- }
- }
|