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

Recurring invoice export CSV

This commit is contained in:
David Bomba 2022-05-10 17:04:24 +10:00
parent f3ee7355c4
commit 252d9a3745
2 changed files with 24 additions and 51 deletions

View File

@ -71,6 +71,8 @@ class InvoiceExport extends BaseExport
'client', 'client',
'currency_id', 'currency_id',
'status', 'status',
'vendor',
'project',
]; ];
public function __construct(Company $company, array $input) public function __construct(Company $company, array $input)

View File

@ -63,49 +63,11 @@ class RecurringInvoiceExport extends BaseExport
'tax_rate3' => 'tax_rate3', 'tax_rate3' => 'tax_rate3',
'terms' => 'terms', 'terms' => 'terms',
'total_taxes' => 'total_taxes', 'total_taxes' => 'total_taxes',
'currency' => 'client_id', 'currency' => 'currency_id',
'vendor' => 'vendor_id', 'vendor' => 'vendor_id',
'project' => 'project_id', 'project' => 'project_id',
]; ];
protected array $all_keys = [
'amount',
'balance',
'client_id',
'custom_surcharge1',
'custom_surcharge2',
'custom_surcharge3',
'custom_surcharge4',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
'date',
'discount',
'due_date',
'exchange_rate',
'footer',
'number',
'paid_to_date',
'partial',
'partial_due_date',
'po_number',
'private_notes',
'public_notes',
'status_id',
'tax_name1',
'tax_name2',
'tax_name3',
'tax_rate1',
'tax_rate2',
'tax_rate3',
'terms',
'total_taxes',
'client_id',
'vendor_id',
'project_id',
];
private array $decorate_keys = [ private array $decorate_keys = [
'country', 'country',
'client', 'client',
@ -135,7 +97,7 @@ class RecurringInvoiceExport 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());
@ -167,7 +129,13 @@ class RecurringInvoiceExport extends BaseExport
foreach(array_values($this->input['report_keys']) as $key){ foreach(array_values($this->input['report_keys']) as $key){
$entity[$key] = $transformed_invoice[$key]; $keyval = array_search($key, $this->entity_keys);
if(array_key_exists($key, $transformed_invoice))
$entity[$keyval] = $transformed_invoice[$key];
else
$entity[$keyval] = '';
} }
return $this->decorateAdvancedFields($invoice, $entity); return $this->decorateAdvancedFields($invoice, $entity);
@ -176,20 +144,23 @@ class RecurringInvoiceExport extends BaseExport
private function decorateAdvancedFields(RecurringInvoice $invoice, array $entity) :array private function decorateAdvancedFields(RecurringInvoice $invoice, array $entity) :array
{ {
if(array_key_exists('currency', $entity)) if(in_array('country_id', $this->input['report_keys']))
$entity['currency'] = $invoice->client->currency()->code; $entity['country'] = $invoice->client->country ? ctrans("texts.country_{$invoice->client->country->name}") : "";
if(array_key_exists('client_id', $entity)) if(in_array('currency_id', $this->input['report_keys']))
$entity['client_id'] = $invoice->client->present()->name(); $entity['currency'] = $invoice->client->currency() ? $invoice->client->currency()->code : $invoice->company->currency()->code;
if(array_key_exists('status_id', $entity)) if(in_array('client_id', $this->input['report_keys']))
$entity['status_id'] = $invoice->stringStatus($invoice->status_id); $entity['client'] = $invoice->client->present()->name();
if(array_key_exists('vendor_id', $entity)) if(in_array('status_id',$this->input['report_keys']))
$entity['vendor_id'] = $invoice->vendor()->exists() ? $invoice->vendor->name : ''; $entity['status'] = $invoice->stringStatus($invoice->status_id);
if(array_key_exists('project_id', $entity)) if(in_array('project_id',$this->input['report_keys']))
$entity['project'] = $invoice->project()->exists() ? $invoice->project->name : ''; $entity['project'] = $invoice->project ? $invoice->project->name : "";
if(in_array('vendor_id',$this->input['report_keys']))
$entity['vendor'] = $invoice->vendor ? $invoice->vendor->name : "";
return $entity; return $entity;
} }