Anons79 Mini Shell

Directory : /home/aplikasiposinfo/www/demo-jadwal.aplikasipos.info/app/Http/Controllers/
Upload File :
Current File : /home/aplikasiposinfo/www/demo-jadwal.aplikasipos.info/app/Http/Controllers/DashboardController.php

<?php

namespace App\Http\Controllers;

use App\Helpers\Helper;
use App\Helpers\WaHelpers;
use App\Models\Jadwal;
use App\Models\Notifikasi;
use App\Models\Pendaftaran;
use App\Models\Siswa;
use App\Models\TargetCapaian;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{

    public $breadcrumbs;
    public $title = "Home";

    public function __construct(UrlGenerator $urlGenerator)
    {
        $this->breadcrumbs = [
            ['title' => $this->title, 'url' => $urlGenerator->route('dashboard')],
        ];
    }

    public function index()
    {
        $breadcrumbs = $this->breadcrumbs;
        if(Request('tanggal')) { 
            $tanggal = TargetCapaian::with(['jadwal', 'jadwal.kegiatan_harian'])->where('tanggal', Request('tanggal'))->whereHas('jadwal', function ($query) {
                $query->where('user_id', Auth::user()->id);
            })->get();

            return response()->json([
                'data' => $tanggal,
                // 'jadwal' => $jadwal,
            ]);
        }


        if(Request('target')) { 
            // $tanggal = TargetCapaian::with(['jadwal', 'jadwal.kegiatan_harian'])->where('tanggal', Request('tanggal'))->whereHas('jadwal', function ($query) {
            //     $query->where('user_id', Auth::user()->id);
            // })->get();

            $target = TargetCapaian::where('id', Request('target'))->first();

            $status = false;
            $message = "Sudah Tercapai";
            if (date('Y-m-d') == $target->tanggal) {
                if($target->capaian == "0") {
                    $status = true;
                    $message = 'Apakah benar target anda telah tercapai!';
                }
            } else {
                if (strtotime($target->tanggal) < strtotime(date('Y-m-d'))) {
                    $message = 'Tanggal telah terlewat!';
                } else {
                    $message = 'Belum saatnya!';
                }
            }

            return response()->json([
                'target' => $target,
                'status' => $status,
                'message' => $message,
                // 'jadwal' => $jadwal,
            ]);
        }

        if(Request('notifikasi')) {
            $siswa = Siswa::where('user_id', Auth::user()->id)->first();
            if($siswa) {
                date_default_timezone_set('Asia/Makassar');

                $jadwal = Jadwal::find(Request('notifikasi'));

                $pesan = "Halo ".$siswa->nama_siswa.", sekarang tanggal ".date('d-m-Y h:i:s', strtotime(Request('tanggal')))." saatnya untuk ".$jadwal->kegiatan.", berlokasi di ".$jadwal->location;
                WaHelpers::sendWa($siswa->no_hp_siswa, $pesan);

                Helper::notifikasi($pesan, $siswa->user_id, 'Siswa');
                return response()->json([
                    'data' => $pesan,
                    // 'jadwal' => $jadwal,
                ]);
            } else {
                return response()->json([
                    'data' => [],
                ]);
            }

        }
        if(Auth()->user()->can('view dashboard')){

            $diterima = Siswa::where('status','aktif')->count();
            $pending = Siswa::where('status','pending')->orWhere('status','proses')->count();
            $ditolak = Siswa::where('status','ditolak')->count();

            $DiterimaBulanan = Siswa::selectRaw('DATE_FORMAT(created_at, "%M") as month')
                                    ->whereYear('created_at', date('Y'))
                                    ->groupBy('month')
                                    ->orderBy('month')
                                    ->get();

            $Chart = [];

            $Chart['DiterimaBulananAktif'] = Siswa::selectRaw('DATE_FORMAT(created_at, "%M") as month, COUNT(*) as count')
                                    ->where('status', 'aktif')
                                    ->whereYear('created_at', date('Y'))
                                    ->groupBy('month')
                                    ->orderBy('month')
                                    ->get();

            $Chart['DiterimaBulananProses'] = Siswa::selectRaw('DATE_FORMAT(created_at, "%M") as month, COUNT(*) as count')
                                            ->where('status', 'pending')->orWhere('status','proses')
                                            ->whereYear('created_at', date('Y'))
                                            ->groupBy('month')
                                            ->orderBy('month')
                                            ->get();

            $Chart['DiterimaBulananDiTolak'] = Siswa::selectRaw('DATE_FORMAT(created_at, "%M") as month, COUNT(*) as count')
                                            ->where('status', 'ditolak')
                                            ->whereYear('created_at', date('Y'))
                                            ->groupBy('month')
                                            ->orderBy('month')
                                            ->get();

            $PermohonanTerbaru = Siswa::where('status', 'pending')->orWhere('status','proses')->orderBy('created_at', 'DESC')->take(20)->get();

            return view('dashboard', compact('breadcrumbs', 'diterima', 'pending', 'ditolak', 'DiterimaBulanan', 'Chart', 'PermohonanTerbaru'));
        } else {
            if(Request('date')) {
                $tanggal = TargetCapaian::with(['jadwal', 'jadwal.kegiatan_harian'])->where('tanggal', Request('date'))->whereHas('jadwal', function ($query) {
                    $query->where('user_id', Auth::user()->id);
                })->get();
                return view('dashboard', compact('breadcrumbs', 'tanggal'));
            } else {
                return view('dashboard', compact('breadcrumbs'));

            }

        }

    }

    public function uploadBuktiPembayaran(Request $request)
    {
        $request->validate([
            'siswa_id' => 'required',
            'metode_pembayaran' => 'required',
            'tipe_pembayaran' => 'required',
        ]);

        DB::beginTransaction();
        try {

            Auth::user()->siswa->update([
                'status' => 'proses',
            ]);

            $no_pendaftaran = 'RSWR-' . date('YmdHis') . rand(100, 999);

            $pendaftaran = Pendaftaran::create([
                'siswa_id' => $request->siswa_id,
                'no_pendaftaran' => $no_pendaftaran,
                'tanggal_daftar' => date('Y-m-d H:i:s'),
                'metode_pembayaran' => $request->metode_pembayaran,
                'tipe_pembayaran' => $request->tipe_pembayaran,
                // $InformasiPublik->image => 'storage/'.$request->bukti_pembayaran->store('bukti_pembayaran', 'public');
                'bukti_pembayaran' => 'storage/'.$request->bukti_pembayaran->store('bukti_pembayaran', 'public'),
            ]);

            // if ($request->bukti_pembayaran) {
            //     $ekstensi = $request->file('bukti_pembayaran')->getClientOriginalExtension();
            //     $nama_file = $request->file('bukti_pembayaran')->getClientOriginalName();
            //     $nama_file = pathinfo($nama_file, PATHINFO_FILENAME);
            //     $nama_file = $nama_file . rand(1000, 9999) . "." . $ekstensi;

            //     $pendaftaran->addMedia($request->file('bukti_pembayaran'))->usingFileName($nama_file)->toMediaCollection('bukti_pembayaran', 'bukti_pembayaran');
            // }

            DB::commit();

            $siswa = Siswa::find($request->siswa_id);
            Helper::notifikasi('Berhasil melakukan pengisian pendaftaran RESWARA', $siswa->user_id, 'Siswa');
            return redirect()->route('dashboard')->with('success', 'Berhasil melakukan pengisian pendaftaran RESWARA');
        } catch (\Throwable $th) {
            //throw $th;
            DB::rollback();
            Log::error($th);
            return back()->with('error', 'Gagal melakukan pengisian pendaftaran RESWARA : ' . $th->getMessage())->withInput();
        }
    }
}

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