我试图将已支付的金额和折扣金额添加到费用类型行,但如果仍未支付,则会对每个费用类型行重复此操作。
代码:
<table id="tableFixedHeader" class="table table-striped table-bordered table-hover">
<thead class="header">
<tr>
<th style="width: 10px"><input type="checkbox" id="select_all" /></th>
<th align="left">Check No</th>
<th align="left">Amount </th>
<th align="left" class="text text-left">Season</th>
<th align="left" class="text text-left">Reason</th>
<th class="text text-right">PID</th>
<th class="text text-right">Date</th>
<th align="left" class="text text-left">Status</th>
<th class="text text-left">Mode</th>
<th align="left" class="text text-left">Due Date</th>
<th align="left" class="text text-left">Discount</th>
<th align="left">Paid </th>
<th align="left">Balance</th>
<th class="text text-left">Issue Date</th>
<th class="text text-right">Action</th>
</tr>
</thead>
<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) {
$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;
foreach ($paid_installments as $index => $pvalue) {
if(($pvalue->advance_id != $value->advance_id))
continue;
$discount_amount = $discount_amount + $pvalue->amount_discount;
$paid_amount = $paid_amount + $pvalue->amount_paid;
}
?>
<?php if ($balance_amount > 0) { ?>
<tr class="danger font12">
<?php } else { ?>
<tr class="dark-gray">
<?php }
?>
<td><input class="checkbox" type="checkbox" name="fee_checkbox"></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">
<button type="button">Add</button>
</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" title="Print Invoice"></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>
</table>
参考图像
控制器:
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{
}
}
}
型号:
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;
}
我尝试了很多方法来添加条件,但我无法得到完美的答案,请帮助我解决这个错误,在图像中,第一行仍然未付款,但已付款金额不等于零,如果未付款,我需要这一行必须为零。提前感谢
不确定我是否理解您的问题,但您是否希望未付款行的金额为0。你可以使用这样的东西:
我添加了这个:
$amount_shown = $value->amount;
if (((int)$value->balance)==(int)($value->amount)) {
$amount_shown = 0;
}
并将其添加到您的表中:
<td><?php echo $amount_shown ?></td>
完整脚本:
<table id="tableFixedHeader" class="table table-striped table-bordered table-hover">
<thead class="header">
<tr>
<th style="width: 10px"><input type="checkbox" id="select_all" /></th>
<th align="left">Check No</th>
<th align="left">Amount <span>(<i class="fa fa-inr"
aria-hidden="true"></i>)</span></th>
<th align="left" class="text text-left">Season</th>
<th align="left" class="text text-left">Reason</th>
<th class="text text-right">PID</th>
<th class="text text-right">Date</th>
<th align="left" class="text text-left">Status</th>
<th class="text text-left">Mode</th>
<th align="left" class="text text-left">Due Date</th>
<th align="left" class="text text-left">Discount <span> (<i class="fa fa-inr"
aria-hidden="true"></i>)</span></th>
<th align="left">Paid <span> (<i class="fa fa-inr"
aria-hidden="true"></i>)</span></th>
<th align="left">Balance <span> (<i class="fa fa-inr"
aria-hidden="true"></i>)</span></th>
<th class="text text-left">Issue Date</th>
<th class="text text-right">Action</th>
</tr>
</thead>
<tbody>
<?php
$total_amount = 0;
$total_discount_amount = 0;
$total_balance_amount = 0;
$total_paid_amount = 0;
// Why do you loop for a total here?
foreach ($farmer_loan as $key => $balance) {
$discount_amount = 0;
$paid_amount = 0;
$total_amount = $total_amount + $balance->amount;
}
$total_amount = 0;
foreach ($paid_installments as $index => $pvalue) {
if(!empty(($pvalue->payment_id)))
$discount_amount = $discount_amount + $pvalue->amount_discount;
$paid_amount = $paid_amount + $pvalue->amount_paid;
}
foreach ($farmer_loan as $index => $value) {
$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 (((int)$value->balance)==(int)($value->amount)) {
$amount_shown = 0;
} else {
$amount_shown = $value->amount;
$total_amount += $amount_shown;
}
?>
<?php
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 $amount_shown ?></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 edit_advance_amount <?php echo $display_none; ?>"
title="Edit Row">
<i class="fa fa-pencil"></i></button>
<button class="btn btn-xs btn-default btn-delete-advance"
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
}
?>
<!-- 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>
</table>
现在工作正常,我只需按余额id添加所有已支付金额组的总和。
控制器:
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);
$total_paid_amount = $this->advance_model->paidAmount($company_id);
// echo '<pre>'; print_r($total_paid_amount); 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,
"rowpaidAmount" =>$total_paid_amount
);
$this->load->view("layout/main_layout",$data);
}
else{
return false;
}
}
}
型号:
public function paidAmount($company_id){
$query =
$this->db->select('(SELECT SUM(p1.amount_paid)) as amount_paid,(SELECT SUM(p1.amount_discount)) as amount_discount,p1.balance_id')
->from('tbl_pay_amount as p1')
->join('tbl_balance as b1', 'p1.balance_id=b1.balance_id')
->group_by('b1.balance_id')
->where("p1.farmer_id", $company_id)
->get();
return $query->result();
}
视图:
<?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) {
$balance_amount = $value->balance;
$total_balance_amount = $total_balance_amount + $balance_amount;
$total_discount_amount = $total_discount_amount + $discount_amount;
foreach ($rowpaidAmount as $index => $pvalue) {
if(($pvalue->balance_id != $value->balance_id))
continue;
$discount_amount =$pvalue->amount_discount;
$paid_amount = $pvalue->amount_paid;
$total_paid_amount = $total_paid_amount + $paid_amount;
}
?>