218 lines
8.2 KiB
PHP
218 lines
8.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Models\DbhPendapatanRealisasi;
|
|
use App\Models\TempRealisasiBelanja;
|
|
use App\Imports\RealisasiBelanjaImport;
|
|
|
|
class RealisasiBelanjaController extends Controller
|
|
{
|
|
public function __construct(){
|
|
$this->siteTitle = "Realisasi Belanja";
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return view('realisasi_belanja.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_belanja.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
try{
|
|
$date = date("Ymd");
|
|
DB::beginTransaction();
|
|
|
|
$req = $request->all();
|
|
$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_sp2d_bun"] = $req["txt_simtrad4_sp2d_bun"];
|
|
$data["created_by"] = Auth::user()->id;
|
|
//var_dump($data); exit;
|
|
DbhPendapatanRealisasi::create($data);
|
|
DB::commit();
|
|
|
|
return redirect()->route('realisasi-pendapatan.index')
|
|
->with('success','Realisasi Pendapatan berhasil dibuat.');
|
|
}catch(\Exception $e){
|
|
|
|
DB::rollBack();
|
|
return redirect()->route('realisasi-pendapatan.create')
|
|
->with('error',$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function edit(DbhPendapatanRealisasi $realisasi_belanja)
|
|
{
|
|
$this->setSubtitle("Ubah Data");
|
|
return view('realisasi_belanja.edit',compact('realisasi_belanja'));
|
|
}
|
|
|
|
public function update(Request $request, DbhPendapatanRealisasi $realisasi_belanja)
|
|
{
|
|
try{
|
|
|
|
DB::beginTransaction();
|
|
|
|
$req = $request->all();
|
|
$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_sp2d_bun"] = $req["txt_simtrad4_sp2d_bun"];
|
|
$data["updated_by"] = Auth::user()->id;
|
|
$realisasi_belanja->update($data);
|
|
|
|
DB::commit();
|
|
|
|
return redirect()->route('realisasi-pendapatan.index')
|
|
->with('success','Realisasi Pendapatan berhasil diubah.');
|
|
}catch(Throwable $e){
|
|
|
|
DB::rollBack();
|
|
return redirect()->route('tx-salurdana.index')
|
|
->with('error','Realisasi Pendapatan gagal diubah!');
|
|
}
|
|
}
|
|
|
|
public function datatable(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$src = $post["src"];
|
|
$ta = $post["ta"];
|
|
|
|
$dataFilter=0;
|
|
$data = DbhPendapatanRealisasi::orderBy("created_at","ASC");
|
|
if (!empty($src)){
|
|
$data->whereRaw("(LOWER(simtrad4_uraian) LIKE '%".strtolower($src)."%')");
|
|
}
|
|
$dataFilter = $data->count();
|
|
$dataTotal = DbhPendapatanRealisasi::count();
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data"=> $data->skip($offset)->take($limit)->get()
|
|
]);
|
|
}
|
|
|
|
public function destroy(DbhPendapatanRealisasi $realisasi_belanja)
|
|
{
|
|
try{
|
|
DB::beginTransaction();
|
|
$realisasi_belanja->delete();
|
|
DB::commit();
|
|
return redirect()->route('realisasi-pendapatan.index')
|
|
->with('success','Data Realisasi Pendapatan berhasil dihapus!');
|
|
|
|
}catch(Throwable $e){
|
|
|
|
DB::rollBack();
|
|
return redirect()->route('realisasi-pendapatan.index')
|
|
->with('error','Data Realisasi Pendapatan gagal dihapus.');
|
|
}
|
|
}
|
|
|
|
public function show(DbhPendapatanRealisasi $realisasi_belanja)
|
|
{
|
|
// if (!Auth::user()->can("Lihat SKPP")){
|
|
// abort(403, 'Youre not allowed to visit this page!');
|
|
// }
|
|
$this->setSubtitle("Detail Data");
|
|
return view('realisasi_belanja.show',compact("realisasi_belanja"));
|
|
}
|
|
|
|
public function upload(Request $request)
|
|
{
|
|
$method = $request->method();
|
|
$this->setSubtitle("Upload Data");
|
|
if ($request->isMethod('post')) {
|
|
$req = $request->all();
|
|
try{
|
|
$this->validate($request, [
|
|
'file' => 'required|mimes:xls,xlsx',
|
|
]);
|
|
|
|
$file = $request->file('file');
|
|
// echo 'File Name: '.$file->getClientOriginalName();
|
|
// echo 'File Extension: '.$file->getClientOriginalExtension();
|
|
// echo 'File Real Path: '.$file->getRealPath();
|
|
// echo 'File Size: '.$file->getSize();
|
|
// echo 'File Mime Type: '.$file->getMimeType();
|
|
$tujuan_upload = 'uploadFiles';
|
|
$file->move($tujuan_upload,$file->getClientOriginalName());
|
|
// var_dump($file->getRealPath()); exit;
|
|
DB::beginTransaction();
|
|
TempRealisasiBelanja::truncate();
|
|
Excel::import(new RealisasiBelanjaImport, $tujuan_upload."/".$file->getClientOriginalName());
|
|
DB::commit();
|
|
return redirect('upload-realisasi-belanja')->with('success','Data Realisasi belanja berhasil diupload.');
|
|
}catch(\Exception $e){
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect('upload-realisasi-belanja')->with('error',$e->getMessage());
|
|
}
|
|
}
|
|
return view('realisasi_belanja.upload');
|
|
}
|
|
|
|
public function uploadDatatable(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$src = isset($post["search"])?$post["search"]["value"]:"";
|
|
|
|
$dataFilter=0;
|
|
$data = TempRealisasiBelanja::orderBy("id","ASC");
|
|
if (!empty($src)){
|
|
$data->whereRaw("(LOWER(jenis_belanja) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(sub_jenis_belanja) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_program) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_skpd) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_kegiatan) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_sub_kegiatan) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_rsk) LIKE '%".strtolower($src)."%'
|
|
OR LOWER(nama_rekening) LIKE '%".strtolower($src)."%')");
|
|
}
|
|
$dataFilter = $data->count();
|
|
$dataTotal = TempRealisasiBelanja::count();
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data"=> $data->skip($offset)->take($limit)->get()
|
|
]);
|
|
}
|
|
}
|