diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 690775318a..97582f4ea7 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -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(); }]); diff --git a/app/Ninja/Presenters/ClientPresenter.php b/app/Ninja/Presenters/ClientPresenter.php index cd32151a37..bb32a8b62f 100644 --- a/app/Ninja/Presenters/ClientPresenter.php +++ b/app/Ninja/Presenters/ClientPresenter.php @@ -1,5 +1,6 @@ {$text}"; } + 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()); diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 0daa733123..560f2d49e6 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -1,5 +1,6 @@ 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); diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 880ded2baf..08a546fa9e 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -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")); + $data = [ + trans('texts.clients') => [], + trans('texts.contacts') => [], + trans('texts.invoices') => [], + trans('texts.quotes') => [], + ]; - $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")); + $clients = Client::scope() + ->with('contacts', 'invoices') + ->get(); - $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] = []; + foreach ($clients as $client) { + if ($client->name) { + $data[trans('texts.clients')][] = [ + 'value' => $client->name, + 'tokens' => explode(' ', $client->name), + 'url' => $client->present()->url, + ]; } - $tokens = explode(' ', $row->name); - $tokens[] = $type; - - if ($type == 'Invoices') { - $tokens[] = intVal($row->token).''; + foreach ($client->contacts as $contact) { + $data[trans('texts.contacts')][] = [ + 'value' => $contact->getDisplayName(), + 'tokens' => explode(' ', $contact->getFullName() . ' ' . $contact->email), + 'url' => $client->present()->url, + ]; } - $data[$type][] = [ - 'value' => $row->name, - 'tokens' => $tokens, - 'url' => URL::to("/{$row->type}/{$row->public_id}"), - ]; + 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; diff --git a/resources/views/accounts/customize_design.blade.php b/resources/views/accounts/customize_design.blade.php index a1860e97ed..2f60a9dd97 100644 --- a/resources/views/accounts/customize_design.blade.php +++ b/resources/views/accounts/customize_design.blade.php @@ -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; }