如果某些行仍未支付,则在每一行中重复收集的金额

Posted

技术标签:

【中文标题】如果某些行仍未支付,则在每一行中重复收集的金额【英文标题】:The collected amount repeating in every row if in case some rows are still unpaid 【发布时间】:2020-11-18 14:08:13 【问题描述】:

当收取特定费用类型的金额时,发票行在每个费用类型行下方重复,发票行只需显示在已支付费用类型下方。请参考下图。

控制器:

public function issueAdvance($company_id)
  if($this->session->userdata("is_active") == 1)
    $seedIssue =$this->seed_issue_model->selectFarmer($company_id);
    $singlefarmer =$this->seed_issue_model->selectIssueDates($company_id);
    $crops = $this->seed_issue_model->get_crop_data(); //Crop
    $pc_code = $this->seed_issue_model->get_pc_data(); //Production-Code
    $advance_amount =$this->advance_model->getLoanData($company_id);
    $paid_installments = $this->advance_model->paidInstallments($company_id);
    if ($this->input->server('REQUEST_METHOD') == "GET") 
        $data = array(
           "page_content" => "advance/view_advance_issue",
           "singleFarmer" =>$singlefarmer,
           "issueSeed"  =>$seedIssue,
           "crop_result" =>$crops,
           "pc_result" =>$pc_code,
           "farmer_loan" =>$advance_amount,
           "paid_installments" =>$paid_installments
        );
        $this->load->view("layout/main_layout",$data);
      else
             
     
   

型号:

public function getLoanData($company_id)
  $query = $this->db->select('a1.farmer_id,a1.advance_id,b1.balance_id,a1.amount,a1.check_no,a1.given_date,a1.due_date,b1.reason,b1.season,b1.mode,b1.balance')
   ->from('tbl_advance as a1')
   ->join('tbl_balance as b1', 'b1.advance_id=a1.advance_id')
   ->where("a1.farmer_id", $company_id)
   ->order_by('a1.given_date', 'desc')
   ->get();
   $result = $query->result();
   return $result;

public function paidInstallments($company_id)
  $query = $this->db->select('a1.farmer_id,a1.advance_id,b1.balance_id,p1.amount_paid,p1.amount_discount,p1.paying_date,p1.payment_id,p1.payment_mode,p1.description,p1.balance_id')
   ->from('tbl_pay_amount as p1')
   ->join('tbl_balance as b1', 'p1.balance_id=b1.balance_id')
   ->join('tbl_advance as a1', 'b1.advance_id=a1.advance_id','p1.advance_id=a1.advance_id') 
   ->where("a1.farmer_id", $company_id)
   ->get();
   $result = $query->result(); 
   return $result;

查看本部分代码:

<tbody>
    <?php

        $total_amount = 0;
        $total_discount_amount = 0;
        $total_balance_amount = 0;
        $total_paid_amount = 0;
        
        foreach ($farmer_loan as $key => $balance) 
            $discount_amount = 0;
            $paid_amount = 0;
            $total_amount = $total_amount + $balance->amount;
        

        foreach ($farmer_loan as $index => $value) 
            if (!empty($value->payment_id)) 

                $paid_amount = $paid_amount + $value->amount_paid;
                $discount_amount = $discount_amount + $value->amount_discount;
            
        ?>

        <?php
            $balance_amount = $value->amount - ($discount_amount + $paid_amount);
            $total_balance_amount = $total_balance_amount + $balance_amount;
            $total_discount_amount = $total_discount_amount + $discount_amount;
            $total_paid_amount = $total_paid_amount + $paid_amount;

            if ($balance_amount > 0) 
        ?>
            <tr class="danger font12">
        <?php
             else 
        ?>
            <tr class="dark-gray">
        <?php
            
        ?>
        <td><input class="checkbox" type="checkbox" name="fee_checkbox"
                data-advance_id="<?php echo $value->advance_id ?>"
                data-balance_id="<?php echo $value->balance_id ?>"
                data-farmer_id="<?php echo $value->farmer_id ?>"></td>
        <td><?php echo $value->check_no ?></td>
        <td><?php echo $value->amount ?></td>
        <td><?php echo $value->reason ?></td>
        <td><?php echo $value->season ?></td>
        <td> </td>
        <td></td>
        <td align="left" class="text text-left width85">
            <?php
                if ($balance_amount == 0)  ?>
                    <span class="label label-success">Paid</span>
                <?php
                     else if (((int)$value->balance)==(int)($value->amount))  ?>
                <span class="label label-danger">Unpaid</span>
                <?php
                     else  ?>
                <span class="label label-warning">Partial</span>
                <?php
                     ?>
          </td>

        <td></td>
        <td><?php echo $value->due_date ?></td>
        <td class="text text-center">
            <?php echo (number_format($discount_amount, 2, '.', '')); ?></td>
        <td class="text text-center">
            <?php echo (number_format($paid_amount, 2, '.', '')); ?></td>
        <td class="text text-right">
            <?php $display_none = "ss-none";
                if ($balance_amount > 0) 
                    $display_none = "";
                    echo (number_format($balance_amount, 2, '.', ''));
                
                ?>
        </td>   
        <td><?php echo $value->given_date ?></td>

        <td>
            <div class="btn-group pull-right amount">
                <?php if ($paid_amount != $value->amount ) ?>
                    <button type="button"
                    data-advance_id="<?php echo $value->advance_id; ?>"
                    data-balance_id="<?php echo $value->balance_id; ?>"
                    data-farmer_id="<?php echo $value->farmer_id; ?>"
                    data.title="Collect Amount"
                    class="btn btn-xs btn-default myCollectFeeBtn <?php echo $display_none; ?>"
                      data-toggle="modal"
                    data-target="#myFeesModal">
                    <i class="fa fa-plus"></i></button>
                <?php if($paid_amount == 0.00) ?>
                    <button type="button"
                    data-advance_id="<?php echo $value->advance_id; ?>"
                    data-balance_id="<?php echo $value->balance_id; ?>"
                    data-farmer_id="<?php echo $value->farmer_id; ?>"
                    class="btn btn-xs btn-default myCollectFeeBtn <?php echo $display_none; ?>"
                    title="Edit Row" data-toggle="modal" data-target="#myFeeModal">
                    <i class="fa fa-pencil"></i></button>
                    <button class="btn btn-xs btn-default"
                    data-advance_id="<?php echo $value->advance_id; ?>"
                    data-balance_id="<?php echo $value->balance_id; ?>"
                    data-farmer_id="<?php echo $value->farmer_id; ?>"
                    title="Delete Row">
                    <i class="fa fa-remove"></i> </button>
                <?php 
                
                ?>
                <?php
                     else  ?>
                        <button class="btn btn-xs btn-default"
                    data-advance_id="<?php echo $value->advance_id; ?>"
                    data-balance_id="<?php echo $value->balance_id; ?>"
                    data-farmer_id="<?php echo $value->farmer_id; ?>"
                    title="Print Row">
                    <i class="fa fa-print"></i> </button>
                <?php
                    
                ?>
            </div>
        </td>

    </tr>
          
    <?php
                
        foreach ($paid_installments as $index => $value) 

          ?>
              <tr class="white-td" id="">
                  <td align="left"></td>
                  <td align="left"></td>
                  <td align="left"></td>
                  <td align="left"></td>
                  <td align="left"></td>
                  <td class="text text-left">
                      <a href="#" data-toggle="popover" class="detail_popover" > <?php echo $value->payment_id; ?></a>
                      <div class="fee_detail_popover" style="display: none">
                          <?php
                          if ($value->description == "") 
                              ?>
                              <p class="text text-danger">No Description</p>
                              <?php
                           else 
                              ?>
                              <p class="text text-info"><?php echo $value->description; ?></p>
                              <?php
                          
                          ?>
                      </div>
                  </td>
                  <td class="text text-left"><?php echo $value->paying_date; ?>
                  </td>
                  <td></td>
                  <td class="text text-left"><?php echo $value->payment_mode; ?></td>
                  <td></td>

                  <td class="text text-right"><?php echo (number_format($value->amount_discount, 2, '.', '')); ?></td>
                  
                  <td class="text text-right"><?php echo (number_format($value->amount_paid, 2, '.', '')); ?></td>
                  <td></td>
                  <td></td>
                  <td class="text text-right">
                    <div class="btn-group pull-right">

                <button class="btn btn-xs btn-default printInv"
                  data-advance_id="<?php echo $value->advance_id; ?>"
                  data-balance_id="<?php echo $value->balance_id; ?>"
                  data-farmer_id="<?php echo $value->farmer_id; ?>"
                  title="Print Invoice">
                  <i class="fa fa-print"></i> </button>
                    </div>
                </td>
            </tr>
            
            <?php
          
          
    ?>

    <?php

    
        ?>
    <!-- FOOTER -->
    <tr class="box box-solid total-bg">
        <td align="left"></td>
        <td align="left" class="text text-left">Grand Total</td>
        <td class="text text-center">
            <?php
            echo ('<i class="fa fa-inr"></i>' . number_format($total_amount, 2, '.', ''));
            ?>       
        </td>

    <td align="left"></td>
    <td align="left"></td>
    <td align="left"></td>
    <td class="text text-left"></td>
    <td class="text text-left"></td>
    <td class="text text-left"></td>
    <td class="text text-left"></td>
    <td class="text text-right">
    <?php
          echo ('<i class="fa fa-inr"></i>' . number_format($total_discount_amount, 2, '.', ''));
      ?>    
    </td>
    <td class="text text-right">
    <?php
      echo ('<i class="fa fa-inr"></i>' . number_format($total_paid_amount, 2, '.', ''));
      ?>
    </td>
    <td class="text text-right">
    <?php
      echo ('<i class="fa fa-inr"></i>' . number_format($total_balance_amount, 2, '.', ''));
      ?>
      </td>
      <td class="text text-right"></td>
      <td></td>
    </tr>
</tbody>

我尝试了很多方法,但我无法解决它,我是全栈 Web 开发的初学者,请帮助我克服这个问题,现在堆栈溢出只是我的希望,需要一个输出,比如我付费第一行的一些金额,发票金额行只需要显示在该行下方。提前致谢。

【问题讨论】:

【参考方案1】:

您在foreach ($paid_installments as $index =&gt; $value) 循环中使用了相同的变量名称$value,它可能与外部变量发生冲突。所以把它改成不同的名字,比如$pvalue。并在循环内添加一项检查,如

foreach ($paid_installments as $index => $pvalue) 
        if($value->advance_id != $pvalue->advance_id )
            continue;
        ?>
        <tr class="white-td" id="">
            <td align="left"></td>
            <td align="left"></td>
            <td align="left"></td>
            <td align="left"></td>
            <td align="left"></td>
            <td class="text text-left">
                <a href="#" data-toggle="popover" class="detail_popover" > <?php echo $pvalue->payment_id; ?></a>
        //...
        //.. 

【讨论】:

请看这个问题,我想你可以帮助我,***.com/questions/63314219/…

以上是关于如果某些行仍未支付,则在每一行中重复收集的金额的主要内容,如果未能解决你的问题,请参考以下文章

在任意时间以任意金额重复付款?

WooCommerce:如果购物车总金额 = 0,则更改支付网关

Zen-cart支付模块,交易金额需改成折后价

必测的支付漏洞——使用fiddler篡改支付金额

贝宝智能支付按钮动态支付金额

用例设计