Correct string to times and ranges. Closes #3540
This commit is contained in:
parent
e8570da2de
commit
c9b7a46c7b
|
@ -58,8 +58,8 @@ class WC_Admin_Dashboard {
|
|||
AND tax.taxonomy = 'shop_order_status'
|
||||
AND term.slug IN ( 'completed', 'processing', 'on-hold' )
|
||||
AND postmeta.meta_key = '_order_total'
|
||||
AND posts.post_date > '" . date( 'Y-m-d', strtotime( 'first day of this month', current_time('timestamp') ) ) . "'
|
||||
AND posts.post_date < '" . date( 'Y-m-d', current_time('timestamp') ) . "'
|
||||
AND posts.post_date >= '" . date( 'Y-m-01', current_time('timestamp') ) . "'
|
||||
AND posts.post_date <= '" . date( 'Y-m-d', current_time('timestamp') ) . "'
|
||||
" );
|
||||
|
||||
// Get top seller
|
||||
|
@ -77,8 +77,8 @@ class WC_Admin_Dashboard {
|
|||
AND term.slug IN ( 'completed', 'processing', 'on-hold' )
|
||||
AND order_item_meta.meta_key = '_qty'
|
||||
AND order_item_meta_2.meta_key = '_product_id'
|
||||
AND posts.post_date > '" . date( 'Y-m-d', strtotime( 'first day of this month', current_time('timestamp') ) ) . "'
|
||||
AND posts.post_date < '" . date( 'Y-m-d', current_time('timestamp') ) . "'
|
||||
AND posts.post_date >= '" . date( 'Y-m-01', current_time('timestamp') ) . "'
|
||||
AND posts.post_date <= '" . date( 'Y-m-d', current_time('timestamp') ) . "'
|
||||
GROUP BY product_id
|
||||
ORDER BY qty DESC
|
||||
LIMIT 1
|
||||
|
|
|
@ -138,7 +138,7 @@ class WC_Admin_Report {
|
|||
|
||||
if ( $filter_range ) {
|
||||
$query['where'] .= "
|
||||
AND post_date > '" . date('Y-m-d', $this->start_date ) . "'
|
||||
AND post_date >= '" . date('Y-m-d', $this->start_date ) . "'
|
||||
AND post_date < '" . date('Y-m-d', strtotime( '+1 DAY', $this->end_date ) ) . "'
|
||||
";
|
||||
}
|
||||
|
@ -396,6 +396,73 @@ class WC_Admin_Report {
|
|||
return '<span class="wc_sparkline ' . ( $type == 'sales' ? 'lines' : 'bars' ) . ' tips" data-color="#777" data-tip="' . $tooltip . '" data-barwidth="' . 60*60*16*1000 . '" data-sparkline="' . esc_attr( json_encode( $sparkline_data ) ) . '"></span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current range and calculate the start and end dates
|
||||
*
|
||||
* @param string $current_range
|
||||
*/
|
||||
public function calculate_current_range( $current_range ) {
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( date( 'Y-01-01', current_time('timestamp') ) );
|
||||
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( date( 'Y-m-01', strtotime( '-1 MONTH', current_time('timestamp') ) ) );
|
||||
$this->end_date = strtotime( date( 'Y-m-t', strtotime( '-1 MONTH', current_time('timestamp') ) ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( date( 'Y-m-01', current_time('timestamp') ) );
|
||||
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main chart
|
||||
* @return string
|
||||
|
|
|
@ -100,66 +100,10 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = '7day';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
default :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php');
|
||||
}
|
||||
|
|
|
@ -149,66 +149,10 @@ class WC_Report_Customers extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = '7day';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
default :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
$admin_users = new WP_User_Query(
|
||||
array(
|
||||
|
|
|
@ -72,66 +72,10 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = '7day';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 1 months max for day view
|
||||
if ( $interval > 1 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
default :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
// Get item sales data
|
||||
if ( $this->show_categories ) {
|
||||
|
|
|
@ -136,66 +136,10 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = '7day';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
default :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php');
|
||||
}
|
||||
|
|
|
@ -117,66 +117,10 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : '7day';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = '7day';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case '7day' :
|
||||
default :
|
||||
$this->start_date = strtotime( '-6 days', current_time( 'timestamp' ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php');
|
||||
}
|
||||
|
|
|
@ -45,61 +45,10 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = 'last_month';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
default :
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
$hide_sidebar = true;
|
||||
|
||||
|
|
|
@ -45,61 +45,10 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
|
|||
|
||||
$current_range = ! empty( $_GET['range'] ) ? $_GET['range'] : 'last_month';
|
||||
|
||||
switch ( $current_range ) {
|
||||
case 'custom' :
|
||||
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
|
||||
$this->end_date = strtotime( '12am + 1 day', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
|
||||
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) )
|
||||
$current_range = 'last_month';
|
||||
|
||||
if ( ! $this->end_date )
|
||||
$this->end_date = current_time('timestamp');
|
||||
|
||||
$interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$interval ++;
|
||||
}
|
||||
|
||||
// 3 months max for day view
|
||||
if ( $interval > 3 )
|
||||
$this->chart_groupby = 'month';
|
||||
else
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'year' :
|
||||
$this->start_date = strtotime( 'first day of january', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'month';
|
||||
break;
|
||||
default :
|
||||
case 'last_month' :
|
||||
$this->start_date = strtotime( 'first day of last month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( 'last day of last month', current_time('timestamp') );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
case 'month' :
|
||||
$this->start_date = strtotime( 'first day of this month', current_time('timestamp') );
|
||||
$this->end_date = strtotime( '12am + 1 day', current_time( 'timestamp' ) );
|
||||
$this->chart_groupby = 'day';
|
||||
break;
|
||||
}
|
||||
|
||||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date), DAY(post_date)';
|
||||
$this->chart_interval = max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month' :
|
||||
$this->group_by_query = 'YEAR(post_date), MONTH(post_date)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
|
||||
$this->chart_interval ++;
|
||||
}
|
||||
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
|
||||
break;
|
||||
}
|
||||
$this->calculate_current_range( $current_range );
|
||||
|
||||
$hide_sidebar = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue