First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
$ValidAccess = 2010;
|
||||
require_once("include/globals.php");
|
||||
include_once("include/queuemail.php");
|
||||
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
logExit("Session is not active\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
// CSRF token validation
|
||||
include "include/ajax.csrfToken.php";
|
||||
|
||||
|
||||
// Set default timezone
|
||||
date_default_timezone_set($school_record['timezone']);
|
||||
$now = date("Y-m-d H:i:s",time());
|
||||
|
||||
$return_data = array();
|
||||
|
||||
$moduleName = "ajax.ChargeAccount.php";
|
||||
// startLog($moduleName);
|
||||
|
||||
|
||||
// Get parameters
|
||||
$user_num = $_GET['user_num'];
|
||||
$balance = $_GET['balance'];
|
||||
$school_num = $school_record['record_num'];
|
||||
|
||||
// Ensure parameters are valid
|
||||
|
||||
writeLog("school_num: $school_num\n");
|
||||
writeLog("user_num: $user_num\n");
|
||||
writeLog("balance: $balance\n");
|
||||
|
||||
|
||||
// Get account info
|
||||
$results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
|
||||
$user = db_fetch_assoc($results);
|
||||
$user_email = $user['email'];
|
||||
writeLog("user_email: $user_email\n");
|
||||
|
||||
|
||||
// Get students in account
|
||||
$results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND user_num = $user_num ORDER BY last_name,first_name");
|
||||
$students = "";
|
||||
while ($row = db_fetch_assoc($results)) {
|
||||
$name = $row['first_name'] . ' ' . $row['last_name'];
|
||||
if (strlen($students)) $students .= ", ";
|
||||
$students .= $name;
|
||||
}
|
||||
|
||||
|
||||
// Get set of Unpaid Orders
|
||||
$query = "SELECT hloh.* FROM hotlunch_order_header as hloh, people as p " .
|
||||
"WHERE hloh.school_num = $school_num " .
|
||||
"AND ordered_by_num = p.record_num " .
|
||||
"AND p.user_num = $user_num " .
|
||||
"AND hloh.status NOT IN ('Paid','Complimentary','Concession') " .
|
||||
"ORDER BY record_num";
|
||||
$orders = db_query($query);
|
||||
writeLog("orders found: " . db_num_rows($orders) . "\n");
|
||||
|
||||
$order_payments = "";
|
||||
$snum = 0;
|
||||
if (db_num_rows($orders) > 0) {
|
||||
while ($row = db_fetch_array($orders)) {
|
||||
$onum = $row['record_num'];
|
||||
$ototal = $row['order_total'];
|
||||
$opaid = $row['amount_paid'];
|
||||
$snum = $row['schedule_num'];
|
||||
$amt = number_format($ototal - $opaid,2);
|
||||
if (strlen($order_payments) > 0) $order_payments .= "|";
|
||||
$order_payments .= "{" . $onum . ":" . $amt . "}";
|
||||
|
||||
$query = "UPDATE hotlunch_order_header " .
|
||||
"SET amount_paid = order_total, " .
|
||||
"status = 'Paid', " .
|
||||
"paid_date = '$today', " .
|
||||
"payment_method = 'PayPal' " .
|
||||
"WHERE record_num = {$onum}";
|
||||
db_query($query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Post payment to account
|
||||
$amount = $balance * -1;
|
||||
$entered_time = time();
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
|
||||
$query = "INSERT INTO user_account " .
|
||||
"(school_num,user_num,schedule_num,transaction_datetime,transaction_type,note,transaction_amount,transaction_fee,payment_method,payment_reference,order_payments,deleted,entered_time) " .
|
||||
"VALUES ($school_num,$user_num,$snum,'$trx_time','Payment','School Account Charge',$amount,0,'School Account','','$order_payments','N',$entered_time)";
|
||||
writeLog("query: $query\n");
|
||||
db_query($query);
|
||||
|
||||
|
||||
// Send school account email notification
|
||||
if (strlen($school_record['school_account_notification_email'])) {
|
||||
$emailRecipient = $school_record['school_name'];
|
||||
$emailTo = $school_record['school_account_notification_email'];
|
||||
$emailFrom = setReplyAddress($school_record['reply_email']);
|
||||
$emailReply = $school_record['school_name'];
|
||||
$emailSubject = $school_record['school_name'] . ": " . getLanguageText('TEXT-SCHOOL-ACCOUNT-CHARGE');
|
||||
|
||||
$emailMessage = getLanguageText('TEXT-USER-ID') . ": " . $user['userid'] . "\n" .
|
||||
getLanguageText('TEXT-NAME') . ": " . $user['first_name'] . ' ' . $user['last_name'] . "\n" .
|
||||
getLanguageText('TEXT-PHONE') . ": " . $user['home_phone'] . "\n" .
|
||||
getLanguageText('TEXT-EMAIL') . ": " . $user_email . "\n" .
|
||||
$GlobalText['Students'] . ": " . $students . "\n" .
|
||||
"\n" .
|
||||
getLanguageText('TEXT-AMOUNT') . ": $currencySymbol" . number_format($balance,2) . "\n\n";
|
||||
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
||||
QueueEmail($user_email, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
||||
// QueueEmail("mark@fester.ca", $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
||||
}
|
||||
|
||||
writeLog("completed\n");
|
||||
?>
|
||||
Reference in new issue
Block a user