From ab4c59082f8ce2620ed55e40132a046e4ffac95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:55:44 +0300 Subject: [PATCH] import and export parent number issues fixed --- app/Exports/Purchases/Sheets/Bills.php | 4 ++-- app/Imports/Purchases/Sheets/Bills.php | 2 +- app/Imports/Sales/Sheets/Invoices.php | 2 +- app/Traits/Import.php | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php index c266ea374..5fe5aa7e0 100644 --- a/app/Exports/Purchases/Sheets/Bills.php +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -26,7 +26,7 @@ class Bills extends Export implements WithColumnFormatting $model->bill_number = $model->document_number; $model->billed_at = $model->issued_at; $model->contact_country = $country; - $model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number ?? null; + $model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number; return parent::map($model); } @@ -53,7 +53,7 @@ class Bills extends Export implements WithColumnFormatting 'contact_zip_code', 'contact_city', 'notes', - 'parent_number', + 'parent_number' ]; } diff --git a/app/Imports/Purchases/Sheets/Bills.php b/app/Imports/Purchases/Sheets/Bills.php index 508284784..eb29e93d1 100644 --- a/app/Imports/Purchases/Sheets/Bills.php +++ b/app/Imports/Purchases/Sheets/Bills.php @@ -35,7 +35,7 @@ class Bills extends Import $row['currency_code'] = $this->getCurrencyCode($row); $row['type'] = Model::BILL_TYPE; $row['contact_country'] = !empty($country) ? $country : null; - $row['parent_id'] = $this->getParentId($row); + $row['parent_id'] = $this->getParentId($row) ?? 0; return $row; } diff --git a/app/Imports/Sales/Sheets/Invoices.php b/app/Imports/Sales/Sheets/Invoices.php index 1ebf7dbe5..be7f6fe61 100644 --- a/app/Imports/Sales/Sheets/Invoices.php +++ b/app/Imports/Sales/Sheets/Invoices.php @@ -35,7 +35,7 @@ class Invoices extends Import $row['currency_code'] = $this->getCurrencyCode($row); $row['type'] = Model::INVOICE_TYPE; $row['contact_country'] = !empty($country) ? $country : null; - $row['parent_id'] = $this->getParentId($row); + $row['parent_id'] = $this->getParentId($row) ?? 0; return $row; } diff --git a/app/Traits/Import.php b/app/Traits/Import.php index abb8f17dc..de0395120 100644 --- a/app/Traits/Import.php +++ b/app/Traits/Import.php @@ -154,11 +154,15 @@ trait Import { $id = isset($row['parent_id']) ? $row['parent_id'] : null; - if (empty($id) && isset($row['document_number']) && !empty($row['parent_number'])) { + if (empty($row['parent_number'])) { + return null; + } + + if (empty($id) && (!empty($row['document_number']) || !empty($row['invoice_number']) || !empty($row['bill_number']))) { $id = Document::number($row['parent_number'])->pluck('id')->first(); } - if (empty($id) && isset($row['number']) && !empty($row['parent_number'])) { + if (empty($id) && isset($row['number'])) { $id = Transaction::number($row['parent_number'])->pluck('id')->first(); }