<?php

namespace WpBookingProAdmin\app\views\dashboard;

use WpBookingPro\Html\ToolBar;
use WpBookingPro\Mvc\Model\Model;
use WpBookingPro\Mvc\View\View;
use WpBookingPro\Factory as FactoryAlias;

class DashboardView extends View
{
    public function display($tpl)
    {
        $input = FactoryAlias::getInput();
        switch ($tpl) {
            case "list":
            default:
                $tpl = "list";
                $modelCustomers = Model::getInstance('customers');
                $this->list_customer = $modelCustomers->get_list_customer_in_year();

                $modelCategories=Model::getInstance('categories');
                $this->list_categories=$modelCategories->getList();


                $modelOrders = Model::getInstance('orders');
                $list_order_in_year = $modelOrders->get_list_order_in_year();
                $list_order_by_month = array();
                foreach ($list_order_in_year as $item) {
                    $list_order_by_month[$item->month][] = $item;
                }


                $now = FactoryAlias::getDate();
                $month = (int)$now->format('m');
                $list_full_order_year = array();
                for ($i = $month; $i < $month + 12; $i++) {
                    {
                        $j = $i;
                        if ($j > 12) {
                            $j = $j - 12;
                        }
                        $key = "month $j";
                        if (isset($list_order_by_month[$j])) {
                            $list_full_order_year[$key] = $list_order_by_month[$j];
                        } else {
                            $list_full_order_year[$key] = array();
                        }
                    }
                }
                $this->list_order_by_month = $list_full_order_year;
                $this->list_order_in_year = $list_order_in_year;

                break;
        }
        return parent::display($tpl);
    }
}