<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Gate;
use App\Models\User;
use App\Models\Syarikat;
use App\Models\LesenPenjaja;
use App\Models\BilPelbagai;
use App\Models\BilPelbagaiItem;
use App\Models\EpbtBpBil;
use App\Models\EpbtEcasResit;
use App\Models\BorangUlasanIk;
use App\Models\MesyuaratPelesenan;
use Illuminate\View\View;
use Illuminate\Support\Facades\DB;
use App\Models\USerSyarikat;
use App\Models\Dokumen;
use App\Models\LesenPenjajaDokumen;
use App\Models\Kawasan;
use App\Models\Taman;
use App\Models\Jalan;
use App\Models\JenisJualan;
use App\Models\EpbtBandar;
use App\Models\EpbtElsnAkaun;

class PenjajaController extends Controller
{
    //
    public function senarai_pt(Request $request){
        $colors = [
            "#1d7af3", // biru vibrant
            "#f3545d", // merah lembayung terang
            "#fdaf4b", // oren lembut
            "#00c9a7", // turquoise
            "#845ec2", // ungu pastel
            "#ffc75f", // kuning lembut
            "#ff6f91", // pink kemerahan
            "#2c73d2", // biru gelap
            "#0081cf", // biru cyan
        ];

        $txt_bayar = '';

        $senarais = LesenPenjaja::where('status_progress', 'baru')->get();

        $kawasans = Kawasan::all();
        
        $i = 0;
        foreach($kawasans as $kaw){
            $pie_nama[] = $kaw->nama;
            $pie[] = LesenPenjaja::where('kawasan_id', $kaw->id)->where('status_progress', 'baru')->count();
            $pie_kaler[] = $colors[$i];
            $i++;
        }        


        return view('admin.penjaja.senaraibaru', compact('senarais', 'txt_bayar', 'pie_nama', 'pie', 'pie_kaler'));
    }

    //
    public function senarai_pt_proses(Request $request){

        $txt_bayar = '';
        $senarais = LesenPenjaja::where('status_progress', 'menunggu bayaran proses')->get();
        
        foreach($senarais as $senarai){
            
            foreach($senarai->bilpelbagais->where('jenis_bil', 'wang proses') as $bil_p){

                try {
                    DB::connection('second_mysql')->getPdo();

                    if((is_null($bil_p->description))||($bil_p->description == '')){
                        $epbtbil = EpbtBpBil::where('noakaun', $bil_p->no_bil_pelbagai)->first();

                        if($epbtbil){
                            $bil_p->status_mylesen_error = ''; 
                            $bil_p->ref_no = $epbtbil->norujukan; 
                            $bil_p->description = $epbtbil->keterangan; 
                            $bil_p->pay_status = $epbtbil->statusbyr; 
                            $bil_p->jabatan = $epbtbil->dept_code; 
                            $bil_p->ent_opr = $epbtbil->ent_opr; 
                            $bil_p->no_bilpelbagai = $epbtbil->nobil; 
                            $bil_p->save();

                            foreach($epbtbil->bil_items as $epbtbil_item){
                                $bilitem = BilPelbagaiItem::create([
                                    'bil_pelbagai_id' => $bil_p->id,
                                    'itemno' => $epbtbil_item->noitem, 
                                    'itemdesc' => $epbtbil_item->keterangan, 
                                    'itemprice' => $epbtbil_item->amaun, 
                                    'gst_type' => $epbtbil_item->jenis_gst, 
                                    'gst_code' => $epbtbil_item->kod_gst, 
                                    'cr_code' => $epbtbil_item->kodcr, 
                                    'dr_code' => $epbtbil_item->koddr, 
                                    'cost_center' => $epbtbil_item->pusatkos, 
                                    'exp_date' => $epbtbil_item->tamat_tempoh
                                ]);              
                            }  

                        }

                    }

                    $bp_bayar = EpbtEcasResit::whereHas('resitItems', function($query) use ($bil_p){
                                                            $query->where('noakaun', $bil_p->no_bil_pelbagai);
                                                })->select('noresit', 'tarikh','amaun')
                                                ->orderBy('tarikh')
                                                ->first();
                    if(!is_null($bp_bayar)){  //cek no resit daripada epbt..klu ada, kita simpan rekod    
                        $bil_p->dt_bayar = $bp_bayar->tarikh; 
                        $bil_p->no_resit = $bp_bayar->noresit;
                        $bil_p->amaun_bayar = $bp_bayar->amaun;       

                        $bil_p->save();
                        
                        $senarai->status_progress = 'semakan bayaran proses';  
                        $senarai->save();  
                    }  
                } catch (\Exception $e) {
                    return back()->with('error', 'Sambungan ke pangkalan data gagal. Sila cuba sebentar lagi.');
                }

            }
        }

        return view('admin.penjaja.senaraiproses', compact('senarais', 'txt_bayar'));
    }

    //
    public function senarai_pt_bukafail(Request $request){

        $txt_bayar = '';

        $senarais = LesenPenjaja::where('status_progress', 'semakan bayaran proses')->get();

        return view('admin.penjaja.senaraibukafail', compact('senarais', 'txt_bayar'));
    }

    //
    public function senarai_pt_daftarlesen(Request $request){

        $txt_bayar = '';

        $senarais = LesenPenjaja::whereIn('status_progress', ['ulasan pegawai', 'ulasan pengarah', 'sokong dibawa ke mesyuarat'])->whereNull('no_akaun_lesen')->get();

        return view('admin.penjaja.senaraidaftarlesen', compact('senarais', 'txt_bayar'));
    }


    //
    public function senarai_mesyuarat(Request $request){

        $txt_bayar = '';

        $mesyuarat = MesyuaratPelesenan::latest()->first();
        $mesyuarats = MesyuaratPelesenan::withCount('lesen_penjajas')->get();
        $senarais = LesenPenjaja::where('status_progress', 'sokong dibawa ke mesyuarat')->get();

        return view('admin.penjaja.senaraimesyuarat', compact('senarais', 'mesyuarat', 'mesyuarats'));
    }

    //
    public function senarai_bawa_mesyuarat(Request $request, $mesyuarat_id){

        $txt_bayar = '';

        $mesyuarat = MesyuaratPelesenan::find($mesyuarat_id);
        $senarais = LesenPenjaja::where('status_progress', 'sokong dibawa ke mesyuarat')->whereDoesntHave('mesyuarats')->get();

        return view('admin.penjaja.senaraibawamesyuaratbaru', compact('senarais', 'mesyuarat'));
    }

    //
    public function senarai_keputusan_mesyuarat(Request $request){

        $txt_bayar = '';

        $mesyuarats = MesyuaratPelesenan::where('kunci_senarai', '1')->withCount('lesen_penjajas')->get();
        
        return view('admin.penjaja.senaraikeputusanmesyuarat', compact('mesyuarats'));
    }

    //
    public function senarai_keputusan_minit_mesyuarat(Request $request, $mesyuarat_id){

        $txt_bayar = '';

        $mesyuarat = MesyuaratPelesenan::find($mesyuarat_id);
        
        return view('admin.penjaja.senaraikeputusanminitmesyuarat', compact('mesyuarat'));
    }

    //
    public function senarai_all(Request $request){
        $query = LesenPenjaja::with(['user', 'syarikat']);

        // carian nama pemohon atau nama syarikat
        if ($request->filled('katakunci')) {
            $katakunci = $request->katakunci;
            $query->whereHas('user', function($q) use ($katakunci) {
                $q->where('name', 'like', "%$katakunci%");
            })->orWhereHas('syarikat', function($q) use ($katakunci) {
                $q->where('name', 'like', "%$katakunci%");
            });
        }

        // carian tahun permohonan
        if ($request->filled('tahun')) {
            $query->whereYear('tarikh_mohon', $request->tahun);
        }

        // pagination
        $senarais = $query->latest()->paginate(10);

        return view('admin.penjaja.laporandashboard', compact('senarais'));
    }

    public function papar(Request $request, $id){
        $show = 'utama';
        $mohon_id = $id;
        $permohonan = LesenPenjaja::find($id);     
     
        return view('admin.penjaja.papar_permohonan', compact('show','permohonan', 'mohon_id'));
    }

    public function papar_map(Request $request, $id){
        
        $show = 'lokasi';
        $mohon_id = $id;
        $permohonan = LesenPenjaja::find($id);        
     
        return view('admin.penjaja.papar_permohonan', compact('show', 'permohonan', 'mohon_id'));
    }

    public function papar_dokumen(Request $request, $id){
        
        $show = 'dokumen'; 
        
        $mohon_id = $id;
        $permohonan = LesenPenjaja::find($id);      

        $doc_kad_pengenalan = null;
        $doc_gambar = null;
        $doc_lokasi = null;
        $doc_kebenaran = null;
        $doc_kenderaan = null;
        $doc_kenderaan_geran = null;
        $doc_suntikan_ty2 = null;
        $doc_kursus_makanan = null;
        if(!$permohonan->dokumens->isEmpty()){
            $doc_kad_pengenalan = $permohonan->dokumens->firstWhere('nama', 'doc_kad_pengenalan');
            $doc_gambar = $permohonan->dokumens->firstWhere('nama', 'doc_gambar');
            $doc_lokasi = $permohonan->dokumens->firstWhere('nama', 'doc_lokasi');
            $doc_kebenaran = $permohonan->dokumens->firstWhere('nama', 'doc_kebenaran');
            $doc_kenderaan = $permohonan->dokumens->firstWhere('nama', 'doc_kenderaan');
            $doc_kenderaan_geran = $permohonan->dokumens->firstWhere('nama', 'doc_kenderaan_geran');
            $doc_suntikan_ty2 = $permohonan->dokumens->firstWhere('nama', 'doc_suntikan_ty2');
            $doc_kursus_makanan = $permohonan->dokumens->firstWhere('nama', 'doc_kursus_makanan');
        }     
     
        return view('admin.penjaja.papar_permohonan', compact('show', 'permohonan', 'doc_kad_pengenalan','doc_gambar',
            'doc_lokasi','doc_kebenaran','doc_kenderaan','doc_kenderaan_geran',
            'doc_suntikan_ty2', 'doc_kursus_makanan', 'mohon_id'));
    }

    public function papar_wangproses(Request $request, $id){
        $show = 'wang proses';
        
        $mohon_id = $id;
        $permohonan = LesenPenjaja::find($id);  
        $jenis_jualans = JenisJualan::all();   
        $kawasans = Kawasan::all();   

        $tamans = [];
        if($permohonan->kawasan_id){
            $tamans = Taman::where('kawasan_id', $permohonan->kawasan_id)->get();
        }

        $jalans = [];
        if($permohonan->taman_id){
            $jalans = Jalan::where('taman_id', $permohonan->taman_id)->get();
        }

        return view('admin.penjaja.papar_permohonan', compact('show','permohonan', 'mohon_id', 'kawasans', 'tamans', 'jalans','jenis_jualans'));
    }

    public function papar_lesen(Request $request, $id){
        $show = 'lesen';
        
        $mohon_id = $id;
        $permohonan = LesenPenjaja::find($id);     
     
        return view('admin.penjaja.papar_permohonan', compact('show','permohonan', 'mohon_id'));
    }

    public function showDokumen($id, $filename)
    {
        $path = 'dokumens/penjaja/'.$id.'/'.$filename;

        if (!Storage::exists($path)) {
            abort(404);
        }

        return response()->file(storage_path('app/' . $path));
    }

    public function create(Request $request): View
    {
        $lesen_penjaja = new LesenPenjaja();
        $penjaja = new User();

        $doc_kad_pengenalan = null;
        $doc_gambar = null;
        $doc_lokasi = null;
        $doc_kebenaran = null;
        $doc_kenderaan = null;
        $doc_kenderaan_geran = null;
        $doc_suntikan_ty2 = null;
        $doc_kursus_makanan = null;


        return view('admin.penjaja.mohon_baru', [
            'user' => $penjaja,
            'permohonan' => $lesen_penjaja,
            'doc_kad_pengenalan' => $doc_kad_pengenalan,
            'doc_gambar' => $doc_gambar,
            'doc_lokasi' => $doc_lokasi,
            'doc_kebenaran' => $doc_kebenaran,
            'doc_kenderaan' => $doc_kenderaan,
            'doc_kenderaan_geran' => $doc_kenderaan_geran,
            'doc_suntikan_ty2' => $doc_suntikan_ty2,
            'doc_kursus_makanan' => $doc_kursus_makanan,
        ]);
    }

    /**
     * Handle an incoming registration request.
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(Request $request)
    {
  
        $penjaja = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'nokp' => $request->nokp,
            'notelefon' => $request->notelefon,
            'alamat' => $request->alamat,
            'jantina' => $request->jantina,
            'bangsa' => $request->bangsa,
            'password' => Hash::make($request->nokp),
        ]);

        $syarikat = Syarikat::firstOrCreate(['nossm'=>$request->nossm],
        [
            'name' => ltrim(rtrim($request->nama_perniagaan)),
            'jenis_perniagaan' => $request->jenis_perniagaan,
            'nossm' => ltrim(rtrim($request->nossm)),
            'alamat' => ltrim(rtrim($request->alamat_perniagaan)),
            'notelefon' => ltrim(rtrim($request->notelefon_perniagaan)),
            'bil_cawangan' => ltrim(rtrim($request->bil_cawangan)),
        ]);

        $user_syarikat = UserSyarikat::create([
            'user_id' => $penjaja->id,
            'syarikat_id' => $syarikat->id,
            'status' => 'aktif'
        ]);

        $jenis_penjaja = JenisPenjaja::find($request->jenis_penjaja_id);

        if($request->mohon_id != ''){
            $lesen_penjaja = LesenPenjaja::find($request->mohon_id);
            $lesen_penjaja->user_id =  $penjaja->id;
            $lesen_penjaja->syarikat_id =  $syarikat->id;
            $lesen_penjaja->jenis_penjaja_id =  $request->jenis_penjaja;
            $lesen_penjaja->jenis_lain =  '';
            $lesen_penjaja->status_tanah =  $request->status_tanah;
            $lesen_penjaja->status_lain =  '';
            $lesen_penjaja->no_petak =  $request->petak_penjajaan;
            $lesen_penjaja->kawasan_id =  $request->kawasan;
            $lesen_penjaja->taman_id =  $request->taman;
            $lesen_penjaja->jalan_id =  $request->jalan;
            $lesen_penjaja->penempatan_id =  $request->penempatan;
            $lesen_penjaja->makanan =  $request->makanan;
            $lesen_penjaja->minuman =  $request->minuman;
            $lesen_penjaja->lain =  $request->lain;
            $lesen_penjaja->masa_jualan_mula =  $request->masa_jualan_mula;
            $lesen_penjaja->masa_jualan_tamat =  $request->masa_jualan_tamat;
            $lesen_penjaja->jenis_kenderaan =  $request->jenis_kenderaan;
            $lesen_penjaja->no_pendaftaran =  $request->no_pendaftaran;
            $lesen_penjaja->longitude =  $request->longitude;
            $lesen_penjaja->latitude =  $request->latitude;
            $lesen_penjaja->group_laporan  =  $jenis_penjaja->kategori;
            $lesen_penjaja->tarikhmohon =  $request->tarikh_mohon;

            $lesen_penjaja->save();
        }
        else{
            $lesen_penjaja = LesenPenjaja::create([
                'user_id' => $penjaja->id,
                'syarikat_id' => $syarikat->id,
                'jenis_penjaja_id' => $request->jenis_penjaja_id, 
                'jenis_lain' => '', 
                'status_tanah' => $request->status_tanah, 
                'status_lain' => '', 
                'no_petak' => $request->petak_penjajaan, 
                'kawasan_id' => $request->kawasan, 
                'taman_id' => $request->taman, 
                'jalan_id' => $request->jalan, 
                'penempatan_id' => $request->penempatan, 
                'makanan' => $request->makanan, 
                'minuman' => $request->minuman, 
                'lain' => $request->lain, 
                'masa_jualan_mula' => $request->masa_jualan_mula, 
                'masa_jualan_tamat' => $request->masa_jualan_tamat, 
                'jenis_kenderaan' => $request->jenis_kenderaan, 
                'no_pendaftaran' => $request->no_pendaftaran, 
                'longitude' => $request->longitude, 
                'latitude' => $request->latitude, 
                'group_laporan' => $jenis_penjaja->kategori,
                'tarikhmohon' =>  $request->tarikh_mohon
            ]);
        }
        
        $folder = 'dokumens/penjaja/'.$lesen_penjaja->id.'/';
        $nama_doc = Dokumen::where('jenis', 'lesen_penjaja')->get();
        foreach($nama_doc as $doc){
            if ($request->hasFile($doc->nama)) { //ada upload?

                $validated = $request->validate([
                    $doc->nama => 'file|mimes:jpg,png,pdf', // 2MB max
                ]);
                
                // Store the file
                $path = $request->file($doc->nama);
                $extension = $path->extension(); // Determine the file's extension based on the file's MIME type...
                
                $name = $doc->nama.".".$extension;

                $path->storeAs($folder, $name);

                $lesen_penjaja_dokumen = LesenPenjajaDokumen::updateOrCreate(
                    [   
                        'lesen_penjaja_id' => $lesen_penjaja->id,
                        'dokumen_id' => $doc->id,
                    ],
                    [
                        'lesen_penjaja_id' => $lesen_penjaja->id,
                        'dokumen_id' => $doc->id,
                        'path' => $name,
                        'jenis_dokumen' => $extension,
                    ]);

            }
        }

        $bil_p = BilPelbagai::firstOrCreate(
            ['no_akaun_bilpelbagai' => $request->no_bil_pelbagai, 'lesen_penjaja_id' => $lesen_penjaja->id],
            ['no_akaun_bilpelbagai' => $request->no_bil_pelbagai, 'lesen_penjaja_id' => $lesen_penjaja->id, 
                'cara_jana' => 'mylesen', 'jenis_bil'=> 'wang proses', 'status_mylesen'=>'1']
        );

        
        $lesen_penjaja->status_progress = 'menunggu bayaran proses';
        $lesen_penjaja->save();

        try {
            DB::connection('second_mysql')->getPdo();

            if($bil_p->wasRecentlyCreated){
                $epbtbil = EpbtBpBil::where('noakaun', $request->no_bil_pelbagai)->first();

                if($epbtbil){
                    $bil_p->status_mylesen_error = ''; 
                    $bil_p->ref_no = $epbtbil->norujukan; 
                    $bil_p->description = $epbtbil->keterangan; 
                    $bil_p->pay_status = $epbtbil->statusbyr; 
                    $bil_p->jabatan = $epbtbil->dept_code; 
                    $bil_p->ent_opr = $epbtbil->ent_opr; 
                    $bil_p->no_bilpelbagai = $epbtbil->nobil; 
                    $bil_p->save();

                    foreach($epbtbil->bil_items as $epbtbil_item){
                        $bilitem = BilPelbagaiItem::create([
                            'bil_pelbagai_id' => $bil_p->id,
                            'itemno' => $epbtbil_item->noitem, 
                            'itemdesc' => $epbtbil_item->keterangan, 
                            'itemprice' => $epbtbil_item->amaun, 
                            'gst_type' => $epbtbil_item->jenis_gst, 
                            'gst_code' => $epbtbil_item->kod_gst, 
                            'cr_code' => $epbtbil_item->kodcr, 
                            'dr_code' => $epbtbil_item->koddr, 
                            'cost_center' => $epbtbil_item->pusatkos, 
                            'exp_date' => $epbtbil_item->tamat_tempoh
                        ]);                   
                    }

                }

            }

            $bp_bayar = EpbtEcasResit::whereHas('resitItems', function($query) use ($request){
                                                    $query->where('noakaun', $request->no_bil_pelbagai);
                                        })->select('noresit', 'tarikh','amaun')
                                        ->orderBy('tarikh')
                                        ->first();
            if(!is_null($bp_bayar)){  //cek no resit daripada epbt..klu ada, kita simpan rekod    
                $bil_p->dt_bayar = $bp_bayar->tarikh; 
                $bil_p->no_resit = $bp_bayar->noresit;
                $bil_p->amaun_bayar = $bp_bayar->amaun;       

                $bil_p->save();
                
                $lesen_penjaja->status_progress = 'semakan bayaran proses';  
                $lesen_penjaja->save();  
            }    
        } catch (\Exception $e) {
            return back()->with('error', 'Sambungan ke pangkalan data gagal. Sila cuba sebentar lagi.');
        }
        

        $lesen_penjaja->no_fail_lesen = $request->no_fail_lesen;
        $lesen_penjaja->no_akaun_lesen = $request->no_akaun_lesen;
        $lesen_penjaja->kod_lesen = $request->kod_lesen;
        $lesen_penjaja->kodkawasan = $request->kawasan;
        $lesen_penjaja->jenis_jualan_id = $request->jenis_jualan;


        try {
            DB::connection('second_mysql')->getPdo();

            $epbtlsn = EpbtElsnAkaun::where('noakaun', $request->no_akaun_lesen)->where('statusaktif', 'A')->first();
            if(!is_null($epbtlsn)){ 
                $lesen_penjaja->dt_lesen_dikeluarkan = $epbtlsn->ent_date;

                $bil_kpi = $lesen_penjaja->kiraKpi();
            }
            
        } catch (\Exception $e) {
            //return back()->with('error', 'Sambungan ke pangkalan data gagal. Sila cuba sebentar lagi.');
        }

        $lesen_penjaja->status_progress = 'lawatan tapak';
        $lesen_penjaja->save();

        $borang = new BorangUlasanIK;
        $borang->lesen_penjaja_id = $lesen_penjaja->id;
        $borang->dt_rujuk_ppkp = now();
        $borang->save();

       // $request->session()->put('lesen_penjaja_id', $lesen_penjaja->id);
        return redirect(route('admin.papar', ['id' => $lesen_penjaja->id]))->with('success', 'Permohonan telah disimpan.');
    }

    public function edit_permohonan(Request $request, $id){
        $permohonan = LesenPenjaja::find($id);

        $doc_kad_pengenalan = null;
        $doc_gambar = null;
        $doc_lokasi = null;
        $doc_kebenaran = null;
        $doc_kenderaan = null;
        $doc_kenderaan_geran = null;
        $doc_suntikan_ty2 = null;
        $doc_kursus_makanan = null;
        if(!$permohonan->dokumens->isEmpty()){
            $doc_kad_pengenalan = $permohonan->dokumens->firstWhere('nama', 'doc_kad_pengenalan');
            $doc_gambar = $permohonan->dokumens->firstWhere('nama', 'doc_gambar');
            $doc_lokasi = $permohonan->dokumens->firstWhere('nama', 'doc_lokasi');
            $doc_kebenaran = $permohonan->dokumens->firstWhere('nama', 'doc_kebenaran');
            $doc_kenderaan = $permohonan->dokumens->firstWhere('nama', 'doc_kenderaan');
            $doc_kenderaan_geran = $permohonan->dokumens->firstWhere('nama', 'doc_kenderaan_geran');
            $doc_suntikan_ty2 = $permohonan->dokumens->firstWhere('nama', 'doc_suntikan_ty2');
            $doc_kursus_makanan = $permohonan->dokumens->firstWhere('nama', 'doc_kursus_makanan');
        }

        if(!is_null($permohonan)){
            Gate::authorize('keje-pt', $permohonan);

            return view('admin.penjaja.mohon_baru', [
            'permohonan' => $permohonan,
            'doc_kad_pengenalan' => $doc_kad_pengenalan,
            'doc_gambar' => $doc_gambar,
            'doc_lokasi' => $doc_lokasi,
            'doc_kebenaran' => $doc_kebenaran,
            'doc_kenderaan' => $doc_kenderaan,
            'doc_kenderaan_geran' => $doc_kenderaan_geran,
            'doc_suntikan_ty2' => $doc_suntikan_ty2,
            'doc_kursus_makanan' => $doc_kursus_makanan,
            ]);
        }
        else{
            return redirect(route('dashboard', absolute: false))->with('error', 'Permohonan tidak dijumpai');
        }
    }

    public function hapus_permohonan($id){
        $permohonan = LesenPenjaja::find($id);
        Gate::authorize('keje-pt', $permohonan);


        $permohonan->delete();
        

        return redirect(route('dashboard', absolute: false));

    }

    public function hantar_permohonan(Request $request){
        $permohonan = LesenPenjaja::find($request->session()->get('lesen_penjaja_id'));

        if(!is_null($permohonan)){
            Gate::authorize('keje-pt', $permohonan);
        
            $permohonan->status_progress = 'baru';
            $permohonan->save();
            
            return redirect(route('dashboard', absolute: false))->with('success', 'Permohonan berjaya dihantar.');
        }
        else{
            return redirect(route('dashboard', absolute: false))->with('error', 'Permohonan tidak dijumpai');
        }

    }
}
