0) { $sclasses = ""; while ($row = db_fetch_array($results)) { // if ($row['class_num'] > 2) { if (strlen($sclasses)) $sclasses .= ","; $sclasses .= $row['class_num']; // } } if (strlen($sclasses)) $cwhere = "AND c.record_num IN ($sclasses) "; } } // Process the menu_num field if (is_array($selected_menu_num)) $selected_menu_num = db_escape_string(implode(",",$selected_menu_num)); else $selected_menu_num = db_escape_string($selected_menu_num); // Check if this is a valid schedule $swhere = ""; if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num']; $query = "select * from hotlunch_schedules " . "where record_num = $schedule_num " . "and school_num = $school_num $swhere"; $results = db_query($query); if (db_num_rows($results) == 0) { header("Location: /?action=$action&error_code=INVALIDSCHED"); return; } $hotlunch_schedule = db_fetch_array($results); // If this is a ScheduleTeam user check if they have permission to access this schedule if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) { $userNum = $_SESSION['UserInfo']['record_num']; $access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum"); if (!$access || $access == 0) { echo("
\n"); $error_message = getLanguageText('TEXT-NO-ACCESS-TO-SCHEDULE'); include "form.messages.php"; return; } } // Get set of menu items for this date $query = "SELECT hlmi.*,hlmd.menu_title,hlmd.sequence AS menu_sequence,hlmd.menu_date " . "FROM hotlunch_menu_items as hlmi, hotlunch_menu_dates as hlmd " . "WHERE hlmi.school_num = $school_num " . "AND hlmi.menu_num IN ($selected_menu_num) " . "AND hlmi.menu_num = hlmd.record_num " . "ORDER BY menu_sequence,menu_date,sequence"; writeLog($query); $results = db_query($query); if (db_num_rows($results) == 0) { header("Location: /?action=$action&error_code=NOMENUITEMS"); return; } $query = "UPDATE supplier_products SET package_qty = 1 WHERE school_num = $supplier_school_num AND (package_qty = 0 OR package_qty IS NULL)"; db_query($query); $menu_items = array(); $count = 0; while ($row = db_fetch_array($results)) { extract($row); if ($item_type == 'Heading') continue; else { writeLog("menu_title: $menu_title"); $menu_items[$count]['menu_title'] = $menu_title; $menu_items[$count]['menu_date'] = $menu_date; $menu_items[$count]['title'] = $item_title; if (strlen($label_title) > 0) $menu_items[$count]['title'] = $label_title; $menu_items[$count]['num'] = $record_num; $menu_items[$count]['oprice'] = $online_price; $menu_items[$count]['pprice'] = $offline_price; $menu_items[$count]['price1'] = $special_price1; $menu_items[$count]['price2'] = $special_price2; $menu_items[$count]['price3'] = $special_price3; $menu_items[$count]['oqty'] = 0; $menu_items[$count]['pqty'] = 0; $menu_items[$count]['revenue'] = 0; $query = "SELECT sum(package_cost / package_qty) FROM supplier_products,hotlunch_menu_products " . "WHERE hotlunch_menu_products.school_num = $school_num " . "AND supplier_products.school_num = $supplier_school_num " . "AND hotlunch_menu_products.menu_item_num = $record_num " . "AND supplier_products.record_num = hotlunch_menu_products.supplier_product_num"; writeLog($query); $cost = floatval(db_getVal($query)); writeLog("cost: $cost"); $cost = round(100 * $cost,0) / 100; writeLog("cost: $cost"); $menu_items[$count]['cost'] = $cost; $count++; } } $cols = count($menu_items); // Initialize the spreadsheet document type header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header("Content-type: application/octet-stream; charset=utf-8"); header("Content-Disposition: attachment; filename=details-spreadsheet.csv"); header('Content-Transfer-Encoding: text'); echo("\xEF\xBB\xBF"); $school_name = $school_record['school_name']; echo("\"$school_name\"\n"); $offset = ""; if ($school_record['collect_student_number'] == 'Y') $offset = ","; // // Output the menu title and dates // writeLog("mode: $mode"); if ($mode == 'detail') { $offset = ",,"; $offset = ""; echo(",$offset"); } $prev_menu_title = ""; for ($i = 0; $i < count($menu_items); $i++) { if ($sort_by == 'Alphabetically') echo(","); echo(","); if ($menu_items[$i]['menu_title'] != $prev_menu_title) echo('"' . str_replace('"','""',$menu_items[$i]['menu_title']) . '"'); $prev_menu_title = $menu_items[$i]['menu_title']; } echo("\n"); if ($hotlunch_schedule['display_menu_date'] == 'Y') { if ($mode == 'detail') { if ($sort_by == 'Alphabetically') echo(","); echo(",$offset"); } $prev_menu_date = ""; for ($i = 0; $i < count($menu_items); $i++) { echo(","); if ($menu_items[$i]['menu_date'] != $prev_menu_date) echo('"' . $menu_items[$i]['menu_date'] . '"'); $prev_menu_date = $menu_items[$i]['menu_date']; } echo("\n"); } // // Output the menu items titles // $menuItemTitles = ""; for ($i = 0; $i < count($menu_items); $i++) { if (strlen($menuItemTitles)) $menuItemTitles .= ","; $menuItemTitles .= '"' . str_replace('"','""',$menu_items[$i]['title']) . '"'; } writeLog("MODE: $mode"); if ($mode == 'detail') { echo(","); if (!isset($classes) || !is_array($classes) || count($classes) == 0) { if ($school_record['collect_student_number'] == 'Y') { echo("\"" . getLanguageText('TEXT-NAME') . "\",\"" . getLanguageText('TEXT-STUDENT-NUMBER') . "\",\"" . $GlobalText['Class'] . "\",\"" . getLanguageText('TEXT-TYPE') . "\",\"" . getLanguageText('TEXT-DATE-ADDED') . "\",\"" . getLanguageText('TEXT-PAID-DATE') . "\",$menuItemTitles"); } else { echo("\"" . getLanguageText('TEXT-NAME') . "\",\"" . $GlobalText['Class'] . "\",\"" . getLanguageText('TEXT-TYPE') . "\",\"" . getLanguageText('TEXT-DATE-ADDED') . "\",\"" . getLanguageText('TEXT-PAID-DATE') ."\",$menuItemTitles"); } } echo("\n"); } else { echo($GlobalText['Class'].",$offset$menuItemTitles"); echo("\n"); } if ($sort_by == 'ClassNoBreaks') $sort_by = 'Class'; // Get list of classes if ($sort_by == 'Class' || $sort_by == 'ClassNoBreaks') { $query = "select c.*,program_name from classes as c left join class_programs as cp on c.class_program = cp.record_num " . "where c.school_num = $base_school_num " . $cwhere . "order by sequence"; $cresults = db_query($query); $count = 0; if (db_num_rows($cresults)) { $classes = array(); while ($class = db_fetch_array($cresults)) { $entry = array(); $class_num = $class['record_num']; // $classes[$count]['num'] = $class_num; $entry['num'] = $class_num; // Get class info for the report $class_info = getClassInfo($class_num,'internal',1); $class_label = $class['label_description']; if (strlen($class_label) > 0) $class_info .= " ($class_label)"; // $classes[$count]['info'] = $class_info; $entry['info'] = $class_info; // $classes[$count]['delivery_group'] = ''; $entry['delivery_group'] = ''; if ($school_record['implement_delivery_groups'] == 'Y') { // $classes[$count]['delivery_group'] = $class['delivery_group']; $entry['delivery_group'] = $class['delivery_group']; } $classes[] = $entry; $count++; } } $entry = array(); $entry['num'] = 0; $entry['info'] = $GlobalText['Staff']; $entry['delivery_group'] = ''; $classes[] = $entry; $entry['num'] = 1; $entry['info'] = getLanguageText('TEXT-CUSTOMER'); $classes[] = $entry; $entry['num'] = 2; $entry['info'] = getLanguageText('TEXT-PARENT'); $classes[] = $entry; } else { $classes = array(); $classes[] = array('num' => 0, 'info' => ''); } // writeLog(print_r($classes,true)); $processed_staff = array(); $division_totals = array(); $division_amounts = array(); $delivery_groups = array(); if ($sort_by == 'ClassNoBreaks') echo(",,,$offset$menuItemTitles\n"); writeLog("school_record['staff_meals_to_classroom']: ".$school_record['staff_meals_to_classroom']); for ($c = 0; $c < count($classes); $c++) { $class_num = $classes[$c]['num']; $class_info = $classes[$c]['info']; writeLog("class_info: $class_info"); $class_group = ''; if (array_key_exists('delivery_group', $classes[$c])) $class_group = $classes[$c]['delivery_group']; writeLog("class_num: $class_num"); writeLog("class_info: $class_info"); if ($mode == 'detail' && is_array($classes) && count($classes) > 0) { $offset = ""; if ($sort_by == 'Alphabetically') $offset = ","; if ($sort_by != 'ClassNoBreaks') echo("\"$class_info\",,$offset$menuItemTitles"); echo(",,,,"); if ($hotlunch_schedule['implement_order_notes'] != 'N') { echo(",".$hotlunch_schedule['order_notes_message']); } if ($hotlunch_schedule['implement_order_notes2'] != 'N') { echo(",".$hotlunch_schedule['order_notes_message2']); } echo("\n"); } // Check where staff meals are sent if ($sort_by == 'Class' || $sort_by == 'ClassNoBreaks') { $cwhere = "and st.class_num = '$class_num' "; $swhere = ""; if ($school_record['staff_meals_to_classroom'] == 'N') { if ($class_num == 0) { $cwhere = ""; $swhere = "and st.people_type = 'Staff' "; } if ($class_num == 2) { $cwhere = "and st.class_num = '$class_num' "; $swhere = "and st.people_type = 'Customer' "; } if ($class_num > 2) { $cwhere = "and st.class_num = '$class_num' "; $swhere = "and st.people_type = 'Student' "; // $swhere = ""; } } writeLog("swhere: $swhere"); // Get set of orders for this menu date if ($reportStudents == 'With Orders') { $query = "select distinct st.first_name,st.last_name,people_type as ptype,hloh.status as status,hloh.ordered_by_num,hloh.source,st.class_num,st.record_num as people_num,user_num," . "menu_price_category,hloh.status,hloh.added_date, hloh.paid_date, hloh.order_total ". "from people as st, hotlunch_order_header as hloh, hotlunch_order_items as hloi " . "where st.school_num = $base_school_num " . "and hloh.school_num = $school_num " . "and hloi.school_num = $school_num " . "and st.record_num = hloh.ordered_by_num " . "and st.record_num = hloi.ordered_by_num " . "and hloh.ordered_by_num = hloi.ordered_by_num " . $cwhere . $swhere . "and hloh.schedule_num = $schedule_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "and hloi.schedule_num = $schedule_num " . "and hloi.menu_num in ($selected_menu_num) " . "and hloi.active = 'Y' " . "and hloh.record_num = hloi.order_num " . "order by ptype desc,last_name,first_name"; } else { $query = "select distinct st.first_name,st.last_name,people_type as ptype,'' as status,st.record_num AS ordered_by_num,'On-Line' AS source,st.class_num,st.record_num as people_num,user_num" . ",menu_price_category,'','', '' ". "from people as st " . "where st.school_num = $base_school_num " . $cwhere . $swhere . "order by ptype desc,last_name,first_name"; } } else { // Get set of orders for this menu date if ($reportStudents == 'With Orders') { $query = "select distinct st.first_name,st.last_name,people_type as ptype,hloh.status as status,hloh.ordered_by_num,hloh.source,st.class_num,st.record_num as people_num,user_num," . "menu_price_category,hloh.status,hloh.added_date, hloh.paid_date, hloh.order_total ". "from people as st, hotlunch_order_header as hloh, hotlunch_order_items as hloi " . "where st.school_num = $base_school_num " . "and hloh.school_num = $school_num " . "and hloi.school_num = $school_num " . "and st.record_num = hloh.ordered_by_num " . "and st.record_num = hloi.ordered_by_num " . "and hloh.schedule_num = $schedule_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "and hloi.schedule_num = $schedule_num " . "and hloi.menu_num in ($selected_menu_num) " . "and hloi.active = 'Y' " . "and hloh.record_num = hloi.order_num " . "order by ptype asc,last_name,first_name"; } else { $query = "select distinct st.first_name,st.last_name,people_type as ptype,'' as status,st.record_num AS ordered_by_num,'On-Line' AS source,st.class_num,st.record_num as people_num,user_num," . "menu_price_category,'','', '' ". "from people as st " . "where st.school_num = $base_school_num " . "order by ptype desc,last_name,first_name"; } } writeLog($query); $people = db_query($query); if (db_num_rows($people)) { // Process each person while ($person = db_fetch_array($people)) { extract($person); $ordered_by_type = $ptype; $order_total = 0; if (isset($order_total)) writeLog("ORDER TOTAL: $order_total +++++++++++++++++++++++++++++++++++++"); if ($mode == 'detail') { if (strlen($last_name)) { $name = $last_name; if (strlen($first_name)) $name .= ", $first_name"; } else $name = $first_name; writeLog("++ NAME: $name"); if ($sort_by == 'ClassNoBreaks') echo("$class_info,"); echo('"' . $name . '"'); echo(","); if ($sort_by == 'Alphabetically') { // $class_info = $classes[$class_num]['info']; $class_info = getClassInfo($class_num,'internal',1); echo("$class_info,"); } if ($school_record['collect_student_number'] == 'Y') { $student_number = db_getVal("SELECT student_number FROM people WHERE school_num = $base_school_num AND record_num = $people_num"); echo($student_number); echo(","); } if (count($classes) == 0) { if ($sort_by != 'Class') $class_info = getClassInfo($class_num); echo('"' . $class_info . '"'); echo(","); } echo('"' . $ordered_by_type . '"'); echo(","); } if ($ordered_by_type == 'Staff') $processed_staff[] = $ordered_by_num; if (!isset($paid_date)) $paid_date = ''; if (!isset($added_date)) $added_date = ''; // echo("$added_date,$paid_date,"); // Get item totals for each person $order_total = 0; for ($i = 0; $i < count($menu_items); $i++) { $menu_item_num = $menu_items[$i]['num']; // Lookup to see if this person has ordered this item $query = "SELECT qty FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " . "WHERE hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND hloh.schedule_num = $schedule_num " . "AND hloh.record_num = hloi.order_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloh.ordered_by_num = $ordered_by_num " . "AND hloi.ordered_by_num = $ordered_by_num " . "AND hloi.schedule_num = $schedule_num " . "AND hloi.menu_item_num = $menu_item_num " . "AND hloi.active = 'Y'"; $mresults = db_query($query); $qty = 0; if (db_num_rows($mresults) == 1) { $mrow = db_fetch_array($mresults); $qty = $mrow['qty']; if ($mode == 'detail') echo($qty); } if ($mode == 'detail') echo(","); if (!isset($division_totals[$class_num][$i])) $division_totals[$class_num][$i] = 0; $division_totals[$class_num][$i] += $qty; if ($class_group != '') { if (!isset($delivery_groups[$class_group][$i])) $delivery_groups[$class_group][$i] = 0; $delivery_groups[$class_group][$i] += $qty; } } if (!isset($division_amounts[$class_num])) $division_amounts[$class_num] = 0; $division_amounts[$class_num] += $order_total; if ($mode == 'detail') echo("$source,\"" . $currencySymbol . number_format($order_total,2) . "\",$status"); if (isset($delivered) && $hotlunch_schedule['schedule_type'] != 'Hot Lunch' && in_array($siteType,array('hotlunch','yearbook','tickets','fundraising'))) echo(",$delivered"); if ($hotlunch_schedule['implement_order_notes'] != 'N') { $order_notes = db_getVal("SELECT order_notes FROM hotlunch_order_header " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status NOT IN ('Inactive','Deleted') " . "AND ordered_by_num = $ordered_by_num"); echo(',"' . $order_notes . '"'); } if ($hotlunch_schedule['implement_order_notes2'] != 'N') { $order_notes2 = db_getVal("SELECT order_notes2 FROM hotlunch_order_header " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status NOT IN ('Inactive','Deleted') " . "AND ordered_by_num = $ordered_by_num"); echo(',"' . $order_notes2 . '"'); } if ($include_parent_info == 'Y') { $info = getContactInfo($user_num); echo(",".$info[0]); echo(",".$info[1]); echo(",".$info[2]); } if ($mode == 'detail') echo("\n"); } } // Spacing between classes if ($mode == 'detail' && count($classes) > 0) echo("\n"); } // // Get other staff orders data // $pwhere = ""; if (count($processed_staff) > 0) $pwhere = "and s.record_num not in (" . implode(",",$processed_staff) . ") "; $query = "select distinct s.first_name,s.last_name,'Staff' as ptype,concat('$currencySymbol',hloh.order_total) as total," . "hloh.status as status,hloh.ordered_by_num,hloh.source,hloh.order_total " . "from people as s, hotlunch_order_header as hloh, hotlunch_order_items as hloi " . "where s.school_num = $base_school_num " . "and hloh.school_num = $school_num " . "and hloi.school_num = $school_num " . "and s.record_num = hloh.ordered_by_num " . "and s.record_num = hloi.ordered_by_num " . "and hloh.ordered_by_num = hloi.ordered_by_num " . "and s.status != 'Inactive' " . "and s.people_type = 'Staff' " . "and hloh.schedule_num = $schedule_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "and hloi.menu_num in ($selected_menu_num) " . "and hloi.active = 'Y' " . "and hloh.record_num = hloi.order_num " . $pwhere . "order by ptype,last_name,first_name"; writeLog("People Query: $query"); $people = db_query($query); if (db_num_rows($people)) { if ($mode == 'detail' && count($classes) > 0) { $offset = ""; if ($sort_by == 'Alphabetically') $offset = ","; if ($school_record['collect_student_number'] == 'Y') echo($GlobalText['Staff']."$offset,,,$menuItemTitles"); else echo($GlobalText['Staff']."$offset,,$menuItemTitles"); echo(",,,,"); if ($hotlunch_schedule['implement_order_notes'] != 'N') { echo(",".$hotlunch_schedule['order_notes_message']); } if ($hotlunch_schedule['implement_order_notes2'] != 'N') { echo(",".$hotlunch_schedule['order_notes_message2']); } echo("\n"); } // Process each person while ($person = db_fetch_array($people)) { extract($person); $ordered_by_type = $ptype; if ($mode == 'detail') { if (strlen($last_name)) { $name = $last_name; if (strlen($first_name)) $name .= ", $first_name"; } else $name = $first_name; writeLog("** Name: $name $order_total"); echo('"' . $name . '"'); echo(",$offset"); if (count($classes) == 0) echo(","); echo('"' . $ordered_by_type . '"'); echo(","); } // Get item totals for each person for ($i = 0; $i < count($menu_items); $i++) { $menu_item_num = $menu_items[$i]['num']; // Lookup to see if this person has ordered this item $query = "select qty from hotlunch_order_items " . "where school_num = $school_num " . "and ordered_by_num = $ordered_by_num " . "and schedule_num = $schedule_num " . "and menu_num in ($selected_menu_num) " . "and menu_item_num = $menu_item_num " . "and active = 'Y'"; $mresults = db_query($query); $qty = 0; if (db_num_rows($mresults) == 1) { $mrow = db_fetch_array($mresults); $qty = $mrow['qty']; if ($mode == 'detail') echo($qty); } if ($mode == 'detail') echo(","); if (!isset($division_totals['Staff'][$i])) $division_totals['Staff'][$i] = 0; $division_totals['Staff'][$i] += $qty; } if (!isset($division_amounts[$class_num])) $division_amounts[$class_num] = 0; $division_amounts[$class_num] += $order_total; if ($mode == 'detail') echo("$source,\"" . $currencySymbol . number_format($order_total,2) . "\""); if ($include_parent_info == 'Y') { echo(",,,"); } if ($mode == 'detail') echo("\n"); } } // Get and process the Concession order $results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_type = 'Concession' AND schedule_num = $schedule_num"); if (db_num_rows($results)) { if ($mode == 'detail') { echo('"'.getLanguageText('TEXT-CONCESSION').'"'); echo(",$offset"); if (count($classes) == 0) echo(","); echo('"'.getLanguageText('TEXT-CONCESSION').'"'); echo(","); } // Get item totals for Concession order for ($i = 0; $i < count($menu_items); $i++) { $menu_item_num = $menu_items[$i]['num']; // Lookup Concession item quantities $query = "select qty from hotlunch_order_items " . "where school_num = $school_num " . "and ordered_by_type = 'Concession' " . "and schedule_num = $schedule_num " . "and menu_num in ($selected_menu_num) " . "and menu_item_num = $menu_item_num " . "and active = 'Y'"; $mresults = db_query($query); $qty = 0; if (db_num_rows($mresults) == 1) { $mrow = db_fetch_array($mresults); $qty = $mrow['qty']; if ($mode == 'detail') echo($qty); } if ($mode == 'detail') echo(","); if (!isset($division_totals['Concession'][$i])) $division_totals['Concession'][$i] = 0; $division_totals['Concession'][$i] += $qty; } } if ($mode == 'detail') echo("\n"); // // Output the division totals // writeLog("SORT_BY: $sort_by"); if ($sort_by == 'Class') { if ($mode == 'detail') { echo("\n"); // Output the menu items titles if (count($classes) == 0) { echo("," . $GlobalText['Class'] . ",,$offset$menuItemTitles"); } else { echo($GlobalText['Class'] . ",,$offset$menuItemTitles"); } } echo("\n"); $grand_totals = array(); foreach ($division_totals as $key => $value) { $class_num = $key; if ($class_num == 'Staff' || $class_num == 'Concession') $class_info = $class_num; else $class_info = getClassInfo($class_num); if ($mode == 'detail') { if (count($classes) == 0) { echo(getLanguageText('TEXT-TOTAL').",$offset\"$class_info\","); } else { echo("\"$class_info\",$offset"); } } else echo("\"$class_info\""); $subtotal = 0; for ($i = 0; $i < count($menu_items); $i++) { echo(","); $div_total = isset($division_totals[$class_num][$i]) ? $division_totals[$class_num][$i] : 0; echo($div_total); if (!isset($grand_totals[$i])) $grand_totals[$i] = 0; $grand_totals[$i] += $div_total; } $total = isset($division_amounts[$class_num]) ? $division_amounts[$class_num] : 0; echo(",,\"" . $currencySymbol . number_format($total,2) . "\"\n"); } // // Output school totals // if ($mode == 'detail') { if (count($classes) == 0) { echo($GlobalText['OrganizationType'] . ",,$offset"); } else { echo(getLanguageText('TEXT-SELECTED-CLASSES-+-STAFF').",$offset"); } } else echo($GlobalText['OrganizationType']); for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo($grand_totals[$i]); } echo("\n"); echo("\n"); //Determine if there are any suppliers $query = "SELECT count(*) FROM suppliers WHERE school_num = $supplier_school_num AND status = 'Active'"; writeLog($query); $numSuppliers = db_getVal($query); writeLog("numSuppliers: $numSuppliers"); if ($numSuppliers > 0) { // Output the item costs echo(getLanguageText('TEXT-ITEM-COST')." \$\$"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,$offset"); } else { echo(",$offset"); } } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo("\"" . $currencySymbol . number_format($menu_items[$i]['cost'],2) . "\""); } echo("\n"); // Output the estimated costs $total = 0; echo(getLanguageText('TEXT-ESTIMATED-COSTS')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) echo(",,"); else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); $cost = $grand_totals[$i] * $menu_items[$i]['cost']; echo("\"" . $currencySymbol . number_format($cost,2) . "\""); $total += $cost; $menu_items[$i]['ctotal'] = $cost; } $total = $currencySymbol . number_format($total,2); echo(",\"$total\""); echo("\n"); echo("\n"); } // Output the on-line prices echo(getLanguageText('TEXT-ON-LINE-PRICE')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo("\"" . $currencySymbol . number_format($menu_items[$i]['oprice'],2) . "\""); } echo("\n"); // Output the on-line qty echo(getLanguageText('TEXT-ON-LINE-QUANTITY-ORDERED')."$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo($menu_items[$i]['oqty']); } echo("\n"); // Output the on-line revenue $ototal = 0; echo(getLanguageText('TEXT-ON-LINE-ORDER-REVENUE')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); $revenue = $menu_items[$i]['oqty'] * $menu_items[$i]['oprice']; $menu_items[$i]['revenue'] += $revenue; echo("\"" . $currencySymbol . number_format($revenue,2) . "\""); $ototal += $revenue; } $ototal = $currencySymbol . number_format($ototal,2); echo(",\"$ototal\""); echo("\n"); echo("\n"); // Output the paper prices echo(getLanguageText('TEXT-PAPER-PRICE')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo("\"" . $currencySymbol . number_format($menu_items[$i]['pprice'],2) . "\""); } echo("\n"); // Output the paper qty echo(getLanguageText('TEXT-QUANTITY-ORDERED')."$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); if ($school_record['collect_student_number'] == 'Y') echo(","); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo($menu_items[$i]['pqty']); } echo("\n"); // Output the paper revenue $ptotal = 0; echo(getLanguageText('TEXT-PAPER-ORDER-REVENUE')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); if ($school_record['collect_student_number'] == 'Y') echo(","); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); $revenue = $menu_items[$i]['pqty'] * $menu_items[$i]['pprice']; $menu_items[$i]['revenue'] += $revenue; echo("\"" . $currencySymbol . number_format($revenue,2) . "\""); $ptotal += $revenue; } $ptotal = $currencySymbol . number_format($ptotal,2); echo(",\"$ptotal\""); echo("\n"); echo("\n"); // Output the total revenue $total = 0; echo(getLanguageText('TEXT-TOTAL-REVENUE')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); if ($school_record['collect_student_number'] == 'Y') echo(","); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); echo("\"" . $currencySymbol . number_format($menu_items[$i]['revenue'],2) . "\""); $total += $menu_items[$i]['revenue']; } $total = $currencySymbol . number_format($total,2); echo(",\"$total\""); echo("\n"); echo("\n"); // Output the estimated profit if ($numSuppliers > 0) { $total = 0; echo(getLanguageText('TEXT-ESTIMATED-PROFIT')." \$\$$offset"); if ($mode == 'detail') { if (count($classes) == 0) { echo(",,"); if ($school_record['collect_student_number'] == 'Y') echo(","); } else echo(","); } for ($i = 0; $i < count($menu_items); $i++) { echo(","); $profit = $menu_items[$i]['revenue'] - $menu_items[$i]['ctotal']; echo("\"" . $currencySymbol . number_format($profit,2) . "\""); $total += $profit; } $total = $currencySymbol . number_format($total,2); echo(",\"$total\""); echo("\n"); } } // // Output the group totals if required // if ($school_record['implement_delivery_groups'] == 'Y') { echo("\n\n"); echo(getLanguageText('TEXT-DELIVERY-GROUPS')); echo(":\n"); ksort($delivery_groups); foreach ($delivery_groups as $g => $group_totals) { $gtitle = $g; $results = db_query("SELECT * FROM delivery_groups WHERE school_num = $base_school_num AND group_id = '$g'"); if (db_num_rows($results)) { $row = db_fetch_assoc($results); $gtitle = $row['group_title']; } echo(',"' . $gtitle . '"' . ",,"); for ($i = 0; $i < count($menu_items); $i++) { $qty = 0; if ($i < count($group_totals) && isset($group_totals[$i])) $qty = number_format($group_totals[$i],0); echo($qty.","); } echo("\n"); } } ?>