Changeset 1029435
- Timestamp:
- 11/20/2014 04:07:45 PM (11 years ago)
- Location:
- woocommerce-sales-by-location-report/trunk
- Files:
-
- 4 edited
-
changelog.txt (modified) (1 diff)
-
classes/class-wc-report-sales-by-location.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
-
woocommerce-location-report.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-sales-by-location-report/trunk/changelog.txt
r1011036 r1029435 1 1 *** WooCommerce Sales By Location Report Changelog *** 2 3 2014.11.20 - version 1.1 4 * Fix - WooCommerce active check 5 * Tweak - yoda coding style 6 * Enhancement - Export functionality in report 2 7 3 8 2014.10.15 - version 1.0 -
woocommerce-sales-by-location-report/trunk/classes/class-wc-report-sales-by-location.php
r1011036 r1029435 6 6 * @category Admin 7 7 * @package WooCommerce/Admin/Reports 8 * @version 1. 0.08 * @version 1.1 9 9 */ 10 10 … … 42 42 'name' => 'total_sales' 43 43 ), 44 'post_date' => array( 45 'type' => 'post_data', 46 'function' => '', 47 'name' => 'post_date' 48 ), 44 49 ), 45 50 'filter_range' => true, 46 'group_by' => ' meta__' . $this->location_by . '_country.meta_value',51 'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date), meta__' . $this->location_by . '_country.meta_value', 47 52 'query_type' => 'get_results' 48 53 ) ); 49 54 55 50 56 //Loop through the returned data and set depending on sales or order totals 51 57 $country_data = array(); 58 $export_data = array(); 52 59 foreach ( $location_query as $location_values ) { 53 60 54 if ( $location_values->countries_data == '') {61 if ( '' == $location_values->countries_data ) { 55 62 $location_values->countries_data = 'UNDEFINED'; 56 63 } 57 64 58 if ( $this->totals_by == 'number-orders' ) { 59 $country_data[$location_values->countries_data] = $location_values->countries_data_count; 60 } elseif ( $this->totals_by == 'order-total' ) { 61 $country_data[$location_values->countries_data] = $location_values->total_sales; 65 if ( 'number-orders' == $this->totals_by ) { 66 $country_data[$location_values->countries_data] = ( isset( $country_data[$location_values->countries_data] ) ) ? $location_values->countries_data_count + $country_data[$location_values->countries_data] : $location_values->countries_data_count; 67 } elseif ( 'order-total' == $this->totals_by ) { 68 $country_data[$location_values->countries_data] = ( isset( $country_data[$location_values->countries_data] ) ) ? $location_values->total_sales + $country_data[$location_values->countries_data] : $location_values->total_sales; 69 } 70 71 if ( 'UNDEFINED' != $location_values->countries_data ) { 72 $export_data[$location_values->countries_data][] = $location_values; 62 73 } 63 74 } … … 68 79 69 80 //If we are using price, then create another set of data with the price set (map does not like adding with price) 70 if ( $this->totals_by == 'order-total') {81 if ( 'order-total' == $this->totals_by ) { 71 82 $sales_data = $this->location_data; 72 83 array_walk($sales_data, function(&$value, $index){ … … 85 96 $total = array_sum( $country_data ); 86 97 87 if ( $this->totals_by == 'order-total') {98 if ( 'order-total' == $this->totals_by ) { 88 99 $total = wc_price( $total ); 89 100 } … … 100 111 'highlight_series' => 2 101 112 ); 113 114 /* Export Code */ 115 $export_array = array(); 116 $report_type = ( 'number-orders' == $this->totals_by ) ? 'countries_data_count' : 'total_sales'; 117 foreach ($export_data as $country => $data) { 118 $export_prep = $this->prepare_chart_data( $data, 'post_date', $report_type, $this->chart_interval, $this->start_date, $this->chart_groupby ); 119 $export_array[$country] = array_values( $export_prep ); 120 } 121 122 // Encode in json format 123 $chart_data = json_encode( $export_array ); 124 125 ?> 126 <div class="chart-container" style="display:none !important;"> 127 <div class="chart-placeholder main" style="display:none !important;"></div> 128 </div> 129 <script type="text/javascript"> 130 var main_chart; 131 132 jQuery(function(){ 133 var order_data = jQuery.parseJSON( '<?php echo $chart_data; ?>' ); 134 135 var series = [ 136 <?php 137 foreach ( $export_array as $country => $data ) { 138 echo "{\n label: \"$country\",\n data: order_data.$country\n },"; 139 } 140 ?> 141 ]; 142 143 main_chart = jQuery.plot( 144 jQuery('.chart-placeholder.main'), 145 series 146 ); 147 }); 148 149 </script> 150 <?php 151 152 /* / Export Code */ 102 153 103 154 return $legend; … … 216 267 */ 217 268 public function get_export_button() { 218 269 $current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day'; 270 ?> 271 <a 272 href="#" 273 download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time('timestamp') ); ?>.csv" 274 class="export_csv" 275 data-export="chart" 276 data-xaxes="<?php _e( 'Date', 'woocommerce' ); ?>" 277 data-groupby="<?php echo $this->chart_groupby; ?>" 278 > 279 <?php _e( 'Export CSV', 'woocommerce' ); ?> 280 </a> 281 <?php 219 282 } 220 283 … … 239 302 onRegionLabelShow: function(e, el, code) { 240 303 <?php 241 if ( isset($_REQUEST['report_by']) && $_REQUEST['report_by'] == 'order-total') { // show formatted price for order totals ?>304 if ( isset($_REQUEST['report_by']) && 'order-total' == $_REQUEST['report_by'] ) { // show formatted price for order totals ?> 242 305 el.html('<strong>'+(map_price_data[code] ? map_price_data[code] : 0)+' <?php _e('orders', 'woocommerce-location-report'); ?> - '+'</strong> '+el.html()); 243 306 <?php -
woocommerce-sales-by-location-report/trunk/readme.txt
r1011036 r1029435 4 4 Requires at least: 3.8 5 5 Tested up to: 4.0 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 License: GPLv3 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 51 51 52 52 == Changelog == 53 = 1.1 - 2014/11/20 54 * Fix - WooCommerce active check 55 * Tweak - yoda coding style 56 * Enhancement - Export functionality in report 53 57 54 58 = 1.0.0 - 10/15/2014 = -
woocommerce-sales-by-location-report/trunk/woocommerce-location-report.php
r1011036 r1029435 6 6 * Author: Chuck Mac 7 7 * Author URI: http://www.chuckmac.info 8 * Version: 1. 0.08 * Version: 1.1 9 9 * Text Domain: wc_location_report 10 10 * Domain Path: /languages/ … … 25 25 26 26 // Check if WooCommerce is active 27 if ( ! i s_woocommerce_active() ) {28 return;27 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 28 return; 29 29 } 30 30 … … 45 45 46 46 /** plugin version number */ 47 public static $version = '1. 0.0';47 public static $version = '1.1'; 48 48 49 49 /** @var string the plugin file */
Note: See TracChangeset
for help on using the changeset viewer.