Forums / Addon Admin Tools / Sales report 2.0

Sales report 2.0

Started by blindside on 29 Aug 2006, 2:41 AM · Views: 248,187

Results 721 to 740 of 882
2 Jan 2018, 7:41 PM
#721
gerrim avatar

gerrim

New Zenner

Join Date:
Jul 2013
Location:
Brisbane, Australia
Posts:
39
Plugin Contributions:
0

Sales report 2.0

This is a great plugin and installation went very smoothly indeed. Thank you to all contributors!

I was wondering how hard it would be to change the default YTD to Financial YTD (i.e. a date range of 1 July to current date - instead of 1 Jan to current date). I've been searching the various files to try and pinpoint where the relevant constant is allocated the start date without much luck (am not experienced enough to work out where I should be making this change).

Could anyone please point me in the right direction?

Thanks...and happy new year to all Zenners!

2 Jan 2018, 9:49 PM
#722
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Sales report 2.0

At first glance it looks like your_admin/stats_sales_report.php line 161 to 205 would be where you could amend the desired dates.

3 Jan 2018, 11:07 AM
#723
gerrim avatar

gerrim

New Zenner

Join Date:
Jul 2013
Location:
Brisbane, Australia
Posts:
39
Plugin Contributions:
0

Re: Sales report 2.0

southshorepizza:

At first glance it looks like your_admin/stats_sales_report.php line 161 to 205 would be where you could amend the desired dates.

Thanks for responding. I'll see what I can do.

18 Feb 2018, 7:47 PM
#724
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Sales report 2.0

Installed Sales Report v3.2.0 in zc155e. PHP version 5.6.31. I'm getting a PHP warning for a null array argument in in_array. Error message follows:

PHP Warning: in_array() expects parameter 2 to be array, null given in ...admin/includes/classes/sales_report.php on line 403
Existing out-of-the-box code is:

            // check to see if product is unique in this timeframe
            // add to 'diff_products' array if so
            if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
                $this->timeframe[$id]['total']['diff_products'][] = $pID;
            }

            if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
            }

Should the code be something like this?

            // check to see if product is unique in this timeframe
            // add to 'diff_products' array if so
            if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
                $this->timeframe[$id]['total']['diff_products'][] = $pID;
            }

            if (is_null($this->timeframe[$id]['orders'][$oID]['diff_products']) || !in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
            }

Should a similar change be made to the if clause above the modified one?

Thanks!

22 Feb 2018, 8:04 PM
#725
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Sales report 2.0

Or should the array be initialized somewhere???

22 Feb 2018, 8:17 PM
#726
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Sales report 2.0

The code in function output_csv in admin/includes/classes/sales_report.php sets a filename that includes the report start date and end date, but the variables representing the dates are not set. Original code at line 881:

        $filename = CSV_FILENAME_PREFIX . date('Ymd', $startDate) . "-" . date('Ymd', $endDate);

The following code is one fix for the problem:

        $filename = CSV_FILENAME_PREFIX . date('Ymd', $this->sd_raw) . "-" . date('Ymd', $this->ed_raw);
24 Feb 2018, 1:20 AM
#727
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Sales report 2.0

Dave224:

Installed Sales Report v3.2.0 in zc155e. PHP version 5.6.31. I'm getting a PHP warning for a null array argument in in_array. Error message follows:

Existing out-of-the-box code is:

        // check to see if product is unique in this timeframe
        // add to 'diff_products' array if so
        if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
            $this->timeframe[$id]['total']['diff_products'][] = $pID;
        }

        if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
            $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
        }
> 
> Should the code be something like this?
> ```
            // check to see if product is unique in this timeframe
            // add to 'diff_products' array if so
            if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
                $this->timeframe[$id]['total']['diff_products'][] = $pID;
            }

            if (is_null($this->timeframe[$id]['orders'][$oID]['diff_products']) || !in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
            }

Should a similar change be made to the if clause above the modified one?

Thanks!

dave,
you seem to be a smart enough guy, why don't you try it and let us know if it works? the effort required to post your solution seems greater than the effort involved in trying your own solution to see if it resolves the problem.

if you wanted to initialize the arrays, you can do it above the while statement on line 348:

$this->timeframe[$id]['orders'][$oID]['diff_products'] = array();
$this->timeframe[$id]['total']['diff_products'] = array();

i like that idea more than the modified if statement, mostly because i am not sure the if statement would resolve the warning.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

28 Feb 2018, 5:04 PM
#728
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Sales report 2.0

There's a problem in Sales Report version 3.2.0 in file admin/stats_sales_report.php at line 387 where the input date target (purchased date, or status date) and input order status are not output properly. Original code in v3.2.0 is:

    $date_target = PRINT_DATE_TARGET;
    if ($date_target == 'purchased') {
        $date_target .= PRINT_DATE_PURCHASED;
    } elseif ($date_target == 'status') {
        $date_target .= (PRINT_DATE_STATUS . ' (' . $status_key[$date_status] . ')');
    }

The above code sets $date_target to the constant PRINT_DATE_CONSTANT in the first line and the subsequent if and elseif tests will never be satisfied.

The following is one approach to fix the problem:

    $date_target = PRINT_DATE_TARGET;
    if ($_GET['date_target'] == 'purchased') {
        $date_target .= PRINT_DATE_PURCHASED;
    } elseif ($_GET['date_target'] == 'status') {
        $date_target .= (PRINT_DATE_STATUS . ' (' . $status_key[$date_status] . ')');
    }

In this approach, $_GET['date_target'] is the input date target. Another approach is to revert to the code in a previous version of sales report.

1 Mar 2018, 11:29 PM
#729
fiddlestix avatar

fiddlestix

New Zenner

Join Date:
Jan 2010
Location:
Northwe't USA
Posts:
7
Plugin Contributions:
0

Re: Sales report 2.0

I'm testing an upgrade from Zen Cart 1.54 to 1.55f and PHP 5.6 to PHP 7.0.27. (and our addons)
I look at PHP every few years when I feel guilted into doing an upgrade, so I'm definitely not comfortable making changes.

Thanks, Dave222, for your solution posted in 725 above. That saved me even more grey hair.

I tried the arrays initialization suggested in 728, sadly that removed the Order and Customer data from the report. I put it (just above the while stmt line 348). Perhaps it would be effective somewhere else. But, unfortunately PHP looks like a bunch of symbols to me, so I'm not quite sure where else to try it. Back in the olden days, I programmed in other languages, so I'm a fan of initializing the arrays, but...as much as I stare at this, senior moments aside, I can't really figure it out.

When testing the CSV for Product Line Items (In admin/includes/classes/sales_report.php), I was getting this error:
PHP Warning: Invalid argument supplied for foreach() in ...includes/classes/sales_report.php on line 1043
AND
*Argument #1 is expected to be an array or a sort flag in .../includes/classes/sales_report.php on line 1050 *

Since I don't know what I'm doing, I just copied the if ...null...continue statement from the order level and changed the timeframe to products and that seemed to do the trick. This is about line 1040.

case 'product':
    // sort the products according to requested sort options
    unset($dataset1, $dataset2);
    foreach($timeframe['products'] as $pID => $p_data) {

CHANGED TO

case 'product':
   // sort the products according to requested sort options
   unset($dataset1, $dataset2);
   if (is_null($timeframe['products'])) {
       // Ignore days for which no info exists
	continue;
   }
   foreach($timeframe['products'] as $pID => $p_data) {
31 Mar 2018, 12:11 AM
#730
soxophoneplayer avatar

soxophoneplayer

Totally Zenned

Join Date:
Feb 2008
Posts:
534
Plugin Contributions:
0

Re: Sales report 2.0

Dave224:

Installed Sales Report v3.2.0 in zc155e. PHP version 5.6.31. I'm getting a PHP warning for a null array argument in in_array. Error message follows:

Existing out-of-the-box code is:

        // check to see if product is unique in this timeframe
        // add to 'diff_products' array if so
        if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
            $this->timeframe[$id]['total']['diff_products'][] = $pID;
        }

        if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
            $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
        }
> 
> Should the code be something like this?
> ```
            // check to see if product is unique in this timeframe
            // add to 'diff_products' array if so
            if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
                $this->timeframe[$id]['total']['diff_products'][] = $pID;
            }

            if (is_null($this->timeframe[$id]['orders'][$oID]['diff_products']) || !in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
            }

Should a similar change be made to the if clause above the modified one?

Thanks!

I had same php warning in logs. Report still worked correctly, just produced the log error. I trid the code change as above and now no error is logged when I generate a report. Thanks for posting.

10 Jun 2018, 9:30 AM
#731
brent avatar

brent

Totally Zenned

Join Date:
Mar 2005
Location:
United Kingdom
Posts:
606
Plugin Contributions:
0

Re: Sales report 2.0

Hi,

When running the report I get the following error:

[10-Jun-2018 07:03:53 UTC] Request URI: /admin/stats_sales_report.php?start_date=01%2F06%2F2017&end_date=10+%2F06%2F2017&date_target=purchased&date_status=1&prod_includes=&cust_includes=&payment_method=&payment_method_omit=&current_status=&manufacturer=0&timeframe=year&timeframe_sort=asc&detail_level=order&li_sort_a=oID&li_sort_order_a=asc&li_sort_b=oID&li_sort_order_b=asc&output_format=display&new_window=1, IP address: ..123.202
#1 mktime() called at [/.../.../admin/includes/classes/sales_report.php:69]
#2 sales_report->__construct() called at [/.../admin/stats_sales_report.php:245]

[10-Jun-2018 07:03:53 UTC] PHP Warning: mktime() expects parameter 4 to be integer, string given in /.../.../admin/includes/classes/sales_report.php on line 69

Zen Cart 1.5.5f
PHP Version 7.1.18

Could someone point me in the right direction to fix this please?

24 Jan 2019, 1:11 PM
#732
harry2cool avatar

harry2cool

Zen Follower

Join Date:
Oct 2005
Posts:
280
Plugin Contributions:
0

Re: Sales report 2.0

Why do I get extended information under "Time Frame" i.e:
IST0JanE_Tue0st+05:300AM2019_TueAM2019

Zencart Ver 1.5.6a
Php 7

Thanks

25 Jan 2019, 6:20 AM
#733
oldngrey avatar

oldngrey

Zen Follower

Join Date:
Apr 2008
Location:
Qld, Australia
Posts:
433
Plugin Contributions:
0

Re: Sales report 2.0

harry2cool:

Why do I get extended information under "Time Frame" i.e:
IST0JanE_Tue0st+05:300AM2019_TueAM2019

Zencart Ver 1.5.6a
Php 7

Thanks

in the file
YOUR_ADMIN\includes\classes\sales_report.php
at the top of the file at approx line 29 define the date format you use eg

define('DATE_FORMAT', 'd/m/Y'); // this is used for date() // addition for PHP 7

Change the comments at the end of the line to your standard for comments

OldNGrey
ZC222 PHP 8.4.27
MySQL 11.8.5-MariaDB

25 Jan 2019, 6:23 AM
#734
oldngrey avatar

oldngrey

Zen Follower

Join Date:
Apr 2008
Location:
Qld, Australia
Posts:
433
Plugin Contributions:
0

Re: Sales report 2.0

If using PHP 7.3 the following changes will be required. In the file

YOUR_ADMIN\includes\classes\sales_report.php

for compliance with PHP 7.3 change "continue;" to "continue 2;" at approx line 1000,
for compliance with PHP 7.3 change "continue;" to "continue 3;" at approx line 1014

Always perform changes in a test environment and back up before making changes

OldNGrey
ZC222 PHP 8.4.27
MySQL 11.8.5-MariaDB

25 Jan 2019, 5:03 PM
#735
harry2cool avatar

harry2cool

Zen Follower

Join Date:
Oct 2005
Posts:
280
Plugin Contributions:
0

Re: Sales report 2.0

We have tried everything, however it's a strange server issue, because on our other website with the newer version the Timeframes show properly.
Any server/php int changes suggested for this particular website ?
This is what I get under TimeFrame column:
The date is not shown;

IST0JanE_Tue0st+05:300AM2019_TueAM2019
IST0JanE_Wed0nd+05:300AM2019_WedAM2019
IST0JanE_Thu0rd+05:300AM2019_ThuAM2019
IST0JanE_Fri0th+05:300AM2019_FriAM2019
IST0JanE_Sat0th+05:300AM2019_SatAM2019
IST0JanE_Sun0th+05:300AM2019_SunAM2019
IST0JanE_Mon0th+05:300AM2019_MonAM2019
IST0JanE_Tue0th+05:300AM2019_TueAM2019
IST0JanE_Wed0th+05:300AM2019_WedAM2019
IST0JanE_Thu0th+05:300AM2019_ThuAM2019
IST0JanE_Fri0th+05:300AM2019_FriAM2019
IST0JanE_Sat0th+05:300AM2019_SatAM2019
IST0JanE_Sun0th+05:300AM2019_SunAM2019
IST0JanE_Mon0th+05:300AM2019_MonAM2019
IST0JanE_Tue0th+05:300AM2019_TueAM2019
IST0JanE_Wed0th+05:300AM2019_WedAM2019
IST0JanE_Thu0th+05:300AM2019_ThuAM2019
IST0JanE_Fri0th+05:300AM2019_FriAM2019
IST0JanE_Sat0th+05:300AM2019_SatAM2019
IST0JanE_Sun0th+05:300AM2019_SunAM2019
IST0JanE_Mon0st+05:300AM2019_MonAM2019
IST0JanE_Tue0nd+05:300AM2019_TueAM2019
IST0JanE_Wed0rd+05:300AM2019_WedAM2019
IST0JanE_Thu0th+05:300AM2019_ThuAM2019
IST0JanE_Fri0th+05:300AM2019_FriAM2019

25 Jan 2019, 5:08 PM
#736
harry2cool avatar

harry2cool

Zen Follower

Join Date:
Oct 2005
Posts:
280
Plugin Contributions:
0

Re: Sales report 2.0

Got below on the logs:

===========
[25-Jan-2019 22:34:59 Asia/Kolkata] PHP Warning: in_array() expects parameter 2 to be array, null given in /home/harry2co/public_html/admin/includes/classes/sales_report.php on line 403
[25-Jan-2019 22:34:59 Asia/Kolkata] Request URI: /adminname/stats_sales_report.php?date_preset=this_month&start_date=&end_date=&date_target=purchased&date_status=1&prod_includes=&cust_includes=&payment_method=&payment_method_omit=&current_status=&manufacturer=0&timeframe=day&timeframe_sort=asc&detail_level=timeframe&li_sort_order_a=asc&li_sort_order_b=asc&output_format=display, IP address: xxx.yy.26.190
#1 in_array() called at [/home/harry2co/public_html/adminname/includes/classes/sales_report.php:403]
#2 sales_report->build_li_totals() called at [/home/harry2co/public_html/adminname/includes/classes/sales_report.php:259]
#3 sales_report->build_timeframe() called at [/home/harry2co/public_html/adminname/includes/classes/sales_report.php:107]
#4 sales_report->__construct() called at [/home/harry2co/public_html/adminname/stats_sales_report.php:245]

Please guide.
Thanks

26 Jan 2019, 1:14 AM
#737
oldngrey avatar

oldngrey

Zen Follower

Join Date:
Apr 2008
Location:
Qld, Australia
Posts:
433
Plugin Contributions:
0

Re: Sales report 2.0

Please list the Zen cart version and PHP version and version of Sale Report you are using to test this.

OldNGrey
ZC222 PHP 8.4.27
MySQL 11.8.5-MariaDB

26 Jan 2019, 5:19 AM
#738
harry2cool avatar

harry2cool

Zen Follower

Join Date:
Oct 2005
Posts:
280
Plugin Contributions:
0

Re: Sales report 2.0

Zencart Ver 1.5.6a
Php 7

26 Jan 2019, 6:35 AM
#740
oldngrey avatar

oldngrey

Zen Follower

Join Date:
Apr 2008
Location:
Qld, Australia
Posts:
433
Plugin Contributions:
0

Re: Sales report 2.0

Sales Report 2.0 (Version 3.2.0) PHP 7.x

The following changes are required as a minimum. My line numbers are higher than for the original files due to inserted comments for all changes I make.

file: YOUR_ADMIN\includes\classes\sales_report.php
where: at the top of the file approx line 29

define('DATE_FORMAT', 'd/m/Y'); // this is used for date() // BMH addition PHP 7

file: YOUR_ADMIN\includes\classes\sales_report.php
where: at approx lines 266, 270 CHANGE

if (count($this->timeframe[$id]['orders']) == 0) {
        $this->timeframe[$id]['orders'] = false;

TO

 if (empty($this->timeframe[$id]['products'])) { 
        $this->timeframe[$id]['orders'] = false;

file: YOUR_ADMIN\includes\classes\sales_report.php
where: at approx line 411 CHANGE

if (!in_array($pID, $this->timeframe[$id]['total']['diff_products'])) {
       $this->timeframe[$id]['total']['diff_products'][] = $pID;
}

TO

if (!empty($this->timeframe[$id]['orders'][$oID]['diff_products']) ) {
		if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                   $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
		}
	}

file: YOUR_ADMIN\includes\classes\sales_report.php
where: at approx line 417 CHANGE

if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
                $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
       }

TO

if (!empty($this->timeframe[$id]['orders'][$oID]['diff_products']) ) {
    if (!in_array($pID, $this->timeframe[$id]['orders'][$oID]['diff_products'])) {
           $this->timeframe[$id]['orders'][$oID]['diff_products'][] = $pID;
    }
}

Perform these changes in a test environment making only one change at a time and review your log files after each test of the report. Add comments to your code.

OldNGrey
ZC222 PHP 8.4.27
MySQL 11.8.5-MariaDB