在此行到列表中是否有更好的方法?

时间:2019-06-24 08:08:32

标签: php postgresql codeigniter

我将一个函数传递给变量($ monthly_receivable)以获取要传递的每个月的值并获取函数的结果..但是过程缓慢。这是唯一的一月份数据,但可以添加从2016年1月到2019年12月的距离月份示例。

当我尝试删除monthly_receivable变量时,它很平滑。

这是我从服务器端到视图(客户端)的代码:

控制器

public function notes_receivable_summary($start_date, $end_date) {
    $loans_list = $this->db->query("SELECT 
                                    borr_name,
                                        co_borrower, 
                                        released_date, 
                                        due_from, 
                                        due_to, 
                                        pn, 
                                        no_months, 
                                        loan_ref, 
                                        loan_id, 
                                        pn 
                                    FROM v_borrowers_nr dd
                                    WHERE (df between '$start_date' AND '$end_date')
                                    ORDER BY loan_ref")->result();
    $months     = $this->db->query("SELECT dd FROM v_months_nr WHERE dd between '$start_date' and '$end_date'")->result();

    $data['monthly_receivable'] = function($date, $loan_ref, $loan_id){
            $enc_url = explode('|', $this->Main_model->encdec($this->uri->segment(2), 'd'));
            $s_date  = $enc_url[1];
            $e_date  = $enc_url[2];
            $sd      = date('Y-m-d', strtotime('-1 months', strtotime($s_date)));
            $ed      = $e_date;

      $q             = $this->db->query("SELECT * FROM f_monthly_rcvble('$loan_ref', $loan_id, '$start_date', '$end_date', '$date')")->row();
        return $q;
    };
    $this->load->view('pages/ajax/reports/sample_nr', $data);
}

查看

<table id="displayTableNR" class="table displayTableNR js-sort-table">
  <?php $month = array(1=>'Jan', 2=>'Feb', 3=>'Mar', 4=>'Apr', 5=>'May', 6=>'Jun', 7=>'Jul', 8=>'Aug', 9=>'Sep', 10=>'Oct', 11=>'Nov', 12=>'Dec'); ?>
  <?php $total_as_of_h = 0; ?>
  <?php $range_date    = !empty($months) ? date('M Y', strtotime($months[0]->dd)) . ' - ' . date('M Y', strtotime($months[count($months) - 1]->dd)) : null; ?>
  <thead>
      <tr class="menu1">
          <th class="table-head b-right" scope="col">Ref. No.</th>
          <th class="table-head b-right js-sort-string fixed-side" scope="col">Name</th>
          <th class="table-head b-right fixed-side" scope="col">Co-Borrower</th>
          <th class="table-head b-right fixed-side" scope="col"><div class="wd-132px">Release Date</div></th>
          <th class="table-head b-right js-sort-date fixed-side" scope="col">From</th>
          <th class="table-head b-right js-sort-date fixed-side" scope="col">To</th>
          <th class="table-head b-right fixed-side text-right" scope="col">PN</th>
          <th class="table-head fixed-side" scope="col">Terms</th>

          <?php $count = 0; ?>
          <?php foreach ($months as $row): ?>
              <?php $d = explode('-', $row->dd); ?>
              <th class="table-head text-center font-strong <?php echo $count % 2 === 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>" colspan="10"><?php echo strtoupper($month[(int) $d[1]]) . ' ' . $d[0]; ?></th>
          <?php $count++; ?>
          <?php $total_as_of_h++; ?>
          <?php endforeach; ?>

          <?php if ($total_as_of_h === count($months)): ?>
              <th class="td-head text-center" colspan="3">COLLECTION ACTUAL/CLOSED OB/EFP</th>
          <?php endif; ?>
      </tr>
      <tr class="menu2">
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head b-right fixed-side"></th>
          <th class="table-head fixed-side"></th>

          <?php $count = 0; ?>
          <?php foreach ($months as $row): ?>
              <th class="table-head font-strong <?php echo $count % 2 === 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Current Target</div></th>
              <th class="table-head font-strong amt_pd <?php echo $count % 2 === 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Actual Collection</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">UA/SP</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Past Due Target UA/SP</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Actual Collection UA/SP</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Past Due Balance UA/SP</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Advanced Payment</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">OB Closed</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Early Full Payments</div></th>
              <th class="table-head font-strong <?php echo $count % 2 == 0 ? 'hexa-color-1' : 'hexa-color-2'; ?>"><div class="wd-132px text-center">Adjustments</div></th>
          <?php $count++; ?>
          <?php endforeach; ?>

          <?php if ($total_as_of_h === count($months)): ?>
              <th class="table-head">TOTAL</th>
              <th class="table-head"><div class="wd-118px text-center">(<?php echo $range_date; ?>)</div></th>
              <th class="table-head">NR BAL</th>
          <?php endif; ?>
      </tr>
  </thead>
  <tbody>

  <?php $totAmntToPay             = 0; ?>            
  <?php $totCollection            = 0; ?>            
  <?php $totBalance               = 0; ?>            

  <?php foreach($loans_list as $r): ?>
  <?php $name   = explode('|', $r->borr_name); ?>
  <tr class="">
    <td class="td-border fixed-side"><?php echo $r->loan_ref; ?></td>
    <?php if (count($name) < 3): ?>
      <td class="td-border br-name-nr fixed-side"><div class="wd-210px"><?php echo strtoupper($name[0]) . ', ' . strtoupper($name[1]); ?></div></td>
    <?php else: ?>
      <td class="td-border br-name-nr fixed-side"><div class="wd-210px"><?php echo strtoupper($name[0]) . ', ' . strtoupper($name[1]) . ' ' . strtoupper($name[2]); ?></div></td>
    <?php endif; ?>
    <td class="td-border fixed-side"><div class="wd-145px"><?php echo strtoupper($r->co_borrower); ?></div></td>
    <td class="td-border fixed-side"><?php echo date('Y-m-d', strtotime($r->released_date)); ?></td>
    <td class="td-border fixed-side"><?php echo date('Y-m-d', strtotime($r->due_from)); ?></td>
    <td class="td-border fixed-side"><?php echo date('Y-m-d', strtotime($r->due_to)); ?></td>
    <td class="td-border text-right fixed-side"><?php echo number_format($r->pn, 2); ?></td>
    <td class="td-border fixed-side"><?php echo number_format($r->no_months, 0); ?></td>

    <!-- TOTALS VARIABLE -->
    <?php $ct1                   = 0; ?>
    <?php $curr_or_prev_uasp     = 0; ?>
    <?php $tot_prev_uasp_balance = 0; ?>

    <?php foreach($months as $row): ?>
    <?php $lref = $r->loan_ref; ?>
    <?php $lid  = $r->loan_id; ?>
    <?php $nr                     = $monthly_receivable($row->dd, $lref, $lid); ?>
      <?php if (is_object($nr)): ?>
        <td class="td-border text-right"><?php echo number_format($nr->amount_due, 2); ?></td>
        <td class="td-border text-right"><?php echo number_format($nr->actual_collection, 2); ?></td>
          <?php if ($ct1 == 0): ?>
            <td class="td-border text-right"></td>
          <?php else: ?>  
            <td class="td-border text-right"><?php echo number_format($nr->col_ua_sp, 2); ?></td>
          <?php endif; ?>
        <td class="td-border text-right"><?php echo number_format($nr->past_due_target_ua_sp, 2); //Past Due Target UA/SP ?></td>
        <td class="td-border text-right"><a href="#" class="clrd-tooltip" data-toggle="tooltip" data-placement="right" title=""><?php echo number_format($nr->past_due_collection_tot_ua_sp, 2); ?></a></td>
        <td class="td-border text-right"><?php echo number_format($nr->past_due_balance, 2); //Past Due Target Balance ?></td>
        <td class="td-border text-right"><a href="#" class="clrd-tooltip" data-toggle="tooltip" data-placement="right" title=""><?php echo number_format($nr->advanced_payment, 2); ?></a></td>
        <td class="td-border text-right"><?php echo number_format($nr->ob_closed, 2); ?></td>
        <td class="td-border text-right"><?php echo number_format($nr->early_full_payments, 2); ?></td>
        <td class="td-border text-right"><?php echo number_format($nr->adjustments, 2); ?></td>
      <?php endif; ?>
    <!-- TOTALS -->
    <?php $ct1++; ?> 
    <?php endforeach; ?>
    <td class="td-border text-right total-to-pay"><?php echo number_format($col_tot_pn, 2); ?></td>
    <td class="td-border text-right total-coll"><?php echo number_format($col_tot_col, 2); ?></td>
    <td class="td-border text-right total-bal"><?php echo number_format($col_tot_pn - $col_tot_col, 2); ?></td>
  </tr>
</tbody>
<tfoot>
    <tr>
        <th class="table-head b-right fixed-side">Ref. No.</th>
        <th class="table-head b-right fixed-side">Name</th>
        <th class="table-head b-right fixed-side">Co-Borrower</th>
        <th class="table-head b-right fixed-side">Release Date</th>
        <th class="table-head b-right fixed-side">From</th>
        <th class="table-head b-right fixed-side">To</th>
        <th class="table-head b-right text-right fixed-side"><?php echo number_format($totPN, 2); ?></th>
        <th class="table-head fixed-side">Terms</th>

        <?php if ($total_as_of_h === count($months)): ?>
            <td class="table-head text-right"><?php echo number_format($totAmntToPay, 2); ?></td>
            <td class="table-head text-right"><?php echo number_format($totCollection, 2); ?></td>
            <td class="table-head text-right"><?php echo number_format($totBalance, 2); ?></td>
        <?php endif; ?>
    </tr>
  </tfoot>
</table>

enter image description here

enter image description here

0 个答案:

没有答案