<?php

$main_class = 'ExportSalesBoard';

class ExportSalesBoard extends Frame
{
    protected $template = 'board/export_sales.tpl';

    public function get_vars()
    {
        $vars = parent::get_vars();
        $vars['from'] = date(Settings::getDateFormat(), time() - (14 * 86400));
        $vars['to'] = date(Settings::getDateFormat());
        $qb = sqlQueryBuilder()->select('id', 'name')->from('users_groups')->orderBy('name');
        $users_groups = $qb->execute()->fetchAll();
        $vars['users_groups'] = array_combine(array_column($users_groups, 'id'), array_column($users_groups, 'name'));

        return $vars;
    }

    public function handle()
    {
        if (getVal('Submit')) {
            $export = new \KupShop\ElninoBundle\Admin\ExportSales();
            $export->exportXLS();

            exit('Done');
        }
    }
}
