Improve CSV invoice import

This commit is contained in:
Hillel Coren 2018-01-01 15:20:36 +02:00
parent 1ac4846f0d
commit 4636cef5d6
2 changed files with 8 additions and 4 deletions

View File

@ -105,6 +105,7 @@ class Invoice extends EntityModel implements BalanceAffecting
{ {
return [ return [
'name', 'name',
'email',
'invoice_number', 'invoice_number',
'po_number', 'po_number',
'invoice_date', 'invoice_date',
@ -130,6 +131,7 @@ class Invoice extends EntityModel implements BalanceAffecting
return [ return [
'number^po' => 'invoice_number', 'number^po' => 'invoice_number',
'client|organization' => 'name', 'client|organization' => 'name',
'email' => 'email',
'paid^date' => 'paid', 'paid^date' => 'paid',
'invoice date|create date' => 'invoice_date', 'invoice date|create date' => 'invoice_date',
'po number' => 'po_number', 'po number' => 'po_number',
@ -140,7 +142,7 @@ class Invoice extends EntityModel implements BalanceAffecting
'description' => 'item_notes', 'description' => 'item_notes',
'quantity|qty' => 'item_quantity', 'quantity|qty' => 'item_quantity',
'amount|cost' => 'item_cost', 'amount|cost' => 'item_cost',
'product|item' => 'item_product', 'product' => 'item_product',
'tax' => 'item_tax1', 'tax' => 'item_tax1',
]; ];
} }

View File

@ -17,7 +17,9 @@ class InvoiceTransformer extends BaseTransformer
*/ */
public function transform($data) public function transform($data)
{ {
if (! $this->getClientId($data->name)) { $clientId = $this->getClientId($data->email) ?: $this->getClientId($data->name);
if (! $clientId) {
return false; return false;
} }
@ -25,9 +27,9 @@ class InvoiceTransformer extends BaseTransformer
return false; return false;
} }
return new Item($data, function ($data) { return new Item($data, function ($data) use ($clientId) {
return [ return [
'client_id' => $this->getClientId($data->name), 'client_id' => $clientId,
'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null, 'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null,
'paid' => $this->getFloat($data, 'paid'), 'paid' => $this->getFloat($data, 'paid'),
'po_number' => $this->getString($data, 'po_number'), 'po_number' => $this->getString($data, 'po_number'),