Plugin Directory

Changeset 3398377


Ignore:
Timestamp:
11/18/2025 09:51:54 PM (2 months ago)
Author:
berrypress
Message:

Update to version 2.0.5 from GitHub

Location:
product-sales-report-for-woocommerce
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • product-sales-report-for-woocommerce/tags/2.0.5/admin/admin.php

    r3393922 r3398377  
    13531353                <div class="ninjalytics-settings-box ags-psr-advanced">
    13541354                        <label class="ninjalytics-settings-label-column">
    1355                             <input disabled type="checkbox" name="report_unfiltered"'.(empty($reportSettings['report_unfiltered']) ? '' : ' checked="checked"').'>
    1356                             <span class="label">Attempt to prevent other plugins or code from changing the export query or output <span class="ninjalytics-pro-badge">Pro</span>'./* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'report-unfiltered' ).'</span>
     1355                            <input type="checkbox" name="report_unfiltered"'.(empty($reportSettings['report_unfiltered']) ? '' : ' checked="checked"').'>
     1356                            <span class="label">Attempt to prevent other plugins or code from changing the export query or output</span>
    13571357                        </label>
    1358                     './* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'remove-html' ).'
     1358                    './* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'report-unfiltered' ).'
    13591359                </div>
    13601360               
  • product-sales-report-for-woocommerce/tags/2.0.5/hm-product-sales-report.php

    r3393922 r3398377  
    44 * Description:          Generates a report on individual WooCommerce products sold during a specified time period.
    55 * Plugin URI:           https://berrypress.com/product/woocommerce/ninjalytics/
    6  * Version:              2.0.4
    7  * WC tested up to:      10.2
     6 * Version:              2.0.5
     7 * WC tested up to:      10.3
    88 * WC requires at least: 2.2
    99 * Author:               BerryPress
     
    4444use Ninjalytics\Reporters\PlatformFeatures;
    4545
    46 define('NINJALYTICS_VERSION', '2.0.4');
     46define('NINJALYTICS_VERSION', '2.0.5');
    4747
    4848add_filter('default_option_ninjalytics_settings', 'ninjalytics_psr_import');
     
    119119        'refunds' => 1,
    120120        'adjustments' => 1,
     121        'report_unfiltered' => 0,
    121122        'report_title_on' => 0,
    122123        'report_title' => '[preset] - [start] to [end]',
     
    188189            'builtin::discount' => 'Total Discount Amount',
    189190            'builtin::taxes' => 'Taxes'
    190         ];
     191        ]
     192        + ($reporter->supports(PlatformFeatures::COGS) ? [
     193            'builtin::cogs' => 'Cost of Goods Sold',
     194            'builtin::profit' => 'Profit',
     195            'builtin::margin' => 'Gross Margin',
     196            'builtin::item_cogs' => 'Current COGS per Item',
     197        ] : []);
    191198       
    192199        foreach (ninjalytics_get_tax_types() as $taxTypeId => $taxType) {
     
    356363            foreach (array(
    357364                'limit_on', 'include_nil', 'include_shipping', 'include_unpublished', 'include_header', 'include_totals',
    358                 'format_amounts', 'exclude_free',
     365                'format_amounts', 'exclude_free', 'report_unfiltered',
    359366                'refunds', 'adjustments', 'report_title_on', 'hm_psr_debug', 'disable_product_grouping', 'intermediate_rounding'
    360367                ) as $checkboxField) {
     
    826833    }
    827834   
     835    // Remove existing filters if the unfiltered option is on
     836    if (!empty($_POST['report_unfiltered'])) {
     837        remove_all_filters('woocommerce_reports_get_order_report_data_args');
     838        remove_all_filters('woocommerce_reports_order_statuses');
     839        remove_all_filters('woocommerce_reports_get_order_report_query');
     840        remove_all_filters('woocommerce_reports_get_order_report_data');
     841    }
     842   
    828843    // Avoid max join size error
    829844// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     
    858873        if (!empty($_POST['refunds'])) {
    859874            $refunded_products = ninjalytics_getReportData($wc_report, $baseFields, ($productsFiltered ? $product_ids : null), $start_date, $end_date, true);
    860             $sold_products = ninjalytics_process_refunds($sold_products, $refunded_products, array(
     875            $sold_products = ninjalytics_process_refunds($sold_products, $refunded_products, array_merge(array(
    861876                'quantity',
    862877                'gross',
    863878                'gross_after_discount',
    864879                'taxes'
    865             ), (int) $_POST['disable_product_grouping'], ((int) $_POST['disable_product_grouping']) == 2 ? 'product_category' : '');
     880            ), ($wc_report->supports(PlatformFeatures::COGS) ? ['cogs'] : [])),
     881            (int) $_POST['disable_product_grouping'], ((int) $_POST['disable_product_grouping']) == 2 ? 'product_category' : '');
    866882        }
    867883       
     
    11591175                            get_the_time('Y-m-d H:i:s', $productId);
    11601176                        }, $product->_product_ids);
     1177                        break;
     1178                    case 'builtin::cogs':
     1179                        $rowValue = $product->cogs ?? '';
     1180                        break;
     1181                    case 'builtin::profit':
     1182                        $rowValue = isset($product->cogs) ? ($product->gross_after_discount - $product->cogs) : '';
     1183                        break;
     1184                    case 'builtin::margin':
     1185                        $rowValue = isset($product->cogs) ? (($product->gross_after_discount - $product->cogs) / $product->gross_after_discount) : '';
     1186                        break;
     1187                    case 'builtin::item_cogs':
     1188                        $rowValueDelimiter = ', ';
     1189                        $rowValue = array_map(function($itemId) {
     1190                            return get_post_meta($itemId, '_cogs_total_value', true);
     1191                        }, $product->_variation_ids ? $product->_variation_ids : ($product->_product_ids ? $product->_product_ids : []));
     1192                        break;
     1193                    case 'builtin::cogs':
     1194                        $rowValue = $product->cogs ?? '';
     1195                        break;
     1196                    case 'builtin::item_cogs':
     1197                        $rowValueDelimiter = ', ';
     1198                        $rowValue = array_map(function($itemId) {
     1199                            return get_post_meta($itemId, '_cogs_total_value', true);
     1200                        }, $product->_variation_ids ? $product->_variation_ids : ($product->_product_ids ? $product->_product_ids : []));
    11611201                        break;
    11621202                    case 'builtin::line_item_count':
     
    13671407                    $rowValue = get_the_time('Y-m-d H:i:s', $productId);
    13681408                    break;
     1409                case 'builtin::item_cogs':
     1410                    $rowValue = get_post_meta($variationId ? $variationId : $productId, '_cogs_total_value', true);
     1411                    break;
    13691412               
    13701413                // hm-export-order-items-pro\hm-export-order-items-pro.php
  • product-sales-report-for-woocommerce/tags/2.0.5/includes/reporters/base.php

    r3393922 r3398377  
    1414    case CHILD_ITEMS;
    1515    case META;
     16    case COGS;
    1617}
    1718
  • product-sales-report-for-woocommerce/tags/2.0.5/includes/reporters/woocommerce.php

    r3379586 r3398377  
    5555   
    5656    public function getPlatformFeatures() {
    57         return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS];
     57        return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS];
    5858    }
    5959   
     
    9696    }
    9797   
     98    public function getDataParams($baseFields) {
     99        $dataParams = parent::getDataParams($baseFields);
     100       
     101        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This is a helper function, to be called after nonce is checked as needed
     102        $intermediateRounding = !empty( $_POST['intermediate_rounding'] );
     103       
     104        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This is a helper function, to be called after nonce is checked as needed
     105        if (empty($_POST['export_orders']) || in_array('builtin::cogs', $_POST['fields'] ?? [])) {
     106            $dataParams[ '_cogs_value' ] = array(
     107                'type' => 'order_item_meta',
     108                'order_item_type' => 'line_item',
     109                'function' => ($intermediateRounding ? 'PSRSUM' : 'SUM'),
     110                'name' => 'cogs',
     111                'join_type' => 'LEFT'
     112            );
     113        }
     114        return $dataParams;
     115    }
    98116   
    99117    public function getVirtualOrderMeta() {
  • product-sales-report-for-woocommerce/tags/2.0.5/readme.txt

    r3393922 r3398377  
    182182
    183183== Changelog ==
     184
     185= 2.0.5, 2025-11-18 =
     186- Add support for Cost of Goods
     187- Add new fields:
     188    - Cost of Goods Sold
     189    - Profit
     190    - Gross Margin
     191    - Current COGS per item
    184192
    185193= 2.0.4, 2025-11-11 =
  • product-sales-report-for-woocommerce/trunk/admin/admin.php

    r3393922 r3398377  
    13531353                <div class="ninjalytics-settings-box ags-psr-advanced">
    13541354                        <label class="ninjalytics-settings-label-column">
    1355                             <input disabled type="checkbox" name="report_unfiltered"'.(empty($reportSettings['report_unfiltered']) ? '' : ' checked="checked"').'>
    1356                             <span class="label">Attempt to prevent other plugins or code from changing the export query or output <span class="ninjalytics-pro-badge">Pro</span>'./* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'report-unfiltered' ).'</span>
     1355                            <input type="checkbox" name="report_unfiltered"'.(empty($reportSettings['report_unfiltered']) ? '' : ' checked="checked"').'>
     1356                            <span class="label">Attempt to prevent other plugins or code from changing the export query or output</span>
    13571357                        </label>
    1358                     './* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'remove-html' ).'
     1358                    './* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ self::docsLink( 'report-configuration/data-and-display', 'report-unfiltered' ).'
    13591359                </div>
    13601360               
  • product-sales-report-for-woocommerce/trunk/hm-product-sales-report.php

    r3393922 r3398377  
    44 * Description:          Generates a report on individual WooCommerce products sold during a specified time period.
    55 * Plugin URI:           https://berrypress.com/product/woocommerce/ninjalytics/
    6  * Version:              2.0.4
    7  * WC tested up to:      10.2
     6 * Version:              2.0.5
     7 * WC tested up to:      10.3
    88 * WC requires at least: 2.2
    99 * Author:               BerryPress
     
    4444use Ninjalytics\Reporters\PlatformFeatures;
    4545
    46 define('NINJALYTICS_VERSION', '2.0.4');
     46define('NINJALYTICS_VERSION', '2.0.5');
    4747
    4848add_filter('default_option_ninjalytics_settings', 'ninjalytics_psr_import');
     
    119119        'refunds' => 1,
    120120        'adjustments' => 1,
     121        'report_unfiltered' => 0,
    121122        'report_title_on' => 0,
    122123        'report_title' => '[preset] - [start] to [end]',
     
    188189            'builtin::discount' => 'Total Discount Amount',
    189190            'builtin::taxes' => 'Taxes'
    190         ];
     191        ]
     192        + ($reporter->supports(PlatformFeatures::COGS) ? [
     193            'builtin::cogs' => 'Cost of Goods Sold',
     194            'builtin::profit' => 'Profit',
     195            'builtin::margin' => 'Gross Margin',
     196            'builtin::item_cogs' => 'Current COGS per Item',
     197        ] : []);
    191198       
    192199        foreach (ninjalytics_get_tax_types() as $taxTypeId => $taxType) {
     
    356363            foreach (array(
    357364                'limit_on', 'include_nil', 'include_shipping', 'include_unpublished', 'include_header', 'include_totals',
    358                 'format_amounts', 'exclude_free',
     365                'format_amounts', 'exclude_free', 'report_unfiltered',
    359366                'refunds', 'adjustments', 'report_title_on', 'hm_psr_debug', 'disable_product_grouping', 'intermediate_rounding'
    360367                ) as $checkboxField) {
     
    826833    }
    827834   
     835    // Remove existing filters if the unfiltered option is on
     836    if (!empty($_POST['report_unfiltered'])) {
     837        remove_all_filters('woocommerce_reports_get_order_report_data_args');
     838        remove_all_filters('woocommerce_reports_order_statuses');
     839        remove_all_filters('woocommerce_reports_get_order_report_query');
     840        remove_all_filters('woocommerce_reports_get_order_report_data');
     841    }
     842   
    828843    // Avoid max join size error
    829844// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     
    858873        if (!empty($_POST['refunds'])) {
    859874            $refunded_products = ninjalytics_getReportData($wc_report, $baseFields, ($productsFiltered ? $product_ids : null), $start_date, $end_date, true);
    860             $sold_products = ninjalytics_process_refunds($sold_products, $refunded_products, array(
     875            $sold_products = ninjalytics_process_refunds($sold_products, $refunded_products, array_merge(array(
    861876                'quantity',
    862877                'gross',
    863878                'gross_after_discount',
    864879                'taxes'
    865             ), (int) $_POST['disable_product_grouping'], ((int) $_POST['disable_product_grouping']) == 2 ? 'product_category' : '');
     880            ), ($wc_report->supports(PlatformFeatures::COGS) ? ['cogs'] : [])),
     881            (int) $_POST['disable_product_grouping'], ((int) $_POST['disable_product_grouping']) == 2 ? 'product_category' : '');
    866882        }
    867883       
     
    11591175                            get_the_time('Y-m-d H:i:s', $productId);
    11601176                        }, $product->_product_ids);
     1177                        break;
     1178                    case 'builtin::cogs':
     1179                        $rowValue = $product->cogs ?? '';
     1180                        break;
     1181                    case 'builtin::profit':
     1182                        $rowValue = isset($product->cogs) ? ($product->gross_after_discount - $product->cogs) : '';
     1183                        break;
     1184                    case 'builtin::margin':
     1185                        $rowValue = isset($product->cogs) ? (($product->gross_after_discount - $product->cogs) / $product->gross_after_discount) : '';
     1186                        break;
     1187                    case 'builtin::item_cogs':
     1188                        $rowValueDelimiter = ', ';
     1189                        $rowValue = array_map(function($itemId) {
     1190                            return get_post_meta($itemId, '_cogs_total_value', true);
     1191                        }, $product->_variation_ids ? $product->_variation_ids : ($product->_product_ids ? $product->_product_ids : []));
     1192                        break;
     1193                    case 'builtin::cogs':
     1194                        $rowValue = $product->cogs ?? '';
     1195                        break;
     1196                    case 'builtin::item_cogs':
     1197                        $rowValueDelimiter = ', ';
     1198                        $rowValue = array_map(function($itemId) {
     1199                            return get_post_meta($itemId, '_cogs_total_value', true);
     1200                        }, $product->_variation_ids ? $product->_variation_ids : ($product->_product_ids ? $product->_product_ids : []));
    11611201                        break;
    11621202                    case 'builtin::line_item_count':
     
    13671407                    $rowValue = get_the_time('Y-m-d H:i:s', $productId);
    13681408                    break;
     1409                case 'builtin::item_cogs':
     1410                    $rowValue = get_post_meta($variationId ? $variationId : $productId, '_cogs_total_value', true);
     1411                    break;
    13691412               
    13701413                // hm-export-order-items-pro\hm-export-order-items-pro.php
  • product-sales-report-for-woocommerce/trunk/includes/reporters/base.php

    r3393922 r3398377  
    1414    case CHILD_ITEMS;
    1515    case META;
     16    case COGS;
    1617}
    1718
  • product-sales-report-for-woocommerce/trunk/includes/reporters/woocommerce.php

    r3379586 r3398377  
    5555   
    5656    public function getPlatformFeatures() {
    57         return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS];
     57        return [PlatformFeatures::CHILD_ITEMS, PlatformFeatures::META, PlatformFeatures::VARIATIONS, PlatformFeatures::SHIPPING, PlatformFeatures::CUSTOMER_USERS, PlatformFeatures::COGS];
    5858    }
    5959   
     
    9696    }
    9797   
     98    public function getDataParams($baseFields) {
     99        $dataParams = parent::getDataParams($baseFields);
     100       
     101        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This is a helper function, to be called after nonce is checked as needed
     102        $intermediateRounding = !empty( $_POST['intermediate_rounding'] );
     103       
     104        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This is a helper function, to be called after nonce is checked as needed
     105        if (empty($_POST['export_orders']) || in_array('builtin::cogs', $_POST['fields'] ?? [])) {
     106            $dataParams[ '_cogs_value' ] = array(
     107                'type' => 'order_item_meta',
     108                'order_item_type' => 'line_item',
     109                'function' => ($intermediateRounding ? 'PSRSUM' : 'SUM'),
     110                'name' => 'cogs',
     111                'join_type' => 'LEFT'
     112            );
     113        }
     114        return $dataParams;
     115    }
    98116   
    99117    public function getVirtualOrderMeta() {
  • product-sales-report-for-woocommerce/trunk/readme.txt

    r3393922 r3398377  
    182182
    183183== Changelog ==
     184
     185= 2.0.5, 2025-11-18 =
     186- Add support for Cost of Goods
     187- Add new fields:
     188    - Cost of Goods Sold
     189    - Profit
     190    - Gross Margin
     191    - Current COGS per item
    184192
    185193= 2.0.4, 2025-11-11 =
Note: See TracChangeset for help on using the changeset viewer.