update
This commit is contained in:
@@ -8,6 +8,8 @@ use App\XFiles;
|
|||||||
use App\SIMBHPJenis;
|
use App\SIMBHPJenis;
|
||||||
use App\SIMBHPReport;
|
use App\SIMBHPReport;
|
||||||
use App\User;
|
use App\User;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
use Validator;
|
use Validator;
|
||||||
use Session;
|
use Session;
|
||||||
|
|
||||||
@@ -161,33 +163,44 @@ class GudangController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rows = $query->orderBy('id', 'DESC')->get();
|
$rows = $query->orderBy('id', 'DESC')->get();
|
||||||
$filename = 'laporan-gudang-bln-'.$bulan.'_thn-'.$tahun.'.csv';
|
$filename = 'laporan-gudang-bln-'.$bulan.'_thn-'.$tahun.'.xlsx';
|
||||||
$headers = [
|
|
||||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
|
||||||
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
|
|
||||||
];
|
|
||||||
|
|
||||||
$callback = function () use ($rows) {
|
return response()->streamDownload(function () use ($rows) {
|
||||||
$file = fopen('php://output', 'w');
|
$spreadsheet = new Spreadsheet();
|
||||||
fputcsv($file, ['Tanggal', 'Bulan', 'Tahun', 'Jenis', 'Deskripsi', 'Pemasukan', 'Pengeluaran', 'Satuan Transaksi', 'Masa Expired', 'Keterangan']);
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$sheet->setTitle('Laporan Gudang');
|
||||||
|
|
||||||
|
$headers = ['Tanggal', 'Bulan', 'Tahun', 'Jenis', 'Deskripsi', 'Pemasukan', 'Pengeluaran', 'Satuan Transaksi', 'Masa Expired', 'Keterangan'];
|
||||||
|
$sheet->fromArray($headers, null, 'A1');
|
||||||
|
|
||||||
|
$rowNumber = 2;
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
fputcsv($file, [
|
$sheet->fromArray([
|
||||||
$row->tanggal,
|
(int) ($row->tanggal ?? 0),
|
||||||
$row->bulan,
|
(int) ($row->bulan ?? 0),
|
||||||
$row->tahun,
|
(int) ($row->tahun ?? 0),
|
||||||
$row->jenis,
|
$row->jenis ?: '-',
|
||||||
$row->deskripsi,
|
$row->deskripsi ?: '-',
|
||||||
(int) ($row->pemasukan ?? 0),
|
(int) ($row->pemasukan ?? 0),
|
||||||
(int) ($row->pengeluaran ?? 0),
|
(int) ($row->pengeluaran ?? 0),
|
||||||
$row->satuan_transaksi ?: '-',
|
$row->satuan_transaksi ?: '-',
|
||||||
$row->masa_expired ?: '-',
|
$row->masa_expired ?: '-',
|
||||||
$row->keterangan ?: '-',
|
$row->keterangan ?: '-',
|
||||||
]);
|
], null, 'A'.$rowNumber);
|
||||||
|
$rowNumber++;
|
||||||
}
|
}
|
||||||
fclose($file);
|
|
||||||
};
|
|
||||||
|
|
||||||
return response()->stream($callback, 200, $headers);
|
foreach (range('A', 'J') as $col) {
|
||||||
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
$writer->save('php://output');
|
||||||
|
$spreadsheet->disconnectWorksheets();
|
||||||
|
unset($spreadsheet);
|
||||||
|
}, $filename, [
|
||||||
|
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonReportbhpPaginated(Request $request) {
|
public function jsonReportbhpPaginated(Request $request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user