244 lines
9.7 KiB
PHP
244 lines
9.7 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\DbhBelanjaRealisasi;
|
|
use App\Models\TempRealisasiBelanja;
|
|
use App\Models\UnitSatuan;
|
|
use App\Imports\RealisasiBelanjaImport;
|
|
|
|
class RealisasiBelanjaController extends Controller
|
|
{
|
|
public function __construct(){
|
|
$this->siteTitle = "DBH Realisasi Belanja";
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return view('realisasi_belanja.index');
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
}
|
|
|
|
public function edit(DbhBelanjaRealisasi $realisasi_belanja)
|
|
{
|
|
}
|
|
|
|
public function update(Request $request, DbhBelanjaRealisasi $realisasi_belanja)
|
|
{
|
|
}
|
|
|
|
public function submit(Request $request, $id)
|
|
{
|
|
$this->setSubtitle("Detail");
|
|
$DbhBelanjaRealisasi = DbhBelanjaRealisasi::where("id", $id)->firstOrNew();
|
|
return view('realisasi_belanja.submit', compact("DbhBelanjaRealisasi"));
|
|
}
|
|
|
|
public function datatable(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$src = isset($post["search"])?$post["search"]["value"]:"";
|
|
|
|
$dataFilter=0;
|
|
$data = DbhBelanjaRealisasi::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 = DbhBelanjaRealisasi::count();
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data"=> $data->skip($offset)->take($limit)->get()
|
|
]);
|
|
}
|
|
|
|
public function destroy(DbhBelanjaRealisasi $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(DbhBelanjaRealisasi $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 Rencana Belanja");
|
|
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 Rencana belanja berhasil diupload, Silahkan validasi data!');
|
|
}catch(\Exception $e){
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect('upload-realisasi-belanja')->with('error',$e->getMessage());
|
|
}
|
|
}
|
|
$this->siteTitle = "Rencana Belanja";
|
|
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()
|
|
]);
|
|
}
|
|
|
|
public function uploadValidate(Request $request)
|
|
{
|
|
try{
|
|
DB::beginTransaction();
|
|
$datas = TempRealisasiBelanja::orderBy("id","ASC")->get();
|
|
for($i=0;$i<$datas->count();$i++){
|
|
$cekData = DbhBelanjaRealisasi::where([
|
|
"kode_rsk"=>$datas[$i]["kode_rsk"],
|
|
// "kode_rekening"=>$datas[$i]["kode_rekening"]
|
|
])->firstOrNew();
|
|
|
|
if (!$cekData==null){
|
|
$cekData->delete();
|
|
// DbhBelanjaRealisasi::where(["kode_rsk"=>$datas[$i]["kode_rsk"],"kode_rekening"=>$datas[$i]["kode_rekening"]])->delete();
|
|
}
|
|
$input = [
|
|
"tahun_anggaran"=>$datas[$i]["tahun_anggaran"],
|
|
"jenis_belanja"=>$datas[$i]["jenis_belanja"],
|
|
"sub_jenis_belanja"=>$datas[$i]["sub_jenis_belanja"],
|
|
"kode_program"=>$datas[$i]["kode_program"],
|
|
"nama_program"=>$datas[$i]["nama_program"],
|
|
"kode_skpd"=>$datas[$i]["kode_skpd"],
|
|
"nama_skpd"=>$datas[$i]["nama_skpd"],
|
|
"kode_kegiatan"=>$datas[$i]["kode_kegiatan"],
|
|
"nama_kegiatan"=>$datas[$i]["nama_kegiatan"],
|
|
"kode_sub_kegiatan"=>$datas[$i]["kode_sub_kegiatan"],
|
|
"nama_sub_kegiatan"=>$datas[$i]["nama_sub_kegiatan"],
|
|
"kode_rsk"=>$datas[$i]["kode_rsk"],
|
|
"nama_rsk"=>$datas[$i]["nama_rsk"],
|
|
// "kode_rekening"=>$datas[$i]["kode_rekening"],
|
|
// "nama_rekening"=>$datas[$i]["nama_rekening"],
|
|
"jumlah_anggaran"=>$datas[$i]["jumlah_anggaran"],
|
|
"volume_satuan"=>$datas[$i]["volume_satuan"],
|
|
"unit_satuan"=>$datas[$i]["unit_satuan"]
|
|
];
|
|
DbhBelanjaRealisasi::create($input);
|
|
}
|
|
TempRealisasiBelanja::truncate();
|
|
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 inputRealisasi(Request $request, $id)
|
|
{
|
|
$DbhBelanjaRealisasi = DbhBelanjaRealisasi::where("id", $id)->firstOrNew();
|
|
$req = $request->all();
|
|
$redirect = isset($req["redirect_link"])?$req["redirect_link"]:"realisasi-belanja";
|
|
if ($request->isMethod('post')) {
|
|
try{
|
|
DB::beginTransaction();
|
|
$data["volume_satuan_realisasi"] = $req["vol_realisasi"];
|
|
$data["unit_satuan_realisasi"] = $req["unit_realisasi"];
|
|
$data["realisasi_by"] = Auth::user()->id;
|
|
$DbhBelanjaRealisasi->update($data);
|
|
DB::commit();
|
|
|
|
return redirect($redirect)->with('success','Data Realisasi berhasil di input!');
|
|
}catch(\Exception $e){
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect($redirect)->with('error',$e->getMessage());
|
|
}
|
|
}
|
|
|
|
$unitSatuan = UnitSatuan::orderBy("id")->get();
|
|
return view('realisasi_belanja.form_input_realisasi',compact("DbhBelanjaRealisasi", "unitSatuan","redirect"));
|
|
}
|
|
}
|