diff --git a/.env.example b/.env.example
index 91c8e15c..d48eeb79 100644
--- a/.env.example
+++ b/.env.example
@@ -61,3 +61,5 @@ BILLPLZ_WALLET_COLLECTION_ID="t0cggbdd"
PERFEXCRM_BASE_URL=""
PERFEXCRM_API_KEY=""
PERFEXCRM_IS_ENABLED="false"
+
+HONEY_TRAP_SEGMENT_ID='false' # set HONEY_TRAP_SEGMENT_ID
diff --git a/app/Classes/General/Eloquent/Filters/WhereHasSeasonalSegment.php b/app/Classes/General/Eloquent/Filters/WhereHasSeasonalSegment.php
new file mode 100644
index 00000000..78905650
--- /dev/null
+++ b/app/Classes/General/Eloquent/Filters/WhereHasSeasonalSegment.php
@@ -0,0 +1,20 @@
+whereHas('seasonalSegments');
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php
index 17a6c900..97fcb193 100644
--- a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php
+++ b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php
@@ -6,7 +6,11 @@ namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
use App\Classes\Modules\Companies\Services\FetchesCompany;
+use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject;
+use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment;
use App\Http\Resources\CompanyResource;
+use App\Models\SeasonalSegment;
+use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -29,15 +33,20 @@ class AssignCompanyToSegmentLogic extends AbstractControllerLogic
/** @var AssignSegmentProcessor */
private $assignCompanyToSegmentProcessor;
+ /** @var CreatesSeasonalSegment */
+ private $createsSeasonalSegment;
+
/**
* AssignCompanyToSegmentLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param AssignSegmentProcessor $assignCompanyToSegmentProcessor
+ * @param CreatesSeasonalSegment $createsSeasonalSegment
*/
- public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor)
+ public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor, CreatesSeasonalSegment $createsSeasonalSegment)
{
$this->fetchesCompany = $fetchesCompany;
$this->assignCompanyToSegmentProcessor = $assignCompanyToSegmentProcessor;
+ $this->createsSeasonalSegment = $createsSeasonalSegment;
}
/**
@@ -54,6 +63,16 @@ 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')) {
+ $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');
+
+ $this->createsSeasonalSegment->execute($seasonalSegmentObject);
+ } else {
+ dd('d');
+ }
+
return $this->resourceResponse(new CompanyResource($company));
}
}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php
new file mode 100644
index 00000000..5911a384
--- /dev/null
+++ b/app/Classes/Modules/Segments/DataTransferObjects/SeasonalSegmentObject.php
@@ -0,0 +1,74 @@
+$companyId = $companyId;
+ $this->segmentId = $segmentId;
+ $this->starting_on = $starting_on;
+ $this->ending_on = $ending_on;
+ $this->status = $status;
+ }
+
+ /**
+ * @return int
+ */
+ public function getCompanyId(): int
+ {
+ return $this->companyId;
+ }
+
+ /**
+ * @return int
+ */
+ public function getSegmentId(): int
+ {
+ return $this->segmentId;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getStartingOn(): string
+ {
+ return $this->starting_on;
+ }
+
+ /**
+ * @return string
+ */
+ public function getEndingOn(): string
+ {
+ return $this->ending_on;
+ }
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php b/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php
new file mode 100644
index 00000000..dc6fdb49
--- /dev/null
+++ b/app/Classes/Modules/Segments/Services/CreatesSeasonalSegment.php
@@ -0,0 +1,27 @@
+company_id = $object->getSegmentId();
+ $model->segment_id = $object->getSegmentId();
+ $model->starting_on = $object->getStartingOn();
+ $model->ending_on = $object->getEndingOn();
+
+ return $this->handler($model);
+
+ }
+}
\ No newline at end of file
diff --git a/app/Console/Commands/RemoveSeasonalSegmentCompany.php b/app/Console/Commands/RemoveSeasonalSegmentCompany.php
new file mode 100644
index 00000000..fd71d891
--- /dev/null
+++ b/app/Console/Commands/RemoveSeasonalSegmentCompany.php
@@ -0,0 +1,48 @@
+count();
+
+ SeasonalSegment::where('ending_on', '<=', Carbon::today())->delete();
+
+ $this->info(Carbon::now() . ' : Done soft delete on seasonal segment company. Total Deleted: ' . $count);
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 8edaaa22..baf9a4cc 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -34,6 +34,10 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')->hourly();
$schedule->command('mail:EmailDoToVTCommand')->dailyAt('10:00')->withoutOverlapping();
+ $schedule->command('seasonalSegmantCompany:remove')
+ ->hourly()
+ ->appendOutputTo (storage_path().'/logs/soft-delete-seasonal-segmant-company.log')
+ ->withoutOverlapping();
}
/**
diff --git a/app/Models/Company.php b/app/Models/Company.php
index def72720..8b2e6081 100644
--- a/app/Models/Company.php
+++ b/app/Models/Company.php
@@ -62,6 +62,14 @@ class Company extends AbstractModel implements Documentable
return $this->belongsToMany(Segment::class, (new SegmentCompany())->getTable(), 'company_id', 'segment_id');
}
+ /**
+ * @return belongsToMany
+ */
+ public function seasonalSegments()
+ {
+ return $this->hasMany(SeasonalSegment::class);
+ }
+
/**
* @return belongsToMany
*/
diff --git a/app/Models/SeasonalSegment.php b/app/Models/SeasonalSegment.php
new file mode 100644
index 00000000..30bb1796
--- /dev/null
+++ b/app/Models/SeasonalSegment.php
@@ -0,0 +1,48 @@
+BelongsTo(Company::class, 'company_id', 'id');
+ }
+
+ public function segment()
+ {
+ return $this->belongsTo(Segment::class);
+ }
+}
diff --git a/database/migrations/2023_03_16_223623_seasonal_segment_table.php b/database/migrations/2023_03_16_223623_seasonal_segment_table.php
new file mode 100644
index 00000000..4b804086
--- /dev/null
+++ b/database/migrations/2023_03_16_223623_seasonal_segment_table.php
@@ -0,0 +1,41 @@
+id();
+ $table->foreignId('company_id')->unsigned();
+ $table->string('status')->default(ApprovalStatus::APPROVED);
+ $table->foreignId('segment_id')->unsigned();
+ $table->timestamp('starting_on')->nullable();
+ $table->timestamp('ending_on')->nullable();
+ $table->softDeletes();
+ $table->timestamps();
+
+ $table->foreign('segment_id')->references('id')->on('segments');
+ $table->foreign('company_id')->references('id')->on('companies');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ }
+}
diff --git a/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue b/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue
new file mode 100644
index 00000000..06726269
--- /dev/null
+++ b/resources/assets/vue/components/companies/elements/SeasonalSegmentComponent.vue
@@ -0,0 +1,47 @@
+
+
Please leave End Date empty if the end date is not confirmed or there is no end date.
+