From 3f59417ab11bdcc3031246e9650147885e439d60 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 23 Sep 2024 07:37:50 +1000 Subject: [PATCH] Add SyncInterface --- app/Interfaces/SyncInterface.php | 21 ++++++ app/Services/Quickbooks/Models/QbClient.php | 78 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 app/Interfaces/SyncInterface.php create mode 100644 app/Services/Quickbooks/Models/QbClient.php diff --git a/app/Interfaces/SyncInterface.php b/app/Interfaces/SyncInterface.php new file mode 100644 index 000000000000..17ca4e69c189 --- /dev/null +++ b/app/Interfaces/SyncInterface.php @@ -0,0 +1,21 @@ +service->sdk->FindById('Customer', $id); + } + + public function syncToNinja(array $records): void + { + + $transformer = new ClientTransformer($this->service->company); + + foreach ($records as $record) { + + $ninja_data = $transformer->qbToNinja($record); + + if ($client = $this->findClient($ninja_data['id'])) { + $client->fill($ninja_data); + $client->save(); + } + } + + } + + public function syncToForeign(array $records): void + { + } + + private function findClient(string $key): ?Client + { + $search = Client::query() + ->withTrashed() + ->where('company_id', $this->service->company->id) + ->where('sync->qb_id', $key); + + if ($search->count() == 0) { + + $client = ClientFactory::create($this->service->company->id, $this->service->company->owner()->id); + + $sync = new ClientSync(); + $sync->qb_id = $key; + $client->sync = $sync; + + return $client; + + } elseif ($search->count() == 1) { + return $this->service->settings->client->update_record ? $search->first() : null; + } + + return null; + + + } +}