mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Add activities to client API
This commit is contained in:
parent
d82a9914c0
commit
b716888083
@ -6,8 +6,6 @@ use App\Http\Requests\ClientRequest;
|
|||||||
use App\Http\Requests\CreateClientRequest;
|
use App\Http\Requests\CreateClientRequest;
|
||||||
use App\Http\Requests\UpdateClientRequest;
|
use App\Http\Requests\UpdateClientRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Activity;
|
|
||||||
use App\Ninja\Transformers\ActivityTransformer;
|
|
||||||
use App\Ninja\Repositories\ClientRepository;
|
use App\Ninja\Repositories\ClientRepository;
|
||||||
use Input;
|
use Input;
|
||||||
use Response;
|
use Response;
|
||||||
@ -59,29 +57,6 @@ class ClientApiController extends BaseAPIController
|
|||||||
return $this->listResponse($clients);
|
return $this->listResponse($clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activity(ClientRequest $request)
|
|
||||||
{
|
|
||||||
$client = $request->entity();
|
|
||||||
|
|
||||||
$activities = Activity::where('activities.account_id', '=', $client->account_id)
|
|
||||||
->where('activities.client_id', '=', $client->id)
|
|
||||||
->where('activities.activity_type_id', '>', 0);
|
|
||||||
|
|
||||||
if (! auth()->user()->hasPermission('view_all')) {
|
|
||||||
$activities = $activities->where('activities.user_id', '=', auth()->user()->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$activities->orderBy('activities.created_at', 'desc')
|
|
||||||
->with('client.contacts', 'user', 'invoice', 'payment', 'credit', 'account', 'task', 'expense', 'contact')
|
|
||||||
->take(500)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$transformer = new ActivityTransformer(auth()->user()->account, $request->serializer);
|
|
||||||
$data = $this->createCollection($activities, $transformer, ENTITY_ACTIVITY);
|
|
||||||
|
|
||||||
return $this->response($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @SWG\Get(
|
* @SWG\Get(
|
||||||
* path="/clients/{client_id}",
|
* path="/clients/{client_id}",
|
||||||
@ -107,7 +82,13 @@ class ClientApiController extends BaseAPIController
|
|||||||
*/
|
*/
|
||||||
public function show(ClientRequest $request)
|
public function show(ClientRequest $request)
|
||||||
{
|
{
|
||||||
return $this->itemResponse($request->entity());
|
$client = $request->entity();
|
||||||
|
|
||||||
|
if (strpos(request()->include, 'activities') !== false) {
|
||||||
|
$client->load('activities.client.contacts', 'activities.user', 'activities.invoice', 'activities.payment', 'activities.credit', 'activities.account', 'activities.task', 'activities.expense', 'activities.contact');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->itemResponse($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,6 +252,14 @@ class Client extends EntityModel
|
|||||||
return $this->hasMany('App\Models\Expense', 'client_id', 'id')->withTrashed();
|
return $this->hasMany('App\Models\Expense', 'client_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function activities()
|
||||||
|
{
|
||||||
|
return $this->hasMany('App\Models\Activity', 'client_id', 'id')->orderBy('id', 'desc');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param bool $isPrimary
|
* @param bool $isPrimary
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Ninja\Transformers;
|
namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Activity;
|
||||||
|
use App\Ninja\Transformers\ActivityTransformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @SWG\Definition(definition="Client", @SWG\Xml(name="Client"))
|
* @SWG\Definition(definition="Client", @SWG\Xml(name="Client"))
|
||||||
@ -58,8 +60,21 @@ class ClientTransformer extends EntityTransformer
|
|||||||
protected $availableIncludes = [
|
protected $availableIncludes = [
|
||||||
'invoices',
|
'invoices',
|
||||||
'credits',
|
'credits',
|
||||||
|
'activities',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Client $client
|
||||||
|
*
|
||||||
|
* @return \League\Fractal\Resource\Collection
|
||||||
|
*/
|
||||||
|
public function includeActivities(Client $client)
|
||||||
|
{
|
||||||
|
$transformer = new ActivityTransformer($this->account, $this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($client->activities, $transformer, ENTITY_ACTIVITY);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
*
|
*
|
||||||
|
@ -10,7 +10,6 @@ Route::put('accounts', 'AccountApiController@update');
|
|||||||
Route::post('refresh', 'AccountApiController@refresh');
|
Route::post('refresh', 'AccountApiController@refresh');
|
||||||
|
|
||||||
Route::resource('clients', 'ClientApiController');
|
Route::resource('clients', 'ClientApiController');
|
||||||
Route::get('client_activity/{client_id}', 'ClientApiController@activity');
|
|
||||||
Route::resource('contacts', 'ContactApiController');
|
Route::resource('contacts', 'ContactApiController');
|
||||||
Route::get('quotes', 'QuoteApiController@index');
|
Route::get('quotes', 'QuoteApiController@index');
|
||||||
Route::get('download/{invoice_id}', 'InvoiceApiController@download');
|
Route::get('download/{invoice_id}', 'InvoiceApiController@download');
|
||||||
|
Loading…
Reference in New Issue
Block a user