From 0497788d98c3fae51627187374c7504cd5c9b931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Davan=C3=A7o?= Date: Fri, 2 Sep 2022 17:56:21 -0300 Subject: [PATCH 1/2] Create sp-produto database seeders --- database/seeders/SpProdutoSeeder.php.stub | 194 ++++++++++++++++ src/Console/InstallSp.php | 37 ++- src/Factories/AccessoryFactory.php | 33 +++ src/Factories/BuyingOptionFactory.php | 40 ++++ src/Factories/CategoryFactory.php | 31 +++ src/Factories/CharacteristicFactory.php | 37 +++ src/Factories/InsuranceCompanyFactory.php | 34 +++ src/Factories/InsuranceFactory.php | 32 +++ src/Factories/ProposalModelFactory.php | 35 +++ .../ProposalModelPeriodicitiesFactory.php | 42 ++++ .../AccessoryCategoryFactory.php | 34 +++ .../AccessoryFactory.php | 38 ++++ .../BlueprintFactory.php | 35 +++ .../BlueprintImageFactory.php | 36 +++ .../CharacteristicFactory.php | 36 +++ .../RealEstateDevelopment/DocumentFactory.php | 40 ++++ .../RealEstateDevelopment/MediaFactory.php | 40 ++++ .../RealEstateDevelopment/MirrorFactory.php | 35 +++ .../MirrorGroupFactory.php | 34 +++ .../ParameterFactory.php | 50 ++++ .../RealEstateDevelopment/StageFactory.php | 41 ++++ .../StageImageFactory.php | 36 +++ .../TypologyAttributeFactory.php | 37 +++ .../RealEstateDevelopment/TypologyFactory.php | 34 +++ .../RealEstateDevelopment/UnitFactory.php | 49 ++++ .../RealEstateDevelopmentFactory.php | 74 ++++++ src/Models/Accessory.php | 20 +- src/Models/AccessoryCategory.php | 20 +- src/Models/BuyingOption.php | 48 +++- src/Models/Characteristic.php | 20 +- src/Models/Insurance.php | 20 +- src/Models/InsuranceCompany.php | 20 +- src/Models/ProposalModel.php | 20 +- src/Models/ProposalModelPeriodicities.php | 28 ++- src/Models/RealEstateDevelopment.php | 213 +++++++++++++++--- .../RealEstateDevelopment/Accessory.php | 65 +++++- .../RealEstateDevelopment/Blueprint.php | 32 ++- .../RealEstateDevelopment/BlueprintImage.php | 20 +- .../RealEstateDevelopment/Characteristic.php | 20 +- src/Models/RealEstateDevelopment/Document.php | 20 +- src/Models/RealEstateDevelopment/Media.php | 28 ++- src/Models/RealEstateDevelopment/Mirror.php | 71 +++++- .../RealEstateDevelopment/MirrorGroup.php | 20 +- .../RealEstateDevelopment/Parameter.php | 66 +++++- src/Models/RealEstateDevelopment/Stage.php | 30 ++- .../RealEstateDevelopment/StageImage.php | 20 +- src/Models/RealEstateDevelopment/Typology.php | 64 +++++- .../TypologyAttribute.php | 31 ++- src/Models/RealEstateDevelopment/Unit.php | 33 ++- src/SpProdutoServiceProvider.php | 94 +++++--- 50 files changed, 2037 insertions(+), 150 deletions(-) create mode 100644 database/seeders/SpProdutoSeeder.php.stub create mode 100644 src/Factories/AccessoryFactory.php create mode 100644 src/Factories/BuyingOptionFactory.php create mode 100644 src/Factories/CategoryFactory.php create mode 100644 src/Factories/CharacteristicFactory.php create mode 100644 src/Factories/InsuranceCompanyFactory.php create mode 100644 src/Factories/InsuranceFactory.php create mode 100644 src/Factories/ProposalModelFactory.php create mode 100644 src/Factories/ProposalModelPeriodicitiesFactory.php create mode 100644 src/Factories/RealEstateDevelopment/AccessoryCategoryFactory.php create mode 100644 src/Factories/RealEstateDevelopment/AccessoryFactory.php create mode 100644 src/Factories/RealEstateDevelopment/BlueprintFactory.php create mode 100644 src/Factories/RealEstateDevelopment/BlueprintImageFactory.php create mode 100644 src/Factories/RealEstateDevelopment/CharacteristicFactory.php create mode 100644 src/Factories/RealEstateDevelopment/DocumentFactory.php create mode 100644 src/Factories/RealEstateDevelopment/MediaFactory.php create mode 100644 src/Factories/RealEstateDevelopment/MirrorFactory.php create mode 100644 src/Factories/RealEstateDevelopment/MirrorGroupFactory.php create mode 100644 src/Factories/RealEstateDevelopment/ParameterFactory.php create mode 100644 src/Factories/RealEstateDevelopment/StageFactory.php create mode 100644 src/Factories/RealEstateDevelopment/StageImageFactory.php create mode 100644 src/Factories/RealEstateDevelopment/TypologyAttributeFactory.php create mode 100644 src/Factories/RealEstateDevelopment/TypologyFactory.php create mode 100644 src/Factories/RealEstateDevelopment/UnitFactory.php create mode 100644 src/Factories/RealEstateDevelopmentFactory.php diff --git a/database/seeders/SpProdutoSeeder.php.stub b/database/seeders/SpProdutoSeeder.php.stub new file mode 100644 index 0000000..d01d21c --- /dev/null +++ b/database/seeders/SpProdutoSeeder.php.stub @@ -0,0 +1,194 @@ +create(); + Accessory::factory(10)->create(); + BuyingOption::factory(10)->create(); + Characteristic::factory(10)->create(); + ProposalModel::factory(10) + ->has(ProposalModelPeriodicities::factory(5), 'periodicities') + ->create(); + InsuranceCompany::factory(10)->create()->each(function (InsuranceCompany $insuranceCompany) { + Insurance::factory([ + 'insurance_company_id' => $insuranceCompany->id + ])->count(10)->create(); + }); + + $bar = $this->command->getOutput()->createProgressBar(10); + $bar->start(); + + // RealEstateDevelopments + RealEstateDevelopment::factory(10)->create()->each(function (RealEstateDevelopment $realEstateDevelopment) use ($bar) { + $hub_company_id = $realEstateDevelopment->hub_company_id; + + // Initial register proposal models + $realEstateDevelopment->proposal_models()->saveMany( + ProposalModel::whereHubCompanyId($hub_company_id)->inRandomOrder()->take(5)->get() + ); + + // Initial register buying options + $realEstateDevelopment->buying_options()->saveMany( + BuyingOption::whereHubCompanyId($hub_company_id)->inRandomOrder()->take(5)->get() + ); + + // Initial register insurance companies + $realEstateDevelopment->insurance_companies()->saveMany( + InsuranceCompany::whereHubCompanyId($hub_company_id)->inRandomOrder()->take(1)->get() + ); + + // Initial register insurance + $realEstateDevelopment->insurances()->saveMany( + Insurance::inRandomOrder()->take(1)->get() + ); + + // Parameters + $realEstateDevelopment->parameters()->saveMany(Parameter::factory(5)->make()); + $realEstateDevelopment->parameters()->each(function (Parameter $parameter, $key) { + $parameter->name = __('Phase :number', [ + 'number' => ($key + 1) + ]); + $parameter->save(); + }); + + // Characteristics + $realEstateDevelopment->characteristics()->saveMany( + RealEstateDevelopment\Characteristic::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + 'characteristic_id' => Characteristic::inRandomOrder()->first(['id'])->id, + ])->count(5)->create() + ); + + // Typologies (must be created before accessories) + $realEstateDevelopment->typologies()->saveMany( + Typology::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(5)->create()->each(function (Typology $typology) use ($realEstateDevelopment) { + $typology->real_estate_developments_proposal_model()->saveMany( + $realEstateDevelopment->proposal_models()->inRandomOrder()->take(5)->get() + ); + }) + ); + + // Accessories + $realEstateDevelopment->accessories()->saveMany( + RealEstateDevelopment\Accessory::factory([ + 'accessory_id' => Accessory::whereHubCompanyId($hub_company_id)->inRandomOrder()->first(['id']), + 'category_id' => AccessoryCategory::inRandomOrder()->first(['id']), + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(5)->create() + ); + + // Documents + $realEstateDevelopment->documents()->saveMany( + Document::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(5)->create() + ); + + // Medias + $realEstateDevelopment->medias()->saveMany( + Media::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(5)->create() + ); + + // Stages + $realEstateDevelopment->stages()->saveMany( + Stage::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(5)->create()->each(function (Stage $stage) { + $stage->real_estate_developments_stages_images()->saveMany( + StageImage::factory(5)->create() + ); + }) + ); + + // Mirrors + $realEstateDevelopment->mirrors()->saveMany( + Mirror::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(2)->create()->each(function (Mirror $mirror) { + $mirror->real_estate_developments_mirrors_subgroups()->saveMany( + MirrorGroup::factory([ + 'mirror_id' => $mirror->id + ])->count(1)->create() + ); + + $mirror->real_estate_developments_parameters()->associate( + Parameter::inRandomOrder()->first() + ); + }) + ); + + // Blueprints + $realEstateDevelopment->blueprints()->saveMany( + Blueprint::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(3)->create()->each(function (Blueprint $blueprint) use ($realEstateDevelopment) { + $blueprint->real_estate_developments_typologies()->saveMany( + $realEstateDevelopment->typologies()->inRandomOrder()->take(5)->get() + ); + + $blueprint->real_estate_developments_blueprint_images()->saveMany( + BlueprintImage::factory()->count(3)->create() + ); + }) + ); + + // Unities + $realEstateDevelopment->unities()->saveMany( + Unit::factory([ + 'real_estate_development_id' => $realEstateDevelopment->id, + ])->count(30)->create()->each(function (Unit $unit) use ($realEstateDevelopment) { + $typology = $realEstateDevelopment->typologies()->inRandomOrder()->first(); + $unit->typology()->associate($typology->id); + + $blueprint = $typology->blueprints()->inRandomOrder()->first(); + $unit->real_estate_developments_blueprints()->associate($blueprint->id); + + $mirror = $realEstateDevelopment->mirrors()->inRandomOrder()->first(); + $unit->mirror_group()->associate($mirror->id); + + $mirror_group = $mirror->mirrorGroup()->inRandomOrder()->first(); + $unit->mirror_subgroup()->associate($mirror_group->id); + }) + ); + + $bar->advance(); + }); + + $bar->finish(); + } +} diff --git a/src/Console/InstallSp.php b/src/Console/InstallSp.php index bb53822..601446d 100644 --- a/src/Console/InstallSp.php +++ b/src/Console/InstallSp.php @@ -78,6 +78,16 @@ public function handle() $this->runMigrations(); + $this->info('Publishing database seeders...'); + + if ($this->shouldRunSeeders()) { + $this->publishSeeders(); + } + + $this->runSeeders(); + + $this->info('Finish database seeders!'); + $this->info('Installed SPPackage'); } @@ -92,11 +102,11 @@ private function configExists(string $fileName): bool } /** - * @param bool|false $forcePublish + * @param bool|false $forcePublish * * @return void */ - private function publishConfiguration($forcePublish = false): void + private function publishConfiguration(bool $forcePublish = false): void { $params = self::VENDOR_PUBLISH_CONFIG_PARAMS; @@ -122,6 +132,11 @@ private function shouldRunMigrations(): bool return $this->confirm('Run migrations of SP package? If you have already done this step, do not do it again!'); } + private function shouldRunSeeders(): bool + { + return $this->confirm('Run seeders of SP package? If you have already done this step, do not do it again!'); + } + /** * @return void */ @@ -136,4 +151,22 @@ private function runMigrations() $this->call('migrate'); $this->info('Finish migrations.'); } + + private function publishSeeders() + { + $this->call('vendor:publish', [ + '--provider' => SpProdutoServiceProvider::class, + '--tag' => 'seeders' + ]); + } + + private function runSeeders() + { + $this->info('Run seeders.'); + $this->call('db:seed', [ + '--class' => 'SpProdutoSeeder' + ]); + $this->newLine(); + $this->info('Finish seeders.'); + } } diff --git a/src/Factories/AccessoryFactory.php b/src/Factories/AccessoryFactory.php new file mode 100644 index 0000000..764cc68 --- /dev/null +++ b/src/Factories/AccessoryFactory.php @@ -0,0 +1,33 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'description' => fake()->text, + 'category_id' => Category::inRandomOrder()->first(), + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + ]; + } +} diff --git a/src/Factories/BuyingOptionFactory.php b/src/Factories/BuyingOptionFactory.php new file mode 100644 index 0000000..f19c91a --- /dev/null +++ b/src/Factories/BuyingOptionFactory.php @@ -0,0 +1,40 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'income_commitment' => fake()->numberBetween(1, 80), + 'when_flow_sent' => fake()->randomKey(BuyingOption::WHEN_FLOW_SENT_LIST), + 'when_flow_validated' => fake()->randomKey(BuyingOption::WHEN_FLOW_VALIDATED_LIST), + 'when_make_sale' => fake()->randomKey(BuyingOption::WHEN_MAKE_SALE_LIST), + 'when_reserve_unit' => fake()->randomKey(BuyingOption::WHEN_RESERVE_UNIT_LIST), + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + ]; + } +} diff --git a/src/Factories/CategoryFactory.php b/src/Factories/CategoryFactory.php new file mode 100644 index 0000000..880e06d --- /dev/null +++ b/src/Factories/CategoryFactory.php @@ -0,0 +1,31 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'description' => fake()->text, + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + ]; + } +} diff --git a/src/Factories/CharacteristicFactory.php b/src/Factories/CharacteristicFactory.php new file mode 100644 index 0000000..776d505 --- /dev/null +++ b/src/Factories/CharacteristicFactory.php @@ -0,0 +1,37 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'description' => fake()->text, + 'icon' => 'https://placeimg.com/640/480/any?' . fake()->uuid, + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + ]; + } +} diff --git a/src/Factories/InsuranceCompanyFactory.php b/src/Factories/InsuranceCompanyFactory.php new file mode 100644 index 0000000..ccde39c --- /dev/null +++ b/src/Factories/InsuranceCompanyFactory.php @@ -0,0 +1,34 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'company_name' => fake()->words(5, true), + 'document' => fake()->cnpj(false), + 'susep' => fake()->numerify('#####'), + 'is_active' => fake()->boolean(), + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + ]; + } +} diff --git a/src/Factories/InsuranceFactory.php b/src/Factories/InsuranceFactory.php new file mode 100644 index 0000000..6fa25f1 --- /dev/null +++ b/src/Factories/InsuranceFactory.php @@ -0,0 +1,32 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'rate' => fake()->numberBetween(0, 100), + 'external_code' => fake()->numerify('#######'), + 'is_active' => fake()->boolean(), + ]; + } +} diff --git a/src/Factories/ProposalModelFactory.php b/src/Factories/ProposalModelFactory.php new file mode 100644 index 0000000..2e46bdb --- /dev/null +++ b/src/Factories/ProposalModelFactory.php @@ -0,0 +1,35 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id + ]; + } +} diff --git a/src/Factories/ProposalModelPeriodicitiesFactory.php b/src/Factories/ProposalModelPeriodicitiesFactory.php new file mode 100644 index 0000000..c98099b --- /dev/null +++ b/src/Factories/ProposalModelPeriodicitiesFactory.php @@ -0,0 +1,42 @@ +boolean; + $pin_value = fake()->boolean; + + return [ + 'uuid' => fake()->uuid(), + 'update_installments_quantity' => $update_installments_quantity, + 'installments' => $update_installments_quantity === false ? 0 : fake()->numberBetween(1, 360), + 'add_on_type' => fake()->randomKey(ProposalModelPeriodicities::ADD_ON_TYPE_LIST), + 'periodicity_quantity' => fake()->numberBetween(1, 360), + 'pin_value' => $pin_value, + 'add_on_value' => $pin_value ? fake()->randomFloat(2, 10, 999999) : null, + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/AccessoryCategoryFactory.php b/src/Factories/RealEstateDevelopment/AccessoryCategoryFactory.php new file mode 100644 index 0000000..da156f6 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/AccessoryCategoryFactory.php @@ -0,0 +1,34 @@ + fake()->uuid(), + 'name' => fake()->userName() + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/AccessoryFactory.php b/src/Factories/RealEstateDevelopment/AccessoryFactory.php new file mode 100644 index 0000000..dd7c8ce --- /dev/null +++ b/src/Factories/RealEstateDevelopment/AccessoryFactory.php @@ -0,0 +1,38 @@ + fake()->uuid(), + 'accessory_id' => Accessory::inRandomOrder()->first(), + 'stock_quantity' => fake()->numberBetween(1, 50), + 'order' => fake()->randomNumber(1, 100), + 'start_at' => now(), + 'end_at' => now()->addDays(fake()->numerify('##')), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/BlueprintFactory.php b/src/Factories/RealEstateDevelopment/BlueprintFactory.php new file mode 100644 index 0000000..01c60f4 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/BlueprintFactory.php @@ -0,0 +1,35 @@ + fake()->uuid(), + 'name' => fake()->company, + 'description' => fake()->text(), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/BlueprintImageFactory.php b/src/Factories/RealEstateDevelopment/BlueprintImageFactory.php new file mode 100644 index 0000000..9d62a5a --- /dev/null +++ b/src/Factories/RealEstateDevelopment/BlueprintImageFactory.php @@ -0,0 +1,36 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'image' => 'https://placeimg.com/640/480/any?' . fake()->uuid, + 'format' => fake()->mimeType(), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/CharacteristicFactory.php b/src/Factories/RealEstateDevelopment/CharacteristicFactory.php new file mode 100644 index 0000000..30f75fc --- /dev/null +++ b/src/Factories/RealEstateDevelopment/CharacteristicFactory.php @@ -0,0 +1,36 @@ + fake()->uuid(), + 'order' => rand(1, 20), + 'differential' => fake()->boolean, + 'description' => fake()->text, + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/DocumentFactory.php b/src/Factories/RealEstateDevelopment/DocumentFactory.php new file mode 100644 index 0000000..bb26a04 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/DocumentFactory.php @@ -0,0 +1,40 @@ + fake()->uuid(), + 'name' => fake()->words(3, true), + 'description' => fake()->text(300), + 'format' => fake()->fileExtension, + 'url' => 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf?' . fake()->uuid, + 'preview' => fake()->optional(0.8)->passthrough('https://placeimg.com/640/480/tech?' . fake()->uuid), + 'active' => fake()->boolean, + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/MediaFactory.php b/src/Factories/RealEstateDevelopment/MediaFactory.php new file mode 100644 index 0000000..f189a54 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/MediaFactory.php @@ -0,0 +1,40 @@ + fake()->uuid(), + 'name' => fake()->word, + 'description' => fake()->paragraph, + 'preview' => 'https://placeimg.com/640/480/any?' . fake()->uuid, + 'media_type' => fake()->randomKey(Media::MEDIA_TYPE_LIST), + 'url' => fake()->imageUrl(), + 'format' => fake()->fileExtension, + 'active' => fake()->boolean, + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/MirrorFactory.php b/src/Factories/RealEstateDevelopment/MirrorFactory.php new file mode 100644 index 0000000..06b2ef8 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/MirrorFactory.php @@ -0,0 +1,35 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'mirror_type' => fake()->randomKey(Mirror::MIRROR_TYPES), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/MirrorGroupFactory.php b/src/Factories/RealEstateDevelopment/MirrorGroupFactory.php new file mode 100644 index 0000000..34864b5 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/MirrorGroupFactory.php @@ -0,0 +1,34 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/ParameterFactory.php b/src/Factories/RealEstateDevelopment/ParameterFactory.php new file mode 100644 index 0000000..2bd80b4 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/ParameterFactory.php @@ -0,0 +1,50 @@ + fake()->uuid(), + 'name' => fake()->name, + 'allow_commercialization' => fake()->boolean(), + 'blueprint_definition_deadline' => fake()->date(), + 'commercialization_status' => fake()->randomKey(Parameter::COMMERCIALIZATION_STATUS_LIST), + 'construction_over_in' => fake()->date(), + 'construction_prevision_in' => fake()->date(), + 'construction_start_in' => fake()->date(), + 'financial_transfer_deadline' => fake()->date(), + 'financial_transfer_status' => fake()->randomKey(Parameter::FINANCIAL_TRANSFER_STATUS_LIST), + 'hand_over_keys_in' => fake()->date(), + 'in_financial_transfer' => fake()->boolean(), + 'launch_in' => fake()->dateTimeBetween('+1 year', '+2 years'), + 'pre_launch_in' => fake()->dateTimeBetween('now', '+2 years'), + 'ready_to_live_in' => fake()->dateTimeBetween('+2 years', '+3 years'), + 'square_meter_price' => fake()->numberBetween(1, 100), + 'steps' => fake()->randomKey(Parameter::STEPS_LIST), + 'verge' => fake()->randomKey(Parameter::VERGE_LIST), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/StageFactory.php b/src/Factories/RealEstateDevelopment/StageFactory.php new file mode 100644 index 0000000..6448cca --- /dev/null +++ b/src/Factories/RealEstateDevelopment/StageFactory.php @@ -0,0 +1,41 @@ +first(); + + return [ + 'uuid' => fake()->uuid(), + 'name' => fake()->words(5, true), + 'registered_at' => fake()->date(), + 'foundation' => fake()->numberBetween($latest ? $latest->foundation : 1, 100), + 'masonry' => fake()->numberBetween($latest ? $latest->masonry : 1, 100), + 'structure' => fake()->numberBetween($latest ? $latest->structure : 1, 100), + 'finishing' => fake()->numberBetween($latest ? $latest->finishing : 1, 100), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/StageImageFactory.php b/src/Factories/RealEstateDevelopment/StageImageFactory.php new file mode 100644 index 0000000..f2f8b9b --- /dev/null +++ b/src/Factories/RealEstateDevelopment/StageImageFactory.php @@ -0,0 +1,36 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'image' => 'https://placeimg.com/640/480/any?' . fake()->uuid, + 'format' => fake()->mimeType(), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/TypologyAttributeFactory.php b/src/Factories/RealEstateDevelopment/TypologyAttributeFactory.php new file mode 100644 index 0000000..8536ac6 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/TypologyAttributeFactory.php @@ -0,0 +1,37 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + 'description' => fake()->text(), + 'type_increase' => fake()->randomKey(TypologyAttribute::ADDITION_TYPE), + 'value_increase' => fake()->randomFloat(2, 0, 9999) + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/TypologyFactory.php b/src/Factories/RealEstateDevelopment/TypologyFactory.php new file mode 100644 index 0000000..4558701 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/TypologyFactory.php @@ -0,0 +1,34 @@ + fake()->uuid(), + 'name' => fake()->words(5, true), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopment/UnitFactory.php b/src/Factories/RealEstateDevelopment/UnitFactory.php new file mode 100644 index 0000000..0963792 --- /dev/null +++ b/src/Factories/RealEstateDevelopment/UnitFactory.php @@ -0,0 +1,49 @@ + fake()->uuid(), + 'name' => fake()->words(3, true), + 'code' => fake()->unique()->numberBetween(100, 10000), + 'unit_type' => fake()->randomKey(Unit::UNIT_TYPE_LIST), + 'floor' => fake()->numberBetween(1, 20), + 'square_meters' => fake()->numberBetween(200, 400), + 'ideal_fraction' => fake()->numberBetween(1, 50), + 'fixed_price' => fake()->numberBetween(10000, 200000), + 'factor' => fake()->numberBetween(1, 10000), + 'special_needs' => fake()->boolean(), + 'observations' => fake()->paragraphs(3, true), + 'ready_to_live_in' => fake()->date(), + 'notary_registration' => fake()->numberBetween(100000, 200000), + 'property_tax_identification' => fake()->numberBetween(100000, 200000), + 'has_empty_fields' => fake()->numberBetween(1, 10), + 'external_code' => fake()->numberBetween(1, 10000), + 'external_subsidiary_code' => fake()->unique()->numberBetween(1, 10000), + ]; + } +} diff --git a/src/Factories/RealEstateDevelopmentFactory.php b/src/Factories/RealEstateDevelopmentFactory.php new file mode 100644 index 0000000..65c58ea --- /dev/null +++ b/src/Factories/RealEstateDevelopmentFactory.php @@ -0,0 +1,74 @@ +city; + + return [ + 'uuid' => fake()->uuid(), + 'status' => fake()->randomKey(RealEstateDevelopment::STATUS_LIST), + 'address' => fake()->streetName, + 'city' => $city, + 'complement' => fake()->numberBetween(1, 300), + 'construction_address' => fake()->streetName, + 'construction_city' => $city, + 'construction_complement' => fake()->numberBetween(1, 300), + 'construction_neighborhood' => fake()->words(5, true), + 'construction_phone' => fake()->phoneNumber, + 'construction_postal_code' => fake()->postcode, + 'construction_state' => fake()->state, + 'construction_street_number' => fake()->numberBetween(1, 300), + 'description' => fake()->paragraph, + 'document' => fake()->cnpj(false), + 'latitude' => fake()->latitude($min = ($lang - (rand(0, 500) / 1000)), $max = ($lang + (rand(0, 500) / 1000))), + 'longitude' => fake()->longitude($min = ($long - (rand(0, 500) / 1000)), $max = ($long + (rand(0, 500) / 1000))), + 'legal_text' => fake()->paragraph, + 'name' => fake()->company . ' ' . fake()->companySuffix, + 'neighborhood' => fake()->words(5, true), + 'nickname' => fake()->company, + 'nire' => fake()->numerify('###########'), + 'nire_date' => fake()->date(), + 'postal_code' => fake()->postcode, + 'real_estate' => fake()->company . ' ' . fake()->companySuffix, + 'real_estate_logo' => 'https://placeimg.com/640/480/arch?' . fake()->uuid, + 'register_number' => fake()->numerify('###########'), + 'registration_number' => fake()->numerify('###########'), + 'registry_office' => fake()->words(5, true), + 'state' => fake()->state, + 'street_number' => fake()->numberBetween(1, 300), + 'hub_company_id' => config('sp-produto.model_company')::inRandomOrder()->first()->id, + 'external_code' => fake()->unique()->numberBetween(1, 300), + 'external_num_code' => fake()->numberBetween(50, 300), + 'external_company_code' => fake()->numberBetween(2, 300), + 'external_subsidiary_code' => fake()->numberBetween(90, 300), + ]; + } +} diff --git a/src/Models/Accessory.php b/src/Models/Accessory.php index 673d8c4..cd86265 100644 --- a/src/Models/Accessory.php +++ b/src/Models/Accessory.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\AccessoryFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,12 +15,23 @@ */ class Accessory extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('accessories'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'accessories'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return AccessoryFactory::new(); } /** diff --git a/src/Models/AccessoryCategory.php b/src/Models/AccessoryCategory.php index c3c3dce..ce6b53c 100644 --- a/src/Models/AccessoryCategory.php +++ b/src/Models/AccessoryCategory.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\CategoryFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,12 +15,23 @@ */ class AccessoryCategory extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('accessory_categories'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'accessory_categories'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return CategoryFactory::new(); } /** diff --git a/src/Models/BuyingOption.php b/src/Models/BuyingOption.php index d216625..57955ae 100644 --- a/src/Models/BuyingOption.php +++ b/src/Models/BuyingOption.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\BuyingOptionFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,14 +15,53 @@ */ class BuyingOption extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('buying_options'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'buying_options'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return BuyingOptionFactory::new(); + } + + public const WHEN_FLOW_SENT_LIST = [ + 'without_restriction' => 'Sem restrição', + 'after_cadastral_analysis' => 'Após análise cadastral', + 'after_credit_approval' => 'Após aprovação de crédito', + 'after_bank_approval' => 'Após aprovação do banco', + ]; + + public const WHEN_FLOW_VALIDATED_LIST = [ + 'without_restriction' => 'Sem restrição', + 'after_cadastral_analysis' => 'Após análise cadastral', + 'after_credit_approval' => 'Após aprovação de crédito', + 'after_bank_approval' => 'Após aprovação do banco', + ]; + + public const WHEN_MAKE_SALE_LIST = [ + 'without_restriction' => 'Sem restrição', + 'after_cadastral_analysis' => 'Após análise cadastral', + 'after_credit_approval' => 'Após aprovação de crédito', + 'after_bank_approval' => 'Após aprovação do banco', + ]; + + public const WHEN_RESERVE_UNIT_LIST = [ + 'without_restriction' => 'Sem restrição', + 'after_cadastral_analysis' => 'Após análise cadastral', + 'after_credit_approval' => 'Após aprovação de crédito', + 'after_bank_approval' => 'Após aprovação do banco', + ]; + /** * The attributes that are mass assignable. * diff --git a/src/Models/Characteristic.php b/src/Models/Characteristic.php index 6041427..e72e277 100644 --- a/src/Models/Characteristic.php +++ b/src/Models/Characteristic.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\CharacteristicFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,12 +15,23 @@ */ class Characteristic extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('characteristics'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'characteristics'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return CharacteristicFactory::new(); } /** diff --git a/src/Models/Insurance.php b/src/Models/Insurance.php index ecd3f1e..11aab53 100644 --- a/src/Models/Insurance.php +++ b/src/Models/Insurance.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\InsuranceFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,12 +15,23 @@ */ class Insurance extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('insurances'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'insurances'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return InsuranceFactory::new(); } /** diff --git a/src/Models/InsuranceCompany.php b/src/Models/InsuranceCompany.php index 3ee84dd..fe6b2ba 100644 --- a/src/Models/InsuranceCompany.php +++ b/src/Models/InsuranceCompany.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\InsuranceCompanyFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,12 +15,23 @@ */ class InsuranceCompany extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('insurance_companies'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'insurance_companies'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return InsuranceCompanyFactory::new(); } /** diff --git a/src/Models/ProposalModel.php b/src/Models/ProposalModel.php index 99e7657..c591c7f 100644 --- a/src/Models/ProposalModel.php +++ b/src/Models/ProposalModel.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\ProposalModelFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -13,12 +16,23 @@ */ class ProposalModel extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('proposal_models'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'proposal_models'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return ProposalModelFactory::new(); } /** diff --git a/src/Models/ProposalModelPeriodicities.php b/src/Models/ProposalModelPeriodicities.php index c547d55..3687711 100644 --- a/src/Models/ProposalModelPeriodicities.php +++ b/src/Models/ProposalModelPeriodicities.php @@ -2,6 +2,9 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\ProposalModelPeriodicitiesFactory; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -12,14 +15,33 @@ */ class ProposalModelPeriodicities extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('proposal_model_periodicities'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'proposal_model_periodicities'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return ProposalModelPeriodicitiesFactory::new(); + } + + /** + * @const array[] + */ + public const ADD_ON_TYPE_LIST = [ + 'fixed_value' => 'Valor fixo', + 'percentage' => 'Porcentagem' + ]; + /** * The attributes that are mass assignable. * diff --git a/src/Models/RealEstateDevelopment.php b/src/Models/RealEstateDevelopment.php index 89f2977..7506551 100644 --- a/src/Models/RealEstateDevelopment.php +++ b/src/Models/RealEstateDevelopment.php @@ -2,14 +2,24 @@ namespace BildVitta\SpProduto\Models; +use BildVitta\SpProduto\Factories\RealEstateDevelopmentFactory; +use BildVitta\SpProduto\Models\RealEstateDevelopment\Blueprint; use BildVitta\SpProduto\Models\RealEstateDevelopment\Document; +use BildVitta\SpProduto\Models\RealEstateDevelopment\Media; use BildVitta\SpProduto\Models\RealEstateDevelopment\MirrorGroup; +use BildVitta\SpProduto\Models\RealEstateDevelopment\Parameter; use BildVitta\SpProduto\Models\RealEstateDevelopment\Stage; +use BildVitta\SpProduto\Models\RealEstateDevelopment\Typology; use BildVitta\SpProduto\Models\RealEstateDevelopment\Unit; use BildVitta\SpProduto\Models\RealEstateDevelopment\Mirror; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; /** * Class RealEstateDevelopment. @@ -18,6 +28,7 @@ */ class RealEstateDevelopment extends BaseModel { + use HasFactory; use SoftDeletes; public const STATUS_LIST = [ @@ -26,10 +37,20 @@ class RealEstateDevelopment extends BaseModel 'in_commercialization' => 'Em comercialização', ]; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('real_estate_developments'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'real_estate_developments'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return RealEstateDevelopmentFactory::new(); } /** @@ -82,7 +103,7 @@ public function __construct() ]; /** - * Get hub company. + * Real estate developments hub company * * @return BelongsTo */ @@ -92,82 +113,208 @@ public function hub_company(): BelongsTo } /** - * Real estate developments proposal models. + * Real estate developments proposal models + * + * @return BelongsToMany + */ + public function proposal_models(): BelongsToMany + { + return $this->belongsToMany(ProposalModel::class, config('sp-produto.table_prefix') . 'proposal_model_real_estate_development') + ->with('periodicities'); + } + + /** + * Real estate developments buying options + * + * @return BelongsToMany + */ + public function buying_options(): BelongsToMany + { + return $this->belongsToMany(BuyingOption::class, config('sp-produto.table_prefix') . 'buying_option_real_estate_development'); + } + + /** + * Real estate development insurance companies + * + * @return BelongsToMany */ - public function proposal_models() + public function insurance_companies(): BelongsToMany { - return $this->belongsToMany(ProposalModel::class, prefixTableName('proposal_model_real_estate_development')); + return $this->belongsToMany(InsuranceCompany::class, config('sp-produto.table_prefix') . 'insurance_company_real_estate_development'); } /** - * Real estate developments buying options. + * Real estate development insurances + * + * @return BelongsToMany */ - public function buying_options() + public function insurances(): BelongsToMany { - return $this->belongsToMany(BuyingOption::class, prefixTableName('buying_option_real_estate_development')); + return $this->belongsToMany(Insurance::class, config('sp-produto.table_prefix') . 'insurance_real_estate_development'); } /** - * Real estate development insurance companies. + * Real estate developments characteristics + * + * @return HasMany */ - public function insurance_companies() + public function characteristics(): HasMany { - return $this->belongsToMany(InsuranceCompany::class, prefixTableName('insurance_company_real_estate_development')); + return $this->hasMany(Characteristic::class); } /** - * Real estate development insurances. + * Real estate developments accessories + * + * @return HasMany */ - public function insurances() + public function accessories(): HasMany { - return $this->belongsToMany(Insurance::class, prefixTableName('insurance_real_estate_development')); + return $this->hasMany(RealEstateDevelopment\Accessory::class); } /** - * Real estate development characteristics. + * Real estate developments documents + * + * @return HasMany */ - public function characteristics() + public function documents(): HasMany { - return $this->belongsTo(Characteristic::class); + return $this->hasMany(Document::class); } /** - * Real estate development groups. + * Real estate developments medias + * + * @return HasMany */ - public function groups() + public function medias(): HasMany { - return $this->belongsTo(MirrorGroup::class); + return $this->hasMany(Media::class); + } + + public function lastStages(): HasMany + { + return $this->hasMany(Stage::class); } /** - * Real estate development stages. + * Real estate developments typologies + * + * @return HasMany */ - public function stages() + public function typologies(): HasMany { - return $this->belongsTo(Stage::class); + return $this->hasMany(Typology::class); } /** - * Real estate development documents. + * Real estate developments mirrors + * + * @return HasMany */ - public function documents() + public function mirrors(): HasMany { - return $this->belongsTo(Document::class); + return $this->hasMany(Mirror::class); } /** - * Real estate developments unities. + * Define a one-to-many relationship. + * + * @return HasMany */ - public function unities() + public function unities(): HasMany { return $this->hasMany(Unit::class); } /** - * Real estate developments mirrors. + * Define a one-to-many relationship. + * + * @return HasMany */ - public function mirrors() + public function blueprints(): HasMany { - return $this->hasMany(Mirror::class); + return $this->hasMany(Blueprint::class); + } + + public function getLaunchInAttribute() + { + if ($parameter = $this->parameters()->latest('created_at')->first()) { + if ($parameter->launch_in) { + return $parameter->launch_in; + } + } + + return null; + } + + /** + * Real estate developments paramenters + * + * @return HasMany + */ + public function parameters(): HasMany + { + return $this->hasMany(Parameter::class); + } + + public function getPreLaunchInAttribute() + { + if ($parameter = $this->parameters()->latest('created_at')->first()) { + if ($parameter->pre_launch_in) { + if ($parameter->pre_launch_in->gt(Carbon::now())) { + return $parameter->pre_launch_in; + } + } + } + + return null; + } + + public function last_stage() + { + try { + return $this->stages()->with(['images'])->latest('registered_at')->firstOrFail(); + } catch (ModelNotFoundException $modelNotFoundException) { + return null; + } + } + + /** + * Real estate developments stages + * + * @return HasMany + */ + public function stages(): HasMany + { + return $this->hasMany(Stage::class); + } + + public function last_parameter() + { + try { + return $this->parameters()->latest('created_at')->firstOrFail(); + } catch (ModelNotFoundException $modelNotFoundException) { + return null; + } + } + + public function real_estate_proposal_models() + { + return $this->proposal_models; + } + + public function real_estate_accessories() + { + return $this->accessories() + ->with(['accessory_categorization', 'accessory']) + ->get() + ->toArray(); + } + + public function getHubCompanyUuidAttribute(): ?string + { + return $this->hub_company?->uuid; } } diff --git a/src/Models/RealEstateDevelopment/Accessory.php b/src/Models/RealEstateDevelopment/Accessory.php index 8557d7c..fa7f9e3 100644 --- a/src/Models/RealEstateDevelopment/Accessory.php +++ b/src/Models/RealEstateDevelopment/Accessory.php @@ -2,9 +2,15 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\AccessoryFactory; +use BildVitta\SpProduto\Models\AccessoryCategory; use BildVitta\SpProduto\Models\BaseModel; +use BildVitta\SpProduto\Models\Accessory as BaseAccessory; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -14,12 +20,23 @@ */ class Accessory extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('real_estate_development_accessories'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'real_estate_development_accessories'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return AccessoryFactory::new(); } /** @@ -44,11 +61,51 @@ public function __construct() 'deleted_at', ]; + public function name(): BelongsTo + { + return $this->accessory(); + } + + /** + * Define Accessory + * + * @return BelongsTo + */ + public function accessory(): BelongsTo + { + return $this->belongsTo(BaseAccessory::class); + } + /** + * Define an inverse one-to-one or many relationship. + * + * @return BelongsTo + */ + public function category(): BelongsTo + { + return $this->belongsTo(AccessoryCategory::class); + } + + /** + * Real Estate Development accessory categorization. + * * @return BelongsTo */ - public function realEstateDevelopment(): BelongsTo + public function accessory_categorization(): BelongsTo + { + return $this->belongsTo(AccessoryCategory::class); + } + + public function real_estate_development(): BelongsTo { return $this->belongsTo(RealEstateDevelopment::class); } + + /** + * @return string|null + */ + public function getNameAttribute(): ?string + { + return $this?->accessory?->name; + } } diff --git a/src/Models/RealEstateDevelopment/Blueprint.php b/src/Models/RealEstateDevelopment/Blueprint.php index 3ceee82..40acca7 100644 --- a/src/Models/RealEstateDevelopment/Blueprint.php +++ b/src/Models/RealEstateDevelopment/Blueprint.php @@ -2,8 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\BlueprintFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -16,12 +19,23 @@ */ class Blueprint extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('blueprints'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'blueprints'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return BlueprintFactory::new(); } /** @@ -61,7 +75,7 @@ public function typologies(): BelongsToMany public function real_estate_development_accessories(): BelongsToMany { return $this->belongsToMany( - Accessory::class, + RealEstateDevelopment\Accessory::class, prefixTableName('blueprint_real_estate_development_accessory'), 'blueprint_id', 'real_estate_development_accessory_id' @@ -82,4 +96,14 @@ public function images() { return $this->real_estate_developments_blueprint_images(); } + + /** + * Get real estate development blueprint typologies. + * + * @return BelongsToMany + */ + public function real_estate_developments_typologies(): BelongsToMany + { + return $this->belongsToMany(Typology::class, config('sp-produto.table_prefix') . 'blueprint_typology'); + } } diff --git a/src/Models/RealEstateDevelopment/BlueprintImage.php b/src/Models/RealEstateDevelopment/BlueprintImage.php index ab8bd2e..8ed0dfc 100644 --- a/src/Models/RealEstateDevelopment/BlueprintImage.php +++ b/src/Models/RealEstateDevelopment/BlueprintImage.php @@ -2,7 +2,10 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\BlueprintImageFactory; use BildVitta\SpProduto\Models\BaseModel; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -13,12 +16,23 @@ */ class BlueprintImage extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('blueprint_images'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'blueprint_images'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return BlueprintImageFactory::new(); } /** diff --git a/src/Models/RealEstateDevelopment/Characteristic.php b/src/Models/RealEstateDevelopment/Characteristic.php index de31b4c..7ca82fb 100644 --- a/src/Models/RealEstateDevelopment/Characteristic.php +++ b/src/Models/RealEstateDevelopment/Characteristic.php @@ -2,8 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\CharacteristicFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,12 +17,23 @@ */ class Characteristic extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('real_estate_development_characteristics'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'real_estate_development_characteristics'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return CharacteristicFactory::new(); } /** diff --git a/src/Models/RealEstateDevelopment/Document.php b/src/Models/RealEstateDevelopment/Document.php index e804573..d40bc0d 100644 --- a/src/Models/RealEstateDevelopment/Document.php +++ b/src/Models/RealEstateDevelopment/Document.php @@ -2,8 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\DocumentFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,12 +17,23 @@ */ class Document extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('documents'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'documents'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return DocumentFactory::new(); } /** diff --git a/src/Models/RealEstateDevelopment/Media.php b/src/Models/RealEstateDevelopment/Media.php index 66e2271..ae462df 100644 --- a/src/Models/RealEstateDevelopment/Media.php +++ b/src/Models/RealEstateDevelopment/Media.php @@ -2,8 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\MediaFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,16 +17,33 @@ */ class Media extends BaseModel { + use HasFactory; use SoftDeletes; - public const MEDIA_TYPES = []; + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'media'; + } - public function __construct() + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory { - parent::__construct(); - $this->table = prefixTableName('media'); + return MediaFactory::new(); } + /** + * @const array MEDIA_TYPE_LIST + */ + public const MEDIA_TYPE_LIST = [ + 'image' => 'Imagem', + 'video' => 'Vídeo', + ]; + /** * The attributes that are mass assignable. * diff --git a/src/Models/RealEstateDevelopment/Mirror.php b/src/Models/RealEstateDevelopment/Mirror.php index 28a6d05..d30a205 100644 --- a/src/Models/RealEstateDevelopment/Mirror.php +++ b/src/Models/RealEstateDevelopment/Mirror.php @@ -2,9 +2,14 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\MirrorFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -14,14 +19,35 @@ */ class Mirror extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('mirrors'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'mirrors'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return MirrorFactory::new(); + } + + /** + * Mirror types. + * + * @const array + */ + public const MIRROR_TYPES = [ + 'horizontal' => 'Horizontal', + 'vertical' => 'Vertical' + ]; + /** * The attributes that are mass assignable. * @@ -39,10 +65,45 @@ public function __construct() ]; /** + * Define a one-to-one relationship. + * * @return BelongsTo */ - public function realEstateDevelopment(): BelongsTo + public function real_estate_developments_parameters(): BelongsTo + { + return $this->belongsTo(Parameter::class, 'parameter_id'); + } + + /** + * @return Collection + */ + public function subgroups(): Collection + { + return $this->mirrorGroup()->with([ + 'units' => function (HasMany $query) { + $query->with(['real_estate_developments_blueprints']); + $query->orderBy('floor'); + } + ])->get(); + } + + /** + * Define a one-to-many relationship. + * + * @return HasMany + */ + public function mirrorGroup(): HasMany + { + return $this->real_estate_developments_mirrors_subgroups(); + } + + /** + * Define a one-to-many relationship. + * + * @return HasMany + */ + public function real_estate_developments_mirrors_subgroups(): HasMany { - return $this->belongsTo(RealEstateDevelopment::class); + return $this->hasMany(MirrorGroup::class); } } diff --git a/src/Models/RealEstateDevelopment/MirrorGroup.php b/src/Models/RealEstateDevelopment/MirrorGroup.php index 57661f5..ead9f4b 100644 --- a/src/Models/RealEstateDevelopment/MirrorGroup.php +++ b/src/Models/RealEstateDevelopment/MirrorGroup.php @@ -2,7 +2,10 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\MirrorGroupFactory; use BildVitta\SpProduto\Models\BaseModel; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,12 +17,23 @@ */ class MirrorGroup extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('mirror_groups'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'mirror_groups'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return MirrorGroupFactory::new(); } /** diff --git a/src/Models/RealEstateDevelopment/Parameter.php b/src/Models/RealEstateDevelopment/Parameter.php index c01c956..b5582ea 100644 --- a/src/Models/RealEstateDevelopment/Parameter.php +++ b/src/Models/RealEstateDevelopment/Parameter.php @@ -2,9 +2,14 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\ParameterFactory; use BildVitta\SpProduto\Models\BaseModel; +use BildVitta\SpProduto\Models\BuyingOption; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -14,14 +19,59 @@ */ class Parameter extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('parameters'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'parameters'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return ParameterFactory::new(); + } + + public const COMMERCIALIZATION_STATUS_LIST = [ + 'holding' => 'Aguardando', + 'in_commercialization' => 'Em comercialização', + 'ready_to_commercializate' => 'Pronto para comercialização', + ]; + + public const FINANCIAL_TRANSFER_STATUS_LIST = [ + 'holding' => 'Aguardando', + 'in_transfer' => 'Em repasse', + ]; + + public const STEPS_LIST = [ + 'pre_launch' => 'Pré-lançamento', + 'launch' => 'Lançamento', + 'under_construction' => 'Em construção', + 'ready_to_live' => 'Pronto para viver', + ]; + + public const VERGE_LIST = [ + '1' => 'Nível 1', + '2' => 'Nível 2', + '3' => 'Nível 3', + '4' => 'Nível 4', + '5' => 'Nível 5', + ]; + + public const REQUIRED_DATES = [ + 'pre_launch_in', + 'launch_in', + 'blueprint_definition_deadline', + 'construction_over_in', + 'construction_start_in' + ]; + /** * The attributes that are mass assignable. * @@ -94,4 +144,14 @@ public function realEstateDevelopment(): BelongsTo { return $this->belongsTo(RealEstateDevelopment::class); } + + /** + * Get the buying options for the parameter. + * + * @return BelongsToMany + */ + public function buying_options(): BelongsToMany + { + return $this->belongsToMany(BuyingOption::class, config('sp-produto.prefix_table') . 'buying_options'); + } } diff --git a/src/Models/RealEstateDevelopment/Stage.php b/src/Models/RealEstateDevelopment/Stage.php index 1855a74..e3df386 100644 --- a/src/Models/RealEstateDevelopment/Stage.php +++ b/src/Models/RealEstateDevelopment/Stage.php @@ -2,8 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\StageFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -15,12 +18,23 @@ */ class Stage extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('stages'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'stages'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return StageFactory::new(); } /** @@ -69,4 +83,14 @@ public function images(): HasMany { return $this->hasMany(StageImage::class); } + + /** + * Get the real estate development stage images. + * + * @return HasMany + */ + public function real_estate_developments_stages_images(): HasMany + { + return $this->hasMany(StageImage::class); + } } diff --git a/src/Models/RealEstateDevelopment/StageImage.php b/src/Models/RealEstateDevelopment/StageImage.php index f90d0fa..624f2df 100644 --- a/src/Models/RealEstateDevelopment/StageImage.php +++ b/src/Models/RealEstateDevelopment/StageImage.php @@ -2,7 +2,10 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\StageImageFactory; use BildVitta\SpProduto\Models\BaseModel; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -13,12 +16,23 @@ */ class StageImage extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('stage_images'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'stage_images'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return StageImageFactory::new(); } /** diff --git a/src/Models/RealEstateDevelopment/Typology.php b/src/Models/RealEstateDevelopment/Typology.php index ca2f863..3ced736 100644 --- a/src/Models/RealEstateDevelopment/Typology.php +++ b/src/Models/RealEstateDevelopment/Typology.php @@ -2,10 +2,15 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\TypologyFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\ProposalModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -15,12 +20,23 @@ */ class Typology extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('typologies'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'typologies'; + } + + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return TypologyFactory::new(); } /** @@ -37,19 +53,49 @@ public function __construct() 'deleted_at', ]; + public function realEstateDevelopment(): BelongsTo + { + return $this->belongsTo(RealEstateDevelopment::class); + } + /** - * @return BelongsTo + * Get the real estate development proposal models. + * + * @return BelongsToMany */ - public function proposal_model(): BelongsTo + public function real_estate_developments_proposal_model(): BelongsToMany { - return $this->belongsTo(ProposalModel::class, prefixTableName('proposal_models')); + return $this->belongsToMany(ProposalModel::class, config('sp-produto.table_prefix') . 'proposal_model_typology', 'typology_id', 'proposal_model_id'); } /** - * @return BelongsTo + * Define a many-to-many relationship. + * + * @return BelongsToMany + */ + public function accessories(): BelongsToMany + { + return $this->belongsToMany(RealEstateDevelopment\Accessory::class, config('sp-produto.table_prefix') . 'real_estate_development_accessory_typology'); + } + + /** + * Get blueprints for typology. + * + * @return BelongsToMany + */ + public function blueprints(): BelongsToMany + { + return $this->belongsToMany(Blueprint::class, config('sp-produto.table_prefix') . 'blueprint_typology') + ->with('real_estate_developments_blueprint_images'); + } + + /** + * Define a one-to-many relationship. + * + * @return HasMany */ - public function real_estate_development(): BelongsTo + public function units(): HasMany { - return $this->belongsTo(RealEstateDevelopment::class, prefixTableName('real_estate_developments')); + return $this->hasMany(Unit::class); } } diff --git a/src/Models/RealEstateDevelopment/TypologyAttribute.php b/src/Models/RealEstateDevelopment/TypologyAttribute.php index 32606ee..4080bf3 100644 --- a/src/Models/RealEstateDevelopment/TypologyAttribute.php +++ b/src/Models/RealEstateDevelopment/TypologyAttribute.php @@ -2,7 +2,10 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\TypologyAttributeFactory; use BildVitta\SpProduto\Models\BaseModel; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -13,14 +16,36 @@ */ class TypologyAttribute extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('typology_attributes'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'typology_attributes'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return TypologyAttributeFactory::new(); + } + + /** + * Tipo de acréscimo. + * + * @const array[] + */ + public const ADDITION_TYPE = [ + 'fixed_value' => 'Valor fixo', + 'addition_value' => 'Acréscimo de valor', + 'percentage' => 'Percentual' + ]; + /** * The attributes that are mass assignable. * diff --git a/src/Models/RealEstateDevelopment/Unit.php b/src/Models/RealEstateDevelopment/Unit.php index afdddc7..7b93d3d 100644 --- a/src/Models/RealEstateDevelopment/Unit.php +++ b/src/Models/RealEstateDevelopment/Unit.php @@ -2,9 +2,11 @@ namespace BildVitta\SpProduto\Models\RealEstateDevelopment; -use App\Models\Settings\SaleStep; +use BildVitta\SpProduto\Factories\RealEstateDevelopment\UnitFactory; use BildVitta\SpProduto\Models\BaseModel; use BildVitta\SpProduto\Models\RealEstateDevelopment; +use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -15,14 +17,37 @@ */ class Unit extends BaseModel { + use HasFactory; use SoftDeletes; - public function __construct() + public function __construct(array $attributes = []) { - parent::__construct(); - $this->table = prefixTableName('units'); + parent::__construct($attributes); + $this->table = config('sp-produto.table_prefix') . 'units'; } + /** + * Create a new factory instance for the model. + * + * @return Factory + */ + protected static function newFactory(): Factory + { + return UnitFactory::new(); + } + + /** + * Type of unity. + * + * @const string + */ + public const UNIT_TYPE_LIST = [ + 'residential' => 'Residencial', + 'commercial' => 'Comercial', + 'garage' => 'Garagem', + 'storage' => 'Armazém', + ]; + /** * The attributes that are mass assignable. * diff --git a/src/SpProdutoServiceProvider.php b/src/SpProdutoServiceProvider.php index f9c2a85..16716d5 100644 --- a/src/SpProdutoServiceProvider.php +++ b/src/SpProdutoServiceProvider.php @@ -15,6 +15,56 @@ */ class SpProdutoServiceProvider extends PackageServiceProvider { + /** + * @var array $migrations + */ + protected array $migrations = [ + 'create_sp_produto_real_estate_developments_table', // must be the first + 'create_sp_produto_buying_options_table', // must be before others buying options tables + 'create_sp_produto_buying_option_real_estate_development_table', + 'create_sp_produto_parameters_table', + 'create_sp_produto_insurance_companies_table', // must be before others insurance tables + 'create_sp_produto_insurances_table', + 'create_sp_produto_insurance_company_real_estate_development_table', + 'create_sp_produto_insurance_real_estate_development_table', + 'create_sp_produto_accessory_categories_table', // must be before the accessories table + 'create_sp_produto_accessories_table', + 'create_sp_produto_mirrors_table', // must be before the mirrors table + 'create_sp_produto_mirror_groups_table', + 'create_sp_produto_blueprints', // must be before others blueprints tables + 'create_sp_produto_blueprint_images_table', + 'create_sp_produto_blueprint_real_estate_development_accessory_table', + 'create_sp_produto_blueprint_typology_table', + 'create_sp_produto_characteristics_table', + 'create_sp_produto_proposal_models_table', // must be before others proposal models tables + 'create_sp_produto_proposal_model_periodicities_table', + 'create_sp_produto_proposal_model_real_estate_development_table', + 'create_sp_produto_proposal_model_typology_table', + 'create_sp_produto_real_estate_development_accessories_table', + 'create_sp_produto_real_estate_development_characteristic_table', + 'create_sp_produto_stages_table', + 'create_sp_produto_typologies_table', // must be before others typologies tables + 'create_sp_produto_typology_attributes_table', + 'create_sp_produto_units_table', + 'create_sp_produto_documents_table', + 'create_sp_produto_media_table', + 'create_sp_produto_stage_images_table', + ]; + + /** + * @var array $commands + */ + protected array $commands = [ + InstallSp::class, + RealEstateDevelopmentImportCommand::class, + RealEstateDevelopmentWorkerCommand::class, + ]; + + /** + * @var string $seeder + */ + protected string $seeder = 'SpProdutoSeeder'; + /** * @param Package $package * @@ -30,46 +80,16 @@ public function configurePackage(Package $package): void $package ->name('sp-produto') ->hasConfigFile(['sp-produto']) - ->hasMigrations([ - 'create_sp_produto_real_estate_developments_table', // must be the first - 'create_sp_produto_buying_options_table', // must be before others buying options tables - 'create_sp_produto_buying_option_real_estate_development_table', - 'create_sp_produto_parameters_table', - 'create_sp_produto_insurance_companies_table', // must be before others insurance tables - 'create_sp_produto_insurances_table', - 'create_sp_produto_insurance_company_real_estate_development_table', - 'create_sp_produto_insurance_real_estate_development_table', - 'create_sp_produto_accessory_categories_table', // must be before the accessories table - 'create_sp_produto_accessories_table', - 'create_sp_produto_mirrors_table', // must be before the mirrors table - 'create_sp_produto_mirror_groups_table', - 'create_sp_produto_blueprints', // must be before others blueprints tables - 'create_sp_produto_blueprint_images_table', - 'create_sp_produto_blueprint_real_estate_development_accessory_table', - 'create_sp_produto_blueprint_typology_table', - 'create_sp_produto_characteristics_table', - 'create_sp_produto_proposal_models_table', // must be before others proposal models tables - 'create_sp_produto_proposal_model_periodicities_table', - 'create_sp_produto_proposal_model_real_estate_development_table', - 'create_sp_produto_proposal_model_typology_table', - 'create_sp_produto_real_estate_development_accessories_table', - 'create_sp_produto_real_estate_development_characteristic_table', - 'create_sp_produto_stages_table', - 'create_sp_produto_typologies_table', // must be before others typologies tables - 'create_sp_produto_typology_attributes_table', - 'create_sp_produto_units_table', - 'create_sp_produto_documents_table', - 'create_sp_produto_media_table', - 'create_sp_produto_stage_images_table', - ]) + ->hasMigrations($this->migrations) ->runsMigrations(); $package ->name('sp-produto') - ->hasCommands([ - InstallSp::class, - RealEstateDevelopmentImportCommand::class, - RealEstateDevelopmentWorkerCommand::class, - ]); + ->hasCommands($this->commands); + + $this->publishes([ + $package->basePath("/../database/seeders/{$this->seeder}.php.stub") + => database_path("seeders/{$this->seeder}.php") + ], 'seeders'); } } From 8ecbeb23cff1ea8d67363b6887d7286759aa9fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Davan=C3=A7o?= Date: Fri, 2 Sep 2022 17:56:52 -0300 Subject: [PATCH 2/2] Fix styles --- .php-cs-fixer.cache | 2 +- src/helpers.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache index c3093f1..bcfecaa 100644 --- a/.php-cs-fixer.cache +++ b/.php-cs-fixer.cache @@ -1 +1 @@ -{"php":"8.1.5","version":"3.9.5:v3.9.5#4465d70ba776806857a1ac2a6f877e582445ff36","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_indentation":true,"array_syntax":{"syntax":"short"}},"hashes":{"src\/helpers.php":2955824014,"src\/Console\/InstallSp.php":145978080,"src\/Console\/Commands\/DataImportCommand.php":1216256611,"src\/Console\/Commands\/Messages\/RealEstateDevelopmentWorkerCommand.php":4020745564,"src\/Console\/Commands\/Messages\/Exceptions\/MessageProcessorException.php":3454944512,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/CharacteristicHelper.php":1546458016,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/ParameterHelper.php":3914539944,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/BlueprintHelper.php":1869376211,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/RealEstateDevelopmentHelper.php":327243289,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/Tools.php":4281896867,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/AccessoriesHelper.php":3839763478,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/MirrorHelper.php":1025311113,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/BuyingOptionHelper.php":4183484867,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/MediaHelper.php":2830690634,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/LogHelper.php":1737667178,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/StageHelper.php":2153974164,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/InsuranceHelper.php":1812328318,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/ProposalModelHelper.php":2787571064,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/TypologyHelper.php":4035498689,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/UnitHelper.php":600379083,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/DocumentHelper.php":2415016804,"src\/Console\/Commands\/Messages\/Resources\/RealEstateDevelopmentMessageProcessor.php":3695817550,"src\/SpProduto.php":1373773954,"src\/SpProdutoFacade.php":2927652880,"src\/Models\/AccessoryCategory.php":2212292934,"src\/Models\/BuyingOption.php":4164122762,"src\/Models\/ProposalModelPeriodicities.php":2421852345,"src\/Models\/ProposalModel.php":2943249074,"src\/Models\/RealEstateDevelopment\/Media.php":1909759360,"src\/Models\/RealEstateDevelopment\/MirrorGroup.php":3614288872,"src\/Models\/RealEstateDevelopment\/StageImage.php":3287229800,"src\/Models\/RealEstateDevelopment\/Stage.php":1357193195,"src\/Models\/RealEstateDevelopment\/Mirror.php":737384235,"src\/Models\/RealEstateDevelopment\/Document.php":22748684,"src\/Models\/RealEstateDevelopment\/Blueprint.php":3621993781,"src\/Models\/RealEstateDevelopment\/BlueprintImage.php":3130137527,"src\/Models\/RealEstateDevelopment\/Accessory.php":2068173232,"src\/Models\/RealEstateDevelopment\/Unit.php":2349401507,"src\/Models\/RealEstateDevelopment\/Typology.php":2899946140,"src\/Models\/RealEstateDevelopment\/Characteristic.php":967651033,"src\/Models\/RealEstateDevelopment\/TypologyAttribute.php":1648503475,"src\/Models\/RealEstateDevelopment\/Parameter.php":2404546049,"src\/Models\/InsuranceCompany.php":24027493,"src\/Models\/Accessory.php":1312199484,"src\/Models\/BaseModel.php":4191027036,"src\/Models\/Characteristic.php":2721515889,"src\/Models\/Insurance.php":3143702067,"src\/Models\/RealEstateDevelopment.php":1839383809,"src\/SpProdutoServiceProvider.php":367073774,"tests\/TestCase.php":2006129264,"tests\/ExampleTest.php":1981190735,"config\/sp-produto.php":2209096954,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/RealEstateDevelopmentImportCommand.php":670787002,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/DispatchNextJob.php":1888004773,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncRelated.php":3047899723,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/UpdateWorker.php":2961100674,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/Connection.php":1690040973,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncData.php":3275117185,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncTables.php":535893488,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Jobs\/RealEstateDevelopmentImportJob.php":2138864383}} \ No newline at end of file +{"php":"8.1.7","version":"3.11.0:v3.11.0#7dcdea3f2f5f473464e835be9be55283ff8cfdc3","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_indentation":true,"array_syntax":{"syntax":"short"}},"hashes":{"src\/helpers.php":43960338,"src\/Console\/InstallSp.php":737218074,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/RealEstateDevelopmentImportCommand.php":670787002,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/DispatchNextJob.php":1888004773,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncRelated.php":3047899723,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/UpdateWorker.php":2961100674,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/Connection.php":1690040973,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncData.php":3275117185,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Resources\/SyncTables.php":535893488,"src\/Console\/Commands\/DataImport\/RealEstateDevelopments\/Jobs\/RealEstateDevelopmentImportJob.php":2138864383,"src\/Console\/Commands\/Messages\/RealEstateDevelopmentWorkerCommand.php":4020745564,"src\/Console\/Commands\/Messages\/Exceptions\/MessageProcessorException.php":3454944512,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/CharacteristicHelper.php":1546458016,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/ParameterHelper.php":3914539944,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/BlueprintHelper.php":1869376211,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/RealEstateDevelopmentHelper.php":327243289,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/Tools.php":4281896867,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/AccessoriesHelper.php":3839763478,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/MirrorHelper.php":1025311113,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/BuyingOptionHelper.php":4183484867,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/MediaHelper.php":2830690634,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/LogHelper.php":1737667178,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/StageHelper.php":2153974164,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/InsuranceHelper.php":1812328318,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/ProposalModelHelper.php":2787571064,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/TypologyHelper.php":4035498689,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/UnitHelper.php":600379083,"src\/Console\/Commands\/Messages\/Resources\/Helpers\/DocumentHelper.php":2415016804,"src\/Console\/Commands\/Messages\/Resources\/RealEstateDevelopmentMessageProcessor.php":3695817550,"src\/SpProduto.php":1373773954,"src\/Factories\/InsuranceFactory.php":221116077,"src\/Factories\/CharacteristicFactory.php":4225836177,"src\/Factories\/ProposalModelPeriodicitiesFactory.php":4148958876,"src\/Factories\/RealEstateDevelopment\/UnitFactory.php":3036647583,"src\/Factories\/RealEstateDevelopment\/AccessoryCategoryFactory.php":223590253,"src\/Factories\/RealEstateDevelopment\/CharacteristicFactory.php":3165326083,"src\/Factories\/RealEstateDevelopment\/MirrorGroupFactory.php":3420126937,"src\/Factories\/RealEstateDevelopment\/MediaFactory.php":1703379055,"src\/Factories\/RealEstateDevelopment\/BlueprintImageFactory.php":3000012332,"src\/Factories\/RealEstateDevelopment\/TypologyFactory.php":503975900,"src\/Factories\/RealEstateDevelopment\/MirrorFactory.php":378700581,"src\/Factories\/RealEstateDevelopment\/ParameterFactory.php":4224983121,"src\/Factories\/RealEstateDevelopment\/TypologyAttributeFactory.php":3382699342,"src\/Factories\/RealEstateDevelopment\/StageFactory.php":3767542198,"src\/Factories\/RealEstateDevelopment\/BlueprintFactory.php":3482799680,"src\/Factories\/RealEstateDevelopment\/DocumentFactory.php":3966933834,"src\/Factories\/RealEstateDevelopment\/StageImageFactory.php":3117213135,"src\/Factories\/RealEstateDevelopment\/AccessoryFactory.php":1275094816,"src\/Factories\/ProposalModelFactory.php":288424814,"src\/Factories\/InsuranceCompanyFactory.php":3556368754,"src\/Factories\/CategoryFactory.php":177862944,"src\/Factories\/BuyingOptionFactory.php":3917826764,"src\/Factories\/RealEstateDevelopmentFactory.php":272098174,"src\/Factories\/AccessoryFactory.php":2955784286,"src\/SpProdutoFacade.php":2927652880,"src\/Models\/AccessoryCategory.php":2675207546,"src\/Models\/BuyingOption.php":414476952,"src\/Models\/ProposalModelPeriodicities.php":1756212288,"src\/Models\/ProposalModel.php":2452794167,"src\/Models\/RealEstateDevelopment\/Media.php":77762344,"src\/Models\/RealEstateDevelopment\/MirrorGroup.php":2354200828,"src\/Models\/RealEstateDevelopment\/StageImage.php":608757471,"src\/Models\/RealEstateDevelopment\/Stage.php":3482482097,"src\/Models\/RealEstateDevelopment\/Mirror.php":3855065,"src\/Models\/RealEstateDevelopment\/Document.php":3375310612,"src\/Models\/RealEstateDevelopment\/Blueprint.php":2685043986,"src\/Models\/RealEstateDevelopment\/BlueprintImage.php":3814320200,"src\/Models\/RealEstateDevelopment\/Accessory.php":3303253254,"src\/Models\/RealEstateDevelopment\/Unit.php":781516100,"src\/Models\/RealEstateDevelopment\/Typology.php":3636316477,"src\/Models\/RealEstateDevelopment\/Characteristic.php":4053363417,"src\/Models\/RealEstateDevelopment\/TypologyAttribute.php":493102300,"src\/Models\/RealEstateDevelopment\/Parameter.php":3533877004,"src\/Models\/InsuranceCompany.php":124430619,"src\/Models\/Accessory.php":2774108451,"src\/Models\/BaseModel.php":4191027036,"src\/Models\/Characteristic.php":2240826723,"src\/Models\/Insurance.php":2542292983,"src\/Models\/RealEstateDevelopment.php":1521370194,"src\/SpProdutoServiceProvider.php":311940593,"tests\/TestCase.php":2006129264,"tests\/ExampleTest.php":1981190735,"config\/sp-produto.php":2209096954}} \ No newline at end of file diff --git a/src/helpers.php b/src/helpers.php index 9b23fbe..982e9a2 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,7 +1,6 @@