2015-11-18 15:40:50 +01:00
|
|
|
<?php namespace App\Ninja\Import\FreshBooks;
|
2015-11-17 14:53:14 +01:00
|
|
|
|
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
use App\Models\Country;
|
2015-11-18 15:40:50 +01:00
|
|
|
use League\Fractal\Resource\Item;
|
2015-11-17 14:53:14 +01:00
|
|
|
|
|
|
|
class ClientTransformer extends TransformerAbstract
|
|
|
|
{
|
2015-11-18 15:40:50 +01:00
|
|
|
public function transform($data, $maps)
|
|
|
|
{
|
|
|
|
if (isset($maps[ENTITY_CLIENT][$data->organization])) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-17 14:53:14 +01:00
|
|
|
|
2015-11-18 15:40:50 +01:00
|
|
|
if (isset($maps['countries'][$data->country])) {
|
|
|
|
$data->country_id = $maps['countries'][$data->country];
|
|
|
|
}
|
2015-11-17 14:53:14 +01:00
|
|
|
|
2015-11-18 15:40:50 +01:00
|
|
|
return new Item($data, function ($data) use ($maps) {
|
2015-11-17 14:53:14 +01:00
|
|
|
return [
|
2015-11-18 15:40:50 +01:00
|
|
|
'name' => $data->organization,
|
|
|
|
'work_phone' => $data->busphone,
|
|
|
|
'address1' => $data->street,
|
|
|
|
'address2' => $data->street2,
|
|
|
|
'city' => $data->city,
|
|
|
|
'state' => $data->province,
|
|
|
|
'postal_code' => $data->postalcode,
|
|
|
|
'private_notes' => $data->notes,
|
2015-11-17 14:53:14 +01:00
|
|
|
'contacts' => [
|
|
|
|
[
|
2015-11-18 15:40:50 +01:00
|
|
|
'first_name' => $data->firstname,
|
|
|
|
'last_name' => $data->lastname,
|
|
|
|
'email' => $data->email,
|
|
|
|
'phone' => $data->mobphone ?: $data->homephone,
|
|
|
|
],
|
2015-11-17 14:53:14 +01:00
|
|
|
],
|
2015-11-18 15:40:50 +01:00
|
|
|
'country_id' => $data->country_id,
|
2015-11-17 14:53:14 +01:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2015-11-18 15:40:50 +01:00
|
|
|
}
|