= 0; $i--) { $headings[] = $SchedulesSequence[$i]['schedule_name']; } $headings[] = getLanguageText('TEXT-TOTAL-ITEMS'); $headings[] = ""; $headings[] = getLanguageText('TEXT-PACKAGE-COST'); $headings[] = getLanguageText('TEXT-PACKAGE-QUANTITY'); $headings[] = getLanguageText('TEXT-TOTAL-COST'); $headings[] = getLanguageText('TEXT-PRICE'); $headings[] = getLanguageText('TEXT-TOTAL-REVENUE'); $headings[] = getLanguageText('TEXT-PROFIT'); $fname = genFileName("supplier-product-sales.csv"); // 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=$fname"); header('Content-Transfer-Encoding: text'); echo("\xEF\xBB\xBF"); // Get selected supplier(s) $suppliers = db_query("SELECT * FROM suppliers WHERE school_num = $supplier_school_num and status = 'Active' $swhere ORDER BY supplier_name"); while ($row = db_fetch_array($suppliers)) { extract($row); $supplier_num = $record_num; // Get supplier products $products = db_query("SELECT * " . "FROM supplier_products " . "WHERE school_num = $supplier_school_num " . "AND supplier_num = $supplier_num " . "AND status = 'Active' " . "AND product_type = 'Product' " . "ORDER BY sequence"); $num_products = db_num_rows($results) . ' ' . getLanguageText('TEXT-PRODUCTS'); $count = 0; $curr_row = $max_rows + 10; if ($num_products > 0) { echo(str_replace('"','""',$supplier_name)."\n"); echo(","); for ($i = 0; $i < count($headings); $i++) { echo(str_replace('"','""',$headings[$i]).","); } echo("\n"); while ($row = db_fetch_assoc($products)) { echo('"'.str_replace('"','""',$row['product_name']).'",'); $product_num = $row['record_num']; $total = 0; for ($i = 0; $i < count($SchedulesSequence); $i++) { $snum = $SchedulesSequence[$i]['record_num']; $query = "SELECT sum(qty) FROM hotlunch_order_items AS hloi, hotlunch_menu_products AS hlmp, hotlunch_menu_items AS hlmi, hotlunch_menu_dates AS hlmd, hotlunch_order_header AS hloh " . "WHERE hloi.school_num = $school_num " . "AND hlmi.school_num = $school_num " . "AND hlmd.school_num = $school_num " . "AND hlmp.school_num = $school_num " . "AND hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND hloh.schedule_num = hloi.schedule_num " . "AND hloi.order_num = hloh.record_num " . "AND hloi.ordered_by_num = hloh.ordered_by_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloi.menu_item_num = hlmp.menu_item_num " . "AND hloi.active = 'Y' " . "AND hlmp.supplier_product_num = $product_num " . "AND hlmp.menu_item_num = hlmi.record_num " . "AND hlmi.menu_num = hlmd.record_num " . "AND hlmd.schedule_num = $snum"; $qty = db_getVal($query); $total += $qty; echo("$qty,"); } echo("$total,"); echo(","); echo('"'.$currencySymbol.number_format($row['package_cost'],2).'",'); echo(number_format($row['package_qty'],0).","); $units = intval(($total + $row['package_qty'] - 1) / $row['package_qty']); $cost = $units * $row['package_cost']; echo('"'.$currencySymbol.number_format($cost,2).'",'); echo('"'.$currencySymbol.number_format($row['standard_online_price'],2).'",'); $revenue = $total * $row['standard_online_price']; echo('"'.$currencySymbol.number_format($revenue,2).'",'); $profit = $revenue - $cost; echo('"'.$currencySymbol.number_format($profit,2).'",'); $count++; echo("\n"); } } echo("\n"); } ?>