1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Import/Transformer/Freshbooks/ClientTransformer.php

58 lines
1.9 KiB
PHP
Raw Normal View History

2022-02-17 00:20:35 +01:00
<?php
/**
* Invoice Ninja (https://clientninja.com).
*
2023-05-01 00:07:41 +02:00
* @link https://github.com/invoiceninja/invoiceninja source repository
2022-02-17 00:20:35 +01:00
*
2023-05-01 00:07:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2022-02-17 00:20:35 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Import\Transformer\Freshbooks;
use App\Import\ImportException;
use App\Import\Transformer\BaseTransformer;
use Illuminate\Support\Str;
/**
* Class ClientTransformer.
*/
class ClientTransformer extends BaseTransformer
{
/**
* @param $data
*
* @return array|bool
*/
public function transform($data)
{
if (isset($data['Organization']) && $this->hasClient($data['Organization'])) {
throw new ImportException('Client already exists');
}
2022-02-17 00:20:35 +01:00
return [
'company_id' => $this->company->id,
'name' => $this->getString($data, 'Organization'),
'phone' => $this->getString($data, 'Phone'),
'address1' => $this->getString($data, 'Street'),
'city' => $this->getString($data, 'City'),
'state' => $this->getString($data, 'Province/State'),
'postal_code' => $this->getString($data, 'Postal Code'),
'country_id' => isset($data['Country']) ? $this->getCountryId($data['Country']) : null,
'private_notes' => $this->getString($data, 'Notes'),
'credit_balance' => 0,
2024-01-14 05:05:00 +01:00
'settings' => new \stdClass(),
'client_hash' => Str::random(40),
'contacts' => [
[
'first_name' => $this->getString($data, 'First Name'),
'last_name' => $this->getString($data, 'Last Name'),
'email' => $this->getString($data, 'Email'),
'phone' => $this->getString($data, 'Phone'),
],
],
];
}
2022-02-17 00:20:35 +01:00
}