[quote name='tbirnseth' timestamp='1319312655' post='124323']
What does a:
{$date|print_r:true}
Show you for the date array. That will tell you what the elements are.
[/quote]
[quote]
Array
(
[TIME] => 23/10/2011
[today] => 23/10/2011
[week] => 17/10/2011
[month] => 01/10/2011
)[/quote]
No 'year' variable is shown in the output, however, I find this strange that I searched the entire CS-Cart file system and found 'year' is also documented in /core/fn.common.php - any idea where (else) this may be controlled and/or a dirty hack to get around this? Thanks for your help.
[quote name='tbirnseth' timestamp='1319351093' post='124345']
Looks like the $date variable (for this controller anyway) is returning the data of today, 1 week ago and one month ago. Looks like it skipped the year.
You can always search the 'controllers' tree for "assign('date" and see what you come up with...
[/quote]
In /controllers/admin/index.tpl
```php
$view->assign('date', $date);
```
A search for "$date" only brings up /core/fn.common.php, in relation to (removed irrelevent code for other unrelated functions):
```php
function fn_this_day_begin()
{
$current_date = 0;
$current_date = time();
$_date_year = strftime("%Y", $current_date);
$_date_month = strftime("%m", $current_date);
$_date_day = strftime("%d", $current_date);
return mktime(0, 0, 0, $_date_month, $_date_day, $_date_year);
}
function fn_create_periods($params)
{
$today = getdate(TIME);
$period = !empty($params['period']) ? $params['period'] : null;
$time_from = !empty($params['time_from']) ? fn_parse_date($params['time_from']) : 0;
$time_to = !empty($params['time_to']) ? fn_parse_date($params['time_to'], true) : TIME;
// Current dates
if ($period == 'D') {
$time_from = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']);
$time_to = TIME;
} elseif ($period == 'W') {
$wday = empty($today['wday']) ? "6" : (($today['wday'] == 1) ? "0" : $today['wday'] - 1);
$wstart = getdate(strtotime("-$wday day"));
$time_from = mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']);
$time_to = TIME;
} elseif ($period == 'M') {
$time_from = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
$time_to = TIME;
} elseif ($period == 'Y') {
$time_from = mktime(0, 0, 0, 1, 1, $today['year']);
$time_to = TIME;
// Last dates
} elseif ($period == 'LD') {
$today = getdate(strtotime("-1 day"));
$time_from = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']);
$time_to = mktime(23, 59, 59, $today['mon'], $today['mday'], $today['year']);
} elseif ($period == 'LW') {
$today = getdate(strtotime("-1 week"));
$wday = empty($today['wday']) ? 6 : (($today['wday'] == 1) ? 0 : $today['wday'] - 1);
$wstart = getdate(strtotime("-$wday day", mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year'])));
$time_from = mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']);
$wend = getdate(strtotime("+6 day", $time_from));
$time_to = mktime(23, 59, 59, $wend['mon'], $wend['mday'], $wend['year']);
} elseif ($period == 'LM') {
$today = getdate(strtotime("-1 month"));
$time_from = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
$time_to = mktime(23, 59, 59, $today['mon'], date('t', strtotime("-1 month")), $today['year']);
} elseif ($period == 'LY') {
$today = getdate(strtotime("-1 year"));
$time_from = mktime(0, 0, 0, 1, 1, $today['year']);
$time_to = mktime(23, 59, 59, 12, 31, $today['year']);
// Last dates
} elseif ($period == 'HH') {
$today = getdate(strtotime("-23 hours"));
$time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']);
$time_to = TIME;
} elseif ($period == 'HW') {
$today = getdate(strtotime("-6 day"));
$time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']);
$time_to = TIME;
} elseif ($period == 'HM') {
$today = getdate(strtotime("-29 day"));
$time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']);
$time_to = TIME;
} elseif ($period == 'HC') {
$today = getdate(strtotime('-' . $params['last_days'] . ' day'));
$time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']);
$time_to = TIME;
}
Registry::get('view')->assign('time_from', $time_from);
Registry::get('view')->assign('time_to', $time_to);
return array($time_from, $time_to);
}
function fn_parse_date($timestamp, $end_time = false)
{
if (!empty($timestamp)) {
if (is_numeric($timestamp)) {
return $timest
}
$ts = explode('/', $timestamp);
$ts = array_map('intval', $ts);
if (empty($ts[2])) {
$ts[2] = date('Y');
}
if (count($ts) == 3) {
list($h, $m, $s) = $end_time ? array(23, 59, 59) : array(0, 0, 0);
if (Registry::get('settings.Appearance.calendar_date_format') == 'month_first') {
$timestamp = mktime($h, $m, $s, $ts[0], $ts[1], $ts[2]);
} else {
$timestamp = mktime($h, $m, $s, $ts[1], $ts[0], $ts[2]);
}
} else {
$timestamp = TIME;
}
}
return !empty($timestamp) ? $timestamp : TIME;
}
function fn_date_format($timestamp, $format = '%b %e, %Y')
{
if (substr(PHP_OS,0,3) == 'WIN') {
$hours = strftime('%I', $timestamp);
$short_hours = ($hours < 10) ? substr($hours, -1) : $hours;
$_win_from = array ('%e', '%T', '%D', '%l');
$_win_to = array ('%d', '%H:%M:%S', '%m/%d/%y', $short_hours);
$format = str_replace($_win_from, $_win_to, $format);
}
$date = getdate($timestamp);
$m = $date['mon'];
$d = $date['mday'];
$y = $date['year'];
$w = $date['wday'];
$hr = $date['hours'];
$pm = ($hr >= 12);
$ir = ($pm) ? ($hr - 12) : $hr;
$dy = $date['yday'];
$fd = getdate(mktime(0, 0, 0, 1, 1, $y)); // first day of year
$wn = (int) (($dy + $fd['wday']) / 7);
if ($ir == 0) {
$ir = 12;
}
$min = $date['minutes'];
$sec = $date['seconds'];
```
So, from this I hazard a guess that 'LY' should pull the previous year, right? Well, it doesn't work either - it doesn't work using:
```php
```
When the link is clicked, it shows the orders from 01/01/2011 until today. This doesn't explain why day, week and month all use "period=C" especially when there the period is defined in fn.common.php as LD,LW,LM, etc.
I guess there probably is a way to manipulate the code above to say, in part pseudo
```php
```
In /controllers/admin/index.php, this code creates last_month (similar is used for last week, but the code shown for year is all there is, there isn't any $last_year code.
```php
// Monthly orders
$date['month'] = date($date_format, mktime(0, 0, 0, $today['mon'], 1, $today['year']));
$last_month = $today;
if ($last_month['mon'] == 1) {
$last_month['mon'] = 12;
$last_month['year']--;
} else {
$last_month['mon']--;
}
$orders_stats['monthly_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount, SUM(total) as total FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i $condition " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, $today['mon'], 1, $today['year']), TIME);
$orders_stats['monthly_orders']['totals'] = db_get_row("SELECT SUM(IF(status IN (?a), total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i $condition " . fn_get_company_condition(), $paid_statuses, mktime(0, 0, 0, $today['mon'], 1, $today['year']), TIME);
$orders_stats['monthly_orders']['prev_totals'] = db_get_row("SELECT SUM(IF(status IN (?a), total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i $condition " . fn_get_company_condition(), $paid_statuses, mktime(0, 0, 0, $last_month['mon'], 1, $last_month['year']), mktime(0, 0, 0, $last_month['mon'], 1, $last_month['year']) + (TIME - mktime(0, 0, 0, $today['mon'], 1, $today['year'])));
if ($orders_stats['monthly_orders']['prev_totals']['total_paid'] > 0) {
$orders_stats['monthly_orders']['totals']['profit'] = intval($orders_stats['monthly_orders']['totals']['total_paid'] * 100 / $orders_stats['monthly_orders']['prev_totals']['total_paid']) - 100;
}
// Yearly orders
$orders_stats['year_orders'] = db_get_hash_array("SELECT status, COUNT(*) as amount, SUM(total) as total FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i $condition " . fn_get_company_condition() . " GROUP BY status", 'status', mktime(0, 0, 0, 1, 1, $today['year']), TIME);
$orders_stats['year_orders']['totals'] = db_get_row("SELECT SUM(IF(status IN (?a), total, 0)) as total_paid, SUM(total) as total, COUNT(*) as amount FROM ?:orders WHERE timestamp >= ?i AND timestamp <= ?i $condition " . fn_get_company_condition(), $paid_statuses, mktime(0, 0, 0, 1, 1, $today['year']), TIME);
```
But I'll be damned if I can find out...any thoughts? Thanks again.
[quote name='The Tool' timestamp='1319357486' post='124349']
No, the code I posted has nothing to do with the top statistics (comparing day, week, month order totals). It only deals with the "Order statistics". Look at the image in the original post and you will see a statistic at the top (code you referred to in your post) and then further down you will see "Order statistics".
Maybe that is the reason you cannot get it to work?
[/quote]
The code posted references the $orders_stats.year_orders variable, which is what I am looking to manipulate. There's only one other thread, which isn't as relative to this.
Thank you.