现在,我正在使用月度发票系统来计算滞纳金和总金额,对于第一个月,滞纳金是发票金额* 10%,然后总金额是发票金额+滞纳金。对于第二个月,滞纳金为第一个月的总金额* 10%,则总金额为第一个月的总金额+滞纳金。
图片就是我现在正在做的
我已完成上图所示的操作,但是手动输入了逾期金额以获取滞纳金和总金额。从总金额中获取逾期金额的另一种方法是吗?但是我显示总金额的方法是循环法。
if(isset($_POST['save_inv'])){
$ddate = count($_POST['ddate']); //get total number of array element
for($i=0;$i<$ddate;$i++) { // loop through array and assign values in variable and insert itin database
if(($_POST['dpayment'][$i] - $_POST['dtotal'][$i]) <= 0){
$query4 = $DBcon->query("UPDATE owner_monthlyfees SET status = '1' WHERE owner = '".$_POST['downer'][$i]."' AND unit_name = '".$_POST['dunit'][$i]."' AND total <= '0'");
}
if($_POST['damt_overdue'][$i] < $_POST['dinv_sum'][$i]){
$query7 = $DBcon->query("UPDATE owner_monthlyfees SET amount_overdue = '".$_POST['damt_overdue'][$i]."' , late_payment_charges = '".$_POST['damt_overdue'][$i]."'*('".$_POST['dlatecharge'][$i]."'/100) , payment = '".$_POST['dpayment'][$i]."' , total = '".$_POST['dinv_sum'][$i]."'+'".$_POST['damt_overdue'][$i]."'+('".$_POST['damt_overdue'][$i]."'*('".$_POST['dlatecharge'][$i]."'/100))-'".$_POST['dpayment'][$i]."' WHERE owner = '".$_POST['downer'][$i]."' and unit_name = '".$_POST['dunit'][$i]."' and date = '".$_POST['ddate'][$i]."'");
}
elseif($_POST['damt_overdue'][$i] > 0){
$query3 = $DBcon->query("UPDATE owner_monthlyfees SET amount_overdue = '".$_POST['damt_overdue'][$i]."' , late_payment_charges = '".$_POST['damt_overdue'][$i]."'*('".$_POST['dlatecharge'][$i]."'/100) , payment = '".$_POST['dpayment'][$i]."' , total = '".$_POST['damt_overdue'][$i]."'+('".$_POST['damt_overdue'][$i]."'*('".$_POST['dlatecharge'][$i]."'/100))-'".$_POST['dpayment'][$i]."' WHERE owner = '".$_POST['downer'][$i]."' and unit_name = '".$_POST['dunit'][$i]."' and date = '".$_POST['ddate'][$i]."'");
}elseif($_POST['damt_overdue'][$i] <= 0){
$query6 = $DBcon->query("UPDATE owner_monthlyfees SET amount_overdue = '".$_POST['damt_overdue'][$i]."' , late_payment_charges = '".$_POST['damt_overdue'][$i]."'*('".$_POST['dlatecharge'][$i]."'/100) , payment = '".$_POST['dpayment'][$i]."' , total = '".$_POST['dinv_sum'][$i]."'-'".$_POST['dpayment'][$i]."' WHERE owner = '".$_POST['downer'][$i]."' and unit_name = '".$_POST['dunit'][$i]."' and date = '".$_POST['ddate'][$i]."'");
}
}
}
$query5 = $DBcon->query("SELECT * FROM owner_monthlyfees WHERE owner = '$owner' AND unit_name = '$unit_name' AND date2 BETWEEN '$newDateString' AND '$today' order by inv_no");
while ($row5=$query5->fetch_array()){
$dunit=$row5['unit_name'];
$downer=$row5['owner'];
$ddate=$row5['date'];
$dinv_no=$row5['inv_no'];
$dinvoice_sum=$row5['invoice_sum'];
$dpayment=$row5['payment'];
$dlatepayment=$row5['late_payment_charges'];
$damt_overdue=$row5['amount_overdue'];
$dlatecharge=$row5['late_charge'];
$dtotal=$row5['total'];
?>
<form method='POST' action='' enctype='multipart/form-data'>
<tr>
<input type="hidden" value="<?php echo $downer; ?>" name="downer[]">
<input type="hidden" value="<?php echo $dunit; ?>" name="dunit[]">
<input type="hidden" value="<?php echo $ddate; ?>" name="ddate[]">
<td class="text-center"><a href="invoice_detail?month=<?php echo $month;?>&inv_no=<?php echo $dinv_no; ?>"><?php echo $ddate; ?></a></td>
<td class="text-center"><?php echo $dinv_no; ?></td>
<td class="text-center"><?php echo $dinvoice_sum; ?><input type="hidden" value="<?php echo $dinvoice_sum; ?>" name="dinv_sum[]"></td>
<td class="text-center"><input type="number" step="0.01" class="disinput" value="<?php echo $dpayment; ?>" name="dpayment[]" disabled></td>
<td class="text-center"><input type="number" step="0.01" class="disinput" value="<?php echo $damt_overdue; ?>" name="damt_overdue[]" disabled></td>
<td class="text-center"><?php echo $dlatepayment; ?><input type="hidden" value="<?php echo $dlatepayment; ?>" name="dlatepayment[]"></td>
<input type="hidden" value="<?php echo $dlatecharge; ?>" name="dlatecharge[]"></td>
<td class="text-center"><?php echo $dtotal; ?><input type="hidden" value="<?php echo $dtotal; ?>" name="dtotal[]"></td>
</tr>
<?php
$dgrandtotal += $dtotal;
}
答案 0 :(得分:0)
我想你想要一张像这样的桌子
-------------------------------------------------------------------------------
|Month|Number| Sum | Payment | Amount Overdue | Late Payment Charges | Amount |
-------------------------------------------------------------------------------
| Jul | 2546 | 500 | | | 50 | 550 |
| Aug | 2546 | 500 | | | 55 | 605 |
| Sep | 2546 | 500 | | | 60.5 | 665.5 |
| Oct | 2546 | 500 | | | 66.55 | 732 |
-------------------------------------------------------------------------------
| | Total | 2552.5 |
-------------------------------------------------------------------------------
首先,您要将所有原始数据存储到新数组中。
$results = [];
while ($row5=$query5->fetch_array()){
$results[] = $row5;
}
现在,您可以遍历它们并在Raws之前和之后访问
foreach ($results as $key => &$result){
if($key == 0 ){
// If the months is the first month
$result['late_payment_charges'] = $result['invoice_sum']*0.1;
$result['total'] = $result['late_payment_charges'] + $result['invoice_sum'];
// 0.1 is 10%
} else {
// Getting the previous month details
$prevMonth = $results[$key-1];
$result['late_payment_charges'] = $prevMonth['total']*0.1;
$result['total'] = $prevMonth['total']+$result['late_payment_charges'];
}
}
现在您可以遍历$results
并将其写入html页面
添加额外的隐藏输入或将发票编号放入输入标签中以获得发票参考
<td class="text-center"><input type="text" name="invoice_number[]" value="<?php echo $dinv_no; ?>"/></td>
将其更新到数据库时
foreach($_POST['invoice_number'] as $key => $value){
$dinv_sum = $_POST['dinv_sum'][$key];
$dpayment = $_POST['dpayment'][$key];
// |
// | Other inputs getting below format
// |
// V
// Now executing "UPDATE INTO owner_monthlyfees SET invoice_sum = $dinv_sum" , payment = "$dpayment" ,....... WHERE inv_no = "$invoice_number"
}