1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Ninja/Import/CSV/ClientTransformer.php

36 lines
1.4 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 [
'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,
'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,
],
],
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
];
});
}
}