diff --git a/app/Http/Controllers/JadwalSalurdanaController.php b/app/Http/Controllers/JadwalSalurdanaController.php index 328b720..0537e8b 100644 --- a/app/Http/Controllers/JadwalSalurdanaController.php +++ b/app/Http/Controllers/JadwalSalurdanaController.php @@ -190,38 +190,56 @@ class JadwalSalurdanaController extends Controller ]); } - public function download() + public function download(Request $request) { - $sqlstr = $this->queryJadwalSalurDana("2022"); + $post = $request->all(); + $typeDana = isset($post["type_dana"])?$post["type_dana"]:""; + $idSPS = isset($post["id_sps"])?$post["id_sps"]:""; + $ta = $post["ta"]; + $sqlstr = $this->queryJadwalSalurDana($ta); + + if (!empty($idSPS)){ + $sqlstr.=" AND x.ID=$idSPS"; + } + + if (!empty($typeDana)){ + if ($typeDana == "cht"){ + $sqlstr.=" AND kode_rekening='4.2.01.01.01.0004'"; + }else{ + $sqlstr.=" AND SUBSTR(kode_rekening,1,12) IN ('4.2.01.01.03','4.2.01.01.04')"; + } + } + + $sqlstr .= " ORDER BY kode_rekening"; $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; + $colIndex = 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($alpha[$colIndex].'1', $bulan); + $colIndex++; + $sheet->mergeCells($alpha[$colIndex].'1'.':'.$alpha[$colIndex].'1'); + $colIndex++; } - $sheet->setCellValue(getAlphabetCell($alphaIndex).'1', "TOTAL"); - $sheet->mergeCells(getAlphabetCell($alphaIndex).'1'.':'.getAlphabetCell($alphaIndex+1).'1'); + $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 - $alphaIndex = 2; - for($i=1;$i<=13;$i++){ - $sheet->setCellValue(getAlphabetCell($alphaIndex).'2', 'Jadwal'); - $sheet->setCellValue(getAlphabetCell($alphaIndex+1).'2', 'Realisasi'); - $alphaIndex+=2; + $colName = "Realisasi"; + for($i=2;$i<=$colIndex;$i++){ + $colName = $colName == "Jadwal" ? "Realisasi":"Jadwal"; + $sheet->setCellValue(getAlphabetCell($i).'2', $colName); } // Data Kolom Bulan dan Realisasi @@ -229,31 +247,30 @@ class JadwalSalurdanaController extends Controller foreach ($data as $val){ $sheet->setCellValue('A' . $rows, $val["kode_rekening"]); $sheet->setCellValue('B' . $rows, $val["nama_rekening"]); - $alphaIndex = 2; $totalJadwalSalur = 0; $totalRealisasi = 0; + $currIndex = 2; 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; + $sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["spsbulan".$i]); $totalJadwalSalur += $val["spsbulan".$i]; - $totalRealisasi += $val['real'.$i]; + $currIndex++; + $sheet->setCellValue(getAlphabetCell($currIndex).$rows, $val["real".$i]); + $totalRealisasi += $val["real".$i]; + $currIndex++; } - $sheet->setCellValue(getAlphabetCell($alphaIndex).$rows, $totalJadwalSalur); - $sheet->setCellValue(getAlphabetCell($alphaIndex+1).$rows, $totalRealisasi); + $sheet->setCellValue(getAlphabetCell($currIndex).$rows, $totalJadwalSalur); + $sheet->setCellValue(getAlphabetCell($currIndex+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); + for ($x=2;$x<=$colIndex;$x++){ + $strAlpha = getAlphabetCell($x); $SUMRANGE = $strAlpha."3:".$strAlpha.($rows-1); $sheet->setCellValue($strAlpha.$rows , "=SUM($SUMRANGE)"); - $alphaIndex++; } $writer = new Xlsx($spreadsheet); diff --git a/public/js/app.js b/public/js/app.js index 728ee2e..5d15e57 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -391,6 +391,8 @@ if($.fn.dataTable != undefined){ $.extend( $.fn.dataTable.ext.classes, { sProcessing: "dataTables_processing", }); + + $($.fn.dataTable.tables( true )).DataTable().columns.adjust().draw(); } $(window).resize(function(){ diff --git a/resources/views/jadwal_salurdana/index_dak.blade.php b/resources/views/jadwal_salurdana/index_dak.blade.php index df3c1fb..4cf3376 100644 --- a/resources/views/jadwal_salurdana/index_dak.blade.php +++ b/resources/views/jadwal_salurdana/index_dak.blade.php @@ -25,33 +25,31 @@