diff --git a/app/Exports/Concerns/ForcesTextColumns.php b/app/Exports/Concerns/ForcesTextColumns.php new file mode 100644 index 00000000..f1523dee --- /dev/null +++ b/app/Exports/Concerns/ForcesTextColumns.php @@ -0,0 +1,54 @@ +getColumn(); + + $isNipValue = in_array($column, $this->nipColumns(), true) + && is_string($value) && strlen($value) >= 15 && ctype_digit($value); + + if (($isNipValue || in_array($column, $this->alwaysTextColumns(), true)) && $value !== '') { + $cell->setValueExplicit((string) $value, DataType::TYPE_STRING); + + return true; + } + + return (new DefaultValueBinder)->bindValue($cell, $value); + } +} diff --git a/app/Exports/DetailTotalRemunerasiExport.php b/app/Exports/DetailTotalRemunerasiExport.php index a1f7e363..e11aa4a3 100644 --- a/app/Exports/DetailTotalRemunerasiExport.php +++ b/app/Exports/DetailTotalRemunerasiExport.php @@ -2,6 +2,7 @@ namespace App\Exports; +use App\Exports\Concerns\ForcesTextColumns; use App\Models\Rekapitulasi\P1; use App\Models\Rekapitulasi\R13; use App\Models\Rekapitulasi\THR; @@ -11,6 +12,7 @@ use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithMultipleSheets; @@ -33,8 +35,15 @@ class DetailTotalRemunerasiExport implements WithMultipleSheets } } -class DetailTotalRemunerasiSheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle +class DetailTotalRemunerasiSheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles, WithTitle { + use ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + protected array $bulanNamas = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', @@ -124,7 +133,7 @@ class DetailTotalRemunerasiSheet implements FromCollection, ShouldAutoSize, With return [ $row['no'], $row['nama'], - $row['nip'] !== '' ? "'".$row['nip'] : '', + $row['nip'], $row['pangkat'], $row['golongan'], $row['jabatan_fungsional'], diff --git a/app/Exports/P1Export.php b/app/Exports/P1Export.php index fd7fa9a6..6507fb91 100644 --- a/app/Exports/P1Export.php +++ b/app/Exports/P1Export.php @@ -3,11 +3,13 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Models\Rekapitulasi\P1; use Carbon\Carbon; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithMultipleSheets; @@ -52,9 +54,19 @@ class P1Export implements WithMultipleSheets } } -class P1MonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle +class P1MonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles, WithTitle { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } protected $jenisPegawai; @@ -130,7 +142,7 @@ class P1MonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormat return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => "'".$pegawai->nip, + 'nip' => $pegawai->nip, 'nama_lengkap' => $pegawai->nama, 'pangkat' => $pegawai->pangkat, 'golongan' => $pegawai->golongan, @@ -145,8 +157,8 @@ class P1MonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormat 'harga_p1' => $pegawai->gaji_yang_dibayarkan, 'pajak_p1' => $pegawai->pph21, 'harga_p1_setelah_pajak' => $pegawai->gaji_bersih, - 'npwp' => $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai->nomor_rekening ?: '', ]; }); diff --git a/app/Exports/P1PerbandinganExport.php b/app/Exports/P1PerbandinganExport.php index 3c88ca35..989b5901 100644 --- a/app/Exports/P1PerbandinganExport.php +++ b/app/Exports/P1PerbandinganExport.php @@ -2,11 +2,13 @@ namespace App\Exports; +use App\Exports\Concerns\ForcesTextColumns; use App\Models\Rekapitulasi\P1; use Carbon\Carbon; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithMultipleSheets; @@ -50,8 +52,20 @@ class P1PerbandinganExport implements WithMultipleSheets } } -class P1PerbandinganMonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle +class P1PerbandinganMonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles, WithTitle { + use ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['Q', 'R']; + } + protected $jenisPegawai; protected $tahun; @@ -153,7 +167,7 @@ class P1PerbandinganMonthlySheet implements FromCollection, ShouldAutoSize, With return (object) [ 'no' => 0, - 'nip' => "'".$cleanNip, + 'nip' => $cleanNip, 'nama_lengkap' => $acuan->nama ?? '-', 'pangkat' => $acuan->pangkat ?? '-', 'golongan' => $acuan->golongan ?? '-', @@ -168,8 +182,8 @@ class P1PerbandinganMonthlySheet implements FromCollection, ShouldAutoSize, With 'selisih_pajak' => $selisihPajak, 'selisih_netto' => $selisihNetto, 'keterangan' => $this->keteranganLabel($selisihNetto), - 'npwp' => $acuan->npwp ? "'".str_replace(['-', '.'], '', $acuan->npwp) : '', - 'nomor_rekening' => $acuan->nomor_rekening ? "'".$acuan->nomor_rekening : '', + 'npwp' => $acuan->npwp ? str_replace(['-', '.'], '', $acuan->npwp) : '', + 'nomor_rekening' => $acuan->nomor_rekening ? $acuan->nomor_rekening : '', 'nama_unit' => $acuan->nama_unit_kerja ?? '-', ]; })->filter(function ($row) { diff --git a/app/Exports/P1SelisihExport.php b/app/Exports/P1SelisihExport.php index 35a9da7f..f81f35b0 100644 --- a/app/Exports/P1SelisihExport.php +++ b/app/Exports/P1SelisihExport.php @@ -3,11 +3,13 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Services\DawaiService; use Carbon\Carbon; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithMultipleSheets; @@ -52,9 +54,19 @@ class P1SelisihExport implements WithMultipleSheets } } -class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle +class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles, WithTitle { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['Q', 'R']; + } protected $jenisPegawai; @@ -141,7 +153,7 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => $item['nip'], // Keep original NIP with quotes + 'nip' => $cleanNip, 'nama_lengkap' => $item['nama_lengkap'], 'pangkat' => $pangkat, 'golongan' => $golongan, @@ -156,8 +168,8 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum 'selisih_pajak' => ($item['selisih_harga_p1'] ?? 0) - ($item['selisih_harga_p1_setelah_pajak'] ?? 0), 'selisih_netto' => $item['selisih_harga_p1_setelah_pajak'] ?? 0, 'keterangan' => $this->jenisSelisihLabel($item), - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', 'nama_unit' => $item['nama_unit'], ]; }); diff --git a/app/Exports/P2Export.php b/app/Exports/P2Export.php index eddbe9e0..615e2b16 100644 --- a/app/Exports/P2Export.php +++ b/app/Exports/P2Export.php @@ -2,6 +2,7 @@ namespace App\Exports; +use App\Exports\Concerns\ForcesTextColumns; use App\Helpers\JenjangPendidikanHelper; use App\Models\Verifikator\JabatanFungsionalRiwayat; use App\Models\Verifikator\JabatanPegawai; @@ -11,6 +12,7 @@ use App\Models\Verifikator\View\Pegawai; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithStyles; @@ -19,10 +21,22 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles, WithTitle +class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles, WithTitle { + use ForcesTextColumns; + private const FAKULTAS_IDS = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } + public function __construct( private readonly ?int $periode, private readonly mixed $unitKerjaId, @@ -153,7 +167,7 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, return (object) [ 'no' => $index + 1, 'nama' => $row->nama, - 'nip' => $row->nip ? "'".$cleanNip : '', + 'nip' => $row->nip ? $cleanNip : '', 'pangkat' => $pangkat, 'golongan' => $golongan, 'nama_jafung' => $namaJafung, @@ -166,8 +180,8 @@ class P2Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, 'total_p2_bruto' => $row->total_p2_bruto ?? 0, 'total_p2_pajak' => $row->total_p2_pajak ?? 0, 'total_p2_netto' => $row->total_p2_netto ?? 0, - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', 'nama_unit' => $row->nama_unit ?? '', ]; }); diff --git a/app/Exports/R13Export.php b/app/Exports/R13Export.php index fe6976ed..6554482e 100644 --- a/app/Exports/R13Export.php +++ b/app/Exports/R13Export.php @@ -3,10 +3,12 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Services\DawaiService; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithStyles; @@ -14,9 +16,19 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class R13Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles +class R13Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } protected $jenisPegawai; @@ -55,7 +67,7 @@ class R13Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => $item['nip'] ? "'".trim($item['nip'], "'") : '', + 'nip' => $item['nip'] ? trim($item['nip'], "'") : '', 'nama' => $item['nama'] ?? $item['nama_lengkap'] ?? '', 'pangkat' => $pangkat, 'golongan' => $golongan, @@ -69,8 +81,8 @@ class R13Export implements FromCollection, ShouldAutoSize, WithColumnFormatting, 'gaji_r13' => $totalR13, 'pajak_r13' => $totalR13 - $totalR13SetelahPajak, 'gaji_r13_bersih' => $totalR13SetelahPajak, - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', 'nama_unit' => $item['nama_unit'] ?? '', ]; }); diff --git a/app/Exports/R13SelisihExport.php b/app/Exports/R13SelisihExport.php index 502503a8..b8608b76 100644 --- a/app/Exports/R13SelisihExport.php +++ b/app/Exports/R13SelisihExport.php @@ -3,10 +3,12 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Services\DawaiService; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithStyles; @@ -14,9 +16,19 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class R13SelisihExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles +class R13SelisihExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } protected $jenisPegawai; @@ -54,7 +66,7 @@ class R13SelisihExport implements FromCollection, ShouldAutoSize, WithColumnForm return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => $item['nip'] ? "'".trim($item['nip'], "'") : '', + 'nip' => $item['nip'] ? trim($item['nip'], "'") : '', 'nama' => $item['nama'] ?? $item['nama_lengkap'] ?? '', 'pangkat' => $pangkat, 'golongan' => $golongan, @@ -69,8 +81,8 @@ class R13SelisihExport implements FromCollection, ShouldAutoSize, WithColumnForm 'selisih_pajak' => $selisihBruto - $selisihNetto, 'selisih_netto' => $selisihNetto, 'keterangan' => $this->keteranganLabel($selisihBruto, $selisihNetto), - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', 'nama_unit' => $item['nama_unit'] ?? '', ]; }); diff --git a/app/Exports/RasioPoinKegiatanExport.php b/app/Exports/RasioPoinKegiatanExport.php index eb51ab4c..34a6f370 100644 --- a/app/Exports/RasioPoinKegiatanExport.php +++ b/app/Exports/RasioPoinKegiatanExport.php @@ -7,6 +7,7 @@ use App\Models\Verifikator\Periode; use App\Models\Verifikator\Team; use App\Models\Verifikator\View\Pegawai; use Illuminate\Support\Facades\Auth; +use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Border; @@ -56,6 +57,9 @@ class RasioPoinKegiatanExport $sheet->setCellValue($cell, $header); } + // Kolom NIP Anggota sebagai teks, supaya NIP panjang tidak dibulatkan jadi notasi ilmiah + $sheet->getStyle('E:E')->getNumberFormat()->setFormatCode('@'); + // Style headers $headerRange = 'A1:N1'; $sheet->getStyle($headerRange)->applyFromArray([ @@ -146,7 +150,7 @@ class RasioPoinKegiatanExport } // Set data anggota - $sheet->setCellValue('E' . $row, "'" . $item['nip_anggota']); // Add quote to NIP + $sheet->setCellValueExplicit('E' . $row, (string) $item['nip_anggota'], DataType::TYPE_STRING); $sheet->setCellValue('F' . $row, $item['nama_anggota']); $sheet->setCellValue('G' . $row, $item['unit_kerja_anggota']); $sheet->setCellValue('H' . $row, $item['posisi']); diff --git a/app/Exports/SimulasiJabatanExport.php b/app/Exports/SimulasiJabatanExport.php index 7c9a35ae..4474732c 100644 --- a/app/Exports/SimulasiJabatanExport.php +++ b/app/Exports/SimulasiJabatanExport.php @@ -2,6 +2,7 @@ namespace App\Exports; +use App\Exports\Concerns\ForcesTextColumns; use App\Helpers\JenjangPendidikanHelper; use App\Models\Verifikator\JabatanFungsionalRiwayat; use App\Models\Verifikator\JabatanPegawaiDetail; @@ -11,6 +12,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMultipleSheets; use Maatwebsite\Excel\Concerns\WithColumnFormatting; @@ -68,8 +70,15 @@ class SimulasiJabatanExport implements WithMultipleSheets } } -class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize, WithTitle, WithColumnFormatting +class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize, WithTitle, WithColumnFormatting, WithCustomValueBinder { + use ForcesTextColumns; + + protected function nipColumns(): array + { + return ['B']; + } + public function __construct(private readonly string $sheetTitle, private readonly Collection $items) {} public static function rows(int $periode, ?int $bulan = null, int|string|null $unitKerjaId = null, ?string $jenis = null, bool $raw = false, bool $grade12 = false, bool $splitUnit = false, ?string $jenjangPendidikan = null): Collection @@ -276,7 +285,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles, } } - $out = ['nama_pegawai'=>$r->nama_pegawai,'nip'=>"'".$r->nip,'unit_kerja'=>$r->unit_kerja ?: 'Tanpa Unit Kerja','jenis_pegawai'=>strtoupper($r->jenis_pegawai),'poin_jf'=>round($jf,2),'nama_jf'=>$d?->fungsional?->nama ?? '-','grade_jf'=>$jfPrices->get(($d?->jabatan_fungsional_id).'-377')?->grade ?? '-','harga_jf_374'=>$jf374,'p2_jf_374'=>$p2jf374,'total_p2_jf_374'=>$p2jf374*$months,'harga_jf_377'=>$jf377,'p2_jf_377'=>$p2jf377,'total_p2_jf_377'=>$p2jf377*$months,'harga_jf_excel'=>$jfExcel,'p2_jf_excel'=>$p2jfExcel,'total_p2_jf_excel'=>$p2jfExcel*$months,'poin_jtt'=>round($jtt,2),'nama_jtt'=>$d?->tambahan?->nama ?? '-','grade_jtt'=>$jttPrices->get(($d?->jabatan_tambahan_id).'-377')?->grade ?? '-','harga_jtt_374'=>$jtt374,'p2_jtt_374'=>$p2jtt374,'total_p2_jtt_374'=>$p2jtt374*$months,'harga_jtt_377'=>$jtt377,'p2_jtt_377'=>$p2jtt377,'total_p2_jtt_377'=>$p2jtt377*$months,'harga_jtt_excel'=>$jttExcel,'p2_jtt_excel'=>$p2jttExcel,'total_p2_jtt_excel'=>$p2jttExcel*$months]; + $out = ['nama_pegawai'=>$r->nama_pegawai,'nip'=>$r->nip,'unit_kerja'=>$r->unit_kerja ?: 'Tanpa Unit Kerja','jenis_pegawai'=>strtoupper($r->jenis_pegawai),'poin_jf'=>round($jf,2),'nama_jf'=>$d?->fungsional?->nama ?? '-','grade_jf'=>$jfPrices->get(($d?->jabatan_fungsional_id).'-377')?->grade ?? '-','harga_jf_374'=>$jf374,'p2_jf_374'=>$p2jf374,'total_p2_jf_374'=>$p2jf374*$months,'harga_jf_377'=>$jf377,'p2_jf_377'=>$p2jf377,'total_p2_jf_377'=>$p2jf377*$months,'harga_jf_excel'=>$jfExcel,'p2_jf_excel'=>$p2jfExcel,'total_p2_jf_excel'=>$p2jfExcel*$months,'poin_jtt'=>round($jtt,2),'nama_jtt'=>$d?->tambahan?->nama ?? '-','grade_jtt'=>$jttPrices->get(($d?->jabatan_tambahan_id).'-377')?->grade ?? '-','harga_jtt_374'=>$jtt374,'p2_jtt_374'=>$p2jtt374,'total_p2_jtt_374'=>$p2jtt374*$months,'harga_jtt_377'=>$jtt377,'p2_jtt_377'=>$p2jtt377,'total_p2_jtt_377'=>$p2jtt377*$months,'harga_jtt_excel'=>$jttExcel,'p2_jtt_excel'=>$p2jttExcel,'total_p2_jtt_excel'=>$p2jttExcel*$months]; // Field mentah hanya untuk konsumen non-Excel (mis. tabel Simulasi Jabatan). // Jangan sertakan pada sheet ekspor karena akan menambah kolom. if ($raw) { @@ -344,7 +353,7 @@ class SimulasiJabatanSheet implements FromCollection, WithHeadings, WithStyles, public function headings(): array { return ['Nama Pegawai','NIP','Unit Kerja','Jenis Pegawai','Poin P2 JF','Nama JF','Grade JF','Harga JF (374)','P2 JF (374)','Total P2 JF (374)','Harga JF (377)','P2 JF (377)','Total P2 JF (377)','Harga JF (Excel)','P2 JF (Excel)','Total P2 JF (Excel)','Poin P2 JTT','Nama JTT','Grade JTT','Harga JTT (374)','P2 JTT (374)','Total P2 JTT (374)','Harga JTT (377)','P2 JTT (377)','Total P2 JTT (377)','Harga JTT (Excel)','P2 JTT (Excel)','Total P2 JTT (Excel)']; } public function columnFormats(): array { - return array_fill_keys(['H','I','J','K','L','M','N','O','P','T','U','V','W','X','Y','Z','AA','AB'], '_([$Rp-421]* #,##0.00_);_([$Rp-421]* (#,##0.00);_([$Rp-421]* "-"??_);_(@_)'); + return ['B' => '@'] + array_fill_keys(['H','I','J','K','L','M','N','O','P','T','U','V','W','X','Y','Z','AA','AB'], '_([$Rp-421]* #,##0.00_);_([$Rp-421]* (#,##0.00);_([$Rp-421]* "-"??_);_(@_)'); } public function title(): string { return mb_substr(str_replace(['\\', '/', '*', '?', ':', '[', ']'], '-', $this->sheetTitle), 0, 31); } public function styles(Worksheet $sheet) { return [1=>['font'=>['bold'=>true,'color'=>['rgb'=>'FFFFFF']], 'fill'=>['fillType'=>Fill::FILL_SOLID,'startColor'=>['rgb'=>'20C997']]], $sheet->getHighestRow()=>['font'=>['bold'=>true]]]; } diff --git a/app/Exports/ThrExport.php b/app/Exports/ThrExport.php index 9f9d4238..15b3f3c4 100644 --- a/app/Exports/ThrExport.php +++ b/app/Exports/ThrExport.php @@ -3,10 +3,12 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Services\DawaiService; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithStyles; @@ -14,9 +16,19 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class ThrExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles +class ThrExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } protected $jenisPegawai; @@ -55,7 +67,7 @@ class ThrExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => $item['nip'] ? "'".trim($item['nip'], "'") : '', + 'nip' => $item['nip'] ? trim($item['nip'], "'") : '', 'nama' => $item['nama'] ?? $item['nama_lengkap'] ?? '', 'pangkat' => $pangkat, 'golongan' => $golongan, @@ -70,8 +82,8 @@ class ThrExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, 'gaji_thr' => $totalThr, 'pajak_thr' => $totalThr - $totalThrSetelahPajak, 'gaji_thr_bersih' => $totalThrSetelahPajak, - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', ]; }); diff --git a/app/Exports/ThrSelisihExport.php b/app/Exports/ThrSelisihExport.php index 4aa9c0c7..15ea74ea 100644 --- a/app/Exports/ThrSelisihExport.php +++ b/app/Exports/ThrSelisihExport.php @@ -3,10 +3,12 @@ namespace App\Exports; use App\Exports\Concerns\EnrichesJabatanData; +use App\Exports\Concerns\ForcesTextColumns; use App\Services\DawaiService; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnFormatting; +use Maatwebsite\Excel\Concerns\WithCustomValueBinder; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithStyles; @@ -14,9 +16,19 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -class ThrSelisihExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles +class ThrSelisihExport implements FromCollection, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping, WithStyles { - use EnrichesJabatanData; + use EnrichesJabatanData, ForcesTextColumns; + + protected function nipColumns(): array + { + return ['C']; + } + + protected function alwaysTextColumns(): array + { + return ['P', 'Q']; + } protected $jenisPegawai; @@ -54,7 +66,7 @@ class ThrSelisihExport implements FromCollection, ShouldAutoSize, WithColumnForm return (object) [ 'no' => 0, // Temporary, will be set after sorting - 'nip' => $item['nip'] ? "'".trim($item['nip'], "'") : '', + 'nip' => $item['nip'] ? trim($item['nip'], "'") : '', 'nama' => $item['nama'] ?? $item['nama_lengkap'] ?? '', 'pangkat' => $pangkat, 'golongan' => $golongan, @@ -69,8 +81,8 @@ class ThrSelisihExport implements FromCollection, ShouldAutoSize, WithColumnForm 'selisih_pajak' => $selisihBruto - $selisihNetto, 'selisih_netto' => $selisihNetto, 'keterangan' => $this->keteranganLabel($selisihBruto, $selisihNetto), - 'npwp' => $pegawai && $pegawai->npwp ? "'".str_replace(['-', '.'], '', $pegawai->npwp) : '', - 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? "'".$pegawai->nomor_rekening : '', + 'npwp' => $pegawai && $pegawai->npwp ? str_replace(['-', '.'], '', $pegawai->npwp) : '', + 'nomor_rekening' => $pegawai && $pegawai->nomor_rekening ? $pegawai->nomor_rekening : '', 'nama_unit' => $item['nama_unit'] ?? '', ]; });