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

56 lines
2.2 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Import\CSV;
2015-11-24 20:45:38 +01:00
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;
/**
2017-01-30 20:40:43 +01:00
* Class ClientTransformer.
*/
2015-12-08 11:10:20 +01:00
class ClientTransformer extends BaseTransformer
2015-11-24 20:45:38 +01:00
{
/**
* @param $data
2017-01-30 20:40:43 +01:00
*
* @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'),
2017-08-03 19:07:16 +02:00
'address2' => $this->getString($data, 'address2'),
2015-12-31 16:09:45 +01:00
'city' => $this->getString($data, 'city'),
'state' => $this->getString($data, 'state'),
'postal_code' => $this->getString($data, 'postal_code'),
2017-08-03 19:07:16 +02:00
'public_notes' => $this->getString($data, 'public_notes'),
'private_notes' => $this->getString($data, 'private_notes'),
'website' => $this->getString($data, 'website'),
'vat_number' => $this->getString($data, 'vat_number'),
'id_number' => $this->getString($data, 'id_number'),
2017-08-03 19:07:16 +02:00
'custom_value1' => $this->getString($data, 'custom1'),
'custom_value2' => $this->getString($data, 'custom2'),
2015-11-24 20:45:38 +01:00
'contacts' => [
[
2017-08-03 19:07:16 +02:00
'first_name' => $this->getString($data, 'contact_first_name'),
'last_name' => $this->getString($data, 'contact_last_name'),
'email' => $this->getString($data, 'contact_email'),
'phone' => $this->getString($data, 'contact_phone'),
'custom_value1' => $this->getString($data, 'contact_custom1'),
'custom_value2' => $this->getString($data, 'contact_custom2'),
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,
2017-08-03 19:07:16 +02:00
'currency_code' => $this->getString($data, 'currency'),
2015-11-24 20:45:38 +01:00
];
});
}
}