📄 sales_report.php
字号:
$value['count']++; $new_currency = false; unset($value); break; } unset($value); } if ($new_currency) { $tf['matrix']['currencies'][] = array('type' => $currency, 'count' => 1); } // Biggest order by revenue (display order # and customer name) if ($tf['matrix']['biggest_per_revenue'] == 0) { $tf['matrix']['biggest_per_revenue'] = $oID; } else { $current_leader = $tf['orders'][ $tf['matrix']['biggest_per_revenue'] ]; if ($o_data['goods'] > $current_leader['goods']) { $tf['matrix']['biggest_per_revenue'] = $oID; } } // Smallest order by revenue (display order # and customer name) if ($tf['matrix']['smallest_per_revenue'] == 0) { $tf['matrix']['smallest_per_revenue'] = $oID; } else { $current_leader = $tf['orders'][ $tf['matrix']['smallest_per_revenue'] ]; if ($o_data['goods'] < $current_leader['goods']) { $tf['matrix']['smallest_per_revenue'] = $oID; } } // Biggest order by product count (display order # and customer name) if ($tf['matrix']['biggest_per_product'] == 0) { $tf['matrix']['biggest_per_product'] = $oID; } else { $current_leader = $tf['orders'][ $tf['matrix']['biggest_per_product'] ]; if ($o_data['num_products'] > $current_leader['num_products']) { $tf['matrix']['biggest_per_product'] = $oID; } } // Smallest order by product count (display order # and customer name) if ($tf['matrix']['smallest_per_product'] == 0) { $tf['matrix']['smallest_per_product'] = $oID; } else { $current_leader = $tf['orders'][ $tf['matrix']['smallest_per_product'] ]; if ($o_data['num_products'] < $current_leader['num_products']) { $tf['matrix']['smallest_per_product'] = $oID; } } } // END foreach($tf['orders'] as $oID => $o_data) // Avg order value $tf['matrix']['avg_order_value'] = ($tf['total']['grand'] / sizeof($tf['orders'])); // Avg number of products in an order $tf['matrix']['avg_products_per_order'] = ($tf['total']['num_products'] / sizeof($tf['orders'])); // Avg number of unique products in an order $tf['matrix']['avg_diff_products_per_order'] = (sizeof($tf['total']['diff_products']) / sizeof($tf['orders'])); // Avg # orders per unique customer $tf['matrix']['avg_orders_per_customer'] = (sizeof($tf['orders']) / sizeof($tf['matrix']['diff_customers'])); // gather statistics from products array foreach($tf['products'] as $pID => $p_data) { // Per product "spread" (number of orders that a product is a part of) foreach($tf['orders'] as $oID => $o_data) { foreach($o_data['diff_products'] as $ordered_pID) { if ($pID == $ordered_pID) { $tf['matrix']['product_spread'][$pID]++; break; } } } // percentage of all revenue by product BEFORE shipping, tax, discounts, and gc's $tf['matrix']['product_revenue_ratio'][$pID] = number_format((($p_data['total'] / $tf['total']['goods']) * 100), 3); // percentage of all quantity by product $tf['matrix']['product_quantity_ratio'][$pID] = number_format((($p_data['quantity'] / $tf['total']['num_products']) * 100), 3); } // END foreach($tf['products'] as $pID => $p_data) } // END for ($i = 0, $i < sizeof($this->timeframe); $i++) } // END function build_matrix() function unique_count($item, $item_array) { if (sizeof($item_array) == 0) { return true; } foreach ($item_array as $id => $compare_item) { if ($item == $compare_item) { return false; } } return true; } ////////////////////////////////////////////////////////// // This function actually creates the CSV file when CSV // output is requested. The logic and looping structure // is nearly identical to that found in the HTML output, // but we seperate it out for the sake of code clarity and // to allow for some differences between the 2 outputs. // function output_csv($csv_header, $timeframe_sort, $li_sort_a, $li_sort_order_a, $li_sort_b, $li_sort_order_b) { $display_tax = ($this->grand_total['tax'] > 0 ? true : false); $filename = CSV_FILENAME_PREFIX . date('Ymd', $startDate) . "-" . date('Ymd', $endDate); header("Pragma: cache"); header("Content-Type: text/comma-separated-values"); header("Content-Disposition: attachment; filename=" . urlencode($filename) . ".csv"); if ($csv_header) { switch ($this->detail_level) { case 'timeframe': echo CSV_HEADING_START_DATE . CSV_SEPARATOR; echo CSV_HEADING_END_DATE . CSV_SEPARATOR; echo TABLE_HEADING_NUM_ORDERS . CSV_SEPARATOR; echo TABLE_HEADING_NUM_PRODUCTS . CSV_SEPARATOR; echo TABLE_HEADING_TOTAL_GOODS . CSV_SEPARATOR; if ($display_tax) echo TABLE_HEADING_TAX . CSV_SEPARATOR; echo TABLE_HEADING_SHIPPING . CSV_SEPARATOR; echo TABLE_HEADING_DISCOUNTS . CSV_SEPARATOR; echo TABLE_HEADING_GC_SOLD . CSV_SEPARATOR; echo TABLE_HEADING_GC_USED . CSV_SEPARATOR; echo TABLE_HEADING_TOTAL . CSV_NEWLINE; break; case 'order': echo CSV_HEADING_START_DATE . CSV_SEPARATOR; echo CSV_HEADING_END_DATE . CSV_SEPARATOR; echo TABLE_HEADING_ORDERS_ID . CSV_SEPARATOR; echo CSV_HEADING_LAST_NAME . CSV_SEPARATOR; echo CSV_HEADING_FIRST_NAME . CSV_SEPARATOR; echo TABLE_HEADING_NUM_PRODUCTS . CSV_SEPARATOR; echo TABLE_HEADING_TOTAL_GOODS . CSV_SEPARATOR; if ($display_tax) echo TABLE_HEADING_TAX . CSV_SEPARATOR; echo TABLE_HEADING_SHIPPING . CSV_SEPARATOR; echo TABLE_HEADING_DISCOUNTS . CSV_SEPARATOR; echo TABLE_HEADING_GC_SOLD . CSV_SEPARATOR; echo TABLE_HEADING_GC_USED . CSV_SEPARATOR; echo TABLE_HEADING_ORDER_TOTAL . CSV_NEWLINE; break; case 'product': echo CSV_HEADING_START_DATE . CSV_SEPARATOR; echo CSV_HEADING_END_DATE . CSV_SEPARATOR; echo TABLE_HEADING_PRODUCT_ID . CSV_SEPARATOR; echo TABLE_HEADING_PRODUCT_NAME . CSV_SEPARATOR; if (DISPLAY_MANUFACTURER) echo TABLE_HEADING_MANUFACTURER . CSV_SEPARATOR; echo TABLE_HEADING_MODEL . CSV_SEPARATOR; echo TABLE_HEADING_BASE_PRICE . CSV_SEPARATOR; echo TABLE_HEADING_QUANTITY . CSV_SEPARATOR; if ($display_tax) echo TABLE_HEADING_TAX . CSV_SEPARATOR; if (DISPLAY_ONE_TIME_FEES) echo TABLE_HEADING_ONETIME_CHARGES . CSV_SEPARATOR; if ($display_tax) echo TABLE_HEADING_TOTAL . CSV_SEPARATOR; echo TABLE_HEADING_PRODUCT_TOTAL . CSV_NEWLINE; break; } } // END if ($csv_header) if ($timeframe_sort == 'desc') { krsort($this->timeframe); } foreach ($this->timeframe as $id => $timeframe) { // format the dates switch ($this->timeframe_group) { case 'day': $start_date = date(TIME_DISPLAY_DAY, $timeframe['sd']); $end_date = date(TIME_DISPLAY_DAY, $timeframe['ed']); break; case 'week': $start_date = date(TIME_DISPLAY_WEEK, $timeframe['sd']); $end_date = date(TIME_DISPLAY_WEEK, $timeframe['ed']); break; case 'month': $start_date = date(TIME_DISPLAY_MONTH, $timeframe['sd']); $end_date = date(TIME_DISPLAY_MONTH, $timeframe['ed']); break; case 'year': $start_date = date(TIME_DISPLAY_YEAR, $timeframe['sd']); $end_date = date(TIME_DISPLAY_YEAR, $timeframe['ed']); break; } switch ($this->detail_level) { case 'timeframe': echo $start_date . CSV_SEPARATOR; echo $end_date . CSV_SEPARATOR; echo $timeframe['total']['num_orders'] . CSV_SEPARATOR; echo $timeframe['total']['num_products'] . CSV_SEPARATOR; //echo TEXT_DIFF . sizeof($timeframe['total']['diff_products']) . CSV_SEPARATOR; echo $timeframe['total']['goods'] . CSV_SEPARATOR; if ($display_tax) $timeframe['total']['tax'] . CSV_SEPARATOR; echo $timeframe['total']['shipping'] . CSV_SEPARATOR; echo $timeframe['total']['discount'] . CSV_SEPARATOR; //echo TEXT_QTY . $timeframe['total']['discount_qty'] . CSV_SEPARATOR; echo $timeframe['total']['gc_sold'] . CSV_SEPARATOR; //echo TEXT_QTY . $timeframe['total']['gc_sold_qty'] . CSV_SEPARATOR; echo $timeframe['total']['gc_used'] . CSV_SEPARATOR; //echo TEXT_QTY . $timeframe['total']['gc_used_qty'] . CSV_SEPARATOR; echo $timeframe['total']['grand'] . CSV_NEWLINE; break; case 'order': // sort the orders according to requested sort options unset($dataset1, $dataset2); foreach($timeframe['orders'] as $oID => $o_data) { $dataset1[$oID] = $o_data[$li_sort_a]; $dataset2[$oID] = $o_data[$li_sort_b]; } if ($li_sort_order_a == 'asc') { if ($li_sort_order_b == 'asc') { array_multisort($dataset1, SORT_ASC, $dataset2, SORT_ASC, $timeframe['orders']); } elseif ($li_sort_order_b == 'desc') { array_multisort($dataset1, SORT_ASC, $dataset2, SORT_DESC, $timeframe['orders']); } } elseif ($li_sort_order_a == 'desc') { if ($li_sort_order_b == 'asc') { array_multisort($dataset1, SORT_DESC, $dataset2, SORT_ASC, $timeframe['orders']); } elseif ($li_sort_order_b == 'desc') { array_multisort($dataset1, SORT_DESC, $dataset2, SORT_DESC, $timeframe['orders']); } } foreach($timeframe['orders'] as $key => $o_data) { // skip order if it has no value if ($o_data['has_no_value']) continue; echo $start_date . CSV_SEPARATOR; echo $end_date . CSV_SEPARATOR; echo $o_data['oID'] . CSV_SEPARATOR; echo $o_data['last_name'] . CSV_SEPARATOR; echo $o_data['first_name'] . CSV_SEPARATOR; echo $o_data['num_products'] . CSV_SEPARATOR; //echo (sizeof($o_data['diff_products']) > 1 ? TEXT_DIFF . sizeof($o_data['diff_products']) : TEXT_SAME) . CSV_SEPARATOR; echo $o_data['goods'] . CSV_SEPARATOR; if ($display_tax) echo $o_data['tax'] . CSV_SEPARATOR; echo $o_data['shipping'] . CSV_SEPARATOR; echo $o_data['discount'] . CSV_SEPARATOR; //echo TEXT_QTY . $o_data['discount_qty'] . CSV_SEPARATOR; echo $o_data['gc_sold'] . CSV_SEPARATOR; //echo TEXT_QTY . $o_data['gc_sold_qty'] . CSV_SEPARATOR; echo $o_data['gc_used'] . CSV_SEPARATOR; //echo TEXT_QTY . $o_data['gc_used_qty'] . CSV_SEPARATOR; echo $o_data['grand'] . CSV_NEWLINE; } echo CSV_NEWLINE; break; case 'product': // sort the products according to requested sort options unset($dataset1, $dataset2); foreach($timeframe['products'] as $pID => $p_data) { $dataset1[$pID] = $p_data[$li_sort_a]; $dataset2[$pID] = $p_data[$li_sort_b]; } if ($li_sort_order_a == 'asc') { if ($li_sort_order_b == 'asc') { array_multisort($dataset1, SORT_ASC, $dataset2, SORT_ASC, $timeframe['products']); } elseif ($li_sort_order_b == 'desc') { array_multisort($dataset1, SORT_ASC, $dataset2, SORT_DESC, $timeframe['products']); } } elseif ($li_sort_order_a == 'desc') { if ($li_sort_order_b == 'asc') { array_multisort($dataset1, SORT_DESC, $dataset2, SORT_ASC, $timeframe['products']); } elseif ($li_sort_order_b == 'desc') { array_multisort($dataset1, SORT_DESC, $dataset2, SORT_DESC, $timeframe['products']); } } foreach($timeframe['products'] as $key => $p_data) { echo $start_date . CSV_SEPARATOR; echo $end_date . CSV_SEPARATOR; echo $p_data['pID'] . CSV_SEPARATOR; echo $p_data['name'] . CSV_SEPARATOR; if (DISPLAY_MANUFACTURER) echo $p_data['manufacturer'] . CSV_SEPARATOR; echo $p_data['model'] . CSV_SEPARATOR; echo $p_data['base_price'] . CSV_SEPARATOR; echo $p_data['quantity'] . CSV_SEPARATOR; if ($display_tax) echo $p_data['tax'] . CSV_SEPARATOR; if (DISPLAY_ONE_TIME_FEES) echo $p_data['onetime_charges'] . CSV_SEPARATOR; if ($display_tax) echo $p_data['total'] . CSV_SEPARATOR; echo $p_data['grand'] . CSV_NEWLINE; } echo CSV_NEWLINE; break; } //END switch ($this->detail_level) } // END foreach ($this->timeframe as $id => $timeframe) } // END function output_csv()/*** END OF CLASS*/ }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -