compound = $compound; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){ $dateS = Carbon::createFromFormat('Y-m-d', $start_date); $start = $dateS->copy()->startOfDay(); if($end_date != ''){ $dateE = Carbon::createFromFormat('Y-m-d', $end_date); $end = $dateE->copy()->endOfDay(); }else{ $end = $dateS->copy()->endOfDay(); } if($modul == '06-07'){ $compound = Compound::where(function($q){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07'); }); })->where('status', $status)->where('jenis', $jenis)->whereBetween('created_at', array($start, $end)); }else if($status != 'Berbayar'){ if($status == 'All'){ $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis) ->whereBetween('created_at', array($start, $end)); }else{ $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis) ->whereBetween('created_at', array($start, $end)); } // $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis) // ->whereBetween('created_at', array($start, $end)); }else{ $compound = Compound::where('status', $status)->where('jenis', $jenis) ->whereBetween('created_at', array($start, $end)); } return $compound; } private function searchCompoundAllWithoutDate($jenis,$modul,$status){ if($modul == '06-07'){ $compound = Compound::where(function($q){ $q->where(function($query){ $query->where('modul', '06')->orWhere('modul','07'); }); })->where('status', $status)->where('jenis', $jenis); }else if($status != 'Berbayar'){ if($status == 'All'){ $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis); }else{ $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis); } }else{ $compound = Compound::where('status', $status)->where('jenis', $jenis); } return $compound; } private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){ if(!empty($start_date)){ $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date); }else{ $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status); } if($enforcer == 'All'){ return $compound; }else { $compound = $compound->where('dikeluarkan', $enforcer); return $compound; } } private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date){ $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date); if($faulty == 'All'){ return $compound; }else { $compound = $compound->where('seksyen_kesalahan', $faulty); return $compound; } } public function index(Request $request) { // $per_page = $request->per_page; $kpd = $request->kpd; $modul = $request->modul; $status = $request->status; $jenis = $request->type; $start_date = $request->start_date; $end_date = $request->end_date; $enforcer = $request->enforcer; $faulty = $request->faulty; $plate_no = strtolower($request->plate_no); $company_no = strtolower($request->company_no); $nric = $request->nric; $nested_data = array(); if(!empty($plate_no)) { $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date); $compound = $compound->where('no_plate',$plate_no)->orderBy('created_at','ASC')->get(); }else if(!empty($kpd)){ $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date); $compound = $compound->where('kpd',$kpd)->orderBy('created_at','ASC')->get(); }else if(!empty($company_no)){ $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date); $compound = $compound->where('no_daftar_syarikat',$company_no)->orderBy('created_at','ASC')->get(); }else if(!empty($nric)){ $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date); $compound = $compound->where('identity',$nric)->orderBy('created_at','ASC')->get(); }else{ $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date); $compound = $compound->orderBy('created_at','ASC')->get(); } // return $compound; return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn() ->addColumn('index', function($row) { $curr = Carbon::now(); $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur'); if($curr->diffInDays($dtC) <= 3){ $html = 'New'; }else{ $html = ''; } return $html; })->rawColumns(['index'])->make(true); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(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)){ $data = array(); $countKPD = $this->compound->withTrashed()->count(); do { $countKPD = $countKPD + 1; } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound); $kpd = 'KP' . $countKPD; $no_siri = date('yn').'-'.$countKPD; $fileData = [ 'no_siri' => $no_siri, ]; if($request->jenis != 'Pelbagai'){ $compoundData = [ 'jenis' => 'Parkir', 'kpd' => $kpd, 'nama' => '-', 'identity' => '-', 'alamat' => '-', "no_plate" => strtolower($request->no_plate), "no_cukai_jalan" => $request->noCukaijalan, "jenis_kenderaan" => $request->jenisKenderaan, "model_kenderaan" => $request->modelKenderaan, "warna_kenderaan" => $request->warnakenderaan, "nama_kawasan" => $request->namaKawasan, "nama_taman" => $request->namaTaman, "nama_jalan" => $request->namaJalan, "no_parking" => $request->noParking, "catatan" => $request->catatan, "lokasi_kejadian" => '-', 'latlong' => $request->Latlong, 'jbkod' => $request->jabatan, 'akta' => $faulty->deed_law_id, 'seksyen_kesalahan' => $faulty->_id, 'jumlah_asal_kompaun' => $faulty->amount, 'jumlah_kemaskini_kompaun' => '', 'dikeluarkan' => $staff->_id, "status" => 'Belum Bayar', "amount_payment" => '', "receipt" => '', "modul" => '03', "penguatkuasa" => '', ]; }else{ $compoundData = [ 'jenis' => 'Pelbagai', 'kpd' => $kpd, 'nama' => $request->namaP, 'identity' => $request->noIc, 'nama_syarikat' => $request->namaS, 'no_daftar_syarikat' => strtolower($request->daftarNo), 'alamat' => $request->alamat, "no_plate" => $request->no_plate, "no_cukai_jalan" => $request->no_cukai_jalan, "catatan" => $request->catatan, "lokasi_kejadian" => '-', 'latlong' => $request->Latlong, 'jbkod' => $request->jabatan, 'akta' => $faulty->deed_law_id, 'seksyen_kesalahan' => $faulty->_id, 'jumlah_asal_kompaun' => $faulty->amount, 'jumlah_kemaskini_kompaun' => '', 'dikeluarkan' => $staff->_id, "status" => 'Belum Bayar', "amount_payment" => '', "receipt" => '', "modul" => '03', "penguatkuasa" => '', "no_telefon" => $request->tel, "no_akaun_lesen" => $request->lesen, "maklumat_tambahan" => '-', ]; } $file = ConfidentialFile::create($fileData); $saved = $file->compound()->create($compoundData); if($saved){ // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first(); // if(!empty($compound)){ dispatch(new UpdateCompoundPrice($kpd)); // $tawaran = ''; // if($compound->jumlah_kemaskini_kompaun != ''){ // $tawaran = $compound->jumlah_kemaskini_kompaun; // }else{ // $tawaran = $compound->jumlah_asal_kompaun; // } $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri)); array_push($data, array('kpd' => $kpd)); return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!'); // } } } } } public function storeNotice(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)){ $data = array(); $countKPD = $this->compound->withTrashed()->count(); do { $countKPD = $countKPD + 1; } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound); $kpd = 'KP' . $countKPD; $no_siri = date('yn').'-'.$countKPD; $fileData = [ 'no_siri' => $no_siri, ]; if($request->jenis != 'Pelbagai'){ $compoundData = [ 'jenis' => 'Parkir', 'kpd' => $kpd, 'nama' => '-', 'identity' => '-', 'alamat' => '-', "no_plate" => strtolower($request->no_plate), "no_cukai_jalan" => $request->noCukaijalan, "jenis_kenderaan" => $request->jenisKenderaan, "model_kenderaan" => $request->modelKenderaan, "warna_kenderaan" => $request->warnakenderaan, "nama_kawasan" => $request->namaKawasan, "nama_taman" => $request->namaTaman, "nama_jalan" => $request->namaJalan, "no_parking" => $request->noParking, "catatan" => $request->catatan, "lokasi_kejadian" => '-', 'latlong' => $request->Latlong, 'jbkod' => $request->jabatan, 'akta' => $faulty->deed_law_id, 'seksyen_kesalahan' => $faulty->_id, 'jumlah_asal_kompaun' => $faulty->amount, 'jumlah_kemaskini_kompaun' => '', 'dikeluarkan' => $staff->_id, "status" => 'Belum Bayar', "amount_payment" => '', "receipt" => '', "modul" => '05', "penguatkuasa" => '', ]; }else{ $compoundData = [ 'jenis' => 'Pelbagai', 'kpd' => $kpd, 'nama' => $request->namaP, 'identity' => $request->noIc, 'nama_syarikat' => $request->namaS, 'no_daftar_syarikat' => strtolower($request->daftarNo), 'alamat' => $request->alamat, "no_plate" => $request->no_plate, "no_cukai_jalan" => $request->no_cukai_jalan, "catatan" => $request->catatan, "lokasi_kejadian" => '-', 'latlong' => $request->Latlong, 'jbkod' => $request->jabatan, 'akta' => $faulty->deed_law_id, 'seksyen_kesalahan' => $faulty->_id, 'jumlah_asal_kompaun' => $faulty->amount, 'jumlah_kemaskini_kompaun' => '', 'dikeluarkan' => $staff->_id, "status" => 'Belum Bayar', "amount_payment" => '', "receipt" => '', "modul" => '05', "penguatkuasa" => '', "no_telefon" => $request->tel, "no_akaun_lesen" => $request->lesen, "maklumat_tambahan" => '-', ]; } $file = ConfidentialFile::create($fileData); $saved = $file->compound()->create($compoundData); if($saved){ // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first(); // if(!empty($compound)){ dispatch(new UpdateCompoundPrice($kpd)); // $tawaran = ''; // if($compound->jumlah_kemaskini_kompaun != ''){ // $tawaran = $compound->jumlah_kemaskini_kompaun; // }else{ // $tawaran = $compound->jumlah_asal_kompaun; // } $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri)); array_push($data, array('kpd' => $kpd)); return $this->sendResponse($data, 'Berjaya simpan rekod notis!'); // } } } } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } public function updateStatusPaymentViaDashboard(Request $request) { $compound = $this->compound::with('ConfidentialFile')->find($request->id); $staff = StaffDetail::find($request->current_id); if(!empty($compound) && !empty($staff)){ if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){ if($compound->status != $request->status){ $compound->status = $request->status; $compound->catatan_dari_admin = $request->remark; $compound->amount_payment = $request->amount; $compound->update_by = $request->current_id; $saved = $compound->save(); if($saved){ $gDate = $compound->created_at->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini", 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh ".$staff->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($history); } if($request->status == "Berbayar"){ return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" '); }else{ return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" '); } }else{ $response = [ 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini', ]; return response()->json($response, 200); } }else{ if($request->remark != ''){ $compound->catatan_dari_admin = $request->remark; $compound->update_by = $request->current_id; $compound->save(); $saved = $compound->save(); if($saved){ $gDate = $compound->created_at->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini", 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh ".$staff->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($history); } return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini'); }else{ $response = [ 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini', ]; return response()->json($response, 200); } }else{ $response = [ 'success' => false, 'message' => 'Tiada kemaskini!', ]; return response()->json($response, 200); } } }else{ if($compound->status != 'Berbayar' && $compound->status != $request->status){ $compound->status = $request->status; $compound->catatan_dari_admin = $request->remark; $compound->amount_payment = $request->amount; $compound->update_by = $request->current_id; $saved = $compound->save(); if($saved){ $gDate = $compound->created_at->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini", 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh ".$staff->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($history); } if($request->status == "Berbayar"){ return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" '); }else{ return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" '); } }else{ $response = [ 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini', ]; return response()->json($response, 200); } }else{ if($request->remark != ''){ $compound->catatan_dari_admin = $request->remark; $compound->update_by = $request->current_id; $compound->save(); $saved = $compound->save(); if($saved){ $gDate = $compound->created_at->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini", 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh ".$staff->full_name."", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $historySaved = $compound->ConfidentialFile->history()->attach($history); } return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini'); }else{ $response = [ 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini', ]; return response()->json($response, 200); } }else{ $response = [ 'success' => false, 'message' => 'Tiada kemaskini!', ]; return response()->json($response, 200); } } } }else{ $response = [ 'success' => false, 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui', ]; return response()->json($response, 200); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }