From aca580780abbaf239fd17f36a474aa69de7c0adf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 20 Oct 2023 09:22:33 +1100 Subject: [PATCH] Ensure order of Item exports --- app/Export/CSV/InvoiceItemExport.php | 16 +++++++++------- app/Export/CSV/PurchaseOrderItemExport.php | 1 + app/Export/CSV/QuoteItemExport.php | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 5ac3c9fb2f..ba2dc00da4 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -137,16 +137,16 @@ class InvoiceItemExport extends BaseExport if (str_contains($key, "item.")) { - $key = str_replace("item.", "", $key); + $tmp_key = str_replace("item.", "", $key); - if($key == 'type_id') - $key = 'type'; + if($tmp_key == 'type_id') + $tmp_key = 'type'; - if($key == 'tax_id') - $key = 'tax_category'; + if($tmp_key == 'tax_id') + $tmp_key = 'tax_category'; - if (property_exists($item, $key)) { - $item_array[$key] = $item->{$key}; + if (property_exists($item, $tmp_key)) { + $item_array[$key] = $item->{$tmp_key}; } else { $item_array[$key] = ''; @@ -156,6 +156,8 @@ class InvoiceItemExport extends BaseExport $transformed_items = array_merge($transformed_invoice, $item_array); $entity = $this->decorateAdvancedFields($invoice, $transformed_items); + + $entity = array_merge(array_flip(array_values($this->input['report_keys'])), $entity); $this->storage_array[] = $entity; diff --git a/app/Export/CSV/PurchaseOrderItemExport.php b/app/Export/CSV/PurchaseOrderItemExport.php index fb09ea6fa8..1ba5db7a12 100644 --- a/app/Export/CSV/PurchaseOrderItemExport.php +++ b/app/Export/CSV/PurchaseOrderItemExport.php @@ -147,6 +147,7 @@ class PurchaseOrderItemExport extends BaseExport $transformed_items = array_merge($transformed_purchase_order, $item_array); $entity = $this->decorateAdvancedFields($purchase_order, $transformed_items); + $entity = array_merge(array_flip(array_values($this->input['report_keys'])), $entity); $this->storage_array[] = $entity; } diff --git a/app/Export/CSV/QuoteItemExport.php b/app/Export/CSV/QuoteItemExport.php index 48bc25b95e..5e327af612 100644 --- a/app/Export/CSV/QuoteItemExport.php +++ b/app/Export/CSV/QuoteItemExport.php @@ -152,6 +152,7 @@ class QuoteItemExport extends BaseExport $transformed_items = array_merge($transformed_quote, $item_array); $entity = $this->decorateAdvancedFields($quote, $transformed_items); + $entity = array_merge(array_flip(array_values($this->input['report_keys'])), $entity); $this->storage_array[] = $entity; }