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

Added support for searching by invoice number in the API

This commit is contained in:
Hillel Coren 2016-06-06 19:04:57 +03:00
parent 44dfa56c31
commit 80202b6d92
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,7 @@
<?php namespace App\Http\Requests; <?php namespace App\Http\Requests;
use App\Models\Invoice;
class InvoiceRequest extends EntityRequest { class InvoiceRequest extends EntityRequest {
protected $entityType = ENTITY_INVOICE; protected $entityType = ENTITY_INVOICE;
@ -7,13 +9,21 @@ class InvoiceRequest extends EntityRequest {
public function entity() public function entity()
{ {
$invoice = parent::entity(); $invoice = parent::entity();
// support loading an invoice by its invoice number
if ($this->invoice_number && ! $invoice) {
$invoice = Invoice::scope()
->whereInvoiceNumber($this->invoice_number)
->withTrashed()
->firstOrFail();
}
// eager load the invoice items // eager load the invoice items
if ($invoice && ! $invoice->relationLoaded('invoice_items')) { if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
$invoice->load('invoice_items'); $invoice->load('invoice_items');
} }
return $invoice; return $invoice;
} }
} }

View File

@ -38,23 +38,23 @@ class EntityTransformer extends TransformerAbstract
{ {
return $date ? $date->getTimestamp() : null; return $date ? $date->getTimestamp() : null;
} }
public function getDefaultIncludes() public function getDefaultIncludes()
{ {
return $this->defaultIncludes; return $this->defaultIncludes;
} }
protected function getDefaults($entity) protected function getDefaults($entity)
{ {
$data = [ $data = [
'account_key' => $this->account->account_key, 'account_key' => $this->account->account_key,
'is_owner' => (bool) Auth::user()->owns($entity), 'is_owner' => (bool) (Auth::check() && Auth::user()->owns($entity)),
]; ];
if ($entity->relationLoaded('user')) { if ($entity->relationLoaded('user')) {
$data['user_id'] = (int) $entity->user->public_id + 1; $data['user_id'] = (int) $entity->user->public_id + 1;
} }
return $data; return $data;
} }
} }