184 lines
5.8 KiB
PHP
184 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\Verifikator\Rekapitulasi;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
|
|
class TotalRemunerasiExport implements FromCollection, WithHeadings, WithMapping, WithColumnFormatting, WithStyles, ShouldAutoSize, WithTitle
|
|
{
|
|
protected int $tahun;
|
|
|
|
public function __construct(int $tahun)
|
|
{
|
|
$this->tahun = $tahun;
|
|
}
|
|
|
|
public function title(): string
|
|
{
|
|
return 'Total Remunerasi '.$this->tahun;
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
$data = Rekapitulasi::where('tahun', $this->tahun)
|
|
->orderBy('id', 'ASC')
|
|
->get()
|
|
->map(function ($item, $index) {
|
|
$totalP2Smt1 = (float) ($item->total_p2 ?? 0);
|
|
$totalP2Smt2 = (float) ($item->total_p2_smt2 ?? 0);
|
|
$totalPublikasiSmt1 = (float) ($item->total_publikasi ?? 0);
|
|
$totalPublikasiSmt2 = (float) ($item->total_publikasi_smt2 ?? 0);
|
|
|
|
$total = (float) ($item->total_p1 ?? 0) +
|
|
(float) ($item->total_thr ?? 0) +
|
|
(float) ($item->total_r13 ?? 0) +
|
|
$totalP2Smt1 +
|
|
$totalP2Smt2 +
|
|
$totalPublikasiSmt1 +
|
|
$totalPublikasiSmt2;
|
|
|
|
return (object) [
|
|
'no' => $index + 1,
|
|
'unit_kerja' => $item->unit_kerja_nama,
|
|
'total_p1' => $item->total_p1 ?? 0,
|
|
'total_thr' => $item->total_thr ?? 0,
|
|
'total_r13' => $item->total_r13 ?? 0,
|
|
'total_p2_smt1' => $totalP2Smt1,
|
|
'total_p2_smt2' => $totalP2Smt2,
|
|
'total_publikasi_smt1' => $totalPublikasiSmt1,
|
|
'total_publikasi_smt2' => $totalPublikasiSmt2,
|
|
'total' => $total,
|
|
];
|
|
});
|
|
|
|
$totals = $data->reduce(function ($carry, $item) {
|
|
$carry['total_p1'] += $item->total_p1;
|
|
$carry['total_thr'] += $item->total_thr;
|
|
$carry['total_r13'] += $item->total_r13;
|
|
$carry['total_p2_smt1'] += $item->total_p2_smt1;
|
|
$carry['total_p2_smt2'] += $item->total_p2_smt2;
|
|
$carry['total_publikasi_smt1'] += $item->total_publikasi_smt1;
|
|
$carry['total_publikasi_smt2'] += $item->total_publikasi_smt2;
|
|
$carry['total'] += $item->total;
|
|
|
|
return $carry;
|
|
}, [
|
|
'total_p1' => 0,
|
|
'total_thr' => 0,
|
|
'total_r13' => 0,
|
|
'total_p2_smt1' => 0,
|
|
'total_p2_smt2' => 0,
|
|
'total_publikasi_smt1' => 0,
|
|
'total_publikasi_smt2' => 0,
|
|
'total' => 0,
|
|
]);
|
|
|
|
$data->push((object) [
|
|
'no' => '',
|
|
'unit_kerja' => 'TOTAL',
|
|
'total_p1' => $totals['total_p1'],
|
|
'total_thr' => $totals['total_thr'],
|
|
'total_r13' => $totals['total_r13'],
|
|
'total_p2_smt1' => $totals['total_p2_smt1'],
|
|
'total_p2_smt2' => $totals['total_p2_smt2'],
|
|
'total_publikasi_smt1' => $totals['total_publikasi_smt1'],
|
|
'total_publikasi_smt2' => $totals['total_publikasi_smt2'],
|
|
'total' => $totals['total'],
|
|
]);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'No',
|
|
'Unit Kerja',
|
|
'P1',
|
|
'THR',
|
|
'R13',
|
|
'P2 Semester 1',
|
|
'P2 Semester 2',
|
|
'Publikasi Semester 1',
|
|
'Publikasi Semester 2',
|
|
'Total Remunerasi',
|
|
];
|
|
}
|
|
|
|
public function map($row): array
|
|
{
|
|
return [
|
|
$row->no,
|
|
$row->unit_kerja,
|
|
$row->total_p1,
|
|
$row->total_thr,
|
|
$row->total_r13,
|
|
$row->total_p2_smt1,
|
|
$row->total_p2_smt2,
|
|
$row->total_publikasi_smt1,
|
|
$row->total_publikasi_smt2,
|
|
$row->total,
|
|
];
|
|
}
|
|
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'C' => '#,##0',
|
|
'D' => '#,##0',
|
|
'E' => '#,##0',
|
|
'F' => '#,##0',
|
|
'G' => '#,##0',
|
|
'H' => '#,##0',
|
|
'I' => '#,##0',
|
|
'J' => '#,##0',
|
|
];
|
|
}
|
|
|
|
public function styles(Worksheet $sheet): array
|
|
{
|
|
$dataCount = $this->collection()->count();
|
|
$totalRowNumber = $dataCount + 1;
|
|
|
|
$styles = [
|
|
1 => [
|
|
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
|
'fill' => [
|
|
'fillType' => Fill::FILL_SOLID,
|
|
'startColor' => ['rgb' => '4472C4'],
|
|
],
|
|
'alignment' => [
|
|
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
|
'vertical' => Alignment::VERTICAL_CENTER,
|
|
],
|
|
],
|
|
];
|
|
|
|
if ($dataCount > 1) {
|
|
$styles[$totalRowNumber] = [
|
|
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
|
'fill' => [
|
|
'fillType' => Fill::FILL_SOLID,
|
|
'startColor' => ['rgb' => '70AD47'],
|
|
],
|
|
'alignment' => [
|
|
'horizontal' => Alignment::HORIZONTAL_RIGHT,
|
|
'vertical' => Alignment::VERTICAL_CENTER,
|
|
],
|
|
];
|
|
}
|
|
|
|
return $styles;
|
|
}
|
|
}
|