【问题标题】:How can I display a field with a certain field bound condition in Codeigniter?如何在 Codeigniter 中显示具有特定字段绑定条件的字段?
【发布时间】:2022-01-21 06:53:52
【问题描述】:

我用 dompdf 以 pdf 的形式打印了账单,账单上有总账单。但是总账单的结果是把bulan_bill中包含的所有付款数据加起来,总账单应该只加起来没有支付的款项。所以我想制作一个总账单,将bulan_status = 0的bulan_bill上的数据相加。

控制器中的代码:

 function printBill() {
    $this->load->helper(array('dompdf'));
    $f = $this->input->get(NULL, TRUE);

    $data['f'] = $f;

    $siswa['santri_id'] = '';
    $params = array();
    $pay = array();
 
// School Year
    if (isset($f['n']) && !empty($f['n']) && $f['n'] != '') {
      $params['period_id'] = $f['n'];
      $pay['period_id'] = $f['n'];
    }

// Student
    if (isset($f['r']) && !empty($f['r']) && $f['r'] != '') {
      $params['santri_room'] = $f['r'];
      $siswa = $this->Santri_model->get(array('santri_room'=>$f['r']));

    }
    $pay['santri_id']=$siswa['santri_id'];
 
    $data['period'] = $this->Period_model->get($params);
    $data['siswa'] = $this->Santri_model->get(array('santri_id'=>$siswa['santri_id'], 'group'=>TRUE));
    $data['bulan'] = $this->Bulan_model->get($pay);
    $data['bebas'] = $this->Bebas_model->get($pay);
 
    $data['setting_district'] = $this->Setting_model->get(array('id' => SCHOOL_DISTRICT)); 
    
    
    $html = $this->load->view('payout/payout_bill_pdf', $data, true);
    $data = pdf_create($html, $siswa['santri_full_name'], TRUE, 'A4', TRUE);
  }

查看代码

    <html>
<head>
  <?php foreach ($siswa as $row): ?>
    <title>Cetak Surat Tagihan - <?php echo $row['santri_full_name'] ?></title>
  <?php endforeach ?>
  </head>
<body>

  <p class="title">RINCIAN PEMBAYARAN ADMINISTRASI</p>
  <p class="tp"> TAHUN PELAJARAN <?php foreach ($period as $row):?> <?php echo ($f['n'] == $row['period_id']) ? $row['period_start'].'/'.$row['period_end'] : '' ?><?php endforeach; ?></p>

  <table style="font-size: 10pt;" width="100%" border="0">
    <tr>
      <td width="100">Kamar Santri</td>
      <td width="5">:</td>
      <?php foreach ($siswa as $row): ?>
        <td width=""><?php echo $row['santri_room'] ?></td>
      <?php endforeach; ?>
    </tr>
    <tr>
      <td>Nama</td>
      <td>:</td>
      <?php foreach ($siswa as $row): ?>
        <td><?php echo $row['santri_full_name'] ?></td>
      <?php endforeach; ?>
    </tr>
    <tr>
      <td>Kelas</td>
      <td>:</td>
      <?php foreach ($siswa as $row): ?>
        <td><?php echo $row['class_name'] ?></td>
      <?php endforeach; ?>
    </tr>
    </table><br>
    <?php if ($f['n'] AND $f['r'] != NULL) { ?> 

      <table width="100%" border="1" style="white-space: nowrap;">
        <tr>
          <th style="height: 30px;">NO</th>
          <th>NAMA PEMBAYARAN</th>
          <th>TANGGAL PEMBAYARAN</th>
          <th>BIAYA</th>
          <th>KETERANGAN</th>
        </tr>
        <?php 
        $i = 1; 
        $beb_total1 = 0;
        foreach ($bulan as $row) :
          $namePay = $row['pos_name'].' - T.A '.$row['period_start'].'/'.$row['period_end'];
          $mont = ($row['month_month_id']<=6) ? $row['period_start'] : $row['period_end'];
          
          ?>
          <tr>
            <td style="text-align: center;"><?php echo $i ?></td>
            <td><?php echo $namePay .' - ('.$row['month_name'].' '.$mont.')' ?></td>
            <td style="text-align: <?php echo ($row['bulan_status']==1) ? 'center' : ''; ?>;"><?php echo ($row['bulan_status']==1) ? pretty_date($row['bulan_date_pay'],'d F Y',false)  : '-' ?></td>
            <td><?php echo ($row['bulan_status']==0) ? 'Rp. '. number_format($row['bulan_bill'], 0, ',', '.') : 'Rp. -' ?></td>
            <td><?php echo ($row['bulan_status']==1) ? 'Lunas' : 'Belum Lunas' ?></td>
            </tr>
          <?php 
          $i++;
          $beb_total1= $beb_total1 + $row['bulan_bill'];
        endforeach
        ?>
        <?php 
        $j = $i;
        $beb_total2 = 0;
        foreach ($bebas as $row) :
          $namePayFree = $row['pos_name'].' - T.A '.$row['period_start'].'/'.$row['period_end'];
          ?>
          <tr>
            <td style="text-align: center;"><?php echo $j ?></td>
            <td><?php echo $namePayFree ?></td>
            <td style="text-align: <?php echo ($row['bebas_total_pay']>0) ? 'center' : ''?>"><?php echo ($row['bebas_total_pay']>0) ? pretty_date($row['bebas_last_update'],'d F Y',false) : '-'  ?></td>
            <td><?php echo ($row['bebas_bill']-$row['bebas_total_pay']!=0) ? 'Rp. '. number_format($row['bebas_bill']-$row['bebas_total_pay'], 0, ',', '.') : 'Rp. -' ?></td>
            <td><?php echo ($row['bebas_bill']==$row['bebas_total_pay']) ? 'Lunas' : 'Belum Lunas' ?></td>
          </tr>
          <?php 
          $beb_total2 = $beb_total2 + $row['bebas_bill']-$row['bebas_total_pay'];
          $j++;
        endforeach
        ?>
      </table>
      <td style="background-color: #dedede; font-weight:bold; border-bottom: 1px solid;">Total Pembayaran</td>
                <td>Rp. </td>
                <td><?php echo number_format($beb_total1+$beb_total2, 0, ',', '.')?></td>
      <?php } else redirect('manage/payout?n='.$f['n'].'&r='.$f['r'])  ?>

【问题讨论】:

    标签: php mysql codeigniter web


    【解决方案1】:

    如果您在查询中添加以下内容,问题将得到解决;

    $this->db->where('bulan_status', '0');
    

    【讨论】:

    • function get_total_bulan ($params = array()){ if(isset($params['bulan_bill'])) { $this->db->where('bulan_bill'); $this->db->where('bulan_status', '0'); }} 是这样的吗?
    • 是或函数 get_total_bulan ($params = array()){ if(isset($params['bulan_bill'])) { $this->db->where('bulan_bill'); $this->db->where('bulan_status', 0); }}
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多