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
|
<?php
require_once "inc/configure.php";
// Retrieve form data $depositId = $_GET["depositId"]; $refidPass = $_GET["refidPass"]; $newDepositDate = $_GET["newDepositDate"]; $newDepositRef = $_GET["newDepositRef"]; $newDepositTotalAmount = $_GET["newDepositTotalAmount"]; $newDepositStatus = $_GET["newDepositStatus"];
if (in_array($_SESSION['user'], array('jmcenza', 'Linda', 'Patrick', 'ITDept'))) {
try { // Retrieve the current deposit information $sql_get_current_deposit = "SELECT deposit_remaining_amount, deposit_total_amount, deposit_reference FROM cus_deposit WHERE refid = :depositId"; $stmt_get_current_deposit = $dbh->prepare($sql_get_current_deposit); $stmt_get_current_deposit->bindParam(':depositId', $depositId, PDO::PARAM_INT); $stmt_get_current_deposit->execute(); $currentDepositInfo = $stmt_get_current_deposit->fetch(PDO::FETCH_ASSOC);
$deltaAdd = $newDepositTotalAmount - $currentDepositInfo['deposit_total_amount'];
// Calculate the new remaining amount $newDepositRemainingAmount = $currentDepositInfo['deposit_remaining_amount'] + $deltaAdd;
if($newDepositRemainingAmount < 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 deposit reference is used in ivc_cus_payment $sql_check_payment_reference = "SELECT COUNT(*) FROM ivc_cus_payment WHERE reference = :oldDepositRef"; $stmt_check_payment_reference = $dbh->prepare($sql_check_payment_reference); $stmt_check_payment_reference->bindParam(':oldDepositRef', $currentDepositInfo['deposit_reference'], PDO::PARAM_STR); $stmt_check_payment_reference->execute(); $paymentReferenceCount = $stmt_check_payment_reference->fetchColumn();
// If the deposit reference is used in ivc_cus_payment, update it if ($paymentReferenceCount > 0) { $sql_update_payment_reference = "UPDATE ivc_cus_payment SET reference = :newDepositRef WHERE reference = :oldDepositRef"; $stmt_update_payment_reference = $dbh->prepare($sql_update_payment_reference); $stmt_update_payment_reference->bindParam(':newDepositRef', $newDepositRef, PDO::PARAM_STR); $stmt_update_payment_reference->bindParam(':oldDepositRef', $currentDepositInfo['deposit_reference'], PDO::PARAM_STR); $stmt_update_payment_reference->execute(); }
// Update the deposit in the cus_deposit table $sql_update_deposit = "UPDATE cus_deposit SET deposit_add_date = :newDepositDate, deposit_reference = :newDepositRef, deposit_total_amount = :newDepositTotalAmount, deposit_remaining_amount = :newDepositRemainingAmount, deposit_status = :newDepositStatus WHERE refid = :depositId";
$stmt_update_deposit = $dbh->prepare($sql_update_deposit); $stmt_update_deposit->bindParam(':newDepositDate', $newDepositDate, PDO::PARAM_STR); $stmt_update_deposit->bindParam(':newDepositRef', $newDepositRef, PDO::PARAM_STR); $stmt_update_deposit->bindParam(':newDepositTotalAmount', $newDepositTotalAmount, PDO::PARAM_STR); $stmt_update_deposit->bindParam(':newDepositRemainingAmount', $newDepositRemainingAmount, PDO::PARAM_STR); $stmt_update_deposit->bindParam(':newDepositStatus', $newDepositStatus, PDO::PARAM_STR); $stmt_update_deposit->bindParam(':depositId', $depositId, PDO::PARAM_INT);
if ($stmt_update_deposit->execute()) { echo "Deposit updated successfully."; echo '<script>window.location.href = "finances_individual_cus1.php?refid=' . $refidPass . '";</script>'; } else { throw new Exception("Error updating deposit."); } } 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>'; }
?>
|