📄 sales_report.php
字号:
if ($diff_prod_order) $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID; // build product line items (if requested) if ($this->detail_level == 'product' || $this->detail_level == 'matrix') { // build array of product info so the function already has what it needs, avoiding another query $product_tax = (zen_calculate_tax($onetime_charges, $tax)) + (zen_calculate_tax(($final_price * $quantity), $tax)); $this_product = array('id' => $pID, 'name' => $products->fields['products_name'], 'model' => $model, 'base_price' => $products->fields['products_price'], 'quantity' => $quantity, 'tax' => $product_tax, 'onetime_charges' => $onetime_charges, 'total' => ( ($final_price * $quantity) + $onetime_charges) ); $this->build_li_products($this_product); } $products->MoveNext(); } // pull shipping, discounts, tax, and gift certificates used from orders_total table $totals = $db->Execute("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $oID . "'"); while (!$totals->EOF) { $class = $totals->fields['class']; $value = $totals->fields['value']; if ($class != "ot_total" && $class != "ot_subtotal") { if($class == "ot_gv") { $order_gc_used += $value; $this->timeframe[$id]['total']['gc_used'] += $value; $this->build_li_orders($oID, 'gc_used', $value); $this->timeframe[$id]['total']['gc_used_qty']++; $this->build_li_orders($oID, 'gc_used_qty', 1); } elseif ($class == "ot_coupon" || $class == "ot_group_pricing") { $order_discount += $value; $this->timeframe[$id]['total']['discount'] += $value; $this->build_li_orders($oID, 'discount', $value); $this->timeframe[$id]['total']['discount_qty']++; $this->build_li_orders($oID, 'discount_qty', 1); } elseif ($class == "ot_tax") { $order_tax += $value; $this->timeframe[$id]['total']['tax'] += $value; $this->build_li_orders($oID, 'tax', $value); } elseif ($class == "ot_shipping") { $order_shipping += $value; $this->timeframe[$id]['total']['shipping'] += $value; $this->build_li_orders($oID, 'shipping', $value); } // this allows for a custom discount, a la Super Orders elseif ($value < 0) { $order_discount += abs($value); $this->timeframe[$id]['total']['discount'] += abs($value); $this->build_li_orders($oID, 'discount', abs($value) ); $this->timeframe[$id]['total']['discount_qty']++; $this->build_li_orders($oID, 'discount_qty', 1); } } $totals->MoveNext(); } // we want to count an order if it has a value in any category $order_values = ($order_goods + $order_tax + $order_shipping + $order_gc_sold + $order_discount + $order_gc_used); if ($order_values != 0) { $this->timeframe[$id]['total']['num_orders']++; $this->build_li_orders($oID, 'has_no_value', false); // add up stored values for order grand total // (goods + tax + shipping + gc_sold) - (discount + gc_used) $order_total = ($order_goods + $order_tax + $order_shipping + $order_gc_sold) - ($order_discount + $order_gc_used); if ($this->detail_level == 'order' || $this->detail_level == 'matrix') { $this->build_li_orders($oID, 'grand', $order_total); } return $order_total; } else { $this->build_li_orders($oID, 'has_no_value', true); return 0; } } // END function build_li_totals($oID) ////////////////////////////////////////////////////////// // build_li_orders() is called each time a value is added // to the 'total' array. If the customer wishes to // display order line items, the value is added to the // corresponding 'orders' array. // function build_li_orders($oID, $field, $value) { $id = $this->timeframe_id; // first check to see if we even need to do anything if ($this->detail_level == 'order' || $this->detail_level == 'matrix') { // create the array if it doesn't already exist if (!is_array($this->timeframe[$id]['orders'][$oID]) ) { $this->timeframe[$id]['orders'][$oID] = array('oID' => $oID, // the $oID key will be reset when we sort the array at // display, so we store it as a part of the array as well 'goods' => 0, 'num_products' => 0, 'diff_products' => array(), 'shipping' => 0, 'tax' => 0, 'discount' => 0, 'discount_qty' => 0, 'gc_sold' => 0, 'gc_sold_qty' => 0, 'gc_used' => 0, 'gc_used_qty' => 0, 'grand' => 0); // get the customer data global $db; $c_data = $db->Execute("select c.* from " . TABLE_CUSTOMERS . " c, " . TABLE_ORDERS . " o where o.customers_id = c.customers_id and o.orders_id = '" . $oID . "' limit 1"); $customers_id = $c_data->fields['customers_id']; $first_name = zen_db_output($c_data->fields['customers_firstname']); $last_name = zen_db_output($c_data->fields['customers_lastname']); $this->timeframe[$id]['orders'][$oID]['customers_id'] = $customers_id; $this->timeframe[$id]['orders'][$oID]['first_name'] = $first_name; $this->timeframe[$id]['orders'][$oID]['last_name'] = $last_name; } // add the passed $value to the passed $field in the ['orders'] array $this->timeframe[$id]['orders'][$oID][$field] += $value; } } ////////////////////////////////////////////////////////// // Since product line items don't need to look at the // orders_total table, we can just call build_li_products // once and build/increment the product array per product // (i.e. products are already line items, orders are not). // function build_li_products($product) { $id = $this->timeframe_id; $pID = $product['id']; // initialize the array for this products_id if it doesn't exist yet if (!is_array($this->timeframe[$id]['products'][$pID]) ) { $this->timeframe[$id]['products'][$pID] = array('pID' => $pID, 'name' => $product['name'], 'model' => $product['model'], 'manufacturer' => '', 'base_price' => $product['base_price'], 'quantity' => $product['quantity'], 'onetime_charges' => $product['onetime_charges'], 'total' => $product['total'], // 'total' = ( ($final_price * $quantity) + $onetime_charges ) ) 'tax' => $product['tax'], 'grand' => $product['total'] + $product['tax']); // get the manufacturers_id from `products` table if (DISPLAY_MANUFACTURER) { global $db; $get_manu_id = $db->Execute("select m.* from " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m where m.manufacturers_id = p.manufacturers_id and products_id = '" . $pID . "' limit 1"); if ($get_manu_id->RecordCount() > 0) { $this->timeframe[$id]['products'][$pID]['manufacturer'] = $get_manu_id->fields['manufacturers_name']; } else { $this->timeframe[$id]['products'][$pID]['manufacturer'] = TEXT_NONE; } } } // or add the values of ordered product to existing 'products' array // note that the informational fields are only defined once (i.e. the SQL sort order matters!) else { $this->timeframe[$id]['products'][$pID]['quantity'] += $product['quantity']; $this->timeframe[$id]['products'][$pID]['onetime_charges'] += $product['onetime_charges']; $this->timeframe[$id]['products'][$pID]['total'] += $product['total']; $this->timeframe[$id]['products'][$pID]['tax'] += $product['tax']; $this->timeframe[$id]['products'][$pID]['grand'] += $product['total'] + $product['tax']; } } // END function build_li_products($product) ////////////////////////////////////////////////////////// // Building the data matrix requires data from both the // order and product level, so we build both arrays when // creating a data matrix. This saves us from having to // run several queries and makes the adding the matrix // report a snap, since we can just tack it on after // building all the data arrays! // function build_matrix() { global $db; for ($i = 0; $i < sizeof($this->timeframe); $i++) { // skip the current timeframe if there isn't any data if (!is_array($this->timeframe[$i]['orders']) ) continue; if (!is_array($this->timeframe[$i]['products']) ) continue; $tf =& $this->timeframe[$i]; $tf['matrix'] = array('diff_customers' => array(), 'payment_methods' => array(), 'shipping_methods' => array(), 'credit_cards' => array(), 'currencies' => array(), 'biggest_per_revenue' => 0, 'biggest_per_products' => 0, 'smallest_per_revenue' => 0, 'smallest_per_products' => 0, 'avg_order_value' => 0, 'avg_products_per_order' => 0, 'avg_diff_products_per_order' => 0, 'avg_orders_per_customer' => 0, 'product_spread' => array(), 'product_revenue_ratio' => array(), 'product_quantity_ratio' => array() ); // gather statistics from orders array foreach($tf['orders'] as $oID => $o_data) { $order = $db->Execute("select * from " . TABLE_ORDERS . " where orders_id = '" . $oID . "'"); // place pertient data in short variables $cc_type = $order->fields['cc_type']; $payment_method = $order->fields['payment_method']; $payment_module_code = $order->fields['payment_module_code']; $shipping_method = $order->fields['shipping_method']; $shipping_module_code = $order->fields['shipping_module_code']; $currency = $order->fields['currency']; // Format shipping method to remove the data in parentheses $shipping_method = explode(" (", $shipping_method, 2); $shipping_method = rtrim($shipping_method[0], ":"); // Number of unique customers $cID = $o_data['customers_id']; $new_customer = true; foreach($tf['matrix']['diff_customers'] as $this_cID => $c_data) { $c_data =& $tf['matrix']['diff_customers'][$this_cID]; if ($cID == $this_cID) { $c_data['num_orders']++; $new_customer = false; break; } unset($c_data); } if ($new_customer) { $tf['matrix']['diff_customers'][$cID] = array('first_name' => $o_data['first_name'], 'last_name' => $o_data['last_name'], 'num_orders' => 1); } // Payment methods used, with count $new_payment_method = true; foreach($tf['matrix']['payment_methods'] as $key => $value) { $value =& $tf['matrix']['payment_methods'][$key]; if ($value['module_code'] == $payment_module_code) { $value['count']++; $new_payment_method = false; unset($value); break; } unset($value); } if ($new_payment_method) { $tf['matrix']['payment_methods'][] = array('method' => $payment_method, 'module_code' => $payment_module_code, 'count' => 1); } // Shipping methods used, with count $new_shipping_method = true; foreach($tf['matrix']['shipping_methods'] as $key => $value) { $value =& $tf['matrix']['shipping_methods'][$key]; if ($value['module_code'] == $shipping_module_code) { $value['count']++; $new_shipping_method = false; unset($value); break; } unset($value); } if ($new_shipping_method) { $tf['matrix']['shipping_methods'][] = array('method' => $shipping_method, 'module_code' => $shipping_module_code, 'count' => 1); } // Credit cards used, with count $new_credit_card = true; foreach($tf['matrix']['credit_cards'] as $key => $value) { $value =& $tf['matrix']['credit_cards'][$key]; if ($value['type'] == $cc_type) { $value['count']++; $new_credit_card = false; unset($value); break; } unset($value); } if ($new_credit_card && $cc_type != '') { $tf['matrix']['credit_cards'][] = array('type' => $cc_type, 'count' => 1); } // Currencies used, with count // eliminate display on report with "if (sizeof($timeframe['matrix']['currencies']) > 1)" $new_currency = true; foreach($tf['matrix']['currencies'] as $key => $value) { $value =& $tf['matrix']['currencies'][$key]; if ($value['type'] == $currency) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -