Skip to content

[1.8] Generator data contract: pass ip_client_meta and ip_invoice_meta to all generators #60

Description

@nielsdrost7

Target repository: InvoicePlane-e-invoices · branch develop
Related feature issues: #13 · #15
Required by: #16, #17, #18, #19, #20, #21

Problem

New v1.8.0 fields are split across two storage layers:

  • Standard columns (client_peppol_id, client_company_number) — already present on the $client object, no change needed
  • Meta key→value pairs (client_einvoice_sdi_code, client_einvoice_pec_email, invoice_routing_code_1/2/3) — stored in ip_client_meta / ip_invoice_meta, not on the main objects

Generators currently receive $client and $invoice objects only. They have no way to access meta values. This must be solved before any generator can implement SdI/PEC routing (#19) or routing codes (#16, #17, #20).

What to do

1. E-invoicing controller (main app) — load meta before generator call

Before calling any generator, load both meta arrays:

$client_meta_rows = $this->db->get_where('ip_client_meta', ['client_id' => $client->client_id])->result();
$client_meta = array_column($client_meta_rows, 'meta_value', 'meta_key');

$invoice_meta_rows = $this->db->get_where('ip_invoice_meta', ['invoice_id' => $invoice->invoice_id])->result();
$invoice_meta = array_column($invoice_meta_rows, 'meta_value', 'meta_key');

Pass both arrays to the generator constructor or a new setMeta() method.

2. BaseXml — store meta as properties

Add $client_meta and $invoice_meta as protected properties on BaseXml so every subclass can access them:

protected array $client_meta  = [];
protected array $invoice_meta = [];

3. Safe access pattern (all generators)

$value = $this->client_meta['client_einvoice_sdi_code'] ?? null;
$code1 = $this->invoice_meta['invoice_routing_code_1'] ?? null;
// null-safe — no PHP warning if key absent

Acceptance criteria

  • $client_meta and $invoice_meta available in every generator via BaseXml properties
  • Missing key access returns null safely — no PHP warnings
  • No generator breaks when both meta arrays are empty []
  • Existing generators that don't yet use meta fields are unaffected
  • The pre-generation validator (see #21) receives the same meta arrays

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions