From 25e75fbc524e01b01c869857d9001388da48bc2d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 5 Mar 2024 16:30:54 +1100 Subject: [PATCH] Fixes for report exports --- app/Export/CSV/InvoiceExport.php | 6 +-- app/Export/CSV/InvoiceItemExport.php | 6 +-- app/Export/CSV/PurchaseOrderExport.php | 60 +++------------------- app/Export/CSV/PurchaseOrderItemExport.php | 38 +++++++++----- app/Export/Decorators/InvoiceDecorator.php | 1 - 5 files changed, 37 insertions(+), 74 deletions(-) diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index 9c81fadab634..e7b08a7ec3ac 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -151,9 +151,9 @@ class InvoiceExport extends BaseExport // $entity['invoice.status'] = $invoice->stringStatus($invoice->status_id); // } - // if (in_array('invoice.recurring_id', $this->input['report_keys'])) { - // $entity['invoice.recurring_id'] = $invoice->recurring_invoice->number ?? ''; - // } + if (in_array('invoice.recurring_id', $this->input['report_keys'])) { + $entity['invoice.recurring_id'] = $invoice->recurring_invoice->number ?? ''; + } if (in_array('invoice.auto_bill_enabled', $this->input['report_keys'])) { $entity['invoice.auto_bill_enabled'] = $invoice->auto_bill_enabled ? ctrans('texts.yes') : ctrans('texts.no'); diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 54cfd22bc3ef..791bfeddad17 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -236,9 +236,9 @@ class InvoiceItemExport extends BaseExport // $entity['invoice.status'] = $invoice->stringStatus($invoice->status_id); // } - // if (in_array('invoice.recurring_id', $this->input['report_keys'])) { - // $entity['invoice.recurring_id'] = $invoice->recurring_invoice->number ?? ''; - // } + if (in_array('invoice.recurring_id', $this->input['report_keys'])) { + $entity['invoice.recurring_id'] = $invoice->recurring_invoice->number ?? ''; + } if (in_array('invoice.assigned_user_id', $this->input['report_keys'])) { $entity['invoice.assigned_user_id'] = $invoice->assigned_user ? $invoice->assigned_user->present()->name() : ''; diff --git a/app/Export/CSV/PurchaseOrderExport.php b/app/Export/CSV/PurchaseOrderExport.php index a43702b035fb..2a1a77956e44 100644 --- a/app/Export/CSV/PurchaseOrderExport.php +++ b/app/Export/CSV/PurchaseOrderExport.php @@ -31,51 +31,6 @@ class PurchaseOrderExport extends BaseExport private Decorator $decorator; - public array $entity_keys = [ - 'amount' => 'purchase_order.amount', - 'balance' => 'purchase_order.balance', - 'vendor' => 'purchase_order.vendor_id', - // 'custom_surcharge1' => 'purchase_order.custom_surcharge1', - // 'custom_surcharge2' => 'purchase_order.custom_surcharge2', - // 'custom_surcharge3' => 'purchase_order.custom_surcharge3', - // 'custom_surcharge4' => 'purchase_order.custom_surcharge4', - 'custom_value1' => 'purchase_order.custom_value1', - 'custom_value2' => 'purchase_order.custom_value2', - 'custom_value3' => 'purchase_order.custom_value3', - 'custom_value4' => 'purchase_order.custom_value4', - 'date' => 'purchase_order.date', - 'discount' => 'purchase_order.discount', - 'due_date' => 'purchase_order.due_date', - 'exchange_rate' => 'purchase_order.exchange_rate', - 'footer' => 'purchase_order.footer', - 'number' => 'purchase_order.number', - 'paid_to_date' => 'purchase_order.paid_to_date', - 'partial' => 'purchase_order.partial', - 'partial_due_date' => 'purchase_order.partial_due_date', - 'po_number' => 'purchase_order.po_number', - 'private_notes' => 'purchase_order.private_notes', - 'public_notes' => 'purchase_order.public_notes', - 'status' => 'purchase_order.status', - 'tax_name1' => 'purchase_order.tax_name1', - 'tax_name2' => 'purchase_order.tax_name2', - 'tax_name3' => 'purchase_order.tax_name3', - 'tax_rate1' => 'purchase_order.tax_rate1', - 'tax_rate2' => 'purchase_order.tax_rate2', - 'tax_rate3' => 'purchase_order.tax_rate3', - 'terms' => 'purchase_order.terms', - 'total_taxes' => 'purchase_order.total_taxes', - 'currency_id' => 'purchase_order.currency_id', - ]; - - private array $decorate_keys = [ - 'country', - 'currency_id', - 'status', - 'vendor', - 'project', - ]; - - public function __construct(Company $company, array $input) { $this->company = $company; @@ -169,7 +124,7 @@ class PurchaseOrderExport extends BaseExport if (is_array($parts) && $parts[0] == 'purchase_order' && array_key_exists($parts[1], $transformed_purchase_order)) { $entity[$key] = $transformed_purchase_order[$parts[1]]; } else { - // nlog($key); + nlog($key); $entity[$key] = $this->decorator->transform($key, $purchase_order); // $entity[$key] = ''; @@ -184,16 +139,13 @@ class PurchaseOrderExport extends BaseExport private function decorateAdvancedFields(PurchaseOrder $purchase_order, array $entity): array { - if (in_array('country_id', $this->input['report_keys'])) { - $entity['country'] = $purchase_order->vendor->country ? ctrans("texts.country_{$purchase_order->vendor->country->name}") : ''; + + if (in_array('purchase_order.currency_id', $this->input['report_keys'])) { + $entity['purchase_order.currency_id'] = $purchase_order->vendor->currency() ? $purchase_order->vendor->currency()->code : $purchase_order->company->currency()->code; } - if (in_array('currency_id', $this->input['report_keys'])) { - $entity['currency_id'] = $purchase_order->vendor->currency() ? $purchase_order->vendor->currency()->code : $purchase_order->company->currency()->code; - } - - if (in_array('vendor_id', $this->input['report_keys'])) { - $entity['vendor'] = $purchase_order->vendor->present()->name(); + if (in_array('purchase_order.vendor_id', $this->input['report_keys'])) { + $entity['purchase_order.vendor_id'] = $purchase_order->vendor->present()->name(); } if (in_array('purchase_order.status', $this->input['report_keys'])) { diff --git a/app/Export/CSV/PurchaseOrderItemExport.php b/app/Export/CSV/PurchaseOrderItemExport.php index a4f9cc5de795..358af941509f 100644 --- a/app/Export/CSV/PurchaseOrderItemExport.php +++ b/app/Export/CSV/PurchaseOrderItemExport.php @@ -192,23 +192,35 @@ class PurchaseOrderItemExport extends BaseExport private function decorateAdvancedFields(PurchaseOrder $purchase_order, array $entity): array { - if (in_array('currency_id', $this->input['report_keys'])) { - $entity['currency'] = $purchase_order->vendor->currency() ? $purchase_order->vendor->currency()->code : $purchase_order->company->currency()->code; + // if (in_array('currency_id', $this->input['report_keys'])) { + // $entity['currency'] = $purchase_order->vendor->currency() ? $purchase_order->vendor->currency()->code : $purchase_order->company->currency()->code; + // } + + // if(array_key_exists('type', $entity)) { + // $entity['type'] = $purchase_order->typeIdString($entity['type']); + // } + + // if(array_key_exists('tax_category', $entity)) { + // $entity['tax_category'] = $purchase_order->taxTypeString($entity['tax_category']); + // } + + // if($this->force_keys) { + // $entity['vendor'] = $purchase_order->vendor->present()->name(); + // $entity['vendor_id_number'] = $purchase_order->vendor->id_number; + // $entity['vendor_number'] = $purchase_order->vendor->number; + // $entity['status'] = $purchase_order->stringStatus($purchase_order->status_id); + // } + + if (in_array('purchase_order.currency_id', $this->input['report_keys'])) { + $entity['purchase_order.currency_id'] = $purchase_order->vendor->currency() ? $purchase_order->vendor->currency()->code : $purchase_order->company->currency()->code; } - if(array_key_exists('type', $entity)) { - $entity['type'] = $purchase_order->typeIdString($entity['type']); + if (in_array('purchase_order.vendor_id', $this->input['report_keys'])) { + $entity['purchase_order.vendor_id'] = $purchase_order->vendor->present()->name(); } - if(array_key_exists('tax_category', $entity)) { - $entity['tax_category'] = $purchase_order->taxTypeString($entity['tax_category']); - } - - if($this->force_keys) { - $entity['vendor'] = $purchase_order->vendor->present()->name(); - $entity['vendor_id_number'] = $purchase_order->vendor->id_number; - $entity['vendor_number'] = $purchase_order->vendor->number; - $entity['status'] = $purchase_order->stringStatus($purchase_order->status_id); + if (in_array('purchase_order.status', $this->input['report_keys'])) { + $entity['purchase_order.status'] = $purchase_order->stringStatus($purchase_order->status_id); } if (in_array('purchase_order.user_id', $this->input['report_keys'])) { diff --git a/app/Export/Decorators/InvoiceDecorator.php b/app/Export/Decorators/InvoiceDecorator.php index 8dd6d36e439d..5ce6d936c6ce 100644 --- a/app/Export/Decorators/InvoiceDecorator.php +++ b/app/Export/Decorators/InvoiceDecorator.php @@ -79,7 +79,6 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface return $invoice->partial_due_date ?? ''; } - public function assigned_user_id(Invoice $invoice) { return $invoice->assigned_user ? $invoice->assigned_user->present()->name() : '';