Fixes fot search by client

This commit is contained in:
David Bomba 2021-12-04 11:16:44 +11:00
parent f2f71f892c
commit 7adaab984b

View File

@ -62,20 +62,30 @@ class BaseTransformer
public function getClient($client_name, $client_email) { public function getClient($client_name, $client_email) {
$clients = $this->maps['company']->clients; $clients = $this->maps['company']->clients;
$clients = $clients->where( 'id_number', $client_name ); $client_id_search = $clients->where( 'id_number', $client_name );
if ( $clients->count() >= 1 ) { if ( $client_id_search->count() >= 1 ) {
return $clients->first()->id; return $client_id_search->first()->id;
nlog("found via id number");
} }
$client_name_search = $clients->where( 'name', $client_name );
if ( $client_name_search->count() >= 1 ) {
return $client_name_search->first()->id;
nlog("found via name");
}
if ( ! empty( $client_email ) ) { if ( ! empty( $client_email ) ) {
$contacts = ClientContact::where( 'company_id', $this->maps['company']->id ) $contacts = ClientContact::where( 'company_id', $this->maps['company']->id )
->where( 'email', $client_email ); ->where( 'email', $client_email );
if ( $contacts->count() >= 1 ) { if ( $contacts->count() >= 1 ) {
return $contacts->first()->client_id; return $contacts->first()->client_id;
nlog("found via contact");
} }
} }
nlog("did not find client");
return null; return null;
} }