render_widget();
}
/**
* Render widget.
*/
public function render_widget() {
?>
render_widget_content();
?>
product_type ] ) ) {
$series_data[ $cost->product_type ] = array(
'name' => isset( $product_types[ $cost->product_type ] ) ? esc_js( $product_types[ $cost->product_type ] ) : 'N/A',
'data' => array(),
);
$colors[ $cost->product_type ] = isset( $product_colors[ $cost->product_type ] ) ? $product_colors[ $cost->product_type ] : '';
$series_products_price[ $cost->product_type ] = array();
}
$time = $current_time;
$cost_price = $cost->price;
$next_rl = $cost->next_renewal;
if ( 'single_site' === $cost->license_type ) {
$cost_sites = Cost_Tracker_DB::get_instance()->get_sites_of_cost( $cost );
$count_sites = count( $cost_sites );
$cost_price = $cost->price * $count_sites;
}
for ( $i = 0; $i < 12; $i++ ) {
if ( ! isset( $series_products_price[ $cost->product_type ][ $i ] ) ) {
$series_products_price[ $cost->product_type ][ $i ] = 0;
}
$upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $time ) );
$upcoming2 = strtotime( gmdate( 'Y-m-t 23:59:59', $time ) );
if ( $next_rl <= $upcoming1 ) {
$next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $cost->renewal_type, false );
}
$next_price = 0;
while ( $next_rl <= $upcoming2 ) {
if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
$next_price = $cost_price;
}
$series_products_price[ $cost->product_type ][ $i ] += $next_price;
$next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $cost->renewal_type, false );
$next_price = 0;
}
$time = $upcoming2 + 1;
if ( $next_rl <= $upcoming2 ) {
$next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming2, $cost->renewal_type, false );
}
}
}
}
$dec = Cost_Tracker_Utility::cost_tracker_format_price( 0, true, array( 'get_decimals' => true ) );
foreach ( $series_products_price as $product_type => $products_price ) {
foreach ( $products_price as $idx => $price ) {
if ( ! isset( $series_data[ $product_type ]['data'][ $idx ] ) ) {
$series_data[ $product_type ]['data'][ $idx ] = 0;
}
$series_data[ $product_type ]['data'][ $idx ] = round( $price, $dec );
}
}
$cur_format = Cost_Tracker_Utility::cost_tracker_format_price( 0, true, array( 'get_currency_format' => true ) );
return array(
'series' => array_values( $series_data ),
'categories' => $categories,
'colors' => array_values( $colors ),
'currency_format' => $cur_format['format'],
'decimals' => $cur_format['decimals'],
);
}
/**
* Method render_widget_content()
*/
public function render_widget_content() {
$costs_data = Cost_Tracker_DB::get_instance()->get_summary_data( array( 'sum_data' => 'all' ) );
$chart_data = static::get_costs_widgets_data( $costs_data );
?>