From 25ec87b6be551c203a330e9d4a02a220e2e4ca0a 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:58:46 +0300 Subject: [PATCH] import item name unique issue fixed --- app/Imports/Purchases/Sheets/BillItemTaxes.php | 9 +++++++-- app/Imports/Sales/Sheets/InvoiceItemTaxes.php | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Imports/Purchases/Sheets/BillItemTaxes.php b/app/Imports/Purchases/Sheets/BillItemTaxes.php index 97273ad93..dba07480d 100644 --- a/app/Imports/Purchases/Sheets/BillItemTaxes.php +++ b/app/Imports/Purchases/Sheets/BillItemTaxes.php @@ -28,10 +28,15 @@ class BillItemTaxes extends Import $row = parent::map($row); - $row['document_id'] = (int) Document::bill()->number($row['bill_number'])->pluck('id')->first(); + $document = Document::with('items')->bill()->number($row['bill_number'])->first(); + + $row['document_id'] = (int) $document->id; if (empty($row['document_item_id']) && !empty($row['item_name'])) { - $item_id = Item::name($row['item_name'])->pluck('id')->first(); + $document_items_ids = $document->items->pluck('item_id')->toArray(); + + $item_id = Item::name($row['item_name'])->whereIn('id', $document_items_ids)->pluck('id')->first(); + $row['document_item_id'] = DocumentItem::bill()->where('item_id', $item_id)->pluck('id')->first(); } diff --git a/app/Imports/Sales/Sheets/InvoiceItemTaxes.php b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php index 9f4fe26b0..39fd743cf 100644 --- a/app/Imports/Sales/Sheets/InvoiceItemTaxes.php +++ b/app/Imports/Sales/Sheets/InvoiceItemTaxes.php @@ -28,10 +28,15 @@ class InvoiceItemTaxes extends Import $row = parent::map($row); - $row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first(); + $document = Document::with('items')->invoice()->number($row['invoice_number'])->first(); + + $row['document_id'] = (int) $document->id; if (empty($row['document_item_id']) && !empty($row['item_name'])) { - $item_id = Item::name($row['item_name'])->pluck('id')->first(); + $document_items_ids = $document->items->pluck('item_id')->toArray(); + + $item_id = Item::name($row['item_name'])->whereIn('id', $document_items_ids)->pluck('id')->first(); + $row['document_item_id'] = DocumentItem::invoice()->where('item_id', $item_id)->pluck('id')->first(); }