<?php

namespace lib\Controllers\DBMS\Client;

use lib\Services\ClientService;

class DashboardController extends ClientController
{
    public function __construct()
    {
        parent::__construct();
        $this->getView()->setPath('dashboard');
    } //

    //서비스카운팅 , total_counting_customer.php 
    //CLI 접속방법 : php index.php site/client/dashboard/totalcount/client_code/코드번호
    //WEB 접속방법 : http://localhost/site/client/dashboard/totalcount/client_code/코드번호
    public function totalcount(array $params)
    {
        if (!array_key_exists('client_code', $params)) {
            throw new \Exception("client_code 값이 정의되지 않았습니다.");
        }
        $client_code = $params['client_code'];
        $dashboard = [];
        foreach (DBMS_SERVICE_SWITCHCODE as $district => $switchcodes) {
            $switchcode_begin = $switchcodes['begin'];
            $switchcode_end  = $switchcodes['end'];
            $dashboard[$district] = $this->getServiceService()->getDistrictCountByClient(
                $client_code,
                $switchcode_begin,
                $switchcode_end
            );
        } //foreach
        foreach (array_keys(DBMS_SERVICE_LINE) as $service_line) {
            $dashboard[$service_line] = $this->getServiceService()->getServiceLineCountByClient($client_code, $service_line);
        } //foreach
        $dashboard['coupon'] = $this->getServiceService()->getCouponCountByClient($client_code);
        $this->dashboard = $dashboard;
        $this->client_code = $client_code;
        return $this->render(__FUNCTION__);
    }
} //Class
