where('api_token', $request->api_token)->first(); if(!empty($user)){ $no_badan = $user->no_badan; $modul = $request->modul; $compound = Compound::with('ConfidentialFile')->where('penguatkuasa', $no_badan)->where('modul', $modul)->orderBy('updated_at', 'desc')->get(); foreach ($compound as $key => $a) { if(!empty($a->ConfidentialFile)){ array_push($nested_data, array( 'kpd' => $a->kpd, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'no_siri' => $a->ConfidentialFile->no_siri, )); } } return $this->sendResponse($nested_data, 'Berjaya, dapatkan senarai file kulit'); }else{ return $this->sendError('', 'data kakitangan tidak ditemui'); } } /** * Create generate kpd number controller. * * @return value */ public function generateKPD(){ // $allowedNumbers = range(0, 9); // shuffle($allowedNumbers); // $digits = array_rand($allowedNumbers, $range); // $number = ''; // foreach($digits as $d){ // $number .= $allowedNumbers[$d]; // } $count = 0; do { $count = Compound::count(); $count = $count + 1; } while (Compound::where("kpd", "=", 'KP'.$count)->first() instanceof Compound); return $count; } /** * Create compound list controller. * * @return json */ public function storeCompound(Request $request) { $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first(); if(empty($staff)){ return $this->sendError('Invalid', 'Staff not existed'); }else { $faulty = Faulty::where('_id',$request->get('seksyen'))->first(); if(!empty($faulty)){ $countKPD = 0; do { $countKPD = Compound::withTrashed()->count(); $countKPD = $countKPD + 1; } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound); $kpd = 'KP' . $countKPD; // $kpd = ''; // do { // $kpd = 'KP' . $this->generateKPD(); // } while (Compound::where("kpd", "=", $kpd)->first() instanceof Compound); if($kpd != ''){ $no_siri = $this->generateKPD(); $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri)); $data = array(); $dataExist = false; do { $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first(); if(!empty($compound)){ $tawaran = ''; if($compound->jumlah_kemaskini_kompaun != ''){ $tawaran = $compound->jumlah_kemaskini_kompaun; }else{ $tawaran = $compound->jumlah_asal_kompaun; } array_push($data, array('kpd' => $kpd, 'jumlah_kompoun' => $tawaran)); $dataExist = true; } }while(!$dataExist); return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!'); } }else{ return $this->sendError('Gagal', 'Rekod seksyen kesalahan tidak ditemui!'); } } } public function storeCompoundAttachment(Request $request) { $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(empty($staff)){ return $this->sendError('Invalid', 'Staff not existed'); }else { $kpd = $request->get('kpd'); $success_upload = 0; $count_upload = 0; $compound = Compound::with('ConfidentialFile')->where('kpd', $kpd)->orWhere('non', $kpd)->first(); if(!empty($compound)){ if($request->hasFile('file')) { $upload = []; foreach($request->file('file') as $f){ $upload[] = [ 'name' => 'file[]', 'contents' => fopen( $f->getPathname(), 'r' ), 'filename' => $f->getClientOriginalName() ]; } $upload [] = [ 'name' => 'kp', 'contents' => $kpd ]; $upload [] = [ 'name' => 'no_siri', 'contents' => $compound->ConfidentialFile->no_siri ]; $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ]; $client = new \GuzzleHttp\Client(); $result = $client->request('POST', 'https://files.sipadu.my/api/upload/compound/picture', [ 'multipart' => $upload ]); $response = json_decode($result->getBody()->getContents()); if($response->success == true){ foreach ($response->data as $key => $d) { $attach = new Attachment(); $attach->path = $d; $compound->attachment()->save($attach); } return $this->sendResponse('', $response->message); }else if($response->success == false){ return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!'); } }else{ return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!'); } }else{ return $this->sendError('Gagal', 'Kompaun '.$kpd.' tidak ditemui!'); } } } public function storeAcceptanceCompound(Request $request) { $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first(); if(empty($staff)){ return $this->sendError('Invalid', 'Staff not existed'); }else { $kpd = $request->get('kpd'); $success_upload = 0; $count_upload = 0; $compound = Compound::with('ConfidentialFile')->where('kpd', $kpd)->orWhere('non', $kpd)->first(); if(!empty($compound)){ if($request->hasFile('file')) { $upload = []; foreach($request->file('file') as $f){ $upload[] = [ 'name' => 'file[]', 'contents' => fopen( $f->getPathname(), 'r' ), 'filename' => $f->getClientOriginalName() ]; } $upload [] = [ 'name' => 'kp', 'contents' => $kpd ]; $upload [] = [ 'name' => 'no_siri', 'contents' => $compound->ConfidentialFile->no_siri ]; $upload [] = [ 'name' => 'type', 'contents' => 'proxy' ]; $client = new \GuzzleHttp\Client(); $result = $client->request('POST', 'https://files.sipadu.my/api/upload/acceptance/compound', [ 'multipart' => $upload ]); $response = json_decode($result->getBody()->getContents()); if($response->success == true){ foreach ($response->data as $key => $d) { $attach = new Attachment(); $attach->path = $d; $compound->attachment()->save($attach); } return $this->sendResponse('', $response->message); }else if($response->success == false){ return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!'); } }else{ return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!'); } }else{ return $this->sendError('Gagal', 'Kompaun '.$kpd.' tidak ditemui!'); } } } public function compoundList($modul){ $nested_data = array(); if($modul == '06-07'){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) { $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->get(); } // $compound = Compound::with(['ConfidentialFile' => function($q){ // $q->where('status', 'Belum Bayar'); // }])->orderBy('updated_at', 'desc')->get(); $class = ''; if($modul == '03'){ $class = "success/"; }else if($a->modul == '04'){ $class = $cat_modul."/primary/"; }else if($a->modul == '05'){ $class = $cat_modul."/warning/"; }else if($a->modul == '06'){ $class = $cat_modul."/info/"; }else if($a->modul == '07'){ $class = $cat_modul."/danger/"; }else if($a->modul == '08'){ $class = $cat_modul."/inverse/"; } $cat_modul = '-'; if($modul != '-'){ $cat = Roles::where('kod',$modul)->first(); if(!empty($cat)){ if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){ $dump = explode(' ',trim($cat->name)); $cat_modul = $dump[0]; }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){ $dump = explode('- ',trim($cat->name)); $cat_modul = $dump[1]; }else{ $cat_modul = $cat->name; } } } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($compound as $a) { if(!empty($a->ConfidentialFile)){ $n1 = ''; $faulty = ''; $tawaran = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); /*$cat_modul = '-'; if($a->modul != '-'){ $cat = Roles::where('kod',$a->modul)->first(); if(!empty($cat)){ if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){ $dump = explode(' ',trim($cat->name)); $cat_modul = $dump[0]; }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){ $dump = explode('- ',trim($cat->name)); $cat_modul = $dump[1]; }else{ $cat_modul = $cat->name; } } }*/ // if($curr < $expiry_date) { // if($a->modul == '03'){ // $n1 = "Baru/success/"; // }else if($a->modul == '04'){ // $n1 = "Baru/".$cat_modul."/primary/"; // }else if($a->modul == '05'){ // $n1 = "Baru/".$cat_modul."/warning/"; // }else if($a->modul == '06'){ // $n1 = "Baru/".$cat_modul."/info/"; // }else if($a->modul == '07'){ // $n1 = "Baru/".$cat_modul."/danger/"; // }else if($a->modul == '08'){ // $n1 = "Baru/".$cat_modul."/inverse/"; // } // }else{ // if($a->modul == '03'){ // $n1 = ""; // }else if($a->modul == '04'){ // $n1 = $cat_modul."/primary/"; // }else if($a->modul == '05'){ // $n1 = $cat_modul."/warning/"; // }else if($a->modul == '06'){ // $n1 = $cat_modul."/info/"; // }else if($a->modul == '07'){ // $n1 = $cat_modul."/danger/"; // }else if($a->modul == '08'){ // $n1 = $cat_modul."/inverse/"; // } // } if($curr < $expiry_date) { $n1 = "Baru/".$class; }else{ $n1 = $class; } if($a->jumlah_kemaskini_kompaun == ''){ $tawaran = $a->jumlah_asal_kompaun; }else{ $tawaran = $a->jumlah_kemaskini_kompaun; } $no_plate = '-'; if($a->no_plate != '-'){ $no_plate = $a->no_plate; }else{ $no_plate = '-'; } // $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first(); // if(!empty($faulty)){ // $faulty = '['.$faulty->sketr.'] '.$faulty->nama; // } array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $a->jenis, 'no_plat' => $no_plate, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'nama' => $a->nama, 'nric' => $a->identity, 'seksyen' => '['.$a->Faulty->sketr.'] '.$a->Faulty->nama, 'jumlah' => 'RM '.$tawaran, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } return \DataTables::of($nested_data)->make(true); } public function compoundFilterList($jbkod,$akta,$sec,$modul){ $nested_data = array(); if($modul == '06-07'){ if($jbkod == "null" && $akta == "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) { $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->get(); }else if($jbkod != "null" && $akta == "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) { $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get(); } }else if($jbkod != "null" && $akta != "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); }else { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get(); } } else if($jbkod != "null" && $akta != "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } }else if($jbkod != "null" && $akta == "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get(); } } else if($jbkod == "null" && $akta != "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); } else if($jbkod == "null" && $akta != "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } else if($jbkod == "null" && $akta == "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar'); }); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); } }else{ if($jbkod == "null" && $akta == "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->get(); }else if($jbkod != "null" && $akta == "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->get(); }else{ $compound = Compound::with('ConfidentialFile')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get(); } }else if($jbkod != "null" && $akta != "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get(); } } else if($jbkod != "null" && $akta != "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } }else if($jbkod != "null" && $akta == "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get(); } } else if($jbkod == "null" && $akta != "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); } else if($jbkod == "null" && $akta != "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } else if($jbkod == "null" && $akta == "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){ $q->where('modul', $modul)->where('status', 'Belum Bayar'); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); } } $class = ''; if($modul == '03'){ $class = "success/"; }else if($a->modul == '04'){ $class = $cat_modul."/primary/"; }else if($a->modul == '05'){ $class = $cat_modul."/warning/"; }else if($a->modul == '06'){ $class = $cat_modul."/info/"; }else if($a->modul == '07'){ $class = $cat_modul."/danger/"; }else if($a->modul == '08'){ $class = $cat_modul."/inverse/"; } $cat_modul = '-'; if($modul != '-'){ $cat = Roles::where('kod',$modul)->first(); if(!empty($cat)){ if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){ $dump = explode(' ',trim($cat->name)); $cat_modul = $dump[0]; }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){ $dump = explode('- ',trim($cat->name)); $cat_modul = $dump[1]; }else{ $cat_modul = $cat->name; } } } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($compound as $a) { if(!empty($a->ConfidentialFile)){ $n1 = ''; $faulty = ''; $tawaran = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); /*$cat_modul = '-'; if($a->modul != '-'){ $cat = Roles::where('kod',$a->modul)->first(); if(!empty($cat)){ if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){ $dump = explode(' ',trim($cat->name)); $cat_modul = $dump[0]; }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){ $dump = explode('- ',trim($cat->name)); $cat_modul = $dump[1]; }else{ $cat_modul = $cat->name; } } }*/ if($curr < $expiry_date) { $n1 = "Baru/".$class; }else{ $n1 = $class; } if($a->jumlah_kemaskini_kompaun == ''){ $tawaran = $a->jumlah_asal_kompaun; }else{ $tawaran = $a->jumlah_kemaskini_kompaun; } $no_plate = '-'; if($a->no_plate != '-'){ $no_plate = $a->no_plate; }else{ $no_plate = '-'; } // $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first(); // if(!empty($faulty)){ // $faulty = '['.$faulty->sketr.'] '.$faulty->nama; // } if(strpos($jbkod, 'Pegawai') !== false) { $temp = explode("|",$jbkod); $user = StaffDetail::with('Department')->where('_id', $temp[1])->first(); if(!empty($user->Department)){ if(in_array($a->jbkod, (array)$user->department_ids)) { array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $a->jenis, 'no_plat' => $no_plate, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'nama' => $a->nama, 'nric' => $a->identity, 'seksyen' => $faulty, 'jumlah' => 'RM '.$tawaran, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } }else { array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $a->jenis, 'no_plat' => $no_plate, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'nama' => $a->nama, 'nric' => $a->identity, 'seksyen' => '['.$a->Faulty->sketr.'] '.$a->Faulty->nama, 'jumlah' => 'RM '.$tawaran, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } } return \DataTables::of($nested_data)->make(true); } public function compoundCompleteLists(){ $nested_data = array(); $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->get(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($compound as $a) { $n1 = ''; $faulty = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } if(!empty($a->ConfidentialFile)){ $cat_modul = '-'; if($a->modul != '-'){ $cat = Roles::where('kod',$a->modul)->first(); if(!empty($cat)){ $cat_modul = $cat->name; } } $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first(); if(!empty($faulty)){ $faulty = '['.$faulty->sketr.'] '.$faulty->nama; } if($a->jumlah_kemaskini_kompaun == ''){ $tawaran = $a->jumlah_asal_kompaun; }else{ $tawaran = $a->jumlah_kemaskini_kompaun; } if($a->no_plate == '-'){ $jenis = 'Pelbagai'; }else{ $jenis = 'Parkir'; } array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $jenis, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'seksyen' => $faulty, 'jumlah' => 'RM '.$tawaran, 'bayaran' => 'RM '.$a->amount_payment, 'receipt' => $a->receipt, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } return \DataTables::of($nested_data)->make(true); } public function compoundCompleteFilterList($jbkod,$akta,$sec){ $nested_data = array(); if($jbkod == "null" && $akta == "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->get(); }else if($jbkod != "null" && $akta == "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->get(); }else{ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get(); } }else if($jbkod != "null" && $akta != "null" && $sec == "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); }else{ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get(); } } else if($jbkod != "null" && $akta != "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } }else if($jbkod != "null" && $akta == "null" && $sec != "null"){ if(strpos($jbkod, 'Pegawai') !== false) { $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); }else{ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get(); } } else if($jbkod == "null" && $akta != "null" && $sec == "null"){ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->get(); } else if($jbkod == "null" && $akta != "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get(); } else if($jbkod == "null" && $akta == "null" && $sec != "null"){ $compound = Compound::with('ConfidentialFile')->where(function($q) { $q->where('status', 'Berbayar'); })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get(); } $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($compound as $a) { $n1 = ''; $faulty = ''; $tawaran = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } if(!empty($a->ConfidentialFile)){ $cat_modul = '-'; if($a->modul != '-'){ $cat = Roles::where('kod',$a->modul)->first(); if(!empty($cat)){ $cat_modul = $cat->name; } } $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first(); if(!empty($faulty)){ $faulty = '['.$faulty->sketr.'] '.$faulty->nama; } if($a->jumlah_kemaskini_kompaun == ''){ $tawaran = $a->jumlah_asal_kompaun; }else{ $tawaran = $a->jumlah_kemaskini_kompaun; } if($a->no_plate == '-'){ $jenis = 'Pelbagai'; }else{ $jenis = 'Parkir'; } if(strpos($jbkod, 'Pegawai') !== false) { $temp = explode("|",$jbkod); $user = StaffDetail::with('Department')->where('_id', $temp[1])->first(); if(!empty($user->Department)){ if(in_array($a->jbkod, (array)$user->department_ids)) { array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $jenis, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'seksyen' => $faulty, 'jumlah' => 'RM '.$tawaran, 'bayaran' => 'RM '.$a->amount_payment, 'receipt' => $a->receipt, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } }else{ array_push($nested_data, array( 'kpd' => $n1.$a->kpd, 'jenis' => $jenis, 'tarikh' => $a->created_at->format('d/m/Y'), 'masa' => $a->created_at->format('h:i a'), 'seksyen' => $faulty, 'jumlah' => 'RM '.$tawaran, 'bayaran' => 'RM '.$a->amount_payment, 'receipt' => $a->receipt, 'status' => $a->status, 'tindakan' => $a->kpd )); $i++; } } } return \DataTables::of($nested_data)->make(true); } public function viewCompoundToday(Request $request) { $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first(); if(empty($staff)){ return $this->sendError('Invalid', 'Staff not existed'); }else { $data = array(); $timestamp = time(); $start = Carbon::createFromTimestamp($timestamp)->startOfDay(); $end = Carbon::createFromTimestamp($timestamp)->endOfDay(); $compound = Compound::with('ConfidentialFile','Faulty','Department')->where('modul','03')->where('dikeluarkan',$staff->_id)->whereBetween('created_at', [$start, $end])->orderBy('created_at','DESC')->get(); foreach($compound as $c){ if(!empty($c->Faulty) && !empty($c->Department)){ $tawaran = ''; $akta = DeedLaw::where('_id',$c->akta)->first(); $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first(); if($c->jenis != 'Parkir'){ array_push($data, array( 'jenis' => $c->jenis, 'kpd' => $c->kpd, 'nama' => $c->nama, 'identity' => $c->identity, 'alamat' => $c->alamat, 'nama_syarikat' => $c->nama_syarikat, 'no_daftar_syarikat' => $c->no_daftar_syarikat, 'lokasi_dikompaun' => $c->lokasi_kejadian, 'nama_kawasan' => $c->nama_kawasan, 'nama_taman' => $c->nama_taman, 'nama_jalan' => $c->nama_jalan, 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama, 'akta' => '['.$akta->akkod.'] '.$akta->nama, 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama, 'latlong' => $c->latlong, 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_c)), 'butiran_kesalahan'=> $c->butiran_kesalahan, 'jumlah' => $c->jumlah_asal_kompaun, 'no_lesen' => $c->no_akaun_lesen, 'no_cukai_jalan' => $c->no_cukai_jalan, 'tempoh' => $c->tempoh, 'tindakan' => $c->tindakan, 'bilangan_anjing' => $c->bil_haiwan ?? '0', )); }else if($c->jenis == 'Parkir'){ array_push($data, array( "no_plate" => $c->no_plate, "no_cukai_jalan" => $c->no_cukai_jalan, "jenis_kenderaan" => $c->jenis_kenderaan, "model_kenderaan" => $c->model_kenderaan, "warna_kenderaan" => $c->warna_kenderaan, "nama_taman" => $c->nama_taman, "nama_jalan" => $c->nama_jalan, "nama_kawasan" => $c->nama_kawasan, "no_parking" => $c->no_parking, 'jumlah' => $c->jumlah_asal_kompaun, 'akta' => '['.$akta->akkod.'] '.$akta->nama, 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama, 'latlong' => $c->latlong, 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_c)), 'kpd' => $c->kpd, 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama, 'jenis' => $c->jenis, 'keterangan'=> $c->catatan, )); } } } return $this->sendResponse($data, 'Senarai data kompaun'); } } public function viewNoticeToday(Request $request) { $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first(); if(empty($staff)){ return $this->sendError('Invalid', 'Staff not existed'); }else { $data = array(); $start = Carbon::now()->startOfDay()->toDateTimeString(); $end = Carbon::now()->endOfDay()->toDateTimeString(); $compound = Compound::with('ConfidentialFile','FaultyNotis','Department')->where('modul','02') ->where('dikeluarkan_n',$staff->_id)->whereBetween('created_n', [$start, $end])->orderBy('created_n','DESC')->get(); foreach($compound as $c){ if(!empty($c->FaultyNotis) && !empty($c->Department)){ $akta = DeedLaw::where('_id',$c->akta_n)->first(); if($c->jenis_n != 'Parkir'){ array_push($data, array( 'jenis' => $c->jenis_n, 'non' => $c->non, 'nama' => $c->nama, 'identity' => $c->identity, 'alamat' => $c->alamat, 'nama_syarikat' => $c->nama_syarikat, 'no_daftar_syarikat' => $c->no_daftar_syarikat, 'lokasi_dikompaun' => $c->lokasi_kejadian, 'nama_kawasan' => $c->nama_kawasan, 'nama_taman' => $c->nama_taman, 'nama_jalan' => $c->nama_jalan, 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama, 'akta' => '['.$akta->akkod.'] '.$akta->nama, 'seksyen_kesalahan' => '['.$c->FaultyNotis->sketr.'] '.$c->FaultyNotis->nama, 'latlong' => $c->latlong, 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_n)), 'butiran_kesalahan'=> $c->butiran_kesalahan_n, 'no_lesen' => $c->no_akaun_lesen, 'no_cukai_jalan' => $c->no_cukai_jalan, 'tempoh' => $c->tempoh, 'tindakan' => $c->tindakan, 'bilangan_anjing' => $c->bil_haiwan ?? '0', )); }else if($c->jenis_n == 'Parkir'){ array_push($data, array( "no_plate" => $c->no_plate, "no_cukai_jalan" => $c->no_cukai_jalan, "jenis_kenderaan" => $c->jenis_kenderaan, "model_kenderaan" => $c->model_kenderaan, "warna_kenderaan" => $c->warna_kenderaan, "nama_taman" => $c->nama_taman, "nama_jalan" => $c->nama_jalan, "nama_kawasan" => $c->nama_kawasan, "no_parking" => $c->no_parking, 'akta' => '['.$akta->akkod.'] '.$akta->nama, 'seksyen_kesalahan' => '['.$c->FaultyNotis->sketr.'] '.$c->FaultyNotis->nama, 'latlong' => $c->latlong, 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_n)), 'non' => $c->non, 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama, 'amount' => $c->FaultyNotis->amount, 'jenis' => $c->jenis, 'keterangan'=> $c->catatan )); } } } return $this->sendResponse($data, 'Senarai data kompaun'); } } }