Skip to content

Commit

Permalink
#131 Fetch Aurora Rentals
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Apr 25, 2024
1 parent 9f48c1d commit 0b9ecb3
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 79 deletions.
49 changes: 19 additions & 30 deletions app/Actions/Fulfilment/Fulfilment/UI/IndexFulfilmentRentals.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,25 @@

class IndexFulfilmentRentals extends OrgAction
{
// protected function getElementGroups(Fulfilment $parent): array
// {
//
// return [
// 'type' => [
// 'label' => __('Type'),
// 'elements' => array_merge_recursive(
// RentalStateEnum::labels($parent->shop),
// RentalStateEnum::count($parent->shop)
// ),
//
// 'engine' => function ($query, $elements) {
// $query->whereIn('type', $elements);
// }
//
// ],
// 'state' => [
// 'label' => __('State'),
// 'elements' => array_merge_recursive(
// rentalstateEnum::labels(),
// rentalstateEnum::count($parent->shop)
// ),
//
// 'engine' => function ($query, $elements) {
// $query->whereIn('state', $elements);
// }
//
// ],
// ];
// }
protected function getElementGroups(Fulfilment $parent): array
{

return [

'state' => [
'label' => __('State'),
'elements' => array_merge_recursive(
RentalStateEnum::labels(),
RentalStateEnum::count($parent->shop)
),

'engine' => function ($query, $elements) {
$query->whereIn('state', $elements);
}

],
];
}

public function handle(Fulfilment $parent, $prefix = null): LengthAwarePaginator
{
Expand Down
28 changes: 14 additions & 14 deletions app/Actions/Market/Product/StoreRentalProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,42 @@ class StoreRentalProduct extends OrgAction
{
use IsStoreProduct;

private RentalStateEnum|null $state=null;
private RentalStateEnum|null $state = null;
private ProductCategory|Shop $parent;

public function handle(Shop|ProductCategory $parent, array $modelData): Product
{

$modelData=$this->setDataFromParent($parent, $modelData);
$modelData = $this->setDataFromParent($parent, $modelData);

data_set($modelData, 'unit_relationship_type', ProductUnitRelationshipType::TIME_INTERVAL->value);
data_set($modelData, 'outerable_type', 'Rental');


$productData=$modelData;
$productData = $modelData;

data_set(
$productData,
'state',
match(Arr::get($modelData, 'state')) {
RentalStateEnum::IN_PROCESS => ProductStateEnum::IN_PROCESS,
RentalStateEnum::ACTIVE => ProductStateEnum::ACTIVE,
RentalStateEnum::DISCONTINUED=> ProductStateEnum::DISCONTINUED,
match (Arr::get($modelData, 'state')) {
RentalStateEnum::IN_PROCESS => ProductStateEnum::IN_PROCESS,
RentalStateEnum::ACTIVE => ProductStateEnum::ACTIVE,
RentalStateEnum::DISCONTINUED => ProductStateEnum::DISCONTINUED,
}
);

/** @var Product $product */
$product = $parent->products()->create($productData);
$product = $parent->products()->create(Arr::except($productData, ['auto_assign_asset', 'auto_assign_asset_type']));
$product->stats()->create();


$price=Arr::get($modelData, 'price');
$price = Arr::get($modelData, 'price');
data_forget($modelData, 'price');
data_set($modelData, 'price', $price);



StoreRental::make()->action($product, $modelData);



ShopHydrateProducts::dispatch($product->shop);
OrganisationHydrateProducts::dispatch($product->organisation);
GroupHydrateProducts::dispatch($product->group);
Expand All @@ -82,7 +79,10 @@ public function rules(): array
return array_merge(
$this->getProductRules(),
[
'state' => ['required', Rule::enum(RentalStateEnum::class)],
'state' => ['required', Rule::enum(RentalStateEnum::class)],
'auto_assign_asset' => ['nullable', 'string', 'in:Pallet,StoredItem'],
'auto_assign_asset_type' => ['nullable', 'string', 'in:pallet,box,oversize'],

]
);
}
Expand All @@ -92,7 +92,7 @@ public function prepareForValidation(ActionRequest $request): void
$this->set('type', ProductTypeEnum::RENTAL);

$this->prepareProductForValidation();
if(!$this->has('state')) {
if (!$this->has('state')) {
$this->set('state', RentalStateEnum::IN_PROCESS);
}
}
Expand Down
12 changes: 7 additions & 5 deletions app/Actions/Market/Rental/StoreRental.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ public function handle(Product $product, array $modelData): Rental
public function rules(): array
{
return [
'status' => ['required', 'boolean'],
'state' => ['required', Rule::enum(RentalStateEnum::class)],
'data' => ['sometimes', 'array'],
'created_at' => ['sometimes', 'date'],
'source_id' => ['sometimes','string','max:63']
'status' => ['required', 'boolean'],
'state' => ['required', Rule::enum(RentalStateEnum::class)],
'data' => ['sometimes', 'array'],
'created_at' => ['sometimes', 'date'],
'source_id' => ['sometimes','string','max:63'],
'auto_assign_asset' => ['nullable', 'string', 'in:Pallet,StoredItem'],
'auto_assign_asset_type' => ['nullable', 'string', 'in:pallet,box,oversize'],

];

Expand Down
82 changes: 52 additions & 30 deletions app/Services/Organisation/Aurora/FetchAuroraService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace App\Services\Organisation\Aurora;

use App\Enums\Fulfilment\Pallet\PalletTypeEnum;
use App\Enums\Market\Product\ProductStateEnum;
use App\Enums\Market\Product\ProductTypeEnum;
use App\Enums\Market\Rental\RentalStateEnum;
Expand All @@ -21,13 +22,14 @@ protected function parseModel(): void
return;
}

$this->parsedData['shop'] = $this->parseShop($this->organisation->id.':'.$this->auroraModelData->{'Product Store Key'});
$this->parsedData['shop'] = $this->parseShop(
$this->organisation->id . ':' . $this->auroraModelData->{'Product Store Key'}
);

$data = [];
$settings = [];



if ($this->auroraModelData->{'Product Valid From'} == '0000-00-00 00:00:00') {
$created_at = null;
} else {
Expand All @@ -44,50 +46,69 @@ protected function parseModel(): void

$code = $this->cleanTradeUnitReference($this->auroraModelData->{'Product Code'});

$type= ProductTypeEnum::SERVICE;
if(preg_match('/rent/i', $code)) {
$type= ProductTypeEnum::RENTAL;
$type = ProductTypeEnum::SERVICE;
if (preg_match('/rent/i', $code)) {
$type = ProductTypeEnum::RENTAL;
}

$this->parsedData['type'] = $type;

if($type==ProductTypeEnum::SERVICE) {
if ($type == ProductTypeEnum::SERVICE) {
$state = match ($this->auroraModelData->{'Product Status'}) {
'InProcess' => ServiceStateEnum::IN_PROCESS,
'Discontinued','Discontinuing' => ServiceStateEnum::DISCONTINUED,
default => ServiceStateEnum::ACTIVE
'InProcess' => ServiceStateEnum::IN_PROCESS,
'Discontinued', 'Discontinuing' => ServiceStateEnum::DISCONTINUED,
default => ServiceStateEnum::ACTIVE
};
} else {
$state = match ($this->auroraModelData->{'Product Status'}) {
'InProcess' => RentalStateEnum::IN_PROCESS,
'Discontinued','Discontinuing' => RentalStateEnum::DISCONTINUED,
default => RentalStateEnum::ACTIVE
'InProcess' => RentalStateEnum::IN_PROCESS,
'Discontinued', 'Discontinuing' => RentalStateEnum::DISCONTINUED,
default => RentalStateEnum::ACTIVE
};
}

$status = false;
if ($state == ProductStateEnum::ACTIVE) {
$status = true;
}

$this->parsedData['service'] = [
'type' => $type,
'owner_type' => $owner_type,
'owner_id' => $owner_id,
'state' => $state,
'code' => $code,
'name' => $this->auroraModelData->{'Product Name'},
'main_outerable_price' => round($unit_price, 2),
'status' => $status,
'data' => $data,
'settings' => $settings,
'created_at' => $created_at,
'source_id' => $this->organisation->id . ':' . $this->auroraModelData->{'Product ID'},
'historic_source_id' => $this->organisation->id . ':' . $this->auroraModelData->{'Product Current Key'},
];


if ($type == ProductTypeEnum::RENTAL) {
$autoAssignAsset = match ($code) {
'Rent-01', 'Rent-02', 'Rent-04' => 'Pallet',
default => null
};

$autoAssignAssetType = match ($code) {
'Rent-01' => PalletTypeEnum::PALLET->value,
'Rent-02' => PalletTypeEnum::OVERSIZE->value,
'Rent-04' => PalletTypeEnum::BOX->value,
default => null
};

$this->parsedData['service']['auto_assign_asset'] = $autoAssignAsset;
$this->parsedData['service']['auto_assign_asset_type'] = $autoAssignAssetType;

$status=false;
if($state==ProductStateEnum::ACTIVE) {
$status=true;
}

$this->parsedData['service'] = [
'type' => $type,
'owner_type' => $owner_type,
'owner_id' => $owner_id,
'state' => $state,
'code' => $code,
'name' => $this->auroraModelData->{'Product Name'},
'main_outerable_price' => round($unit_price, 2),
'status' => $status,
'data' => $data,
'settings' => $settings,
'created_at' => $created_at,
'source_id' => $this->organisation->id.':'.$this->auroraModelData->{'Product ID'},
'historic_source_id' => $this->organisation->id.':'.$this->auroraModelData->{'Product Current Key'},

];

}


Expand All @@ -97,4 +118,5 @@ protected function fetchData($id): object|null
->table('Product Dimension')
->where('Product ID', $id)->first();
}

}

0 comments on commit 0b9ecb3

Please sign in to comment.