Plugin Directory

Changeset 1029435


Ignore:
Timestamp:
11/20/2014 04:07:45 PM (11 years ago)
Author:
chuckmac
Message:

Version 1.1 Release

  • Fix - WooCommerce active check
  • Tweak - yoda coding style
  • Enhancement - Export functionality in report

Squashed commit of the following:

commit a4097ae62b8516d1799765d58d1e7104e2bf2bb8
Author: Chuck Mac <chuck@…>
Date: Thu Nov 20 10:55:29 2014 -0500

Marking version 1.1 ready in readme

commit 5320973fe251d253e386f55ad44cfd5edae2fc97
Author: Chuck Mac <chuck@…>
Date: Thu Nov 20 10:44:12 2014 -0500

Adding Export CSV Functionality
Refactor report data in order to generate report files.
Worked within WooCommerce report export functions, so have a hidden chart
which holds the data.

commit e08042265514ed7c6b66541684bfc29a8362d6ea
Author: Chuck Mac <chuck@…>
Date: Wed Nov 19 14:14:09 2014 -0500

Yoda Coding Style
To match WordPress coding standards

commit fabbb77ebc9e88d89989bf41701062f5ffd2c59b
Author: Chuck Mac <chuck@…>
Date: Tue Oct 28 09:13:54 2014 -0400

Fix - Check if WooCommerce is active syntax

Location:
woocommerce-sales-by-location-report/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-sales-by-location-report/trunk/changelog.txt

    r1011036 r1029435  
    11*** WooCommerce Sales By Location Report Changelog ***
     2
     32014.11.20 - version 1.1
     4* Fix - WooCommerce active check
     5* Tweak - yoda coding style
     6* Enhancement - Export functionality in report
    27
    382014.10.15 - version 1.0
  • woocommerce-sales-by-location-report/trunk/classes/class-wc-report-sales-by-location.php

    r1011036 r1029435  
    66 * @category    Admin
    77 * @package     WooCommerce/Admin/Reports
    8  * @version     1.0.0
     8 * @version     1.1
    99 */
    1010
     
    4242                        'name'     => 'total_sales'
    4343                    ),
     44                    'post_date' => array(
     45                        'type'     => 'post_data',
     46                        'function' => '',
     47                        'name'     => 'post_date'
     48                    ),
    4449                ),
    4550                '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',
    4752                'query_type' => 'get_results'
    4853            ) );
    4954
     55
    5056        //Loop through the returned data and set depending on sales or order totals
    5157        $country_data = array();
     58        $export_data = array();
    5259        foreach ( $location_query as $location_values ) {
    5360
    54             if ( $location_values->countries_data == '' ) {
     61            if ( '' == $location_values->countries_data ) {
    5562                $location_values->countries_data = 'UNDEFINED';
    5663            }
    5764
    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;
    6273            }
    6374        }
     
    6879
    6980        //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 ) {
    7182            $sales_data = $this->location_data;
    7283            array_walk($sales_data, function(&$value, $index){
     
    8596        $total = array_sum( $country_data );
    8697
    87         if ( $this->totals_by == 'order-total' ) {
     98        if ( 'order-total' == $this->totals_by ) {
    8899            $total = wc_price( $total );
    89100        }
     
    100111            'highlight_series' => 2
    101112        );
     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 */
    102153
    103154        return $legend;
     
    216267     */
    217268    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
    219282    }
    220283
     
    239302                    onRegionLabelShow: function(e, el, code) {
    240303                        <?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 ?>
    242305                            el.html('<strong>'+(map_price_data[code] ? map_price_data[code] : 0)+' <?php _e('orders', 'woocommerce-location-report'); ?> - '+'</strong> '+el.html());
    243306                        <?php
  • woocommerce-sales-by-location-report/trunk/readme.txt

    r1011036 r1029435  
    44Requires at least: 3.8
    55Tested up to: 4.0
    6 Stable tag: 1.0
     6Stable tag: 1.1
    77License: GPLv3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    5151
    5252== Changelog ==
     53= 1.1 - 2014/11/20
     54* Fix - WooCommerce active check
     55* Tweak - yoda coding style
     56* Enhancement - Export functionality in report
    5357
    5458= 1.0.0 - 10/15/2014 =
  • woocommerce-sales-by-location-report/trunk/woocommerce-location-report.php

    r1011036 r1029435  
    66 * Author: Chuck Mac
    77 * Author URI: http://www.chuckmac.info
    8  * Version: 1.0.0
     8 * Version: 1.1
    99 * Text Domain: wc_location_report
    1010 * Domain Path: /languages/
     
    2525
    2626// Check if WooCommerce is active
    27 if ( ! is_woocommerce_active() ) {
    28     return;
     27if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     28    return;
    2929}
    3030
     
    4545
    4646    /** plugin version number */
    47     public static $version = '1.0.0';
     47    public static $version = '1.1';
    4848
    4949    /** @var string the plugin file */
Note: See TracChangeset for help on using the changeset viewer.