siteTitle = "DBH Realisasi Pendapatan"; parent::__construct(); } public function index() { return view('realisasi_pendapatan.index') ->with('i', (request()->input('page', 1) - 1) * 10); } public function create() { // if (!Auth::user()->can("Tambah SKPP")){ // abort(403, 'Youre not allowed to visit this page!'); // } $this->setSubtitle("Tambah Data"); return view('realisasi_pendapatan.create'); } protected function dataPendapatan($req= []) { $data["tahun"] = $req["txt_ta"]; $data["id_sps"] = $req["txt_id_sps"]; $txt_rek_sps = explode("|",$req["txt_rek_sps"]); $data["kode_rekening_sps"] = $txt_rek_sps[0]; $data["nama_rekening_sps"] = $txt_rek_sps[1]; $data["simtrad4_uraian"] = $req["txt_simtrad4_uraian"]; $data["simtrad4_kotor"] = replaceMoney($req["txt_simtrad4_kotor"]); $data["simtrad4_potongan"] = replaceMoney($req["txt_simtrad4_potongan"]); $data["simtrad4_bersih"] = replaceMoney($req["txt_simtrad4_bersih"]); $data["simtrad4_tgl_sp2d_bun"] = ConvertIndoDate($req["txt_simtrad4_tgl_sp2d_bun"]); $data["simtrad4_sp2d_bun"] = $req["txt_simtrad4_sp2d_bun"]; return $data; } public function store(Request $request) { try{ $date = date("Ymd"); DB::beginTransaction(); $req = $request->all(); $data = $this->dataPendapatan($req); $data["created_by"] = Auth::user()->id; $PendapatanRealisasi = PendapatanRealisasi::create($data); // SEND NOTIF $userBendahara = User::where("role_name","bendahara")->get()->toArray(); $userBendahara = array_column($userBendahara,"id"); $url = "/realisasi-pendapatan/".$PendapatanRealisasi->id; $message = "Realisasi Pendapatan telah dibuat oleh Bidang Anggaran dengan No. SP2D BUN ".$req["txt_simtrad4_sp2d_bun"]; $this->sendNotif("anggaran", "bendahara", $userBendahara, $message, $url, "Realisasi Pendapatan", $PendapatanRealisasi->id); DB::commit(); return redirect('/realisasi-pendapatan') ->with('success','Realisasi Pendapatan berhasil dibuat.'); }catch(\Exception $e){ DB::rollBack(); return redirect('/realisasi-pendapatan') ->with('error',$e->getMessage()); } } public function edit(PendapatanRealisasi $realisasi_pendapatan) { $this->setSubtitle("Ubah Data"); return view('realisasi_pendapatan.edit',compact('realisasi_pendapatan')); } public function update(Request $request, PendapatanRealisasi $realisasi_pendapatan) { try{ DB::beginTransaction(); $req = $request->all(); $data = $this->dataPendapatan($req); $data["updated_by"] = Auth::user()->id; $realisasi_pendapatan->update($data); DB::commit(); return redirect('/realisasi-pendapatan') ->with('success','Realisasi Pendapatan berhasil diubah.'); }catch(Throwable $e){ DB::rollBack(); return redirect('/realisasi-pendapatan') ->with('error','Realisasi Pendapatan gagal diubah!'); } } public function rinciDBH(Request $request) { $idSPS = $request->idSPS; $select = DB::raw("spsbulan1,spsbulan2,spsbulan3,spsbulan4,spsbulan5,spsbulan6,spsbulan7,spsbulan8,spsbulan9,spsbulan10,spsbulan11,spsbulan12"); $sps = Sps_pendapatan::select($select)->where("ID",$idSPS)->firstOrNew(); return response()->json($sps); } public function datatable(Request $request) { $post = $request->all(); $offset = $post["start"]; $limit = $post["length"]; $src = $post["src"]; $ta = $post["ta"]; $dataFilter=0; $data = PendapatanRealisasi::orderBy("created_at","ASC"); if (!empty($src)){ $data->whereRaw("(LOWER(simtrad4_uraian) LIKE '%".strtolower($src)."%')"); } $dataFilter = $data->count(); $dataTotal = PendapatanRealisasi::count(); return response()->json([ "recordsTotal" => $dataTotal, "recordsFiltered" => $dataFilter, "data"=> $data->skip($offset)->take($limit)->get() ]); } public function destroy(PendapatanRealisasi $realisasi_pendapatan) { try{ DB::beginTransaction(); $realisasi_pendapatan->delete(); DB::commit(); return redirect('/realisasi-pendapatan.index') ->with('success','Data Realisasi Pendapatan berhasil dihapus!'); }catch(Throwable $e){ DB::rollBack(); return redirect('/realisasi-pendapatan.index') ->with('error','Data Realisasi Pendapatan gagal dihapus.'); } } public function show(PendapatanRealisasi $realisasi_pendapatan) { // if (!Auth::user()->can("Lihat SKPP")){ // abort(403, 'Youre not allowed to visit this page!'); // } $this->readNotif($realisasi_pendapatan->id); $this->setSubtitle("Detail Data"); return view('realisasi_pendapatan.show',compact("realisasi_pendapatan")); } public function sts(Request $request, $realisasiId) { // $request->validate([ // 'nama' => 'required', // 'nip' => 'required', // 'nrk' => 'required', // ]); // if (!Auth::user()->can("Tambah SKPP")){ // abort(403, 'Youre not allowed to visit this page!'); // } $req = $request->all(); try{ $date = date("Ymd"); DB::beginTransaction(); $data = PendapatanRealisasi::firstOrNew(array('id' => $realisasiId)); if ($data["simtrad4_bersih"]<>replaceMoney($req["rkud_jumlah"])){ return redirect(url("/realisasi-pendapatan/".$realisasiId))->with('error', "Jumlah STS harus sama dengan Rencana !"); } $data["rkud_tgl"] = $req["rkud_tgl"]; $data["rkud_no_sts"] = $req["rkud_no_sts"]; $data["rkud_kode_akun"] = $req["rkud_kode_akun"]; $data["rkud_nama_akun"] = $req["rkud_nama_akun"]; $data["rkud_jumlah"] = replaceMoney($req["rkud_jumlah"]); $data->save(); DB::commit(); return redirect('/realisasi-pendapatan')->with('success','STS berhasil diinput.'); }catch(\Exception $e){ DB::rollBack(); return redirect(url("/realisasi-pendapatan/".$realisasiId))->with('error',$e->getMessage()); } } }