ultimatepos/Modules/SupplyChain/Http/Controllers/DashboardController.php

53 lines
1.6 KiB
PHP

<?php
namespace Modules\SupplyChain\Http\Controllers;
use App\Http\MenuIcons;
use App\Utils\ModuleUtil;
use Illuminate\Routing\Controller;
use Menu;
use Modules\SupplyChain\Models\DemandForecast;
use Modules\SupplyChain\Models\RfqRequest;
use Modules\SupplyChain\Models\SupplierScorecard;
use Modules\SupplyChain\Utils\SupplyChainUtil;
class DashboardController extends Controller
{
use Concerns\AuthorizesSupplyChain;
public function __construct(
protected SupplyChainUtil $supplyChainUtil
) {
}
public function index()
{
$this->authorizeSupplyChain('supplychain.view');
$businessId = $this->supplyChainUtil->getBusinessId();
$stats = [
'scorecards' => SupplierScorecard::forBusiness($businessId)->count(),
'forecasts' => DemandForecast::forBusiness($businessId)->count(),
'open_rfqs' => RfqRequest::forBusiness($businessId)->where('status', 'open')->count(),
'high_risk_suppliers' => SupplierScorecard::forBusiness($businessId)
->whereIn('risk_level', ['high', 'critical'])
->distinct('contact_id')
->count('contact_id'),
];
$recentScorecards = SupplierScorecard::forBusiness($businessId)
->with('contact')
->orderByDesc('period_end')
->limit(5)
->get();
$recentRfqs = RfqRequest::forBusiness($businessId)
->orderByDesc('id')
->limit(5)
->get();
return view('supplychain::dashboard.index', compact('stats', 'recentScorecards', 'recentRfqs'));
}
}