183 lines
5.4 KiB
PHP
183 lines
5.4 KiB
PHP
<?php
|
|
|
|
// Set default timezone
|
|
date_default_timezone_set("Canada/Pacific");
|
|
$now = date("Y-m-d H:i:s",time());
|
|
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
logExit("Session is not active",$moduleName);
|
|
exit;
|
|
}
|
|
|
|
// CSRF token validation
|
|
include "include/ajax.csrfToken.php";
|
|
|
|
|
|
|
|
$ValidAccess = 2010;
|
|
$sessionName = 'hotlunch';
|
|
session_name($sessionName);
|
|
session_start();
|
|
require_once("include/globals.php");
|
|
|
|
|
|
$moduleName = "ajax.PostPaid.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
|
|
$return_data = array();
|
|
|
|
// Get parameters
|
|
$school_num = intval($_GET['school_num']);
|
|
$invoice_num = intval($_GET['invoice_num']);
|
|
$method = db_escape_string($_GET['method']);
|
|
|
|
// Ensure parameters are valid
|
|
|
|
|
|
if (!is_numeric($school_num)) logExit("School num is not numeric",$moduleName);
|
|
if (!is_numeric($invoice_num)) logExit("Invoice num is not numeric",$moduleName);
|
|
if ($school_num == 0) logExit("school_num is zero",$moduleName);
|
|
|
|
writeLog("school_num: $school_num");
|
|
writeLog("invoice_num: $invoice_num");
|
|
|
|
|
|
// Get school name
|
|
$query = "SELECT * FROM schools WHERE record_num = $school_num";
|
|
writeLog("query: $query");
|
|
$results = db_query($query);
|
|
$school = db_fetch_assoc($results);
|
|
$school_name = $school['school_name'];
|
|
$currency = 'CAD';
|
|
if ($school['country'] == 'USA') $currency = 'USD';
|
|
|
|
|
|
// Get invoice record
|
|
$query = "SELECT * FROM invoice_header WHERE school_num = $school_num AND record_num = $invoice_num";
|
|
writeLog("query: $query");
|
|
$results = db_query($query);
|
|
$invoice = db_fetch_assoc($results);
|
|
|
|
$renewal_date = $invoice['renewal_date'];
|
|
$school_num = $invoice['school_num'];
|
|
$amount = $invoice['total'];
|
|
$invoice_record_num = $invoice['record_num'];
|
|
|
|
$today = date("Y-m-d",time());
|
|
$query = "UPDATE invoice_header SET amount_paid = total, status = 'Paid', payment_date = '$today', payment_method = '$method' WHERE record_num = $invoice_record_num";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
// Update the renewal date for the school
|
|
$renewal_date = date("Y-m-d",strtotime($renewal_date) - 60 * 60 * 12);
|
|
writeLog("renewal_date: $renewal_date");
|
|
$edate = db_getVal("SELECT expiry_date FROM schools WHERE record_num = $school_num");
|
|
writeLog("edate: $edate");
|
|
|
|
if ($renewal_date > $edate) {
|
|
$query = "UPDATE schools SET expiry_date = '$renewal_date' WHERE record_num = $school_num";
|
|
writeLog($query);
|
|
db_query($query);
|
|
}
|
|
|
|
|
|
// Update school record that the invoice has been paid
|
|
$query = "UPDATE schools SET renewal_invoice_paid = 'Y' WHERE record_num = $school_num";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
// Get country
|
|
$school_country = db_getVal("SELECT country FROM schools WHERE record_num = $school_num");
|
|
$currency = 'CAD';
|
|
if ($school_country == 'USA') $currency = 'USD';
|
|
|
|
//
|
|
// Save payment info for deposit report
|
|
//
|
|
$table = new Table("invoice_payments");
|
|
|
|
$invoice_num = $invoice_record_num + 500;
|
|
$entered = time();
|
|
$payment_date = date("Y-m-d",$entered);
|
|
$batch_num = 0;
|
|
|
|
$entry = array();
|
|
$entry['school_num'] = $school_num;
|
|
$entry['invoice_num'] = $invoice_num;
|
|
$entry['payment_date'] = $payment_date;
|
|
$entry['entered'] = $entered;
|
|
$entry['amount'] = $amount;
|
|
$entry['currency'] = $currency;
|
|
$entry['group_with_next'] = 'N';
|
|
$entry['batch_num'] = 0;
|
|
$entry['batch_closed_date'] = NULL;
|
|
$entry['method'] = $method;
|
|
$entry['user_ip'] = $_SERVER["REMOTE_ADDR"];
|
|
|
|
$query = $table->BuildInsert($entry);
|
|
db_query($query);
|
|
|
|
|
|
// Get school info
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
|
$row = db_fetch_array($results);
|
|
$school_name = $row['school_name'];
|
|
$school_status = $row['status'];
|
|
$expiry_date = $row['expiry_date'];
|
|
$system_configuration = $row['system_configuration'];
|
|
|
|
|
|
|
|
// Send thank you to school
|
|
include "include/queuemail.php";
|
|
|
|
// Get school contacts
|
|
$contacts = db_query("SELECT * FROM school_contact_list WHERE school_num = $school_num AND contact_email != '' AND contact_email IS NOT NULL ORDER BY sequence");
|
|
$count = 0;
|
|
while ($row = db_fetch_assoc($contacts)) {
|
|
extract($row,MYSQL_ASSOC);
|
|
|
|
$emailMessage = "Hello $contact_name,\n" .
|
|
"\n" .
|
|
"Your payment has been received and posted to your account.\n" .
|
|
"\n" .
|
|
"Do not hesitate to send me an email with any questions or suggestions that you may have.\n" .
|
|
"\n" .
|
|
"School Name: $school_name\n" .
|
|
"School Status: $school_status\n" .
|
|
"Renewal Date: $renewal_date\n" .
|
|
"Configuration: $system_configuration\n" .
|
|
"\n" .
|
|
"Thank You\n" .
|
|
"\n" .
|
|
"Hot Lunches On-Line\n" .
|
|
"(604)996-7181" . "\n" .
|
|
"1-888-9HOTLUNCH (1-888-946-8586)" . "\n" .
|
|
"\n" .
|
|
"support@hotlunches.net\n" .
|
|
"http://www.hotlunches.net/\n\n";
|
|
|
|
$emailRecipient = $contact_name;
|
|
$emailTo = $contact_email;
|
|
$emailReply = "Hot Lunches On-Line";
|
|
$emailFrom = "support@hotlunches.net";
|
|
$emailSubject = "HotLunches.net Payment Received From $school_name";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
if ($count == 0) {
|
|
$emailRecipient = "Hot Lunches Online";
|
|
$emailTo = "support@hotlunches.net";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
}
|
|
$count++;
|
|
}
|
|
|
|
|
|
|
|
writeLog("completed");
|
|
?>
|