1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Added getString helper to CSV import

This commit is contained in:
Hillel Coren 2015-12-31 17:09:45 +02:00
parent db2e37d31b
commit 06c1534093
4 changed files with 47 additions and 40 deletions

View File

@ -19,6 +19,11 @@ class BaseTransformer extends TransformerAbstract
return isset($this->maps[ENTITY_CLIENT][$name]);
}
protected function getString($data, $field)
{
return (isset($data->$field) && $data->$field) ? $data->$field : null;
}
protected function getClientId($name)
{
$name = strtolower($name);

View File

@ -13,19 +13,19 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) {
return [
'name' => isset($data->name) ? $data->name : null,
'work_phone' => isset($data->work_phone) ? $data->work_phone : null,
'address1' => isset($data->address1) ? $data->address1 : null,
'city' => isset($data->city) ? $data->city : null,
'state' => isset($data->state) ? $data->state : null,
'postal_code' => isset($data->postal_code) ? $data->postal_code : null,
'private_notes' => isset($data->notes) ? $data->notes : null,
'name' => $this->getString($data, 'name'),
'work_phone' => $this->getString($data, 'work_phone'),
'address1' => $this->getString($data, 'address1'),
'city' => $this->getString($data, 'city'),
'state' => $this->getString($data, 'state'),
'postal_code' => $this->getString($data, 'postal_code'),
'private_notes' => $this->getString($data, 'notes'),
'contacts' => [
[
'first_name' => isset($data->first_name) ? $data->first_name : null,
'last_name' => isset($data->last_name) ? $data->last_name : null,
'email' => isset($data->email) ? $data->email : null,
'phone' => isset($data->phone) ? $data->phone : null,
'first_name' => $this->getString($data, 'first_name'),
'last_name' => $this->getString($data, 'last_name'),
'email' => $this->getString($data, 'email'),
'phone' => $this->getString($data, 'phone'),
],
],
'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null,

View File

@ -20,14 +20,14 @@ class InvoiceTransformer extends BaseTransformer
'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,
'po_number' => isset($data->po_number) ? $data->po_number : null,
'terms' => isset($data->terms) ? $data->terms : null,
'public_notes' => isset($data->notes) ? $data->notes : null,
'po_number' => $this->getString($data, 'po_number'),
'terms' => $this->getString($data, 'terms'),
'public_notes' => $this->getString($data, 'public_notes'),
'invoice_date_sql' => isset($data->invoice_date) ? $data->invoice_date : null,
'invoice_items' => [
[
'product_key' => '',
'notes' => isset($data->notes) ? $data->notes : null,
'notes' => $this->getString($data, 'notes'),
'cost' => isset($data->amount) ? (float) $data->amount : null,
'qty' => 1,
]

View File

@ -85,7 +85,8 @@ class ImportService
$data_index = $this->transformRow($source, $entityType, $row, $maps);
if ($data_index !== false) {
if($data_index !== true){// Wasn't merged with another row
if ($data_index !== true) {
// Wasn't merged with another row
$row_list[] = array('row' => $row, 'data_index' => $data_index);
}
} else {
@ -132,18 +133,18 @@ class ImportService
if ($entityType == ENTITY_INVOICE) {
if (empty($this->processedRows[$data['invoice_number']])) {
$this->processedRows[$data['invoice_number']] = $data;
}
else{
} else {
// Merge invoice items
$this->processedRows[$data['invoice_number']]['invoice_items'] = array_merge($this->processedRows[$data['invoice_number']]['invoice_items'], $data['invoice_items']);
return true;
}
}
else{
} else {
$this->processedRows[] = $data;
}
end($this->processedRows);
return key($this->processedRows);
}
@ -423,7 +424,8 @@ class ImportService
$data_index = $this->transformRow($source, $entityType, $row, $maps);
if ($data_index !== false) {
if($data_index !== true){// Wasn't merged with another row
if ($data_index !== true) {
// Wasn't merged with another row
$row_list[] = array('row' => $row, 'data_index' => $data_index);
}
} else {