killed code relating to dashboard sales

This commit is contained in:
Mike Jolley 2013-07-18 09:23:21 +01:00
parent 924b02b0e5
commit 0a8be76453
5 changed files with 1 additions and 295 deletions

View File

@ -286,177 +286,4 @@ function woocommerce_dashboard_recent_reviews() {
} else {
echo '<p>' . __( 'There are no product reviews yet.', 'woocommerce' ) . '</p>';
}
}
/**
* Orders this month filter function - filters orders for the month
*
* @access public
* @param string $where (default: '')
* @return void
*/
function orders_this_month( $where = '' ) {
global $the_month_num, $the_year;
$month = $the_month_num;
$year = (int) $the_year;
$first_day = strtotime("{$year}-{$month}-01");
//$last_day = strtotime('-1 second', strtotime('+1 month', $first_day));
$last_day = strtotime('+1 month', $first_day);
$after = date('Y-m-d', $first_day);
$before = date('Y-m-d', $last_day);
$where .= " AND post_date > '$after'";
$where .= " AND post_date < '$before'";
return $where;
}
/**
* Sales widget
*
* @access public
* @return void
*/
function woocommerce_dashboard_sales() {
add_action( 'admin_footer', 'woocommerce_dashboard_sales_js' );
?><div id="placeholder" style="width:100%; height:300px; position:relative;"></div><?php
}
/**
* Sales widget javascript
*
* @access public
* @return void
*/
function woocommerce_dashboard_sales_js() {
global $woocommerce, $wp_locale;
$screen = get_current_screen();
if (!$screen || $screen->id!=='dashboard') return;
global $current_month_offset, $the_month_num, $the_year;
// Get orders to display in widget
add_filter( 'posts_where', 'orders_this_month' );
$args = array(
'numberposts' => -1,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'shop_order',
'post_status' => 'publish' ,
'suppress_filters' => false,
'tax_query' => array(
array(
'taxonomy' => 'shop_order_status',
'terms' => apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ),
'field' => 'slug',
'operator' => 'IN'
)
)
);
$orders = get_posts( $args );
$order_counts = array();
$order_amounts = array();
// Blank date ranges to begin
$month = $the_month_num;
$year = (int) $the_year;
$first_day = strtotime("{$year}-{$month}-01");
$last_day = strtotime('-1 second', strtotime('+1 month', $first_day));
if ((date('m') - $the_month_num)==0) :
$up_to = date('d', strtotime('NOW'));
else :
$up_to = date('d', $last_day);
endif;
$count = 0;
while ($count < $up_to) :
$time = strtotime(date('Ymd', strtotime('+ '.$count.' DAY', $first_day))).'000';
$order_counts[$time] = 0;
$order_amounts[$time] = 0;
$count++;
endwhile;
if ($orders) :
foreach ($orders as $order) :
$order_data = new WC_Order($order->ID);
if ($order_data->status=='cancelled' || $order_data->status=='refunded') continue;
$time = strtotime(date('Ymd', strtotime($order->post_date))).'000';
if (isset($order_counts[$time])) :
$order_counts[$time]++;
else :
$order_counts[$time] = 1;
endif;
if (isset($order_amounts[$time])) :
$order_amounts[$time] = $order_amounts[$time] + $order_data->order_total;
else :
$order_amounts[$time] = (float) $order_data->order_total;
endif;
endforeach;
endif;
remove_filter( 'posts_where', 'orders_this_month' );
/* Script variables */
$params = array(
'currency_format_num_decimals' => absint( get_option( 'woocommerce_price_num_decimals' ) ),
'currency_format_symbol' => get_woocommerce_currency_symbol(),
'currency_format_decimal_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ) ),
'currency_format_thousand_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ) ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ),
'number_of_sales' => absint( array_sum( $order_counts ) ),
'sales_amount' => woocommerce_price( array_sum( $order_amounts ) ),
'i18n_sold' => __( 'Sold', 'woocommerce' ),
'i18n_earned' => __( 'Earned', 'woocommerce' ),
'i18n_month_names' => array_values( $wp_locale->month_abbrev ),
);
$order_counts_array = array();
foreach ($order_counts as $key => $count) :
$order_counts_array[] = array($key, $count);
endforeach;
$order_amounts_array = array();
foreach ($order_amounts as $key => $amount) :
$order_amounts_array[] = array($key, $amount);
endforeach;
$order_data = array( 'order_counts' => $order_counts_array, 'order_amounts' => $order_amounts_array );
$params['order_data'] = json_encode($order_data);
// Queue scripts
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'woocommerce_dashboard_sales', $woocommerce->plugin_url() . '/assets/js/admin/dashboard_sales' . $suffix . '.js', array( 'jquery', 'flot', 'flot-resize', 'accounting' ), $woocommerce->version );
wp_register_script( 'flot', $woocommerce->plugin_url() . '/assets/js/admin/jquery.flot'.$suffix.'.js', array('jquery'), '1.0' );
wp_register_script( 'flot-resize', $woocommerce->plugin_url() . '/assets/js/admin/jquery.flot.resize'.$suffix.'.js', array('jquery', 'flot'), '1.0' );
wp_register_script( 'flot-time', $woocommerce->plugin_url() . '/assets/js/admin/jquery.flot.time'.$suffix.'.js', array('jquery', 'flot'), '1.0' );
wp_localize_script( 'woocommerce_dashboard_sales', 'params', $params );
wp_print_scripts( 'woocommerce_dashboard_sales' );
}

File diff suppressed because one or more lines are too long

View File

@ -1391,13 +1391,6 @@ ul.woocommerce_stats {
top: -5px;
}
#woocommerce_dashboard_sales {
h3 a {
float: right;
margin-left: 8px;
}
}
ul.recent-orders, ul.stock_list {
li {
overflow: hidden;

View File

@ -1,113 +0,0 @@
jQuery(function(){
function weekendAreas(axes) {
var markings = [];
var d = new Date(axes.xaxis.min);
// go to the first Saturday
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
d.setUTCSeconds(0);
d.setUTCMinutes(0);
d.setUTCHours(0);
var i = d.getTime();
do {
// when we don't set yaxis, the rectangle automatically
// extends to infinity upwards and downwards
markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
i += 7 * 24 * 60 * 60 * 1000;
} while (i < axes.xaxis.max);
return markings;
}
var order_data = jQuery.parseJSON( params.order_data.replace(/&quot;/g, '"') );
var d = order_data.order_counts;
var d2 = order_data.order_amounts;
for (var i = 0; i < d.length; ++i) d[i][0] += 60 * 60 * 1000;
for (var i = 0; i < d2.length; ++i) d2[i][0] += 60 * 60 * 1000;
var placeholder = jQuery("#placeholder");
var plot = jQuery.plot(placeholder, [ { label: params.number_of_sales, data: d }, { label: params.sales_amount, data: d2, yaxis: 2 } ], {
series: {
lines: { show: true, fill: true },
points: { show: true }
},
grid: {
show: true,
aboveData: false,
color: '#ccc',
backgroundColor: '#fff',
borderWidth: 2,
borderColor: '#ccc',
clickable: false,
hoverable: true,
markings: weekendAreas
},
xaxis: {
mode: "time",
timeformat: "%d %b",
monthNames: params.i18n_month_names,
tickLength: 1,
minTickSize: [1, "day"]
},
yaxes: [ { min: 0, tickSize: 10, tickDecimals: 0 }, { position: "right", min: 0, tickDecimals: 2 } ],
colors: ["#8a4b75", "#47a03e"],
legend: {
show: true,
position: "nw"
}
});
placeholder.resize();
function showTooltip(x, y, contents) {
jQuery('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
padding: '5px 10px',
border: '3px solid #3da5d5',
background: '#288ab7'
}).appendTo("body").fadeIn(200);
}
var previousPoint = null;
jQuery("#placeholder").bind("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery("#tooltip").remove();
if (item.series.label==params.number_of_sales) {
var y = item.datapoint[1];
showTooltip(item.pageX, item.pageY, params.i18n_sold + ": " + y);
} else {
var y = item.datapoint[1].toFixed(2);
var formatted_total = accounting.formatMoney( y, {
symbol : params.currency_format_symbol,
decimal : params.currency_format_decimal_sep,
thousand : params.currency_format_thousand_sep,
precision : params.currency_format_num_decimals,
format : params.currency_format
} );
showTooltip( item.pageX, item.pageY, params.i18n_earned + ": " + formatted_total );
}
}
}
else {
jQuery("#tooltip").remove();
previousPoint = null;
}
});
});

View File

@ -1 +0,0 @@
jQuery(function(){function e(e){var t=[],n=new Date(e.xaxis.min);n.setUTCDate(n.getUTCDate()-(n.getUTCDay()+1)%7);n.setUTCSeconds(0);n.setUTCMinutes(0);n.setUTCHours(0);var r=n.getTime();do{t.push({xaxis:{from:r,to:r+1728e5}});r+=6048e5}while(r<e.xaxis.max);return t}function u(e,t,n){jQuery('<div id="tooltip">'+n+"</div>").css({position:"absolute",display:"none",top:t+5,left:e+5,padding:"5px 10px",border:"3px solid #3da5d5",background:"#288ab7"}).appendTo("body").fadeIn(200)}var t=jQuery.parseJSON(params.order_data.replace(/&quot;/g,'"')),n=t.order_counts,r=t.order_amounts;for(var i=0;i<n.length;++i)n[i][0]+=36e5;for(var i=0;i<r.length;++i)r[i][0]+=36e5;var s=jQuery("#placeholder"),o=jQuery.plot(s,[{label:params.number_of_sales,data:n},{label:params.sales_amount,data:r,yaxis:2}],{series:{lines:{show:!0,fill:!0},points:{show:!0}},grid:{show:!0,aboveData:!1,color:"#ccc",backgroundColor:"#fff",borderWidth:2,borderColor:"#ccc",clickable:!1,hoverable:!0,markings:e},xaxis:{mode:"time",timeformat:"%d %b",monthNames:params.i18n_month_names,tickLength:1,minTickSize:[1,"day"]},yaxes:[{min:0,tickSize:10,tickDecimals:0},{position:"right",min:0,tickDecimals:2}],colors:["#8a4b75","#47a03e"],legend:{show:!0,position:"nw"}});s.resize();var a=null;jQuery("#placeholder").bind("plothover",function(e,t,n){if(n){if(a!=n.dataIndex){a=n.dataIndex;jQuery("#tooltip").remove();if(n.series.label==params.number_of_sales){var r=n.datapoint[1];u(n.pageX,n.pageY,params.i18n_sold+": "+r)}else{var r=n.datapoint[1].toFixed(2),i=accounting.formatMoney(r,{symbol:params.currency_format_symbol,decimal:params.currency_format_decimal_sep,thousand:params.currency_format_thousand_sep,precision:params.currency_format_num_decimals,format:params.currency_format});u(n.pageX,n.pageY,params.i18n_earned+": "+i)}}}else{jQuery("#tooltip").remove();a=null}})});