<h3 style="text-align: center;"><?php echo strtoupper($nama) ?></h3>
<h4></h4>
<table width="100%" style="border-collapse:collapse;" border="1">
    <tr>
        <?php
            $numrow = 1;
            if (count($master['pendapatan']) > 0 || count($master['potongan']) > 0) {
                $numrow = 2;
            }
        ?>
        <td rowspan="<?= $numrow ?>" style="text-align: center;" width="30">NO</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;" width="100">NIK</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;">NAMA KARYAWAN</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;">CABANG</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;">DEPARTEMEN</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;">JABATAN</td>
        <td rowspan="<?= $numrow ?>" style="text-align: center;">GAPOK</td>
        <?php
            if (count($master['pendapatan']) > 0) {
                echo '<td colspan="'.count($master['pendapatan']).'" style="text-align: center;">PENDAPATAN</td>';
            }
            if (count($master['potongan']) > 0) {
                echo '<td colspan="'.count($master['potongan']).'" style="text-align: center;">POTONGAN</td>';
            }
        ?>
    </tr>
    <?php
    if (count($master['pendapatan']) > 0 || count($master['potongan']) > 0) {
        echo '<tr>';
        if (count($master['pendapatan']) > 0) {
            foreach ($master['pendapatan'] as $komponen) {
                echo '<td style="text-align: center;">'.$komponen['nm_komponen'].(($komponen['flag_persentase_gapok'] == '1') ? ' ('.$komponen['gapok_persen'].'%)' : '').'</td>';
            }
        }
        if (count($master['potongan']) > 0) {
            foreach ($master['potongan'] as $komponen) {
                echo '<td style="text-align: center;">'.$komponen['nm_komponen'].(($komponen['flag_persentase_gapok'] == '1') ? ' ('.$komponen['gapok_persen'].'%)' : '').'</td>';
            }
        }
        echo '</tr>';
    }
    ?>
    <?php
    $no = 1;
    foreach ($data as $row) {
    ?>
        <tr>
            <td style="text-align: center;"><?= $no; ?></td>
            <td><?= "#".$row->nik."#"; ?></td>
            <td><?= $row->nama_lengkap; ?></td>
            <td><?= $row->kode_cabang." - ".$row->nama_cabang; ?></td>
            <td><?= $row->kode_departemen." - ".$row->nama_departemen; ?></td>
            <td><?= $row->kode_jabatan." - ".$row->nama_jabatan; ?></td>
            <td style="text-align: right"><?= $row->nominal; ?></td>
            <?php
            if (count($master['pendapatan']) > 0) {
                foreach ($pendapatan[$row->id_karyawan] as $komponen) {
                    echo '<td style="text-align: right">'.$komponen['nominal_tunjangan'].'</td>';
                }
            }
            if (count($master['potongan']) > 0) {
                foreach ($potongan[$row->id_karyawan] as $komponen) {
                    echo '<td style="text-align: right">'.$komponen['nominal_potongan'].'</td>';
                }
            }
            ?>
        </tr>
    <?php
        $no++;
    }
    ?>
</table>
