First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$headerArgs = "";
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator');
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Process all actions to list and edit records
|
||||
//
|
||||
$naction = "";
|
||||
|
||||
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
||||
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
||||
|
||||
if (!isset($menu_num)) $menu_num = 0;
|
||||
$headerArgs = "&schedule_num=$schedule_num&menu_num=$menu_num&naction=$naction";
|
||||
|
||||
|
||||
if (!isset($schedule_num)) {
|
||||
$error_message = getLanguageText('ERRORMSG-MISSING-DATA');
|
||||
$action = 'schedule-reports';
|
||||
$naction = '';
|
||||
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Check if this is a valid schedule
|
||||
$query = "select * from hotlunch_schedules " .
|
||||
"where school_num = $school_num " .
|
||||
"and record_num = $schedule_num";
|
||||
$results = db_query($query);
|
||||
|
||||
if (db_num_rows($results) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
|
||||
$action = 'schedule-reports';
|
||||
$naction = '';
|
||||
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
$hotlunch_schedule = db_fetch_array($results);
|
||||
$schedule_name = $hotlunch_schedule['schedule_name'];
|
||||
|
||||
|
||||
$templatePageTitle = getLanguageText('TEXT-ORDER-UPDATE') . "<br>\n$schedule_name";
|
||||
|
||||
include "hotlunch_reports.menu.php";
|
||||
echo("<br>\n");
|
||||
|
||||
|
||||
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
||||
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
||||
|
||||
$school_num = $school_record['record_num'];
|
||||
|
||||
include "form.messages.php";
|
||||
|
||||
switch (strtolower($naction)) {
|
||||
default:
|
||||
?>
|
||||
<form method='post' id='recalcorders' action='/'>
|
||||
<table width='650' class='content-table'>
|
||||
<tr>
|
||||
<td colspan='2' align='center'><b><?php echo("$schedule_name"); ?></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan='2'> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width='30%' align='right'><?php displayLanguageText('TEXT-LOG-MESSAGE'); ?>:</td>
|
||||
<td align='left'><input type='text' name='logmsg' id='logmsg' size='60'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan='2' align='center'>
|
||||
<br>
|
||||
<input type='submit' value="<?php displayLanguageText('TEXT-UPDATE-ORDERS'); ?>" class='btn btn--primary'>
|
||||
<br>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type='hidden' name='action' id='action' value='order-recalc'>
|
||||
<input type='hidden' name='naction' id='naction' value='recalc'>
|
||||
<input type='hidden' name='schedule_num' id='schedule_num' value='<?php echo($schedule_num) ?>'>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'recalc':
|
||||
$orders = db_query("SELECT hloh.*,p.first_name,p.last_name FROM hotlunch_order_header AS hloh, people AS p " .
|
||||
"WHERE hloh.school_num = $school_num " .
|
||||
"AND p.school_num = $base_school_num " .
|
||||
"AND p.record_num = hloh.ordered_by_num " .
|
||||
"AND hloh.schedule_num = $schedule_num " .
|
||||
"ORDER BY last_name, first_name");
|
||||
echo("<p>" . db_num_rows($orders) . "</p>");
|
||||
?>
|
||||
<table width='650' class='content-table'>
|
||||
<tr class='heading'>
|
||||
<td colspan='2' align='center'><?php displayLanguageText('TEXT-ORDERS-UPDATED'); ?></td>
|
||||
</tr>
|
||||
<tr class='heading'>
|
||||
<td align='left' width='75%'><?php echo($GlobalText['StudentName']); ?></td>
|
||||
<td align='center'><?php displayLanguageText('TEXT-STATUS'); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
$today = date("Y-m-d",time());
|
||||
$count = 0;
|
||||
while ($row = db_fetch_assoc($orders)) {
|
||||
$order_num = $row['record_num'];
|
||||
$source = $row['source'];
|
||||
$price_category = $row['price_category'];
|
||||
|
||||
// Update order item prices
|
||||
$items = db_query("SELECT * FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num");
|
||||
while ($item = db_fetch_assoc($items)) {
|
||||
$menu_item_num = $item['menu_item_num'];
|
||||
$qty = $item['qty'];
|
||||
$rnum = $item['record_num'];
|
||||
|
||||
$results = db_query("SELECT * FROM hotlunch_menu_items WHERE school_num = $school_num AND record_num = $menu_item_num");
|
||||
$mitem = db_fetch_assoc($results);
|
||||
|
||||
switch ($price_category) {
|
||||
case 'Regular':
|
||||
default:
|
||||
$price = $mitem['online_price'];
|
||||
if ($source == 'Paper') $price = $mitem['offline_price'];
|
||||
break;
|
||||
|
||||
case 'Special 1':
|
||||
$price = $mitem['special_price1'];
|
||||
break;
|
||||
|
||||
case 'Special 2':
|
||||
$price = $mitem['special_price2'];
|
||||
break;
|
||||
|
||||
case 'Special 3':
|
||||
$price = $mitem['special_price3'];
|
||||
break;
|
||||
}
|
||||
|
||||
$price = sprintf("%0.2f",$price);
|
||||
$extended_price = number_format($price * $qty,2);
|
||||
db_query("UPDATE hotlunch_order_items SET menu_item_price = $price, extended_price = $extended_price WHERE school_num = $school_num AND record_num = $rnum");
|
||||
}
|
||||
|
||||
|
||||
// Get order total
|
||||
$query = "select sum(extended_price) " .
|
||||
"from hotlunch_order_items " .
|
||||
"where school_num = $school_num " .
|
||||
"and order_num = $order_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and active != 'N'";
|
||||
$order_subtotal = db_getVal($query);
|
||||
|
||||
// Get order
|
||||
$pnum = $row['ordered_by_num'];
|
||||
$disc = $row['discount_amount'];
|
||||
$total = $row['order_total'];
|
||||
$paid = $row['amount_paid'];
|
||||
$status = $row['status'];
|
||||
$order_total = $order_subtotal;
|
||||
|
||||
$amount_paid = $paid;
|
||||
if ($status == 'Paid' || $total == $paid || $paid > $order_total) $amount_paid = $order_total;
|
||||
|
||||
// Calculate new order total
|
||||
$order_subtotal = floatval($order_subtotal);
|
||||
$order_total = floatval($order_total);
|
||||
$amount_paid = floatval($amount_paid);
|
||||
|
||||
if ($disc > 0 && $order_subtotal > $disc) $order_total = $order_subtotal - $disc;
|
||||
$order_subtotal = number_format($order_subtotal,2);
|
||||
$order_total = number_format($order_total,2);
|
||||
$amount_paid = number_format($amount_paid,2);
|
||||
|
||||
// Log the change in order total
|
||||
$change_amount = $order_total - $total;
|
||||
if ($change_amount != 0 && strlen($logmsg)) {
|
||||
$totals = calcOrderTotal($order_num,$schedule_num,'Y');
|
||||
$user_num = db_getVal("SELECT user_num FROM people WHERE school_num = $base_school_num AND record_num = $pnum");
|
||||
$entered_time = time();
|
||||
$trx_time = date("Y-m-d H:i:s",$entered_time);
|
||||
if (strlen($logmsg)) {
|
||||
$lognote = db_escape_string("#$order_num: $currencySymbol" . number_format($change_amount,2));
|
||||
$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,transaction_status) " .
|
||||
"VALUES ($school_num,$user_num,$schedule_num,'$trx_time','TRX Note','$logmsg - $lognote',0,0,NULL,'',NULL,'N',$entered_time,'Closed')";
|
||||
db_query($query);
|
||||
$rnum = db_insert_id();
|
||||
|
||||
$additional_note = "#$order_num - " . getLanguageText('TEXT-PREVIOUS-ORDER-TOTAL') . ": $currencySymbol" . $total . ' => ' . getLanguageText('TEXT-NEW-ORDER-TOTAL') . ": $currencySymbol" . $totals['order_total'];
|
||||
db_query("UPDATE user_account SET additional_note = '" . db_escape_string($additional_note) . "' WHERE record_num = $rnum");
|
||||
}
|
||||
|
||||
$ototal = $totals['order_total'];
|
||||
db_query("UPDATE hotlunch_order_header SET order_total = $ototal WHERE school_num = $school_num AND record_num = $order_num");
|
||||
|
||||
$status = getLanguageText('TEXT-UPDATED');
|
||||
}
|
||||
else {
|
||||
$status = " - ";
|
||||
}
|
||||
|
||||
|
||||
// Get person's name
|
||||
$name = $row['first_name'] . ' ' . $row['last_name'];
|
||||
|
||||
$class = 'data-odd';
|
||||
if ($count % 2) $class = 'data-even';
|
||||
$count++;
|
||||
?>
|
||||
<tr class='<?php echo($class) ?>'>
|
||||
<td align='left'><?php echo($name) ?></td>
|
||||
<td align='center'><?php echo($status) ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
?>
|
||||
<?php include "hotlunch_orders.print_buttons.php"; ?>
|
||||
|
||||
<?php
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user