Jump to content

Sales Graph in Admin not appearing


peterp

Recommended Posts

Hi All,

I have just upgraded a client to the new ver 5.2.4 and now when they log in the Sales graph on the dasboard does not appear, have I failed to do something or is this new functionality.

Hope somebody can advise and hankyou in anticipation

Link to comment
Share on other sites

At about line 110 in the file /admin/sources/dashboard.index.php, there is (line split for readability):

$sales = $GLOBALS['db']->select('CubeCart_order_summary',
array('order_date', 'total'),
array('order_date' => '>='.mktime(0,0,0,date('m', $last_year),1,date('Y', $last_year)),
'status' => array(3), 'total' => '>0'));
The resulting query is:
SELECT `order_date`, `total` FROM `CubeCart_order_summary`
WHERE CubeCart_order_summary.order_date >= '-2653200'
AND `status` IN (3) AND CubeCart_order_summary.total > '0' ;
The CubeCart_order_summary.order_date >= '-2653200' is miscalculated.

 

This:

mktime(0,0,0,date('m', $last_year),1,date('Y', $last_year))

should be:

mktime(0,0,0,1,1,$last_year)

 

Then, near lines 123-124:

$this_year = strftime('%G',strtotime('this year'));
$last_year = strftime('%G',strtotime('last year'));
The %G specifier is not recognized by Windows systems. It can be fixed by two parts:
$this_year = strftime((PHP_WIN ? '%Y' : '%G'),strtotime('this year'));
$last_year = strftime((PHP_WIN ? '%Y' : '%G'),strtotime('last year'));
And also, in /ini.inc.php, after this:
define('PHP_5_3', version_compare(PHP_VERSION, '5.3.0', '>='));
add:
define('PHP_WIN', strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
What's the difference between %Y and %G? According to a certain ISO standard, if the first week in a year has three or fewer days in it, that week actually belongs to the prior year. %Y gets the year, absolutely.
Link to comment
Share on other sites

Also, looking at dashboard.index.inc.php, comparing lines 128 vs 134, we see that the order of chart data is switched:
['Month', '$this_year', '$last_year']
['$m',  $last_year_month,      $this_year_month]
 
I suggest fixing the order of arguments in the second statement:
['$m', $this_year_month, $last_year_month]
 
(Although the natural tendency is to read left to right, earlier years to later years.)

Link to comment
Share on other sites

The legend on the right-side of the chart gives two years, each in a color. The colors of the actual bars are reversed. That is, if your legend says the 2013 year is red, it's the blue bars that are representing sales in 2013.

 

You won't notice anything significant if your sales are fairly equal between this year and last.

Link to comment
Share on other sites

Al

 

Any chance of posting the patched file for this if it is a single file that doesnt cause any problems being patched by itself ?

 

Also is it possible to request that a lot more detailed reports be added to the next or a at least a future release, such as by day for a selected month and a lot more comparative reports be added.  Many stores have a huge amount of interesting data on sales stored but without extracting that and doing complicated excel spreadsheets which are beyond most users there is no way to see this.  The reporting side is one area that would REALLY benefit from some serious work !

 

Thanks

Ian

Link to comment
Share on other sites

Hi Ian,

 

I'm also keen to improve reporting for the next major release. Hopefully we can do that...  

 

Latest admin/sources/dashboard.index.inc.php file is below:

<?php
/*
+--------------------------------------------------------------------------
|   CubeCart 5
|   ========================================
|	CubeCart is a registered trade mark of Devellion Limited
|   Copyright Devellion Limited 2006. All rights reserved.
|	License Type: CubeCart is NOT Open Source Software and Limitations Apply
|   Licence Info: http://www.cubecart.com/site/faq/license.php
+--------------------------------------------------------------------------
*/

if (!defined('CC_INI_SET')) die('Access Denied');

global $glob, $lang, $admin_data;

## Save notes
if (isset($_POST['notes']['dashboard_notes']) && !empty($_POST['notes']['dashboard_notes'])) {
	$update = array('dashboard_notes' => $_POST['notes']['dashboard_notes']);
	if ($GLOBALS['db']->update('CubeCart_admin_users', $update, array('admin_id' => Admin::getInstance()->get('admin_id')))) {
		$GLOBALS['session']->delete('', 'admin_data');
		$GLOBALS['main']->setACPNotify($lang['dashboard']['notice_notes_save']);
	} else {
		$GLOBALS['main']->setACPWarning($lang['dashboard']['error_notes_save']);
	}
	httpredir(currentPage());
}

## Check if setup folder remains after install/upgrade
if ($glob['installed'] && file_exists(CC_ROOT_DIR.CC_DS.'setup')) {
	$history = $GLOBALS['db']->misc('SELECT `version` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_history` ORDER BY `time` DESC LIMIT 1');
	if(version_compare(CC_VERSION,$history[0]['version'],'>')) {
		$GLOBALS['main']->setACPWarning(sprintf($lang['dashboard']['error_version'], CC_VERSION, $history[0]['version']));
	} elseif(file_exists(CC_ROOT_DIR.CC_DS.'setup')) {
		$GLOBALS['main']->setACPWarning($lang['dashboard']['error_setup_folder']);
	}	
}
## Are they using the mysql root user?
if ($glob['dbusername'] == 'root' && !$GLOBALS['config']->get('config', 'debug')) {
	$GLOBALS['main']->setACPWarning($lang['dashboard']['error_mysql_root'],true,false);
}
## Windows only - Is global.inc.php writable?
if (substr(PHP_OS, 0, 3) !== 'WIN' && is_writable('includes'.CC_DS.'global.inc.php')) {
	if(!chmod('includes'.CC_DS.'global.inc.php',0444)) {
		$GLOBALS['main']->setACPWarning($lang['dashboard']['error_global_risk']);
	}
}

$mysql_mode = $GLOBALS['db']->misc('SELECT @@sql_mode;');
if(stristr($mysql_mode[0]['@@sql_mode'], 'strict')) {
	$GLOBALS['main']->setACPWarning($lang['setup']['error_strict_mode']);
}

## Check current version
if (!isset($_SESSION['version-check']) && $request = new Request('cp.cubecart.com', '/licence/version/'.CC_VERSION)) {
	$request->skiplog(true);
	$request->cache(true);
	$request->setData(array('version' => CC_VERSION));
	if (($response = $request->send()) !== false) {
		if (version_compare(trim($response), CC_VERSION, '>')) {
			$GLOBALS['main']->setACPWarning(sprintf($lang['dashboard']['error_version_update'], $response, CC_VERSION).' <a href="?_g=maintenance&amp;node=index#upgrade">'.$lang['maintain']['upgrade_now'].'</a>');
		}
		$_SESSION['version-check'] = true;
	}
}

$GLOBALS['smarty']->assign('DASH_NOTES', Admin::getInstance()->get('dashboard_notes'));

$GLOBALS['main']->wikiPage('Dashboard');
### Dashboard ###
$GLOBALS['main']->addTabControl($lang['dashboard']['title_dashboard'], 'dashboard');
## Quick Stats
if(Admin::getInstance()->permissions('statistics', CC_PERM_READ, false, false)) {
	$total_sales = $GLOBALS['db']->query('SELECT SUM(`total`) as `total_sales` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_order_summary` WHERE `status` = 3;');
	$quick_stats['total_sales'] = Tax::getInstance()->priceFormat((float)$total_sales[0]['total_sales']);
	
	$ave_order 	= $GLOBALS['db']->query('SELECT AVG(`total`) as `ave_order` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_order_summary` WHERE `status` = 3;');
	$quick_stats['ave_order'] = Tax::getInstance()->priceFormat((float)$ave_order[0]['ave_order']);
	
	$this_year 			= date('Y');
	$this_month 		= date('m');
	$this_month_start 	= mktime (0, 0, 0, $this_month, '01', $this_year);
	## Work out prev month looks silly but should stop -1 month on 1st March returning January (28 Days in Feb)
	$last_month 		= date('m',strtotime("-1 month", mktime(12,0,0,$this_month,15,$this_month)));
	$last_year 			= ($last_month < $this_month) ? $this_year : ($this_year - 1);
	$last_month_start 	= mktime (0, 0, 0, $last_month, '01', $last_year);
	
	$last_month_sales 	= $GLOBALS['db']->query('SELECT SUM(`total`) as `last_month` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_order_summary` WHERE `status` = 3 AND `order_date` > '.$last_month_start.' AND `order_date` < '.$this_month_start.';');
	$quick_stats['last_month'] = Tax::getInstance()->priceFormat((float)$last_month_sales[0]['last_month']);
	
	$this_month_sales 	= $GLOBALS['db']->query('SELECT SUM(`total`) as `this_month` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_order_summary` WHERE `status` = 3 AND `order_date` > '.$this_month_start.';');
	$quick_stats['this_month'] = Tax::getInstance()->priceFormat((float)$this_month_sales[0]['this_month']);
	
	$GLOBALS['smarty']->assign('QUICK_STATS', $quick_stats);
}
## Last 5 orders
if (($last_orders = $GLOBALS['db']->select('CubeCart_order_summary', array('cart_order_id', 'first_name', 'last_name', 'name'), false, array('order_date' => 'DESC'), 5)) !== false) {
	$GLOBALS['smarty']->assign('LAST_ORDERS', $last_orders);
}

## Quick Tasks
$date_format = "Y-m-d";
$today		 = date($date_format);
$quick_tasks['today'] 		= urlencode(date($date_format));
$quick_tasks['this_weeks']	= urlencode(date($date_format, strtotime("last monday")));
foreach ($GLOBALS['hooks']->load('admin.dashboard.quick_tasks') as $hook) include $hook;
$GLOBALS['smarty']->assign('QUICK_TASKS',$quick_tasks);

## Statistics (Google Charts)

$sales = $GLOBALS['db']->select('CubeCart_order_summary', array('order_date', 'total'), array('order_date' => '>='.mktime(0,0,0,date('m', $last_year),1,date('Y', $last_year)), 'status' => array(3), 'total' => '>0'));
$data= array();
if($sales) { ## Get data to put in chart
	foreach ($sales as $sale) {
		$year	= date('Y', $sale['order_date']);
		$month	= date('M', $sale['order_date']);
		if (isset($data[$year][$month])) {
			$data[$year][$month] += sprintf('%0.2f',$sale['total']);
		} else {
			$data[$year][$month] = sprintf('%0.2f',$sale['total']);
		}
	}
}

$this_year = strftime('%G',strtotime('this year'));
$last_year = strftime('%G',strtotime('last year'));

$chart_data['data'] = "['Month', '$this_year', '$last_year'],";

for ($month = 1; $month <= 12; $month++) {
	$m = date("M", mktime(0, 0, 0, $month, 10));
	$last_year_month = (isset($data[$last_year][$m]) && $data[$last_year][$m]>0) ? $data[$last_year][$m] : 0;
	$this_year_month = (isset($data[$this_year][$m]) && $data[$this_year][$m]>0) ? $data[$this_year][$m] : 0;
	$chart_data['data'] .= "['$m',  $this_year_month, $last_year_month],";
}

$chart_data['title'] = $lang['dashboard']['title_sales_stats'].': '.$last_year.' - '.$this_year;
$GLOBALS['smarty']->assign('CHART', $chart_data);

## Pending Orders Tab
$page		= (isset($_GET['orders'])) ? $_GET['orders'] : 1;
$unsettled_count 	= $GLOBALS['db']->count('CubeCart_order_summary', 'cart_order_id', array('status' => array(1,2)));
$results_per_page = 25;
$unsettled_orders = $GLOBALS['db']->select('CubeCart_order_summary', array('cart_order_id', 'name', 'first_name', 'last_name', 'order_date', 'customer_id', 'total', 'status'), 'status IN (1,2) OR `dashboard` = 1', '`dashboard` DESC, `status` DESC,`order_date` ASC', $results_per_page, $page);

if ($unsettled_orders) {
	$tax = Tax::getInstance();
	$GLOBALS['main']->addTabControl($lang['dashboard']['title_orders_unsettled'], 'orders', null, null, $unsettled_count);
	foreach ($unsettled_orders as $order) {
		if (($notes = $GLOBALS['db']->select('CubeCart_order_notes', array('cart_order_id'), array('cart_order_id' => $order['cart_order_id']))) !== false) {
			$order['notes'] = $notes[0];
		}
		$order['icon']		= (empty($order['customer_id'])) ? 'user_ghost' : 'user_registered';
		$order['date']		= formatTime($order['order_date']);
		$order['total']		= Tax::getInstance()->priceFormat($order['total']);
		$order['status']	= $lang['order_state']['name_'.$order['status']];
		$orders[] = $order;
	}
	$GLOBALS['smarty']->assign('ORDERS', $orders);
	$GLOBALS['smarty']->assign('ORDER_PAGINATION', $GLOBALS['db']->pagination($unsettled_count, $results_per_page, $page, $show = 5,'orders', 'orders', $glue = ' ', $view_all = true));
} 

## Product Reviews Tab
$page		= (isset($_GET['reviews'])) ? $_GET['reviews'] : 1;
if (($reviews = $GLOBALS['db']->select('CubeCart_reviews', false, array('approved' => '0'), false, 25, $page)) !== false) {
	$reviews_count = $GLOBALS['db']->count('CubeCart_reviews','id');
	
	$GLOBALS['main']->addTabControl($lang['dashboard']['title_reviews_pending'], 'product_reviews', null, null, $reviews_count);
	foreach ($reviews as $review) {
		$product			= $GLOBALS['db']->select('CubeCart_inventory', array('name'), array('product_id' => (int)$review['product_id']));
		$review['product']	= $product[0];
		$review['date'] 	= formatTime($review['time']);
		$review['delete']	= "?_g=products&amp;node=reviews&amp;delete=".(int)$review['id'];
		$review['edit']		= "?_g=products&amp;node=reviews&amp;edit=".(int)$review['id'];
		$review['stars']	= 5;
		$review_list[] = $review;
	}
	$GLOBALS['smarty']->assign('REVIEWS', $review_list);
	$GLOBALS['smarty']->assign('REVIEW_PAGINATION', $GLOBALS['db']->pagination($reviews_count, 25, $page, $show = 5,'reviews', 'product_reviews', $glue = ' ', $view_all = true));
}

## Stock Warnings
$page		= (isset($_GET['stock'])) ? $_GET['stock'] : 1;

$tables = '`'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_inventory` AS `I` LEFT JOIN `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_option_matrix` AS `M` on `I`.`product_id` = `M`.`product_id`';

$fields = 'I.name ,I.stock_level AS I_stock_level, I.stock_warning AS I_stock_warning, I.product_id, M.stock_level AS M_stock_level, M.use_stock as M_use_stock, M.cached_name';

$where = 'use_stock_level = 1';
$where .= ' AND (';
$where .= '(M.use_stock = 1 AND M.status = 1 AND M.stock_level <= '.(int)$GLOBALS['config']->get('config', 'stock_warn_level').')';
$where .= ' OR ';
$where .= '((I.stock_warning > 0 AND I.stock_level <= I.stock_warning) OR (I.stock_warning <= 0 AND I.stock_level <= '.(int)$GLOBALS['config']->get('config', 'stock_warn_level').'))';
$where .= ')';

$order_by = 'I.stock_level ASC';

$result_limit = is_numeric($GLOBALS['config']->get('config', 'stock_warn_limit')) ? (int)$GLOBALS['config']->get('config', 'stock_warn_limit') : false;

//if (($stock = $GLOBALS['db']->select($tables, $fields, $where, $order_by, 25, $page)) !== false) {
if ($result_limit!==0 && ($stock_c = $GLOBALS['db']->select($tables, $fields, $where)) !== false) {
	$stock_count = count($stock_c);
	$stock = $GLOBALS['db']->select($tables, $fields, $where, $order_by, $result_limit, $page);
	$GLOBALS['smarty']->assign('STOCK', $stock);
	$GLOBALS['main']->addTabControl($lang['dashboard']['title_stock_warnings'], 'stock_warnings', null, null, $stock_count);
	$GLOBALS['smarty']->assign('STOCK_PAGINATION', $GLOBALS['db']->pagination($stock_count, $result_limit, $page, $show = 5,'stock', 'stock_warnings', $glue = ' ', $view_all = true));
	
	foreach ($GLOBALS['hooks']->load('admin.dashboard.stock.post') as $hook) include $hook;
}

## Latest News (from RSS)
if ($GLOBALS['config']->has('config', 'default_rss_feed') && !$GLOBALS['config']->isEmpty('config', 'default_rss_feed') && filter_var($GLOBALS['config']->get('config', 'default_rss_feed'), FILTER_VALIDATE_URL)) {
	$url = parse_url($GLOBALS['config']->get('config', 'default_rss_feed'));
	$path = (isset($url['query'])) ? $url['path'].'?'.$url['query'] : $url['path'];
	$request = new Request($url['host'], $path);
	$request->cache(true);
	$request->setMethod('POST');
	$request->setData('Null');
	if (($response = $request->send()) !== false) {
		try {
			if (($data = new SimpleXMLElement($response)) !== false) {
				foreach ($data->channel->children() as $key => $value) {
					if ($key == 'item') continue;
					$news[$key]	= (string)$value;
				}
				if ($data['version'] >= 2) {
					foreach ($data->channel->item as $item) {
						$news['items'][]	= array(
							'title'			=> (string)$item->title,
							'link'			=> (string)$item->link,
						);
					}
				}
				$GLOBALS['smarty']->assign('NEWS', $news);
			}
		} catch (Exception $e) {
			trigger_error($e->getMessage(), E_USER_WARNING);
		}
	}
}
$GLOBALS['main']->addTabControl($lang['dashboard']['title_store_overview'], 'advanced');

$count	= array(
	'products'	=> $GLOBALS['db']->count('CubeCart_inventory', 'product_id'),
	'orders'	=> $GLOBALS['db']->count('CubeCart_order_summary', 'cart_order_id'),
	'customers'	=> $GLOBALS['db']->count('CubeCart_customer', 'customer_id'),
);

$tmp1 = 0;
$tmp2 = 0;

$system	= array(
	'cc_version'	=> CC_VERSION,
	'cc_build'		=> null,
	'php_version'	=> PHP_VERSION,
	'mysql_version'	=> $GLOBALS['db']->serverVersion(),
	'server'		=> $_SERVER['SERVER_SOFTWARE'],
	'client'		=> $_SERVER['HTTP_USER_AGENT'],
	'dir_images'	=> dirsize(CC_ROOT_DIR.CC_DS.'images', $tmp1),
	'dir_files'		=> dirsize(CC_ROOT_DIR.CC_DS.'files', $tmp2),
);

$GLOBALS['smarty']->assign('SYS', $system);
$GLOBALS['smarty']->assign('PHP', ini_get_all());
$GLOBALS['smarty']->assign('COUNT', $count);

$GLOBALS['main']->addTabControl($lang['common']['search'], 'sidebar');

$page_content = $GLOBALS['smarty']->fetch('templates/dashboard.index.php');

Link to comment
Share on other sites

hi Brian,

            With reference to your question in reply 2 the client has gone from ver 5.2.2 to ver 5.2.4 and now they don't even see a blank graph they see nothing. The upgrade went well and there was no errors so have I forgotten something or should I have to setup something up to get the google graph apps to work

Rgards

Link to comment
Share on other sites

When CubeCart delivers the dashboard page to your browser, your browser will make a request to get the Google Charts javascript file (the javascript file is fetched from a link, just like links to CSS files, images, etc.).

 

Use a utility that can examine all the traffic going into and out of your browser. When you make a request to CubeCart for the dashboard page, your browser will follow with requests for all the page's resources. Check to see if a request is being made to these locations:

https://www.google.com/jsapi
https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
https://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js
https://www.google.com/uds/?file=visualization&v=1&packages=corechart
https://www.google.com/uds/api/visualization/1.0/d780f2951a73e815f003b2b487c1d0a3/format+en,default,corechart.I.js
https://ajax.googleapis.com/ajax/static/modules/gviz/1.0/core/tooltip.css

 

If these calls aren't being made, then we need to verify the integrity of the dashboard.index.php template file.

Link to comment
Share on other sites

Hi Brian,

            All the calls that you detailed are being made except for the last one that is not be called is this and issue.

Also this particular site is new and there is no sales as yet, however nothing is displaying not even a red or blue line or any axises.

Thanks for yopur help and best regards

Peterp

Link to comment
Share on other sites

Hi Brian,

              I'm now totally confused, when I run cubecart ver5.2.4 using the internet explorer browser I don't get the graph, however when I run it using the mozilla browser the graph now appears what is happening. I have even tried using the compatability switch for IE  and that doesn't help

Link to comment
Share on other sites

Hi Brian,

             Some more interesting information, I decided that I would try another computer which is running windows 7 and you guessed it the chart appeared, so I then tried an apple ipad and the chart appeared, I then tried on the computer that was not displaying the chart using IE browser I used Mozilla and the chart appeared this computer was also running windows XP service pack 3. So I then tried another site on the XP computer using IE and the chart didn't display. So are you confused now, I am.

So it seems that the chart is not displaying on computers that are running windows XP using IE but will display the chart when mozilla is used as the browser.

So are there some settings in IE and/or XP that have to be set so as to get the chart to display?????

 

Thankyou for your patience and best regards,

Peterp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...