mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04: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;
|
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
|
* @param $name
|
||||||
* @return null
|
* @return null
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php namespace App\Ninja\Import\CSV;
|
<?php namespace App\Ninja\Import\CSV;
|
||||||
|
|
||||||
|
use Utils;
|
||||||
use App\Ninja\Import\BaseTransformer;
|
use App\Ninja\Import\BaseTransformer;
|
||||||
use League\Fractal\Resource\Item;
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ class ExpenseTransformer extends BaseTransformer
|
|||||||
{
|
{
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'amount' => isset($data->amount) ? (float) $data->amount : null,
|
'amount' => $this->getFloat($data, 'amount'),
|
||||||
'vendor_id' => isset($data->vendor) ? $this->getVendorId($data->vendor) : null,
|
'vendor_id' => isset($data->vendor) ? $this->getVendorId($data->vendor) : null,
|
||||||
'client_id' => isset($data->client) ? $this->getClientId($data->client) : 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,
|
'expense_date' => isset($data->expense_date) ? date('Y-m-d', strtotime($data->expense_date)) : null,
|
||||||
|
@ -26,7 +26,7 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
return [
|
return [
|
||||||
'client_id' => $this->getClientId($data->name),
|
'client_id' => $this->getClientId($data->name),
|
||||||
'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' => isset($data->paid) ? (float) $data->paid : null,
|
'paid' => $this->getFloat($data, 'paid'),
|
||||||
'po_number' => $this->getString($data, 'po_number'),
|
'po_number' => $this->getString($data, 'po_number'),
|
||||||
'terms' => $this->getString($data, 'terms'),
|
'terms' => $this->getString($data, 'terms'),
|
||||||
'public_notes' => $this->getString($data, 'public_notes'),
|
'public_notes' => $this->getString($data, 'public_notes'),
|
||||||
@ -35,11 +35,11 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
[
|
[
|
||||||
'product_key' => '',
|
'product_key' => '',
|
||||||
'notes' => $this->getString($data, 'notes'),
|
'notes' => $this->getString($data, 'notes'),
|
||||||
'cost' => isset($data->amount) ? (float) $data->amount : null,
|
'cost' => $this->getFloat($data, 'amount'),
|
||||||
'qty' => 1,
|
'qty' => 1,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ class PaymentTransformer extends BaseTransformer
|
|||||||
{
|
{
|
||||||
return new Item($data, function ($data) {
|
return new Item($data, function ($data) {
|
||||||
return [
|
return [
|
||||||
'amount' => $data->paid,
|
'amount' => $this->getFloat($data, 'paid'),
|
||||||
'payment_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
'payment_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
|
||||||
'client_id' => $data->client_id,
|
'client_id' => $data->client_id,
|
||||||
'invoice_id' => $data->invoice_id,
|
'invoice_id' => $data->invoice_id,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class ProductTransformer extends BaseTransformer
|
|||||||
return [
|
return [
|
||||||
'product_key' => $this->getString($data, 'product_key'),
|
'product_key' => $this->getString($data, 'product_key'),
|
||||||
'notes' => $this->getString($data, 'notes'),
|
'notes' => $this->getString($data, 'notes'),
|
||||||
'cost' => $this->getNumber($data, 'cost'),
|
'cost' => $this->getFloat($data, 'cost'),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user