Anons79 Mini Shell

Directory : /home/aplikasiposinfo/.trash/app.2/Http/Controllers/
Upload File :
Current File : /home/aplikasiposinfo/.trash/app.2/Http/Controllers/PaguAnggaranController.php

<?php

namespace App\Http\Controllers;

use App\Models\IndukOpd;
use App\Models\SubKegiatan;
use Illuminate\Http\Request;
use App\Models\detailKegiatan;
use App\Models\visiRpjmd;
use Illuminate\Support\Facades\Auth;

class PaguAnggaranController extends Controller
{
    protected $routeName = 'pagu_anggaran';
    protected $viewName = 'pagu_anggaran';
    protected $title = 'Pagu Anggaran';

    public function index()
    {
        //
        $route = $this->routeName;
        $title = $this->title;
        
        
        $tahun = visiRpjmd::get();
        
        $tahunArray = [];
        
        foreach ($tahun as $item) {
            $range = range($item->tahun_awal, $item->tahun_akhir);
            $tahunArray = array_merge($tahunArray, $range);
        }

        // Hilangkan duplikat (karena 2025-2026 muncul dua kali)
        $tahunArray = array_unique($tahunArray);
        sort($tahunArray); // Urutkan lagi
        
        if(isset($_GET['tahun'])) {
            $results = visiRpjmd::where('tahun_awal', '<=', $_GET['tahun'])
                    ->where('tahun_akhir', '>=', $_GET['tahun'])
                    ->get();
        } else {
        $results = visiRpjmd::where('tahun_awal', '<=', date('Y'))
                    ->where('tahun_akhir', '>=', date('Y'))
                    ->get();            
        }
        
        $indukOpd = IndukOpd::pluck('nama', 'id');
        if(Auth::user()->roles->first()->name !== "Admin"){
            $indukOpd = IndukOpd::where('id', Auth::user()->induk_opd_id)->pluck('nama', 'id');
        }
        $induk_opd_arr = $indukOpd;
        return view('pagu_anggaran.index',compact('route','title', 'induk_opd_arr', 'tahunArray'));

    }

    /**
     * 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)
    {
        //
    }

    /**
     * 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)
    {
        //
        $subKegiatan = SubKegiatan::find($id);

        try {
            $subKegiatan->update([
                'pagu_indikatif' => $request->pagu_indikatif,
            ]);

            return redirect()->route($this->routeName.'.index')->with(['success'=>'Berhasil Mengubah Data Pagu Kegiatan: '.$subKegiatan->nama_kegiatan]);
        } catch (\Throwable $th) {
            //throw $th;
            dd($th->getMessage());
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    public function apiEdit($id){

        $detailKegiatan = SubKegiatan::find($id);

        return response()->json([
            'status' => 'success',
            'data' => $detailKegiatan,
        ]);
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]