invoiceninja/app/Ninja/Datatables/ClientDatatable.php

165 lines
5.6 KiB
PHP
Raw Permalink Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Ninja\Datatables;
2016-05-23 19:52:20 +03:00
use Auth;
2017-01-30 21:40:43 +02:00
use URL;
use Utils;
2016-05-23 19:52:20 +03:00
class ClientDatatable extends EntityDatatable
{
public $entityType = ENTITY_CLIENT;
2016-11-24 11:41:11 +02:00
public $sortCol = 4;
2019-01-30 22:00:26 +11:00
public $fieldToSum = 'balance';
2016-05-23 19:52:20 +03:00
public function columns()
{
return [
[
'name',
function ($model) {
2017-10-14 20:55:37 +03:00
$str = link_to("clients/{$model->public_id}", $model->name ?: '')->toHtml();
return $this->addNote($str, $model->private_notes);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
2016-11-27 11:46:32 +02:00
'contact',
2016-05-23 19:52:20 +03:00
function ($model) {
2016-11-27 11:46:32 +02:00
return link_to("clients/{$model->public_id}", $model->contact ?: '')->toHtml();
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
'email',
function ($model) {
return link_to("clients/{$model->public_id}", $model->email ?: '')->toHtml();
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
2017-02-28 20:24:30 +02:00
[
'id_number',
function ($model) {
return $model->id_number;
},
Auth::user()->account->clientNumbersEnabled()
],
2019-01-30 22:00:26 +11:00
[
'custom_client1::' . Auth::user()->account->customLabel('client1'),
function ($model) {
return $model->custom_value1 ;
},
Auth::user()->account->customFieldsOption('client1_filter')
],
[
'custom_client2::' . Auth::user()->account->customLabel('client2'),
function ($model) {
return $model->custom_value2;
},
Auth::user()->account->customFieldsOption('client2_filter')
],
2016-05-23 19:52:20 +03:00
[
'client_created_at',
2016-05-23 19:52:20 +03:00
function ($model) {
return Utils::timestampToDateString(strtotime($model->created_at));
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
'last_login',
function ($model) {
return Utils::timestampToDateString(strtotime($model->last_login));
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, $model->currency_id, $model->country_id);
2017-01-30 21:40:43 +02:00
},
],
2016-05-23 19:52:20 +03:00
];
}
public function actions()
{
return [
[
trans('texts.edit_client'),
function ($model) {
if(Auth::user()->can('edit', [ENTITY_CLIENT, $model]))
return URL::to("clients/{$model->public_id}/edit");
elseif(Auth::user()->can('view', [ENTITY_CLIENT, $model]))
return URL::to("clients/{$model->public_id}");
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
2017-01-30 18:05:31 +02:00
'--divider--', function () {
return false;
},
2016-05-23 19:52:20 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('edit', [ENTITY_CLIENT, $model]);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.new_task'),
function ($model) {
return URL::to("tasks/create/{$model->public_id}");
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_TASK);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.new_invoice'),
function ($model) {
return URL::to("invoices/create/{$model->public_id}");
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_INVOICE);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.new_quote'),
function ($model) {
return URL::to("quotes/create/{$model->public_id}");
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->hasFeature(FEATURE_QUOTES) && Auth::user()->can('createEntity', ENTITY_QUOTE);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
2017-01-30 18:05:31 +02:00
'--divider--', function () {
return false;
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return (Auth::user()->can('createEntity', ENTITY_TASK) || Auth::user()->can('createEntity', ENTITY_INVOICE)) && (Auth::user()->can('createEntity', ENTITY_PAYMENT) || Auth::user()->can('createEntity', ENTITY_CREDIT) || Auth::user()->can('createEntity', ENTITY_EXPENSE));
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.enter_payment'),
function ($model) {
return URL::to("payments/create/{$model->public_id}");
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_PAYMENT);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.enter_credit'),
function ($model) {
return URL::to("credits/create/{$model->public_id}");
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_CREDIT);
2017-01-30 21:40:43 +02:00
},
2016-05-23 19:52:20 +03:00
],
[
trans('texts.enter_expense'),
function ($model) {
2018-05-08 23:16:35 +03:00
return URL::to("expenses/create/{$model->public_id}");
2016-05-23 19:52:20 +03:00
},
2016-07-21 15:35:23 +03:00
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_EXPENSE);
2017-01-30 21:40:43 +02:00
},
],
2016-05-23 19:52:20 +03:00
];
}
}