Client Export

This commit is contained in:
David Bomba 2023-07-14 19:08:55 +10:00
parent 1127f3ea5f
commit a4a03cc3ed
3 changed files with 14 additions and 20 deletions

View File

@ -75,7 +75,8 @@ class BaseExport
protected array $client_report_keys = [ protected array $client_report_keys = [
"name" => "client.name", "name" => "client.name",
"user" => "client.user_id", "user" => "client.user",
"assigned_user" => "client.assigned_user",
"balance" => "client.balance", "balance" => "client.balance",
"paid_to_date" => "client.paid_to_date", "paid_to_date" => "client.paid_to_date",
"currency" => "client.currency_id", "currency" => "client.currency_id",
@ -796,6 +797,7 @@ class BaseExport
$header[] = "{$prefix} " . ctrans("texts.{$key}"); $header[] = "{$prefix} " . ctrans("texts.{$key}");
} }
nlog($header);
return $header; return $header;
} }

View File

@ -82,7 +82,6 @@ class ClientExport extends BaseExport
]; ];
public array $forced_keys = [ public array $forced_keys = [
'status',
]; ];
public function __construct(Company $company, array $input) public function __construct(Company $company, array $input)
@ -144,11 +143,11 @@ class ClientExport extends BaseExport
$keyval = array_search($key, $this->entity_keys); $keyval = array_search($key, $this->entity_keys);
if (is_array($parts) && $parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { 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)) { } 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 { } else {
$entity[$keyval] = ''; $entity[$key] = '';
} }
} }
@ -157,6 +156,14 @@ class ClientExport extends BaseExport
private function decorateAdvancedFields(Client $client, array $entity) :array 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'])) { if (in_array('client.country_id', $this->input['report_keys'])) {
$entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : ''; $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['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : '';
} }
$entity['status'] = $this->calculateStatus($client);
return $entity; return $entity;
} }

View File

@ -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
* @return Builder * @return Builder