<?php

if (!defined('ABSPATH')) {
    exit;
}
/*Exit if accessed directly*/
/******************************************************************************************************************************************************
*
*
*	[get the data]
*
*
******************************************************************************************************************************************************/
$data = wppizza_report_dataset($this->pluginOptions, $this->pluginLocale, $this->pluginOrderTable);
/**make some vars to use**/
$selectedReport = !empty($_GET['report']) ? $_GET['report'] : '';
$fromVal = !empty($_GET['from']) ? $_GET['from'] : '';
$toVal = !empty($_GET['to']) ? $_GET['to'] : '';
$exportLabel = $data['view'] == 'ini' ? __('Export All', $this->pluginLocale) : __('Export Range', $this->pluginLocale);
/******************************************************************************************************************************************************
*
*
*	[echo html]
*
*
******************************************************************************************************************************************************/
/**h2**/
echo "<h2>" . $this->pluginName . " " . __('Reports', $this->pluginLocale) . "</h2>";
?>

<!-- range select -->
    function wppizza_do_dashboard_widget()
    {
        if (version_compare(PHP_VERSION, '5.3', '<')) {
            print "<div style='text-align:center;margin:50px 0'>Sorry, reporting is only available with php >=5.3</div>";
            return;
        }
        /**number of posts**/
        $count_posts = wp_count_posts(WPPIZZA_POST_TYPE);
        /*number of categories**/
        $taxonomy = WPPIZZA_TAXONOMY;
        $terms = get_terms($taxonomy);
        $count_categories = 0;
        if ($terms && !is_wp_error($terms)) {
            $count_categories = count($terms);
        }
        /***sales***/
        require_once WPPIZZA_PATH . 'inc/admin.report.functions.php';
        $data = wppizza_report_dataset($this->pluginOptions, $this->pluginLocale, $this->pluginOrderTable);
        //print_r($data['dataset']);
        /**totals**/
        $totalSalesValue = $data['dataset']['sales_value_total'];
        $totalSalesCount = $data['dataset']['sales_count_total'];
        $totalItemsCount = $data['dataset']['items_count_total'];
        /**today**/
        $totalSalesValueToday = 0;
        $totalSalesCountToday = 0;
        $totalItemsCountToday = 0;
        if (isset($data['dataset']['sales'][date("Y-m-d")])) {
            $totalSalesValueToday = $data['dataset']['sales'][date("Y-m-d")]['sales_value_total'];
            $totalSalesCountToday = $data['dataset']['sales'][date("Y-m-d")]['sales_count_total'];
            $totalItemsCountToday = $data['dataset']['sales'][date("Y-m-d")]['items_count_total'];
        }
        echo '
			<table class="wppizza-dash wppizza-dash-sales">
				<thead>
					<tr>
						<th>&nbsp;</th>
						<th>' . __('Total', $this->pluginLocale) . '</th>
						<th>' . __('Today', $this->pluginLocale) . '</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>' . __('Earnings', $this->pluginLocale) . '</td>
						<td>' . $data['currency'] . ' ' . $totalSalesValue . '</td>
						<td>' . $data['currency'] . ' ' . $totalSalesValueToday . '</td>
					</tr>
					<tr>
						<td>' . __('Sales', $this->pluginLocale) . '</td>
						<td>' . $totalSalesCount . '</td>
						<td>' . $totalSalesCountToday . '</td>
					</tr>
					<tr>
						<td>' . __('Items Sold', $this->pluginLocale) . '</td>
						<td>' . $totalItemsCount . '</td>
						<td>' . $totalItemsCountToday . '</td>
					</tr>
				</tbody>
			</table>

			<table class="wppizza-dash wppizza-dash-items">
				<thead>
					<tr>
						<th>' . __('Menu Items (active)', $this->pluginLocale) . '</th>
						<th>' . __('Categories', $this->pluginLocale) . '</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>' . $count_posts->publish . '</td>
						<td>' . $count_categories . '</td>
					</tr>
				</tbody>
			</table>


	';
    }