First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
$ValidAccess = 2010;
|
||||
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$action = "home";
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team');
|
||||
if (checkPermission($AllowedUserTypes) != 1) {
|
||||
header("Location: /?action=$action&error_code=NOACCESS");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get parameters
|
||||
if (array_key_exists('supplier_num',$_GET)) $selected_supplier_num = intval($_GET['supplier_num']);
|
||||
if (array_key_exists('supplier_num',$_POST)) $selected_supplier_num = intval($_POST['supplier_num']);
|
||||
if (array_key_exists('selected_menus',$_GET)) $selected_menus = $_GET['selected_menus'];
|
||||
if (array_key_exists('selected_menus',$_POST)) $selected_menus = $_POST['selected_menus'];
|
||||
if (!isset($mode)) $mode = 'detail';
|
||||
unset($schedule_num);
|
||||
|
||||
// Get schedules numbers
|
||||
if (isset($selected_menus) && is_array($selected_menus) && count($selected_menus) > 0) {
|
||||
$menuNumbers = db_escape_string(implode(',',$selected_menus));
|
||||
$results = db_query("SELECT DISTINCT schedule_num FROM hotlunch_menu_dates WHERE record_num IN ($menuNumbers)");
|
||||
if (db_num_rows($results)) {
|
||||
$schedule_num = "";
|
||||
$selected_schedules = array();
|
||||
while ($row = db_fetch_array($results)) {
|
||||
if ($schedule_num) $schedule_num .= ",";
|
||||
$schedule_num .= $row['schedule_num'];
|
||||
$selected_schedules[] = $row['schedule_num'];
|
||||
}
|
||||
}
|
||||
$scheduleNums = $schedule_num;
|
||||
}
|
||||
else {
|
||||
header("Location: /?action=$action&error_code=NOSCHED");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that there are orders for these schedules
|
||||
$num = db_getVal("select count(*) from hotlunch_order_header where school_num = $school_num and schedule_num IN ($schedule_num) and ordered_by_type != 'Concession' and status NOT IN ('Inactive','Deleted')");
|
||||
if ($num == 0) {
|
||||
header("Location: /?action=$action&error_code=NOORDERS");
|
||||
return;
|
||||
}
|
||||
|
||||
// Post supplier orders for each schedule
|
||||
for ($i = 0; $i < count($selected_menus); $i++) {
|
||||
$curr_menu_num = $selected_menus[$i];
|
||||
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE record_num = $curr_menu_num");
|
||||
include "supplier_orders.post.php";
|
||||
}
|
||||
|
||||
|
||||
$numMenuDates = count($selected_menus);
|
||||
$firstMenuDate = $selected_menus[0];
|
||||
$menuNumbers = implode(',',$selected_menus);
|
||||
|
||||
|
||||
// Check the class_num value for staff to ensure that every staff person has a valid class number
|
||||
$query = "SELECT * FROM people WHERE school_num = $base_school_num AND class_num IS NULL";
|
||||
$results = db_query($query);
|
||||
if (db_num_rows($results)) {
|
||||
while ($row = db_fetch_assoc($results)) {
|
||||
$rnum = $row['record_num'];
|
||||
db_query("UPDATE people SET class_num = 0 WHERE school_num = $base_school_num AND class_num IS NULL AND record_num = $rnum");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get set of suppliers to process
|
||||
$swhere = "";
|
||||
if (isset($selected_supplier_num)) $swhere = "and soh.supplier_num = $selected_supplier_num ";
|
||||
$query = "select supplier_name,supplier_num,delivery_date,menu_date,soh.record_num as supplier_order_num " .
|
||||
"from supplier_order_header as soh, suppliers as s, hotlunch_menu_dates as hlmd " .
|
||||
"where soh.school_num = $school_num " .
|
||||
"and s.school_num = $supplier_school_num " .
|
||||
"and hlmd.school_num = $school_num " .
|
||||
"and soh.schedule_num IN ($schedule_num) " .
|
||||
"and soh.menu_num in ($menuNumbers) " .
|
||||
"and soh.menu_num = hlmd.record_num " .
|
||||
"and soh.supplier_num = s.record_num " .
|
||||
$swhere .
|
||||
"order by supplier_name,menu_date";
|
||||
$orders = db_query($query);
|
||||
|
||||
|
||||
// Ensure that there are supplier orders to process
|
||||
if (db_num_rows($orders) == 0) {
|
||||
$error_message = "Error: No Orders Found";
|
||||
header("Location: /?action=home&error_code=NOORDERS");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 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=multi-menu-supplier-orders.csv");
|
||||
header('Content-Transfer-Encoding: text');
|
||||
|
||||
echo("\xEF\xBB\xBF");
|
||||
|
||||
|
||||
// Process each order
|
||||
$today = date("D M jS, Y",time());
|
||||
$prev_supplier = 0;
|
||||
$totals = array();
|
||||
$products = array();
|
||||
|
||||
while ($order = db_fetch_array($orders)) {
|
||||
|
||||
extract($order);
|
||||
$order_subtotal = 0;
|
||||
$mdate = date("D M jS, Y",strtotime($menu_date));
|
||||
|
||||
// Print supplier info if this is a new supplier
|
||||
if ($supplier_num != $prev_supplier) {
|
||||
if ($prev_supplier > 0) {
|
||||
echo("\"$prev_supplier_name\",TOTALS," . $totals['qty'] . ",,," . $totals['units'] . "," . $totals['cost'] . "\n");
|
||||
echo("\n\n\n");
|
||||
}
|
||||
$prev_supplier = $supplier_num;
|
||||
$totals = array();
|
||||
|
||||
// Get supplier info
|
||||
$query = "select * from suppliers " .
|
||||
"where school_num = $supplier_school_num " .
|
||||
"AND status = 'Active' " .
|
||||
"and record_num = $supplier_num";
|
||||
$results = db_query($query);
|
||||
$supplier = db_fetch_array($results);
|
||||
extract($supplier);
|
||||
$prev_supplier_name = $supplier_name;
|
||||
|
||||
echo("\"$supplier_name\",\"$today\"\n");
|
||||
echo("Menu Date,Item,Qty Ordered,Pkg Qty,Pkg Cost,Pkg Units,Total Cost\n");
|
||||
}
|
||||
|
||||
// Get and process the order items
|
||||
$query = "SELECT sp.product_name,supplier_product_num,SUM(online_qty) AS online_qty,sp.package_qty,package_cost " .
|
||||
"FROM supplier_order_items as soi, supplier_products as sp " .
|
||||
"WHERE soi.school_num = $school_num " .
|
||||
"AND sp.school_num = $supplier_school_num " .
|
||||
"AND soi.supplier_num = $supplier_num " .
|
||||
"AND soi.supplier_product_num = sp.record_num " .
|
||||
"AND soi.menu_num in ($menuNumbers) " .
|
||||
"GROUP BY 1,2,4,5 " .
|
||||
"ORDER BY sp.sequence,product_name";
|
||||
// "AND soi.order_num = $supplier_order_num " .
|
||||
$order_items = db_query($query);
|
||||
|
||||
while ($row = db_fetch_array($order_items)) {
|
||||
extract($row);
|
||||
$units = intval(($online_qty + $package_qty - 1) / $package_qty);
|
||||
$units = intval(($quantity + $package_qty - 1) / $package_qty);
|
||||
$cost = number_format($units * $package_cost,2);
|
||||
echo("\"$mdate\",\"$product_name\",$online_qty,$package_qty,$package_cost,$units,$cost\n");
|
||||
|
||||
$totals['qty'] += $online_qty;
|
||||
$totals['units'] += $units;
|
||||
$totals['cost'] += $cost;
|
||||
|
||||
$products[$supplier_product_num]['qty'] += $online_qty;
|
||||
$products[$supplier_product_num]['product_name'] = $product_name;
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
echo("\"$supplier_name\",TOTALS," . $totals['qty'] . ",,," . $totals['units'] . "," . $totals['cost'] . "\n");
|
||||
|
||||
echo("\n");
|
||||
|
||||
echo("PRODUCT TOTALS,Product,Qty Ordered\n");
|
||||
foreach ($products as $key => $value) {
|
||||
echo("," . $products[$key]['product_name'] . ",".$products[$key]['qty'] . "\n");
|
||||
}
|
||||
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user