1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 09:51:35 +02:00
invoiceninja/app/Ninja/Import/CSV/ClientTransformer.php

36 lines
1.3 KiB
PHP
Raw Normal View History

2015-11-24 20:45:38 +01:00
<?php namespace App\Ninja\Import\CSV;
2015-12-08 11:10:20 +01:00
use App\Ninja\Import\BaseTransformer;
2015-11-24 20:45:38 +01:00
use League\Fractal\Resource\Item;
2015-12-08 11:10:20 +01:00
class ClientTransformer extends BaseTransformer
2015-11-24 20:45:38 +01:00
{
2015-12-08 11:10:20 +01:00
public function transform($data)
2015-11-24 20:45:38 +01:00
{
2015-12-08 11:10:20 +01:00
if (isset($data->name) && $this->hasClient($data->name)) {
2015-11-24 20:45:38 +01:00
return false;
}
2015-12-08 11:10:20 +01:00
return new Item($data, function ($data) {
2015-11-24 20:45:38 +01:00
return [
2015-12-31 16:09:45 +01:00
'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'),
2015-11-24 20:45:38 +01:00
'contacts' => [
[
2015-12-31 16:09:45 +01:00
'first_name' => $this->getString($data, 'first_name'),
'last_name' => $this->getString($data, 'last_name'),
'email' => $this->getString($data, 'email'),
'phone' => $this->getString($data, 'phone'),
2015-11-24 20:45:38 +01:00
],
],
2015-12-08 11:10:20 +01:00
'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null,
2015-11-24 20:45:38 +01:00
];
});
}
}