Download File STS per-TA

This commit is contained in:
Pusdatin BPKD Jkt
2022-12-30 11:45:37 +07:00
parent e9678f40c4
commit 27d1bd4c22
2 changed files with 72 additions and 50 deletions
@@ -205,7 +205,7 @@ class RealisasiPendapatanController extends Controller
$file = $request->file('file_sts'); $file = $request->file('file_sts');
if ($file){ if ($file){
$fileName = $req["rkud_no_sts"].".".$file->getClientOriginalExtension(); $fileName = $req["rkud_no_sts"].".".$file->getClientOriginalExtension();
$tujuan_upload = config('constants.upload_path_sts'); $tujuan_upload = config('constants.upload_path_sts').getTA();
File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true); File::isDirectory($tujuan_upload) or File::makeDirectory($tujuan_upload, 0777, true, true);
$file->move($tujuan_upload, $fileName); $file->move($tujuan_upload, $fileName);
$data["file_sts"] = $fileName; $data["file_sts"] = $fileName;
@@ -231,55 +231,75 @@ class RealisasiPendapatanController extends Controller
public function download(Request $request) public function download(Request $request)
{ {
$post = $request->all(); $post = $request->all();
$sps = isset($post["sps"])?$post["sps"]:""; $sps = isset($post["sps"])?$post["sps"]:"";
$ta = $post["ta"]; $ta = $post["ta"];
$data = PendapatanRealisasi::orderBy("created_at","ASC"); if ($post["export-type"]=="excel")
if (!empty($sps)){ {
$data->where("id_sps",$sps);
$data = PendapatanRealisasi::orderBy("created_at","ASC");
if (!empty($sps)){
$data->where("id_sps",$sps);
}
$fileName = 'Realisasi-pendapatan.xlsx';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(getAlphabetCell(0).'1', 'Uraian');
$sheet->setCellValue(getAlphabetCell(1).'1', 'Kotor');
$sheet->setCellValue(getAlphabetCell(2).'1', 'Potongan');
$sheet->setCellValue(getAlphabetCell(3).'1', 'Bersih');
$sheet->setCellValue(getAlphabetCell(4).'1', 'Retur');
$sheet->setCellValue(getAlphabetCell(5).'1', 'Jumlah Bersih');
$sheet->setCellValue(getAlphabetCell(6).'1', 'SP2D BUN');
$sheet->setCellValue(getAlphabetCell(7).'1', 'TGL SP2D BUN');
$sheet->setCellValue(getAlphabetCell(8).'1', 'TGL STS');
$sheet->setCellValue(getAlphabetCell(9).'1', 'NO STS');
$sheet->setCellValue(getAlphabetCell(10).'1', 'Kode Akun');
$sheet->setCellValue(getAlphabetCell(11).'1', 'Nama Akun');
$sheet->setCellValue(getAlphabetCell(12).'1', 'Jumlah');
$rows = 2;
foreach ($data->get() as $val){
$sheet->setCellValue(getAlphabetCell(0) . $rows, $val["simtrad4_uraian"]);
$sheet->setCellValue(getAlphabetCell(1) . $rows, $val["simtrad4_kotor"]);
$sheet->setCellValue(getAlphabetCell(2) . $rows, $val["simtrad4_potongan"]);
$sheet->setCellValue(getAlphabetCell(3) . $rows, $val["simtrad4_bersih"]);
$sheet->setCellValue(getAlphabetCell(4) . $rows, $val["retur"]);
$sheet->setCellValue(getAlphabetCell(5) . $rows, $val["bersih"]);
$sheet->setCellValue(getAlphabetCell(6) . $rows, $val["simtrad4_sp2d_bun"]);
$sheet->setCellValue(getAlphabetCell(7) . $rows, $val["simtrad4_tgl_sp2d_bun"]);
$sheet->setCellValue(getAlphabetCell(8) . $rows, $val["rkud_tgl"]);
$sheet->setCellValue(getAlphabetCell(9) . $rows, $val["rkud_no_sts"]);
$sheet->setCellValue(getAlphabetCell(10) . $rows, $val["kode_rekening_sps"]);
$sheet->setCellValue(getAlphabetCell(11) . $rows, $val["nama_rekening_sps"]);
$sheet->setCellValue(getAlphabetCell(12) . $rows, $val["rkud_jumlah"]);
$rows++;
}
$writer = new Xlsx($spreadsheet);
$writer->save("downloadFiles/".$fileName);
}else if($post["export-type"]=="all_sts"){
$zip = new \ZipArchive();
$fileName = "STS_ALL_".getTA().".zip";
if ($zip->open(public_path("downloadFiles/".$fileName), \ZipArchive::CREATE)== TRUE)
{
$files = File::files(public_path(config('constants.upload_path_sts').getTA()));
foreach ($files as $key => $value){
$relativeName = basename($value);
$zip->addFile($value, $relativeName);
}
$zip->close();
}
} }
$fileName = 'Realisasi-pendapatan.xlsx';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(getAlphabetCell(0).'1', 'Uraian');
$sheet->setCellValue(getAlphabetCell(1).'1', 'Kotor');
$sheet->setCellValue(getAlphabetCell(2).'1', 'Potongan');
$sheet->setCellValue(getAlphabetCell(3).'1', 'Bersih');
$sheet->setCellValue(getAlphabetCell(4).'1', 'Retur');
$sheet->setCellValue(getAlphabetCell(5).'1', 'Jumlah Bersih');
$sheet->setCellValue(getAlphabetCell(6).'1', 'SP2D BUN');
$sheet->setCellValue(getAlphabetCell(7).'1', 'TGL SP2D BUN');
$sheet->setCellValue(getAlphabetCell(8).'1', 'TGL STS');
$sheet->setCellValue(getAlphabetCell(9).'1', 'NO STS');
$sheet->setCellValue(getAlphabetCell(10).'1', 'Kode Akun');
$sheet->setCellValue(getAlphabetCell(11).'1', 'Nama Akun');
$sheet->setCellValue(getAlphabetCell(12).'1', 'Jumlah');
$rows = 2;
foreach ($data->get() as $val){
$sheet->setCellValue(getAlphabetCell(0) . $rows, $val["simtrad4_uraian"]);
$sheet->setCellValue(getAlphabetCell(1) . $rows, $val["simtrad4_kotor"]);
$sheet->setCellValue(getAlphabetCell(2) . $rows, $val["simtrad4_potongan"]);
$sheet->setCellValue(getAlphabetCell(3) . $rows, $val["simtrad4_bersih"]);
$sheet->setCellValue(getAlphabetCell(4) . $rows, $val["retur"]);
$sheet->setCellValue(getAlphabetCell(5) . $rows, $val["bersih"]);
$sheet->setCellValue(getAlphabetCell(6) . $rows, $val["simtrad4_sp2d_bun"]);
$sheet->setCellValue(getAlphabetCell(7) . $rows, $val["simtrad4_tgl_sp2d_bun"]);
$sheet->setCellValue(getAlphabetCell(8) . $rows, $val["rkud_tgl"]);
$sheet->setCellValue(getAlphabetCell(9) . $rows, $val["rkud_no_sts"]);
$sheet->setCellValue(getAlphabetCell(10) . $rows, $val["kode_rekening_sps"]);
$sheet->setCellValue(getAlphabetCell(11) . $rows, $val["nama_rekening_sps"]);
$sheet->setCellValue(getAlphabetCell(12) . $rows, $val["rkud_jumlah"]);
$rows++;
}
$writer = new Xlsx($spreadsheet);
$writer->save("downloadFiles/".$fileName);
$headers = [ $headers = [
'Content-Type' => 'application/vnd.ms-excel', 'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'attachment;filename='.$fileName 'Content-Disposition' => 'attachment;filename='.$fileName
]; ];
return response()->download("downloadFiles/".$fileName, $fileName, $headers); return response()->download("downloadFiles/".$fileName, $fileName, $headers);
} }
@@ -289,6 +309,7 @@ class RealisasiPendapatanController extends Controller
'Content-Type' => 'application/pdf', 'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment;filename='.$realisasi->file_sts 'Content-Disposition' => 'attachment;filename='.$realisasi->file_sts
]; ];
return response()->download(config('constants.upload_path_sts').$realisasi->file_sts, $realisasi->file_sts, $headers); return response()->download(config('constants.upload_path_sts').getTA()."/".$realisasi->file_sts, $realisasi->file_sts, $headers);
} }
} }
@@ -32,6 +32,7 @@
<div class="col-1"> <div class="col-1">
<div class="form-group"> <div class="form-group">
<label>Periode</label> <label>Periode</label>
<input type="hidden" id="export-type">
<input class="form-control form-control-sm" id="srcTA" name="ta" value="{{ getTA() }}" readonly> <input class="form-control form-control-sm" id="srcTA" name="ta" value="{{ getTA() }}" readonly>
</div> </div>
</div> </div>
@@ -210,14 +211,14 @@
extype: "excel" extype: "excel"
} }
}, },
// { {
// text: "<i class=\'fas fa-file-pdf\'></i> Pdf", text: "<i class=\'fas fa-file-archive\'></i> File(s) STS",
// className: "export-data link-pdf", className: "export-data",
// attr: { attr: {
// formid: "frm_proses_spm_sp2d", formid: "frmRealisasi",
// extype: "pdf" extype: "all_sts"
// } }
// } }
], ],
} }
], ],