[英]Auto calculate the total amount and late charges amount
現在,我正在使用月度發票系統來計算滯納金和總金額,對於第一個月,滯納金是發票金額* 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;
}
我想你想要一張桌子
-------------------------------------------------------------------------------
|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"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.