Download Jadwal Salur

This commit is contained in:
Pusdatin BPKD Jkt
2022-08-05 11:31:57 +07:00
parent d981418604
commit 1e877fa951
3 changed files with 95 additions and 54 deletions
@@ -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);