From c9818cc580df1a038e9f304bbc536e21a36bee3f Mon Sep 17 00:00:00 2001 From: Raul Perusquia Date: Wed, 25 Sep 2024 01:18:29 +0800 Subject: [PATCH] debug fetch stock movements --- .../Transfers/Aurora/FetchAuroraAction.php | 1 + .../Aurora/FetchAuroraDeletedLocations.php | 32 +++++++++++++------ .../Aurora/FetchAuroraOrgStockMovement.php | 4 +++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/Actions/Transfers/Aurora/FetchAuroraAction.php b/app/Actions/Transfers/Aurora/FetchAuroraAction.php index 301088518e..2b4429e8f2 100644 --- a/app/Actions/Transfers/Aurora/FetchAuroraAction.php +++ b/app/Actions/Transfers/Aurora/FetchAuroraAction.php @@ -66,6 +66,7 @@ protected function preProcessCommand(Command $command): void 'fetch:outers', 'fetch:portfolios', 'fetch:stock_movements', + 'fetch:deleted-locations', ])) { $this->onlyNew = (bool)$command->option('only_new'); } diff --git a/app/Actions/Transfers/Aurora/FetchAuroraDeletedLocations.php b/app/Actions/Transfers/Aurora/FetchAuroraDeletedLocations.php index 4351057ae7..31a2a31b8b 100644 --- a/app/Actions/Transfers/Aurora/FetchAuroraDeletedLocations.php +++ b/app/Actions/Transfers/Aurora/FetchAuroraDeletedLocations.php @@ -40,13 +40,13 @@ public function handle(SourceOrganisationService $organisationSource, int $organ ); $this->recordNew($organisationSource); - $sourceData = explode(':', $location->source_id); - DB::connection('aurora')->table('Location Deleted Dimension') - ->where('Location Deleted Key', $sourceData[1]) - ->update(['aiku_id' => $location->id]); - } + $sourceData = explode(':', $location->source_id); + DB::connection('aurora')->table('Location Deleted Dimension') + ->where('Location Deleted Key', $sourceData[1]) + ->update(['aiku_id' => $location->id]); + return $location; } @@ -55,18 +55,32 @@ public function handle(SourceOrganisationService $organisationSource, int $organ public function getModelsQuery(): Builder { - return DB::connection('aurora') + $query = DB::connection('aurora') ->table('Location Deleted Dimension') - ->select('Location Deleted Key as source_id') - ->orderBy('source_id') + ->select('Location Deleted Key as source_id'); + + if ($this->onlyNew) { + $query->whereNull('aiku_id'); + } + + $query->orderBy('source_id') ->when(app()->environment('testing'), function ($query) { return $query->limit(20); }); + + return $query; } public function count(): ?int { - return DB::connection('aurora')->table('Location Deleted Dimension')->count(); + $query = DB::connection('aurora') + ->table('Location Deleted Dimension'); + if ($this->onlyNew) { + $query->whereNull('aiku_id'); + } + + return $query->count(); + } } diff --git a/app/Transfers/Aurora/FetchAuroraOrgStockMovement.php b/app/Transfers/Aurora/FetchAuroraOrgStockMovement.php index 02c628596b..9780d2a07d 100644 --- a/app/Transfers/Aurora/FetchAuroraOrgStockMovement.php +++ b/app/Transfers/Aurora/FetchAuroraOrgStockMovement.php @@ -36,6 +36,10 @@ protected function parseModel(): void $location = $this->parseLocation($this->organisation->id.':'.$this->auroraModelData->{'Location Key'}, $this->organisationSource); + if (!$location) { + dd($this->auroraModelData->{'Location Key'}); + } + $date = $this->parseDatetime($this->auroraModelData->{'Date'}); $type = null;