123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
-
- namespace App\Http\Controllers\Officer;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use LynX39\LaraPdfMerger\Facades\PdfMerger;
-
- use File;
- use Carbon\Carbon;
- use PDF;
-
- use App\SiteSetting;
- 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\ItemInventory;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- use App\Jobs\UpdateCompoundPrice;
-
- class TaskController extends Controller
- {
- /**
- * Create Task list controller.
- *
- * @return json
- */
- public function requestUpdateTask(Request $request){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $jbkod = $compound->jbkod;
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- if($request->dashboard == "true"){
- $roles = Roles::where('kod', $request->kategori_modul)->first();
- if($compound->modul == $request->kategori_modul){
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah berada di dalam kategori modul '.$roles->name);
- }else{
-
- $reg_id = array();
- if(count($roles->staff_detail_ids) > 0){
- foreach($roles->staff_detail_ids as $s){
- $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){
- $q->where('jbkod', $jbkod);
- }])->where('_id', $s)->first();
- if(!empty($staff->StaffDetail)){
- if($staff->token_firebase != ''){
- $reg_id[] = $staff->token_firebase;
- }
- }
- }
- }
-
- if(count($reg_id) > 0) {
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', url('api/push/notification'), [
- 'verify' => false,
- 'form_params' => [
- 'title' => $roles->name.' '.$compound->kpd,
- 'msg' => 'Kompaun ini telah di pindahkan ke modul '.$roles->name,
- 'register_id' => $reg_id,
- ]
- ]);
- }
-
- $compound->modul = $request->kategori_modul;
- $compound->save();
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Serahan Modul",
- 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah diserahkan ke modul ".$roles->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', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya diserahkan ke kategori modul '.$roles->name);
- }
- }else if($request->dashboard == "false"){
- if($compound->penguatkuasa == $request->penguatkuasa){
- $staff = StaffDetail::where('_id',$request->penguatkuasa)->first();
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah diserahkan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->full_name);
- }else{
-
- $staff = Staff::with('StaffDetail')->where('_id',$request->penguatkuasa)->where(function($q){
- $q->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa');
- })->first();
- $role = Roles::where('kod', $compound->modul)->first();
-
- if(!empty($staff)){
- if($staff->token_firebase != '') {
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', url('api/push/notification'), [
- 'verify' => false,
- 'form_params' => [
- 'title' => $role->name.' '.$compound->kpd,
- 'msg' => 'Kompaun ini berada di ruangan '.$role->name,
- 'register_id[]' => $staff->token_firebase,
- ]
- ]);
- }
-
-
- $compound->penguatkuasa = $request->penguatkuasa;
- $compound->save();
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Menugaskan Penguatkuasa ".$staff->StaffDetail->full_name,
- 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah ditugaskan kepada penguatkuasa <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
- ];
-
- $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 Kemaskini!</strong> Kompaun ini berjaya ditugaskan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->StaffDetail->full_name);
- }else{
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Data penguatkuasa tidak ditemui');
- }
- }
- }
- }
- }
|