feat(qa): complete market milestones and personnel report tables
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Requests;
|
||||
use App\Services\CountryCatalogue;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreSimulationFormDraftRequest extends FormRequest
|
||||
@@ -137,7 +138,7 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
'economic_snapshot.public_fields_confirmation' => ['nullable', 'in:yes,no'],
|
||||
'economic_snapshot.validation_acknowledged' => ['nullable', 'in:yes,no'],
|
||||
'economic_snapshot.investment_budget_min' => ['nullable', 'numeric', 'min:0'],
|
||||
'economic_snapshot.investment_budget_max' => ['nullable', 'numeric', 'min:0', \Illuminate\Validation\Rule::when($this->filled('economic_snapshot.investment_budget_min'), 'gte:economic_snapshot.investment_budget_min')],
|
||||
'economic_snapshot.investment_budget_max' => ['nullable', 'numeric', 'min:0', Rule::when($this->filled('economic_snapshot.investment_budget_min'), 'gte:economic_snapshot.investment_budget_min')],
|
||||
'economic_snapshot.currency' => ['nullable', 'string', 'regex:/^[A-Z]{3}$/'],
|
||||
'economic_snapshot.opportunity_currency' => ['nullable', 'string', 'regex:/^[A-Z]{3}$/'],
|
||||
'economic_snapshot.rate' => ['nullable', 'numeric', 'between:0,100'],
|
||||
@@ -217,11 +218,13 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
foreach ([
|
||||
'project_team_snapshot' => [
|
||||
'keys' => ['competency', 'state', 'action', 'estimated_cost', 'due_date'],
|
||||
'optional' => ['department', 'quantity', 'monthly_salary', 'start_month', 'end_month'],
|
||||
'states' => ['available', 'gap', 'unknown'],
|
||||
'amounts' => ['estimated_cost'],
|
||||
'amounts' => ['estimated_cost', 'monthly_salary'],
|
||||
],
|
||||
'project_execution_snapshot' => [
|
||||
'keys' => ['title', 'due_date', 'status', 'planned_amount', 'actual_amount'],
|
||||
'optional' => ['start_date', 'responsible', 'department'],
|
||||
'states' => ['planned', 'in_progress', 'completed'],
|
||||
'amounts' => ['planned_amount', 'actual_amount'],
|
||||
],
|
||||
@@ -232,7 +235,7 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
$rows = json_decode((string) $economic[$field], true);
|
||||
$valid = is_array($rows) && count($rows) <= 100;
|
||||
foreach (is_array($rows) ? $rows : [] as $row) {
|
||||
if (! is_array($row) || array_diff(array_keys($row), $schema['keys']) !== []
|
||||
if (! is_array($row) || array_diff(array_keys($row), array_merge($schema['keys'], $schema['optional'])) !== []
|
||||
|| array_diff($schema['keys'], array_keys($row)) !== []
|
||||
|| array_filter($row, fn ($value) => ! is_string($value) || mb_strlen($value) > 500) !== []) {
|
||||
$valid = false;
|
||||
@@ -244,12 +247,19 @@ class StoreSimulationFormDraftRequest extends FormRequest
|
||||
break;
|
||||
}
|
||||
foreach ($schema['amounts'] as $amountKey) {
|
||||
if ($row[$amountKey] !== '' && (! is_numeric($row[$amountKey]) || (float) $row[$amountKey] < 0)) {
|
||||
if (isset($row[$amountKey]) && $row[$amountKey] !== '' && ($amountKey === 'monthly_salary'
|
||||
? ! preg_match('/^\d+(?:\.\d{1,2})?$/', $row[$amountKey])
|
||||
: (! is_numeric($row[$amountKey]) || (float) $row[$amountKey] < 0))) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
foreach (['due_date'] as $dateKey) {
|
||||
if ($row[$dateKey] !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $row[$dateKey])) {
|
||||
foreach (['quantity', 'start_month', 'end_month'] as $integerKey) {
|
||||
if (isset($row[$integerKey]) && $row[$integerKey] !== '' && (! preg_match('/^\d+$/', $row[$integerKey]) || (float) $row[$integerKey] > ($integerKey === 'quantity' ? 1000000 : 60) || ($integerKey !== 'quantity' && (int) $row[$integerKey] < 1))) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
foreach (['due_date', 'start_date'] as $dateKey) {
|
||||
if (isset($row[$dateKey]) && $row[$dateKey] !== '' && ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $row[$dateKey])) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user