Adjustments for activity exports

This commit is contained in:
David Bomba 2023-09-14 15:34:02 +10:00
parent cee315cf6d
commit 2558c4345f
2 changed files with 40 additions and 9 deletions

View File

@ -57,9 +57,11 @@ class ActivityExport extends BaseExport
return ['identifier' => $value, 'display_value' => $headerdisplay[$value]]; return ['identifier' => $value, 'display_value' => $headerdisplay[$value]];
})->toArray(); })->toArray();
$report = $query->cursor() $report = $query->cursor()
->map(function ($credit) { ->map(function ($resource) {
return $this->buildActivityRow($credit); $row = $this->buildActivityRow($resource);
return $this->processMetaData($row, $resource);
})->toArray(); })->toArray();
return array_merge(['columns' => $header], $report); return array_merge(['columns' => $header], $report);
@ -70,6 +72,8 @@ class ActivityExport extends BaseExport
return [ return [
Carbon::parse($activity->created_at)->format($this->date_format), Carbon::parse($activity->created_at)->format($this->date_format),
ctrans("texts.activity_{$activity->activity_type_id}",[ ctrans("texts.activity_{$activity->activity_type_id}",[
'payment_amount' => $activity->payment ? $activity->payment->amount : '',
'adjustment' => $activity->payment ? $activity->payment->refunded : '',
'client' => $activity->client ? $activity->client->present()->name() : '', 'client' => $activity->client ? $activity->client->present()->name() : '',
'contact' => $activity->contact ? $activity->contact->present()->name() : '', 'contact' => $activity->contact ? $activity->contact->present()->name() : '',
'quote' => $activity->quote ? $activity->quote->number : '', 'quote' => $activity->quote ? $activity->quote->number : '',
@ -101,7 +105,7 @@ class ActivityExport extends BaseExport
$this->date_format = DateFormat::find($this->company->settings->date_format_id)->format; $this->date_format = DateFormat::find($this->company->settings->date_format_id)->format;
ksort($this->entity_keys); // ksort($this->entity_keys);
if (count($this->input['report_keys']) == 0) { if (count($this->input['report_keys']) == 0) {
$this->input['report_keys'] = array_values($this->entity_keys); $this->input['report_keys'] = array_values($this->entity_keys);
@ -146,4 +150,27 @@ class ActivityExport extends BaseExport
{ {
return $entity; return $entity;
} }
public function processMetaData(array $row, $resource): array
{
$clean_row = [];
foreach (array_values($this->input['report_keys']) as $key => $value) {
nlog("key: {$key}, value: {$value}");
nlog($row);
$clean_row[$key]['entity'] = 'activity';
$clean_row[$key]['id'] = $key;
$clean_row[$key]['hashed_id'] = null;
$clean_row[$key]['value'] = $row[$key];
$clean_row[$key]['identifier'] = $value;
$clean_row[$key]['display_value'] = $row[$key];
}
return $clean_row;
}
} }

View File

@ -11,6 +11,7 @@
namespace App\Export\CSV; namespace App\Export\CSV;
use App\Models\Activity;
use App\Models\Quote; use App\Models\Quote;
use App\Utils\Number; use App\Utils\Number;
use App\Models\Client; use App\Models\Client;
@ -915,13 +916,13 @@ class BaseExport
$helper = new Helpers(); $helper = new Helpers();
$header = []; $header = [];
nlog("header"); // nlog("header");
foreach ($this->input['report_keys'] as $value) { foreach ($this->input['report_keys'] as $value) {
$key = array_search($value, $this->entity_keys); $key = array_search($value, $this->entity_keys);
$original_key = $key; $original_key = $key;
nlog("{$key} => {$value}"); // nlog("{$key} => {$value}");
$prefix = ''; $prefix = '';
if(!$key) { if(!$key) {
@ -991,7 +992,7 @@ class BaseExport
$prefix = ''; $prefix = '';
} }
nlog("key => {$key}"); // nlog("key => {$key}");
$key = str_replace('item.', '', $key); $key = str_replace('item.', '', $key);
$key = str_replace('recurring_invoice.', '', $key); $key = str_replace('recurring_invoice.', '', $key);
@ -1045,7 +1046,7 @@ class BaseExport
} }
} }
nlog($header); // nlog($header);
return $header; return $header;
} }
@ -1057,6 +1058,7 @@ class BaseExport
$entity = ''; $entity = '';
match ($class) { match ($class) {
Activity::class => $entity = 'activity',
Invoice::class => $entity = 'invoice', Invoice::class => $entity = 'invoice',
RecurringInvoice::class => $entity = 'recurring_invoice', RecurringInvoice::class => $entity = 'recurring_invoice',
Quote::class => $entity = 'quote', Quote::class => $entity = 'quote',
@ -1079,7 +1081,9 @@ class BaseExport
$report_keys = explode(".", $value); $report_keys = explode(".", $value);
$column_key = $value; $column_key = $value;
nlog($value);
nlog($report_keys);
nlog($row);
if($value == 'product_image') { if($value == 'product_image') {
$column_key = 'image'; $column_key = 'image';
$value = 'image'; $value = 'image';