57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Warehouse\app\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Warehouse\app\Models\Warehouse;
|
|
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
|
|
|
class WarehouseValidationRuleController extends Controller
|
|
{
|
|
/**
|
|
* Display warehouse validation rules.
|
|
*/
|
|
public function index()
|
|
{
|
|
$companyId = auth()->user()->company_id;
|
|
|
|
return view('warehouse::rules.index', [
|
|
'warehouses' => Warehouse::where('company_id', $companyId)->orderBy('name')->get(),
|
|
'rules' => WarehouseValidationRule::with('warehouse')
|
|
->whereHas('warehouse', fn ($query) => $query->where('company_id', $companyId))
|
|
->latest()
|
|
->paginate(20),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Create a validation rule for a warehouse.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$companyId = $request->user()->company_id;
|
|
|
|
$data = $request->validate([
|
|
'warehouse_id' => ['required', 'exists:warehouses,id'],
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'rule_key' => ['required', 'string', 'max:100'],
|
|
'severity' => ['required', 'in:info,warning,error,blocker'],
|
|
'configuration' => ['nullable', 'json'],
|
|
]);
|
|
|
|
$warehouse = Warehouse::where('company_id', $companyId)->findOrFail($data['warehouse_id']);
|
|
|
|
WarehouseValidationRule::create([
|
|
'warehouse_id' => $warehouse->id,
|
|
'name' => $data['name'],
|
|
'rule_key' => $data['rule_key'],
|
|
'severity' => $data['severity'],
|
|
'is_active' => true,
|
|
'configuration' => $data['configuration'] ? json_decode($data['configuration'], true) : null,
|
|
]);
|
|
|
|
return back()->with('status', 'Validation rule created.');
|
|
}
|
|
}
|