Perbaikan P1 Remunerasi

This commit is contained in:
Ariyutta
2026-09-01 09:24:16 +07:00
parent 78678752d5
commit 055ab44ef5
13 changed files with 702 additions and 159 deletions
+54 -42
View File
@@ -72,6 +72,8 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
*/
private $cachedCollection;
private array $totals = [];
protected $bulanNames = [
1 => 'Januari',
2 => 'Februari',
@@ -112,7 +114,9 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
private function buildCollection()
{
$data = $this->fetchSelisihData();
$response = $this->fetchSelisihResponse();
$data = $response['data'] ?? [];
$this->totals = $response;
// Sertakan semua pegawai dari endpoint selisih (Kekurangan, Kelebihan, maupun Tidak Ada selisih)
$filteredData = collect($data)->filter(function ($item) {
@@ -168,40 +172,37 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
return $item;
});
// Add total row
if ($sortedData->count() > 0) {
$totalHargaJafung = $sortedData->sum('harga_jafung');
$totalHargaJtt = $sortedData->sum('harga_jtt');
$totalSelisihBruto = $sortedData->sum('selisih_bruto');
$totalSelisihPajak = $sortedData->sum('selisih_pajak');
$totalSelisihNetto = $sortedData->sum('selisih_netto');
for ($spacer = 0; $spacer < 3; $spacer++) {
$sortedData->push((object) ['is_spacer' => true]);
}
$sortedData->push((object) [
'no' => '',
'nip' => '',
'nama_lengkap' => 'TOTAL',
'pangkat' => '',
'golongan' => '',
'nama_jafung' => '',
'grade_jafung' => '',
'harga_jafung' => $totalHargaJafung,
'nama_jtt' => '',
'grade_jtt' => '',
'harga_jtt' => $totalHargaJtt,
'jenis_pegawai' => '',
'selisih_bruto' => $totalSelisihBruto,
'selisih_pajak' => $totalSelisihPajak,
'selisih_netto' => $totalSelisihNetto,
'keterangan' => '',
'npwp' => '',
'nomor_rekening' => '',
'nama_unit' => '',
]);
$summary = [
'Total Kelebihan P1' => 'total_kelebihan_p1',
'Total Kelebihan P1 Setelah Pajak' => 'total_kelebihan_p1_setelah_pajak',
'Total Kekurangan P1' => 'total_kekurangan_p1',
'Total Kekurangan P1 Setelah Pajak' => 'total_kekurangan_p1_setelah_pajak',
];
foreach ($summary as $label => $key) {
$sortedData->push((object) [
'is_summary' => true,
'nama_lengkap' => $label,
'summary_value' => $this->totals[$key] ?? 0,
]);
}
}
return $sortedData;
}
private function fetchSelisihResponse(): array
{
$dawaiService = new DawaiService;
return $dawaiService->getDataP1SelisihResponse($this->jenisPegawai, $this->tahun, $this->bulan, $this->unit);
}
private function fetchSelisihData(): array
{
$dawaiService = new DawaiService;
@@ -266,6 +267,19 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
public function map($row): array
{
if ($row->is_spacer ?? false) {
return array_fill(0, 19, '');
}
if ($row->is_summary ?? false) {
return [
'',
$row->nama_lengkap.':',
$row->summary_value,
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
];
}
return [
$row->no,
$row->nama_lengkap,
@@ -308,7 +322,8 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
public function styles(Worksheet $sheet)
{
$dataCount = $this->collection()->count();
$totalRowNumber = $dataCount + 1; // +1 untuk header
$summaryStartRow = $dataCount - 2;
$accountingFormat = '_("Rp"\ * #,##0.00_);_("Rp"\ * \-#,##0.00_);_("Rp"\ * "-"??_);_(@_)';
$styles = [
// Header row styling
@@ -325,19 +340,16 @@ class P1SelisihMonthlySheet implements FromCollection, ShouldAutoSize, WithColum
],
];
// Total row styling jika ada data
if ($dataCount > 1) { // > 1 karena ada row TOTAL
$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,
],
];
if ($dataCount > 0) {
for ($rowNumber = $summaryStartRow; $rowNumber <= $summaryStartRow + 3; $rowNumber++) {
$styles['B'.$rowNumber] = [
'font' => ['bold' => true],
];
$styles['C'.$rowNumber] = [
'font' => ['bold' => true],
'numberFormat' => ['formatCode' => $accountingFormat],
];
}
}
return $styles;