1111 lines
49 KiB
PHP
1111 lines
49 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\BelanjaRealisasi;
|
|
use App\Models\BelanjaRealisasiDetail;
|
|
use App\Models\BelanjaRealisasiRinci;
|
|
use App\Models\BelanjaRealisasiKontrak;
|
|
use App\Models\BelanjaRealisasiBast;
|
|
use App\Models\BelanjaRealisasiSPD;
|
|
use App\Models\TempRealisasiBelanja;
|
|
use App\Models\VwAkbSpdRealRsk;
|
|
use App\Models\VwJenisBelanja;
|
|
use App\Models\VwDpaRsk;
|
|
use App\Models\Tropd;
|
|
use App\Models\VwBelanjaRealisasi;
|
|
use App\Models\UnitSatuan;
|
|
use App\Models\Sp2d;
|
|
use App\Models\Trbas;
|
|
use App\Models\Sps_pendapatan;
|
|
use App\Models\BelanjaRealisasiRinciDau;
|
|
use App\Imports\RealisasiBelanjaImport;
|
|
use App\Imports\RealisasiBelanjaImportDak;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class RealisasiBelanjaController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->siteTitle = "Belanja";
|
|
parent::__construct();
|
|
$this->setIconTitle("fa fa-share");
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return view('realisasi_belanja.index');
|
|
}
|
|
|
|
public function create(Request $request)
|
|
{
|
|
if (Auth::user()->lock_tambah_data == 1) {
|
|
abort(403, 'Tidak diperbolehkan menambah data oleh admin!');
|
|
}
|
|
$get = $request->all();
|
|
$rskExists = BelanjaRealisasi::where("kode_rsk", $get["rsk"])->count();
|
|
if ($rskExists > 0) {
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('error', 'Data dengan RSK yand dipilih sudah ada!');
|
|
}
|
|
|
|
$VwDpaRsk = VwDpaRsk::where("I_ID", $get["rsk"])->first();
|
|
|
|
$unitSatuan = UnitSatuan::orderBy("id")->get();
|
|
|
|
return view('realisasi_belanja.create', compact("unitSatuan", "VwDpaRsk"));
|
|
}
|
|
|
|
public function createFromRsk()
|
|
{
|
|
return view('realisasi_belanja.create_from_rsk');
|
|
}
|
|
|
|
public function createFromRskDatatable(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$src = isset($post["search"]["value"]) ? strtolower($post["search"]["value"]) : "";
|
|
$skpd = "";
|
|
|
|
$sqlStr = "SELECT * FROM SAMASA.VW_DPA_RSK WHERE C_ANGG_TAHUN=" . getTA();
|
|
|
|
if (getRole() == "skpd") {
|
|
$sqlStr .= " AND C_OPD='" . Auth::user()->nrk . "'";
|
|
} elseif (getRole() == "sbpk") {
|
|
$sqlStr .= " AND C_WIL_SP2DPROSES=" . Auth::user()->wilayah;
|
|
} else {
|
|
if (!empty($skpd)) {
|
|
$sqlStr .= " AND C_OPD='" . $skpd . "'";
|
|
}
|
|
}
|
|
|
|
$filter = "";
|
|
if (!empty($src)) {
|
|
$src = strtolower($src);
|
|
$filter = " AND ( LOWER(N_SUBGIAT) like '%" . $src . "%' OR LOWER(N_RSK) like '%" . $src . "%')";
|
|
}
|
|
|
|
$dataFilter = DB::select(DB::raw("SELECT COUNT(I_ID) as JML FROM ($sqlStr $filter) x"));
|
|
$dataTotal = DB::select(DB::raw("SELECT COUNT(I_ID) as JML FROM ($sqlStr) x"));
|
|
$data = DB::select(DB::raw("SELECT * FROM (" . $sqlStr . $filter . ") a ORDER BY a.I_IDOPD, a.I_ID OFFSET " . $offset . " ROWS FETCH NEXT " . $limit . " ROWS ONLY"));
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal[0]->jml,
|
|
"recordsFiltered" => $dataFilter[0]->jml,
|
|
"data" => $data
|
|
]);
|
|
}
|
|
|
|
protected function inputDataRealisasi($request)
|
|
{
|
|
$req = $request->all();
|
|
$VwDpaRsk = VwDpaRsk::where("I_ID", $req["rsk"])->first();
|
|
|
|
$input = [
|
|
"tahun_anggaran" => getTA(),
|
|
"jenis_belanja" => $req["jenis"],
|
|
"sub_jenis_belanja" => isset($req["sub_jenis"]) ? $req["sub_jenis"] : 0,
|
|
"kode_program" => $VwDpaRsk["c_program"],
|
|
"nama_program" => $VwDpaRsk["n_program"],
|
|
"kode_skpd" => $VwDpaRsk["c_opd"],
|
|
"nama_skpd" => $VwDpaRsk["n_opd"],
|
|
"kode_kegiatan" => $VwDpaRsk["c_giat"],
|
|
"nama_kegiatan" => $VwDpaRsk["n_giat"],
|
|
"kode_sub_kegiatan" => $VwDpaRsk["c_subgiat"],
|
|
"nama_sub_kegiatan" => $VwDpaRsk["n_subgiat"],
|
|
"kode_rsk" => $VwDpaRsk["i_id"],
|
|
"nama_rsk" => $VwDpaRsk["n_rsk"],
|
|
"kode_rekening" => null,
|
|
"nama_rekening" => null,
|
|
"jumlah_anggaran" => $VwDpaRsk["v_angg_tapd"],
|
|
"alokasi_anggaran" => isset($req["alokasi_anggaran"]) ? replaceMoney($req["alokasi_anggaran"]) : 0,
|
|
"volume_satuan" => isset($req["vol"]) ? replaceMoney($req["vol"]) : 0,
|
|
"unit_satuan" => isset($req["unit"]) ? $req["unit"] : "",
|
|
"periode_anggaran" => isset($req["periode_anggaran"]) ? $req["periode_anggaran"] : "",
|
|
"jml_rencana_kontrak" => isset($req["jml_rencana_kontrak"]) ? $req["jml_rencana_kontrak"] : 0,
|
|
"jenis_dana" => $req["jenis_dana"],
|
|
"sub_jenis_dana" => $req["sub_jenis_dana"],
|
|
// "id_sps"=>isset($req["id_sps"])?$req["id_sps"]:0,
|
|
"created_by" => Auth::user()->id
|
|
];
|
|
|
|
if (isset($req["id_sps"])) {
|
|
$sps = Trbas::where("C_AKUN", $req["id_sps"])->whereRaw("C_TAHUN_BERLAKU<=" . getTA() . " AND C_TAHUN_BERAKHIR>=" . getTA())->firstorNew();
|
|
|
|
if ($sps) {
|
|
$input["kode_rekening"] = $sps["c_akun"];
|
|
$input["nama_rekening"] = $sps["n_akun"];
|
|
}
|
|
}
|
|
|
|
return $input;
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
"jenis_dana" => "required",
|
|
"sub_jenis_dana" => "required",
|
|
"jenis" => "required",
|
|
"rsk" => "required",
|
|
// "periode_anggaran"=>'required',
|
|
// "vol"=>"required",
|
|
// "unit"=>"required",
|
|
//"id_sps"=>"required", // Karena ada yg tidak memakai SPS
|
|
]);
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
$input = $this->inputDataRealisasi($request);
|
|
$belanjaRealisasi = BelanjaRealisasi::create($input);
|
|
|
|
if ($request["jenis_dana"] == "DAU") {
|
|
BelanjaRealisasiRinciDau::where("belanja_realisasi_id", $belanjaRealisasi->id)->delete();
|
|
foreach ($request["dau"]["deskripsi"] as $k => $dau) {
|
|
$inputRinciDau["belanja_realisasi_id"] = $belanjaRealisasi->id;
|
|
$inputRinciDau["id_rinci_dau"] = $dau;
|
|
$inputRinciDau["deskripsi"] = $request["dau"]["deskripsi_name"][$k];
|
|
$inputRinciDau["jml_anggaran"] = replaceMoney($request["dau"]["anggaran"][$k]);
|
|
$inputRinciDau["volume_satuan"] = $request["dau"]["volume"][$k];
|
|
$inputRinciDau["periode_anggaran"] = $request["dau"]["periode_anggaran"][$k];
|
|
$inputRinciDau["unit_satuan"] = $request["dau"]["unit"][$k];
|
|
|
|
BelanjaRealisasiRinciDau::create($inputRinciDau);
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('success', 'Data Realisasi Belanja berhasil dibuat!');
|
|
} catch (Throwable $e) {
|
|
|
|
DB::rollBack();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('error', 'Data Realisasi Belanja gagal dibuat.');
|
|
}
|
|
}
|
|
|
|
public function edit(VwBelanjaRealisasi $realisasi_belanja)
|
|
{
|
|
$VwDpaRsk = VwDpaRsk::where("I_ID", $realisasi_belanja->kode_rsk)->first();
|
|
$unitSatuan = UnitSatuan::orderBy("id")->get();
|
|
$sps = Sps_pendapatan::select(DB::raw("ID,KODE_REKENING||' | '||NAMA_REKENING as name"))->where("ID", $realisasi_belanja->id_sps)->first();
|
|
$BelanjaRealisasiRinciDau = BelanjaRealisasiRinciDau::where("belanja_realisasi_id", $realisasi_belanja->id)->get();
|
|
|
|
return view('realisasi_belanja.edit', compact("realisasi_belanja", "sps", "unitSatuan", "VwDpaRsk", "BelanjaRealisasiRinciDau"));
|
|
}
|
|
|
|
public function update(Request $request, BelanjaRealisasi $realisasi_belanja)
|
|
{
|
|
if (Auth::user()->lock_ubah_data == 1) {
|
|
abort(403, 'Tidak diperbolehkan mengupdate data oleh admin!');
|
|
}
|
|
$request->validate([
|
|
"jenis_dana" => "required",
|
|
"sub_jenis_dana" => "required",
|
|
"jenis" => "required",
|
|
"rsk" => "required",
|
|
// "vol"=>"required",
|
|
// "unit"=>"required",
|
|
//"id_sps"=>"required",
|
|
]);
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
$input = $this->inputDataRealisasi($request);
|
|
$realisasi_belanja->update($input);
|
|
|
|
if ($request["jenis_dana"] == "DAU") {
|
|
BelanjaRealisasiRinciDau::where("belanja_realisasi_id", $realisasi_belanja->id)->delete();
|
|
foreach ($request["dau"]["deskripsi"] as $k => $dau) {
|
|
$inputRinciDau["belanja_realisasi_id"] = $realisasi_belanja->id;
|
|
$inputRinciDau["id_rinci_dau"] = $dau;
|
|
$inputRinciDau["deskripsi"] = $request["dau"]["deskripsi_name"][$k];
|
|
$inputRinciDau["jml_anggaran"] = replaceMoney($request["dau"]["anggaran"][$k]);
|
|
$inputRinciDau["volume_satuan"] = $request["dau"]["volume"][$k];
|
|
$inputRinciDau["unit_satuan"] = $request["dau"]["unit"][$k];
|
|
$inputRinciDau["periode_anggaran"] = $request["dau"]["periode_anggaran"][$k];
|
|
|
|
BelanjaRealisasiRinciDau::create($inputRinciDau);
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('success', 'Data Realisasi Belanja berhasil diubah!');
|
|
} catch (Throwable $e) {
|
|
|
|
DB::rollBack();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('error', 'Data Realisasi Belanja gagal diubah.');
|
|
}
|
|
}
|
|
|
|
public function submit(Request $request, $id)
|
|
{
|
|
$BelanjaRealisasi = DB::select(DB::raw("SELECT * FROM SAMASA.VW_BELANJA_REALISASI WHERE ID='$id'"));
|
|
$BelanjaRealisasi = $BelanjaRealisasi[0];
|
|
|
|
$this->setTitle("Realisasi Belanja");
|
|
$this->setSubtitle("Realisasi Belanja :: " . $BelanjaRealisasi->jenis_dana . " " . $BelanjaRealisasi->nama_subjenis_dana);
|
|
|
|
if (getRole() == "sbpk") {
|
|
$sbpkUpdate = BelanjaRealisasi::where("id", $id)->firstOrNew();
|
|
$sbpkUpdate->update(["f_view_sbpk" => 1]);
|
|
}
|
|
|
|
if (getRole() == "skpd") {
|
|
if ($BelanjaRealisasi->kode_skpd != Auth::user()->nrk) {
|
|
abort(403, 'Tidak diperbolehkan mengunjungi halaman ini!');
|
|
}
|
|
}
|
|
|
|
if ($request->isMethod('post')) {
|
|
$req = $request->all();
|
|
$data["volume_satuan"] = $req["vol"];
|
|
$data["unit_satuan"] = $req["unit"];
|
|
$data["updated_by"] = Auth::user()->id;
|
|
$BelanjaRealisasi->update($data);
|
|
return redirect(URL::to("/realisasi-belanja/$id/submit"))->with('success', 'Data Realisasi Belanja berhasil di ubah!');
|
|
}
|
|
|
|
$unitSatuan = UnitSatuan::orderBy("id")->get();
|
|
$sps = Sps_pendapatan::select(DB::raw("ID,KODE_REKENING||' | '||NAMA_REKENING as name"))->where("ID", $BelanjaRealisasi->id_sps)->first();
|
|
|
|
return view('realisasi_belanja.submit', compact("BelanjaRealisasi", "unitSatuan", "sps"));
|
|
}
|
|
|
|
public function submit_akb_spd(VwBelanjaRealisasi $BelanjaRealisasi)
|
|
{
|
|
|
|
$vwAKB = DB::select(DB::raw("SELECT * FROM SAMASA.MV_ASYNC_AKB_REALISASI x WHERE I_IDRSK = " . $BelanjaRealisasi->kode_rsk));
|
|
if ($vwAKB) {
|
|
$vwAKB = json_decode(json_encode($vwAKB[0]), true);
|
|
} else {
|
|
$vwAKB = [];
|
|
}
|
|
|
|
$vwSPD = [];
|
|
if ($BelanjaRealisasi->jenis_dana == "DBH" && $BelanjaRealisasi->nama_subjenis_dana != "CHT") {
|
|
$vwSPD = BelanjaRealisasi::getSPD($BelanjaRealisasi->kode_sub_kegiatan, $BelanjaRealisasi->id_skpd);
|
|
} else {
|
|
$vwSPD = BelanjaRealisasiSPD::where("id_rsk", $BelanjaRealisasi->kode_rsk)->get();
|
|
}
|
|
|
|
$vwSP2D = DB::select(
|
|
DB::raw('SELECT x.I_ID as IDSP2D, x.I_SP2DNO_DOK,
|
|
TO_CHAR(x.D_SP2D_SAH,\'DD-MM-YYYY\') AS D_SP2D_SAH, sum(y.V_SPP) as V_SPP
|
|
FROM NEWSIPKD.TMSP2D x
|
|
LEFT JOIN NEWSIPKD.V_SPPBLJRSK y
|
|
ON x.I_ID = y.I_IDSP2D
|
|
WHERE y.I_IDRSK=' . $BelanjaRealisasi->kode_rsk . ' AND X.D_SP2D_SAH IS NOT NULL GROUP BY x.I_ID, x.I_SP2DNO_DOK,x.D_SP2D_SAH ORDER BY x.D_SP2D_SAH ')
|
|
);
|
|
|
|
$BelanjaRealisasiKontrak = BelanjaRealisasiKontrak::where("belanja_realisasi_id", $BelanjaRealisasi->id)->get();
|
|
|
|
return view('realisasi_belanja.submit_akb_spd_kontrak', compact("BelanjaRealisasi", "vwAKB", "vwSPD", "vwSP2D", "BelanjaRealisasiKontrak"));
|
|
}
|
|
|
|
public function submit_realisasi(VwBelanjaRealisasi $BelanjaRealisasi)
|
|
{
|
|
// GET BELANJA SEMESTER ======================================================
|
|
$BelanjaRealisasiDetail = BelanjaRealisasiDetail::where("belanja_realisasi_id", $BelanjaRealisasi->id)->get();
|
|
$BelanjaRealisasiDetail = json_decode(json_encode($BelanjaRealisasiDetail), true);
|
|
$semester1 = array_search(1, array_column($BelanjaRealisasiDetail, "semester"));
|
|
$semester1 = $semester1 > -1 ? $BelanjaRealisasiDetail[$semester1] : [];
|
|
$semester2 = array_search(2, array_column($BelanjaRealisasiDetail, "semester"));
|
|
$semester2 = $semester2 > -1 ? $BelanjaRealisasiDetail[$semester2] : [];
|
|
$BelanjaRealisasiDetail = [];
|
|
$BelanjaRealisasiDetail[0] = $semester1;
|
|
$BelanjaRealisasiDetail[1] = $semester2;
|
|
|
|
$BelanjaRealisasiRinci = BelanjaRealisasiRinci::where("belanja_realisasi_id", $BelanjaRealisasi->id)->firstorNew();
|
|
|
|
$realisasi = $this->getRealisasi($BelanjaRealisasi->kode_rsk);
|
|
$jmlRealisasi1 = empty($realisasi->sms1) ? 0 : $realisasi->sms1;
|
|
$jmlRealisasi2 = empty($realisasi->sms2) ? 0 : $realisasi->sms2;
|
|
$totalRealisasi = $jmlRealisasi2;
|
|
$BelanjaRealisasiRinciDau = BelanjaRealisasiRinciDau::where("belanja_realisasi_id", $BelanjaRealisasi->id)->get();
|
|
$unitSatuan = UnitSatuan::orderBy("id")->get();
|
|
|
|
return view('realisasi_belanja.submit_realisasi', compact("BelanjaRealisasi", "BelanjaRealisasiDetail", "BelanjaRealisasiRinci", "BelanjaRealisasiRinciDau", "jmlRealisasi1", "jmlRealisasi2", "unitSatuan", "totalRealisasi"));
|
|
}
|
|
|
|
public function realisasiDau(Request $request)
|
|
{
|
|
$req = $request->all();
|
|
$idSubmit = 0;
|
|
foreach ($req["dau"]["realisasi"] as $k => $dau) {
|
|
$inputRinciDau["jml_realisasi"] = replaceMoney($dau);
|
|
$inputRinciDau["volume_satuan_realisasi"] = $request["dau"]["volume_realisasi"][$k];
|
|
$inputRinciDau["unit_satuan_realisasi"] = $request["dau"]["unit_realisasi"][$k];
|
|
$inputRinciDau["periode_anggaran"] = $request["dau"]["periode_anggaran"][$k];
|
|
|
|
|
|
$BelanjaRealisasiRinciDau = BelanjaRealisasiRinciDau::where("id", $request["dau"]["id"][$k]);
|
|
$BelanjaRealisasiRinciDau->update($inputRinciDau);
|
|
$idSubmit = $BelanjaRealisasiRinciDau->first()->belanja_realisasi_id;
|
|
}
|
|
|
|
return redirect(URL::to("/realisasi-belanja/" . $idSubmit . "/submit"))
|
|
->with('success', 'Data Rinci DAU berhasil disimpan!');
|
|
}
|
|
|
|
public function tableFilter(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$src = isset($post["search"]["value"]) ? strtolower($post["search"]["value"]) : "";
|
|
$JenisDana = isset($post["jenis_dana"]) ? $post["jenis_dana"] : "";
|
|
$SubJenisDana = isset($post["sub_jenis_dana"]) ? $post["sub_jenis_dana"] : "";
|
|
$skpd = isset($post["skpd"]) ? $post["skpd"] : "";
|
|
$subkeg = isset($post["subkeg"]) ? $post["subkeg"] : "";
|
|
$idSPS = isset($post["id_sps"]) ? $post["id_sps"] : "";
|
|
$fReview = isset($post["f_review"]) ? $post["f_review"] : "";
|
|
|
|
$filter = " WHERE tahun_anggaran = " . getTA();
|
|
|
|
if (getRole() == "skpd") {
|
|
$filter .= " AND KODE_SKPD='" . Auth::user()->nrk . "'";
|
|
} elseif (getRole() == "sbpk") {
|
|
$filter .= " AND KODE_SKPD IN (SELECT C_OPD FROM NEWSIPKD.TROPD WHERE C_WIL_SP2DPROSES=" . Auth::user()->wilayah . ")";
|
|
} elseif (getRole() == "walikota") {
|
|
$id = Tropd::where("C_OPD", Auth::user()->nrk)->first()["i_id"];
|
|
$filter .= " AND KODE_SKPD IN (SELECT C_OPD FROM NEWSIPKD.TROPD WHERE I_IDINDUK=" . $id . ")";
|
|
}
|
|
|
|
if (!empty($skpd)) {
|
|
$filter .= " AND KODE_SKPD='" . $skpd . "'";
|
|
}
|
|
|
|
if (!empty($JenisDana)) {
|
|
$filter .= " AND JENIS_DANA = '" . $JenisDana . "'";
|
|
}
|
|
|
|
if (!empty($SubJenisDana)) {
|
|
$filter .= " AND SUB_JENIS_DANA = " . $SubJenisDana;
|
|
}
|
|
|
|
if (!empty($idSPS)) {
|
|
$filter .= " AND KODE_REKENING = '" . $idSPS . "'";
|
|
}
|
|
|
|
if (!empty($fReview)) {
|
|
$fReview = $fReview == 2 ? 0 : $fReview;
|
|
$filter .= " AND f_view_sbpk = $fReview";
|
|
}
|
|
|
|
if (!empty($src)) {
|
|
$src = strtolower($src);
|
|
$filter .= " AND ( LOWER(NAMA_PROGRAM) LIKE '%" . $src . "%' OR
|
|
LOWER(NAMA_SUB_KEGIATAN) LIKE '%" . $src . "%' OR
|
|
LOWER(NAMA_RSK) LIKE '%" . $src . "%' OR
|
|
kode_rsk = '" . $src . "' ) ";
|
|
}
|
|
|
|
return $filter;
|
|
}
|
|
|
|
public function datatable(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$ta = $post["ta"];
|
|
|
|
$dataFilter = DB::select(DB::raw("SELECT COUNT(ID) as JML FROM VW_BELANJA_REALISASI " . $this->tableFilter($request)));
|
|
$dataTotal = BelanjaRealisasi::where("tahun_anggaran", $ta)->count();
|
|
$sqlStr = "SELECT * FROM SAMASA.VW_DPA_RSK WHERE C_ANGG_TAHUN=" . getTA();
|
|
if (getRole() == "skpd") {
|
|
$dataTotal = BelanjaRealisasi::where("tahun_anggaran", $ta)->whereRaw("KODE_SKPD='" . Auth::user()->nrk . "'")->count();
|
|
} elseif (getRole() == "sbpk") {
|
|
$dataTotal = BelanjaRealisasi::where("tahun_anggaran", $ta)->whereRaw("KODE_SKPD IN (SELECT C_OPD FROM NEWSIPKD.TROPD WHERE C_WIL_SP2DPROSES=" . Auth::user()->wilayah . ")");
|
|
}
|
|
$data = DB::select(DB::raw(BelanjaRealisasi::tableDataReport($ta, $this->tableFilter($request), $offset, $limit)));
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter[0]->jml,
|
|
"data" => $data
|
|
]);
|
|
}
|
|
|
|
public function destroy(BelanjaRealisasi $realisasi_belanja)
|
|
{
|
|
if (Auth::user()->lock_hapus_data == 1) {
|
|
abort(403, 'Tidak diperbolehkan menghapus data oleh admin!');
|
|
}
|
|
try {
|
|
DB::beginTransaction();
|
|
$realisasi_belanja->delete();
|
|
DB::commit();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('success', 'Data Realisasi Belanja berhasil dihapus!');
|
|
} catch (Throwable $e) {
|
|
|
|
DB::rollBack();
|
|
return redirect(URL::to("/realisasi-belanja"))
|
|
->with('error', 'Data Realisasi Belanja gagal dihapus.');
|
|
}
|
|
}
|
|
|
|
public function show(BelanjaRealisasi $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, $typeDana)
|
|
{
|
|
if (Auth::user()->is_lock_upload == 1) {
|
|
abort(403, 'Tidak diperbolehkan mengupload data oleh admin!');
|
|
}
|
|
$method = $request->method();
|
|
$this->setTitle("Upload Rencana Belanja " . strtoupper($typeDana));
|
|
$this->setSubtitle("Upload File");
|
|
$this->setIconTitle("fas fa-upload");
|
|
if ($request->isMethod('post')) {
|
|
$req = $request->all();
|
|
try {
|
|
$this->validate($request, [
|
|
'file' => 'required|mimes:xls,xlsx',
|
|
]);
|
|
|
|
$file = $request->file('file');
|
|
$subJenisDana = $request->optJenisDana;
|
|
$ta = $request->ta;
|
|
$tujuan_upload = 'uploadFiles';
|
|
$file->move($tujuan_upload, $file->getClientOriginalName());
|
|
|
|
DB::beginTransaction();
|
|
TempRealisasiBelanja::where("userid", Auth::user()->id)->delete();
|
|
if ($typeDana == "dbh") {
|
|
Excel::import(new RealisasiBelanjaImport($ta, strtoupper($typeDana), $subJenisDana), $tujuan_upload . "/" . $file->getClientOriginalName());
|
|
} else {
|
|
Excel::import(new RealisasiBelanjaImportDak($ta, strtoupper($typeDana), $subJenisDana), $tujuan_upload . "/" . $file->getClientOriginalName());
|
|
}
|
|
DB::commit();
|
|
|
|
return redirect(URL::to("/upload-realisasi-belanja/" . $typeDana))->with('success', 'Data Rencana belanja berhasil diupload, Silahkan validasi data!');
|
|
} catch (\Exception $e) {
|
|
// throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
abort(500, $e->getMessage());
|
|
// return redirect(URL::to("/upload-realisasi-belanja/".$typeDana))->with('error',$e->getMessage());
|
|
}
|
|
}
|
|
$VwJenisBelanja = VwJenisBelanja::orderBy("ID_JENIS_BELANJA")->get();
|
|
$this->siteTitle = "Rencana Belanja";
|
|
$view = $typeDana == "dbh" ? "upload" : "upload_dak";
|
|
return view('realisasi_belanja.' . $view, compact("VwJenisBelanja"));
|
|
}
|
|
|
|
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::where("userid", Auth::user()->id)->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::where("userid", Auth::user()->id)->count();
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data" => $data->skip($offset)->take($limit)->get()
|
|
]);
|
|
}
|
|
|
|
public function uploadValidate(Request $request, $typeDana)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
$datas = TempRealisasiBelanja::where("userid", Auth::user()->id)->orderBy("id", "ASC")->get();
|
|
for ($i = 0; $i < $datas->count(); $i++) {
|
|
$cekData = BelanjaRealisasi::where([
|
|
"kode_rsk" => $datas[$i]["kode_rsk"],
|
|
// "kode_rekening"=>$datas[$i]["kode_rekening"]
|
|
])->firstOrNew();
|
|
|
|
/* if (!$cekData==null){
|
|
$cekData->delete();
|
|
// BelanjaRealisasi::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"],
|
|
"jumlah_anggaran" => $datas[$i]["jumlah_anggaran"],
|
|
"volume_satuan" => $datas[$i]["volume_satuan"],
|
|
"unit_satuan" => $datas[$i]["unit_satuan"],
|
|
"jml_rencana_kontrak" => $datas[$i]["jml_rencana_kontrak"],
|
|
"jenis_dana" => $datas[$i]["jenis_dana"],
|
|
"sub_jenis_dana" => $datas[$i]["sub_jenis_dana"],
|
|
"created_by" => $datas[$i]["userid"]
|
|
];
|
|
|
|
if (!$cekData == null) {
|
|
$cekData->update($input);
|
|
} else {
|
|
BelanjaRealisasi::create($input);
|
|
}
|
|
}
|
|
TempRealisasiBelanja::where("userid", Auth::user()->id)->delete();
|
|
DB::commit();
|
|
return redirect(URL::to("/upload-realisasi-belanja/" . $typeDana))->with('success', 'Data Realisasi belanja berhasil diupload.');
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect(URL::to("/upload-realisasi-belanja/" . $typeDana))->with('error', $e->getMessage());
|
|
}
|
|
return view('realisasi_belanja.upload');
|
|
}
|
|
|
|
public function getRealisasi($kdRsk, $sms = 1)
|
|
{
|
|
$select = [];
|
|
for ($i = 1; $i <= 6; $i++) {
|
|
$select[] = " BULAN_" . substr("00" . $i, -2);
|
|
}
|
|
$Selectfilter = implode("+", $select) . " AS SMS1, ";
|
|
|
|
for ($i = 7; $i <= 12; $i++) {
|
|
$select[] = " BULAN_" . substr("00" . $i, -2);
|
|
}
|
|
$Selectfilter .= implode("+", $select) . " AS SMS2 ";
|
|
|
|
$jmlRealisasi = DB::select(DB::raw("SELECT SUM(SMS1) SMS1,SUM(SMS2) SMS2 FROM (SELECT $Selectfilter FROM MV_REALISASI_BELANJA_PERBULAN
|
|
WHERE I_IDRSK = " . $kdRsk . ") x"));
|
|
|
|
return $jmlRealisasi[0];
|
|
}
|
|
|
|
public function ubahSPD(Request $request, $id)
|
|
{
|
|
$req = $request->all();
|
|
$detailRSK = DB::select(DB::raw("SELECT * FROM SAMASA.VW_DPA_RSK WHERE I_ID = $id"));
|
|
$detailRSK = json_decode(json_encode($detailRSK[0]), true);
|
|
$SPDs = BelanjaRealisasi::getSPD($detailRSK["c_subgiat"], $detailRSK["i_idopd"]);
|
|
|
|
$redirect = URL::to($req["redirect"]);
|
|
|
|
if ($request->isMethod('post')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$itemSPD = isset($req["spd"]) ? $req["spd"] : [];
|
|
// if (count($itemSPD)>0)
|
|
// {
|
|
BelanjaRealisasiSPD::where("id_rsk", $id)->delete();
|
|
$SPDs = (array) $SPDs;
|
|
foreach ($itemSPD as $rowSPD) {
|
|
$check = array_search($rowSPD, array_column($SPDs, "no_spd"));
|
|
if ($check > -1) {
|
|
$data["id_rsk"] = $id;
|
|
$data["no_spd"] = $SPDs[$check]->no_spd;
|
|
$data["tgl"] = $SPDs[$check]->tgl;
|
|
$data["jumlah"] = $SPDs[$check]->jumlah;
|
|
|
|
BelanjaRealisasiSPD::create($data);
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
$msg = "Data SPD berhasil di input!";
|
|
if ($request->ajax()) {
|
|
return response()->json(["success" => true, "message" => $msg]);
|
|
} else {
|
|
return redirect($redirect)->with('success', $msg);
|
|
}
|
|
// }else{
|
|
// return redirect($redirect)->with('error', "Data SPD belum dipilih!");
|
|
// }
|
|
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
if ($request->ajax()) {
|
|
return response()->json(["success" => false, "message" => $e->getMessage()]);
|
|
} else {
|
|
return redirect($redirect)->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
$selected = BelanjaRealisasiSPD::where("id_rsk", $id)->get();
|
|
//$selected = (array) $selected;
|
|
$selected = json_decode(json_encode($selected), true);
|
|
|
|
return view('realisasi_belanja.form_input_spd', compact("SPDs", "id", "redirect", "selected"));
|
|
}
|
|
|
|
public function inputRealisasi(Request $request, $id)
|
|
{
|
|
$req = $request->all();
|
|
$BelanjaRealisasi = BelanjaRealisasi::where("id", $id)->firstOrNew();
|
|
$ta = $BelanjaRealisasi->tahun_anggaran;
|
|
$filter = "";
|
|
$semester = "";
|
|
$redirect = isset($req["redirect_link"]) ? $req["redirect_link"] : URL::to("/realisasi-belanja");
|
|
if ($req["type"] == "sms") {
|
|
$sms = (int)$req["sms"];
|
|
if ($sms == 1) {
|
|
$semester = "SEMESTER 1";
|
|
$filter = " AND D_POSTING BETWEEN '" . $ta . "0101' AND '" . $ta . "0630' ";
|
|
} else {
|
|
$semester = "SEMESTER 2";
|
|
$filter = " AND D_POSTING BETWEEN '" . $ta . "0101' AND '" . $ta . "1231' ";
|
|
}
|
|
|
|
$BelanjaRealisasiDetail = BelanjaRealisasiDetail::where("belanja_realisasi_id", $BelanjaRealisasi->id)->where("semester", $sms)->first();
|
|
$jmlRealisasi = DB::select(DB::raw("SELECT sum(REALISASI) as jml FROM NEWSIPKD.VW_BKU_REALISASI_RSK
|
|
WHERE IDRSK = " . $BelanjaRealisasi->kode_rsk . $filter));
|
|
$jmlRealisasi = $jmlRealisasi[0];
|
|
if ($request->isMethod('post')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
BelanjaRealisasiDetail::where("belanja_realisasi_id", $BelanjaRealisasi->id)->where("semester", $sms)->delete();
|
|
$data["belanja_realisasi_id"] = $BelanjaRealisasi->id;
|
|
$data["jumlah_realisasi"] = $jmlRealisasi->jml;
|
|
$data["alokasi_realisasi"] = replaceMoney($req["alokasi_realisasi"]);
|
|
$data["volume_satuan_realisasi"] = $req["vol_realisasi"];
|
|
$data["unit_satuan_realisasi"] = $req["unit_realisasi"];
|
|
// $data["periode_anggaran"] = $req["periode_anggaran"];
|
|
$data["semester"] = (int)$req["sms"];
|
|
$data["created_by"] = Auth::user()->id;
|
|
BelanjaRealisasiDetail::create($data);
|
|
|
|
$BelanjaRealisasiDetail = BelanjaRealisasiDetail::where("belanja_realisasi_id", $BelanjaRealisasi->id)->orderby("semester")->get();
|
|
$dataBelanjaRealisasi = [];
|
|
if (count($BelanjaRealisasiDetail) == 1) {
|
|
$dataBelanjaRealisasi["jumlah_realisasi"] = $BelanjaRealisasiDetail[0]->jumlah_realisasi;
|
|
$dataBelanjaRealisasi["volume_satuan_realisasi"] = $BelanjaRealisasiDetail[0]->volume_satuan_realisasi;
|
|
$dataBelanjaRealisasi["unit_satuan_realisasi"] = $BelanjaRealisasiDetail[0]->unit_satuan_realisasi;
|
|
} else if (count($BelanjaRealisasiDetail) > 1) {
|
|
$dataBelanjaRealisasi["jumlah_realisasi"] = $BelanjaRealisasiDetail[1]->jumlah_realisasi;
|
|
$dataBelanjaRealisasi["volume_satuan_realisasi"] = $BelanjaRealisasiDetail[1]->volume_satuan_realisasi;
|
|
$dataBelanjaRealisasi["unit_satuan_realisasi"] = $BelanjaRealisasiDetail[1]->unit_satuan_realisasi;
|
|
}
|
|
$dataBelanjaRealisasi["realisasi_by"] = Auth::user()->id;
|
|
$BelanjaRealisasi->update($dataBelanjaRealisasi);
|
|
|
|
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("BelanjaRealisasi", "BelanjaRealisasiDetail", "jmlRealisasi", "unitSatuan", "redirect", "semester", "sms"));
|
|
} else if ($req["type"] == "rinci") {
|
|
|
|
if ($request->isMethod('post')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$bulan = $req["bulan"];
|
|
$data["belanja_realisasi_id"] = $BelanjaRealisasi->id;
|
|
$data["jumlah_realisasi_" . $bulan] = replaceMoney($req["jml_realisasi"]);
|
|
$data["volume_satuan_realisasi_" . $bulan] = replaceMoney($req["vol_realisasi"]);
|
|
$data["created_by"] = Auth::user()->id;
|
|
// var_dump($data); exit;
|
|
BelanjaRealisasiRinci::updateOrCreate(
|
|
["belanja_realisasi_id" => $BelanjaRealisasi->id],
|
|
$data
|
|
);
|
|
|
|
DB::commit();
|
|
|
|
return redirect($redirect)->with('success', 'Data Realisasi Rinci berhasil di input!');
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect($redirect)->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$BelanjaRealisasiRinci = BelanjaRealisasiRinci::where("belanja_realisasi_id", $BelanjaRealisasi->id)->firstorNew();
|
|
$BelanjaRealisasiRinci = json_encode($BelanjaRealisasiRinci);
|
|
return view('realisasi_belanja.form_input_realisasi_rinci', compact("BelanjaRealisasi", "redirect", "BelanjaRealisasiRinci"));
|
|
}
|
|
}
|
|
|
|
public function datatableInputRealisasi(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$src = isset($post["search"]) ? $post["search"]["value"] : "";
|
|
|
|
$dataFilter = 0;
|
|
$data = DB::select(
|
|
DB::raw('SELECT x.I_ID as IDSP2D, x.I_IDOPD,x.I_SP2DNO_DOK,TO_CHAR(x.D_SP2D_SAH,\'DD-MM-YYYY\') AS D_SP2D_SAH,x.V_SPP,
|
|
a.no_sp2d,a.jumlah_realisasi,a.VOLUME_SATUAN_REALISASI,a.UNIT_SATUAN_REALISASI,a.ID
|
|
FROM NEWSIPKD.TMSP2D x
|
|
LEFT JOIN NEWSIPKD.TMSPPRINCIBLJRSK y
|
|
ON x.I_IDSPP = y.I_IDSPP
|
|
LEFT JOIN SAMASA.DBH_BELANJA_REALISASI_DETAIL a
|
|
ON x.I_SP2DNO_DOK = a.NO_SP2D
|
|
WHERE y.I_IDRSK = ' . $request->id . ' ORDER BY x.D_SP2D_SAH ')
|
|
);
|
|
$dataFilter = count($data);
|
|
$dataTotal = $dataFilter;
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data" => $data
|
|
]);
|
|
}
|
|
|
|
protected function uploadFileKontrak($request, $id)
|
|
{
|
|
$file = $request->file('file_kontrak');
|
|
if ($file) {
|
|
$fileName = $file->getClientOriginalName();
|
|
$tujuan_upload = config('constants.upload_path_kontrak') . $id;
|
|
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
|
|
$file->move($tujuan_upload, $fileName);
|
|
return $fileName;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function kontrak(Request $request, $id)
|
|
{
|
|
$BelanjaRealisasi = BelanjaRealisasi::where("id", $id)->firstOrNew();
|
|
$req = $request->all();
|
|
$redirect = "/realisasi-belanja/" . $id . "/submit";
|
|
$action = "/realisasi-belanja/" . $id . "/kontrak";
|
|
// var_dump("WOY"); exit;
|
|
if ($request->isMethod('post')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
$this->validate($request, [
|
|
'file_kontrak' => 'required|mimes:pdf',
|
|
]);
|
|
$fileName = $this->uploadFileKontrak($request, $id);
|
|
|
|
BelanjaRealisasiKontrak::where("belanja_realisasi_id", $id)->where("nomor_kontrak", $req["nomor_kontrak"])->firstOrNew()->delete();
|
|
$data["belanja_realisasi_id"] = $id;
|
|
$data["nomor_kontrak"] = $req["nomor_kontrak"];
|
|
$data["tgl_kontrak"] = ConvertIndoDate($req["tgl_kontrak"]);
|
|
$data["nominal_kontrak"] = replaceMoney($req["nominal_kontrak"]);
|
|
$data["file_kontrak"] = $fileName;
|
|
$data["nomor_bast"] = "";
|
|
$data["created_by"] = Auth::user()->id;
|
|
BelanjaRealisasiKontrak::create($data);
|
|
|
|
DB::commit();
|
|
|
|
return redirect($redirect)->with('success', 'Data Kontrak berhasil di input!');
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect($redirect)->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
return view('realisasi_belanja.form_kontrak', compact("BelanjaRealisasi", "action"));
|
|
}
|
|
|
|
public function kontrakUpdate(Request $request, $idKontrak)
|
|
{
|
|
$BelanjaRealisasiKontrak = BelanjaRealisasiKontrak::where("id", $idKontrak)->firstorNew();
|
|
$BelanjaRealisasi = BelanjaRealisasi::where("id", $BelanjaRealisasiKontrak->belanja_realisasi_id)->firstOrNew();
|
|
$req = $request->all();
|
|
$redirect = "/realisasi-belanja/" . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/submit";
|
|
$action = "/realisasi-belanja/" . $idKontrak . "/kontrak";
|
|
if ($request->isMethod('put')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
$data["nomor_kontrak"] = $req["nomor_kontrak"];
|
|
$data["tgl_kontrak"] = ConvertIndoDate($req["tgl_kontrak"]);
|
|
$data["nominal_kontrak"] = replaceMoney($req["nominal_kontrak"]);
|
|
$data["nomor_bast"] = "";
|
|
$fileName = $this->uploadFileKontrak($request, $BelanjaRealisasi->id);
|
|
if ($fileName) {
|
|
$data["file_kontrak"] = $fileName;
|
|
}
|
|
$BelanjaRealisasiKontrak->update($data);
|
|
DB::commit();
|
|
|
|
return redirect($redirect)->with('success', 'Data Kontrak berhasil di input!');
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect($redirect)->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
return view('realisasi_belanja.form_kontrak', compact("BelanjaRealisasi", "BelanjaRealisasiKontrak", "action"));
|
|
}
|
|
|
|
public function destroyKontrak($id)
|
|
{
|
|
try {
|
|
|
|
DB::beginTransaction();
|
|
|
|
$BelanjaRealisasiKontrak = BelanjaRealisasiKontrak::where("id", $id)->firstorNew();
|
|
$alamatFile = config('constants.upload_path_kontrak') . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/" . $BelanjaRealisasiKontrak->file_kontrak;
|
|
if (file_exists($alamatFile)) {
|
|
unlink($alamatFile);
|
|
}
|
|
|
|
$basts = BelanjaRealisasiBast::where("id_kontrak", $id)->get();
|
|
foreach ($basts as $bast) {
|
|
$this->delBast($bast->id);
|
|
}
|
|
|
|
BelanjaRealisasiKontrak::where("id", $id)->delete();
|
|
|
|
DB::commit();
|
|
|
|
return redirect(URL::to("/realisasi-belanja/" . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/submit"))
|
|
->with('success', 'Data Kontrak Realisasi Belanja berhasil dihapus!');
|
|
} catch (Throwable $e) {
|
|
|
|
DB::rollBack();
|
|
return redirect(URL::to("/realisasi-belanja/" . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/submit"))
|
|
->with('error', 'Data Kontrak Realisasi Belanja gagal dihapus.');
|
|
}
|
|
}
|
|
|
|
public function downloadKontrak($kode)
|
|
{
|
|
$kode = explode("__", $kode);
|
|
$BelanjaRealisasiKontrak = BelanjaRealisasiKontrak::where(["belanja_realisasi_id" => $kode[0], "id" => $kode[1]])->firstorNew();
|
|
$headers = [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment;filename=' . $BelanjaRealisasiKontrak->file_kontrak
|
|
];
|
|
if ($BelanjaRealisasiKontrak) {
|
|
return response()->download(config('constants.upload_path_kontrak') . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/" . $BelanjaRealisasiKontrak->file_kontrak, $BelanjaRealisasiKontrak->file_kontrak, $headers);
|
|
} else {
|
|
echo "File tidak ditemukan!";
|
|
}
|
|
}
|
|
|
|
protected function uploadFileBast($request, $id)
|
|
{
|
|
$file = $request->file('file_bast');
|
|
if ($file) {
|
|
$fileName = $file->getClientOriginalName();
|
|
$tujuan_upload = config('constants.upload_path_kontrak') . $id . "/bast";
|
|
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
|
|
$file->move($tujuan_upload, $fileName);
|
|
return $fileName;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function bast(Request $request, $id)
|
|
{
|
|
$kontrak = BelanjaRealisasiKontrak::where("id", $id)->firstOrNew();
|
|
$BelanjaRealisasiBast = BelanjaRealisasiBast::where("id_kontrak", $id)->get();
|
|
return view('realisasi_belanja.list_bast', compact("BelanjaRealisasiBast", "kontrak"));
|
|
}
|
|
|
|
public function bastCreate(Request $request, $idKontrak)
|
|
{
|
|
$req = $request->all();
|
|
$kontrak = BelanjaRealisasiKontrak::where("id", $idKontrak)->firstOrNew();
|
|
$redirect = "/realisasi-belanja/" . $kontrak->belanja_realisasi_id . "/submit";
|
|
$action = "/realisasi-belanja/" . $idKontrak . "/bast/add";
|
|
// var_dump("WOY"); exit;
|
|
if ($request->isMethod('post')) {
|
|
try {
|
|
DB::beginTransaction();
|
|
$this->validate($request, [
|
|
'file_bast' => 'required|mimes:pdf',
|
|
]);
|
|
$fileName = $this->uploadFileBast($request, $kontrak->belanja_realisasi_id);
|
|
BelanjaRealisasiBast::where("id_kontrak", $idKontrak)->where("nomor_bast", $req["nomor_bast"])->firstOrNew()->delete();
|
|
$data["id_kontrak"] = $idKontrak;
|
|
$data["nomor_bast"] = $req["nomor_bast"];
|
|
$data["tgl_bast"] = ConvertIndoDate($req["tgl_bast"]);
|
|
$data["nominal_bast"] = replaceMoney($req["nominal_bast"]);
|
|
$data["file_bast"] = $fileName;
|
|
$data["created_by"] = Auth::user()->id;
|
|
BelanjaRealisasiBast::create($data);
|
|
|
|
DB::commit();
|
|
|
|
return redirect($redirect)->with('success', 'Data BAST berhasil di input!');
|
|
} catch (\Exception $e) {
|
|
throw new \Exception($e->getMessage());
|
|
DB::rollBack();
|
|
return redirect($redirect)->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
return view('realisasi_belanja.form_bast', compact("kontrak", "action"));
|
|
}
|
|
|
|
protected function delBast($id)
|
|
{
|
|
$BelanjaRealisasiBast = BelanjaRealisasiBast::where("id", $id)->firstorNew();
|
|
$BelanjaRealisasiKontrak = BelanjaRealisasiKontrak::where("id", $BelanjaRealisasiBast->id_kontrak)->firstorNew();
|
|
$alamatFile = config('constants.upload_path_kontrak') . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/bast/" . $BelanjaRealisasiBast->file_bast;
|
|
if (file_exists($alamatFile)) {
|
|
unlink($alamatFile);
|
|
}
|
|
return BelanjaRealisasiBast::where("id", $id)->delete();
|
|
}
|
|
|
|
public function destroyBast($id)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
$this->delBast($id);
|
|
DB::commit();
|
|
return redirect(URL::to("/realisasi-belanja/" . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/submit"))
|
|
->with('success', 'Data BAST Realisasi Belanja berhasil dihapus!');
|
|
} catch (Throwable $e) {
|
|
|
|
DB::rollBack();
|
|
return redirect(URL::to("/realisasi-belanja/" . $BelanjaRealisasiKontrak->belanja_realisasi_id . "/submit"))
|
|
->with('error', 'Data BAST Realisasi Belanja gagal dihapus.');
|
|
}
|
|
}
|
|
|
|
public function downloadBast($kode)
|
|
{
|
|
$kode = explode("__", $kode);
|
|
$BelanjaRealisasiBast = BelanjaRealisasiBast::where(["id_kontrak" => $kode[0], "id" => $kode[1]])->firstorNew();
|
|
$kontrak = BelanjaRealisasiKontrak::where("id", $kode[0])->firstOrNew();
|
|
$headers = [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment;filename=' . $BelanjaRealisasiBast->file_bast
|
|
];
|
|
if ($BelanjaRealisasiBast) {
|
|
return response()->download(config('constants.upload_path_kontrak') . $kontrak->belanja_realisasi_id . "/bast/" . $BelanjaRealisasiBast->file_bast, $BelanjaRealisasiBast->file_bast, $headers);
|
|
} else {
|
|
echo "File tidak ditemukan!";
|
|
}
|
|
}
|
|
|
|
public function download(Request $request)
|
|
{
|
|
$data = DB::select(DB::raw(BelanjaRealisasi::tableDataReport(getTA(), $this->tableFilter($request))));
|
|
$data = json_decode(json_encode($data), true);
|
|
|
|
$fileName = 'Realisasi-belanja.xlsx';
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$arrCol = [
|
|
'Kode SKPD' => 'kode_skpd',
|
|
'Nama SKPD' => 'nama_skpd',
|
|
'Kode Program' => 'kode_program',
|
|
'Nama Program' => 'nama_program',
|
|
'Kode Sub Kegiatan' => 'kode_sub_kegiatan',
|
|
'Sub Kegiatan' => 'nama_sub_kegiatan',
|
|
'Kode RSK' => 'kode_rsk',
|
|
'Nama RSK' => 'nama_rsk',
|
|
'Kode Rekening' => 'kode_rekening',
|
|
'Nama Rekening' => 'nama_rekening',
|
|
'Jenis Output (Berdasarkan PMK)' => 'keterangan_dau',
|
|
'Anggaran' => 'jumlah_anggaran',
|
|
'Alokasi Anggaran' => 'alokasi_anggaran',
|
|
'Volume' => 'volume_satuan',
|
|
'Unit' => 'unit_satuan',
|
|
'Realisasi SIPD' => 'jml',
|
|
'Realisasi' => 'jumlah_realisasi',
|
|
'Volume Realisasi' => 'volume_satuan_realisasi',
|
|
'Unit Realisasi' => 'unit_satuan_realisasi',
|
|
'Jenis Belanja' => 'nama_jenis_belanja',
|
|
'Sumber Dana Anggaran DAU' => 'periode_anggaran',
|
|
'Sub Jenis Belanja' => 'nama_sub_jenis_belanja',
|
|
'Semester 1' => ["semester1", "satuan_sms1"],
|
|
'Semester 2' => ["semester2", "satuan_sms2"],
|
|
];
|
|
|
|
foreach (GetBulan() as $key => $namaBulan) {
|
|
$arrCol += [$namaBulan => ["jumlah_realisasi_" . ($key + 1), "volume_satuan_realisasi_" . ($key + 1)]];
|
|
}
|
|
|
|
$i = 0;
|
|
foreach ($arrCol as $key => $fieldVal) {
|
|
if (is_array($fieldVal)) {
|
|
foreach ($fieldVal as $rowfieldVal) {
|
|
$sheet->setCellValue(getAlphabetCell($i) . '1', $key);
|
|
$i++;
|
|
}
|
|
$sheet->mergeCells(getAlphabetCell($i - 2) . '1:' . getAlphabetCell($i - 1) . '1');
|
|
} else {
|
|
$sheet->setCellValue(getAlphabetCell($i) . '1', $key);
|
|
$i++;
|
|
}
|
|
}
|
|
|
|
$rows = 2;
|
|
foreach ($data as $val) {
|
|
$i = 0;
|
|
foreach ($arrCol as $key => $fieldVal) {
|
|
if (is_array($fieldVal)) {
|
|
foreach ($fieldVal as $rowfieldVal) {
|
|
$valNotNull = $val[$rowfieldVal] ? $val[$rowfieldVal] : 0;
|
|
$contentVal = str_contains($rowfieldVal, "volume_satuan_realisasi") ? $valNotNull . " " . $val["unit_satuan"] : $valNotNull;
|
|
$sheet->setCellValue(getAlphabetCell($i) . $rows, $contentVal);
|
|
$i++;
|
|
}
|
|
} else {
|
|
$sheet->setCellValue(getAlphabetCell($i) . $rows, $val[$fieldVal]);
|
|
$i++;
|
|
}
|
|
}
|
|
$rows++;
|
|
}
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
$writer->save("downloadFiles/" . $fileName);
|
|
$headers = [
|
|
'Content-Type' => 'application/vnd.ms-excel',
|
|
'Content-Disposition' => 'attachment;filename=' . $fileName
|
|
];
|
|
return response()->download("downloadFiles/" . $fileName, $fileName, $headers);
|
|
}
|
|
}
|