From b4c45e0a47f8c4aa97f149f704a2f614f7a5a14e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 2 Dec 2023 15:23:49 +1100 Subject: [PATCH] v5.7.56 --- app/Export/CSV/ExpenseExport.php | 3 ++- app/Export/CSV/RecurringInvoiceExport.php | 4 ++-- app/Export/CSV/TaskExport.php | 10 ++++++---- app/Export/Decorators/PaymentDecorator.php | 6 ++++-- app/Export/Decorators/TaskDecorator.php | 4 ++-- tests/Feature/Export/ReportCsvGenerationTest.php | 8 +++----- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index a9bf09901bb0..a2f48805acb3 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -106,7 +106,8 @@ class ExpenseExport extends BaseExport private function buildRow(Expense $expense) :array { $transformed_expense = $this->expense_transformer->transform($expense); - + $transformed_expense['currency_id'] = $expense->currency ? $expense->currency->code : $expense->company->currency()->code; + $entity = []; foreach (array_values($this->input['report_keys']) as $key) { diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index 9f543bee03c3..b3c0487a45a5 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -110,7 +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); +// nlog($transformed_invoice); $entity = []; @@ -128,7 +128,7 @@ nlog($transformed_invoice); } } -nlog($entity); +// nlog($entity); return $entity; // return $this->decorateAdvancedFields($invoice, $entity); } diff --git a/app/Export/CSV/TaskExport.php b/app/Export/CSV/TaskExport.php index 191089987bb1..332c9d8807d9 100644 --- a/app/Export/CSV/TaskExport.php +++ b/app/Export/CSV/TaskExport.php @@ -138,18 +138,20 @@ class TaskExport extends BaseExport } elseif (array_key_exists($key, $transformed_entity)) { $entity[$key] = $transformed_entity[$key]; } elseif (in_array($key, ['task.start_date', 'task.end_date', 'task.duration'])) { - // + $entity[$key] = ''; } else { // nlog($key); $entity[$key] = $this->decorator->transform($key, $task); // $entity[$key] = $this->resolveKey($key, $task, $this->entity_transformer); } + // $entity['task.start_date'] = ''; + // $entity['task.end_date'] = ''; + // $entity['task.duration'] = ''; + } - $entity['task.start_date'] = ''; - $entity['task.end_date'] = ''; - $entity['task.duration'] = ''; + if (is_null($task->time_log) || (is_array(json_decode($task->time_log, 1)) && count(json_decode($task->time_log, 1)) == 0)) { $this->storage_array[] = $entity; diff --git a/app/Export/Decorators/PaymentDecorator.php b/app/Export/Decorators/PaymentDecorator.php index 7366b580824b..0c952cb46759 100644 --- a/app/Export/Decorators/PaymentDecorator.php +++ b/app/Export/Decorators/PaymentDecorator.php @@ -26,6 +26,8 @@ class PaymentDecorator extends Decorator implements DecoratorInterface $payment = $entity; } elseif($entity->payment) { $payment = $entity->payment; + } elseif($entity->payments()->exists()) { + $payment = $entity->payments()->first(); } if($key == 'amount' && (!$entity instanceof Payment)) { @@ -41,10 +43,10 @@ class PaymentDecorator extends Decorator implements DecoratorInterface if($payment && method_exists($this, $key)) { return $this->{$key}($payment); } - - if($payment && ($payment->{$key} ?? false)){ + elseif($payment && $payment->{$key}){ return $payment->{$key}; } + return ''; } diff --git a/app/Export/Decorators/TaskDecorator.php b/app/Export/Decorators/TaskDecorator.php index 32a81e6a7097..912abe4f9c85 100644 --- a/app/Export/Decorators/TaskDecorator.php +++ b/app/Export/Decorators/TaskDecorator.php @@ -30,8 +30,8 @@ class TaskDecorator extends Decorator implements DecoratorInterface if($task && method_exists($this, $key)) { return $this->{$key}($task); - } elseif($task->{$key}) { - return $task->{$key} ?? ''; + } elseif($task && $task->{$key}) { + return $task->{$key}; } return ''; diff --git a/tests/Feature/Export/ReportCsvGenerationTest.php b/tests/Feature/Export/ReportCsvGenerationTest.php index 2470876d55cf..397e00c321de 100644 --- a/tests/Feature/Export/ReportCsvGenerationTest.php +++ b/tests/Feature/Export/ReportCsvGenerationTest.php @@ -655,7 +655,7 @@ class ReportCsvGenerationTest extends TestCase $csv = $response->body(); - +// nlog($csv); $this->assertEquals(3600, $this->getFirstValueByColumn($csv, 'Task Duration')); $this->assertEquals('test1', $this->getFirstValueByColumn($csv, 'Task Description')); $this->assertEquals('16/Jul/2023', $this->getFirstValueByColumn($csv, 'Task Start Date')); @@ -890,7 +890,7 @@ class ReportCsvGenerationTest extends TestCase $csv = $response->body(); - nlog($csv); + // 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')); @@ -1765,7 +1765,7 @@ class ReportCsvGenerationTest extends TestCase $data = [ 'date_range' => 'all', - 'report_keys' => ["client.name","invoice.number","invoice.amount","payment.date", "payment.amount"], + 'report_keys' => ["client.name","invoice.number","invoice.amount", "payment.date", "payment.amount"], 'send_email' => false, ]; @@ -1784,13 +1784,11 @@ class ReportCsvGenerationTest extends TestCase $csv = $response->body(); - $this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name')); $this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number')); $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')); - } public function testClientContactCsvGeneration()