475 lines
17 KiB
PHP
475 lines
17 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$CurrentTable = "invoice_payments";
|
|
$DeleteField = "school_num,invoice_num,payment_date";
|
|
$dSeparator = " - ";
|
|
$FormFile = "payments.form.php";
|
|
$TitleText = "Payments";
|
|
$OrderBy = "entered";
|
|
$Sequence = 'N';
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = "$TitleText " . getLanguageText('TEXT-ADMINISTRATION');
|
|
$PageTitle = "Insert New";
|
|
$headerArgs = "";
|
|
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
$action = '';
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
include "schools.options.php";
|
|
|
|
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
|
|
switch (strtolower($naction)) {
|
|
case "add":
|
|
$next_naction = "insert";
|
|
$active = 'Y';
|
|
|
|
include $FormFile;
|
|
break;
|
|
|
|
case "insert":
|
|
extract($_POST);
|
|
|
|
include "include/queuemail.php";
|
|
$invoice_num = implode(",",$selected_invoices);
|
|
$entered = time();
|
|
$payment_date = date("Y-m-d",$entered);
|
|
|
|
// Insert primary record
|
|
$table = new Table("$CurrentTable");
|
|
$query = $table->BuildInsert();
|
|
db_query($query);
|
|
|
|
// Flag each invoice
|
|
$payment_details = "";
|
|
|
|
for ($i = 0; $i < count($selected_invoices); $i++) {
|
|
$inum = $selected_invoices[$i];
|
|
|
|
// Get invoice record
|
|
$results = db_query("SELECT * FROM invoice_header WHERE record_num = $inum");
|
|
$invoice = db_fetch_array($results);
|
|
|
|
// Get school
|
|
$snum = $invoice['school_num'];
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $snum");
|
|
$school = db_fetch_array($results);
|
|
$school_name = $school['school_name'];
|
|
|
|
// Update invoice header
|
|
$today = date("Y-m-d",time());
|
|
db_query("UPDATE invoice_header SET amount_paid = total, status = 'Paid', payment_date = '$today' WHERE record_num = $inum");
|
|
$payment_amount = $invoice['billing_amount'];
|
|
if ($currency == 'GBP') $payment_amount = number_format($payment_amount,2) . " GBP";
|
|
else $payment_amount = '$' . number_format($payment_amount,2);
|
|
|
|
if ($notification == 'Multiple') {
|
|
$contact_name = $school['contact_name'];
|
|
$contact_email = $school['contact_email'];
|
|
|
|
$msgType = 'singlePayment';
|
|
include "emailMessage.php";
|
|
|
|
$emailRecipient = $contact_name;
|
|
$emailTo = $contact_email;
|
|
$emailReply = "Hot Lunches OnLine";
|
|
$emailFrom = "support@hotlunches.net";
|
|
$emailSubject = "Hot Lunches On-Line Payment Received from $school_name";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
|
|
$emailRecipient = "Hot Lunches Online";
|
|
$emailTo = "support@hotlunches.net";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
}
|
|
else {
|
|
$payment_details .= "School Name: $school_name\n" .
|
|
"Invoice Number: $inum\n" .
|
|
"Invoice Total: $payment_amount\n\n";
|
|
}
|
|
}
|
|
|
|
// If required send single notification
|
|
if ($notification == 'Single') {
|
|
// Get school
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
|
$school = db_fetch_array($results);
|
|
$school_name = $school['school_name'];
|
|
$contact_name = $school['contact_name'];
|
|
$contact_email = $school['contact_email'];
|
|
|
|
$msgType = 'multiplePayment';
|
|
include "emailMessage.php";
|
|
|
|
$emailRecipient = $contact_name;
|
|
$emailTo = $contact_email;
|
|
$emailReply = "Hot Lunches On-Line";
|
|
$emailFrom = "support@hotlunches.net";
|
|
$emailSubject = "Hot Lunches On-Line Payment Received from $school_name";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
|
|
$emailRecipient = "Hot Lunches Online";
|
|
$emailTo = "support@hotlunches.net";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
}
|
|
|
|
$naction = 'list';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "edit":
|
|
$next_naction = "update";
|
|
|
|
// Get current record
|
|
$record_num = intval($_GET['record_num']);
|
|
|
|
$query = "select * from $CurrentTable where record_num = $record_num";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) == 1) {
|
|
$row = db_fetch_array($results);
|
|
extract($row);
|
|
include $FormFile;
|
|
}
|
|
else {
|
|
$error_message = getLanguageText('RECORD-NOT-FOUND-MSG');
|
|
}
|
|
break;
|
|
|
|
case "update":
|
|
extract($_POST);
|
|
|
|
// Save the invoice header
|
|
$table = new Table("$CurrentTable");
|
|
$query = $table->BuildUpdate();
|
|
db_query($query);
|
|
|
|
$form_message = getLanguageText('RECORD-UPDATED-MSG');
|
|
$naction = "list";
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "close-batch":
|
|
$batch_num = db_getVal("SELECT max(batch_num) FROM invoice_payments");
|
|
$batch_num += 1;
|
|
$today = date("Y-m-d",time());
|
|
db_query("UPDATE invoice_payments SET batch_num = $batch_num, batch_closed_date = '$today' WHERE batch_num = 0");
|
|
|
|
$form_message = "Deposit Batch Has Been Closed";
|
|
$naction = "list";
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "open-batch":
|
|
$batch_num = intval($_GET['batch_num']);
|
|
db_query("UPDATE invoice_payments SET batch_num = 0 WHERE batch_num = $batch_num");
|
|
|
|
$form_message = "Deposit Batch Has Been Opened";
|
|
$naction = "list";
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
case "delete":
|
|
$record_num = intval($_GET['record_num']);
|
|
|
|
$query = "select * from $CurrentTable where record_num = $record_num";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) == 1) {
|
|
$row = db_fetch_array($results);
|
|
extract($row);
|
|
|
|
$dFields = explode(",",$DeleteField);
|
|
$dTitle = "$TitleText ";
|
|
for ($i = 0; $i < count($dFields); $i++) {
|
|
$dTitle .= $row[$dFields[$i]] . $dSeparator;
|
|
}
|
|
|
|
include "delete.form.php";
|
|
}
|
|
else {
|
|
$error_message = "Error: Record Not Found";
|
|
}
|
|
break;
|
|
|
|
case "delete-confirmed":
|
|
$record_num = intval($_GET['record_num']);
|
|
|
|
// Delete the current record
|
|
db_query("delete from $CurrentTable where record_num = $record_num");
|
|
|
|
$form_message = getLanguageText('RECORD-DELETED-MSG');
|
|
$naction = "list";
|
|
header("Location: /?action=$action&naction=$naction&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
|
|
|
|
// Get school record
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
|
$row = db_fetch_array($results);
|
|
extract($row);
|
|
|
|
$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. If you can\n" .
|
|
"write a testimonial about how the system was to use I would appreciate it.\n" .
|
|
"\n" .
|
|
"School Name: $school_name\n" .
|
|
"Payment Amount: $payment_amount\n" .
|
|
"\n" .
|
|
"Thank You\n" .
|
|
"\n" .
|
|
"Hot Lunches Online\n" .
|
|
"(604)996-7181\n" .
|
|
"1-888-9-HOTLUNCH (1-888-475-6657)\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 = "Hot Lunches On-Line Payment Received from $school_name";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
|
|
$emailRecipient = "Hot Lunches Online";
|
|
$emailTo = "support@hotlunches.net";
|
|
|
|
QueueEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply, $emailRecipient);
|
|
|
|
|
|
$form_message = "Invoice has been updated: $school_name - #$inum";
|
|
|
|
$naction = "list";
|
|
break;
|
|
|
|
case "group-with-next":
|
|
$record_num = $_GET['record_num'];
|
|
db_query("UPDATE $CurrentTable SET group_with_next = 'Y' WHERE record_num = $record_num");
|
|
|
|
$naction = "list";
|
|
break;
|
|
|
|
case "ungroup-payment":
|
|
$record_num = $_GET['record_num'];
|
|
db_query("UPDATE $CurrentTable SET group_with_next = 'N' WHERE record_num = $record_num");
|
|
|
|
$naction = "list";
|
|
break;
|
|
|
|
default:
|
|
$naction = "list";
|
|
break;
|
|
}
|
|
|
|
|
|
//
|
|
// List all records if naction is "list"
|
|
//
|
|
if ($naction == "list" || $naction == 'list-all') {
|
|
|
|
// Get records to display
|
|
$columnHeaders = array("School","Invoice(s)","Payment Date","Group","Batch","Amount","Currency","Group Total");
|
|
$columnAlign = array('left','center','center','center','center','center','center','center','right');
|
|
|
|
// Sort order
|
|
$OrderBy = "order by batch_num,currency,entered";
|
|
|
|
|
|
// Display only selected payments
|
|
$swhere = "";
|
|
if (array_key_exists('selected_batch',$_GET)) {
|
|
$selected_batch = $_GET['selected_batch'];
|
|
$swhere .= " and batch_num = $selected_batch ";
|
|
}
|
|
|
|
if (array_key_exists('show',$_GET) && $_GET['show'] == 'Current' || ($naction == 'list' && !isset($selected_batch))) {
|
|
$swhere = " and batch_num = 0 ";
|
|
$TitleText = "Current $TitleText";
|
|
$openList = true;
|
|
}
|
|
|
|
if (array_key_exists('selected_school_num',$_GET) && strlen($_GET['selected_school_num']) > 0) {
|
|
$selected_school = $_GET['selected_school_num'];
|
|
$swhere .= " and school_num = $selected_school ";
|
|
$TitleText = "$school_name $TitleText";
|
|
}
|
|
|
|
// Get set of records to display
|
|
$query = "select school_name,url,invoice_num,payment_date,amount,currency,group_with_next,batch_num,p.record_num,p.school_num " .
|
|
"from schools as s,invoice_payments as p " .
|
|
"where s.record_num = p.school_num " .
|
|
$swhere .
|
|
$OrderBy;
|
|
$results = db_query($query);
|
|
|
|
// Initialize loop parameters
|
|
$data = array();
|
|
$otipSpans = "";
|
|
$gnum = -1;
|
|
$group_total = 0;
|
|
$count = 0;
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
extract($row);
|
|
|
|
if ($batch_num != $gnum) {
|
|
$group_total = 0;
|
|
$gnum = $batch_num;
|
|
}
|
|
|
|
$group_total += $amount;
|
|
if ($group_with_next == 'Y') $group_with_next = "<span class='error'> $group_with_next </span>";
|
|
|
|
$irnum = $invoice_num - 500;
|
|
|
|
$data[] = array("<a href='http://$url' target='_blank'><b>$school_name</b></a>",
|
|
"<a href='#' class='ezs-link' snum='$school_num' inum='$irnum' amt='$amount'>$invoice_num</a>",
|
|
$payment_date,
|
|
$batch_num,
|
|
"$" . number_format($amount,2),
|
|
$currency,
|
|
$group_with_next,
|
|
"$" . number_format($group_total,2),
|
|
"record_num" => $record_num);
|
|
|
|
$count++;
|
|
}
|
|
|
|
|
|
$group_icon = "<img src='images/icons/addfile24.png' alt='Group With Next' border='0'>";
|
|
$ungroup_icon = "<img src='images/icons/deletefile24.png' alt='Ungroup Payment' border='0'>";
|
|
|
|
$commands = array(
|
|
"<a href='?action=payments&naction=group-with-next&record_num=%d'>$group_icon</a>",
|
|
"<a href='?action=payments&naction=ungroup-payment&record_num=%d'>$ungroup_icon</a>"
|
|
);
|
|
|
|
$message_width = $default_data_width;
|
|
include "form.messages.php";
|
|
|
|
echo("<center>\n");
|
|
echo("<p><b>$TitleText List</b></p>\n");
|
|
echo("</center>\n");
|
|
|
|
$insertNew = 'Y';
|
|
listData($data,$columnHeaders,$action,$commands,$insertNew,$columnAlign);
|
|
|
|
if ($count > 0) {
|
|
?>
|
|
<center>
|
|
<table cellspacing='1' cellpadding='1' border='0'>
|
|
<tr>
|
|
<td align='center'><a href='?action=payments-print' class='btn btn--primary btn--xsmall'>Deposit Report</a></td>
|
|
<?php
|
|
if (array_key_exists('selected_batch',$_GET)) {
|
|
$selected_batch = $_GET['selected_batch'];
|
|
?>
|
|
<td align='center'><a href='?action=payments&naction=open-batch&batch_num=<?php echo($selected_batch) ?>' class='btn btn--primary btn--xsmall'>Open Batch</a></td>
|
|
<?php
|
|
}
|
|
else {
|
|
?>
|
|
<td align='center'><a href='?action=payments&naction=close-batch' class='btn btn--primary btn--xsmall'>Close Batch</a></td>
|
|
<?php
|
|
}
|
|
?>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<br>
|
|
<?php
|
|
}
|
|
|
|
|
|
// List previous batches with approximate totals
|
|
$columnHeaders = array("Batch Num","Closed","CAD","US","GBP");
|
|
$columnAlign = array('center','center','center','center','center');
|
|
$results = db_query("SELECT DISTINCT batch_num,batch_closed_date FROM invoice_payments WHERE batch_num > 0 ORDER BY batch_num DESC");
|
|
|
|
$data = array();
|
|
while ($row = db_fetch_array($results)) {
|
|
extract($row);
|
|
|
|
$cad = '$' . number_format(floatval(db_getVal("SELECT sum(amount) FROM invoice_payments WHERE batch_num = $batch_num AND currency = 'CAD'")),2);
|
|
$usd = '$' . number_format(floatval(db_getVal("SELECT sum(amount) FROM invoice_payments WHERE batch_num = $batch_num AND currency = 'USD'")),2);
|
|
$gbp = '£' . number_format(floatval(db_getVal("SELECT sum(amount) FROM invoice_payments WHERE batch_num = $batch_num AND currency = 'GBP'")),2);
|
|
|
|
$data[] = array($batch_num,$batch_closed_date,$cad,$usd,$gbp,"record_num" => $batch_num);
|
|
}
|
|
|
|
$commands = array(
|
|
"<a href='?action=payments&selected_batch=%d'>$view_icon_small</a>",
|
|
"<a href='?action=payments-print&batch_num=%d'>$print_icon_small</a>",
|
|
);
|
|
$default_data_width = 600;
|
|
listDataCustom($data,$columnHeaders,'',$commands,'N',$columnAlign);
|
|
echo("<br>\n");
|
|
|
|
|
|
// Display totals by year
|
|
$columnHeaders = array("School Year","Total","Invoices","Average<br> per Invoice","Schools","Average<br> per School");
|
|
$columnAlign = array('center','right','center','right','center','right');
|
|
$query = "SELECT school_year, sum(total) as total, count(*) as invoices, round(avg(total),2) as average, count(distinct school_num) as schools " .
|
|
"FROM invoice_header " .
|
|
"WHERE status != 'Cancelled' " .
|
|
"GROUP BY 1 ORDER BY 1";
|
|
$results = db_query($query);
|
|
|
|
$data = array();
|
|
$grand_total = 0;
|
|
while ($row = db_fetch_array($results)) {
|
|
extract($row);
|
|
$grand_total += $total;
|
|
$savg = $total / $schools;
|
|
$data[] = array($school_year,
|
|
"$" . number_format($total,2),
|
|
$invoices,
|
|
"$" . number_format($average,2),
|
|
$schools,
|
|
"$" . number_format($savg,2));
|
|
}
|
|
|
|
$totals = array('',"$" . number_format($grand_total,2),'','','','');
|
|
|
|
$default_data_width = 600;
|
|
listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign,$totals);
|
|
echo("<br>\n");
|
|
}
|
|
|
|
include "schools.options.php";
|
|
|
|
endTemplate();
|
|
?>
|