%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/geotechnics/api/app/Http/Controllers/Api/v1/
Upload File :
Create Path :
Current File : /var/www/html/geotechnics/api/app/Http/Controllers/Api/v1/DashboardController.php

<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Api\ApiController;
use App\Models\Project;
use App\Models\ProjectStatus;
use App\Models\Subscription;
use App\Models\User;
use App\Transformers\ProjectTransformer;
use Carbon\Carbon;
use Illuminate\Http\Request;

class DashboardController extends ApiController
{
    /**
     * User $user.
     */
    protected $user;

    /**
     * PostsController constructor.
     */
    public function __construct()
    {
        $this->user = auth()
            ->guard('api')
            ->user();
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function getLastMonthSubscriptions()
    {
        return response()->json(Subscription::getLastMonthGroups(), 200);
    }

    public function getLastMonthProjects()
    {
        return response()->json(Project::getLastMonthGroups(), 200);
    }

    public function getLastMonthClients()
    {
        return response()->json(User::getLastMonthGroups(), 200);
    }

    public function getDeadlines(Request $request)
    {
        $startDate = Carbon::parse($request->get('date'))
                           ->startOfMonth()
                           ->subWeek();
        $endDate = Carbon::parse($request->get('date'))
                         ->endOfMonth()
                         ->addWeek();

        $projects = Project::query();

        if ($this->user->roles()
                       ->count() === 0) {
            $projects = $projects->where('client_id', $this->user->id);
        }

        $projects = $projects->where('status', '!=', ProjectStatus::DRAFT)
                             ->where('status', '!=', ProjectStatus::CANCELED)
                             ->where('status', '!=', ProjectStatus::REJECTED)
                             ->where('due_date', '>=', $startDate)
                             ->where('due_date', '<=', $endDate)
                             ->get();

        return $this->collection($projects, new ProjectTransformer());
    }

}

Zerion Mini Shell 1.0