2022-02-17 02:12:51 +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 02:12:51 +01:00
|
|
|
*
|
2023-05-01 00:07:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-02-17 02:12:51 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Import\Transformer\Invoicely;
|
|
|
|
|
|
|
|
use App\Import\ImportException;
|
|
|
|
use App\Import\Transformer\BaseTransformer;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ClientTransformer.
|
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
class ClientTransformer extends BaseTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
*
|
|
|
|
* @return array|bool
|
|
|
|
*/
|
|
|
|
public function transform($data)
|
|
|
|
{
|
|
|
|
if (isset($data['Client Name']) && $this->hasClient($data['Client Name'])) {
|
|
|
|
throw new ImportException('Client already exists');
|
|
|
|
}
|
2022-02-17 02:12:51 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$transformed = [
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'name' => $this->getString($data, 'Client Name'),
|
|
|
|
'phone' => $this->getString($data, 'Phone'),
|
|
|
|
'country_id' => isset($data['Country']) ? $this->getCountryIdBy2($data['Country']) : null,
|
|
|
|
'credit_balance' => 0,
|
2024-01-14 05:05:00 +01:00
|
|
|
'settings' => new \stdClass(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'client_hash' => Str::random(40),
|
|
|
|
'contacts' => [
|
|
|
|
[
|
|
|
|
'email' => $this->getString($data, 'Email'),
|
|
|
|
'phone' => $this->getString($data, 'Phone'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2022-02-17 03:27:21 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return $transformed;
|
|
|
|
}
|
2022-02-17 02:12:51 +01:00
|
|
|
}
|