Skip to content

Commit

Permalink
#928 Fetch Aurora History (updated) test on locations
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Oct 4, 2024
1 parent bfdc3e2 commit 0060b9f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/Actions/CRM/Customer/DeleteCustomerDeliveryAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle(Customer $customer, Address $address): Customer
AddressHydrateUsage::dispatch($address);

$address->delete();

$customer->refresh();
return $customer;
}
Expand Down
6 changes: 5 additions & 1 deletion app/Actions/Inventory/Location/StoreLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ public function inWarehouseArea(WarehouseArea $warehouseArea, ActionRequest $req
return $this->handle($warehouseArea, $this->validatedData);
}

public function action(WarehouseArea|Warehouse $parent, array $modelData, int $hydratorsDelay = 0, bool $strict = true): Location
public function action(WarehouseArea|Warehouse $parent, array $modelData, int $hydratorsDelay = 0, bool $strict = true, $audit = true): Location
{
if (!$audit) {
Location::disableAuditing();
}

$this->asAction = true;
$this->strict = $strict;
$this->hydratorsDelay = $hydratorsDelay;
Expand Down
3 changes: 2 additions & 1 deletion app/Actions/Inventory/Location/UpdateLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function rules(): array
'allow_stocks' => ['sometimes', 'required', 'boolean'],
'allow_fulfilment' => ['sometimes', 'required', 'boolean'],
'allow_dropshipping' => ['sometimes', 'required', 'boolean'],
'last_fetched_at' => ['sometimes', 'date'],
'max_weight' => ['sometimes', 'nullable', 'numeric', 'min:0.1', 'max:1000000'],
'max_volume' => ['sometimes', 'nullable', 'numeric', 'min:0.1', 'max:1000000'],
];

if (!$this->strict) {
Expand Down
8 changes: 5 additions & 3 deletions app/Actions/Transfers/Aurora/FetchAuroraHistories.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public function getModelsQuery(): Builder
//enum('sold_since','last_sold','first_sold','placed','wrote','deleted','edited','cancelled','charged','merged','created','associated','disassociate','register','login','logout','fail_login','password_request','password_reset','search')
$query = DB::connection('aurora')
->table('History Dimension')
->where('Direct Object', 'Customer')
// ->whereIn('Action', ['edited', 'created']);
->whereIn('Action', ['created'])
// ->whereIn('Direct Object', ['Customer','Location'])
// ->whereIn('Action', ['edited', 'created']);

->where('Direct Object', 'Location')
->whereIn('Action', ['edited', 'created'])
->select('History Key as source_id')
->orderBy('History Date', 'asc');

Expand Down
11 changes: 10 additions & 1 deletion app/Actions/Transfers/Aurora/FetchAuroraLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Transfers\SourceOrganisationService;
use Exception;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;

class FetchAuroraLocations extends FetchAuroraAction
Expand Down Expand Up @@ -44,9 +45,17 @@ public function handle(SourceOrganisationService $organisationSource, int $organ
parent: $locationData['parent'],
modelData: $locationData['location'],
hydratorsDelay: 60,
strict: false
strict: false,
audit: false
);

Location::enableAuditing();
$this->saveMigrationHistory(
$location,
Arr::except($locationData['customer'], ['fetched_at','last_fetched_at'])
);


$this->recordNew($organisationSource);
$sourceData = explode(':', $location->source_id);
DB::connection('aurora')->table('Location Dimension')
Expand Down
4 changes: 2 additions & 2 deletions app/Transfers/Aurora/FetchAuroraEmployee.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function fetch(int $id): ?array
}


$userData = $this->parseUser();
$userData = $this->parseUserFromEmployee();
// if ($userData) {
// $this->parsedData['employee']['username'] = $userData['username'];
// $this->parsedData['employee']['legacy_password'] = $userData['legacy_password'];
Expand Down Expand Up @@ -146,7 +146,7 @@ public function fetch(int $id): ?array
}


private function parseUser(): ?array
private function parseUserFromEmployee(): ?array
{
$auroraUserData = DB::connection('aurora')
->table('User Dimension as users')
Expand Down
24 changes: 17 additions & 7 deletions app/Transfers/Aurora/FetchAuroraHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace App\Transfers\Aurora;

use App\Models\CRM\Customer;
use App\Models\Inventory\Location;
use Illuminate\Support\Facades\DB;

class FetchAuroraHistory extends FetchAurora
Expand Down Expand Up @@ -73,6 +75,8 @@ protected function parseModel(): void
$this->parsedData['history']['user_type'] = class_basename($user);
$this->parsedData['history']['user_id'] = $user->id;
}


}


Expand All @@ -84,7 +88,7 @@ protected function fetchData($id): object|null
}


protected function parseAuditableFromHistory()
protected function parseAuditableFromHistory(): Customer|Location|null
{
$auditable = null;

Expand All @@ -93,6 +97,12 @@ protected function parseAuditableFromHistory()
$auditable = $this->parseCustomer(
$this->organisation->id.':'.$this->auroraModelData->{'Direct Object Key'}
);
break;
case 'Location':
$auditable = $this->parseLocation(
$this->organisation->id.':'.$this->auroraModelData->{'Direct Object Key'},
$this->organisationSource
);
}


Expand Down Expand Up @@ -132,11 +142,11 @@ protected function parseHistoryOldValues($auditable, string $event): array
if ($event == 'created') {
return [];
}
return $this->parseHistoryUpdatedOldValues($auditable);

return [];
}

protected function parseHistoryNewValues($auditable, string $event)
protected function parseHistoryNewValues($auditable, string $event): array
{
if ($event == 'created') {
return $this->parseHistoryCreatedNewValues($auditable);
Expand Down Expand Up @@ -222,10 +232,10 @@ protected function parseCustomerHistoryCreatedNewValues($auditable): array
$abstract = $this->auroraModelData->{'History Details'};
}

if ($abstract == 'Customer registered' ||
$abstract == 'New customer added' ||
$abstract == 'Nouveau Client ajoute' ||
$abstract == 'New customer'
if ($abstract == 'Customer registered'
|| $abstract == 'New customer added'
|| $abstract == 'Nouveau Client ajoute'
|| $abstract == 'New customer'
) {
$newValues['name'] = '';
}
Expand Down
4 changes: 3 additions & 1 deletion app/Transfers/Aurora/FetchAuroraLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ protected function parseModel(): void
'code' => $code,
'source_id' => $this->organisation->id.':'.$this->auroraModelData->{'Location Key'},
'fetched_at' => now(),
'last_fetched_at' => now()
'last_fetched_at' => now(),
'max_weight' => $this->auroraModelData->{'Location Max Weight'} == 0 ? null : $this->auroraModelData->{'Location Max Weight'},
'max_volume' => $this->auroraModelData->{'Location Max Volume'} == 0 ? null : $this->auroraModelData->{'Location Max Volume'},
];
}

Expand Down
6 changes: 6 additions & 0 deletions app/Transfers/Aurora/WithAuroraSysAdminParsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace App\Transfers\Aurora;

use App\Actions\Transfers\Aurora\FetchAuroraDeletedUsers;
use App\Actions\Transfers\Aurora\FetchAuroraUsers;
use App\Models\CRM\WebUser;
use App\Models\SysAdmin\Guest;
use App\Models\SysAdmin\User;
Expand Down Expand Up @@ -110,6 +112,10 @@ protected function parseUserFromHistory(): User|WebUser|null
}


return $this->parseUser($this->organisation->id.':'.$this->auroraModelData->{'User Key'});
}


protected function parseUserPhoto(): array
{
$profileImages = $this->getModelImagesCollection(
Expand Down

0 comments on commit 0060b9f

Please sign in to comment.