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()); + } }