1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/ActivityService.php

67 lines
2.7 KiB
PHP
Raw Normal View History

2015-11-05 23:37:04 +01:00
<?php namespace App\Services;
use Utils;
use App\Models\Client;
use App\Services\BaseService;
use App\Ninja\Repositories\ActivityRepository;
class ActivityService extends BaseService
{
protected $activityRepo;
protected $datatableService;
public function __construct(ActivityRepository $activityRepo, DatatableService $datatableService)
{
$this->activityRepo = $activityRepo;
$this->datatableService = $datatableService;
}
public function getDatatable($clientPublicId = null)
{
2015-11-16 13:30:44 +01:00
$clientId = Client::getPrivateId($clientPublicId);
$query = $this->activityRepo->findByClientId($clientId);
2015-11-05 23:37:04 +01:00
return $this->createDatatable(ENTITY_ACTIVITY, $query);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'activities.id',
function ($model) {
return Utils::timestampToDateTimeString(strtotime($model->created_at));
}
],
[
'activity_type_id',
function ($model) {
$data = [
'client' => link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)),
'user' => $model->is_system ? '<i>' . trans('texts.system') . '</i>' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email),
'invoice' => $model->invoice ? link_to('/invoices/' . $model->invoice_public_id, $model->is_recurring ? trans('texts.recurring_invoice') : $model->invoice) : null,
'quote' => $model->invoice ? link_to('/quotes/' . $model->invoice_public_id, $model->invoice) : null,
'contact' => $model->contact_id ? link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)) : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email),
'payment' => $model->payment ?: '',
'credit' => Utils::formatMoney($model->credit, $model->currency_id, $model->country_id)
2015-11-05 23:37:04 +01:00
];
return trans("texts.activity_{$model->activity_type_id}", $data);
}
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, $model->currency_id, $model->country_id);
2015-11-05 23:37:04 +01:00
}
],
[
'adjustment',
function ($model) {
return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id, $model->country_id) : '';
2015-11-05 23:37:04 +01:00
}
]
];
}
}