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 = " $group_with_next ";
$irnum = $invoice_num - 500;
$data[] = array("$school_name",
"$invoice_num",
$payment_date,
$batch_num,
"$" . number_format($amount,2),
$currency,
$group_with_next,
"$" . number_format($group_total,2),
"record_num" => $record_num);
$count++;
}
$group_icon = "
";
$ungroup_icon = "
";
$commands = array(
"$group_icon",
"$ungroup_icon"
);
$message_width = $default_data_width;
include "form.messages.php";
echo("
$TitleText List
\n"); echo("| Deposit Report | Open Batch | Close Batch |