113 lines
2.6 KiB
PHP
113 lines
2.6 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");
|
|
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.PostEZS.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
|
|
|
|
$return_data = array();
|
|
|
|
// Get parameters
|
|
$school_num = intval($_GET['school_num']);
|
|
$invoice_num = intval($_GET['invoice_num']);
|
|
|
|
// Ensure parameters are valid
|
|
|
|
if (!is_numeric($school_num)) logExit("School num is not numeric");
|
|
if (!is_numeric($invoice_num)) logExit("Invoice num is not numeric");
|
|
if ($school_num == 0) logExit("school_num is zero");
|
|
|
|
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);
|
|
|
|
|
|
$db_host = "polarbear2";
|
|
$db_uname = "ezssoftwaredb";
|
|
$db_pass = "ezs7785422700@@";
|
|
|
|
writeLog("db_uname: $db_uname");
|
|
writeLog("db_pass: $db_pass");
|
|
|
|
db_close($_DB);
|
|
$_DB = mysql_connect($db_host,$db_uname,$db_pass);
|
|
|
|
db_query("SET NAMES utf8");
|
|
db_query("SET CHARACTER SET utf8");
|
|
|
|
db_query("USE schoolappointments");
|
|
|
|
|
|
$payments = new Table("invoice_payments");
|
|
|
|
$note = $school_name;
|
|
$application = "Hot Lunches";
|
|
$invoice_subtotal = $invoice['subtotal'];
|
|
$invoice_gst = $invoice['gst'];
|
|
$invoice_total = $invoice['total'];
|
|
$entered = time();
|
|
$payment_date = date("Y-m-d",$entered);
|
|
$amount = $invoice_total;
|
|
$group_with_next = 'N';
|
|
$batch_num = 0;
|
|
$company = 'EZS Software';
|
|
|
|
$query = $payments->BuildInsert();
|
|
writeLog("query: $query");
|
|
db_query($query);
|
|
|
|
// Check for an open batch
|
|
$batch_message = "";
|
|
$numOpen = db_getVal("SELECT count(*) FROM invoice_payments WHERE batch_num = 0");
|
|
if ($numOpen > 0) {
|
|
$amount = db_getVal("SELECT sum(amount) FROM invoice_payments WHERE batch_num = 0");
|
|
$batch_message = "There is an Open Batch with $numOpen Cheques - $currencySymbol".number_format($amount,2);
|
|
}
|
|
|
|
$return_data['form_message'] = $batch_message;
|
|
|
|
echo(json_encode($return_data));
|
|
writeLog("completed");
|
|
return(0);
|
|
|
|
?>
|