diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 443f5bfc32..153bfe7e8f 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -28,11 +28,11 @@ class SearchController extends Controller public function __invoke(GenericSearchRequest $request) { - if(config('scount.driver') == 'elastic' && $request->has('search') && $request->input('search') !== '') { + if(config('scout.driver') == 'elastic') { try{ - return $this->search($request->input('search', '')); + return $this->search($request->input('search', '*')); } catch(\Exception $e) { - nlog("elk down?"); + nlog("elk down?" . $e->getMessage()); } } diff --git a/app/Import/Transformer/BaseTransformer.php b/app/Import/Transformer/BaseTransformer.php index c75e377ff9..827c62eae4 100644 --- a/app/Import/Transformer/BaseTransformer.php +++ b/app/Import/Transformer/BaseTransformer.php @@ -211,11 +211,12 @@ class BaseTransformer public function getClient($client_name, $client_email) { - if (! empty($client_name)) { + if (strlen($client_name ?? '') >=1) { $client_id_search = Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->where('id_number', $client_name); + nlog("idnommer ".$client_id_search->count()); if ($client_id_search->count() >= 1) { return $client_id_search->first()->id; } @@ -226,17 +227,22 @@ class BaseTransformer strtolower(str_replace(' ', '', $client_name)), ]); + + nlog("client_name_search ".$client_name_search->count()); + if ($client_name_search->count() >= 1) { return $client_name_search->first()->id; } } - if (! empty($client_email)) { + if (strlen($client_email ?? '' ) >=1) { $contacts = ClientContact::query()->whereHas('client', function ($query) { $query->where('is_deleted', false); }) ->where('company_id', $this->company->id) ->where('email', $client_email); + nlog("contact count = " . $contacts->count()); + if ($contacts->count() >= 1) { return $contacts->first()->client_id; } diff --git a/app/Import/Transformer/Invoice2Go/InvoiceTransformer.php b/app/Import/Transformer/Invoice2Go/InvoiceTransformer.php index 28d8d530aa..442d084647 100644 --- a/app/Import/Transformer/Invoice2Go/InvoiceTransformer.php +++ b/app/Import/Transformer/Invoice2Go/InvoiceTransformer.php @@ -64,11 +64,11 @@ class InvoiceTransformer extends BaseTransformer $client_id = null; - if($this->hasClient($this->getString($invoice_data, 'Name') || $this->getContact($this->getString($invoice_data, 'EmailRecipient')))) { + // if($this->hasClient($this->getString($invoice_data, 'Name') || $this->getContact($this->getString($invoice_data, 'EmailRecipient')))) { - $client_id = $this->getClient($this->getString($invoice_data, 'Name'), $this->getString($invoice_data, 'EmailRecipient')); + $client_id = $this->getClient($this->getString($invoice_data, 'Name'), $this->getString($invoice_data, 'EmailRecipient')); - } + // } if ($client_id) { $transformed['client_id'] = $client_id; diff --git a/app/Models/Client.php b/app/Models/Client.php index 6407c4a8e6..57ffcf6f3a 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -12,14 +12,15 @@ namespace App\Models; use Laravel\Scout\Searchable; +use App\DataMapper\ClientSync; use App\Utils\Traits\AppSetup; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesDates; use App\DataMapper\FeesAndLimits; use App\Models\Traits\Excludable; use App\DataMapper\ClientSettings; -use App\DataMapper\ClientSync; use App\DataMapper\CompanySettings; +use Illuminate\Support\Facades\App; use App\Services\Client\ClientService; use App\Utils\Traits\GeneratesCounter; use Laracasts\Presenter\PresentableTrait; @@ -126,8 +127,6 @@ class Client extends BaseModel implements HasLocalePreference use AppSetup; use ClientGroupSettingsSaver; use Excludable; - - use Searchable; protected $presenter = ClientPresenter::class; @@ -241,8 +240,17 @@ class Client extends BaseModel implements HasLocalePreference public function toSearchableArray() { + + $locale = $this->locale(); + App::setLocale($locale); + + $name = ctrans('texts.client') . " | " . $this->present()->name(); + + if(strlen($this->vat_number ?? '') > 1) + $name .= " | ". $this->vat_number; + return [ - 'name' => $this->present()->name(), + 'name' => $name, 'is_deleted' => $this->is_deleted, 'hashed_id' => $this->hashed_id, 'number' => $this->number, @@ -272,6 +280,11 @@ class Client extends BaseModel implements HasLocalePreference ]; } + public function getScoutKey() + { + return $this->hashed_id; + } + public function getEntityType() { return self::class; diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 1df334bdf2..2fb32bb19e 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -185,6 +185,11 @@ class ClientContact extends Authenticatable implements HasLocalePreference ]; } + public function getScoutKey() + { + return $this->hashed_id; + } + /* V2 type of scope */ diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 56797bfe2e..38a7e9123d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -11,12 +11,13 @@ namespace App\Models; -use App\DataMapper\InvoiceSync; use App\Utils\Ninja; use Laravel\Scout\Searchable; use Illuminate\Support\Carbon; +use App\DataMapper\InvoiceSync; use App\Utils\Traits\MakesDates; use App\Helpers\Invoice\InvoiceSum; +use Illuminate\Support\Facades\App; use App\Utils\Traits\MakesReminders; use App\Utils\Traits\NumberFormatter; use App\Services\Ledger\LedgerService; @@ -29,6 +30,7 @@ use App\Helpers\Invoice\InvoiceSumInclusive; use App\Utils\Traits\Invoice\ActionsInvoice; use Illuminate\Database\Eloquent\SoftDeletes; use App\Events\Invoice\InvoiceReminderWasEmailed; +use App\Utils\Number; /** * App\Models\Invoice @@ -146,7 +148,6 @@ class Invoice extends BaseModel use MakesInvoiceValues; use MakesReminders; use ActionsInvoice; - use Searchable; protected $presenter = EntityPresenter::class; @@ -244,8 +245,11 @@ class Invoice extends BaseModel public function toSearchableArray() { + $locale = $this->company->locale(); + App::setLocale($locale); + return [ - 'name' => $this->client->present()->name() . ' - ' . $this->number, + 'name' => ctrans('texts.invoice') . " " . $this->number . " | " . $this->client->present()->name() . ' | ' . Number::formatMoney($this->amount, $this->company) . ' | ' . $this->translateDate($this->date, $this->company->date_format(), $locale), 'hashed_id' => $this->hashed_id, 'number' => $this->number, 'is_deleted' => $this->is_deleted, @@ -253,14 +257,20 @@ class Invoice extends BaseModel 'balance' => (float) $this->balance, 'due_date' => $this->due_date, 'date' => $this->date, - 'custom_value1' => $this->custom_value1, - 'custom_value2' => $this->custom_value2, - 'custom_value3' => $this->custom_value3, - 'custom_value4' => $this->custom_value4, + 'custom_value1' => (string)$this->custom_value1, + 'custom_value2' => (string)$this->custom_value2, + 'custom_value3' => (string)$this->custom_value3, + 'custom_value4' => (string)$this->custom_value4, 'company_key' => $this->company->company_key, + 'po_number' => (string)$this->po_number, ]; } + public function getScoutKey() + { + return $this->hashed_id; + } + public function getEntityType() { return self::class; diff --git a/app/PaymentDrivers/Braintree/ACH.php b/app/PaymentDrivers/Braintree/ACH.php index df705328df..7948e794a8 100644 --- a/app/PaymentDrivers/Braintree/ACH.php +++ b/app/PaymentDrivers/Braintree/ACH.php @@ -143,6 +143,7 @@ class ACH implements MethodInterface, LivewireMethodInterface $result = $this->braintree->gateway->transaction()->sale([ 'amount' => $this->braintree->payment_hash->data->amount_with_fee, 'paymentMethodToken' => $token->token, + 'channel' => 'invoiceninja_BT', 'options' => [ 'submitForSettlement' => true, ], diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 197f863ab3..f18a9fa42d 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -115,6 +115,7 @@ class CreditCard implements LivewireMethodInterface 'options' => [ 'submitForSettlement' => true, ], + 'channel' => 'invoiceninja_BT', 'billing' => [ 'streetAddress' => $this->braintree->client->address1 ?: '', 'extendedAddress' => $this->braintree->client->address2 ?: '', diff --git a/app/PaymentDrivers/Braintree/PayPal.php b/app/PaymentDrivers/Braintree/PayPal.php index 2ad3851548..7e7cf5d6d9 100644 --- a/app/PaymentDrivers/Braintree/PayPal.php +++ b/app/PaymentDrivers/Braintree/PayPal.php @@ -72,6 +72,7 @@ class PayPal implements LivewireMethodInterface 'amount' => $this->braintree->payment_hash->data->amount_with_fee, 'paymentMethodToken' => $token, 'deviceData' => $state['client-data'], + 'channel' => 'invoiceninja_BT', 'options' => [ 'submitForSettlement' => true, 'paypal' => [ diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index f75f151e5b..1102764f44 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -202,6 +202,9 @@ class BaseRepository $model->saveQuietly(); + if(method_exists($model, 'searchable')) + $model->searchable(); + /* Model now persisted, now lets do some child tasks */ if ($model instanceof Invoice) { diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index b2cf9f9176..3ff1b2057a 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -229,7 +229,10 @@ class HtmlEngine $data['$status_logo'] = ['value' => '