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 CreditDatatable extends EntityDatatable
|
|
|
|
|
{
|
|
|
|
|
public $entityType = ENTITY_CREDIT;
|
2016-11-24 11:41:11 +02:00
|
|
|
public $sortCol = 4;
|
2019-01-30 22:00:26 +11:00
|
|
|
public $fieldToSum = 'amount';
|
2016-11-30 20:21:50 +02:00
|
|
|
|
2016-05-23 19:52:20 +03:00
|
|
|
public function columns()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'client_name',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if (Auth::user()->can('view', [ENTITY_CLIENT, $model]))
|
|
|
|
|
return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml() : '';
|
|
|
|
|
else
|
2016-05-23 19:52:20 +03:00
|
|
|
return Utils::getClientDisplayName($model);
|
|
|
|
|
|
|
|
|
|
},
|
2017-01-30 21:40:43 +02:00
|
|
|
! $this->hideClient,
|
2016-05-23 19:52:20 +03:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'amount',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if(Auth::user()->can('view', [ENTITY_CLIENT, $model]))
|
|
|
|
|
return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id) . '<span '.Utils::getEntityRowClass($model).'/>';
|
2017-01-30 21:40:43 +02:00
|
|
|
},
|
2016-05-23 19:52:20 +03:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'balance',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if(Auth::user()->can('view', [ENTITY_CLIENT, $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
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'credit_date',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if (Auth::user()->can('view', [ENTITY_CREDIT, $model]))
|
|
|
|
|
return link_to("credits/{$model->public_id}/edit", Utils::fromSqlDate($model->credit_date_sql))->toHtml();
|
|
|
|
|
else
|
2017-03-28 12:40:53 +03:00
|
|
|
return Utils::fromSqlDate($model->credit_date_sql);
|
2016-12-04 12:24:48 +02:00
|
|
|
|
2017-01-30 21:40:43 +02:00
|
|
|
},
|
2016-05-23 19:52:20 +03:00
|
|
|
],
|
2017-03-30 11:46:52 +03:00
|
|
|
[
|
|
|
|
|
'public_notes',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if (Auth::user()->can('view', [ENTITY_CREDIT, $model]))
|
|
|
|
|
return e($model->public_notes);
|
2017-03-30 11:46:52 +03:00
|
|
|
},
|
|
|
|
|
],
|
2016-05-23 19:52:20 +03:00
|
|
|
[
|
|
|
|
|
'private_notes',
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
if (Auth::user()->can('view', [ENTITY_CREDIT, $model]))
|
|
|
|
|
return e($model->private_notes);
|
2017-01-30 21:40:43 +02:00
|
|
|
},
|
|
|
|
|
],
|
2016-05-23 19:52:20 +03:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actions()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2016-11-30 20:21:50 +02:00
|
|
|
[
|
|
|
|
|
trans('texts.edit_credit'),
|
|
|
|
|
function ($model) {
|
|
|
|
|
return URL::to("credits/{$model->public_id}/edit");
|
|
|
|
|
},
|
|
|
|
|
function ($model) {
|
2018-06-07 20:08:34 +10:00
|
|
|
return Auth::user()->can('view', [ENTITY_CREDIT, $model]);
|
2017-01-30 21:40:43 +02:00
|
|
|
},
|
2016-11-30 20:21:50 +02:00
|
|
|
],
|
2016-05-23 19:52:20 +03:00
|
|
|
[
|
|
|
|
|
trans('texts.apply_credit'),
|
|
|
|
|
function ($model) {
|
|
|
|
|
return URL::to("payments/create/{$model->client_public_id}") . '?paymentTypeId=1';
|
|
|
|
|
},
|
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
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|