2021-02-17 00:15:42 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://clientninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/clientninja/clientninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com)
|
2021-02-17 00:15:42 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-02-17 00:15:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Import\Transformers\Zoho;
|
|
|
|
|
|
|
|
use App\Import\ImportException;
|
|
|
|
use App\Import\Transformers\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['Company Name']) && $this->hasClient($data['Company Name'])) {
|
|
|
|
throw new ImportException('Client already exists');
|
|
|
|
}
|
2021-02-17 00:15:42 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = (string) $this->getCurrencyByCode($data, 'Currency');
|
2021-02-17 00:15:42 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (strval($data['Payment Terms'] ?? '') > 0) {
|
|
|
|
$settings->payment_terms = $data['Payment Terms'];
|
|
|
|
}
|
2021-02-17 00:15:42 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return [
|
|
|
|
'company_id' => $this->maps['company']->id,
|
|
|
|
'name' => $this->getString($data, 'Company Name'),
|
2022-11-30 01:46:02 +01:00
|
|
|
'phone' => $this->getString($data, 'Phone'),
|
2022-06-21 11:57:17 +02:00
|
|
|
'private_notes' => $this->getString($data, 'Notes'),
|
|
|
|
'website' => $this->getString($data, 'Website'),
|
|
|
|
'id_number' => $this->getString($data, 'Customer ID'),
|
|
|
|
'address1' => $this->getString($data, 'Billing Address'),
|
|
|
|
'address2' => $this->getString($data, 'Billing Street2'),
|
|
|
|
'city' => $this->getString($data, 'Billing City'),
|
|
|
|
'state' => $this->getString($data, 'Billing State'),
|
|
|
|
'postal_code' => $this->getString($data, 'Billing Code'),
|
|
|
|
'country_id' => isset($data['Billing Country']) ? $this->getCountryId($data['Billing Country']) : null,
|
2021-02-17 00:15:42 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
'shipping_address1' => $this->getString($data, 'Shipping Address'),
|
|
|
|
'shipping_address2' => $this->getString($data, 'Shipping Street2'),
|
|
|
|
'shipping_city' => $this->getString($data, 'Shipping City'),
|
|
|
|
'shipping_state' => $this->getString($data, 'Shipping State'),
|
|
|
|
'shipping_postal_code' => $this->getString($data, 'Shipping Code'),
|
|
|
|
'shipping_country_id' => isset($data['Shipping Country']) ? $this->getCountryId($data['Shipping Country']) : null,
|
|
|
|
'credit_balance' => 0,
|
|
|
|
'settings' => $settings,
|
|
|
|
'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'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2021-02-17 00:15:42 +01:00
|
|
|
}
|