From 63d4a68f652739603ba2fd1f7e623d91ccf36fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:48:40 +0300 Subject: [PATCH] fixed recurring import has row issue --- .../RecurringBills/Sheets/RecurringBills.php | 18 ++++++++++++++++++ .../Sheets/RecurringInvoices.php | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/Imports/Purchases/RecurringBills/Sheets/RecurringBills.php b/app/Imports/Purchases/RecurringBills/Sheets/RecurringBills.php index 1834fa41f..cae2cc5e0 100644 --- a/app/Imports/Purchases/RecurringBills/Sheets/RecurringBills.php +++ b/app/Imports/Purchases/RecurringBills/Sheets/RecurringBills.php @@ -60,4 +60,22 @@ class RecurringBills extends Import return $rules; } + + //This function is used in import classes. If the data in the row exists in the database, it is returned. + public function hasRow($row) + { + $has_row = $this->model::billRecurring()->get($this->columns)->each(function ($data) { + $data->setAppends([]); + $data->unsetRelations(); + }); + + $search_value = []; + + //In the model, the fields to be searched for the row are determined. + foreach ($this->columns as $key) { + $search_value[$key] = isset($row[$key]) ? $row[$key] : null; + } + + return in_array($search_value, $has_row->toArray()); + } } diff --git a/app/Imports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php b/app/Imports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php index e505533a1..c95083a47 100644 --- a/app/Imports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php +++ b/app/Imports/Sales/RecurringInvoices/Sheets/RecurringInvoices.php @@ -60,4 +60,22 @@ class RecurringInvoices extends Import return $rules; } + + //This function is used in import classes. If the data in the row exists in the database, it is returned. + public function hasRow($row) + { + $has_row = $this->model::invoiceRecurring()->get($this->columns)->each(function ($data) { + $data->setAppends([]); + $data->unsetRelations(); + }); + + $search_value = []; + + //In the model, the fields to be searched for the row are determined. + foreach ($this->columns as $key) { + $search_value[$key] = isset($row[$key]) ? $row[$key] : null; + } + + return in_array($search_value, $has_row->toArray()); + } }