diff --git a/app/Abstracts/Import.php b/app/Abstracts/Import.php index 653cda22430..eb05b9ab02b 100644 --- a/app/Abstracts/Import.php +++ b/app/Abstracts/Import.php @@ -42,9 +42,9 @@ public function map($row): array // created_by is equal to the owner id. Therefore, the value in export is owner email. if (isset($row['created_by'])) { - $row['created_by'] = User::where('email', $row['created_by'])->first()?->id ?? $this->user->id; + $row['created_by'] = $this->getCreatedById($row); } - + $row['created_from'] = $this->getSourcePrefix() . 'import'; // Make enabled field integer diff --git a/app/Traits/Import.php b/app/Traits/Import.php index e04b113ec91..8681e785c66 100644 --- a/app/Traits/Import.php +++ b/app/Traits/Import.php @@ -14,6 +14,7 @@ use App\Jobs\Setting\CreateCategory; use App\Jobs\Setting\CreateCurrency; use App\Jobs\Setting\CreateTax; +use App\Models\Auth\User; use App\Models\Banking\Account; use App\Models\Common\Contact; use App\Models\Common\Item; @@ -110,6 +111,17 @@ public function getCurrencyCode($row) return $currency->code; } + public function getCreatedById($row) + { + $user = User::where('email', $row['created_by'])->first(); + + if (! empty($user)) { + return $user->id; + } + + return $this->user->id; + } + public function getDocumentId($row) { $id = isset($row['document_id']) ? $row['document_id'] : null;