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

Add client activity to API

This commit is contained in:
Hillel Coren 2018-08-02 22:35:59 +03:00
parent 9fa50c1675
commit d82a9914c0
3 changed files with 31 additions and 2 deletions

View File

@ -6,6 +6,8 @@ use App\Http\Requests\ClientRequest;
use App\Http\Requests\CreateClientRequest;
use App\Http\Requests\UpdateClientRequest;
use App\Models\Client;
use App\Models\Activity;
use App\Ninja\Transformers\ActivityTransformer;
use App\Ninja\Repositories\ClientRepository;
use Input;
use Response;
@ -57,6 +59,29 @@ class ClientApiController extends BaseAPIController
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(
* path="/clients/{client_id}",

View File

@ -34,8 +34,11 @@ class ActivityTransformer extends EntityTransformer
'updated_at' => $this->getTimestamp($activity->updated_at),
'expense_id' => $activity->expense_id ? $activity->expense->public_id : null,
'is_system' => $activity->is_system ? (bool) $activity->is_system : null,
'contact_id' => $activity->contact_id ? $activity->contact->public_id : null,
'task_id' => $activity->task_id ? $activity->task->public_id : null,
'contact_id' => $activity->contact_id ? (int) $activity->contact->public_id : null,
'task_id' => $activity->task_id ? (int) $activity->task->public_id : null,
'notes' => $activity->notes,
'adjustment' => (float) $activity->adjustment,
'balance' => (float) $activity->balance,
];
}
}

View File

@ -10,6 +10,7 @@ Route::put('accounts', 'AccountApiController@update');
Route::post('refresh', 'AccountApiController@refresh');
Route::resource('clients', 'ClientApiController');
Route::get('client_activity/{client_id}', 'ClientApiController@activity');
Route::resource('contacts', 'ContactApiController');
Route::get('quotes', 'QuoteApiController@index');
Route::get('download/{invoice_id}', 'InvoiceApiController@download');