invoiceninja/app/Ninja/Datatables/ProjectDatatable.php

88 lines
2.5 KiB
PHP
Raw Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Ninja\Datatables;
2016-11-29 19:47:26 +02:00
use Auth;
2017-01-30 21:40:43 +02:00
use URL;
use Utils;
2016-11-29 19:47:26 +02:00
class ProjectDatatable extends EntityDatatable
{
public $entityType = ENTITY_PROJECT;
public $sortCol = 1;
2019-01-30 22:00:26 +11:00
public $fieldToSum = 'budgeted_hours';
2016-11-29 19:47:26 +02:00
public function columns()
{
return [
[
'project',
2017-01-30 18:05:31 +02:00
function ($model) {
if (Auth::user()->can('view', [ENTITY_PROJECT, $model]))
return $this->addNote(link_to("projects/{$model->public_id}", $model->project)->toHtml(), $model->private_notes);
else
2016-11-29 19:47:26 +02:00
return $model->project;
2017-01-30 21:40:43 +02:00
},
2016-11-29 19:47:26 +02:00
],
[
'client_name',
2017-01-30 18:05:31 +02:00
function ($model) {
2016-11-29 19:47:26 +02:00
if ($model->client_public_id) {
if (Auth::user()->can('view', [ENTITY_CLIENT, $model]))
return link_to("clients/{$model->client_public_id}", $model->client_name)->toHtml();
else
2016-11-29 19:47:26 +02:00
return Utils::getClientDisplayName($model);
} else {
return '';
}
2017-01-30 21:40:43 +02:00
},
],
2017-12-24 17:23:43 +02:00
[
'due_date',
function ($model) {
return Utils::fromSqlDate($model->due_date);
},
],
[
'budgeted_hours',
function ($model) {
2017-12-24 21:01:17 +02:00
return $model->budgeted_hours ?: '';
2017-12-24 17:23:43 +02:00
},
],
[
'task_rate',
function ($model) {
2017-12-24 21:01:17 +02:00
return floatval($model->task_rate) ? Utils::formatMoney($model->task_rate) : '';
}
],
2016-11-29 19:47:26 +02:00
];
}
public function actions()
{
return [
[
trans('texts.edit_project'),
function ($model) {
2017-01-30 21:40:43 +02:00
return URL::to("projects/{$model->public_id}/edit");
2016-11-29 19:47:26 +02:00
},
function ($model) {
return Auth::user()->can('view', [ENTITY_PROJECT, $model]);
2017-01-30 21:40:43 +02:00
},
2016-11-29 19:47:26 +02:00
],
[
trans('texts.invoice_project'),
function ($model) {
return "javascript:submitForm_project('invoice', {$model->public_id})";
},
function ($model) {
2019-01-30 22:00:26 +11:00
return Auth::user()->can('createEntity', ENTITY_INVOICE);
},
],
2016-11-29 19:47:26 +02:00
];
}
}