<?php

namespace Modules\User\Controllers\Warehouse;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Order\Services\OrderService;

class DashboardController extends Controller
{

    public function __construct(
        private OrderService $orderService
    ){}

    public function index(Request $request) :View
    {
        $today_date = date('Y-m-d');
        $today_orders_total = $this->orderService->get([
            'today'=>$today_date,
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->sum('total');
        $month_orders_total = $this->orderService->get([
            'date'=>date('Y-m-').'01',
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->sum('total');
        $week_orders_total = $this->orderService->get([
            'date'=>date('Y-m-d',strtotime(' -1 weeks')),
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->sum('total');
        $year_orders_total = $this->orderService->get([
            'date'=>date('Y-').'01-01',
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->sum('total');
        $today_orders_count = $this->orderService->get([
            'today'=>$today_date,
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->count();
        $month_orders_count = $this->orderService->get([
            'date'=>date('Y-m-').'01',
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->count();
        $week_orders_count = $this->orderService->get([
            'date'=>date('Y-m-d',strtotime(' -1 weeks')),
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->count();
        $year_orders_count = $this->orderService->get([
            'date'=>date('Y-').'01-01',
            'warehouse_id'=>auth()->user()->warehouse_id,
        ])->count();


        return view('warehouse.index',get_defined_vars());
    }
}
