Changeset 3454961
- Timestamp:
- 02/05/2026 09:16:22 PM (5 weeks ago)
- Location:
- product-sales-report-for-woocommerce
- Files:
-
- 16 edited
- 1 copied
-
tags/2.0.11 (copied) (copied from product-sales-report-for-woocommerce/trunk)
-
tags/2.0.11/admin/admin.php (modified) (6 diffs)
-
tags/2.0.11/css/ninjalytics.css (modified) (1 diff)
-
tags/2.0.11/hm-product-sales-report.php (modified) (6 diffs)
-
tags/2.0.11/includes/reporters/base.php (modified) (2 diffs)
-
tags/2.0.11/includes/reporters/orders-base.php (modified) (1 diff)
-
tags/2.0.11/includes/reporters/woocommerce.php (modified) (1 diff)
-
tags/2.0.11/js/ninjalytics.js (modified) (1 diff)
-
tags/2.0.11/readme.txt (modified) (2 diffs)
-
trunk/admin/admin.php (modified) (6 diffs)
-
trunk/css/ninjalytics.css (modified) (1 diff)
-
trunk/hm-product-sales-report.php (modified) (6 diffs)
-
trunk/includes/reporters/base.php (modified) (2 diffs)
-
trunk/includes/reporters/orders-base.php (modified) (1 diff)
-
trunk/includes/reporters/woocommerce.php (modified) (1 diff)
-
trunk/js/ninjalytics.js (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
product-sales-report-for-woocommerce/tags/2.0.11/admin/admin.php
r3445620 r3454961 838 838 <?php foreach ( 839 839 [ 840 'basic' => 'Quick', 840 'preset' => 'Quick', 841 'basic' => 'Relative', 841 842 'absolute' => 'Absolute', 842 843 'dynamic' => 'Expression' … … 851 852 852 853 <div id="ninjalytics-date-range-dropdown-body"> 854 <div class="ninjalytics-date-range-dropdown-tab-content" 855 id="ninjalytics-date-range-preset"> 856 <div> 857 <label for="ninjalytics-date-range-preset-select"><?php esc_html_e( 'Report Dates', 'product-sales-report-for-woocommerce' ) ?>:</label> 858 <div> 859 <select id="ninjalytics-date-range-preset-select" name="report_time_preset"> 860 <?php foreach( ninjalytics_get_report_dates_presets() as $datePresetId => $datePreset) { ?> 861 <option value="<?php echo(esc_attr($datePresetId)); ?>"<?php selected( $datePresetId, $reportSettings['report_time_preset'] ); ?>> 862 <?php echo(esc_html( $datePreset['label'] )); ?> 863 </option> 864 <?php } ?> 865 </select> 866 </div> 867 <p></p> 868 </div> 869 </div> 853 870 <div class="ninjalytics-date-range-dropdown-tab-content" 854 871 id="ninjalytics-date-range-basic"> … … 1106 1123 type="checkbox" 1107 1124 name="product_tag_filter_on" 1108 id="ninjalytics-product-tag-filter-on" data-toggle-key="product_tag_filter_on"1125 id="ninjalytics-product-tag-filter-on" 1109 1126 disabled 1110 1127 /> … … 1114 1131 </label> 1115 1132 </div> 1116 <div class="ninjalytics-field-child" data-toggle-panel="product_tag_filter_on">1133 <div class="ninjalytics-field-child"> 1117 1134 <div class="ninjalytics-product-tag-filter"> 1118 1135 <label for="hm_psr_product_tag_filter" … … 1147 1164 <input id="ninjalytics-product-meta-filter-on" type="checkbox" 1148 1165 name="product_meta_filter_on" 1149 data-toggle-key="product_meta_filter_on"1150 1166 disabled/> 1151 1167 <label for="ninjalytics-product-meta-filter-on"><?php esc_html_e( 'Only products with field', 'product-sales-report-for-woocommerce' ) ?> … … 1153 1169 <?php self::docsLink( 'report-configuration/products', 'only-products-with-field', true ) ?></label> 1154 1170 </div> 1155 <div class="ninjalytics-field-child" data-toggle-panel="product_meta_filter_on">1171 <div class="ninjalytics-field-child"> 1156 1172 <div class="ninjalytics-field-conditional-logic"> 1157 1173 <select name="product_meta_filter_key" class="hm-psr-select-other" disabled> -
product-sales-report-for-woocommerce/tags/2.0.11/css/ninjalytics.css
r3435296 r3454961 204 204 margin-top: 5px; 205 205 color: #5A607F; 206 } 207 #ninjalytics-date-range-dropdown:has(input#report_time_mode_preset:checked) #ninjalytics-date-range-preset.ninjalytics-date-range-dropdown-tab-content { 208 display: block; 206 209 } 207 210 #ninjalytics-date-range-dropdown:has(input#report_time_mode_basic:checked) #ninjalytics-date-range-basic.ninjalytics-date-range-dropdown-tab-content { -
product-sales-report-for-woocommerce/tags/2.0.11/hm-product-sales-report.php
r3445620 r3454961 4 4 * Description: Generates a report on individual WooCommerce products sold during a specified time period. 5 5 * Plugin URI: https://berrypress.com/product/woocommerce/ninjalytics/?utm_campaign=wordpressorg&source=ninjalytics-free-plugin 6 * Version: 2.0.1 06 * Version: 2.0.11 7 7 * WC tested up to: 10.4 8 8 * WC requires at least: 2.2 … … 52 52 if ( ! defined( 'ABSPATH' ) ) exit; 53 53 54 define('NINJALYTICS_FREE_VERSION', '2.0.1 0');54 define('NINJALYTICS_FREE_VERSION', '2.0.11'); 55 55 56 56 add_filter('default_option_ninjalytics_settings', __NAMESPACE__.'\\ninjalytics_psr_import'); … … 454 454 } 455 455 456 function ninjalytics_get_report_dates_presets() 457 { 458 return [ 459 'last7' => [ 460 'label' => __( 'Last 7 days', 'product-sales-report-for-woocommerce' ), 461 'settings' => [ 462 'report_time_mode' => 'basic', 463 'report_time_basic_from_unit' => '-d', 464 'report_time_basic_from' => '7', 465 'report_time_basic_from_round' => '', 466 'report_time_basic_to_unit' => 'now', 467 'report_time_basic_to' => '', 468 'report_time_basic_to_round' => '', 469 ] 470 ], 471 'last30' => [ 472 'label' => __( 'Last 30 days', 'product-sales-report-for-woocommerce' ), 473 'settings' => [ 474 'report_time_mode' => 'basic', 475 'report_time_basic_from_unit' => '-d', 476 'report_time_basic_from' => '30', 477 'report_time_basic_from_round' => '', 478 'report_time_basic_to_unit' => 'now', 479 'report_time_basic_to' => '', 480 'report_time_basic_to_round' => '', 481 ], 482 ], 483 'last90' => [ 484 'label' => __( 'Last 90 days', 'product-sales-report-for-woocommerce' ), 485 'settings' => [ 486 'report_time_mode' => 'basic', 487 'report_time_basic_from_unit' => '-d', 488 'report_time_basic_from' => '90', 489 'report_time_basic_from_round' => '', 490 'report_time_basic_to_unit' => 'now', 491 'report_time_basic_to' => '', 492 'report_time_basic_to_round' => '', 493 ], 494 ], 495 'last1y' => [ 496 'label' => __( 'Past 1 year', 'product-sales-report-for-woocommerce' ), 497 'settings' => [ 498 'report_time_mode' => 'basic', 499 'report_time_basic_from_unit' => '-cm', 500 'report_time_basic_from' => '12', 501 'report_time_basic_from_round' => '', 502 'report_time_basic_to_unit' => 'now', 503 'report_time_basic_to' => '', 504 'report_time_basic_to_round' => '', 505 ], 506 ], 507 'today' => [ 508 'label' => __( 'Today', 'product-sales-report-for-woocommerce' ), 509 'settings' => [ 510 'report_time_mode' => 'basic', 511 'report_time_basic_from_unit' => 'd', 512 'report_time_basic_from' => '0', 513 'report_time_basic_from_round' => 'd', 514 'report_time_basic_to_unit' => 'd', 515 'report_time_basic_to' => '0', 516 'report_time_basic_to_round' => 'd', 517 ], 518 ], 519 'yesterday' => [ 520 'label' => __( 'Yesterday', 'product-sales-report-for-woocommerce' ), 521 'settings' => [ 522 'report_time_mode' => 'basic', 523 'report_time_basic_from_unit' => '-d', 524 'report_time_basic_from' => '1', 525 'report_time_basic_from_round' => 'd', 526 'report_time_basic_to_unit' => '-d', 527 'report_time_basic_to' => '1', 528 'report_time_basic_to_round' => 'd', 529 ], 530 ], 531 'month' => [ 532 'label' => __( 'This month', 'product-sales-report-for-woocommerce' ), 533 'settings' => [ 534 'report_time_mode' => 'basic', 535 'report_time_basic_from_unit' => 'cm', 536 'report_time_basic_from' => '0', 537 'report_time_basic_from_round' => 'm', 538 'report_time_basic_to_unit' => 'cm', 539 'report_time_basic_to' => '0', 540 'report_time_basic_to_round' => 'm', 541 ], 542 ], 543 'lastmonth' => [ 544 'label' => __( 'Last month', 'product-sales-report-for-woocommerce' ), 545 'settings' => [ 546 'report_time_mode' => 'basic', 547 'report_time_basic_from_unit' => '-cm', 548 'report_time_basic_from' => '1', 549 'report_time_basic_from_round' => 'm', 550 'report_time_basic_to_unit' => '-cm', 551 'report_time_basic_to' => '1', 552 'report_time_basic_to_round' => 'm', 553 ] 554 ], 555 'forever' => [ 556 'label' => __( 'All time', 'product-sales-report-for-woocommerce' ), 557 'settings' => [ 558 'report_time_mode' => 'basic', 559 'report_time_basic_from_unit' => 'max', 560 'report_time_basic_from' => '', 561 'report_time_basic_from_round' => '', 562 'report_time_basic_to_unit' => 'max', 563 'report_time_basic_to' => '', 564 'report_time_basic_to_round' => '', 565 ] 566 ] 567 ]; 568 } 456 569 function ninjalytics_get_report_dates($reporter, $withDesc=false) 457 570 { … … 461 574 // Calculate report start and end dates (timestamps) 462 575 $dates = []; 576 577 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- just comparing against known value 578 if (($_POST['report_time_mode'] ?? '') == 'preset') { 579 $presets = ninjalytics_get_report_dates_presets(); 580 581 $datePreset = sanitize_text_field(wp_unslash($_POST['report_time_preset'] ?? '')); 582 if (!isset($presets[$datePreset])) { 583 throw new Exception(); 584 } 585 586 $datesPresetLabel = $presets[$datePreset]['label']; 587 $_POST = array_merge($_POST, $presets[$datePreset]['settings']); 588 } 463 589 464 590 switch ($_POST['report_time_mode'] ?? '') { … … 503 629 504 630 if ($withDesc) { 505 $fromUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_from_unit'] ?? '')); 506 $toUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_to_unit'] ?? '')); 507 $startsNow = $fromUnit == 'now' || ($fromUnit != 'max' && empty($_POST['report_time_basic_from'])); 508 $endsNow = $toUnit == 'now' || ($toUnit != 'max' && empty($_POST['report_time_basic_to'])); 509 if ($fromUnit == 'max' && $toUnit == 'max') { 510 $desc = 'All time'; 631 if (isset($datesPresetLabel)) { 632 $desc = $datesPresetLabel; 511 633 } else { 512 if ($fromUnit == 'now') { 513 switch ($_POST['report_time_basic_from_round'] ?? '') { 514 case 'd': 515 $startDesc = 'today'; 516 break; 517 case 'm': 518 break; 519 default: 520 $startDesc = 'now'; 521 } 522 } 523 524 if ($toUnit == 'now') { 525 switch ($_POST['report_time_basic_to_round'] ?? '') { 526 case 'd': 527 $endDesc = 'today'; 528 break; 529 case 'm': 530 break; 531 default: 532 $endDesc = 'now'; 533 } 534 } 535 536 if (!isset($startDesc) || !isset($endDesc)) { 537 if ($_POST['report_time_basic_from_round'] == 'd' && $_POST['report_time_basic_to_round'] == 'd') { 538 $format = str_replace('F', 'M', get_option('date_format')); 539 } else if ($_POST['report_time_basic_from_round'] == 'm' && $_POST['report_time_basic_to_round'] == 'm') { 540 $format = 'M Y'; 541 } else { 542 $format = str_replace('F', 'M', get_option('date_format')).' '.(stripos(get_option('time_format'), 'A') === false ? 'H:i:s' : 'g:i:s A'); 634 $fromUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_from_unit'] ?? '')); 635 $toUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_to_unit'] ?? '')); 636 $startsNow = $fromUnit == 'now' || ($fromUnit != 'max' && empty($_POST['report_time_basic_from'])); 637 $endsNow = $toUnit == 'now' || ($toUnit != 'max' && empty($_POST['report_time_basic_to'])); 638 if ($fromUnit == 'max' && $toUnit == 'max') { 639 $desc = 'All time'; 640 } else { 641 if ($fromUnit == 'now') { 642 switch ($_POST['report_time_basic_from_round'] ?? '') { 643 case 'd': 644 $startDesc = 'today'; 645 break; 646 case 'm': 647 break; 648 default: 649 $startDesc = 'now'; 650 } 543 651 } 544 652 545 if (!isset($startDesc)) { 546 $startDesc = gmdate($format, $dates[0]); 653 if ($toUnit == 'now') { 654 switch ($_POST['report_time_basic_to_round'] ?? '') { 655 case 'd': 656 $endDesc = 'today'; 657 break; 658 case 'm': 659 break; 660 default: 661 $endDesc = 'now'; 662 } 547 663 } 548 if (!isset($endDesc)) { 549 $endDesc = gmdate($format, $dates[1]); 664 665 if (!isset($startDesc) || !isset($endDesc)) { 666 if ($_POST['report_time_basic_from_round'] == 'd' && $_POST['report_time_basic_to_round'] == 'd') { 667 $format = str_replace('F', 'M', get_option('date_format')); 668 } else if ($_POST['report_time_basic_from_round'] == 'm' && $_POST['report_time_basic_to_round'] == 'm') { 669 $format = 'M Y'; 670 } else { 671 $format = str_replace('F', 'M', get_option('date_format')).' '.(stripos(get_option('time_format'), 'A') === false ? 'H:i:s' : 'g:i:s A'); 672 } 673 674 if (!isset($startDesc)) { 675 $startDesc = gmdate($format, $dates[0]); 676 } 677 if (!isset($endDesc)) { 678 $endDesc = gmdate($format, $dates[1]); 679 } 550 680 } 681 682 $desc = $startDesc == $endDesc ? $startDesc : $startDesc.' to '.$endDesc; 551 683 } 552 553 $desc = $startDesc == $endDesc ? $startDesc : $startDesc.' to '.$endDesc;554 684 } 555 685 … … 2580 2710 'name' => 'groupby_field' 2581 2711 ); 2582 } else if ($ groupByField == 'o_builtin::order_source') {2712 } else if ($reporter->supports(PlatformFeatures::ORDER_SOURCE) && $groupByField == 'o_builtin::order_source') { 2583 2713 // Replicated in non-shipping data function above 2584 2714 $dataParams['_wc_order_attribution_source_type'] = array( -
product-sales-report-for-woocommerce/tags/2.0.11/includes/reporters/base.php
r3435296 r3454961 103 103 'chart_type' => 'line_series', 104 104 105 'report_time_mode' => 'basic', 105 'report_time_mode' => 'preset', 106 'report_time_preset' => 'last30', 106 107 'report_time_basic_from' => '', 107 108 'report_time_basic_from_unit' => 'max', … … 270 271 $dates = $wpdb->get_row('SELECT MIN(date_created_gmt), MAX(date_created_gmt) FROM '.$wpdb->prefix.'wc_orders', ARRAY_N); 271 272 if (!$dates || !count($dates) == 2) { 272 throw new Exception();273 throw new \Exception(); 273 274 } 274 275 $min = strtotime($dates[0]); -
product-sales-report-for-woocommerce/tags/2.0.11/includes/reporters/orders-base.php
r3435296 r3454961 40 40 $this->groupByFields['o_builtin::order_quarter'] = 'Order Quarter'; 41 41 $this->groupByFields['o_builtin::order_year'] = 'Order Year'; 42 $this->groupByFields['o_builtin::order_source'] = 'Order Source'; 42 43 if ($this->supports(PlatformFeatures::ORDER_SOURCE)) { 44 $this->groupByFields['o_builtin::order_source'] = 'Order Source'; 45 } 43 46 44 47 $fields = \NinjalyticsFree\ninjalytics_get_order_item_fields($this); -
product-sales-report-for-woocommerce/tags/2.0.11/includes/reporters/woocommerce.php
r3435296 r3454961 83 83 84 84 public function getPlatformFeatures() { 85 return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::CHILD_ITEMS_META, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS ];85 return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::CHILD_ITEMS_META, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS, PlatformFeatures::ORDER_SOURCE]; 86 86 } 87 87 -
product-sales-report-for-woocommerce/tags/2.0.11/js/ninjalytics.js
r3435296 r3454961 444 444 445 445 $('#ninjalytics-settings .hm-psr-select-other') 446 .append($('<option>').html('Other...'). addClass('hm-psr-select-other-option'))446 .append($('<option>').html('Other...').prop('disabled', true).addClass('hm-psr-select-other-option')) 447 447 .closest('select') 448 448 .change(function() { -
product-sales-report-for-woocommerce/tags/2.0.11/readme.txt
r3445620 r3454961 5 5 Requires PHP: 8.1 6 6 Tested up to: 6.9 7 Stable tag: 2.0.1 07 Stable tag: 2.0.11 8 8 License: GPLv3 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 183 183 184 184 == Changelog == 185 186 = 2.0.11, 2025-02-05 = 187 - Add: Quick Dates (last X days, etc) to report dates 188 - Fix: Order source issue 189 - Fix: "Other" (custom) report fields should have disabled state 185 190 186 191 = 2.0.10, 2025-01-23 = -
product-sales-report-for-woocommerce/trunk/admin/admin.php
r3445620 r3454961 838 838 <?php foreach ( 839 839 [ 840 'basic' => 'Quick', 840 'preset' => 'Quick', 841 'basic' => 'Relative', 841 842 'absolute' => 'Absolute', 842 843 'dynamic' => 'Expression' … … 851 852 852 853 <div id="ninjalytics-date-range-dropdown-body"> 854 <div class="ninjalytics-date-range-dropdown-tab-content" 855 id="ninjalytics-date-range-preset"> 856 <div> 857 <label for="ninjalytics-date-range-preset-select"><?php esc_html_e( 'Report Dates', 'product-sales-report-for-woocommerce' ) ?>:</label> 858 <div> 859 <select id="ninjalytics-date-range-preset-select" name="report_time_preset"> 860 <?php foreach( ninjalytics_get_report_dates_presets() as $datePresetId => $datePreset) { ?> 861 <option value="<?php echo(esc_attr($datePresetId)); ?>"<?php selected( $datePresetId, $reportSettings['report_time_preset'] ); ?>> 862 <?php echo(esc_html( $datePreset['label'] )); ?> 863 </option> 864 <?php } ?> 865 </select> 866 </div> 867 <p></p> 868 </div> 869 </div> 853 870 <div class="ninjalytics-date-range-dropdown-tab-content" 854 871 id="ninjalytics-date-range-basic"> … … 1106 1123 type="checkbox" 1107 1124 name="product_tag_filter_on" 1108 id="ninjalytics-product-tag-filter-on" data-toggle-key="product_tag_filter_on"1125 id="ninjalytics-product-tag-filter-on" 1109 1126 disabled 1110 1127 /> … … 1114 1131 </label> 1115 1132 </div> 1116 <div class="ninjalytics-field-child" data-toggle-panel="product_tag_filter_on">1133 <div class="ninjalytics-field-child"> 1117 1134 <div class="ninjalytics-product-tag-filter"> 1118 1135 <label for="hm_psr_product_tag_filter" … … 1147 1164 <input id="ninjalytics-product-meta-filter-on" type="checkbox" 1148 1165 name="product_meta_filter_on" 1149 data-toggle-key="product_meta_filter_on"1150 1166 disabled/> 1151 1167 <label for="ninjalytics-product-meta-filter-on"><?php esc_html_e( 'Only products with field', 'product-sales-report-for-woocommerce' ) ?> … … 1153 1169 <?php self::docsLink( 'report-configuration/products', 'only-products-with-field', true ) ?></label> 1154 1170 </div> 1155 <div class="ninjalytics-field-child" data-toggle-panel="product_meta_filter_on">1171 <div class="ninjalytics-field-child"> 1156 1172 <div class="ninjalytics-field-conditional-logic"> 1157 1173 <select name="product_meta_filter_key" class="hm-psr-select-other" disabled> -
product-sales-report-for-woocommerce/trunk/css/ninjalytics.css
r3435296 r3454961 204 204 margin-top: 5px; 205 205 color: #5A607F; 206 } 207 #ninjalytics-date-range-dropdown:has(input#report_time_mode_preset:checked) #ninjalytics-date-range-preset.ninjalytics-date-range-dropdown-tab-content { 208 display: block; 206 209 } 207 210 #ninjalytics-date-range-dropdown:has(input#report_time_mode_basic:checked) #ninjalytics-date-range-basic.ninjalytics-date-range-dropdown-tab-content { -
product-sales-report-for-woocommerce/trunk/hm-product-sales-report.php
r3445620 r3454961 4 4 * Description: Generates a report on individual WooCommerce products sold during a specified time period. 5 5 * Plugin URI: https://berrypress.com/product/woocommerce/ninjalytics/?utm_campaign=wordpressorg&source=ninjalytics-free-plugin 6 * Version: 2.0.1 06 * Version: 2.0.11 7 7 * WC tested up to: 10.4 8 8 * WC requires at least: 2.2 … … 52 52 if ( ! defined( 'ABSPATH' ) ) exit; 53 53 54 define('NINJALYTICS_FREE_VERSION', '2.0.1 0');54 define('NINJALYTICS_FREE_VERSION', '2.0.11'); 55 55 56 56 add_filter('default_option_ninjalytics_settings', __NAMESPACE__.'\\ninjalytics_psr_import'); … … 454 454 } 455 455 456 function ninjalytics_get_report_dates_presets() 457 { 458 return [ 459 'last7' => [ 460 'label' => __( 'Last 7 days', 'product-sales-report-for-woocommerce' ), 461 'settings' => [ 462 'report_time_mode' => 'basic', 463 'report_time_basic_from_unit' => '-d', 464 'report_time_basic_from' => '7', 465 'report_time_basic_from_round' => '', 466 'report_time_basic_to_unit' => 'now', 467 'report_time_basic_to' => '', 468 'report_time_basic_to_round' => '', 469 ] 470 ], 471 'last30' => [ 472 'label' => __( 'Last 30 days', 'product-sales-report-for-woocommerce' ), 473 'settings' => [ 474 'report_time_mode' => 'basic', 475 'report_time_basic_from_unit' => '-d', 476 'report_time_basic_from' => '30', 477 'report_time_basic_from_round' => '', 478 'report_time_basic_to_unit' => 'now', 479 'report_time_basic_to' => '', 480 'report_time_basic_to_round' => '', 481 ], 482 ], 483 'last90' => [ 484 'label' => __( 'Last 90 days', 'product-sales-report-for-woocommerce' ), 485 'settings' => [ 486 'report_time_mode' => 'basic', 487 'report_time_basic_from_unit' => '-d', 488 'report_time_basic_from' => '90', 489 'report_time_basic_from_round' => '', 490 'report_time_basic_to_unit' => 'now', 491 'report_time_basic_to' => '', 492 'report_time_basic_to_round' => '', 493 ], 494 ], 495 'last1y' => [ 496 'label' => __( 'Past 1 year', 'product-sales-report-for-woocommerce' ), 497 'settings' => [ 498 'report_time_mode' => 'basic', 499 'report_time_basic_from_unit' => '-cm', 500 'report_time_basic_from' => '12', 501 'report_time_basic_from_round' => '', 502 'report_time_basic_to_unit' => 'now', 503 'report_time_basic_to' => '', 504 'report_time_basic_to_round' => '', 505 ], 506 ], 507 'today' => [ 508 'label' => __( 'Today', 'product-sales-report-for-woocommerce' ), 509 'settings' => [ 510 'report_time_mode' => 'basic', 511 'report_time_basic_from_unit' => 'd', 512 'report_time_basic_from' => '0', 513 'report_time_basic_from_round' => 'd', 514 'report_time_basic_to_unit' => 'd', 515 'report_time_basic_to' => '0', 516 'report_time_basic_to_round' => 'd', 517 ], 518 ], 519 'yesterday' => [ 520 'label' => __( 'Yesterday', 'product-sales-report-for-woocommerce' ), 521 'settings' => [ 522 'report_time_mode' => 'basic', 523 'report_time_basic_from_unit' => '-d', 524 'report_time_basic_from' => '1', 525 'report_time_basic_from_round' => 'd', 526 'report_time_basic_to_unit' => '-d', 527 'report_time_basic_to' => '1', 528 'report_time_basic_to_round' => 'd', 529 ], 530 ], 531 'month' => [ 532 'label' => __( 'This month', 'product-sales-report-for-woocommerce' ), 533 'settings' => [ 534 'report_time_mode' => 'basic', 535 'report_time_basic_from_unit' => 'cm', 536 'report_time_basic_from' => '0', 537 'report_time_basic_from_round' => 'm', 538 'report_time_basic_to_unit' => 'cm', 539 'report_time_basic_to' => '0', 540 'report_time_basic_to_round' => 'm', 541 ], 542 ], 543 'lastmonth' => [ 544 'label' => __( 'Last month', 'product-sales-report-for-woocommerce' ), 545 'settings' => [ 546 'report_time_mode' => 'basic', 547 'report_time_basic_from_unit' => '-cm', 548 'report_time_basic_from' => '1', 549 'report_time_basic_from_round' => 'm', 550 'report_time_basic_to_unit' => '-cm', 551 'report_time_basic_to' => '1', 552 'report_time_basic_to_round' => 'm', 553 ] 554 ], 555 'forever' => [ 556 'label' => __( 'All time', 'product-sales-report-for-woocommerce' ), 557 'settings' => [ 558 'report_time_mode' => 'basic', 559 'report_time_basic_from_unit' => 'max', 560 'report_time_basic_from' => '', 561 'report_time_basic_from_round' => '', 562 'report_time_basic_to_unit' => 'max', 563 'report_time_basic_to' => '', 564 'report_time_basic_to_round' => '', 565 ] 566 ] 567 ]; 568 } 456 569 function ninjalytics_get_report_dates($reporter, $withDesc=false) 457 570 { … … 461 574 // Calculate report start and end dates (timestamps) 462 575 $dates = []; 576 577 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- just comparing against known value 578 if (($_POST['report_time_mode'] ?? '') == 'preset') { 579 $presets = ninjalytics_get_report_dates_presets(); 580 581 $datePreset = sanitize_text_field(wp_unslash($_POST['report_time_preset'] ?? '')); 582 if (!isset($presets[$datePreset])) { 583 throw new Exception(); 584 } 585 586 $datesPresetLabel = $presets[$datePreset]['label']; 587 $_POST = array_merge($_POST, $presets[$datePreset]['settings']); 588 } 463 589 464 590 switch ($_POST['report_time_mode'] ?? '') { … … 503 629 504 630 if ($withDesc) { 505 $fromUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_from_unit'] ?? '')); 506 $toUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_to_unit'] ?? '')); 507 $startsNow = $fromUnit == 'now' || ($fromUnit != 'max' && empty($_POST['report_time_basic_from'])); 508 $endsNow = $toUnit == 'now' || ($toUnit != 'max' && empty($_POST['report_time_basic_to'])); 509 if ($fromUnit == 'max' && $toUnit == 'max') { 510 $desc = 'All time'; 631 if (isset($datesPresetLabel)) { 632 $desc = $datesPresetLabel; 511 633 } else { 512 if ($fromUnit == 'now') { 513 switch ($_POST['report_time_basic_from_round'] ?? '') { 514 case 'd': 515 $startDesc = 'today'; 516 break; 517 case 'm': 518 break; 519 default: 520 $startDesc = 'now'; 521 } 522 } 523 524 if ($toUnit == 'now') { 525 switch ($_POST['report_time_basic_to_round'] ?? '') { 526 case 'd': 527 $endDesc = 'today'; 528 break; 529 case 'm': 530 break; 531 default: 532 $endDesc = 'now'; 533 } 534 } 535 536 if (!isset($startDesc) || !isset($endDesc)) { 537 if ($_POST['report_time_basic_from_round'] == 'd' && $_POST['report_time_basic_to_round'] == 'd') { 538 $format = str_replace('F', 'M', get_option('date_format')); 539 } else if ($_POST['report_time_basic_from_round'] == 'm' && $_POST['report_time_basic_to_round'] == 'm') { 540 $format = 'M Y'; 541 } else { 542 $format = str_replace('F', 'M', get_option('date_format')).' '.(stripos(get_option('time_format'), 'A') === false ? 'H:i:s' : 'g:i:s A'); 634 $fromUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_from_unit'] ?? '')); 635 $toUnit = sanitize_text_field(wp_unslash($_POST['report_time_basic_to_unit'] ?? '')); 636 $startsNow = $fromUnit == 'now' || ($fromUnit != 'max' && empty($_POST['report_time_basic_from'])); 637 $endsNow = $toUnit == 'now' || ($toUnit != 'max' && empty($_POST['report_time_basic_to'])); 638 if ($fromUnit == 'max' && $toUnit == 'max') { 639 $desc = 'All time'; 640 } else { 641 if ($fromUnit == 'now') { 642 switch ($_POST['report_time_basic_from_round'] ?? '') { 643 case 'd': 644 $startDesc = 'today'; 645 break; 646 case 'm': 647 break; 648 default: 649 $startDesc = 'now'; 650 } 543 651 } 544 652 545 if (!isset($startDesc)) { 546 $startDesc = gmdate($format, $dates[0]); 653 if ($toUnit == 'now') { 654 switch ($_POST['report_time_basic_to_round'] ?? '') { 655 case 'd': 656 $endDesc = 'today'; 657 break; 658 case 'm': 659 break; 660 default: 661 $endDesc = 'now'; 662 } 547 663 } 548 if (!isset($endDesc)) { 549 $endDesc = gmdate($format, $dates[1]); 664 665 if (!isset($startDesc) || !isset($endDesc)) { 666 if ($_POST['report_time_basic_from_round'] == 'd' && $_POST['report_time_basic_to_round'] == 'd') { 667 $format = str_replace('F', 'M', get_option('date_format')); 668 } else if ($_POST['report_time_basic_from_round'] == 'm' && $_POST['report_time_basic_to_round'] == 'm') { 669 $format = 'M Y'; 670 } else { 671 $format = str_replace('F', 'M', get_option('date_format')).' '.(stripos(get_option('time_format'), 'A') === false ? 'H:i:s' : 'g:i:s A'); 672 } 673 674 if (!isset($startDesc)) { 675 $startDesc = gmdate($format, $dates[0]); 676 } 677 if (!isset($endDesc)) { 678 $endDesc = gmdate($format, $dates[1]); 679 } 550 680 } 681 682 $desc = $startDesc == $endDesc ? $startDesc : $startDesc.' to '.$endDesc; 551 683 } 552 553 $desc = $startDesc == $endDesc ? $startDesc : $startDesc.' to '.$endDesc;554 684 } 555 685 … … 2580 2710 'name' => 'groupby_field' 2581 2711 ); 2582 } else if ($ groupByField == 'o_builtin::order_source') {2712 } else if ($reporter->supports(PlatformFeatures::ORDER_SOURCE) && $groupByField == 'o_builtin::order_source') { 2583 2713 // Replicated in non-shipping data function above 2584 2714 $dataParams['_wc_order_attribution_source_type'] = array( -
product-sales-report-for-woocommerce/trunk/includes/reporters/base.php
r3435296 r3454961 103 103 'chart_type' => 'line_series', 104 104 105 'report_time_mode' => 'basic', 105 'report_time_mode' => 'preset', 106 'report_time_preset' => 'last30', 106 107 'report_time_basic_from' => '', 107 108 'report_time_basic_from_unit' => 'max', … … 270 271 $dates = $wpdb->get_row('SELECT MIN(date_created_gmt), MAX(date_created_gmt) FROM '.$wpdb->prefix.'wc_orders', ARRAY_N); 271 272 if (!$dates || !count($dates) == 2) { 272 throw new Exception();273 throw new \Exception(); 273 274 } 274 275 $min = strtotime($dates[0]); -
product-sales-report-for-woocommerce/trunk/includes/reporters/orders-base.php
r3435296 r3454961 40 40 $this->groupByFields['o_builtin::order_quarter'] = 'Order Quarter'; 41 41 $this->groupByFields['o_builtin::order_year'] = 'Order Year'; 42 $this->groupByFields['o_builtin::order_source'] = 'Order Source'; 42 43 if ($this->supports(PlatformFeatures::ORDER_SOURCE)) { 44 $this->groupByFields['o_builtin::order_source'] = 'Order Source'; 45 } 43 46 44 47 $fields = \NinjalyticsFree\ninjalytics_get_order_item_fields($this); -
product-sales-report-for-woocommerce/trunk/includes/reporters/woocommerce.php
r3435296 r3454961 83 83 84 84 public function getPlatformFeatures() { 85 return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::CHILD_ITEMS_META, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS ];85 return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::CHILD_ITEMS_META, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS, PlatformFeatures::ORDER_SOURCE]; 86 86 } 87 87 -
product-sales-report-for-woocommerce/trunk/js/ninjalytics.js
r3435296 r3454961 444 444 445 445 $('#ninjalytics-settings .hm-psr-select-other') 446 .append($('<option>').html('Other...'). addClass('hm-psr-select-other-option'))446 .append($('<option>').html('Other...').prop('disabled', true).addClass('hm-psr-select-other-option')) 447 447 .closest('select') 448 448 .change(function() { -
product-sales-report-for-woocommerce/trunk/readme.txt
r3445620 r3454961 5 5 Requires PHP: 8.1 6 6 Tested up to: 6.9 7 Stable tag: 2.0.1 07 Stable tag: 2.0.11 8 8 License: GPLv3 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 183 183 184 184 == Changelog == 185 186 = 2.0.11, 2025-02-05 = 187 - Add: Quick Dates (last X days, etc) to report dates 188 - Fix: Order source issue 189 - Fix: "Other" (custom) report fields should have disabled state 185 190 186 191 = 2.0.10, 2025-01-23 =
Note: See TracChangeset
for help on using the changeset viewer.