1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for contact exports

This commit is contained in:
David Bomba 2022-05-10 13:59:39 +10:00
parent 0d812f97a0
commit 9c359bc3b4
2 changed files with 18 additions and 63 deletions

View File

@ -144,8 +144,7 @@ class ClientExport extends BaseExport
$parts = explode(".",$key); $parts = explode(".",$key);
$keyval = array_search ($key, $this->entity_keys); $keyval = array_search($key, $this->entity_keys);
if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) { if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
$entity[$keyval] = $transformed_client[$parts[1]]; $entity[$keyval] = $transformed_client[$parts[1]];
@ -158,8 +157,6 @@ class ClientExport extends BaseExport
} }
nlog($this->decorateAdvancedFields($client, $entity));
return $this->decorateAdvancedFields($client, $entity); return $this->decorateAdvancedFields($client, $entity);
} }

View File

@ -50,7 +50,7 @@ class ContactExport extends BaseExport
'name' => 'client.name', 'name' => 'client.name',
'number' => 'client.number', 'number' => 'client.number',
'paid_to_date' => 'client.paid_to_date', 'paid_to_date' => 'client.paid_to_date',
'phone' => 'client.phone', 'client_phone' => 'client.phone',
'postal_code' => 'client.postal_code', 'postal_code' => 'client.postal_code',
'private_notes' => 'client.private_notes', 'private_notes' => 'client.private_notes',
'public_notes' => 'client.public_notes', 'public_notes' => 'client.public_notes',
@ -66,7 +66,7 @@ class ContactExport extends BaseExport
'currency' => 'client.currency', 'currency' => 'client.currency',
'first_name' => 'contact.first_name', 'first_name' => 'contact.first_name',
'last_name' => 'contact.last_name', 'last_name' => 'contact.last_name',
'phone' => 'contact.phone', 'contact_phone' => 'contact.phone',
'contact_custom_value1' => 'contact.custom_value1', 'contact_custom_value1' => 'contact.custom_value1',
'contact_custom_value2' => 'contact.custom_value2', 'contact_custom_value2' => 'contact.custom_value2',
'contact_custom_value3' => 'contact.custom_value3', 'contact_custom_value3' => 'contact.custom_value3',
@ -74,49 +74,6 @@ class ContactExport extends BaseExport
'email' => 'contact.email', 'email' => 'contact.email',
]; ];
protected array $all_keys = [
'client.address1',
'client.address2',
'client.balance',
'client.city',
'client.country_id',
'client.credit_balance',
'client.custom_value1',
'client.custom_value2',
'client.custom_value3',
'client.custom_value4',
'client.id_number',
'client.industry_id',
'client.last_login',
'client.name',
'client.number',
'client.paid_to_date',
'client.phone',
'client.postal_code',
'client.private_notes',
'client.public_notes',
'client.shipping_address1',
'client.shipping_address2',
'client.shipping_city',
'client.shipping_country_id',
'client.shipping_postal_code',
'client.shipping_state',
'client.state',
'client.vat_number',
'client.website',
'client.currency',
'contact.first_name',
'contact.last_name',
'contact.phone',
'contact.custom_value1',
'contact.custom_value2',
'contact.custom_value3',
'contact.custom_value4',
'contact.email',
];
private array $decorate_keys = [ private array $decorate_keys = [
'client.country_id', 'client.country_id',
'client.shipping_country_id', 'client.shipping_country_id',
@ -145,7 +102,7 @@ class ContactExport extends BaseExport
$this->csv = Writer::createFromString(); $this->csv = Writer::createFromString();
if(count($this->input['report_keys']) == 0) if(count($this->input['report_keys']) == 0)
$this->input['report_keys'] = $this->all_keys; $this->input['report_keys'] = array_values($this->entity_keys);
//insert the header //insert the header
$this->csv->insertOne($this->buildHeader()); $this->csv->insertOne($this->buildHeader());
@ -178,15 +135,16 @@ class ContactExport extends BaseExport
foreach(array_values($this->input['report_keys']) as $key){ foreach(array_values($this->input['report_keys']) as $key){
$parts = explode(".",$key); $parts = explode(".",$key);
$entity[$parts[1]] = ""; $keyval = array_search($key, $this->entity_keys);
if($parts[0] == 'client') { if($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
$entity[$parts[1]] = $transformed_client[$parts[1]]; $entity[$keyval] = $transformed_client[$parts[1]];
} }
elseif($parts[0] == 'contact') { elseif($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
$entity[$parts[1]] = $transformed_contact[$parts[1]]; $entity[$keyval] = $transformed_contact[$parts[1]];
} }
else
$entity[$keyval] = "";
} }
return $this->decorateAdvancedFields($contact->client, $entity); return $this->decorateAdvancedFields($contact->client, $entity);
@ -196,16 +154,16 @@ class ContactExport extends BaseExport
private function decorateAdvancedFields(Client $client, array $entity) :array private function decorateAdvancedFields(Client $client, array $entity) :array
{ {
if(array_key_exists('country_id', $entity)) if(in_array('client.country_id', $this->input['report_keys']))
$entity['country_id'] = $client->country ? ctrans("texts.country_{$client->country->name}") : ""; $entity['country'] = $client->country ? ctrans("texts.country_{$client->country->name}") : "";
if(array_key_exists('shipping_country_id', $entity)) if(in_array('client.shipping_country_id', $this->input['report_keys']))
$entity['shipping_country_id'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : ""; $entity['shipping_country'] = $client->shipping_country ? ctrans("texts.country_{$client->shipping_country->name}") : "";
if(array_key_exists('currency', $entity)) if(in_array('client.currency', $this->input['report_keys']))
$entity['currency'] = $client->currency()->code; $entity['currency'] = $client->currency() ? $client->currency()->code : $client->company->currency()->code;
if(array_key_exists('industry_id', $entity)) if(in_array('client.industry_id', $this->input['report_keys']))
$entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : ""; $entity['industry_id'] = $client->industry ? ctrans("texts.industry_{$client->industry->name}") : "";
return $entity; return $entity;