mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Added support for searching by invoice number in the API
This commit is contained in:
parent
44dfa56c31
commit
80202b6d92
@ -1,5 +1,7 @@
|
||||
<?php namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceRequest extends EntityRequest {
|
||||
|
||||
protected $entityType = ENTITY_INVOICE;
|
||||
@ -7,13 +9,21 @@ class InvoiceRequest extends EntityRequest {
|
||||
public function 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
|
||||
if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -38,23 +38,23 @@ class EntityTransformer extends TransformerAbstract
|
||||
{
|
||||
return $date ? $date->getTimestamp() : null;
|
||||
}
|
||||
|
||||
|
||||
public function getDefaultIncludes()
|
||||
{
|
||||
return $this->defaultIncludes;
|
||||
}
|
||||
|
||||
|
||||
protected function getDefaults($entity)
|
||||
{
|
||||
$data = [
|
||||
'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')) {
|
||||
$data['user_id'] = (int) $entity->user->public_id + 1;
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user