From a4a03cc3ed9ba13ddef07bb8bfa251a3cf722c25 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 14 Jul 2023 19:08:55 +1000 Subject: [PATCH] Client Export --- app/Export/CSV/BaseExport.php | 4 +++- app/Export/CSV/ClientExport.php | 17 +++++++++++------ app/Filters/InvoiceFilters.php | 13 ------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index ca5e9c1a0953..d15e51b477e5 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -75,7 +75,8 @@ class BaseExport protected array $client_report_keys = [ "name" => "client.name", - "user" => "client.user_id", + "user" => "client.user", + "assigned_user" => "client.assigned_user", "balance" => "client.balance", "paid_to_date" => "client.paid_to_date", "currency" => "client.currency_id", @@ -796,6 +797,7 @@ class BaseExport $header[] = "{$prefix} " . ctrans("texts.{$key}"); } +nlog($header); return $header; } diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index c41dcc7a63df..21a862ec9d90 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -82,7 +82,6 @@ class ClientExport extends BaseExport ]; public array $forced_keys = [ - 'status', ]; public function __construct(Company $company, array $input) @@ -144,11 +143,11 @@ class ClientExport extends BaseExport $keyval = array_search($key, $this->entity_keys); if (is_array($parts) && $parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { - $entity[$keyval] = $transformed_client[$parts[1]]; + $entity[$key] = $transformed_client[$parts[1]]; } elseif (is_array($parts) && $parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) { - $entity[$keyval] = $transformed_contact[$parts[1]]; + $entity[$key] = $transformed_contact[$parts[1]]; } else { - $entity[$keyval] = ''; + $entity[$key] = ''; } } @@ -157,6 +156,14 @@ class ClientExport extends BaseExport private function decorateAdvancedFields(Client $client, array $entity) :array { + if (in_array('client.user', $this->input['report_keys'])) { + $entity['client.user'] = $client->user->present()->name(); + } + + if (in_array('client.assigned_user', $this->input['report_keys'])) { + $entity['client.assigned_user'] = $client->assigned_user ? $client->user->present()->name() : ''; + } + if (in_array('client.country_id', $this->input['report_keys'])) { $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : ''; } @@ -173,8 +180,6 @@ class ClientExport extends BaseExport $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : ''; } - $entity['status'] = $this->calculateStatus($client); - return $entity; } diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index 3f1feccc3610..1e07412eda4c 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -135,19 +135,6 @@ class InvoiceFilters extends QueryFilters } - - - /** - * @return Builder - * @throws RuntimeException - */ - public function without_deleted_clients(): Builder - { - return $this->builder->whereHas('client', function ($query) { - $query->where('is_deleted', 0); - }); - } - /** * @return Builder * @return Builder