mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:40:09 -05:00 
			
		
		
		
	Improvements to search
This commit is contained in:
		
							parent
							
								
									4a749d5868
								
							
						
					
					
						commit
						308e5a1656
					
				@ -372,6 +372,8 @@ class ReportController extends BaseController
 | 
			
		||||
                            $query->where('invoice_date', '>=', $startDate)
 | 
			
		||||
                                  ->where('invoice_date', '<=', $endDate)
 | 
			
		||||
                                  ->where('is_deleted', '=', false)
 | 
			
		||||
                                  ->where('is_quote', '=', false)
 | 
			
		||||
                                  ->where('is_recurring', '=', false)
 | 
			
		||||
                                  ->with(['payments' => function($query) {
 | 
			
		||||
                                        $query->withTrashed()
 | 
			
		||||
                                              ->with('payment_type', 'account_gateway.gateway')
 | 
			
		||||
@ -419,6 +421,8 @@ class ReportController extends BaseController
 | 
			
		||||
                        ->with(['invoices' => function($query) use ($startDate, $endDate) {
 | 
			
		||||
                            $query->where('invoice_date', '>=', $startDate)
 | 
			
		||||
                                  ->where('invoice_date', '<=', $endDate)
 | 
			
		||||
                                  ->where('is_quote', '=', false)
 | 
			
		||||
                                  ->where('is_recurring', '=', false)
 | 
			
		||||
                                  ->withArchived();
 | 
			
		||||
                        }]);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
<?php namespace App\Ninja\Presenters;
 | 
			
		||||
 | 
			
		||||
use URL;
 | 
			
		||||
use Utils;
 | 
			
		||||
use Laracasts\Presenter\Presenter;
 | 
			
		||||
 | 
			
		||||
@ -28,6 +29,11 @@ class ClientPresenter extends Presenter {
 | 
			
		||||
        return "<span class=\"label label-{$class}\">{$text}</span>";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function url()
 | 
			
		||||
    {
 | 
			
		||||
        return URL::to('/clients/' . $this->entity->public_id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function link()
 | 
			
		||||
    {
 | 
			
		||||
        return link_to('/clients/' . $this->entity->public_id, $this->entity->getDisplayName());
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
<?php namespace App\Ninja\Presenters;
 | 
			
		||||
 | 
			
		||||
use URL;
 | 
			
		||||
use Utils;
 | 
			
		||||
use Laracasts\Presenter\Presenter;
 | 
			
		||||
 | 
			
		||||
@ -66,6 +67,11 @@ class InvoicePresenter extends Presenter {
 | 
			
		||||
        return $this->entity->frequency ? $this->entity->frequency->name : '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function url()
 | 
			
		||||
    {
 | 
			
		||||
        return URL::to('/invoices/' . $this->entity->public_id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function link()
 | 
			
		||||
    {
 | 
			
		||||
        return link_to('/invoices/' . $this->entity->public_id, $this->entity->invoice_number);
 | 
			
		||||
 | 
			
		||||
@ -82,47 +82,42 @@ class AccountRepository
 | 
			
		||||
 | 
			
		||||
    private function getAccountSearchData()
 | 
			
		||||
    {
 | 
			
		||||
        $clients = \DB::table('clients')
 | 
			
		||||
            ->where('clients.deleted_at', '=', null)
 | 
			
		||||
            ->where('clients.account_id', '=', \Auth::user()->account_id)
 | 
			
		||||
            ->whereRaw("clients.name <> ''")
 | 
			
		||||
            ->select(\DB::raw("'clients' as type, '" . trans('texts.clients') . "' as trans_type, clients.public_id, clients.name, '' as token"));
 | 
			
		||||
 | 
			
		||||
        $contacts = \DB::table('clients')
 | 
			
		||||
            ->join('contacts', 'contacts.client_id', '=', 'clients.id')
 | 
			
		||||
            ->where('clients.deleted_at', '=', null)
 | 
			
		||||
            ->where('clients.account_id', '=', \Auth::user()->account_id)
 | 
			
		||||
            ->whereRaw("CONCAT(contacts.first_name, contacts.last_name, contacts.email) <> ''")
 | 
			
		||||
            ->select(\DB::raw("'clients' as type, '" . trans('texts.contacts') . "' as trans_type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name, ' ', contacts.email) as name, '' as token"));
 | 
			
		||||
 | 
			
		||||
        $invoices = \DB::table('clients')
 | 
			
		||||
            ->join('invoices', 'invoices.client_id', '=', 'clients.id')
 | 
			
		||||
            ->where('clients.account_id', '=', \Auth::user()->account_id)
 | 
			
		||||
            ->where('clients.deleted_at', '=', null)
 | 
			
		||||
            ->where('invoices.deleted_at', '=', null)
 | 
			
		||||
            ->select(\DB::raw("'invoices' as type, '" . trans('texts.invoices') . "' as trans_type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name, invoices.invoice_number as token"));
 | 
			
		||||
 | 
			
		||||
        $data = [];
 | 
			
		||||
 | 
			
		||||
        foreach ($clients->union($contacts)->union($invoices)->get() as $row) {
 | 
			
		||||
            $type = $row->trans_type;
 | 
			
		||||
 | 
			
		||||
            if (!isset($data[$type])) {
 | 
			
		||||
                $data[$type] = [];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $tokens = explode(' ', $row->name);
 | 
			
		||||
            $tokens[] = $type;
 | 
			
		||||
 | 
			
		||||
            if ($type == 'Invoices') {
 | 
			
		||||
                $tokens[] = intVal($row->token).'';
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $data[$type][] = [
 | 
			
		||||
                'value' => $row->name,
 | 
			
		||||
                'tokens' => $tokens,
 | 
			
		||||
                'url' => URL::to("/{$row->type}/{$row->public_id}"),
 | 
			
		||||
        $data = [
 | 
			
		||||
            trans('texts.clients') => [],
 | 
			
		||||
            trans('texts.contacts') => [],
 | 
			
		||||
            trans('texts.invoices') => [],
 | 
			
		||||
            trans('texts.quotes') => [],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $clients = Client::scope()
 | 
			
		||||
                    ->with('contacts', 'invoices')
 | 
			
		||||
                    ->get();
 | 
			
		||||
 | 
			
		||||
        foreach ($clients as $client) {
 | 
			
		||||
            if ($client->name) {
 | 
			
		||||
                $data[trans('texts.clients')][] = [
 | 
			
		||||
                    'value' => $client->name,
 | 
			
		||||
                    'tokens' => explode(' ', $client->name),
 | 
			
		||||
                    'url' => $client->present()->url,
 | 
			
		||||
                ];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach ($client->contacts as $contact) {
 | 
			
		||||
                $data[trans('texts.contacts')][] = [
 | 
			
		||||
                    'value' => $contact->getDisplayName(),
 | 
			
		||||
                    'tokens' => explode(' ', $contact->getFullName() . ' ' . $contact->email),
 | 
			
		||||
                    'url' => $client->present()->url,
 | 
			
		||||
                ];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach ($client->invoices as $invoice) {
 | 
			
		||||
                $entityType = $invoice->getEntityType();
 | 
			
		||||
                $data[trans("texts.{$entityType}s")][] = [
 | 
			
		||||
                    'value' => $invoice->getDisplayName() . ': ' . $client->getDisplayName(),
 | 
			
		||||
                    'tokens' => explode(' ', $invoice->invoice_number . ' ' . intval($invoice->invoice_number) . ' ' . $client->getDisplayName()),
 | 
			
		||||
                    'url' => $invoice->present()->url,
 | 
			
		||||
                ];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $data;
 | 
			
		||||
 | 
			
		||||
@ -25,10 +25,10 @@
 | 
			
		||||
        /* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
 | 
			
		||||
        pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
 | 
			
		||||
        .string { color: green; }
 | 
			
		||||
        .number { color: darkorange; }
 | 
			
		||||
        .number { color: red; }
 | 
			
		||||
        .boolean { color: blue; }
 | 
			
		||||
        .null { color: magenta; }
 | 
			
		||||
        .key { color: red; }
 | 
			
		||||
        .null { color: gray; }
 | 
			
		||||
        .key { color: black; }
 | 
			
		||||
 | 
			
		||||
      </style>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user