jeudi 30 juillet 2020

Total paid amount repeating in every row CodeIgniter

The total paid amount for particular fees type is repeating for every row, need a solution to overcome from this logic.please refer image below
Controller -

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);
         // echo '<pre>'; print_r($paid_installments); echo ("</pre>"); exit();
          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{
            }
        }
    }

Model -

public function getLoanData($company_id){
      $query = 
       $this->db->select(
                        'a1.farmer_id,b1.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,b1.advance_id,b1.balance_id,a1.amount,a1.check_no,a1.given_date,a1.due_date,b1.reason,b1.season,b1.mode,b1.balance,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') 
                ->where("a1.farmer_id", $company_id)
                ->get();
                $result = $query->result();
                return $result;
        }

View Part -

<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 ($paid_installments as $key => $kvalue) {
                                            if($kvalue->advance_id == $balance->advance_id )
                                                        continue;
                                                $discount_amount = $discount_amount + $kvalue->amount_discount;
                                                $paid_amount = $paid_amount + $kvalue->amount_paid;
                                        }
                                        foreach ($farmer_loan as $index => $value) {
                                    ?>

                                    <?php
                                            $balance_amount = $value->balance;
                                            $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->balance ){ ?>
                                                    <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 => $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>
                                                                <div class="fee_detail_popover" style="display: none">
                                                                    <?php
                                                                    if ($pvalue->description == "") {
                                                                        ?>
                                                                        <p class="text text-danger">No Description</p>
                                                                        <?php
                                                                    } else {
                                                                        ?>
                                                                        <p class="text text-info"><?php echo $pvalue->description; ?></p>
                                                                        <?php
                                                                    }
                                                                    ?>
                                                                </div>
                                                            </td>
                                                            <td class="text text-left"><?php echo $pvalue->paying_date; ?>
                                                            </td>
                                                            <td></td>
                                                            <td class="text text-left"><?php echo $pvalue->payment_mode; ?></td>
                                                            <td></td>

                                                            <td class="text text-right"><?php echo (number_format($pvalue->amount_discount, 2, '.', '')); ?></td>
                                                            
                                                            <td class="text text-right"><?php echo (number_format($pvalue->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 $pvalue->advance_id; ?>"
                                                                data-balance_id="<?php echo $pvalue->balance_id; ?>"
                                                                data-farmer_id="<?php echo $pvalue->farmer_id; ?>"
                                                                title="Print Invoice">
                                                                <i class="fa fa-print"></i> </button>
                                                            </div>
                                                        </td>
                                                    </tr>     
                                                <?php
                                                    }
                                                ?>
                                    <?php
                                        }
                                    ?>

When amount to be paid for a particular fees type, the paid amount repeating in every other unpaid rows,it need to be update in only paid row, thanks in advance.example image

Aucun commentaire:

Enregistrer un commentaire