Files
HotLunches/fix.orders.change_log.php
2026-10-19 15:22:52 -07:00

78 lines
2.7 KiB
PHP

<?php
include "db.php";
include "table.php";
$hlohTable = new Table("hotlunch_order_header");
$hloiTable = new Table("hotlunch_order_items");
$cutoff = '2026-09-01';
$school_num = 18402;
$ordered_by_num = 2299767;
$query = "SELECT * FROM hotlunch_order_change_log WHERE updated_time > '$cutoff 00:00:00' AND module = 'hotlunch_reports.php' ORDER BY school_num";
$query = "SELECT * FROM hotlunch_order_change_log WHERE school_num = $school_num AND ordered_by_num = $ordered_by_num";
$query = "SELECT * FROM hotlunch_order_change_log WHERE school_num = $school_num AND updated_time > '$cutoff 00:00:00' ORDER BY ordered_by_num";
$orders = db_query($query);
$num = db_num_rows($orders);
echo("Num Orders: $num\n");
$count = 0;
while ($row = db_fetch_assoc($orders)) {
extract($row);
$oUserNum = $user_num;
if ($oUserNum == 0) continue;
$query = "SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $schedule_num AND ordered_by_num = $ordered_by_num";
$results = db_query($query);
if (db_num_rows($results) == 0) {
$student = 'unknown';
$username = 'unknown';
$person = db_getVal("SELECT * FROM people WHERE record_num = $ordered_by_num");
if (is_array($person)) {
$student = $person['first_name'].' '.$person['last_name'];
$user_num = $person['user_num'];
$user = db_getVal("SELECT * FROM users WHERE record_num = $user_num");
$username = $user['first_name'].' '.$user['last_name'];
}
$count++;
if ($student != 'unknown') echo("$school_num - $student :: $username $oUserNum\n");
echo("Schedule Num: $schedule_num Order Num: $order_num ($status) Person Num: $ordered_by_num\n");
if ($schedule_num > 0) {
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE $school_num = $school_num AND record_num = $schedule_num");
echo("--- $schedule_name\n");
}
$order_items = explode("|||9",$order_detail);
$prev_menu = 0;
for ($i = 0; $i < count($order_items); $i++) {
$entry = $order_items[$i];
if ($i > 0) $entry = '9'.$entry;
$item = explode("|",$entry);
$menu_num = $item[0];
$qty = $item[3];
$price = '$'.$item[4];
$mitem = $item[5];
if ($prev_menu != $menu_num) {
$mtitle = db_getVal("SELECT menu_title FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num = $menu_num");
echo(" --- $mtitle $menu_num\n");
$prev_menu = $menu_num;
}
printf(" %2d %5s %s\n",$qty,$price,$mitem);
}
echo("--------------------------------\n");
}
}
echo("Not Replaced: $count\n");
?>