<h3 style="text-align: center;">LAPORAN PIPELINE</h3>
<h4 style="text-align: center;"><?= strtoupper($periode) ?></h4>
<h4></h4>
<table width="100%" style="border-collapse:collapse;" border="1">
    <!-- HEADER -->
    <tr>
        <td rowspan="2">NO</td>
        <td rowspan="2">NIK</td>
        <td rowspan="2">NAMA KARYAWAN</td>
        <?php
            if(COUNT($tahapan_trx) > 0){
                foreach($tahapan_trx AS $tahapan){
                    echo '<th colspan="2" class="text-center text-uppercase">'.$tahapan->nama.'</th>';
                }
            }else{
                echo '<th colspan="2" class="text-center text-uppercase">-</th>';
            }
        ?>
    </tr>
    <tr>
        <?php
            if(COUNT($tahapan_trx) > 0){
                for ($x = 1; $x <= COUNT($tahapan_trx); $x++) {
                    echo '<th class="text-center">JUMLAH</th>';
                    echo '<th class="text-center">NOMINAL</th>';
                }
            }else{
                echo '<th class="text-center">JUMLAH</th>';
                echo '<th class="text-center">NOMINAL</th>';
            }
        ?>
    </tr>

    <!-- BODY -->
    <?php 
        $no = 0;
        foreach ($list as $field) {
            $no++;
    ?>
            <tr>
                <td class="text-center"><?= $no ?></td>
                <td class="text-center">#<?= $field->nik ?>#</td>
                <td class="text-center"><?= $field->nama_lengkap ?></td>

                <?php
                    if(COUNT($tahapan_trx) > 0){
                        foreach($tahapan_trx AS $tahapan){
                            $var_nominal_layanan = "nominal___". $tahapan->id_tahapan_m;
                            $var_jumlah_po = "jumlah_po___". $tahapan->id_tahapan_m;

                            echo '<td class="text-center">'.$field->$var_jumlah_po. '</td>';
                            echo '<td class="text-center">'.$field->$var_nominal_layanan. '</td>';

                            $total[$tahapan->id_tahapan_m]['jumlah'] += (int)$field->$var_jumlah_po;
                            $total[$tahapan->id_tahapan_m]['nominal'] += (int)$field->$var_nominal_layanan;
                        }
                    }else{
                        echo '<td class="text-center">-</td>';
                        echo '<td class="text-center">-</td>';
                    }
                ?>
            </tr>
    <?php 
        } 
    ?>
     
    <!-- FOOTER -->
    <tr>
        <td colspan="3" class="text-center">TOTAL</td>
        <?php 
            if(COUNT($tahapan_trx) > 0){
                foreach($tahapan_trx AS $tahapan){
                    echo '<td class="text-center">'. $total[$tahapan->id_tahapan_m]['jumlah']. '</td>';
                    echo '<td class="text-center">'. $total[$tahapan->id_tahapan_m]['nominal']. '</td>';
                }
            }else{
                echo '<td class="text-center">-</td>';
                echo '<td class="text-center">-</td>';
            }
        ?>
    </tr>
</table>