bobdonkey Posted June 12, 2015 Share Posted June 12, 2015 Hi allI need to track the number of items in the inventory. I already have a new table which keeps a daily record, so now I need to show a chart with the numbers going back a couple of weeks or so. So I just need to chart the contents of a table.My question is, how does CC6 create the sales chart? Some pointers if possible, then I can implement for the inventory as well.Thanks Quote Link to comment Share on other sites More sharing options...
bsmither Posted June 12, 2015 Share Posted June 12, 2015 "How does CC6 create the sales chart?"The file /admin/statistics.index.inc.php is used to gather the information and load the data into an array or graph data sent to the skin template. The template takes the data and feeds it to a javascript powered Google Chart package.There are no hooks in the file, so the code for any new visible chart (as opposed to an exportable report) will need to be edited directly into the file.Generally, the sequence goes:1. Declare how many columns per 'page' and accept the GET value for the page number or use 1.2. Build your query.3. Have the database execute your query while testing for a false result.4. If not false, add a tab, process the data, and load it into an array for the chart package.5. Send the array to the template.At the bottom of the file, just above assigning the GRAPH_DATA, let's add some code.// Daily Inventory Counts (DIC) $per_page = 21; $page = (isset($_GET['page_dic']) && is_numeric($_GET['page_dic'])) ? $_GET['page_dic'] : 1; $query = "SELECT `count` FROM `".$glob['dbprefix']."CubeCart_daily_inventory` ORDER BY `day` DESC"; if (($results = $GLOBALS['db']->query($query, $per_page, $page)) !== false) { $GLOBALS['main']->addTabControl("Inv Counts", 'stats_dic'); $smarty_data['dic'] = array(); foreach ($results as $key => $result) { // Process the results here. } $g_graph_data['dic']['data'] = "['Daily Count of Inventory','Counts']"; $g_graph_data['dic']['title'] = ''; $g_graph_data['dic']['hAxis'] = "Day"; $g_graph_data['dic']['vAxis'] = "Count""; $GLOBALS['smarty']->assign('DIC', $smarty_data['dic']); $GLOBALS['smarty']->assign('PAGINATION_DIC', $GLOBALS['db']->pagination($numrows, $per_page, $page, 5, 'page_dic', 'stats_dic', ' ', false)); unset($results, $result); } This is a start. It should be simple to process the data, but we can explore that later.Then, add a new <div> section for the tab to show the chart on the template statistics.index.php. Quote Link to comment Share on other sites More sharing options...
bobdonkey Posted June 14, 2015 Author Share Posted June 14, 2015 Wow, thanks bsmither, very useful! Have a bit of a back log of stuff and the moment, but this is really helpful, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.