zoho improvements

This commit is contained in:
David Bomba 2023-06-21 14:21:43 +10:00
parent 786bda2515
commit de7afb9944
3 changed files with 15 additions and 4 deletions

View File

@ -246,6 +246,15 @@ class BaseTransformer
->exists(); ->exists();
} }
public function hasClientIdNumber($id_number)
{
return Client::where('company_id', $this->company->id)
->where('is_deleted', false)
->where('id_number', trim($id_number))
->exists();
}
/** /**
* @param $name * @param $name
* *

View File

@ -27,7 +27,12 @@ class ClientTransformer extends BaseTransformer
*/ */
public function transform($data) public function transform($data)
{ {
if (isset($data['Company Name']) && $this->hasClient($data['Company Name'])) { $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]);
}
elseif (isset($data['Company Name']) && $this->hasClient($data['Company Name'])) {
throw new ImportException('Client already exists => '. $data['Company Name']); throw new ImportException('Client already exists => '. $data['Company Name']);
} }
@ -38,8 +43,6 @@ class ClientTransformer extends BaseTransformer
$settings->payment_terms = $data['Payment Terms']; $settings->payment_terms = $data['Payment Terms'];
} }
$client_id_proxy = array_key_exists('Customer ID', $data) ? 'Customer ID' : 'Primary Contact ID';
$data = [ $data = [
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'name' => $this->getString($data, 'Display Name'), 'name' => $this->getString($data, 'Display Name'),

View File

@ -123,7 +123,6 @@ class InvoiceTransformer extends BaseTransformer
return $client_id_search->first()->id; return $client_id_search->first()->id;
} }
$client_repository = app()->make(\App\Repositories\ClientRepository::class); $client_repository = app()->make(\App\Repositories\ClientRepository::class);
$client_repository->import_mode = true; $client_repository->import_mode = true;