<?php
loadcontroller('base/list');
class ControllerReportCouponUsed extends ControllerBaseList {

    protected $referencePathFile = 'report/coupon_used';

    protected function loadData()
    {
        //parent::loadData(); verificar
        $this->load->type('tipocomum');
        $this->language->load('report/coupon_used');

        $this->dataVue['Type_Status'] = Type_Status::getEnumList();
        $this->dataVue['Type_DisplayModuleOption'] = Type_DisplayModuleOption::getEnumList();


        $this->dataVue['error_dataMax'] = $this->language->get('error_dataMax');

        $this->dataVue['TypesForJs'] = array(
            Type_Status::getEnumList(),
            Type_DisplayModuleOption::getEnumList()
        );

    }

    protected function actionUrls()
    {
        $this->dataVue['actionFilter'] = $this->url->link("report/coupon_used/filter", "token=" . $this->session->data['token'] , "SSL");
    }

    protected function loadModel(){
        parent::loadModel();
        $this->load->model('localisation/geo_zone');
    }

    public function filter(){
        $this->load->model('report/coupon_used');
        $this->load->model('localisation/currency');

        $list = $this->model_report_coupon_used-> getCoupon($this->request->post['filters'],$this->request->post['page']);
        $listTotal = $this->model_report_coupon_used-> getCouponTotal($this->request->post['filters']);

        $renderPagination = parent::renderPagination($listTotal,$this->request->post['page']);

        $info = array();
        foreach ($list as $item){
            $info[] = array(
                'coupon_id'     =>  $item['coupon_id'],
                'NAME'          => $item['NAME'],
                'CODE'          => $item['CODE'],
                'TYPE'          => $item['TYPE'],
                'discount'      => $item['discount'],
                'shipping'      => $item['shipping'],
                'total'         => $item['total'],
                'date_start'    => $item['date_start'],
                'date_end'      => $item['date_end'],
                'uses_total'    => $item['uses_total'],
                'uses_customer' => $item['uses_customer'],
                'STATUS'        => $item['STATUS'],
                'date_added'    => $item['date_added'],
                'Qtd'           => $item['Qtd'],
                'media'         => $this->currency->format($item['media']),
                'valTotal'      => $this->currency->format($item['valTotal']),
            );
        }

        return $this->response->setOutputJson(['list' => $info, 'pagination' => $renderPagination , 'limit' => $this->config->get('config_admin_limit')]);
    }

}
?>