Machanla, mn bulk invoices walata payment karanna code ekak liuwa, mata dan bulk payment delete karanna hada ganna one.
mn liuwa code eke mokak hari aulak thiyanwada ??
mn liuwa code eke mokak hari aulak thiyanwada ??
Code:
<?php
$cId = 1; // Client id
$payAmt = 2500;
$tempTotal = 0;
$inDel = mysqli_query($con,"SELECT * FROM `invoice` WHERE `customer_id` = '$cId' AND `status` = 'active' ORDER BY `id` ASC") or die(mysqli_error($con));
while($row2 = mysqli_fetch_array($inDel)){
$totDue = $row2['amount'];
$id = $row2['id'];
if($tempTotal >= 0){ //check temp total
if($tempTotal == 0 && $payAmt >= $totDue){ // check payAmt grater than equal
$tempTotal = $payAmt - $totDue;
if($tempTotal >= 0){
if($tempTotal == 0){
$tempTotal = -1;
}
$queryUp = mysqli_query($con,"UPDATE `invoice` SET `status` = 'paid', `paidBal` = '$totDue' WHERE `id` = '$id'") or die(mysqli_error($con));
}
}else if($tempTotal > 0 && $tempTotal >= $totDue){
$tempTotal = $tempTotal - $totDue;
if($tempTotal == 0){
$tempTotal = -1;
}
$queryUp = mysqli_query($con,"UPDATE `invoice` SET `status` = 'paid', `paidBal` = '$totDue' WHERE `id` = '$id'") or die(mysqli_error($con));
}else{
if($tempTotal == 0){
$tempTotal = $payAmt;
}
$queryUp = mysqli_query($con,"UPDATE `invoice` SET `status` = 'pending' , `paidBal` = '$tempTotal' WHERE `id` = '$id'") or die(mysqli_error($con));
$tempTotal = -1;
}
}
}