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

45 lines
1.6 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;
/**
* Class ClientTransformer
*/
2015-12-08 11:10:20 +01:00
class ClientTransformer extends BaseTransformer
2015-11-24 20:45:38 +01:00
{
/**
* @param $data
* @return bool|Item
*/
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'),
'website' => $this->getString($data, 'website'),
'vat_number' => $this->getString($data, 'vat_number'),
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
];
});
}
}