mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Improved number parsing for CSV import
This commit is contained in:
parent
b7465a8f17
commit
4658abfbd4
@ -63,6 +63,16 @@ class BaseTransformer extends TransformerAbstract
|
||||
return (isset($data->$field) && $data->$field) ? $data->$field : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $field
|
||||
* @return float
|
||||
*/
|
||||
protected function getFloat($data, $field)
|
||||
{
|
||||
return (isset($data->$field) && $data->$field) ? Utils::parseFloat($data->$field) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return null
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace App\Ninja\Import\CSV;
|
||||
|
||||
use Utils;
|
||||
use App\Ninja\Import\BaseTransformer;
|
||||
use League\Fractal\Resource\Item;
|
||||
|
||||
@ -16,7 +17,7 @@ class ExpenseTransformer extends BaseTransformer
|
||||
{
|
||||
return new Item($data, function ($data) {
|
||||
return [
|
||||
'amount' => isset($data->amount) ? (float) $data->amount : null,
|
||||
'amount' => $this->getFloat($data, 'amount'),
|
||||
'vendor_id' => isset($data->vendor) ? $this->getVendorId($data->vendor) : null,
|
||||
'client_id' => isset($data->client) ? $this->getClientId($data->client) : null,
|
||||
'expense_date' => isset($data->expense_date) ? date('Y-m-d', strtotime($data->expense_date)) : null,
|
||||
|
@ -26,7 +26,7 @@ class InvoiceTransformer extends BaseTransformer
|
||||
return [
|
||||
'client_id' => $this->getClientId($data->name),
|
||||
'invoice_number' => isset($data->invoice_number) ? $this->getInvoiceNumber($data->invoice_number) : null,
|
||||
'paid' => isset($data->paid) ? (float) $data->paid : null,
|
||||
'paid' => $this->getFloat($data, 'paid'),
|
||||
'po_number' => $this->getString($data, 'po_number'),
|
||||
'terms' => $this->getString($data, 'terms'),
|
||||
'public_notes' => $this->getString($data, 'public_notes'),
|
||||
@ -35,11 +35,11 @@ class InvoiceTransformer extends BaseTransformer
|
||||
[
|
||||
'product_key' => '',
|
||||
'notes' => $this->getString($data, 'notes'),
|
||||
'cost' => isset($data->amount) ? (float) $data->amount : null,
|
||||
'cost' => $this->getFloat($data, 'amount'),
|
||||
'qty' => 1,
|
||||
]
|
||||
],
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ class PaymentTransformer extends BaseTransformer
|
||||
{
|
||||
return new Item($data, function ($data) {
|
||||
return [
|
||||
'amount' => $data->paid,
|
||||
'amount' => $this->getFloat($data, 'paid'),
|
||||
'payment_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
||||
'client_id' => $data->client_id,
|
||||
'invoice_id' => $data->invoice_id,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class ProductTransformer extends BaseTransformer
|
||||
return [
|
||||
'product_key' => $this->getString($data, 'product_key'),
|
||||
'notes' => $this->getString($data, 'notes'),
|
||||
'cost' => $this->getNumber($data, 'cost'),
|
||||
'cost' => $this->getFloat($data, 'cost'),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user