302 lines
10 KiB
PHP
302 lines
10 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\Sps_pendapatan;
|
|
use App\Models\BelanjaRealisasi;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
class JadwalSalurdanaController extends Controller
|
|
{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->setTitle("Jadwal Salur Dana");
|
|
$this->setIconTitle("fa fa-calendar-alt");
|
|
}
|
|
|
|
/*
|
|
public function index()
|
|
{
|
|
return view('jadwal_salurdana.index');
|
|
}
|
|
*/
|
|
|
|
protected function filterJadwalSalur($request)
|
|
{
|
|
$ta = getTA();
|
|
|
|
$post = $request->all();
|
|
$typeDana = isset($post["jenis_dana"])?strtoupper($post["jenis_dana"]):"";
|
|
$idSPS = isset($post["id_sps"])?$post["id_sps"]:"";
|
|
$sqlstr = Sps_pendapatan::queryJadwalSalurDana($ta);
|
|
|
|
if (!empty($idSPS)){
|
|
$sqlstr.=" AND x.KODE_REKENING='$idSPS'";
|
|
}
|
|
|
|
if (!empty($typeDana)){
|
|
$kodeRekening = "'".implode("','",getKodeRekInduk($typeDana))."'";
|
|
$sqlstr.=" AND SUBSTR(x.kode_rekening,1,12) IN ($kodeRekening)";
|
|
}
|
|
|
|
return $sqlstr;
|
|
}
|
|
|
|
protected function filterBelanja($request, $typeDana)
|
|
{
|
|
$ta = getTA();
|
|
|
|
$post = $request->all();
|
|
$src = isset($post["src"]) ? $post["src"]:"";
|
|
$idSPS = isset($post["id_sps"])?$post["id_sps"]:"";
|
|
$skpd = isset($post["skpd"])?$post["skpd"]:"";
|
|
|
|
$where = "";
|
|
if (!empty($typeDana)){
|
|
$where = $typeDana == "cht" ? " AND x.jenis_dana = 'DBH' AND lower(x.NAMA_SUBJENIS_DANA) = 'cht' ": " AND x.jenis_dana = '$typeDana'";
|
|
}
|
|
$where.= !empty($idSPS) ? " AND x.kode_rekening='$idSPS' ":"";
|
|
|
|
$sqlstr = 'SELECT x.kode_skpd, x.nama_skpd, x.kode_rsk, x.nama_rsk, x.jumlah_anggaran, y.*
|
|
FROM SAMASA.VW_BELANJA_REALISASI x
|
|
LEFT JOIN SAMASA.MV_ASYNC_AKB_REALISASI y
|
|
ON x.KODE_RSK = y.I_IDRSK AND x.TAHUN_ANGGARAN = y.C_ANGG_TAHUN
|
|
WHERE x.TAHUN_ANGGARAN = \''.$ta.'\''.$where;
|
|
|
|
if (getRole()=="skpd"){
|
|
$sqlstr.=" AND KODE_SKPD='".Auth::user()->nrk."'";
|
|
}else{
|
|
if ($skpd){
|
|
$sqlstr.=" AND KODE_SKPD='$skpd'";
|
|
}
|
|
}
|
|
|
|
return $sqlstr;
|
|
}
|
|
|
|
public function datatableSalur(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
|
|
$sqlstr = $this->filterJadwalSalur($request);
|
|
$dataTotal = count(DB::select(DB::raw($sqlstr)));
|
|
|
|
$sqlLimit = $limit > 0?" OFFSET ".$offset." ROWS FETCH NEXT ".$limit." ROWS ONLY ":"";
|
|
$data = DB::select(DB::raw($sqlstr.'ORDER BY x.kode_rekening '.$sqlLimit));
|
|
$dataFilter = count(DB::select(DB::raw($sqlstr)));
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data"=> $data
|
|
]);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return view("jadwal_salurdana.index");
|
|
}
|
|
|
|
public function datatableBelanja(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$offset = $post["start"];
|
|
$limit = $post["length"];
|
|
$typeDana = $post["jenis_dana"];
|
|
|
|
$sqlstr = $this->filterBelanja($request, $typeDana);
|
|
|
|
$sqlLimit = $limit > 0?" OFFSET ".$offset." ROWS FETCH NEXT ".$limit." ROWS ONLY ":"";
|
|
$data = DB::select(DB::raw($sqlstr.' ORDER BY x.kode_skpd,x.kode_rsk '.$sqlLimit));
|
|
$dataTotal = count(DB::select(DB::raw($sqlstr)));
|
|
$dataFilter = count(DB::select(DB::raw($sqlstr)));
|
|
|
|
return response()->json([
|
|
"recordsTotal" => $dataTotal,
|
|
"recordsFiltered" => $dataFilter,
|
|
"data"=> $data
|
|
]);
|
|
}
|
|
|
|
protected function exportJadwalSalur($request)
|
|
{
|
|
$sqlstr = $this->filterJadwalSalur($request);
|
|
$sqlstr .= " ORDER BY kode_rekening";
|
|
|
|
$data = DB::select(DB::raw($sqlstr));
|
|
$data = json_decode(json_encode($data),true);
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setTitle('Jadwal Salur');
|
|
|
|
$sheet->setCellValue('A1', 'Kode Rekening');
|
|
$sheet->setCellValue('B1', 'Nama Rekening');
|
|
$alpha = range("A","Z");
|
|
$colIndex = 2;
|
|
// Nama Kolom bulan
|
|
$bulans = GetBulan();
|
|
foreach($bulans as $bulan){
|
|
$sheet->setCellValue($alpha[$colIndex].'1', $bulan);
|
|
$colIndex++;
|
|
$sheet->mergeCells($alpha[$colIndex].'1'.':'.$alpha[$colIndex].'1');
|
|
$colIndex++;
|
|
}
|
|
$sheet->setCellValue(getAlphabetCell($colIndex).'1', "Total");
|
|
$sheet->mergeCells(getAlphabetCell($colIndex).'1'.':'.getAlphabetCell($colIndex+1).'1');
|
|
$sheet->mergeCells('A1:A2');
|
|
$sheet->mergeCells('B1:B2');
|
|
$colIndex++;
|
|
|
|
// Nama Kolom Jadwal dan Realisasi
|
|
$colName = "Realisasi";
|
|
for($i=2;$i<=$colIndex;$i++){
|
|
$colName = $colName == "Jadwal" ? "Realisasi":"Jadwal";
|
|
$sheet->setCellValue(getAlphabetCell($i).'2', $colName);
|
|
}
|
|
|
|
// Data Kolom Bulan dan Realisasi
|
|
$rows = 3;
|
|
foreach ($data as $val){
|
|
$sheet->setCellValue('A' . $rows, $val["kode_rekening"]);
|
|
$sheet->setCellValue('B' . $rows, $val["nama_rekening"]);
|
|
$totalJadwalSalur = 0;
|
|
$totalRealisasi = 0;
|
|
$currIndex = 2;
|
|
for($i=1;$i<=12;$i++){
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["spsbulan".$i]);
|
|
$totalJadwalSalur += $val["spsbulan".$i];
|
|
$currIndex++;
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["real".$i]);
|
|
$totalRealisasi += $val["real".$i];
|
|
$currIndex++;
|
|
}
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $totalJadwalSalur);
|
|
$sheet->setCellValue(getAlphabetCell($currIndex+1).$rows, $totalRealisasi);
|
|
|
|
$rows++;
|
|
}
|
|
|
|
// TOTAL BAWAH
|
|
$sheet->setCellValue("A".$rows , "TOTAL");
|
|
$sheet->mergeCells('A'.$rows.':'.'B'.$rows);
|
|
for ($x=2;$x<=$colIndex;$x++){
|
|
$strAlpha = getAlphabetCell($x);
|
|
$SUMRANGE = $strAlpha."3:".$strAlpha.($rows-1);
|
|
$sheet->setCellValue($strAlpha.$rows , "=SUM($SUMRANGE)");
|
|
}
|
|
|
|
return $spreadsheet;
|
|
}
|
|
|
|
public function download(Request $request)
|
|
{
|
|
$spreadsheet = $this->exportJadwalSalur($request);
|
|
|
|
$fileName = 'Jadwal-salur-dana.xlsx';
|
|
$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);
|
|
}
|
|
|
|
|
|
public function downloadAll(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
|
|
$fileName = 'Jadwal-salur-belanja-'.date("Ymd").'.xlsx';
|
|
|
|
$spreadsheet = $this->exportJadwalSalur($request);
|
|
$spreadsheet->createSheet();
|
|
$spreadsheet->setActiveSheetIndex(1);
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
$sheet->setTitle('Akb dan Realisasi');
|
|
$sheet->setCellValue('A1', 'SKPD');
|
|
$sheet->setCellValue('B1', 'RSK');
|
|
$alpha = range("A","Z");
|
|
$colIndex = 2;
|
|
// Nama Kolom bulan
|
|
$bulans = GetBulan();
|
|
foreach($bulans as $bulan){
|
|
$sheet->setCellValue($alpha[$colIndex].'1', $bulan);
|
|
$colIndex++;
|
|
$sheet->mergeCells($alpha[$colIndex].'1'.':'.$alpha[$colIndex].'1');
|
|
$colIndex++;
|
|
}
|
|
$sheet->setCellValue(getAlphabetCell($colIndex).'1', "Total");
|
|
$sheet->mergeCells(getAlphabetCell($colIndex).'1'.':'.getAlphabetCell($colIndex+1).'1');
|
|
$sheet->mergeCells('A1:A2');
|
|
$sheet->mergeCells('B1:B2');
|
|
$colIndex++;
|
|
|
|
// Nama Kolom Jadwal dan Realisasi
|
|
$colName = "Realisasi";
|
|
for($i=2;$i<=$colIndex;$i++){
|
|
$colName = $colName == "AKB" ? "Realisasi":"AKB";
|
|
$sheet->setCellValue(getAlphabetCell($i).'2', $colName);
|
|
}
|
|
|
|
|
|
$sqlstr = $this->filterBelanja($request, $post["jenis_dana"]);
|
|
|
|
$data = DB::select(DB::raw($sqlstr));
|
|
$data = json_decode(json_encode($data),true);
|
|
|
|
// Data Kolom Bulan dan Realisasi
|
|
$rows = 3;
|
|
foreach ($data as $val){
|
|
$sheet->setCellValue('A' . $rows, $val["kode_skpd"]." | ".$val["nama_skpd"]);
|
|
$sheet->setCellValue('B' . $rows, $val["kode_rsk"]." | ".$val["nama_rsk"]);
|
|
$totalJadwalSalur = 0;
|
|
$totalRealisasi = 0;
|
|
$currIndex = 2;
|
|
for($i=1;$i<=12;$i++){
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["v_akb_".substr("00".$i,-2)]);
|
|
$totalJadwalSalur += $val["v_akb_".substr("00".$i,-2)];
|
|
$currIndex++;
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["v_bku_".substr("00".$i,-2)]);
|
|
$totalRealisasi += $val["v_bku_".substr("00".$i,-2)];
|
|
$currIndex++;
|
|
}
|
|
$sheet->setCellValue(getAlphabetCell($currIndex).$rows, $totalJadwalSalur);
|
|
$sheet->setCellValue(getAlphabetCell($currIndex+1).$rows, $totalRealisasi);
|
|
|
|
$rows++;
|
|
}
|
|
|
|
// TOTAL BAWAH
|
|
$sheet->setCellValue("A".$rows , "TOTAL");
|
|
$sheet->mergeCells('A'.$rows.':'.'B'.$rows);
|
|
for ($x=2;$x<=$colIndex;$x++){
|
|
$strAlpha = getAlphabetCell($x);
|
|
$SUMRANGE = $strAlpha."3:".$strAlpha.($rows-1);
|
|
$sheet->setCellValue($strAlpha.$rows , "=SUM($SUMRANGE)");
|
|
}
|
|
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
|
|
$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);
|
|
}
|
|
|
|
}
|