@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SaveSupplierRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->purchasing_role === PurchasingRole::Procurement;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
$supplier = $this->route('supplier');
|
||||
$uniqueNuit = Rule::unique('suppliers')->where('tenant_id', $this->user()?->tenant_id);
|
||||
if ($supplier instanceof Supplier) {
|
||||
$uniqueNuit->ignore($supplier->id);
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => 'required|string|max:200',
|
||||
'nuit' => ['required', 'regex:/^\d{9}$/', $uniqueNuit],
|
||||
'contact' => 'required|string|max:200', 'email' => 'required|email|max:200',
|
||||
'phone' => 'required|string|max:50', 'address' => 'required|string|max:500',
|
||||
'category' => 'required|string|max:200', 'beneficiaries' => 'required|string|min:3|max:2000',
|
||||
'document_references' => 'required|string|min:5|max:3000', 'diligence_notes' => 'required|string|min:10|max:3000',
|
||||
'blocked' => 'required|boolean', 'next_review' => 'required|date_format:Y-m-d|after_or_equal:today',
|
||||
'version' => $supplier instanceof Supplier ? 'required|integer|min:1' : 'prohibited',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreRequisitionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
return $user !== null && $user->tenant_id !== null && $user->department_id !== null;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'cost_center_id' => ['required', 'integer', Rule::exists('cost_centers', 'id')->where('tenant_id', $this->user()?->tenant_id)->where('department_id', $this->user()?->department_id)],
|
||||
'priority' => ['required', Rule::in(['normal', 'high', 'urgent'])],
|
||||
'needed_by' => ['required', 'date_format:Y-m-d', 'after_or_equal:today'],
|
||||
'justification' => ['required', 'string', 'min:10', 'max:5000'],
|
||||
'items' => ['required', 'array', 'min:1', 'max:50'],
|
||||
'items.*.description' => ['required', 'string', 'max:255'],
|
||||
'items.*.category' => ['required', 'string', 'max:100'],
|
||||
'items.*.purchase_type' => ['required', Rule::in(['consumable', 'service', 'other'])],
|
||||
'items.*.quantity' => ['required', 'numeric', 'min:0.001', 'max:1000000', 'regex:/^\d+(\.\d{1,3})?$/'],
|
||||
'items.*.unit' => ['required', 'string', 'max:30'],
|
||||
'items.*.unit_price' => ['required', 'numeric', 'min:0.01', 'max:100000000', 'regex:/^\d+(\.\d{1,2})?$/'],
|
||||
'items.*.tax_rate' => ['required', 'numeric', 'between:0,100', 'regex:/^\d+(\.\d{1,2})?$/'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'cost_center_id.exists' => 'Seleccione um centro de custo do seu departamento.',
|
||||
'needed_by.after_or_equal' => 'A entrega pretendida deve ser hoje ou numa data futura.',
|
||||
'justification.min' => 'Descreva a necessidade da compra com pelo menos 10 caracteres.',
|
||||
'items.*.quantity.regex' => 'Use até três casas decimais na quantidade.',
|
||||
'items.*.unit_price.regex' => 'Use até duas casas decimais no preço.',
|
||||
'items.*.tax_rate.regex' => 'Use até duas casas decimais na taxa de IVA.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user