diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 09f5726b2f42..304782acd6c7 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -105,6 +105,7 @@ class Invoice extends EntityModel implements BalanceAffecting { return [ 'name', + 'email', 'invoice_number', 'po_number', 'invoice_date', @@ -130,6 +131,7 @@ class Invoice extends EntityModel implements BalanceAffecting return [ 'number^po' => 'invoice_number', 'client|organization' => 'name', + 'email' => 'email', 'paid^date' => 'paid', 'invoice date|create date' => 'invoice_date', 'po number' => 'po_number', @@ -140,7 +142,7 @@ class Invoice extends EntityModel implements BalanceAffecting 'description' => 'item_notes', 'quantity|qty' => 'item_quantity', 'amount|cost' => 'item_cost', - 'product|item' => 'item_product', + 'product' => 'item_product', 'tax' => 'item_tax1', ]; } diff --git a/app/Ninja/Import/CSV/InvoiceTransformer.php b/app/Ninja/Import/CSV/InvoiceTransformer.php index 1e711fb18cd5..ec50fe07ed51 100644 --- a/app/Ninja/Import/CSV/InvoiceTransformer.php +++ b/app/Ninja/Import/CSV/InvoiceTransformer.php @@ -17,7 +17,9 @@ class InvoiceTransformer extends BaseTransformer */ public function transform($data) { - if (! $this->getClientId($data->name)) { + $clientId = $this->getClientId($data->email) ?: $this->getClientId($data->name); + + if (! $clientId) { return false; } @@ -25,9 +27,9 @@ class InvoiceTransformer extends BaseTransformer return false; } - return new Item($data, function ($data) { + return new Item($data, function ($data) use ($clientId) { return [ - 'client_id' => $this->getClientId($data->name), + 'client_id' => $clientId, 'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null, 'paid' => $this->getFloat($data, 'paid'), 'po_number' => $this->getString($data, 'po_number'),