diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyInfoObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyInfoObject.php new file mode 100644 index 00000000..2fd3546e --- /dev/null +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyInfoObject.php @@ -0,0 +1,120 @@ +company = $company; + $this->unifiedSocialCreditIdentifier = $unifiedSocialCreditIdentifier; + $this->businessRegistrationNumber = $businessRegistrationNumber; + $this->type = $type; + $this->legalRepresentative = $legalRepresentative; + $this->lastYearInspection = $lastYearInspection; + $this->dateEstablishment = $dateEstablishment; + $this->operationPeriod = $operationPeriod; + } + + /** + * @return Company + */ + public function getCompany(): Company + { + return $this->company; + } + + /** + * @return string + */ + public function getUnifiedSocialCreditIdentifier(): string + { + return $this->unifiedSocialCreditIdentifier; + } + + /** + * @return string + */ + public function getBusinessRegistrationNumber(): string + { + return $this->businessRegistrationNumber; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return string + */ + public function getLegalRepresentative(): string + { + return $this->legalRepresentative; + } + + /** + * @return string + */ + public function getLastYearInspection(): string + { + return $this->lastYearInspection; + } + + /** + * @return string + */ + public function getDateOfEstablishment(): string + { + return $this->dateEstablishment; + } + + /** + * @return string + */ + public function getOperationPeriod(): string + { + return $this->operationPeriod; + } +} diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyInfoProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyInfoProcessor.php new file mode 100644 index 00000000..bf7af606 --- /dev/null +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyInfoProcessor.php @@ -0,0 +1,58 @@ +canCreateCompanyInfo = $canCreateCompanyInfo; + $this->createsCompanyInfo = $createsCompanyInfo; + } + + /** + * @param Company $company + * @param Request $request + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Company $company, Request $request): Model + { + $companyInfo_object = new CompanyInfoObject( + $company, + $request->input('unified_social_credit_identifier'), + $request->input('business_registration_number'), + $request->input('type'), + $request->input('legal_representative'), + $request->input('last_year_of_inspection'), + $request->input('date_of_establishment'), + $request->input('operation_period') + ); + + $this->canCreateCompanyInfo->passes($companyInfo_object); + + $companyInfo = $this->createsCompanyInfo->execute($companyInfo_object); + + return $companyInfo; + } +} diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php index ad9abeb8..e4b5f321 100644 --- a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php @@ -14,25 +14,28 @@ use Illuminate\Database\Eloquent\Model; class CreateCompanyProcessor { - /** @var CanCreateCompany */ private $canCreateCompany; /** @var CreatesCompany */ private $createsCompany; + /** @var CreateCompanyInfoProcessor */ + private $createCompanyInfoProcessor; + /** * CreateUserProcessor constructor. * @param CanCreateCompany $canCreateCompany * @param CreatesCompany $createsCompany + * @param CreateCompanyInfoProcessor $createsCompanyInfoProcessor */ - public function __construct(CanCreateCompany $canCreateCompany, CreatesCompany $createsCompany) + public function __construct(CanCreateCompany $canCreateCompany, CreatesCompany $createsCompany, CreateCompanyInfoProcessor $createCompanyInfoProcessor) { $this->canCreateCompany = $canCreateCompany; $this->createsCompany = $createsCompany; + $this->createCompanyInfoProcessor = $createCompanyInfoProcessor; } - /** * @param Request $request * @param int $businessType @@ -50,11 +53,20 @@ class CreateCompanyProcessor $company_object = new CompanyObject( $companyName, $companyReference, - $businessType, $companyType, $status); + $businessType, + $companyType, + $status); $this->canCreateCompany->passes($company_object); - return $this->createsCompany->execute($company_object); + $company = $this->createsCompany->execute($company_object); + + if($businessType == BusinessType::ONLINE_SHOP) + { + $this->createCompanyInfoProcessor->execute($company, $request); + } + + return $company; } diff --git a/app/Classes/Modules/Companies/Services/CreatesCompanyInfo.php b/app/Classes/Modules/Companies/Services/CreatesCompanyInfo.php new file mode 100644 index 00000000..2611827a --- /dev/null +++ b/app/Classes/Modules/Companies/Services/CreatesCompanyInfo.php @@ -0,0 +1,31 @@ +company_id = $object->getCompany()->id; + $model->unified_social_credit_identifier = $object->getUnifiedSocialCreditIdentifier(); + $model->business_registration_number = $object->getBusinessRegistrationNumber(); + $model->type = $object->getType(); + $model->legal_representative = $object->getLegalRepresentative(); + $model->last_year_of_inspection = $object->getLastYearInspection(); + $model->date_of_establishment = $object->getDateOfEstablishment(); + $model->operation_period = $object->getOperationPeriod(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompanyInfo.php b/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompanyInfo.php new file mode 100644 index 00000000..894ac149 --- /dev/null +++ b/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompanyInfo.php @@ -0,0 +1,50 @@ +companyInfoValidation = $companyInfoValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CompanyInfoObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->companyInfoValidation->validate($object); + } + + /** + * @param CompanyInfoObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyInfoValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyInfoValidation.php new file mode 100644 index 00000000..b5935eb0 --- /dev/null +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyInfoValidation.php @@ -0,0 +1,66 @@ + $object->getCompany()->id, + 'unified_social_credit_identifier' => $object->getUnifiedSocialCreditIdentifier(), + 'business_registration_number' => $object->getBusinessRegistrationNumber(), + 'type' => $object->getType(), + 'legal_representative' => $object->getLegalRepresentative(), + 'last_year_of_inspection' => $object->getLastYearInspection(), + 'date_of_establishment' => $object->getDateOfEstablishment(), + 'operation_period' => $object->getOperationPeriod() + ]; + } + + /** + * @param string $type + * @return array + */ + protected function rules(?string $type = 'POST'): array + { + if ($type == 'POST') { + return [ + 'company_id' => 'required', + 'unified_social_credit_identifier' => 'required', + 'business_registration_number' => 'required', + 'type' => 'required', + 'legal_representative' => 'required', + 'last_year_of_inspection' => 'required', + 'date_of_establishment' => 'required|date', + 'operation_period' => 'required' + ]; + } + elseif($type == 'PUT') { + return [ + 'unified_social_credit_identifier' => 'required', + 'business_registration_number' => 'required', + 'type' => 'required', + 'legal_representative' => 'required', + 'last_year_of_inspection' => 'required', + 'date_of_establishment' => 'required|date', + 'operation_period' => 'required' + ]; + } + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/CompanyHistory.php b/app/Classes/ValueObjects/Constants/CompanyHistory.php new file mode 100644 index 00000000..57dd3269 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/CompanyHistory.php @@ -0,0 +1,11 @@ + $this->unified_social_credit_identifier, + 'business_registration_number' => $this->business_registration_number, + 'type' => $this->type, + 'legal_representative' => $this->legal_representative, + 'last_year_of_inspection' => $this->last_year_of_inspection, + 'date_of_establishment' => $this->date_of_establishment, + 'operation_period' => $this->operation_period, + 'history' => $this->history, + 'security' => $this->security + ]; + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index fceab5bc..ffd2421c 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -66,6 +66,9 @@ class CompanyResource extends JsonResource $this->mergeWhen($this->business_type === BusinessType::CURRENCY_VENDOR, [ 'currencies' => $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : [], 'service_charge' => $serviceCharge + ]), + $this->mergeWhen($this->business_type === BusinessType::ONLINE_SHOP, [ + 'company_infos' => new CompanyInfoResource($this->infos) ]) ]; diff --git a/app/Models/Company.php b/app/Models/Company.php index def72720..43e26566 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -1,6 +1,7 @@ HasOne(CompanyInfo::class, 'company_id'); + } /** * @return HasMany @@ -67,7 +76,7 @@ class Company extends AbstractModel implements Documentable */ public function employees(): belongsToMany { - return $this->belongsToMany(User::class, (new Employee())->getTable(), 'company_id','user_id'); + return $this->belongsToMany(User::class, (new Employee())->getTable(), 'company_id', 'user_id'); } /** @@ -101,7 +110,7 @@ class Company extends AbstractModel implements Documentable { return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']); } - + /** * @return HasMany */ @@ -121,25 +130,25 @@ class Company extends AbstractModel implements Documentable /** * @return Builder */ - public function services(): Builder { - return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { - $query->Where(function($query){ + public function services(): Builder + { + return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function ($query) { + $query->Where(function ($query) { $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); - })->orWhere(function($query) { + })->orWhere(function ($query) { $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id')); }); }); } - public function servicesConfigurations(): Collection { - return $this->services()->get()->map(function($service) { - return new ServiceConfigurationsObject($service, + public function servicesConfigurations(): Collection + { + return $this->services()->get()->map(function ($service) { + return new ServiceConfigurationsObject( + $service, $service->constants->where('reference', SegmentConstants::SERVICE_TYPE)->first(), - $service->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->whereIn('segment_id', $this->segments->pluck('id'))); + $service->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->whereIn('segment_id', $this->segments->pluck('id')) + ); }); } - } - - - diff --git a/app/Models/CompanyInfo.php b/app/Models/CompanyInfo.php new file mode 100644 index 00000000..0e2b09f6 --- /dev/null +++ b/app/Models/CompanyInfo.php @@ -0,0 +1,24 @@ +belongsTo(Company::class, 'company_id', 'id'); + } +} diff --git a/database/migrations/2022_05_14_185154_create_company_infos_table.php b/database/migrations/2022_05_14_185154_create_company_infos_table.php new file mode 100644 index 00000000..0afdaffe --- /dev/null +++ b/database/migrations/2022_05_14_185154_create_company_infos_table.php @@ -0,0 +1,43 @@ +id(); + $table->foreignId('company_id')->unsigned(); + $table->foreign('company_id')->references('id')->on('companies'); + $table->string('unified_social_credit_identifier'); + $table->string('business_registration_number'); + $table->string('type'); + $table->string('legal_representative'); + $table->string('last_year_of_inspection'); + $table->date('date_of_establishment'); + $table->string('operation_period'); + $table->boolean('history')->comment('check if have bad record')->default(CompanyHistory::NOBADRECORD); + $table->string('security')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('company_infos'); + } +}