sergeybodin 2023-07-19 13:04:27 +03:00
commit 23bf227650
9 changed files with 51 additions and 77 deletions

View File

@ -69,9 +69,8 @@ class Entry extends Model {
if ($this->active_since) {
$state = ($this->active_since <= now()) ? EntryState::ACTIVE : EntryState::AWAITING;
if ($this->active_till && ($this->active_till <= now())) $state = EntryState::EXPIRED;
elseif ($this->suspended_since && ($this->suspended_since <= now())) {
}
elseif ($this->cancelled_at && ($this->cancelled_at <= now())) $state = EntryState::CANCELLED;
elseif ($this->suspended_since && ($this->suspended_since <= now()) && (!$this->suspended_till || ($this->suspended_till > now()))) $state = EntryState::SUSPENDED;
}
return $state ? ['name' => $state, 'title' => EntryState::TITLES[$state] ?? null] : null;
}

View File

@ -46,7 +46,11 @@ class Registry extends Model {
public function getParsedTypeAttribute(): array {
return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null, 'options' => RegistryType::OPTIONS[$this->type] ?? []];
return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null, 'options' => $this->options];
}
public function getOptionsAttribute(): array {
return RegistryType::OPTIONS[$this->type] ?? [];
}

View File

@ -21,7 +21,7 @@ class RegistryType {
public const OPTIONS = [
self::SIMPLE => [],
self::RULESET => ['categories' => true, 'operations' => true, 'states' => true],
self::RULESET => ['categories' => true, 'operations' => 'entry-operation-ruleset', 'states' => true],
self::LABORATORIES => ['properties' => 'entry-properties-laboratory', 'states' => true],
self::CERTIFIERS => ['properties' => 'entry-properties-certifier', 'states' => true],
self::EXPERTS => ['categories' => true, 'properties' => 'entry-properties-expert', 'states' => true],

View File

@ -38,6 +38,14 @@ class EntryFilters extends FiltersService {
];
}
public function operationsFields(Collection $filters): array {
return [];
}
public function propertiesFilters(Collection $filters): array {
return [];
}
public function getListings(Collection $filters): Fractal {
return fractal(Dictionary::byName('listings')->first()->items, new DictionaryItemTransformer());

View File

@ -68,7 +68,25 @@ class EntryForms extends FormsService {
'title' => 'Дата окончания действия',
'type' => FieldType::DATE,
'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null
]
],
[
'name' => 'suspended_since',
'title' => 'Дата начала приостановки',
'type' => FieldType::DATE,
'value' => ($v = $model->suspended_since ?? null) ? $v->toIso8601String() : null
],
[
'name' => 'suspended_till',
'title' => 'Дата окончания приостановки',
'type' => FieldType::DATE,
'value' => ($v = $model->suspended_till ?? null) ? $v->toIso8601String() : null
],
[
'name' => 'cancelled_at',
'title' => 'Дата отмены',
'type' => FieldType::DATE,
'value' => ($v = $model->cancelled_at ?? null) ? $v->toIso8601String() : null
],
];
return ['data' => $fields];
}

View File

@ -16,87 +16,24 @@ class OperationForms extends FormsService {
public function form(?string $id = null, array $data = []): array {
$model = NirObject::byUuid($id)->first();
$entry = Entry::byUuid($data['entry'] ?? null)->firstOrFail();
$groups = [
['name' => 'common', 'fields' => $this->commonGroupFields($model)]
['name' => 'common', 'fields' => $this->commonGroupFields($entry, $model)]
];
return ['title' => $this->formTitle($model), 'data' => $groups];
}
public function commonGroupFields(?NirObject $model): array {
public function commonGroupFields(Entry $entry, ?NirObject $model): array {
$objectTypeName = $entry->registry->options['operations'] ?? null;
return $model ? fractal($model->groups->first()->fields, new ObjectPropertyTransformer($model))->toArray() :
fractal(ObjectType::byName('entry-operation')->first()->groups()->first()->fields, new FieldTransformer())->toArray();
/*
$fields = [
[
'name' => 'type',
'title' => 'Вид работы',
'type' => FieldType::RELATION,
'required' => true,
'appearance' => 'radio',
'options' => $this->getRelationItems(OperationType::TITLES),
'value' => $this->getRelationValue(OperationType::TITLES, $model->type ?? null)
],
[
'name' => 'order_name',
'title' => 'Наименование приказа',
'type' => FieldType::STRING,
'required' => true,
'value' => $model->order_name ?? null
],
[
'name' => 'order_date',
'title' => 'Дата приказа',
'required' => true,
'type' => FieldType::DATE,
'value' => ($v = $model->order_date ?? null) ? $v->toIso8601String() : null
],
[
'name' => 'order',
'title' => 'Документ приказа',
'type' => FieldType::DOCUMENT,
'required' => true,
'value' => ($order = $model->order ?? null) ? fractal($order, new AssetTransformer()) : null
],
[
'name' => 'listing',
'title' => 'Вхождение в перечень ПП',
'type' => FieldType::RELATION,
'multiple' => true,
'appearance' => 'checkbox',
'options' => fractal(Dictionary::byName('listings')->first()->items, new DictionaryItemTransformer()),
'value' => null
],
[
'name' => 'active_since',
'title' => 'Дата начала действия',
'type' => FieldType::DATE,
'required' => true,
'value' => ($v = $model->active_since ?? null) ? $v->toIso8601String() : null
],
[
'name' => 'active_till',
'title' => 'Дата окончания действия',
'type' => FieldType::DATE,
'value' => ($v = $model->active_till ?? null) ? $v->toIso8601String() : null
],
[
'name' => 'developer',
'title' => 'Разработчик',
'type' => FieldType::STRING,
'required' => true,
'value' => $model->developer ?? null
]
];
return ['data' => $fields];
*/
fractal(ObjectType::byName($objectTypeName)->firstOrFail()->groups()->first()->fields, new FieldTransformer())->toArray();
}
public function store(array $data): ?JsonResponse {
$entry = Entry::byUuid($data['entry'] ?? null)->firstOrFail();
$model = $entry->createObject('entry-operation', null, 'operations');
$model = $entry->createObject($entry->registry->options['operations'] ?? null, null, 'operations');
$model->setValues($data);
return fractal($model, new ObjectTransformer())->respond();
}

View File

@ -28,6 +28,9 @@ class EntryTransformer extends TransformerAbstract {
'state' => $model->state,
'active_since' => $model->active_since ? $model->active_since->toIso8601String() : null,
'active_till' => $model->active_till ? $model->active_till->toIso8601String() : null,
'suspended_since' => $model->suspended_since ? $model->suspended_since->toIso8601String() : null,
'suspended_till' => $model->suspended_till ? $model->suspended_till->toIso8601String() : null,
'cancelled_at' => $model->cancelled_at ? $model->cancelled_at->toIso8601String() : null,
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
];

View File

@ -97,7 +97,7 @@ class ObjectTypeFieldsTableSeeder extends Seeder {
]
],
'entry-operation' => [
'entry-operation-ruleset' => [
'common' => [
'fields' => ['operation-type', 'order-name', 'order-date', 'order-document', 'listings', 'active-since', 'active-till', 'developer']
]

View File

@ -78,7 +78,12 @@ class ObjectTypesTableSeeder extends Seeder {
],
'entry-operation' => [
'title' => 'Действие с записью в реестре'
'title' => 'Действие с записью в реестре',
'children' => [
'entry-operation-ruleset' => [
'title' => 'Действие со сводом правил'
]
]
]
];