2016-12-23 17:52:00 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Presenters;
|
|
|
|
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ConsumablePresenter
|
|
|
|
* @package App\Presenters
|
|
|
|
*/
|
|
|
|
class ConsumablePresenter extends Presenter
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formatted JSON for data table.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function forDataTable()
|
|
|
|
{
|
|
|
|
$actions = '<nobr>';
|
|
|
|
if (Gate::allows('checkout', $this->model)) {
|
|
|
|
$actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $this->id), $this->numRemaining() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Gate::allows('update', $this->model)) {
|
|
|
|
$actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $this->id));
|
|
|
|
}
|
|
|
|
if (Gate::allows('delete', $this->model)) {
|
|
|
|
$actions .= Helper::generateDatatableButton(
|
|
|
|
'delete',
|
|
|
|
route('consumables.destroy', $this->id),
|
|
|
|
true, /* enabled */
|
|
|
|
trans('admin/consumables/message.delete.confirm'),
|
|
|
|
$this->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$actions .='</nobr>';
|
|
|
|
|
|
|
|
$results = [
|
2016-12-23 19:23:07 -08:00
|
|
|
'actions' => $actions,
|
|
|
|
'category' => $this->categoryUrl(),
|
|
|
|
'companyName' => $this->companyUrl(),
|
2016-12-23 17:52:00 -08:00
|
|
|
'id' => $this->id,
|
|
|
|
'item_no' => $this->item_no,
|
2016-12-23 19:23:07 -08:00
|
|
|
'location' => $this->locationUrl(),
|
|
|
|
'manufacturer' => $this->manufacturerUrl(),
|
|
|
|
'min_amt' => $this->min_amt,
|
|
|
|
'model_number' => $this->model_number,
|
|
|
|
'name' => $this->nameUrl(),
|
|
|
|
'numRemaining' => $this->numRemaining(),
|
2016-12-23 17:52:00 -08:00
|
|
|
'order_number' => $this->order_number,
|
|
|
|
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
|
2016-12-23 19:23:07 -08:00
|
|
|
'purchase_date' => $this->purchase_date,
|
|
|
|
'qty' => $this->qty,
|
2016-12-23 17:52:00 -08:00
|
|
|
];
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-30 11:44:47 -08:00
|
|
|
* Displayable name of consumable
|
2016-12-23 17:52:00 -08:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 11:44:47 -08:00
|
|
|
|
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->model->name;
|
|
|
|
}
|
|
|
|
|
2016-12-27 12:03:47 -08:00
|
|
|
public function nameUrl()
|
2016-12-23 17:52:00 -08:00
|
|
|
{
|
|
|
|
return (string)link_to_route('consumables.show', $this->name, $this->id);
|
|
|
|
}
|
2016-12-26 15:19:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Url to view this item.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function viewUrl()
|
|
|
|
{
|
|
|
|
return route('consumables.show', $this->id);
|
|
|
|
}
|
2016-12-23 17:52:00 -08:00
|
|
|
}
|