donnykurnia icon

Untitled

donnykurnia | PRO | 03/09/17 04:36:20 AM UTC | 0 ⭐ | 332 👁️ | Never ⏰ | []
PHP |

2.51 KB

|

None

|

0 👍

/

0 👎

<?php
 
public function getKartuPiutang()
{
  $tgl      = $this->input->post('tgl');
  $supplier = $this->input->post('id');
  $pecah    = explode(" - ",$tgl);
  $tglawal  = date_format(date_create($pecah[0]),"Y-m-d");
  $tglakhir = date_format(date_create($pecah[1]),"Y-m-d");
  $data     = $this->M_pempers->kartupiutang($supplier,$tglawal,$tglakhir)->result();
 
  $array_hasil = [];
  foreach ($data as $a) {
    $rowspan_key = "{$a->invoice_date}-{$a->invoice_no}-{$a->invoice_value}";
    if ( !isset( $array_hasil[$rowspan_key] ) ) {
      $array_hasil[$rowspan_key] = [];
    }
    $array_hasil[$rowspan_key][] = $a;
  }
  $this->load->view('tabel', ['array_hasil' => $array_hasil]);
}
 
 
<!-- view tabel -->
<table>
  <thead>
    <tr>
      <th colspan="2" class="center">INVOICE</th>
      <th colspan="2" class="center">BUKTI</th>
      <th colspan="2"></th>
    </tr>
    <tr class="success">
      <th class="center">TGL</th>
      <th class="center">NO</th>
      <th class="center">TGL</th>
      <th class="center">NO</th>
      <th class="center">PIUTANG</th>
      <th class="center">BAYAR</th>
    </tr> 
  </thead>
  <tbody>
    <?php foreach ($array_hasil as $rowspan_key => $baris_invoice_date): ?>
      <?php if( count($baris_invoice_date) > 0 ): ?>
        <?php
          $data_baris_pertama = $baris_invoice_date[0];
          //perhitungan $piutang disini
        ?>
        <!-- baris pertama -->
        <tr>
          <td rowspan="<?= count($baris_invoice_date) ?>"><?= $data_baris_pertama->invoice_date ?></td>
          <td rowspan="<?= count($baris_invoice_date) ?>"><?= $data_baris_pertama->invoice_no ?></td>
          <td><?= $data_baris_pertama->payment_date ?></td>
          <td><?= $data_baris_pertama->reference_no ?></td>
          <td rowspan="<?= count($baris_invoice_date) ?>">Rp. <?= number_format($piutang) ?></td>
          <td>Rp. <?= number_format($data_baris_pertama->payment_invoice) ?></td>
        </tr>
        <!-- baris berikutnya -->
        <?php $data_baris_sisa = array_slice($baris_invoice_date, 1) ?>
        <?php if( count($data_baris_sisa) > 0 ): ?>
          <?php foreach ( $data_baris_sisa as $baris ): ?>
            <tr>
              <td><?= $baris->payment_date ?></td>
              <td><?= $baris->reference_no ?></td>
              <td>Rp. <?= number_format($baris->payment_invoice) ?></td>
            </tr>
          <?php endforeach ?>
        <?php endif ?>
      <?php endif ?>
    <?php endforeach ?>
  </tbody>
</table>

Comments