1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Ninja/Datatables/ClientDatatable.php

138 lines
4.6 KiB
PHP
Raw Normal View History

2016-07-21 14:35:23 +02:00
<?php namespace App\Ninja\Datatables;
2016-05-23 18:52:20 +02:00
use Utils;
use URL;
use Auth;
class ClientDatatable extends EntityDatatable
{
public $entityType = ENTITY_CLIENT;
2016-11-24 10:41:11 +01:00
public $sortCol = 4;
2016-05-23 18:52:20 +02:00
public function columns()
{
return [
[
'name',
function ($model) {
return link_to("clients/{$model->public_id}", $model->name ?: '')->toHtml();
}
],
[
2016-11-27 10:46:32 +01:00
'contact',
2016-05-23 18:52:20 +02:00
function ($model) {
2016-11-27 10:46:32 +01:00
return link_to("clients/{$model->public_id}", $model->contact ?: '')->toHtml();
2016-05-23 18:52:20 +02:00
}
],
[
'email',
function ($model) {
return link_to("clients/{$model->public_id}", $model->email ?: '')->toHtml();
}
],
[
'client_created_at',
2016-05-23 18:52:20 +02:00
function ($model) {
return Utils::timestampToDateString(strtotime($model->created_at));
}
],
[
'last_login',
function ($model) {
return Utils::timestampToDateString(strtotime($model->last_login));
}
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, $model->currency_id, $model->country_id);
}
]
];
}
public function actions()
{
return [
[
trans('texts.edit_client'),
function ($model) {
return URL::to("clients/{$model->public_id}/edit");
},
function ($model) {
return Auth::user()->can('editByOwner', [ENTITY_CLIENT, $model->user_id]);
}
],
[
'--divider--', function(){return false;},
function ($model) {
$user = Auth::user();
return $user->can('editByOwner', [ENTITY_CLIENT, $model->user_id]) && ($user->can('create', ENTITY_TASK) || $user->can('create', ENTITY_INVOICE));
}
],
[
trans('texts.new_task'),
function ($model) {
return URL::to("tasks/create/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
return Auth::user()->can('create', ENTITY_TASK);
}
],
[
trans('texts.new_invoice'),
function ($model) {
return URL::to("invoices/create/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
return Auth::user()->can('create', ENTITY_INVOICE);
}
],
[
trans('texts.new_quote'),
function ($model) {
return URL::to("quotes/create/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-10-27 10:57:51 +02:00
return Auth::user()->hasFeature(FEATURE_QUOTES) && Auth::user()->can('create', ENTITY_QUOTE);
2016-05-23 18:52:20 +02:00
}
],
[
'--divider--', function(){return false;},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
$user = Auth::user();
return ($user->can('create', ENTITY_TASK) || $user->can('create', ENTITY_INVOICE)) && ($user->can('create', ENTITY_PAYMENT) || $user->can('create', ENTITY_CREDIT) || $user->can('create', ENTITY_EXPENSE));
}
],
[
trans('texts.enter_payment'),
function ($model) {
return URL::to("payments/create/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
return Auth::user()->can('create', ENTITY_PAYMENT);
}
],
[
trans('texts.enter_credit'),
function ($model) {
return URL::to("credits/create/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
return Auth::user()->can('create', ENTITY_CREDIT);
}
],
[
trans('texts.enter_expense'),
function ($model) {
return URL::to("expenses/create/0/{$model->public_id}");
},
2016-07-21 14:35:23 +02:00
function ($model) {
2016-05-23 18:52:20 +02:00
return Auth::user()->can('create', ENTITY_EXPENSE);
}
]
];
}
}