-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
396 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/Actions/Fulfilment/Fulfilment/Hydrators/FulfilmentHydrateCustomers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/* | ||
* Author: Raul Perusquia <raul@inikoo.com> | ||
* Created: Tue, 14 May 2024 15:19:54 British Summer Time, Sheffield, UK | ||
* Copyright (c) 2024, Raul A Perusquia Flores | ||
*/ | ||
|
||
namespace App\Actions\Fulfilment\Fulfilment\Hydrators; | ||
|
||
use App\Actions\Traits\WithEnumStats; | ||
use App\Enums\Fulfilment\FulfilmentCustomer\FulfilmentCustomerStatus; | ||
use App\Models\Fulfilment\Fulfilment; | ||
use App\Models\Fulfilment\FulfilmentCustomer; | ||
use Illuminate\Queue\Middleware\WithoutOverlapping; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class FulfilmentHydrateCustomers | ||
{ | ||
use AsAction; | ||
use WithEnumStats; | ||
|
||
|
||
private Fulfilment $fulfilment; | ||
|
||
public function __construct(Fulfilment $fulfilment) | ||
{ | ||
$this->fulfilment = $fulfilment; | ||
} | ||
|
||
public function getJobMiddleware(): array | ||
{ | ||
return [(new WithoutOverlapping($this->fulfilment->id))->dontRelease()]; | ||
} | ||
|
||
|
||
public function handle(Fulfilment $fulfilment): void | ||
{ | ||
$stats = [ | ||
'number_customers_interest_pallets_storage' => $fulfilment->fulfilmentCustomers()->where('pallets_storage', true)->count(), | ||
'number_customers_interest_items_storage' => $fulfilment->fulfilmentCustomers()->where('items_storage', true)->count(), | ||
'number_customers_interest_dropshipping' => $fulfilment->fulfilmentCustomers()->where('dropshipping', true)->count(), | ||
|
||
]; | ||
|
||
$stats=array_merge($stats, $this->getEnumStats( | ||
model:'customers', | ||
field: 'status', | ||
enum: FulfilmentCustomerStatus::class, | ||
models: FulfilmentCustomer::class, | ||
where: function ($q) use ($fulfilment) { | ||
$q->where('fulfilment_id', $fulfilment->id); | ||
} | ||
)); | ||
|
||
$fulfilment->stats()->update($stats); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/Actions/Fulfilment/FulfilmentCustomer/Hydrators/FulfilmentCustomerHydrateStatus.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/* | ||
* Author: Raul Perusquia <raul@inikoo.com> | ||
* Created: Tue, 14 May 2024 15:19:54 British Summer Time, Sheffield, UK | ||
* Copyright (c) 2024, Raul A Perusquia Flores | ||
*/ | ||
|
||
namespace App\Actions\Fulfilment\FulfilmentCustomer\Hydrators; | ||
|
||
use App\Actions\Traits\WithEnumStats; | ||
use App\Enums\Fulfilment\FulfilmentCustomer\FulfilmentCustomerStatus; | ||
use App\Enums\Fulfilment\RentalAgreement\RentalAgreementStateEnum; | ||
use App\Models\Fulfilment\FulfilmentCustomer; | ||
use Illuminate\Queue\Middleware\WithoutOverlapping; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class FulfilmentCustomerHydrateStatus | ||
{ | ||
use AsAction; | ||
use WithEnumStats; | ||
|
||
private FulfilmentCustomer $fulfilmentCustomer; | ||
|
||
public function __construct(FulfilmentCustomer $fulfilmentCustomer) | ||
{ | ||
$this->fulfilmentCustomer = $fulfilmentCustomer; | ||
} | ||
|
||
public function getJobMiddleware(): array | ||
{ | ||
return [(new WithoutOverlapping($this->fulfilmentCustomer->id))->dontRelease()]; | ||
} | ||
|
||
public function handle(FulfilmentCustomer $fulfilmentCustomer): void | ||
{ | ||
$status = FulfilmentCustomerStatus::NO_RENTAL_AGREEMENT; | ||
|
||
if ($fulfilmentCustomer->rentalAgreement) { | ||
if ($fulfilmentCustomer->rentalAgreement->state == RentalAgreementStateEnum::ACTIVE) { | ||
$status = FulfilmentCustomerStatus::ACTIVE; | ||
|
||
} elseif ($fulfilmentCustomer->rentalAgreement->state == RentalAgreementStateEnum::EXPIRED) { | ||
$status = FulfilmentCustomerStatus::LOST; | ||
} | ||
} | ||
$fulfilmentCustomer->update( | ||
['status' => $status] | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.