2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Datatables;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use Str;
|
2017-01-30 20:40:43 +01:00
|
|
|
use URL;
|
|
|
|
use Utils;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
class ProductDatatable extends EntityDatatable
|
|
|
|
{
|
|
|
|
public $entityType = ENTITY_PRODUCT;
|
2016-11-24 10:46:57 +01:00
|
|
|
public $sortCol = 4;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
public function columns()
|
|
|
|
{
|
2018-02-14 12:25:23 +01:00
|
|
|
$account = Auth::user()->account;
|
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'product_key',
|
|
|
|
function ($model) {
|
|
|
|
return link_to('products/'.$model->public_id.'/edit', $model->product_key)->toHtml();
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'notes',
|
|
|
|
function ($model) {
|
2018-02-14 12:11:47 +01:00
|
|
|
return $this->showWithTooltip($model->notes);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'cost',
|
|
|
|
function ($model) {
|
2018-07-08 14:08:02 +02:00
|
|
|
return Utils::roundSignificant($model->cost);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'tax_rate',
|
|
|
|
function ($model) {
|
|
|
|
return $model->tax_rate ? ($model->tax_name . ' ' . $model->tax_rate . '%') : '';
|
|
|
|
},
|
2018-02-14 12:25:23 +01:00
|
|
|
$account->invoice_item_taxes,
|
|
|
|
],
|
|
|
|
[
|
2018-02-21 15:25:05 +01:00
|
|
|
'custom_value1',
|
2018-02-14 12:25:23 +01:00
|
|
|
function ($model) {
|
|
|
|
return $model->custom_value1;
|
|
|
|
},
|
2018-04-04 15:24:59 +02:00
|
|
|
$account->customLabel('product1')
|
2017-01-30 20:40:43 +01:00
|
|
|
],
|
2018-02-14 12:25:23 +01:00
|
|
|
[
|
2018-02-21 15:25:05 +01:00
|
|
|
'custom_value2',
|
2018-02-14 12:25:23 +01:00
|
|
|
function ($model) {
|
|
|
|
return $model->custom_value2;
|
|
|
|
},
|
2018-04-04 15:24:59 +02:00
|
|
|
$account->customLabel('product2')
|
2018-02-14 12:25:23 +01:00
|
|
|
]
|
2016-05-23 18:52:20 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
uctrans('texts.edit_product'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("products/{$model->public_id}/edit");
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
|
|
|
],
|
2018-03-18 10:09:24 +01:00
|
|
|
[
|
|
|
|
trans('texts.clone_product'),
|
|
|
|
function ($model) {
|
2018-03-20 12:54:24 +01:00
|
|
|
return URL::to("products/{$model->public_id}/clone");
|
2018-03-18 10:09:24 +01:00
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return Auth::user()->can('create', ENTITY_PRODUCT);
|
|
|
|
},
|
|
|
|
],
|
2017-11-03 10:25:14 +01:00
|
|
|
[
|
|
|
|
trans('texts.invoice_product'),
|
|
|
|
function ($model) {
|
|
|
|
return "javascript:submitForm_product('invoice', {$model->public_id})";
|
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return (! $model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
|
|
|
|
},
|
|
|
|
],
|
2016-05-23 18:52:20 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|