From 7d37e6cb2caef8fb109847cc66d1ab518d818ca9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 2 Dec 2023 14:40:28 +1100 Subject: [PATCH] Fixes for export resolution --- app/Export/CSV/RecurringInvoiceExport.php | 2 + app/Export/Decorators/ClientDecorator.php | 122 +----------------- app/Export/Decorators/ContactDecorator.php | 36 +----- app/Export/Decorators/CreditDecorator.php | 24 +--- app/Export/Decorators/ExpenseDecorator.php | 74 ++--------- app/Export/Decorators/InvoiceDecorator.php | 106 ++------------- .../Export/ReportCsvGenerationTest.php | 3 +- 7 files changed, 34 insertions(+), 333 deletions(-) diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index 772d2da5d3b2..9f543bee03c3 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -110,6 +110,7 @@ class RecurringInvoiceExport extends BaseExport { $transformed_invoice = $this->invoice_transformer->transform($invoice); $transformed_invoice['frequency_id'] = $invoice->frequencyForKey($invoice->frequency_id); //need to inject this here because it is also a valid key +nlog($transformed_invoice); $entity = []; @@ -127,6 +128,7 @@ class RecurringInvoiceExport extends BaseExport } } +nlog($entity); return $entity; // return $this->decorateAdvancedFields($invoice, $entity); } diff --git a/app/Export/Decorators/ClientDecorator.php b/app/Export/Decorators/ClientDecorator.php index 6fb1b70b8486..f082370885c2 100644 --- a/app/Export/Decorators/ClientDecorator.php +++ b/app/Export/Decorators/ClientDecorator.php @@ -30,6 +30,9 @@ class ClientDecorator extends Decorator implements DecoratorInterface if($client && method_exists($this, $key)) { return $this->{$key}($client); } + elseif($client && $client->{$key}) { + return $client->{$key}; + } return ''; } @@ -39,11 +42,6 @@ class ClientDecorator extends Decorator implements DecoratorInterface return $client->present()->name(); } - public function number(Client $client) - { - return $client->number ?? ''; - } - public function user(Client $client) { return $client->user->present()->name(); @@ -54,29 +52,14 @@ class ClientDecorator extends Decorator implements DecoratorInterface return $client->assigned_user ? $client->user->present()->name() : ''; } - public function balance(Client $client) - { - return $client->balance ?? 0; - } - - public function paid_to_date(Client $client) - { - return $client->paid_to_date ?? 0; - } - public function currency_id(Client $client) { return $client->currency() ? $client->currency()->code : $client->company->currency()->code; } - public function website(Client $client) - { - return $client->website ?? ''; - } - public function private_notes(Client $client) { - return $client->private_notes ?? ''; + return strip_tags($client->private_notes ?? ''); } public function industry_id(Client $client) @@ -89,66 +72,11 @@ class ClientDecorator extends Decorator implements DecoratorInterface return $client->size ? ctrans("texts.size_{$client->size->name}") : ''; } - public function phone(Client $client) - { - return $client->phone ?? ''; - } - - public function address1(Client $client) - { - return $client->address1 ?? ''; - } - - public function address2(Client $client) - { - return $client->address2 ?? ''; - } - - public function city(Client $client) - { - return $client->city ?? ''; - } - - public function state(Client $client) - { - return $client->state ?? ''; - } - - public function postal_code(Client $client) - { - return $client->postal_code ?? ''; - } - public function country_id(Client $client) { return $client->country ? ctrans("texts.country_{$client->country->name}") : ''; } - public function shipping_address1(Client $client) - { - return $client->shipping_address1 ?? ''; - } - - public function shipping_address2(Client $client) - { - return $client->shipping_address2 ?? ''; - } - - public function shipping_city(Client $client) - { - return $client->shipping_city ?? ''; - } - - public function shipping_state(Client $client) - { - return $client->shipping_state ?? ''; - } - - public function shipping_postal_code(Client $client) - { - return $client->shipping_postal_code ?? ''; - } - public function shipping_country_id(Client $client) { return $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : ''; @@ -159,49 +87,9 @@ class ClientDecorator extends Decorator implements DecoratorInterface return $client?->settings?->payment_terms ?? $client->company->settings->payment_terms; } - public function vat_number(Client $client) - { - return $client->vat_number ?? ''; - } - - public function id_number(Client $client) - { - return $client->id_number ?? ''; - } - public function public_notes(Client $client) { - return $client->public_notes ?? ''; - } - - public function custom_value1(Client $client) - { - return $client->custom_value1 ?? ''; - } - - public function custom_value2(Client $client) - { - return $client->custom_value2 ?? ''; - } - - public function custom_value3(Client $client) - { - return $client->custom_value3 ?? ''; - } - - public function custom_value4(Client $client) - { - return $client->custom_value4 ?? ''; - } - - public function payment_balance(Client $client) - { - return $client->payment_balance ?? 0; - } - - public function credit_balance(Client $client) - { - return $client->credit_balance ?? 0; + return strip_tags($client->public_notes ?? ''); } public function classification(Client $client) diff --git a/app/Export/Decorators/ContactDecorator.php b/app/Export/Decorators/ContactDecorator.php index ae8ba8e5dcfd..dcc425b57110 100644 --- a/app/Export/Decorators/ContactDecorator.php +++ b/app/Export/Decorators/ContactDecorator.php @@ -28,42 +28,12 @@ class ContactDecorator implements DecoratorInterface if($contact && method_exists($this, $key)) { return $this->{$key}($contact); } + elseif($contact && $contact->{$key}){ + return $contact->{$key}; + } return ''; } - public function phone(ClientContact $contact) - { - return $contact->phone ?? ''; - } - public function first_name(ClientContact $contact) - { - return $contact->first_name ?? ''; - } - public function last_name(ClientContact $contact) - { - return $contact->last_name ?? ''; - } - public function email(ClientContact $contact) - { - return $contact->email ?? ''; - } - public function custom_value1(ClientContact $contact) - { - return $contact->custom_value1 ?? ''; - } - public function custom_value2(ClientContact $contact) - { - return $contact->custom_value2 ?? ''; - } - public function custom_value3(ClientContact $contact) - { - return $contact->custom_value3 ?? ''; - } - public function custom_value4(ClientContact $contact) - { - return $contact->custom_value4 ?? ''; - } - } diff --git a/app/Export/Decorators/CreditDecorator.php b/app/Export/Decorators/CreditDecorator.php index 67a6341c5769..07f9907606ce 100644 --- a/app/Export/Decorators/CreditDecorator.php +++ b/app/Export/Decorators/CreditDecorator.php @@ -27,32 +27,14 @@ class CreditDecorator implements DecoratorInterface if($credit && method_exists($this, $key)) { return $this->{$key}($credit); + } elseif($credit && $credit->{$key}){ + return $credit->{$key}; } return ''; } - public function number(Credit $credit) - { - return $credit->number ?? ''; - } - public function amount(Credit $credit) - { - return $credit->amount ?? 0; - } - public function balance(Credit $credit) - { - return $credit->balance ?? 0; - } - public function paid_to_date(Credit $credit) - { - return $credit->paid_to_date ?? 0; - } - public function po_number(Credit $credit) - { - return $credit->po_number ?? ''; - } public function date(Credit $credit) { return $credit->date ?? ''; @@ -63,7 +45,7 @@ class CreditDecorator implements DecoratorInterface } public function terms(Credit $credit) { - return $credit->terms ?? ''; + return strip_tags($credit->terms ?? ''); } public function discount(Credit $credit) { diff --git a/app/Export/Decorators/ExpenseDecorator.php b/app/Export/Decorators/ExpenseDecorator.php index 22bb798a4a7c..903f6cf8a8fe 100644 --- a/app/Export/Decorators/ExpenseDecorator.php +++ b/app/Export/Decorators/ExpenseDecorator.php @@ -27,40 +27,24 @@ class ExpenseDecorator implements DecoratorInterface if($expense && method_exists($this, $key)) { return $this->{$key}($expense); + } elseif($expense && $expense->{$key}) { + return $expense->{$key}; } return ''; } - public function amount(Expense $expense) - { - return $expense->amount ?? 0; - } public function category_id(Expense $expense) { return $expense->category ? $expense->category->name : ''; } + public function client_id(Expense $expense) { return $expense->client ? $expense->client->present()->name() : ''; } - public function custom_value1(Expense $expense) - { - return $expense->custom_value1 ?? ''; - } - public function custom_value2(Expense $expense) - { - return $expense->custom_value2 ?? ''; - } - public function custom_value3(Expense $expense) - { - return $expense->custom_value3 ?? ''; - } - public function custom_value4(Expense $expense) - { - return $expense->custom_value4 ?? ''; - } + public function currency_id(Expense $expense) { return $expense->currency ? $expense->currency->code : $expense->company->currency()->code; @@ -85,17 +69,14 @@ class ExpenseDecorator implements DecoratorInterface { return $expense->payment_date ?? ''; } - public function number(Expense $expense) - { - return $expense->number ?? ''; - } + public function payment_type_id(Expense $expense) { return $expense->payment_type ? $expense->payment_type->name : ''; } public function private_notes(Expense $expense) { - return $expense->private_notes ?? ''; + return strip_tags($expense->private_notes ?? ''); } public function project_id(Expense $expense) { @@ -103,48 +84,9 @@ class ExpenseDecorator implements DecoratorInterface } public function public_notes(Expense $expense) { - return $expense->public_notes ?? ''; - } - public function tax_amount1(Expense $expense) - { - return $expense->tax_amount1 ?? 0; - } - public function tax_amount2(Expense $expense) - { - return $expense->tax_amount2 ?? 0; - } - public function tax_amount3(Expense $expense) - { - return $expense->tax_amount3 ?? 0; - } - public function tax_name1(Expense $expense) - { - return $expense->tax_name1 ?? ''; - } - public function tax_name2(Expense $expense) - { - return $expense->tax_name2 ?? ''; - } - public function tax_name3(Expense $expense) - { - return $expense->tax_name3 ?? ''; - } - public function tax_rate1(Expense $expense) - { - return $expense->tax_rate1 ?? 0; - } - public function tax_rate2(Expense $expense) - { - return $expense->tax_rate2 ?? 0; - } - public function tax_rate3(Expense $expense) - { - return $expense->tax_rate3 ?? 0; - } - public function transaction_reference(Expense $expense) - { - return $expense->transaction_reference ?? ''; + return strip_tags($expense->public_notes ?? ''); } + public function vendor_id(Expense $expense) { return $expense->vendor ? $expense->vendor->name : ''; diff --git a/app/Export/Decorators/InvoiceDecorator.php b/app/Export/Decorators/InvoiceDecorator.php index bea2f6678541..5de8817fac6f 100644 --- a/app/Export/Decorators/InvoiceDecorator.php +++ b/app/Export/Decorators/InvoiceDecorator.php @@ -23,36 +23,20 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface $invoice = $entity; } elseif($entity->invoice) { $invoice = $entity->invoice; + } elseif($entity->invoices()->exists()) { + $invoice = $entity->invoices()->first(); } if($invoice && method_exists($this, $key)) { return $this->{$key}($invoice); + }elseif($invoice && $invoice->{$key}){ + return $invoice->{$key}; } return ''; } - public function number(Invoice $invoice) - { - return $invoice->number ?? ''; - } - public function amount(Invoice $invoice) - { - return $invoice->amount ?? 0; - } - public function balance(Invoice $invoice) - { - return $invoice->balance ?? 0; - } - public function paid_to_date(Invoice $invoice) - { - return $invoice->paid_to_date ?? 0; - } - public function po_number(Invoice $invoice) - { - return $invoice->po_number ?? ''; - } public function date(Invoice $invoice) { return $invoice->date ?? ''; @@ -63,11 +47,11 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface } public function terms(Invoice $invoice) { - return $invoice->terms ?? ''; + return strip_tags($invoice->terms ?? ''); } public function footer(Invoice $invoice) { - return $invoice->footer ?? ''; + return strip_tags($invoice->footer ?? ''); } public function status(Invoice $invoice) { @@ -75,7 +59,7 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface } public function public_notes(Invoice $invoice) { - return $invoice->public_notes ?? ''; + return strip_tags($invoice->public_notes ?? ''); } public function private_notes(Invoice $invoice) { @@ -89,42 +73,13 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface { return $invoice->is_amount_discount ? ctrans('texts.yes') : ctrans('texts.no'); } - public function discount(Invoice $invoice) - { - return $invoice->discount ?? 0; - } - public function partial(Invoice $invoice) - { - return $invoice->partial ?? 0; - } + public function partial_due_date(Invoice $invoice) { return $invoice->partial_due_date ?? ''; } - public function custom_surcharge1(Invoice $invoice) - { - return $invoice->custom_surcharge1 ?? 0; - } - public function custom_surcharge2(Invoice $invoice) - { - return $invoice->custom_surcharge2 ?? 0; - } - public function custom_surcharge3(Invoice $invoice) - { - return $invoice->custom_surcharge3 ?? 0; - } - public function custom_surcharge4(Invoice $invoice) - { - return $invoice->custom_surcharge4 ?? 0; - } - public function exchange_rate(Invoice $invoice) - { - return $invoice->exchange_rate ?? 0; - } - public function total_taxes(Invoice $invoice) - { - return $invoice->total_taxes ?? 0; - } + + public function assigned_user_id(Invoice $invoice) { return $invoice->assigned_user ? $invoice->assigned_user->present()->name(): ''; @@ -133,46 +88,7 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface { return $invoice->user ? $invoice->user->present()->name(): ''; } - public function custom_value1(Invoice $invoice) - { - return $invoice->custom_value1 ?? ''; - } - public function custom_value2(Invoice $invoice) - { - return $invoice->custom_value2 ?? ''; - } - public function custom_value3(Invoice $invoice) - { - return $invoice->custom_value3 ?? ''; - } - public function custom_value4(Invoice $invoice) - { - return $invoice->custom_value4 ?? ''; - } - public function tax_name1(Invoice $invoice) - { - return $invoice->tax_name1 ?? ''; - } - public function tax_name2(Invoice $invoice) - { - return $invoice->tax_name2 ?? ''; - } - public function tax_name3(Invoice $invoice) - { - return $invoice->tax_name3 ?? ''; - } - public function tax_rate1(Invoice $invoice) - { - return $invoice->tax_rate1 ?? 0; - } - public function tax_rate2(Invoice $invoice) - { - return $invoice->tax_rate2 ?? 0; - } - public function tax_rate3(Invoice $invoice) - { - return $invoice->tax_rate3 ?? 0; - } + public function recurring_id(Invoice $invoice) { return $invoice->recurring_invoice ? $invoice->recurring_invoice->number : ''; diff --git a/tests/Feature/Export/ReportCsvGenerationTest.php b/tests/Feature/Export/ReportCsvGenerationTest.php index ca6e4a5817bb..2470876d55cf 100644 --- a/tests/Feature/Export/ReportCsvGenerationTest.php +++ b/tests/Feature/Export/ReportCsvGenerationTest.php @@ -890,10 +890,11 @@ class ReportCsvGenerationTest extends TestCase $csv = $response->body(); + nlog($csv); $this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Payment Amount')); $this->assertEquals(now()->addSeconds($this->company->timezone()->utc_offset)->format('Y-m-d'), $this->getFirstValueByColumn($csv, 'Payment Date')); - // $this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number')); + $this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number')); $this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Invoice Amount')); $this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name')); $this->assertEquals(0, $this->getFirstValueByColumn($csv, 'Client Balance'));