1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Import/Transformer/Zoho/ClientTransformer.php

81 lines
3.3 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://clientninja.com).
*
2023-05-01 00:07:41 +02:00
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-05-01 00:07:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Import\Transformer\Zoho;
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)
{
2023-06-21 06:21:43 +02:00
$client_id_proxy = array_key_exists('Customer ID', $data) ? 'Customer ID' : 'Primary Contact ID';
if(isset($data[$client_id_proxy]) && $this->hasClientIdNumber($data[$client_id_proxy])) {
throw new ImportException('Client ID already exists => '. $data[$client_id_proxy]);
2023-10-26 04:57:44 +02:00
} elseif (isset($data['Company Name']) && $this->hasClient($data['Company Name'])) {
2023-05-16 09:41:54 +02:00
throw new ImportException('Client already exists => '. $data['Company Name']);
}
$settings = new \stdClass;
$settings->currency_id = (string) $this->getCurrencyByCode($data, 'Currency');
if (strval($data['Payment Terms'] ?? '') > 0) {
$settings->payment_terms = $data['Payment Terms'];
}
2023-05-16 09:41:54 +02:00
$data = [
'company_id' => $this->company->id,
2022-08-16 09:13:56 +02:00
'name' => $this->getString($data, 'Display Name'),
'phone' => $this->getString($data, 'Phone'),
'private_notes' => $this->getString($data, 'Notes'),
'website' => $this->getString($data, 'Website'),
2022-08-16 09:13:56 +02:00
'id_number' => $this->getString($data, $client_id_proxy),
'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,
'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, 'EmailID'),
'phone' => $this->getString($data, 'Phone'),
],
],
];
2023-05-16 09:41:54 +02:00
return $data;
}
}