From 584819a51347b2a7141ff820f001aa1f59d381e4 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 20 Mar 2023 10:12:47 +0800 Subject: [PATCH] honey trap update --- .../AssignCompanyToSegmentLogic.php | 14 +++-- .../RemoveCompanyFromSegmentLogic.php | 6 +-- .../Commands/RemoveSeasonalSegmentCompany.php | 18 +++++-- app/Http/Resources/CompanyResource.php | 1 + .../Resources/SeasonalSegmentResource.php | 37 +++++++++++++ .../elements/SeasonalSegmentComponent.vue | 52 +++++++++++++------ 6 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 app/Http/Resources/SeasonalSegmentResource.php diff --git a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php index b02b3d5a..56ccfc00 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic; - +use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor; use App\Classes\Modules\Companies\Services\FetchesCompany; @@ -63,19 +63,17 @@ 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')) { + if ($request->input('ending_on')) { - // todo-new - // if (isset($request->input('ending_on')) && $request->input('ending_on') <= Carbon::now()) { - // return error - // } + if ($request->input('ending_on') && $request->input('ending_on') <= Carbon::now()) { + throw new MalformedRequestException('The Ending Date must be equal to or later than today\'s date.'); + } // todo-new // if (count($company->seasonalSegments)) { - // return error + // throw new MalformedRequestException('System error. Please contact admin.'); // } - $start_date = $request->input('starting_on') ? $request->input('starting_on') : Carbon::now(); $seasonalSegmentObject = new SeasonalSegmentObject($company->id, $request->input('segment_id'), $start_date, $request->input('ending_on') ?? null); diff --git a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php index 66915574..fa08ff55 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php @@ -56,11 +56,9 @@ class RemoveCompanyFromSegmentLogic extends AbstractControllerLogic $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(); - } + $company->seasonalSegments()->where('id', $request->route('segment_id'))->delete(); + $this->removesCompanyFromSegment->execute($company, $segment); return $this->resourceResponse(new CompanyResource($company)); diff --git a/app/Console/Commands/RemoveSeasonalSegmentCompany.php b/app/Console/Commands/RemoveSeasonalSegmentCompany.php index eb739df2..b28a9b67 100644 --- a/app/Console/Commands/RemoveSeasonalSegmentCompany.php +++ b/app/Console/Commands/RemoveSeasonalSegmentCompany.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Models\SeasonalSegment; use Illuminate\Console\Command; use Carbon\Carbon; +use App\Classes\Modules\Companies\Services\RemovesCompanyFromSegment; class RemoveSeasonalSegmentCompany extends Command { @@ -22,14 +23,18 @@ class RemoveSeasonalSegmentCompany extends Command */ protected $description = 'Perform soft delete on Seasonal Segment Company'; + /** @var RemovesCompanyFromSegment */ + private $removesCompanyFromSegment; + /** * Create a new command instance. * * @return void */ - public function __construct() + public function __construct(RemovesCompanyFromSegment $removesCompanyFromSegment) { parent::__construct(); + $this->removesCompanyFromSegment = $removesCompanyFromSegment; } /** @@ -39,12 +44,15 @@ class RemoveSeasonalSegmentCompany extends Command */ public function handle() { - $count = SeasonalSegment::where('ending_on', '<=', Carbon::today())->count(); + $seasonalSegment = SeasonalSegment::where('ending_on', '<=', Carbon::today())->get(); - SeasonalSegment::where('ending_on', '<=', Carbon::today())->delete(); + if (count($seasonalSegment)){ + $this->info(Carbon::now() . ' : Total Deleted: ' . count($seasonalSegment)); - if ($count){ - $this->info(Carbon::now() . ' : Total Deleted: ' . $count); + foreach ($seasonalSegment as $seasonalSegmentCompany) { + $this->removesCompanyFromSegment->execute($seasonalSegmentCompany->company, $seasonalSegmentCompany->segment); + $seasonalSegmentCompany->delete(); + } } } } diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 6d7cb2e4..85ecee16 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -61,6 +61,7 @@ class CompanyResource extends JsonResource 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => SegmentResource::collection($this->segments), + 'seasonalSegment' => $this->whenLoaded('seasonalSegments', SeasonalSegmentResource::collection($this->seasonalSegments)), 'services' => (new FetchesCompanyServices())->getServices($this->servicesConfigurations()), 'wallet' => $this->whenLoaded('wallets', new WalletResource($this->wallets()->with('transactions')->first()), new WalletResource($this->wallets()->first())), 'created_at' => $this->created_at->format('d-m-Y'), diff --git a/app/Http/Resources/SeasonalSegmentResource.php b/app/Http/Resources/SeasonalSegmentResource.php new file mode 100644 index 00000000..8a38f5be --- /dev/null +++ b/app/Http/Resources/SeasonalSegmentResource.php @@ -0,0 +1,37 @@ + $this->id, + 'segment_name' => ucwords($this->segment->name), + 'ending_on' => $this->ending_on->format('d-m-Y'), + ]; + } +} diff --git a/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue b/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue index 06726269..4e3dad78 100644 --- a/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue +++ b/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue @@ -10,30 +10,52 @@ style=" fill:#000000;"> -
-
-
-
Name
-
-
+
-
{{item.name}} - {{item.reference}}
+
+
+
Name
+
+
+
+
+
{{item.name}}
+
+
+
+
+
+
+
Marking
+
+
+
- +
+
+
{{ segment.segment_name }}
+
+
+
{{ segment.ending_on }}
+
+
+