<?php

namespace App\Classes\Modules\ControllersLogic\Dashboard;

use App\Models\Company;
use App\Models\Order;
use Carbon\Carbon;

class CustomerReportLogic
{
    /* @var Order */
    private $orderRepository;

    /* @var Company */
    private $companiesRepository;

    /**
     * ActiveCustomerReportLogic constructor.
     * @param Order $orderRepository
     * @param Company $companiesRepository
     */
    public function __construct(Order $orderRepository, Company $companiesRepository)
    {
        $this->orderRepository = $orderRepository;
        $this->companiesRepository = $companiesRepository;
    }


    public function execute() {
        $active = $this->orderRepository->whereYear('created_at', '=', Carbon::now()->year)->whereMonth('created_at', '=', Carbon::now()->month)->orderBy('company_id')->get()->groupBy('company_id');
        $company = $this->companiesRepository->count();

        if ($company > $active->count()) $company -= $active->count();
        else $company = $active->count() - $company;

        return [$active->count(), $company];

    }
}