2020-12-16 11:06:20 +01:00
|
|
|
<?php
|
2020-12-19 02:45:12 +01:00
|
|
|
/**
|
|
|
|
* client Ninja (https://clientninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/clientninja/clientninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. client Ninja LLC (https://clientninja.com)
|
2020-12-19 02:45:12 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-12-16 11:06:20 +01:00
|
|
|
|
2021-02-17 00:15:42 +01:00
|
|
|
namespace App\Import\Transformers\Csv;
|
|
|
|
use App\Import\ImportException;
|
|
|
|
use App\Import\Transformers\BaseTransformer;
|
2020-12-16 11:06:20 +01:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ClientTransformer.
|
|
|
|
*/
|
|
|
|
class ClientTransformer extends BaseTransformer
|
|
|
|
{
|
|
|
|
/**
|
2021-02-13 01:20:15 +01:00
|
|
|
* @param $data
|
|
|
|
*
|
2021-02-17 00:15:42 +01:00
|
|
|
* @return array|bool
|
2021-02-13 01:20:15 +01:00
|
|
|
*/
|
2020-12-16 11:06:20 +01:00
|
|
|
public function transform($data)
|
|
|
|
{
|
|
|
|
if (isset($data->name) && $this->hasClient($data->name)) {
|
2021-02-17 00:15:42 +01:00
|
|
|
throw new ImportException('Client already exists');
|
2020-12-16 11:06:20 +01:00
|
|
|
}
|
|
|
|
|
2020-12-16 12:52:40 +01:00
|
|
|
$settings = new \stdClass;
|
2021-02-17 00:15:42 +01:00
|
|
|
$settings->currency_id = (string)$this->getCurrencyByCode($data);
|
2020-12-16 11:06:20 +01:00
|
|
|
|
2021-02-17 00:15:42 +01:00
|
|
|
return [
|
2021-02-13 01:20:15 +01:00
|
|
|
'company_id' => $this->maps['company']->id,
|
|
|
|
'name' => $this->getString( $data, 'client.name' ),
|
|
|
|
'work_phone' => $this->getString( $data, 'client.phone' ),
|
|
|
|
'address1' => $this->getString( $data, 'client.address1' ),
|
|
|
|
'address2' => $this->getString( $data, 'client.address2' ),
|
|
|
|
'city' => $this->getString( $data, 'client.city' ),
|
|
|
|
'state' => $this->getString( $data, 'client.state' ),
|
|
|
|
'shipping_address1' => $this->getString( $data, 'client.shipping_address1' ),
|
|
|
|
'shipping_address2' => $this->getString( $data, 'client.shipping_address2' ),
|
|
|
|
'shipping_city' => $this->getString( $data, 'client.shipping_city' ),
|
|
|
|
'shipping_state' => $this->getString( $data, 'client.shipping_state' ),
|
|
|
|
'shipping_postal_code' => $this->getString( $data, 'client.shipping_postal_code' ),
|
|
|
|
'public_notes' => $this->getString( $data, 'client.public_notes' ),
|
|
|
|
'private_notes' => $this->getString( $data, 'client.private_notes' ),
|
|
|
|
'website' => $this->getString( $data, 'client.website' ),
|
|
|
|
'vat_number' => $this->getString( $data, 'client.vat_number' ),
|
|
|
|
'id_number' => $this->getString( $data, 'client.id_number' ),
|
|
|
|
'custom_value1' => $this->getString( $data, 'client.custom1' ),
|
|
|
|
'custom_value2' => $this->getString( $data, 'client.custom2' ),
|
|
|
|
'custom_value3' => $this->getString( $data, 'client.custom3' ),
|
|
|
|
'custom_value4' => $this->getString( $data, 'client.custom4' ),
|
|
|
|
'balance' => preg_replace( '/[^0-9,.]+/', '', $this->getFloat( $data, 'client.balance' ) ),
|
|
|
|
'paid_to_date' => preg_replace( '/[^0-9,.]+/', '', $this->getFloat( $data, 'client.paid_to_date' ) ),
|
|
|
|
'credit_balance' => 0,
|
|
|
|
'settings' => $settings,
|
|
|
|
'client_hash' => Str::random( 40 ),
|
|
|
|
'contacts' => [
|
|
|
|
[
|
|
|
|
'first_name' => $this->getString( $data, 'contact.first_name' ),
|
|
|
|
'last_name' => $this->getString( $data, 'contact.last_name' ),
|
|
|
|
'email' => $this->getString( $data, 'contact.email' ),
|
|
|
|
'phone' => $this->getString( $data, 'contact.phone' ),
|
|
|
|
'custom_value1' => $this->getString( $data, 'contact.custom1' ),
|
|
|
|
'custom_value2' => $this->getString( $data, 'contact.custom2' ),
|
|
|
|
'custom_value3' => $this->getString( $data, 'contact.custom3' ),
|
|
|
|
'custom_value4' => $this->getString( $data, 'contact.custom4' ),
|
|
|
|
],
|
|
|
|
],
|
2021-02-17 00:15:42 +01:00
|
|
|
'country_id' => isset( $data['client.country'] ) ? $this->getCountryId( $data['client.country']) : null,
|
|
|
|
'shipping_country_id' => isset($data['client.shipping_country'] ) ? $this->getCountryId( $data['client.shipping_country'] ) : null,
|
2021-02-13 01:20:15 +01:00
|
|
|
];
|
2020-12-16 11:06:20 +01:00
|
|
|
}
|
|
|
|
}
|