diff --git a/app/Exports/Banking/Transactions.php b/app/Exports/Banking/Transactions.php index aee773b3b28..b4a3ad6116e 100644 --- a/app/Exports/Banking/Transactions.php +++ b/app/Exports/Banking/Transactions.php @@ -20,6 +20,7 @@ public function map($model): array $model->contact_email = $model->contact->email; $model->category_name = $model->category->name; $model->invoice_bill_number = $model->document->document_number ?? 0; + $model->parent_number = Model::isRecurring()->find($model->parent_id)?->number; return parent::map($model); } @@ -41,6 +42,7 @@ public function fields(): array 'payment_method', 'reference', 'reconciled', + 'parent_number', ]; } diff --git a/app/Exports/Purchases/Sheets/Bills.php b/app/Exports/Purchases/Sheets/Bills.php index 6f3bf5e0e3a..c266ea37437 100644 --- a/app/Exports/Purchases/Sheets/Bills.php +++ b/app/Exports/Purchases/Sheets/Bills.php @@ -26,6 +26,7 @@ public function map($model): array $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; return parent::map($model); } @@ -52,6 +53,7 @@ public function fields(): array 'contact_zip_code', 'contact_city', 'notes', + 'parent_number', ]; } diff --git a/app/Exports/Sales/Sheets/Invoices.php b/app/Exports/Sales/Sheets/Invoices.php index 39a7d3410bd..857874536ef 100644 --- a/app/Exports/Sales/Sheets/Invoices.php +++ b/app/Exports/Sales/Sheets/Invoices.php @@ -26,6 +26,7 @@ public function map($model): array $model->invoice_number = $model->document_number; $model->invoiced_at = $model->issued_at; $model->contact_country = $country; + $model->parent_number = Model::invoiceRecurring()->find($model->parent_id)?->document_number; return parent::map($model); } @@ -53,6 +54,7 @@ public function fields(): array 'contact_city', 'notes', 'footer', + 'parent_number', ]; } diff --git a/app/Imports/Banking/Transactions.php b/app/Imports/Banking/Transactions.php index eae60c77c07..a7a41680d69 100644 --- a/app/Imports/Banking/Transactions.php +++ b/app/Imports/Banking/Transactions.php @@ -24,6 +24,7 @@ public function map($row): array $row['category_id'] = $this->getCategoryId($row); $row['contact_id'] = $this->getContactId($row); $row['document_id'] = $this->getDocumentId($row); + $row['parent_id'] = $this->getParentId($row); return $row; } diff --git a/app/Imports/Purchases/Sheets/Bills.php b/app/Imports/Purchases/Sheets/Bills.php index 8a6c7206bc0..5082847845d 100644 --- a/app/Imports/Purchases/Sheets/Bills.php +++ b/app/Imports/Purchases/Sheets/Bills.php @@ -35,6 +35,7 @@ public function map($row): array $row['currency_code'] = $this->getCurrencyCode($row); $row['type'] = Model::BILL_TYPE; $row['contact_country'] = !empty($country) ? $country : null; + $row['parent_id'] = $this->getParentId($row); return $row; } diff --git a/app/Imports/Sales/Sheets/Invoices.php b/app/Imports/Sales/Sheets/Invoices.php index aeb831de878..1ebf7dbe5eb 100644 --- a/app/Imports/Sales/Sheets/Invoices.php +++ b/app/Imports/Sales/Sheets/Invoices.php @@ -35,6 +35,7 @@ public function map($row): array $row['currency_code'] = $this->getCurrencyCode($row); $row['type'] = Model::INVOICE_TYPE; $row['contact_country'] = !empty($country) ? $country : null; + $row['parent_id'] = $this->getParentId($row); return $row; } diff --git a/app/Traits/Import.php b/app/Traits/Import.php index 64a6dc57c2c..abb8f17dc4e 100644 --- a/app/Traits/Import.php +++ b/app/Traits/Import.php @@ -16,6 +16,7 @@ use App\Jobs\Setting\CreateTax; use App\Models\Auth\User; use App\Models\Banking\Account; +use App\Models\Banking\Transaction; use App\Models\Common\Contact; use App\Models\Common\Item; use App\Models\Document\Document; @@ -149,6 +150,21 @@ public function getDocumentId($row) return is_null($id) ? $id : (int) $id; } + public function getParentId($row) + { + $id = isset($row['parent_id']) ? $row['parent_id'] : null; + + if (empty($id) && isset($row['document_number']) && !empty($row['parent_number'])) { + $id = Document::number($row['parent_number'])->pluck('id')->first(); + } + + if (empty($id) && isset($row['number']) && !empty($row['parent_number'])) { + $id = Transaction::number($row['parent_number'])->pluck('id')->first(); + } + + return is_null($id) ? $id : (int) $id; + } + public function getItemId($row, $type = null) { $id = isset($row['item_id']) ? $row['item_id'] : null;