1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<?php
require_once "inc/configure.php";
// Retrieve form data $fullPaymentId = $_GET["fullPaymentId"]; $refidPass = $_GET["refidPass"]; $newfullPaymentDate = $_GET["newfullPaymentDate"]; $newfullPaymentRef = $_GET["newfullPaymentRef"]; $newfullPaymentTotalAmount = $_GET["newfullPaymentTotalAmount"]; $newfullPaymentStatus = $_GET["newfullPaymentStatus"];
if (in_array($_SESSION['user'], array('jmcenza', 'Linda', 'Patrick', 'ITDept'))) {
try { // Retrieve the current payment information $sql_get_current_fullPayment = "SELECT payments_remaining_amount, payments_total_amount, payments_reference FROM cus_payments WHERE refid = :fullPaymentId"; $stmt_get_current_fullPayment = $dbh->prepare($sql_get_current_fullPayment); $stmt_get_current_fullPayment->bindParam(':fullPaymentId', $fullPaymentId, PDO::PARAM_INT); $stmt_get_current_fullPayment->execute(); $currentfullPaymentInfo = $stmt_get_current_fullPayment->fetch(PDO::FETCH_ASSOC);
$deltaAdd = $newfullPaymentTotalAmount - $currentfullPaymentInfo['payments_total_amount'];
// Calculate the new remaining amount $newfullPaymentRemainingAmount = $currentfullPaymentInfo['payments_remaining_amount'] + $deltaAdd;
if($newfullPaymentRemainingAmount < 0){ //the remaining balance is below 0 - not possible echo '<script>window.location.href = "finances_individual_cus1.php?refid=' . $refidPass . '&RemainingBelow0=true";</script>'; exit; }
// Check if the payment reference is used in ivc_cus_payment $sql_check_payment_reference = "SELECT COUNT(*) FROM ivc_cus_payment WHERE reference = :oldfullPaymentRef"; $stmt_check_payment_reference = $dbh->prepare($sql_check_payment_reference); $stmt_check_payment_reference->bindParam(':oldfullPaymentRef', $currentfullPaymentInfo['payments_reference'], PDO::PARAM_STR); $stmt_check_payment_reference->execute(); $paymentReferenceCount = $stmt_check_payment_reference->fetchColumn();
// If the payment reference is used in ivc_cus_payment, update it if ($paymentReferenceCount > 0) { $sql_update_payment_reference = "UPDATE ivc_cus_payment SET reference = :newfullPaymentRef WHERE reference = :oldfullPaymentRef"; $stmt_update_payment_reference = $dbh->prepare($sql_update_payment_reference); $stmt_update_payment_reference->bindParam(':newfullPaymentRef', $newfullPaymentRef, PDO::PARAM_STR); $stmt_update_payment_reference->bindParam(':oldfullPaymentRef', $currentfullPaymentInfo['payments_reference'], PDO::PARAM_STR); $stmt_update_payment_reference->execute(); }
// Update the payment in the cus_payments table $sql_update_fullPayment = "UPDATE cus_payments SET payments_add_date = :newfullPaymentDate, payments_reference = :newfullPaymentRef, payments_total_amount = :newfullPaymentTotalAmount, payments_remaining_amount = :newfullPaymentRemainingAmount, payments_status = :newfullPaymentStatus WHERE refid = :fullPaymentId";
$stmt_update_fullPayment = $dbh->prepare($sql_update_fullPayment); $stmt_update_fullPayment->bindParam(':newfullPaymentDate', $newfullPaymentDate, PDO::PARAM_STR); $stmt_update_fullPayment->bindParam(':newfullPaymentRef', $newfullPaymentRef, PDO::PARAM_STR); $stmt_update_fullPayment->bindParam(':newfullPaymentTotalAmount', $newfullPaymentTotalAmount, PDO::PARAM_STR); $stmt_update_fullPayment->bindParam(':newfullPaymentRemainingAmount', $newfullPaymentRemainingAmount, PDO::PARAM_STR); $stmt_update_fullPayment->bindParam(':newfullPaymentStatus', $newfullPaymentStatus, PDO::PARAM_STR); $stmt_update_fullPayment->bindParam(':fullPaymentId', $fullPaymentId, PDO::PARAM_INT);
if ($stmt_update_fullPayment->execute()) { echo "Payment updated successfully."; echo '<script>window.location.href = "finances_individual_cus1.php?refid=' . $refidPass . '";</script>'; } else { throw new Exception("Error updating payment."); } } catch (PDOException $e) { echo "Database Error: " . $e->getMessage(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
}else{ echo '<script>setTimeout(function(){ window.location.href = "finances_individual_cus1.php?refid=' . $refidPass . '"; });</script>'; }
?>
|