From a59837ceb213a9dadd54c6fe4319ee13298ff342 Mon Sep 17 00:00:00 2001 From: Rustem Date: Sat, 15 Feb 2025 22:27:11 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/PipiCarInstallCommands.php | 1 + modules/auto/script.php | 93 +++++++++++------------ modules/auto_equipment/access.json | 9 +++ modules/auto_equipment/app.json | 101 +++++++++++++++++++++++++ modules/auto_equipment/migrate.php | 23 ++++++ modules/auto_equipment/script.php | 54 +++++++++++++ modules/auto_equipment/seeds/seed.json | 8 ++ modules/brand_models/migrate.php | 1 + modules/brand_models/script.php | 1 + modules/owner_contracts/script.php | 27 ++++--- modules/owners/script.php | 53 +++++++------ 11 files changed, 283 insertions(+), 88 deletions(-) create mode 100644 modules/auto_equipment/access.json create mode 100644 modules/auto_equipment/app.json create mode 100644 modules/auto_equipment/migrate.php create mode 100644 modules/auto_equipment/script.php create mode 100644 modules/auto_equipment/seeds/seed.json diff --git a/app/Console/PipiCarInstallCommands.php b/app/Console/PipiCarInstallCommands.php index 176be68..83524cd 100644 --- a/app/Console/PipiCarInstallCommands.php +++ b/app/Console/PipiCarInstallCommands.php @@ -27,6 +27,7 @@ class PipiCarInstallCommands extends InstallCommand 'auto_brands', // Бренд авто 'auto_colors', // Цвета авто 'auto_types', // Типы авто + 'auto_equipment', // Комплектация авто 'brand_models', // Модель авто 'auto_classes', // Класс авто 'auto_tariffs', // Тарифы авто diff --git a/modules/auto/script.php b/modules/auto/script.php index 2ef7794..14b23be 100644 --- a/modules/auto/script.php +++ b/modules/auto/script.php @@ -40,54 +40,53 @@ return new class extends \A7kz\Platform\Commands\InstallScript { if ($count === 0) { foreach ($segments as $segment) { foreach ($data as $value) { - $car = UniModel::model('pipi_auto', $segment->connector); - $car->code = $value['Код']; - $car->name = $value['Наименование']; - $car->type_id = UniModel::model('pipi_auto_types', $segment->connector) - ->firstOrCreate([ - 'name' => $value['Тип'] - ])->id; - $car->class_id = UniModel::model('pipi_auto_classes', $segment->connector) - ->firstOrCreate([ - 'name' => $value['Класс'] - ])->id; - $autoBrand = UniModel::model('pipi_auto_brands', $segment->connector) - ->firstOrCreate([ - 'name' => $value['Марка'] - ]); - $car->brand_id = $autoBrand->id; - $car->model_id = UniModel::model('pipi_brand_models', $segment->connector) - ->firstOrCreate([ - 'name' => $value['Модель'], - 'brand_id' => $autoBrand->id, - 'year' => $this->formatDate($value['ГодПроизводства'])?->format('Y'), - ])->id; - $car->color_id = UniModel::model('pipi_auto_colors', $segment->connector) - ->firstOrCreate([ - 'name' => $value['Цвет'] - ])->id; - $car->serial_number = $value['СерийныйНомер']; - $car->state_number = $value['ГосНомер']; - $car->manufacture_year = $this->formatDate($value['ГодПроизводства'])?->format('Y-m-d'); - $car->passport_number = $value['НомерТехПаспорта']; - $car->passport_date = $this->formatDate($value['ДатаТехпаспорта'])?->format('Y-m-d'); - $car->estimated_cost = $value['ОценочнаяСтоимость']; - $owner = UniModel::model('pipi_owners', $segment->connector) - ->firstOrCreate([ - 'name' =>$value['ВладелецИмущества'] - ]); - $car->owner_id = $owner->id; - $car->is_trust_management = (bool) $value['ВДоверенномУправлении']; - $car->owner_percentage = $value['ПроцентВладельца']; - $car->owner_contract = $owner->contract_file_path; - $car->is_inactive = (bool) $value['НеИспользовать']; - $car->is_predefined = (bool) $value['Предопределенный']; - $car->predefined_data_name = $value['ИмяПредопределенныхДанных']; - $car->inspection_kit = json_validate($value['КомпректацияДляОсмотра']) ? $value['КомпректацияДляОсмотра'] : null; - if ($value['ПометкаУдаления'] == 'Да') { - $car->deleted_at = now(); + if ($value['ПометкаУдаления'] == 'Нет') { + $car = UniModel::model('pipi_auto', $segment->connector); + $car->code = $value['Код']; + $car->name = $value['Наименование']; + $car->type_id = UniModel::model('pipi_auto_types', $segment->connector) + ->firstOrCreate([ + 'name' => $value['Тип'] + ])->id; + $car->class_id = UniModel::model('pipi_auto_classes', $segment->connector) + ->firstOrCreate([ + 'name' => $value['Класс'] + ])->id; + $autoBrand = UniModel::model('pipi_auto_brands', $segment->connector) + ->firstOrCreate([ + 'name' => $value['Марка'] + ]); + $car->brand_id = $autoBrand->id; + $car->model_id = UniModel::model('pipi_brand_models', $segment->connector) + ->firstOrCreate([ + 'name' => $value['Модель'], + 'brand_id' => $autoBrand->id, + 'year' => $this->formatDate($value['ГодПроизводства'])?->format('Y'), + ])->id; + $car->color_id = UniModel::model('pipi_auto_colors', $segment->connector) + ->firstOrCreate([ + 'name' => $value['Цвет'] + ])->id; + $car->serial_number = $value['СерийныйНомер']; + $car->state_number = $value['ГосНомер']; + $car->manufacture_year = $this->formatDate($value['ГодПроизводства'])?->format('Y-m-d'); + $car->passport_number = $value['НомерТехПаспорта']; + $car->passport_date = $this->formatDate($value['ДатаТехпаспорта'])?->format('Y-m-d'); + $car->estimated_cost = $value['ОценочнаяСтоимость']; + $owner = UniModel::model('pipi_owners', $segment->connector) + ->firstOrCreate([ + 'name' =>$value['ВладелецИмущества'] + ]); + $car->owner_id = $owner->id; + $car->is_trust_management = (bool) $value['ВДоверенномУправлении']; + $car->owner_percentage = $value['ПроцентВладельца']; + $car->owner_contract = $owner->contract_file_path; + $car->is_inactive = (bool) $value['НеИспользовать']; + $car->is_predefined = (bool) $value['Предопределенный']; + $car->predefined_data_name = $value['ИмяПредопределенныхДанных']; + $car->inspection_kit = json_validate($value['КомпректацияДляОсмотра']) ? $value['КомпректацияДляОсмотра'] : null; + $car->save(); } - $car->save(); } } } diff --git a/modules/auto_equipment/access.json b/modules/auto_equipment/access.json new file mode 100644 index 0000000..9e4f179 --- /dev/null +++ b/modules/auto_equipment/access.json @@ -0,0 +1,9 @@ +{ + "admin": [ + "default", + "add", + "show", + "edit", + "delete" + ] +} diff --git a/modules/auto_equipment/app.json b/modules/auto_equipment/app.json new file mode 100644 index 0000000..a012b6e --- /dev/null +++ b/modules/auto_equipment/app.json @@ -0,0 +1,101 @@ +{ + "module": "pipicar", + "name": "pipicar.auto_equipment", + "type": "crud", + "title": "Комплектация Автомобилей", + "data": { + "table": "pipi_auto_equipment", + "pk": "id", + "limit": 25, + "segment": true, + "timestamp": false, + "fields": { + "id": { + "type": "pk" + }, + "name": { + "type": "string" + } + } + }, + "ui": { + "grid": { + "title": "Комплектация Автомобилей", + "template": "app.base.crud.grid", + "cols": [ + { + "name": "name", + "caption": "Название комплектации" + } + ], + "action": { + "head": [ + "add" + ], + "row": [ + "edit", + "delete" + ] + }, + "filter": { + "template": "app.base.crud.filter", + "rows": [ + { + "cols": [ + { + "size": 6, + "input": { + "name": "name", + "label": "Название комплектации" + } + } + ] + } + ] + } + }, + "forms": { + "add": { + "title": "Добавление комплектации", + "template": "app.base.crud.form", + "form": { + "submits": "struct:crud.form.edit.submits", + "rows": [ + { + "cols": [ + { + "size": 12, + "input": { + "name": "name", + "label": "Название комплектации" + } + } + ] + } + ] + } + }, + "edit": { + "title": "Редактирование комплектации", + "template": "app.base.crud.form", + "form": { + "rows": [ + { + "cols": [ + { + "size": 12, + "input": { + "name": "name", + "label": "Название комплектации" + } + } + ] + } + ], + "submits": "struct:crud.form.edit.submits" + } + } + } + }, + "actions": "struct:crud.actions" +} diff --git a/modules/auto_equipment/migrate.php b/modules/auto_equipment/migrate.php new file mode 100644 index 0000000..44fc686 --- /dev/null +++ b/modules/auto_equipment/migrate.php @@ -0,0 +1,23 @@ +connector)->create('pipi_auto_equipment', static function (Blueprint $table) { + $table->id(); + $table->string('name')->nullable()->comment('Наименование'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } +}; diff --git a/modules/auto_equipment/script.php b/modules/auto_equipment/script.php new file mode 100644 index 0000000..c5e4783 --- /dev/null +++ b/modules/auto_equipment/script.php @@ -0,0 +1,54 @@ +upgrade(); + $this->seed(); + } + + private function upgrade(): void + { + $segments = Segment::listActive(); + foreach ($segments as $segment) { + if (!Schema::connection($segment->connector)->hasTable('pipi_auto_equipment')) { + Schema::connection($segment->connector)->create('pipi_auto_equipment', static function (Blueprint $table) { + $table->id(); + $table->string('name')->nullable()->comment('Наименование'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } + } + + private function seed() + { + $count = UniModel::model('pipi_auto_equipment')->count(); + if ($count === 0) { + $seed = Storage::disk('pipicar_crm')->get('auto_equipment/seeds/seed.json'); + + $data = json_decode($seed, true); + foreach ($data as $item) { + UniModel::model('pipi_auto_equipment')->create([ + 'name' => $item['name'], + ]); + } + } + } +}; diff --git a/modules/auto_equipment/seeds/seed.json b/modules/auto_equipment/seeds/seed.json new file mode 100644 index 0000000..0305dd3 --- /dev/null +++ b/modules/auto_equipment/seeds/seed.json @@ -0,0 +1,8 @@ +[ + { + "name": "Полная" + }, + { + "name": "Комфорт" + } +] diff --git a/modules/brand_models/migrate.php b/modules/brand_models/migrate.php index 38332bd..e6a496e 100644 --- a/modules/brand_models/migrate.php +++ b/modules/brand_models/migrate.php @@ -16,6 +16,7 @@ return new class extends Migration $table->id(); $table->string('name')->nullable()->comment('Наименование'); $table->integer('year')->nullable()->comment('Год выпуска'); + $table->unsignedBigInteger('equipment_id')->nullable('Комплектация'); $table->timestamps(); $table->softDeletes(); diff --git a/modules/brand_models/script.php b/modules/brand_models/script.php index 5652ca0..1cffc99 100644 --- a/modules/brand_models/script.php +++ b/modules/brand_models/script.php @@ -30,6 +30,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $table->id(); $table->string('name')->nullable()->comment('Наименование'); $table->integer('year')->nullable()->comment('Год выпуска'); + $table->unsignedBigInteger('equipment_id')->nullable('Комплектация'); $table->timestamps(); $table->softDeletes(); diff --git a/modules/owner_contracts/script.php b/modules/owner_contracts/script.php index b029e64..6025864 100644 --- a/modules/owner_contracts/script.php +++ b/modules/owner_contracts/script.php @@ -68,21 +68,20 @@ return new class extends \A7kz\Platform\Commands\InstallScript { if ($count === 0) { foreach ($segments as $segment) { foreach ($data as $value) { - $model = UniModel::model('pipi_owner_contracts', $segment->connector); - $model->is_group = (bool) $value['ЭтоГруппа']; - $model->code = $value['Код']; - $model->name = $value['Наименование']; - $model->comments = $value['Комментарий']; - $model->organization = $value['Организация']; - $model->contract_number = $value['НомерДоговора']; - $model->contract_date = $this->formatDate($value['ДатаДоговора'])?->format('Y-m-d'); - $model->started_at = $this->formatDate($value['ДатаНачалаДействияДоговора'])?->format('Y-m-d'); - $model->ended_at = $this->formatDate($value['ДатаОкончанияДействияДоговора'])?->format('Y-m-d'); - $model->payment_type = $value['УсловияОплаты']; - if ($value['ПометкаУдаления'] = 'Да') { - $model->deleted_at = now(); + if ($value['ПометкаУдаления'] == 'Нет') { + $model = UniModel::model('pipi_owner_contracts', $segment->connector); + $model->is_group = (bool) $value['ЭтоГруппа']; + $model->code = $value['Код']; + $model->name = $value['Наименование']; + $model->comments = $value['Комментарий']; + $model->organization = $value['Организация']; + $model->contract_number = $value['НомерДоговора']; + $model->contract_date = $this->formatDate($value['ДатаДоговора'])?->format('Y-m-d'); + $model->started_at = $this->formatDate($value['ДатаНачалаДействияДоговора'])?->format('Y-m-d'); + $model->ended_at = $this->formatDate($value['ДатаОкончанияДействияДоговора'])?->format('Y-m-d'); + $model->payment_type = $value['УсловияОплаты']; + $model->save(); } - $model->save(); } } diff --git a/modules/owners/script.php b/modules/owners/script.php index 65a024f..01095de 100644 --- a/modules/owners/script.php +++ b/modules/owners/script.php @@ -73,34 +73,33 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $segments = Segment::listActive(); foreach ($segments as $segment) { foreach ($data as $value) { - $model = UniModel::model('pipi_owners', $segment->connector); - $model->is_group = (bool) $value['ЭтоГруппа']; - $model->code = $value['Код']; - $model->name = $value['Наименование']; - $model->comments = $value['Комментарий']; - $model->iin = $value['ИдентификационныйКодЛичности']; - $model->kbe = $value['КБЕ']; - $model->okpo_code = $value['КодПоОКПО']; - $model->main_contact = $value['ОсновноеКонтактноеЛицо']; - $model->bank_account = $value['ОсновнойБанковскийСчет']; - $model->address = $value['Адрес']; - $model->phone = $value['Телефон']; - $model->mail = $value['Почта']; - $model->id_number = $value['УдНомер']; - if ($value['УдДата']) { - $model->id_date = $this->formatDate($value['УдДата'])->format('Y-m-d'); + if ($value['ПометкаУдаления'] == 'Нет') { + $model = UniModel::model('pipi_owners', $segment->connector); + $model->is_group = (bool) $value['ЭтоГруппа']; + $model->code = $value['Код']; + $model->name = $value['Наименование']; + $model->comments = $value['Комментарий']; + $model->iin = $value['ИдентификационныйКодЛичности']; + $model->kbe = $value['КБЕ']; + $model->okpo_code = $value['КодПоОКПО']; + $model->main_contact = $value['ОсновноеКонтактноеЛицо']; + $model->bank_account = $value['ОсновнойБанковскийСчет']; + $model->address = $value['Адрес']; + $model->phone = $value['Телефон']; + $model->mail = $value['Почта']; + $model->id_number = $value['УдНомер']; + if ($value['УдДата']) { + $model->id_date = $this->formatDate($value['УдДата'])->format('Y-m-d'); + } + $model->issued = $value['УдВыдан']; + if ($value['ОсновнойДоговор']) { + $model->contract_id = UniModel::model('pipi_owner_contracts', $segment->connector) + ->firstOrCreate([ + 'name' => $value['ОсновнойДоговор'] + ])->id; + } + $model->save(); } - $model->issued = $value['УдВыдан']; - if ($value['ОсновнойДоговор']) { - $model->contract_id = UniModel::model('pipi_owner_contracts', $segment->connector) - ->firstOrCreate([ - 'name' => $value['ОсновнойДоговор'] - ])->id; - } - if ($value['ПометкаУдаления'] == 'Да') { - $model->deleted_at = now(); - } - $model->save(); } }