This commit is contained in:
David Bomba 2023-12-02 15:23:49 +11:00
parent 7d37e6cb2c
commit b4c45e0a47
6 changed files with 19 additions and 16 deletions

View File

@ -106,6 +106,7 @@ class ExpenseExport extends BaseExport
private function buildRow(Expense $expense) :array private function buildRow(Expense $expense) :array
{ {
$transformed_expense = $this->expense_transformer->transform($expense); $transformed_expense = $this->expense_transformer->transform($expense);
$transformed_expense['currency_id'] = $expense->currency ? $expense->currency->code : $expense->company->currency()->code;
$entity = []; $entity = [];

View File

@ -110,7 +110,7 @@ class RecurringInvoiceExport extends BaseExport
{ {
$transformed_invoice = $this->invoice_transformer->transform($invoice); $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 $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 = []; $entity = [];
@ -128,7 +128,7 @@ nlog($transformed_invoice);
} }
} }
nlog($entity); // nlog($entity);
return $entity; return $entity;
// return $this->decorateAdvancedFields($invoice, $entity); // return $this->decorateAdvancedFields($invoice, $entity);
} }

View File

@ -138,18 +138,20 @@ class TaskExport extends BaseExport
} elseif (array_key_exists($key, $transformed_entity)) { } elseif (array_key_exists($key, $transformed_entity)) {
$entity[$key] = $transformed_entity[$key]; $entity[$key] = $transformed_entity[$key];
} elseif (in_array($key, ['task.start_date', 'task.end_date', 'task.duration'])) { } elseif (in_array($key, ['task.start_date', 'task.end_date', 'task.duration'])) {
// $entity[$key] = '';
} else { } else {
// nlog($key); // nlog($key);
$entity[$key] = $this->decorator->transform($key, $task); $entity[$key] = $this->decorator->transform($key, $task);
// $entity[$key] = $this->resolveKey($key, $task, $this->entity_transformer); // $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)) { 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; $this->storage_array[] = $entity;

View File

@ -26,6 +26,8 @@ class PaymentDecorator extends Decorator implements DecoratorInterface
$payment = $entity; $payment = $entity;
} elseif($entity->payment) { } elseif($entity->payment) {
$payment = $entity->payment; $payment = $entity->payment;
} elseif($entity->payments()->exists()) {
$payment = $entity->payments()->first();
} }
if($key == 'amount' && (!$entity instanceof Payment)) { if($key == 'amount' && (!$entity instanceof Payment)) {
@ -41,10 +43,10 @@ class PaymentDecorator extends Decorator implements DecoratorInterface
if($payment && method_exists($this, $key)) { if($payment && method_exists($this, $key)) {
return $this->{$key}($payment); return $this->{$key}($payment);
} }
elseif($payment && $payment->{$key}){
if($payment && ($payment->{$key} ?? false)){
return $payment->{$key}; return $payment->{$key};
} }
return ''; return '';
} }

View File

@ -30,8 +30,8 @@ class TaskDecorator extends Decorator implements DecoratorInterface
if($task && method_exists($this, $key)) { if($task && method_exists($this, $key)) {
return $this->{$key}($task); return $this->{$key}($task);
} elseif($task->{$key}) { } elseif($task && $task->{$key}) {
return $task->{$key} ?? ''; return $task->{$key};
} }
return ''; return '';

View File

@ -655,7 +655,7 @@ class ReportCsvGenerationTest extends TestCase
$csv = $response->body(); $csv = $response->body();
// nlog($csv);
$this->assertEquals(3600, $this->getFirstValueByColumn($csv, 'Task Duration')); $this->assertEquals(3600, $this->getFirstValueByColumn($csv, 'Task Duration'));
$this->assertEquals('test1', $this->getFirstValueByColumn($csv, 'Task Description')); $this->assertEquals('test1', $this->getFirstValueByColumn($csv, 'Task Description'));
$this->assertEquals('16/Jul/2023', $this->getFirstValueByColumn($csv, 'Task Start Date')); $this->assertEquals('16/Jul/2023', $this->getFirstValueByColumn($csv, 'Task Start Date'));
@ -890,7 +890,7 @@ class ReportCsvGenerationTest extends TestCase
$csv = $response->body(); $csv = $response->body();
nlog($csv); // nlog($csv);
$this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Payment Amount')); $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(now()->addSeconds($this->company->timezone()->utc_offset)->format('Y-m-d'), $this->getFirstValueByColumn($csv, 'Payment Date'));
@ -1784,13 +1784,11 @@ class ReportCsvGenerationTest extends TestCase
$csv = $response->body(); $csv = $response->body();
$this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name')); $this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name'));
$this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number')); $this->assertEquals('12345', $this->getFirstValueByColumn($csv, 'Invoice Invoice Number'));
$this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Payment Amount')); $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(now()->addSeconds($this->company->timezone()->utc_offset)->format('Y-m-d'), $this->getFirstValueByColumn($csv, 'Payment Date'));
} }
public function testClientContactCsvGeneration() public function testClientContactCsvGeneration()