dongra1984 2019-06-24 08:08
浏览 48

这个行到列表有没有更好的方法?

I pass a function into the variable ($monthly_receivable) to get the value of each months to pass and get the result of a function.. but the process is dumb slow. This was the only january data but it can add a distance months example January 2016 to December 2019.

When i try to remove that variable monthly_receivable it was smooth.

This is my code from server-side to view (client-side):

Controller

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);
}

View

<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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题