Skip to content

[1.8] Main app: client model and controller — save and load e-invoicing fields #57

Description

@nielsdrost7

Target repository: InvoicePlane (main app) · branch prep/v180
Related feature issues: #13 · #14
Depends on: #55 — DB migration · #56 — client form UI

What to do

1. Mdl_clients — add new columns to allowed fields

Add client_peppol_id and client_company_number to the allowed fields array in Mdl_clients so the standard save() call persists them automatically. No extra code is needed beyond this.

2. Client controller — meta upsert on save

After Mdl_clients->save(), explicitly upsert the two FatturaPA meta fields into ip_client_meta. These are not columns and are not saved by the model:

foreach (['client_einvoice_sdi_code', 'client_einvoice_pec_email'] as $key) {
    $value = $this->input->post($key) ?: null;
    // INSERT INTO ip_client_meta (client_id, meta_key, meta_value) VALUES (?, ?, ?)
    // ON DUPLICATE KEY UPDATE meta_value = VALUES(meta_value)
}

Clearing a field (empty string submitted) should set the meta row to NULL or delete the row.

3. Client controller — meta load on edit

When loading a client for the edit form, read both meta keys back from ip_client_meta and pass them to the view:

$meta_rows = $this->db->get_where('ip_client_meta', ['client_id' => $id])->result();
$client_meta = array_column($meta_rows, 'meta_value', 'meta_key');
// Pass $client_meta['client_einvoice_sdi_code'] and ['client_einvoice_pec_email'] to view

Acceptance criteria

  • client_peppol_id and client_company_number saved via standard Mdl_clients->save()
  • client_einvoice_sdi_code and client_einvoice_pec_email upserted into ip_client_meta after save
  • Client edit form pre-populates all four fields correctly on load
  • Clearing a meta field (empty string) removes or nullifies the meta row

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