1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Improvements to search

This commit is contained in:
Hillel Coren 2016-02-25 23:33:48 +02:00
parent 4a749d5868
commit 308e5a1656
5 changed files with 49 additions and 38 deletions

View File

@ -372,6 +372,8 @@ class ReportController extends BaseController
$query->where('invoice_date', '>=', $startDate) $query->where('invoice_date', '>=', $startDate)
->where('invoice_date', '<=', $endDate) ->where('invoice_date', '<=', $endDate)
->where('is_deleted', '=', false) ->where('is_deleted', '=', false)
->where('is_quote', '=', false)
->where('is_recurring', '=', false)
->with(['payments' => function($query) { ->with(['payments' => function($query) {
$query->withTrashed() $query->withTrashed()
->with('payment_type', 'account_gateway.gateway') ->with('payment_type', 'account_gateway.gateway')
@ -419,6 +421,8 @@ class ReportController extends BaseController
->with(['invoices' => function($query) use ($startDate, $endDate) { ->with(['invoices' => function($query) use ($startDate, $endDate) {
$query->where('invoice_date', '>=', $startDate) $query->where('invoice_date', '>=', $startDate)
->where('invoice_date', '<=', $endDate) ->where('invoice_date', '<=', $endDate)
->where('is_quote', '=', false)
->where('is_recurring', '=', false)
->withArchived(); ->withArchived();
}]); }]);

View File

@ -1,5 +1,6 @@
<?php namespace App\Ninja\Presenters; <?php namespace App\Ninja\Presenters;
use URL;
use Utils; use Utils;
use Laracasts\Presenter\Presenter; use Laracasts\Presenter\Presenter;
@ -28,6 +29,11 @@ class ClientPresenter extends Presenter {
return "<span class=\"label label-{$class}\">{$text}</span>"; return "<span class=\"label label-{$class}\">{$text}</span>";
} }
public function url()
{
return URL::to('/clients/' . $this->entity->public_id);
}
public function link() public function link()
{ {
return link_to('/clients/' . $this->entity->public_id, $this->entity->getDisplayName()); return link_to('/clients/' . $this->entity->public_id, $this->entity->getDisplayName());

View File

@ -1,5 +1,6 @@
<?php namespace App\Ninja\Presenters; <?php namespace App\Ninja\Presenters;
use URL;
use Utils; use Utils;
use Laracasts\Presenter\Presenter; use Laracasts\Presenter\Presenter;
@ -66,6 +67,11 @@ class InvoicePresenter extends Presenter {
return $this->entity->frequency ? $this->entity->frequency->name : ''; return $this->entity->frequency ? $this->entity->frequency->name : '';
} }
public function url()
{
return URL::to('/invoices/' . $this->entity->public_id);
}
public function link() public function link()
{ {
return link_to('/invoices/' . $this->entity->public_id, $this->entity->invoice_number); return link_to('/invoices/' . $this->entity->public_id, $this->entity->invoice_number);

View File

@ -82,47 +82,42 @@ class AccountRepository
private function getAccountSearchData() private function getAccountSearchData()
{ {
$clients = \DB::table('clients') $data = [
->where('clients.deleted_at', '=', null) trans('texts.clients') => [],
->where('clients.account_id', '=', \Auth::user()->account_id) trans('texts.contacts') => [],
->whereRaw("clients.name <> ''") trans('texts.invoices') => [],
->select(\DB::raw("'clients' as type, '" . trans('texts.clients') . "' as trans_type, clients.public_id, clients.name, '' as token")); trans('texts.quotes') => [],
];
$contacts = \DB::table('clients') $clients = Client::scope()
->join('contacts', 'contacts.client_id', '=', 'clients.id') ->with('contacts', 'invoices')
->where('clients.deleted_at', '=', null) ->get();
->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') foreach ($clients as $client) {
->join('invoices', 'invoices.client_id', '=', 'clients.id') if ($client->name) {
->where('clients.account_id', '=', \Auth::user()->account_id) $data[trans('texts.clients')][] = [
->where('clients.deleted_at', '=', null) 'value' => $client->name,
->where('invoices.deleted_at', '=', null) 'tokens' => explode(' ', $client->name),
->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")); 'url' => $client->present()->url,
];
$data = [];
foreach ($clients->union($contacts)->union($invoices)->get() as $row) {
$type = $row->trans_type;
if (!isset($data[$type])) {
$data[$type] = [];
} }
$tokens = explode(' ', $row->name); foreach ($client->contacts as $contact) {
$tokens[] = $type; $data[trans('texts.contacts')][] = [
'value' => $contact->getDisplayName(),
if ($type == 'Invoices') { 'tokens' => explode(' ', $contact->getFullName() . ' ' . $contact->email),
$tokens[] = intVal($row->token).''; 'url' => $client->present()->url,
];
} }
$data[$type][] = [ foreach ($client->invoices as $invoice) {
'value' => $row->name, $entityType = $invoice->getEntityType();
'tokens' => $tokens, $data[trans("texts.{$entityType}s")][] = [
'url' => URL::to("/{$row->type}/{$row->public_id}"), 'value' => $invoice->getDisplayName() . ': ' . $client->getDisplayName(),
]; 'tokens' => explode(' ', $invoice->invoice_number . ' ' . intval($invoice->invoice_number) . ' ' . $client->getDisplayName()),
'url' => $invoice->present()->url,
];
}
} }
return $data; return $data;

View File

@ -25,10 +25,10 @@
/* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */ /* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; } pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; } .string { color: green; }
.number { color: darkorange; } .number { color: red; }
.boolean { color: blue; } .boolean { color: blue; }
.null { color: magenta; } .null { color: gray; }
.key { color: red; } .key { color: black; }
</style> </style>