> <?php echo TITLE; ?>
'', 'text' => '---'); while ($orders_list = tep_db_fetch_array($orders_list_query)) { $orders_list_array[] = array('id' => $orders_list['orders_id'], 'text' => $orders_list['orders_id']." - ".tep_date_short($orders_list['date_purchased'])); } echo '  ' . tep_draw_pull_down_menu('start', $orders_list_array, (isset($_GET['orders_id']) ? $_GET['orders_id'] : ''), 'size="1"') . '   '; ?>
 
 
 
= $start ORDER BY orders_id"); // if both fields are filed in we select orders betwenn $start and $end } else { $orders = tep_db_query("SELECT orders_id, date_purchased, customers_name, cc_owner, customers_company, customers_email_address, billing_street_address, billing_city, billing_state, billing_postcode, billing_country, customers_telephone, delivery_name, delivery_company, delivery_street_address, delivery_city, delivery_state, delivery_postcode, delivery_country, cc_type, cc_number, cc_expires FROM orders WHERE orders_id >= $start AND orders_id <= $end ORDER BY orders_id"); } //patch // cache manufacturer list $manufacturers_query = tep_db_query("SELECT manufacturers_id, manufacturers_name from manufacturers"); $all_manufacturers=array(); while ($row_manufacturers = mysql_fetch_array($manufacturers_query)) { $all_manufacturers[$row_manufacturers[0]] = $row_manufacturers[1]; } //$csv_output ="\n"; $all_orders=array(); $all_products=array(); while ($row_orders = mysql_fetch_array($orders)) { $all_orders[] = $row_orders["orders_id"]; } foreach ($all_orders as $order_id) { //Get list of products ordered $orders_products = tep_db_query("select products_id, products_price, products_cost, products_quantity, products_name from orders_products where orders_id = " . $order_id); while($row_orders_products = mysql_fetch_array($orders_products)) { $pid = $row_orders_products[0]; $price = $row_orders_products[1]; $cost = $row_orders_products[2]; $qty = $row_orders_products[3]; $name = $row_orders_products[4]; if (! in_array($pid, $all_products)) { $products = tep_db_query("select products_quantity, products_price, products_cost, manufacturers_id" . " from products where products_id = " . $pid); $row_products = mysql_fetch_array($products); $manufacturer = $all_manufacturers[$row_products[3]]; $stock = $row_products[0]; $margin = $price - $cost; $cost = $row_products[2]; $price = $row_products[1]; $all_products[$pid] = array( "name" => $name, "manufacturer" => $manufacturer, "qty" => $qty, "margin" => $margin, "stock" => $stock, "cost" => $cost, "price" => $price, ); } else { $all_products[$pid]['qty'] += $qty; $all_products[$pid]['margin'] += $margin; } } } // While loop to list the item $currencies = new currencies(); foreach ( $all_products as $id => $one ) { $csv_output .= $id . ";"; $csv_output .= filter_text($one['name']) . ";"; $csv_output .= filter_text($one['manufacturer']) . ";"; $csv_output .= $one['qty'] . ";"; $csv_output .= $currencies->format($one['margin']) . ";"; $csv_output .= $one['stock'] . ";"; $csv_output .= $currencies->format($one['cost']) . ";"; $csv_output .= $currencies->format($one['price']) . "\n"; } // --------------------------------------------------------------------------// //print header("Content-Type: application/force-download\n"); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); header("Content-Disposition: attachment; filename=ordersexports_" . date("Ymd") . ".csv"); print $csv_output; exit; }//function main function filter_text($text) { $filter_array = array(",","\r","\n","\t"); return str_replace($filter_array,"",$text); } // function for the filter ?>