Download Jadwal Salur
This commit is contained in:
@@ -8,12 +8,15 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\Sps_pendapatan;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class JadwalSalurdanaController extends Controller
|
||||
{
|
||||
public function __construct(){
|
||||
$this->siteTitle = "Jadwal Salur Dana";
|
||||
parent::__construct();
|
||||
$this->setTitle("Jadwal Salur Dana");
|
||||
$this->setIconTitle("fa fa-calendar-alt");
|
||||
}
|
||||
|
||||
public function index()
|
||||
@@ -21,6 +24,32 @@ class JadwalSalurdanaController extends Controller
|
||||
return view('jadwal_salurdana.index');
|
||||
}
|
||||
|
||||
protected function queryJadwalSalurDana($ta)
|
||||
{
|
||||
return 'SELECT kode_rekening,nama_rekening,spsbulan1,spsbulan2,spsbulan3,spsbulan4,
|
||||
spsbulan5,spsbulan6,spsbulan7,spsbulan8,spsbulan9,spsbulan10,spsbulan11,spsbulan12,
|
||||
SUBSTR(KODE_REKENING,1,12) AS kodegrup,SUBSTR(KODE_REKENING,1,9) AS groupall,
|
||||
NVL("1",0) AS "REAL1",NVL("2",0) AS "REAL2",NVL("3",0) AS "REAL3",
|
||||
NVL("4",0) AS "REAL4",NVL("5",0) AS "REAL5",NVL("6",0) AS "REAL6",
|
||||
NVL("7",0) AS "REAL7",NVL("8",0) AS "REAL8",NVL("9",0) AS "REAL9",
|
||||
NVL("10",0) AS "REAL10",NVL("11",0) AS "REAL11",NVL("12",0) AS "REAL12"
|
||||
FROM PROKSI.SPS_PENDAPATAN x
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT * FROM (
|
||||
SELECT ID_SPS,extract(month from RKUD_TGL) AS BULAN,RKUD_JUMLAH
|
||||
FROM SAMASA.PENDAPATAN_REALISASI
|
||||
WHERE TAHUN=\''.$ta.'\'
|
||||
)
|
||||
PIVOT
|
||||
(
|
||||
SUM(RKUD_JUMLAH)
|
||||
FOR BULAN IN(1,2,3,4,5,6,7,8,9,10,11,12)
|
||||
)
|
||||
)y ON x.ID = y.ID_SPS
|
||||
WHERE x.TAHUN = '.$ta.' AND x.SKPD_ID=980 AND SUBSTR(x.KODE_REKENING,1,3)=\'4.2\'';
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
$post = $request->all();
|
||||
@@ -31,28 +60,13 @@ class JadwalSalurdanaController extends Controller
|
||||
$dataFilter = 0;
|
||||
$typeDana = isset($post["type_dana"])?$post["type_dana"]:"";
|
||||
$idSPS = isset($post["id_sps"])?$post["id_sps"]:"";
|
||||
$sqlstr = 'SELECT kode_rekening,nama_rekening,spsbulan1,spsbulan2,spsbulan3,spsbulan4,
|
||||
spsbulan5,spsbulan6,spsbulan7,spsbulan8,spsbulan9,spsbulan10,spsbulan11,spsbulan12,
|
||||
SUBSTR(KODE_REKENING,1,12) AS kodegrup,SUBSTR(KODE_REKENING,1,9) AS groupall,
|
||||
NVL("1",0) AS "REAL1",NVL("2",0) AS "REAL2",NVL("3",0) AS "REAL3",
|
||||
NVL("4",0) AS "REAL4",NVL("5",0) AS "REAL5",NVL("6",0) AS "REAL6",
|
||||
NVL("7",0) AS "REAL7",NVL("8",0) AS "REAL8",NVL("9",0) AS "REAL9",
|
||||
NVL("10",0) AS "REAL10",NVL("11",0) AS "REAL11",NVL("12",0) AS "REAL12"
|
||||
FROM PROKSI.SPS_PENDAPATAN x
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT * FROM (
|
||||
SELECT ID_SPS,extract(month from RKUD_TGL) AS BULAN,RKUD_JUMLAH
|
||||
FROM SAMASA.PENDAPATAN_REALISASI
|
||||
WHERE TAHUN=\''.$ta.'\'
|
||||
)
|
||||
PIVOT
|
||||
(
|
||||
SUM(RKUD_JUMLAH)
|
||||
FOR BULAN IN(1,2,3,4,5,6,7,8,9,10,11,12)
|
||||
)
|
||||
)y ON x.ID = y.ID_SPS
|
||||
WHERE x.TAHUN = '.$ta.' AND x.SKPD_ID=980 AND SUBSTR(x.KODE_REKENING,1,3)=\'4.2\'';
|
||||
$sqlstr = $this->queryJadwalSalurDana($ta);
|
||||
|
||||
if (!empty($idSPS)){
|
||||
$sqlstr.=" AND x.ID=$idSPS";
|
||||
}
|
||||
|
||||
$dataTotal = count(DB::select(DB::raw($sqlstr)));
|
||||
|
||||
if (!empty($typeDana)){
|
||||
if ($typeDana == "cht"){
|
||||
@@ -61,12 +75,6 @@ class JadwalSalurdanaController extends Controller
|
||||
$sqlstr.=" AND SUBSTR(kode_rekening,1,12) IN ('4.2.01.01.03','4.2.01.01.04')";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($idSPS)){
|
||||
$sqlstr.=" AND x.ID=$idSPS";
|
||||
}
|
||||
|
||||
$dataTotal = count(DB::select(DB::raw($sqlstr)));
|
||||
$data = DB::select(DB::raw($sqlstr.'ORDER BY kode_rekening OFFSET '.$offset.' ROWS FETCH NEXT '.$limit.' ROWS ONLY'));
|
||||
$dataFilter = count(DB::select(DB::raw($sqlstr)));
|
||||
|
||||
@@ -112,14 +120,19 @@ class JadwalSalurdanaController extends Controller
|
||||
NVL(V_BKU_09,0) AS V_BKU_09,
|
||||
NVL(V_BKU_10,0) AS V_BKU_10,
|
||||
NVL(V_BKU_11,0) AS V_BKU_11,
|
||||
NVL(V_BKU_12,0) AS V_BKU_12
|
||||
NVL(V_BKU_12,0) AS V_BKU_12,
|
||||
TOTAL AS TOTAL_REALISASI
|
||||
FROM (
|
||||
SELECT IDRSK,
|
||||
extract(month FROM TO_DATE(D_POSTING, \'YYYYMMDD\')) AS BULAN,
|
||||
SUM (REALISASI) AS V_REALISASI
|
||||
FROM NEWSIPKD.VW_BKU_REALISASI_RSK
|
||||
WHERE TAHUN_ANGGARAN = \''.$ta.'\'
|
||||
GROUP BY IDRSK,D_POSTING
|
||||
SELECT x.*,SUM (V_REALISASI) OVER ( PARTITION BY IDRSK ) AS Total
|
||||
FROM
|
||||
(
|
||||
SELECT IDRSK,
|
||||
extract(month FROM TO_DATE(D_POSTING, \'YYYYMMDD\')) AS BULAN,
|
||||
SUM (REALISASI) AS V_REALISASI
|
||||
FROM NEWSIPKD.VW_BKU_REALISASI_RSK
|
||||
WHERE TAHUN_ANGGARAN = \''.$ta.'\'
|
||||
GROUP BY IDRSK,D_POSTING
|
||||
) x
|
||||
)
|
||||
PIVOT
|
||||
(
|
||||
@@ -161,13 +174,14 @@ class JadwalSalurdanaController extends Controller
|
||||
) yy
|
||||
ON xx.IDRSK = yy.RSK_BELANJARINCI_ID
|
||||
) y
|
||||
ON x.KODE_RSK = y.IDRSK';
|
||||
ON x.KODE_RSK = y.IDRSK
|
||||
WHERE x.TAHUN_ANGGARAN = \''.$ta.'\' ';
|
||||
$data = DB::connection('oracle')->select(DB::raw($sqlstr.' ORDER BY x.id OFFSET '.$offset.' ROWS FETCH NEXT '.$limit.' ROWS ONLY'));
|
||||
$dataTotal = count(DB::connection('oracle')->select(DB::raw($sqlstr)));;
|
||||
if (!empty($src)){
|
||||
//$data->whereRaw("(LOWER(NAMA_REKENING) LIKE '%".strtolower($src)."%' OR LOWER(KODE_REKENING) LIKE '%".strtolower($src)."%')");
|
||||
}
|
||||
$dataFilter = count(DB::connection('oracle')->select(DB::raw($sqlstr)));
|
||||
$dataTotal = 0;
|
||||
|
||||
return response()->json([
|
||||
"recordsTotal" => $dataTotal,
|
||||
@@ -176,4 +190,79 @@ class JadwalSalurdanaController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function download()
|
||||
{
|
||||
$sqlstr = $this->queryJadwalSalurDana("2022");
|
||||
$data = DB::select(DB::raw($sqlstr));
|
||||
//var_dump($data); exit;
|
||||
$data = json_decode(json_encode($data),true);
|
||||
$fileName = 'Jadwal-salur-dana.xlsx';
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setCellValue('A1', 'Kode Rekening');
|
||||
$sheet->setCellValue('B1', 'Nama Rekening');
|
||||
$alpha = range("A","Z");
|
||||
$alphaIndex = 2;
|
||||
// Nama Kolom bulan
|
||||
$bulans = GetBulan();
|
||||
foreach($bulans as $bulan){
|
||||
$sheet->setCellValue($alpha[$alphaIndex].'1', $bulan);
|
||||
$sheet->mergeCells($alpha[$alphaIndex].'1'.':'.$alpha[$alphaIndex+1].'1');
|
||||
$alphaIndex+=2;
|
||||
}
|
||||
$sheet->setCellValue(getAlphabetCell($alphaIndex).'1', "TOTAL");
|
||||
$sheet->mergeCells(getAlphabetCell($alphaIndex).'1'.':'.getAlphabetCell($alphaIndex+1).'1');
|
||||
$sheet->mergeCells('A1:A2');
|
||||
$sheet->mergeCells('B1:B2');
|
||||
|
||||
// Nama Kolom Jadwal dan Realisasi
|
||||
$alphaIndex = 2;
|
||||
for($i=1;$i<=13;$i++){
|
||||
$sheet->setCellValue(getAlphabetCell($alphaIndex).'2', 'Jadwal');
|
||||
$sheet->setCellValue(getAlphabetCell($alphaIndex+1).'2', 'Realisasi');
|
||||
$alphaIndex+=2;
|
||||
}
|
||||
|
||||
// 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"]);
|
||||
$alphaIndex = 2;
|
||||
$totalJadwalSalur = 0;
|
||||
$totalRealisasi = 0;
|
||||
for($i=1;$i<=12;$i++){
|
||||
$sheet->setCellValue($alpha[$alphaIndex].$rows, $val["spsbulan".$i]);
|
||||
$sheet->setCellValue($alpha[$alphaIndex+1].$rows, $val['real'.$i]);
|
||||
$alphaIndex+=2;
|
||||
$totalJadwalSalur += $val["spsbulan".$i];
|
||||
$totalRealisasi += $val['real'.$i];
|
||||
}
|
||||
$sheet->setCellValue(getAlphabetCell($alphaIndex).$rows, $totalJadwalSalur);
|
||||
$sheet->setCellValue(getAlphabetCell($alphaIndex+1).$rows, $totalRealisasi);
|
||||
|
||||
$rows++;
|
||||
}
|
||||
|
||||
// TOTAL BAWAH
|
||||
$alphaIndex = 2;
|
||||
$sheet->setCellValue("A".$rows , "TOTAL");
|
||||
$sheet->mergeCells('A'.$rows.':'.'B'.$rows);
|
||||
for ($x=1;$x<=13;$x++){
|
||||
$strAlpha = getAlphabetCell($alphaIndex);
|
||||
$SUMRANGE = $strAlpha."3:".$strAlpha.($rows-1);
|
||||
$sheet->setCellValue($strAlpha.$rows , "=SUM($SUMRANGE)");
|
||||
$alphaIndex++;
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user