84 lines
2.6 KiB
PHP
84 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\AdvancedPlanning\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\AdvancedPlanning\Http\Controllers\Concerns\AuthorizesAdvancedPlanning;
|
|
use Modules\AdvancedPlanning\Models\CapacityResource;
|
|
use Modules\AdvancedPlanning\Services\IntegrationBridgeService;
|
|
use Modules\AdvancedPlanning\Utils\AdvancedPlanningUtil;
|
|
|
|
class CapacityResourceController extends Controller
|
|
{
|
|
use AuthorizesAdvancedPlanning;
|
|
|
|
public function __construct(
|
|
protected IntegrationBridgeService $bridge,
|
|
protected AdvancedPlanningUtil $util
|
|
) {
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->authorizeAp('ap.resources.view');
|
|
|
|
$resources = CapacityResource::forBusiness($this->businessId())
|
|
->orderBy('name')
|
|
->paginate(25);
|
|
|
|
return view('advancedplanning::capacity_resources.index', compact('resources'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->authorizeAp('ap.resources.manage');
|
|
|
|
$resourceTypes = ['line', 'equipment', 'labor'];
|
|
|
|
return view('advancedplanning::capacity_resources.create', compact('resourceTypes'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$this->authorizeAp('ap.resources.manage');
|
|
|
|
$data = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'resource_type' => 'required|in:line,equipment,labor',
|
|
'daily_capacity_hours' => 'required|numeric|min:0.1|max:24',
|
|
'efficiency_pct' => 'required|numeric|min:1|max:100',
|
|
'is_active' => 'nullable|boolean',
|
|
]);
|
|
|
|
CapacityResource::create([
|
|
'business_id' => $this->businessId(),
|
|
'name' => $data['name'],
|
|
'resource_type' => $data['resource_type'],
|
|
'daily_capacity_hours' => $data['daily_capacity_hours'],
|
|
'efficiency_pct' => $data['efficiency_pct'],
|
|
'is_active' => $request->boolean('is_active', true),
|
|
]);
|
|
|
|
return redirect()->action([self::class, 'index'])->with('status', [
|
|
'success' => true,
|
|
'msg' => __('advancedplanning::lang.resource_created'),
|
|
]);
|
|
}
|
|
|
|
public function sync()
|
|
{
|
|
$this->authorizeAp('ap.resources.manage');
|
|
|
|
$result = $this->bridge->syncCapacityResources($this->businessId());
|
|
|
|
return back()->with('status', [
|
|
'success' => true,
|
|
'msg' => __('advancedplanning::lang.resources_synced', [
|
|
'created' => $result['created'],
|
|
'updated' => $result['updated'],
|
|
]),
|
|
]);
|
|
}
|
|
}
|