diff --git a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php index 942cde3a..b02b3d5a 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php @@ -64,9 +64,21 @@ class AssignCompanyToSegmentLogic extends AbstractControllerLogic $this->assignCompanyToSegmentProcessor->execute($company, $request->input('segment_id')); if (env('HONEY_TRAP_SEGMENT_ID') && env('HONEY_TRAP_SEGMENT_ID') == $request->input('segment_id')) { + + // todo-new + // if (isset($request->input('ending_on')) && $request->input('ending_on') <= Carbon::now()) { + // return error + // } + + // todo-new + // if (count($company->seasonalSegments)) { + // return error + // } + + $start_date = $request->input('starting_on') ? $request->input('starting_on') : Carbon::now(); - $seasonalSegmentObject = new SeasonalSegmentObject($request->route('id'), $request->input('segment_id'), $start_date, $request->input('ending_on')); - // $seasonalSegmentObject = new SeasonalSegmentObject((int)$request->route('id'), $request->input('segment_id'), '01-01-2022', '01-01-2022'); + + $seasonalSegmentObject = new SeasonalSegmentObject($company->id, $request->input('segment_id'), $start_date, $request->input('ending_on') ?? null); $this->createsSeasonalSegment->execute($seasonalSegmentObject); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php index 10623311..66915574 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php @@ -53,10 +53,13 @@ class RemoveCompanyFromSegmentLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); $segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]); + + if (env('HONEY_TRAP_SEGMENT_ID') && env('HONEY_TRAP_SEGMENT_ID') == $request->route('segment_id')) { + $company->seasonalSegments->first()->delete(); + } $this->removesCompanyFromSegment->execute($company, $segment); diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php index 5911a384..d045556e 100644 --- a/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php +++ b/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php @@ -30,9 +30,9 @@ class SeasonalSegmentObject implements DataTransferObject * @param string $starting_on * @param string $ending_on */ - public function __construct(int $companyId, int $segmentId, string $starting_on, string $ending_on, ?int $status = ApprovalStatus::APPROVED) + public function __construct(int $companyId, int $segmentId, string $starting_on, ?string $ending_on = null, ?int $status = ApprovalStatus::APPROVED) { - $this->$companyId = $companyId; + $this->companyId = $companyId; $this->segmentId = $segmentId; $this->starting_on = $starting_on; $this->ending_on = $ending_on; @@ -67,7 +67,7 @@ class SeasonalSegmentObject implements DataTransferObject /** * @return string */ - public function getEndingOn(): string + public function getEndingOn(): ?string { return $this->ending_on; } diff --git a/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php b/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php index dc6fdb49..0125a956 100644 --- a/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php +++ b/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php @@ -16,7 +16,7 @@ class CreatesSeasonalSegment extends AbstractUpdateRecord */ public function execute(SeasonalSegmentObject $object) { $model = new SeasonalSegment(); - $model->company_id = $object->getSegmentId(); + $model->company_id = $object->getCompanyId(); $model->segment_id = $object->getSegmentId(); $model->starting_on = $object->getStartingOn(); $model->ending_on = $object->getEndingOn();