First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) {
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
header("Location: /?error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$school_num = $school_record['record_num'];
|
||||
|
||||
|
||||
// Get schedules for this school
|
||||
$cutoff = date("Y-m-d",time() - 60 * 60 * 24 * 500);
|
||||
$query = "SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND schedule_start_date > '$cutoff'";
|
||||
$results = db_query($query);
|
||||
$Schedules = array();
|
||||
while ($row = db_fetch_assoc($results)) {
|
||||
$snum = $row['record_num'];
|
||||
$Schedules[$snum] = $row;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle selected date ranges
|
||||
$start_date = date("Y-m-d",time());
|
||||
$end_date = date("Y-m-d",time());
|
||||
|
||||
if (array_key_exists('start_date',$_GET) && strlen($_GET['start_date']) > 0) $start_date = $_GET['start_date'];
|
||||
if (array_key_exists('end_date',$_GET) && strlen($_GET['end_date']) > 0) {
|
||||
$end_date = $_GET['end_date'];
|
||||
if ($end_date < $start_date) {
|
||||
$end_date = $start_date;
|
||||
$error_message = "Error: Specified Start Date is After Specified End Date";
|
||||
}
|
||||
}
|
||||
|
||||
$twhere = "AND hloh.added_date BETWEEN '$start_date' AND '$end_date' ";
|
||||
$print_cmd = '';
|
||||
|
||||
|
||||
// View only a selected userid
|
||||
$uwhere = "";
|
||||
unset($selected_usernum);
|
||||
if (array_key_exists('selected_usernum',$_GET) && strlen($_GET['selected_usernum']) > 0) {
|
||||
$selected_usernum = $_GET['selected_usernum'];
|
||||
$uwhere = "AND u.record_num = $selected_usernum ";
|
||||
$print_cmd .= "&selected_usernum=$selected_usernum";
|
||||
}
|
||||
|
||||
|
||||
// View only selected classes
|
||||
unset($selected_class);
|
||||
if (array_key_exists('selected_class',$_GET) && strlen($_GET['selected_class']) > 0) {
|
||||
$selected_class = $_GET['selected_class'];
|
||||
if ($selected_class != 'All') $uwhere .= "AND st.class_num = '$selected_class' ";
|
||||
$print_cmd .= "&selected_class=$selected_class";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Get all requested records
|
||||
//
|
||||
$columnHeaders = array($GlobalText['Class'],
|
||||
$GlobalText['Student'],
|
||||
getLanguageText('TEXT-' . strtoupper($school_record['registrants_are'])),
|
||||
getLanguageText('TEXT-ORDER-NUMBER'),
|
||||
getLanguageText('TEXT-SUBTOTAL'),
|
||||
getLanguageText('TEXT-DISCOUNT'),
|
||||
getLanguageText('TEXT-ORDER-TOTAL'),
|
||||
getLanguageText('TEXT-TAX'),
|
||||
getLanguageText('TEXT-ORDER-NET')
|
||||
);
|
||||
if (array_key_exists('additional_info',$_GET) && $_GET['additional_info'] == 'Y') $columnHeaders[] = getLanguageText('TEXT-ADDITIONAL-INFORMATION');
|
||||
|
||||
$columnHeaders[] = "";
|
||||
$columnHeaders[] = getLanguageText('TEXT-STATUS');
|
||||
$columnHeaders[] = getLanguageText('TEXT-SOURCE');
|
||||
$columnHeaders[] = getLanguageText('TEXT-SCHEDULE');
|
||||
$columnHeaders[] = getLanguageText('TEXT-ORDER-TOTAL');
|
||||
$columnHeaders[] = getLanguageText('TEXT-COST');
|
||||
$columnHeaders[] = getLanguageText('TEXT-PAID');
|
||||
$columnHeaders[] = getLanguageText('TEXT-PROFIT');
|
||||
$columnHeaders[] = getLanguageText('TEXT-PAYMENT-METHOD');
|
||||
|
||||
$query = "SELECT st.class_num,st.first_name,st.last_name,st.record_num AS stnum,u.first_name AS parent_first_name,u.last_name AS parent_last_name,u.record_num AS unum," .
|
||||
"hloh.record_num AS order_num,order_subtotal,discount_amount,order_total,hloh.amount_paid,hloh.order_cost,hloh.status,hloh.source,hloh.schedule_num,payment_method " .
|
||||
"FROM people AS st, users AS u, hotlunch_order_header AS hloh " .
|
||||
"WHERE st.school_num = $base_school_num " .
|
||||
"AND u.school_num = $base_school_num " .
|
||||
"AND st.user_num = u.record_num " .
|
||||
"AND hloh.school_num = $school_num " .
|
||||
"AND hloh.ordered_by_num = st.record_num " .
|
||||
$uwhere . $twhere .
|
||||
"ORDER BY 1,3,2";
|
||||
$transactions = db_query($query);
|
||||
|
||||
$data = array();
|
||||
while ($row = db_fetch_assoc($transactions)) {
|
||||
$tax = 0;
|
||||
$order_num = $row['order_num'];
|
||||
$stnum = $row['stnum'];
|
||||
$unum = $row['unum'];
|
||||
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $unum AND order_num = $order_num AND transaction_type = 'Tax Charge'");
|
||||
if (db_num_rows($results)) {
|
||||
$r = db_fetch_assoc($results);
|
||||
$tax = $r['transaction_amount'];
|
||||
}
|
||||
|
||||
$net = $row['order_total'] + $tax;
|
||||
|
||||
$class_info = getClassInfo($row['class_num']);
|
||||
|
||||
$additional = "";
|
||||
if (array_key_exists('additional_info',$_GET) && $_GET['additional_info'] == 'Y') {
|
||||
$results = db_query("SELECT hlmi.item_title FROM hotlunch_menu_items AS hlmi, hotlunch_order_items AS hloi " .
|
||||
"WHERE hlmi.school_num = $school_num " .
|
||||
"AND hloi.school_num = $school_num " .
|
||||
"AND hlmi.record_num = hloi.menu_item_num " .
|
||||
"AND hloi.order_num = $order_num " .
|
||||
"AND hloi.active != 'N' " .
|
||||
"ORDER BY hlmi.sequence");
|
||||
if (db_num_rows($results)) {
|
||||
while ($r = db_fetch_assoc($results)) {
|
||||
if (strlen($additional)) $additional .= ",";
|
||||
$additional .= $r['item_title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$order_cost = floatval($row['order_cost']);
|
||||
if ($order_cost == 0.00) {
|
||||
// Calculate the order cost
|
||||
$schedule_num = $row['schedule_num'];
|
||||
$query = "select sum(hloi.qty * hlmp.supplier_product_qty * (sp.package_cost / sp.package_qty)) as cost " .
|
||||
"from hotlunch_order_items as hloi, hotlunch_menu_products as hlmp, supplier_products as sp " .
|
||||
"where hloi.school_num = $school_num " .
|
||||
"and hlmp.school_num = $school_num " .
|
||||
"and sp.school_num = $supplier_school_num " .
|
||||
"and hloi.order_num = $order_num " .
|
||||
"and hloi.schedule_num = $schedule_num " .
|
||||
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
||||
"and hlmp.supplier_product_num = sp.record_num";
|
||||
$order_cost = floatval(db_getVal($query));
|
||||
|
||||
$query = "UPDATE hotlunch_order_header SET order_cost = $order_cost WHERE school_num = $school_num AND record_num = $order_num";
|
||||
db_query($query);
|
||||
}
|
||||
|
||||
$profit = $row['order_total'] - $order_cost;
|
||||
if ($row['status'] == 'Complimentary') $profit = -1 * $order_cost;
|
||||
|
||||
$snum = $row['schedule_num'];
|
||||
$sname = $Schedules[$snum]['schedule_name'];
|
||||
|
||||
$data[] = array($class_info,
|
||||
$row['first_name'] . ' ' . $row['last_name'],
|
||||
$row['parent_first_name'] . ' ' . $row['parent_last_name'],
|
||||
$row['order_num'],
|
||||
$currencySymbol . $row['order_subtotal'],
|
||||
$currencySymbol . number_format($row['discount_amount'],2),
|
||||
$currencySymbol . $row['order_total'],
|
||||
$currencySymbol . number_format($tax,2),
|
||||
$currencySymbol . number_format($net,2),
|
||||
$additional,
|
||||
"",
|
||||
$row['status'],
|
||||
$row['source'],
|
||||
$sname,
|
||||
$currencySymbol . number_format($row['order_total'],2),
|
||||
$currencySymbol . number_format($order_cost,2),
|
||||
$currencySymbol . number_format($row['amount_paid'],2),
|
||||
$currencySymbol . number_format($profit,2),
|
||||
$row['payment_method'],
|
||||
);
|
||||
}
|
||||
|
||||
$fname = genFileName("order-details-summary.csv");
|
||||
xlsData($data,$columnHeaders,$fname);
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user