public function getCompletedAtLabel()
    {
        if ($this->isComplete()) {
            $class = 'label label-success';
            $icon = 'fa fa-check';
            $message = $this->completed_at;
        } else {
            $class = 'label label-danger';
            $icon = 'fa fa-times';
            $message = 'No report has been created.';
        }

        $icon = HTML::create('i', '', ['class' => $icon]);

        return HTML::raw("$icon $message");
    }

Returns an HTML label for the work orders completed at date.

@return string

Returns an HTML label for the work orders completed at date .


public function complete($statusId)
    {
        if (is_null($this->started_at)) {
            $this->started_at = $this->freshTimestamp();
        }

        $this->completed_at = $this->freshTimestamp();
        $this->status_id = $statusId;

        return $this->save();
    }

public function complete ( $ statusId ) { if ( is_null ( $ this -> started_at ) ) { $ this -> started_at = $ this -> freshTimestamp ( ) ; } $ this -> completed_at = $ this -> freshTimestamp ( ) ; $ this -> status_id = $ statusId ; return $ this -> save ( ) ; }

Completes the work order by saving the completed at timestamp to now.

@param int|string $statusId

@return $this|bool

Completes the work order by saving the completed at timestamp to now .


public function table(Status $status)
    {
        return $this->table->of('work-orders.statuses', function (TableGrid $table) use ($status) {
            $table->with($status)->paginate($this->perPage);

            $table->column('Status', function (Column $column) {
                $column->value = function (Status $status) {
                    return link_to_route('maintenance.work-orders.statuses.edit', $status->getLabel(), [$status->getKey()]);
                };
            });

            $table->column('created_at');

            $table->column('created_by', function (Column $column) {
                $column->value = function (Status $status) {
                    if ($status->user instanceof User) {
                        return $status->user->getRecipientName();
                    } else {
                        return HTML::create('em', 'None');
                    }
                };
            });
        });
    }

public function table ( Status $ status ) { return $ this -> table -> of ( 'work-orders.statuses' , function ( TableGrid $ table ) use ( $ status ) { $ table -> with ( $ status ) -> paginate ( $ this -> perPage ) ; $ table -> column ( 'Status' , function ( Column $ column ) { $ column -> value = function ( Status $ status ) { return link_to_route ( 'maintenance.work-orders.statuses.edit' , $ status -> getLabel ( ) , [ $ status -> getKey ( ) ] ) ; } ; } ) ; $ table -> column ( 'created_at' ) ; $ table -> column ( 'created_by' , function ( Column $ column ) { $ column -> value = function ( Status $ status ) { if ( $ status -> user instanceof User ) { return $ status -> user -> getRecipientName ( ) ; } else { return HTML :: create ( 'em' , 'None' ) ; } } ; } ) ; } ) ; }

Returns a new table of all statuses.

@param Status $status

@return \Orchestra\Contracts\Html\Builder


public function form(Status $status)
    {
        return $this->form->of('work-orders.statuses', function (FormGrid $form) use ($status) {
            if ($status->exists) {
                $method = 'PATCH';
                $url = route('maintenance.work-orders.statuses.update', [$status->getKey()]);
                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $url = route('maintenance.work-orders.statuses.store', [$status->getKey()]);
                $form->submit = 'Create';
            }

            $colors = config('maintenance.colors', []);

            $form->with($status);

            $form->attributes(compact('method', 'url'));

            $form->fieldset(function (Fieldset $fieldset) use ($colors) {
                $fieldset
                    ->control('input:text', 'name')
                    ->attributes([
                        'placeholder' => 'ex. Awaiting Parts / Supplies',
                    ]);

                $fieldset
                    ->control('select', 'color')
                    ->options($colors)
                    ->value(function (Status $status) {
                        return $status->color;
                    })
                    ->attributes([
                        'class' => 'select2-color',
                    ]);
            });
        });
    }

Returns a new form of the specified status.

@param Status $status

@return \Orchestra\Contracts\Html\Builder

Returns a new form of the specified status .


public function index()
    {
        $priorities = $this->presenter->table($this->priority);

        $navbar = $this->presenter->navbar();

        return view('work-orders.priorities.index', compact('priorities', 'navbar'));
    }

public function index ( ) { $ priorities = $ this -> presenter -> table ( $ this -> priority ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'work-orders.priorities.index' , compact ( 'priorities' , 'navbar' ) ) ; }

Displays all priorities.

@return \Illuminate\View\View


public function store(PriorityRequest $request)
    {
        $priority = $this->priority->newInstance();

        return $this->dispatch(new Store($request, $priority));
    }

public function store ( PriorityRequest $ request ) { $ priority = $ this -> priority -> newInstance ( ) ; return $ this -> dispatch ( new Store ( $ request , $ priority ) ) ; }

Creates a new priority.

@param PriorityRequest $request

@return bool


public function edit($id)
    {
        $priority = $this->priority->findOrFail($id);

        $form = $this->presenter->form($priority);

        return view('work-orders.priorities.edit', compact('form'));
    }

public function edit ( $ id ) { $ priority = $ this -> priority -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ priority ) ; return view ( 'work-orders.priorities.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified priority.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified priority .


public function update(PriorityRequest $request, $id)
    {
        $priority = $this->priority->findOrFail($id);

        return $this->dispatch(new Update($request, $priority));
    }

public function update ( PriorityRequest $ request , $ id ) { $ priority = $ this -> priority -> findOrFail ( $ id ) ; return $ this -> dispatch ( new Update ( $ request , $ priority ) ) ; }

Updates the specified priority.

@param PriorityRequest $request
@param int|string      $id

@return bool


public function scopeStock($query, $operator = null, $stock = null)
    {
        if ($operator && $stock) {
            return $query->whereHas('stocks', function ($query) use ($operator, $stock) {
                if ($output = $this->getOperator($operator)) {
                    return $query->where('quantity', $output[0], $stock);
                } else {
                    return $query;
                }
            });
        }

        return $query;
    }

public function scopeStock ( $ query , $ operator = null , $ stock = null ) { if ( $ operator && $ stock ) { return $ query -> whereHas ( 'stocks' , function ( $ query ) use ( $ operator , $ stock ) { if ( $ output = $ this -> getOperator ( $ operator ) ) { return $ query -> where ( 'quantity' , $ output [ 0 ] , $ stock ) ; } else { return $ query ; } } ) ; } return $ query ; }

Filters query by the inputted inventory item stock quantity.

@param $query
@param string $operator
@param string $stock

@return mixed

Filters query by the inputted inventory item stock quantity .


public function scopeSku($query, $sku = null)
    {
        if ($sku) {
            return $query->whereHas('sku', function ($query) use ($sku) {
                return $query->where('code', 'LIKE', '%'.$sku.'%');
            });
        }

        return $query;
    }

public function scopeSku ( $ query , $ sku = null ) { if ( $ sku ) { return $ query -> whereHas ( 'sku' , function ( $ query ) use ( $ sku ) { return $ query -> where ( 'code' , 'LIKE' , '%' . $ sku . '%' ) ; } ) ; } return $ query ; }

Filters query by the inputted inventory sku.

@param $query
@param string $sku

@return mixed

Filters query by the inputted inventory sku .


public function getCurrentStockAttribute()
    {
        $stock = $this->getTotalStock();

        if ($this->hasMetric()) {
            return sprintf('%s %s', $stock, $this->getMetricSymbol());
        }

        return $stock;
    }

public
function
getCurrentStockAttribute
(
)
{
$
stock
=
$
this
->
getTotalStock
(
)
;
if
(
$
this
->
hasMetric
(
)
)
{
return
sprintf
(
'%s %s'
,
$
stock
,
$
this
->
getMetricSymbol
(
)
)
;
}
return
$
stock
;
}

Mutator for showing the total current stock of the inventory item.

@return int|string

Mutator for showing the total current stock of the inventory item .


public function getRevisedMetricAttribute($id)
    {
        if ($id) {
            $metric = $this->metric()->find($id);

            if ($metric) {
                return $metric->name;
            }
        }

        return;
    }

public function getRevisedMetricAttribute ( $ id ) { if ( $ id ) { $ metric = $ this -> metric ( ) -> find ( $ id ) ; if ( $ metric ) { return $ metric -> name ; } } return ; }

Retrieves the revised metric attribute.

@param int|string $id

@return null|string

Retrieves the revised metric attribute .


protected function getOperator($string)
    {
        $allowed_operators = ['>', '<', '=', '>=', '<='];

        $output = preg_split("/[\[\]]/", $string);

        if (is_array($output)) {
            if (array_key_exists('1', $output) && array_key_exists('2', $output)) {
                if (in_array($output[1], $allowed_operators)) {
                    return [$output[1], $output[2]];
                }
            } else {
                return $output;
            }
        }

        return false;
    }

protected function getOperator ( $ string ) { $ allowed_operators = [ '>' , '<' , '=' , '>=' , '<=' ] ; $ output = preg_split ( "/[\[\]]/" , $ string ) ; if ( is_array ( $ output ) ) { if ( array_key_exists ( '1' , $ output ) && array_key_exists ( '2' , $ output ) ) { if ( in_array ( $ output [ 1 ] , $ allowed_operators ) ) { return [ $ output [ 1 ] , $ output [ 2 ] ] ; } } else { return $ output ; } } return false ; }

Retrieves a valid operator from the specified string.

@param string $string

@return bool|array

Retrieves a valid operator from the specified string .


public function scopeSort($query, $field = null, $sort = null)
    {
        /*
         * Make sure both the field and sort variables are present
         */
        if ($field && $sort) {
            /*
             * Retrieve all column names for the current model table
             */
            $columns = Schema::getColumnListing($this->getTable());

            /*
             * Make sure the field inputted is available on the current table
             */
            if (in_array($field, $columns)) {

                /*
                 * Make sure the sort input is equal to asc or desc
                 */
                if ($sort === 'asc' || $sort === 'desc') {
                    /*
                     * Return the query sorted
                     */
                    return $query->orderBy($field, $sort);
                }
            }
        }

        /*
         * Default to latest scope
         */
        return $query->latest();
    }

/*
                     * Return the query sorted
                     */

/*
         * Default to latest scope
         */

Allows all columns on the current database table to be sorted through
query scope.

@param object $query
@param string $field
@param string $sort

@return object

Allows all columns on the current database table to be sorted through query scope .


public function getFullPathAttribute()
    {
        $config = sprintf('filesystems.%s.root', $this->getDisk());

        $default = storage_path('app');

        $basePath = config($config, $default);

        return $basePath.DIRECTORY_SEPARATOR.$this->file_path;
    }

public function getFullPathAttribute ( ) { $ config = sprintf ( 'filesystems.%s.root' , $ this -> getDisk ( ) ) ; $ default = storage_path ( 'app' ) ; $ basePath = config ( $ config , $ default ) ; return $ basePath . DIRECTORY_SEPARATOR . $ this -> file_path ; }

Returns the full path of the uploaded file.

@return string

Returns the full path of the uploaded file .


public function index()
    {
        $statuses = $this->presenter->table($this->status);

        $navbar = $this->presenter->navbar();

        return view('work-orders.statuses.index', compact('statuses', 'navbar'));
    }

public function index ( ) { $ statuses = $ this -> presenter -> table ( $ this -> status ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'work-orders.statuses.index' , compact ( 'statuses' , 'navbar' ) ) ; }

Displays all statuses.

@return \Illuminate\View\View


public function store(StatusRequest $request)
    {
        $status = $this->status->newInstance();

        return $this->dispatch(new Store($request, $status));
    }

public function store ( StatusRequest $ request ) { $ status = $ this -> status -> newInstance ( ) ; return $ this -> dispatch ( new Store ( $ request , $ status ) ) ; }

Creates a new status.

@param StatusRequest $request

@return bool


public function edit($id)
    {
        $status = $this->status->findOrFail($id);

        $form = $this->presenter->form($status);

        return view('work-orders.statuses.edit', compact('form'));
    }

public function edit ( $ id ) { $ status = $ this -> status -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ status ) ; return view ( 'work-orders.statuses.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified status.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified status .


public function update(StatusRequest $request, $id)
    {
        $status = $this->status->findOrFail($id);

        return $this->dispatch(new Update($request, $status));
    }

public function update ( StatusRequest $ request , $ id ) { $ status = $ this -> status -> findOrFail ( $ id ) ; return $ this -> dispatch ( new Update ( $ request , $ status ) ) ; }

Updates the specified status.

@param StatusRequest $request
@param int|string    $id

@return bool


public function create($itemId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $form = $this->presenter->form($item, $variant = true);

        return view('inventory.variants.create', compact('form'));
    }

public function create ( $ itemId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ form = $ this -> presenter -> form ( $ item , $ variant = true ) ; return view ( 'inventory.variants.create' , compact ( 'form' ) ) ; }

Displays the form for creating a variant for the specified inventory item.

@param int|string $itemId

@return \Illuminate\View\View

Displays the form for creating a variant for the specified inventory item .


public function store(InventoryRequest $request, $itemId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $variant = $item->newVariant();

        $variant->name = $request->input('name', $item->name);
        $variant->category_id = $request->input('category', $item->category_id);
        $variant->metric_id = $request->input('metric', $item->metric_id);

        return $variant->save();
    }

public function store ( InventoryRequest $ request , $ itemId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ variant = $ item -> newVariant ( ) ; $ variant -> name = $ request -> input ( 'name' , $ item -> name ) ; $ variant -> category_id = $ request -> input ( 'category' , $ item -> category_id ) ; $ variant -> metric_id = $ request -> input ( 'metric' , $ item -> metric_id ) ; return $ variant -> save ( ) ; }

Creates a variant of the specified inventory item.

@param InventoryRequest $request
@param int|string       $itemId

@return bool

Creates a variant of the specified inventory item .


public function create($workOrderId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        if ($workOrder->isComplete()) {
            throw new ReportExistsException();
        }

        $form = $this->presenter->form($workOrder, $this->report);

        return view('work-orders.report.create', compact('form'));
    }

public function create ( $ workOrderId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; if ( $ workOrder -> isComplete ( ) ) { throw new ReportExistsException ( ) ; } $ form = $ this -> presenter -> form ( $ workOrder , $ this -> report ) ; return view ( 'work-orders.report.create' , compact ( 'form' ) ) ; }

Displays the form for creating a work order report.

@param int|string $workOrderId

@throws ReportExistsException

@return \Illuminate\View\View

Displays the form for creating a work order report .


public function store(ReportRequest $request, $workOrderId)
    {
        $workOrder = $this->workOrder->findOrFail($workOrderId);

        $report = $this->report->newInstance();

        return $this->dispatch(new Store($request, $workOrder, $report));
    }

public function store ( ReportRequest $ request , $ workOrderId ) { $ workOrder = $ this -> workOrder -> findOrFail ( $ workOrderId ) ; $ report = $ this -> report -> newInstance ( ) ; return $ this -> dispatch ( new Store ( $ request , $ workOrder , $ report ) ) ; }

Creates a new work order report.

@param ReportRequest $request
@param int|string    $workOrderId

@return bool


public function table($workOrder)
    {
        return $this->table->of('work-orders', function (TableGrid $table) use ($workOrder) {
            $table->with($workOrder)->paginate($this->perPage);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('ID', 'id');

            $table->column('subject', function (Column $column) {
                $column->value = function (WorkOrder $workOrder) {
                    return link_to_route('maintenance.work-orders.show', $workOrder->subject, [$workOrder->getKey()]);
                };
            });

            $table->column('Created At', 'created_at');

            $table->column('created_by', function (Column $column) {
                $column->value = function (WorkOrder $workOrder) {
                    return $workOrder->user->fullname;
                };
            });

            $table->column('priority', function (Column $column) {
                $column->value = function (WorkOrder $workOrder) {
                    if ($workOrder->priority instanceof Priority) {
                        return $workOrder->priority->getLabel();
                    }

                    return HTML::create('em', 'None');
                };
            });

            $table->column('status', function (Column $column) {
                $column->value = function (WorkOrder $workOrder) {
                    if ($workOrder->status instanceof Status) {
                        return $workOrder->status->getLabel();
                    }

                    return HTML::create('em', 'None');
                };
            });
        });
    }

public
function
table
(
$
workOrder
)
{
return
$
this
->
table
->
of
(
'work-orders'
,
function
(
TableGrid
$
table
)
use
(
$
workOrder
)
{
$
table
->
with
(
$
workOrder
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'ID'
,
'id'
)
;
$
table
->
column
(
'subject'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrder
$
workOrder
)
{
return
link_to_route
(
'maintenance.work-orders.show'
,
$
workOrder
->
subject
,
[
$
workOrder
->
getKey
(
)
]
)
;
}
;
}
)
;
$
table
->
column
(
'Created At'
,
'created_at'
)
;
$
table
->
column
(
'created_by'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrder
$
workOrder
)
{
return
$
workOrder
->
user
->
fullname
;
}
;
}
)
;
$
table
->
column
(
'priority'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrder
$
workOrder
)
{
if
(
$
workOrder
->
priority
instanceof
Priority
)
{
return
$
workOrder
->
priority
->
getLabel
(
)
;
}
return
HTML
::
create
(
'em'
,
'None'
)
;
}
;
}
)
;
$
table
->
column
(
'status'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
WorkOrder
$
workOrder
)
{
if
(
$
workOrder
->
status
instanceof
Status
)
{
return
$
workOrder
->
status
->
getLabel
(
)
;
}
return
HTML
::
create
(
'em'
,
'None'
)
;
}
;
}
)
;
}
)
;
}

Returns a new table of all work orders.

@param WorkOrder|Builder $workOrder

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all work orders .


public function tableAssigned($workOrder)
    {
        $workOrder = $workOrder->whereHas('assignments', function (Builder $query) {
            $query->where('to_user_id', auth()->id());
        });

        return $this->table($workOrder);
    }

public function tableAssigned ( $ workOrder ) { $ workOrder = $ workOrder -> whereHas ( 'assignments' , function ( Builder $ query ) { $ query -> where ( 'to_user_id' , auth ( ) -> id ( ) ) ; } ) ; return $ this -> table ( $ workOrder ) ; }

Returns a new table of all work orders assigned to the current user.

@param WorkOrder|Builder $workOrder

@return Builder

Returns a new table of all work orders assigned to the current user .


public function tableSessions(WorkOrder $workOrder)
    {
        $presenter = new WorkOrderSessionPresenter($this->form, $this->table);

        return $presenter->tablePerWorker($workOrder);
    }

public function tableSessions ( WorkOrder $ workOrder ) { $ presenter = new WorkOrderSessionPresenter ( $ this -> form , $ this -> table ) ; return $ presenter -> tablePerWorker ( $ workOrder ) ; }

Displays a table of all unique sessions on the specified work order.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder

Displays a table of all unique sessions on the specified work order .


public function form(WorkOrder $workOrder)
    {
        return $this->form->of('work-orders', function (FormGrid $form) use ($workOrder) {
            if ($workOrder->exists) {
                $method = 'PATCH';
                $url = route('maintenance.work-orders.update', [$workOrder->getKey()]);
                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $url = route('maintenance.work-orders.store');
                $form->submit = 'Create';
            }

            $form->with($workOrder);

            $form->attributes(compact('method', 'url'));

            $form->fieldset(function (Fieldset $fieldset) {
                $fieldset
                    ->control('select', 'category')
                    ->value(function (WorkOrder $workOrder) {
                        return $workOrder->category_id;
                    })
                    ->options(function () {
                        return Category::getSelectHierarchy('work-orders');
                    });

                $fieldset
                    ->control('select', 'location')
                    ->value(function (WorkOrder $workOrder) {
                        return $workOrder->location_id;
                    })
                    ->options(function () {
                        return Location::getSelectHierarchy();
                    });

                $fieldset
                    ->control('select', 'status')
                    ->options(function () {
                        $statuses = Status::all()->pluck('name', 'id');
                        $statuses[0] = 'None';

                        return $statuses;
                    });

                $fieldset
                    ->control('select', 'priority')
                    ->value(function (WorkOrder $workOrder) {
                        return $workOrder->priority_id;
                    })
                    ->options(function () {
                        $priorities = Priority::all()->pluck('name', 'id');
                        $priorities[0] = 'None';

                        return $priorities;
                    });

                $fieldset
                    ->control('select', 'assets[]')
                    ->label('Assets')
                    ->options(function () {
                        return Asset::all()->pluck('name', 'id');
                    })
                    ->attributes([
                        'class'    => 'select2',
                        'multiple' => true,
                    ]);

                $fieldset
                    ->control('input:text', 'subject')
                    ->attributes([
                        'placeholder' => 'ex. Worked on HVAC',
                    ]);

                $fieldset->control('input:textarea', 'description');
            });
        });
    }

public
function
form
(
WorkOrder
$
workOrder
)
{
return
$
this
->
form
->
of
(
'work-orders'
,
function
(
FormGrid
$
form
)
use
(
$
workOrder
)
{
if
(
$
workOrder
->
exists
)
{
$
method
=
'PATCH'
;
$
url
=
route
(
'maintenance.work-orders.update'
,
[
$
workOrder
->
getKey
(
)
]
)
;
$
form
->
submit
=
'Save'
;
}
else
{
$
method
=
'POST'
;
$
url
=
route
(
'maintenance.work-orders.store'
)
;
$
form
->
submit
=
'Create'
;
}
$
form
->
with
(
$
workOrder
)
;
$
form
->
attributes
(
compact
(
'method'
,
'url'
)
)
;
$
form
->
fieldset
(
function
(
Fieldset
$
fieldset
)
{
$
fieldset
->
control
(
'select'
,
'category'
)
->
value
(
function
(
WorkOrder
$
workOrder
)
{
return
$
workOrder
->
category_id
;
}
)
->
options
(
function
(
)
{
return
Category
::
getSelectHierarchy
(
'work-orders'
)
;
}
)
;
$
fieldset
->
control
(
'select'
,
'location'
)
->
value
(
function
(
WorkOrder
$
workOrder
)
{
return
$
workOrder
->
location_id
;
}
)
->
options
(
function
(
)
{
return
Location
::
getSelectHierarchy
(
)
;
}
)
;
$
fieldset
->
control
(
'select'
,
'status'
)
->
options
(
function
(
)
{
$
statuses
=
Status
::
all
(
)
->
pluck
(
'name'
,
'id'
)
;
$
statuses
[
0
]
=
'None'
;
return
$
statuses
;
}
)
;
$
fieldset
->
control
(
'select'
,
'priority'
)
->
value
(
function
(
WorkOrder
$
workOrder
)
{
return
$
workOrder
->
priority_id
;
}
)
->
options
(
function
(
)
{
$
priorities
=
Priority
::
all
(
)
->
pluck
(
'name'
,
'id'
)
;
$
priorities
[
0
]
=
'None'
;
return
$
priorities
;
}
)
;
$
fieldset
->
control
(
'select'
,
'assets[]'
)
->
label
(
'Assets'
)
->
options
(
function
(
)
{
return
Asset
::
all
(
)
->
pluck
(
'name'
,
'id'
)
;
}
)
->
attributes
(
[
'class'
=>
'select2'
,
'multiple'
=>
true
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'subject'
)
->
attributes
(
[
'placeholder'
=>
'ex. Worked on HVAC'
,
]
)
;
$
fieldset
->
control
(
'input:textarea'
,
'description'
)
;
}
)
;
}
)
;
}

Returns a new form for work orders.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder


public function formComment(WorkOrder $workOrder, Comment $comment)
    {
        $presenter = new WorkOrderCommentPresenter($this->form, $this->table);

        return $presenter->form($workOrder, $comment);
    }

public function formComment ( WorkOrder $ workOrder , Comment $ comment ) { $ presenter = new WorkOrderCommentPresenter ( $ this -> form , $ this -> table ) ; return $ presenter -> form ( $ workOrder , $ comment ) ; }

Returns a new form for the specified work order comment.

@param WorkOrder $workOrder
@param Comment   $comment

@return \Orchestra\Contracts\Html\Builder

Returns a new form for the specified work order comment .


public function handle(Filesystem $filesystem)
    {
        $files = $this->request->file('files');

        if (is_array($files)) {
            $uploaded = [];

            foreach ($files as $file) {
                // Double check that we have an uploaded file instance.
                if ($file instanceof UploadedFile) {
                    // Generates the unique file name.
                    $name = implode('.', [uuid(), $file->getClientOriginalExtension()]);

                    // Generates the complete storage path.
                    $path = implode(DIRECTORY_SEPARATOR, [$this->path, $name]);

                    // Try and move the uploaded file into storage.
                    if ($filesystem->put($path, file_get_contents($file->getRealPath()))) {
                        // Successfully moved uploaded file, create the record.

                        $attributes = [
                            'user_id'   => auth()->id(),
                            'name'      => $file->getClientOriginalName(),
                            'file_name' => $name,
                            'file_path' => $path,
                        ];

                        $uploaded[] = $this->relation->create($attributes);
                    }
                }
            }

            return $uploaded;
        }

        return false;
    }

Uploads and attaches files for the current relation.

@param Filesystem $filesystem

@return bool|array

Uploads and attaches files for the current relation .


public function table(Asset $asset)
    {
        return $this->table->of('assets', function (TableGrid $table) use ($asset) {
            $table->with($asset)->paginate($this->perPage);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('tag');

            $table->column('name', function (Column $column) {
                $column->value = function (Asset $asset) {
                    return link_to_route('maintenance.assets.show', $asset->name, [$asset->getKey()]);
                };
            });

            $table->column('category', function (Column $column) {
                $column->value = function (Asset $asset) {
                    return $asset->category->trail;
                };
            });

            $table->column('location', function (Column $column) {
                $column->value = function (Asset $asset) {
                    return $asset->location->trail;
                };
            });

            $table->column('created_at');
        });
    }

public
function
table
(
Asset
$
asset
)
{
return
$
this
->
table
->
of
(
'assets'
,
function
(
TableGrid
$
table
)
use
(
$
asset
)
{
$
table
->
with
(
$
asset
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'tag'
)
;
$
table
->
column
(
'name'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Asset
$
asset
)
{
return
link_to_route
(
'maintenance.assets.show'
,
$
asset
->
name
,
[
$
asset
->
getKey
(
)
]
)
;
}
;
}
)
;
$
table
->
column
(
'category'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Asset
$
asset
)
{
return
$
asset
->
category
->
trail
;
}
;
}
)
;
$
table
->
column
(
'location'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Asset
$
asset
)
{
return
$
asset
->
location
->
trail
;
}
;
}
)
;
$
table
->
column
(
'created_at'
)
;
}
)
;
}

Returns a new table of all assets.

@param Asset $asset

@return \Orchestra\Contracts\Html\Builder


public function form(Asset $asset)
    {
        return $this->form->of('assets', function (FormGrid $form) use ($asset) {
            if ($asset->exists) {
                $method = 'PATCH';
                $route = route('maintenance.assets.update', [$asset->getKey()]);
                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $route = route('maintenance.assets.store');
                $form->submit = 'Create';
            }

            $categories = Category::getSelectHierarchy('assets');
            $locations = Location::getSelectHierarchy();

            $form->resource($this, $route, $asset, compact('method'));

            $form->fieldset(function (Fieldset $fieldset) use ($categories, $locations) {
                $fieldset
                    ->control('input:text', 'tag')
                    ->attributes([
                        'placeholder' => 'ex. 100010',
                    ]);

                $fieldset
                    ->control('input:text', 'name')
                    ->attributes([
                        'placeholder' => 'ex. Ford F150',
                    ]);

                $fieldset
                    ->control('select', 'category')
                    ->options($categories)
                    ->value(function (Asset $asset) {
                        return $asset->category_id;
                    });

                $fieldset
                    ->control('select', 'location')
                    ->options($locations)
                    ->value(function (Asset $asset) {
                        return $asset->location_id;
                    });

                $fieldset->control('input:textarea', 'description');

                $fieldset->control('select', 'condition')
                    ->options(trans('assets.conditions'))
                    ->value(function (Asset $asset) {
                        return $asset->condition_number;
                    });

                $fieldset->control('input:text', 'vendor')
                    ->attributes([
                        'placeholder' => 'ex. Ford',
                    ]);

                $fieldset->control('input:text', 'make')
                    ->attributes([
                        'placeholder' => 'ex. F',
                    ]);

                $fieldset->control('input:text', 'model')
                    ->attributes([
                        'placeholder' => 'ex. 150',
                    ]);

                $fieldset->control('input:text', 'serial')
                    ->attributes([
                        'placeholder' => 'ex. 153423-13432432-2342423',
                    ]);

                $fieldset->control('input:text', 'size')
                    ->attributes([
                        'placeholder' => 'ex. 1905 x 2463',
                    ]);

                $fieldset->control('input:text', 'weight')
                    ->attributes([
                        'placeholder' => 'ex. 1 Ton',
                    ]);

                $fieldset->control('input:text', 'acquired_at')
                    ->attributes([
                        'class'       => 'pickadate',
                        'placeholder' => 'Click to Select a Date',
                    ]);

                $fieldset->control('input:text', 'end_of_life')
                    ->attributes([
                        'class'       => 'pickadate',
                        'placeholder' => 'Click to Select a Date',
                    ]);
            });
        });
    }

public
function
form
(
Asset
$
asset
)
{
return
$
this
->
form
->
of
(
'assets'
,
function
(
FormGrid
$
form
)
use
(
$
asset
)
{
if
(
$
asset
->
exists
)
{
$
method
=
'PATCH'
;
$
route
=
route
(
'maintenance.assets.update'
,
[
$
asset
->
getKey
(
)
]
)
;
$
form
->
submit
=
'Save'
;
}
else
{
$
method
=
'POST'
;
$
route
=
route
(
'maintenance.assets.store'
)
;
$
form
->
submit
=
'Create'
;
}
$
categories
=
Category
::
getSelectHierarchy
(
'assets'
)
;
$
locations
=
Location
::
getSelectHierarchy
(
)
;
$
form
->
resource
(
$
this
,
$
route
,
$
asset
,
compact
(
'method'
)
)
;
$
form
->
fieldset
(
function
(
Fieldset
$
fieldset
)
use
(
$
categories
,
$
locations
)
{
$
fieldset
->
control
(
'input:text'
,
'tag'
)
->
attributes
(
[
'placeholder'
=>
'ex. 100010'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'name'
)
->
attributes
(
[
'placeholder'
=>
'ex. Ford F150'
,
]
)
;
$
fieldset
->
control
(
'select'
,
'category'
)
->
options
(
$
categories
)
->
value
(
function
(
Asset
$
asset
)
{
return
$
asset
->
category_id
;
}
)
;
$
fieldset
->
control
(
'select'
,
'location'
)
->
options
(
$
locations
)
->
value
(
function
(
Asset
$
asset
)
{
return
$
asset
->
location_id
;
}
)
;
$
fieldset
->
control
(
'input:textarea'
,
'description'
)
;
$
fieldset
->
control
(
'select'
,
'condition'
)
->
options
(
trans
(
'assets.conditions'
)
)
->
value
(
function
(
Asset
$
asset
)
{
return
$
asset
->
condition_number
;
}
)
;
$
fieldset
->
control
(
'input:text'
,
'vendor'
)
->
attributes
(
[
'placeholder'
=>
'ex. Ford'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'make'
)
->
attributes
(
[
'placeholder'
=>
'ex. F'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'model'
)
->
attributes
(
[
'placeholder'
=>
'ex. 150'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'serial'
)
->
attributes
(
[
'placeholder'
=>
'ex. 153423-13432432-2342423'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'size'
)
->
attributes
(
[
'placeholder'
=>
'ex. 1905 x 2463'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'weight'
)
->
attributes
(
[
'placeholder'
=>
'ex. 1 Ton'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'acquired_at'
)
->
attributes
(
[
'class'
=>
'pickadate'
,
'placeholder'
=>
'Click to Select a Date'
,
]
)
;
$
fieldset
->
control
(
'input:text'
,
'end_of_life'
)
->
attributes
(
[
'class'
=>
'pickadate'
,
'placeholder'
=>
'Click to Select a Date'
,
]
)
;
}
)
;
}
)
;
}

Returns a new form for the specified asset.

@param Asset $asset

@return \Orchestra\Contracts\Html\Builder

Returns a new form for the specified asset .


public function table($item)
    {
        return $this->table->of('inventory', function (TableGrid $table) use ($item) {
            $table->with($item)->paginate($this->perPage);

            $table->attributes([
                'class' => 'table table-hover table-striped',
            ]);

            $table->column('ID', 'id');

            $table->column('sku', function (Column $column) {
                $column->label = 'SKU';

                $column->value = function (Inventory $item) {
                    return $item->getSku();
                };
            });

            $table->column('name', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return link_to_route('maintenance.inventory.show', $item->name, [$item->getKey()]);
                };
            });

            $table->column('category', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return $item->category->trail;
                };
            });

            $table->column('current_stock', function (Column $column) {
                $column->value = function (Inventory $item) {
                    return $item->getTotalStock();
                };
            });
        });
    }

public
function
table
(
$
item
)
{
return
$
this
->
table
->
of
(
'inventory'
,
function
(
TableGrid
$
table
)
use
(
$
item
)
{
$
table
->
with
(
$
item
)
->
paginate
(
$
this
->
perPage
)
;
$
table
->
attributes
(
[
'class'
=>
'table table-hover table-striped'
,
]
)
;
$
table
->
column
(
'ID'
,
'id'
)
;
$
table
->
column
(
'sku'
,
function
(
Column
$
column
)
{
$
column
->
label
=
'SKU'
;
$
column
->
value
=
function
(
Inventory
$
item
)
{
return
$
item
->
getSku
(
)
;
}
;
}
)
;
$
table
->
column
(
'name'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Inventory
$
item
)
{
return
link_to_route
(
'maintenance.inventory.show'
,
$
item
->
name
,
[
$
item
->
getKey
(
)
]
)
;
}
;
}
)
;
$
table
->
column
(
'category'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Inventory
$
item
)
{
return
$
item
->
category
->
trail
;
}
;
}
)
;
$
table
->
column
(
'current_stock'
,
function
(
Column
$
column
)
{
$
column
->
value
=
function
(
Inventory
$
item
)
{
return
$
item
->
getTotalStock
(
)
;
}
;
}
)
;
}
)
;
}

Returns a table of all inventory items.

@param Inventory|\Illuminate\Database\Eloquent\Builder $item

@return \Orchestra\Contracts\Html\Builder

Returns a table of all inventory items .


public function tableStocks(Inventory $item)
    {
        return (new InventoryStockPresenter($this->form, $this->table))->table($item);
    }

public function tableStocks ( Inventory $ item ) { return ( new InventoryStockPresenter ( $ this -> form , $ this -> table ) ) -> table ( $ item ) ; }

Returns a table of stocks for the specified inventory item.

@param Inventory $item

@return \Orchestra\Contracts\Html\Builder

Returns a table of stocks for the specified inventory item .


public function form(Inventory $inventory, $variant = false)
    {
        return $this->form->of('inventory', function (FormGrid $form) use ($inventory, $variant) {
            if ($inventory->exists) {
                if ($variant === true) {
                    // If the inventory item exists and we're looking to create a form
                    // for a variant, we'll set the forms options accordingly.
                    $method = 'POST';
                    $url = route('maintenance.inventory.variants.store', [$inventory->getKey()]);
                    $form->submit = 'Create';
                } else {
                    // Otherwise we'll set the options to update the specified inventory item.
                    $method = 'PATCH';
                    $url = route('maintenance.inventory.update', [$inventory->getKey()]);
                    $form->submit = 'Save';
                }
            } else {
                $method = 'POST';
                $url = route('maintenance.inventory.store');
                $form->submit = 'Create';
            }

            $form->with($inventory);

            $form->attributes(compact('method', 'url'));

            $categories = Category::getSelectHierarchy('inventories');

            $metrics = Metric::all()->pluck('name', 'id');
            $metrics->put(0, 'None');

            $form->fieldset(function (Fieldset $fieldset) use ($categories, $metrics) {
                $fieldset
                    ->control('select', 'category')
                    ->value(function (Inventory $item) {
                        return $item->category_id;
                    })
                    ->options($categories);

                $fieldset
                    ->control('select', 'metric')
                    ->value(function (Inventory $item) {
                        return $item->metric_id;
                    })
                    ->options($metrics);

                $fieldset
                    ->control('input:text', 'name')
                    ->attributes([
                        'placeholder' => 'ex. Nails',
                    ]);

                $fieldset->control('input:textarea', 'description');
            });
        });
    }

Returns a new form for creating a new inventory item.

@param Inventory  $inventory
@param bool|false $variant

@return \Orchestra\Contracts\Html\Builder

Returns a new form for creating a new inventory item .


public function navbarStocks(Inventory $item)
    {
        return (new InventoryStockPresenter($this->form, $this->table))->navbar($item);
    }

public function navbarStocks ( Inventory $ item ) { return ( new InventoryStockPresenter ( $ this -> form , $ this -> table ) ) -> navbar ( $ item ) ; }

Returns a new navbar for the inventory stocks index.

@param Inventory $item

@return \Illuminate\Support\Fluent

Returns a new navbar for the inventory stocks index .


public function store(AttachmentRequest $request, $workOrderId)
    {
        if ($uploaded = $this->processor->store($request, $workOrderId)) {
            $count = (is_array($uploaded) ? count($uploaded) : 0);

            flash()->success('Success!', "Successfully uploaded $count file(s).");

            return redirect()->route('maintenance.work-orders.attachments.index', [$workOrderId]);
        } else {
            flash()->error('Error!', 'There was an issue uploading the files you selected. Please try again.');

            return redirect()->route('maintenance.work-orders.attachments.create', [$workOrderId]);
        }
    }

Processes storing the attachment record.

@param AttachmentRequest $request
@param int|string        $workOrderId

@return \Illuminate\Http\RedirectResponse

Processes storing the attachment record .


public function update(AttachmentUpdateRequest $request, $workOrderId, $attachmentId)
    {
        if ($this->processor->update($request, $workOrderId, $attachmentId)) {
            flash()->success('Success!', 'Successfully updated attachment.');

            return redirect()->route('maintenance.work-orders.attachments.show', [$workOrderId, $attachmentId]);
        } else {
            flash()->error('Error!', 'There was an issue updating this attachment. Please try again.');

            return redirect()->route('maintenance.work-orders.attachments.edit', [$workOrderId, $attachmentId]);
        }
    }

Updates the specified ticket upload.

@param AttachmentUpdateRequest $request
@param int|string              $workOrderId
@param int|string              $attachmentId

@return \Illuminate\Http\RedirectResponse


public function table(Metric $metric)
    {
        return $this->table->of('metrics', function (TableGrid $table) use ($metric) {
            $table->with($metric)->paginate($this->perPage);

            $table->column('name');
            $table->column('symbol');
            $table->column('Created', 'created_at');
        });
    }

public function table ( Metric $ metric ) { return $ this -> table -> of ( 'metrics' , function ( TableGrid $ table ) use ( $ metric ) { $ table -> with ( $ metric ) -> paginate ( $ this -> perPage ) ; $ table -> column ( 'name' ) ; $ table -> column ( 'symbol' ) ; $ table -> column ( 'Created' , 'created_at' ) ; } ) ; }

Returns a new table of all metrics.

@param Metric $metric

@return \Orchestra\Contracts\Html\Builder


public function tableHistory($for, MorphMany $revisions)
    {
        return $this->table->of("$for.revisions", function (TableGrid $table) use ($revisions) {
            $table->with($revisions)->paginate($this->perPage);

            $table->pageName = 'history';

            $table->column('user_responsible', function (Column $column) {
                $column->value = function (Revision $revision) {
                    $user = $revision->getUserResponsible();

                    if ($user instanceof User) {
                        return $user->getRecipientName();
                    }

                    return HTML::create('em', 'None');
                };
            });

            $table->column('changed', function (Column $column) {
                $column->value = function (Revision $revision) {
                    return $revision->getColumnName();
                };
            });

            $table->column('from', function (Column $column) {
                $column->value = function (Revision $revision) {
                    $old = $revision->getOldValue();

                    if (is_null($old)) {
                        return HTML::create('em', 'None');
                    }

                    return $old;
                };
            });

            $table->column('to', function (Column $column) {
                $column->value = function (Revision $revision) {
                    $new = $revision->getNewValue();

                    if (is_null($new)) {
                        return HTML::create('em', 'None');
                    }

                    return $new;
                };
            });

            $table->column('On', 'created_at');
        });
    }

public function tableHistory ( $ for , MorphMany $ revisions ) { return $ this -> table -> of ( "$for.revisions" , function ( TableGrid $ table ) use ( $ revisions ) { $ table -> with ( $ revisions ) -> paginate ( $ this -> perPage ) ; $ table -> pageName = 'history' ; $ table -> column ( 'user_responsible' , function ( Column $ column ) { $ column -> value = function ( Revision $ revision ) { $ user = $ revision -> getUserResponsible ( ) ; if ( $ user instanceof User ) { return $ user -> getRecipientName ( ) ; } return HTML :: create ( 'em' , 'None' ) ; } ; } ) ; $ table -> column ( 'changed' , function ( Column $ column ) { $ column -> value = function ( Revision $ revision ) { return $ revision -> getColumnName ( ) ; } ; } ) ; $ table -> column ( 'from' , function ( Column $ column ) { $ column -> value = function ( Revision $ revision ) { $ old = $ revision -> getOldValue ( ) ; if ( is_null ( $ old ) ) { return HTML :: create ( 'em' , 'None' ) ; } return $ old ; } ; } ) ; $ table -> column ( 'to' , function ( Column $ column ) { $ column -> value = function ( Revision $ revision ) { $ new = $ revision -> getNewValue ( ) ; if ( is_null ( $ new ) ) { return HTML :: create ( 'em' , 'None' ) ; } return $ new ; } ; } ) ; $ table -> column ( 'On' , 'created_at' ) ; } ) ; }

Returns a new table of all revisions.

@param string    $for
@param MorphMany $revisions

@return \Orchestra\Contracts\Html\Builder


public function store(ImageRequest $request, $id)
    {
        $asset = $this->asset->find($id);

        $attachments = $this->image->upload($request, $asset, $asset->images());

        if ($attachments) {
            $message = 'Successfully uploaded files.';

            return redirect()->route('maintenance.assets.images.index', [$asset->id])->withSuccess($message);
        } else {
            $message = 'There was an issue uploading the files you selected. Please try again.';

            return redirect()->route('maintenance.assets.images.create', [$id])->withErrors($message);
        }
    }

Uploads images and attaches them to the specified asset.

@param ImageRequest $request
@param int|string   $id

@return \Illuminate\Http\RedirectResponse

Uploads images and attaches them to the specified asset .


public function show($id, $imageId)
    {
        $asset = $this->asset->find($id);

        $image = $asset->images()->find($imageId);

        if ($image) {
            return view('assets.images.show', compact('asset', 'image'));
        }

        abort(404);
    }

public function show ( $ id , $ imageId ) { $ asset = $ this -> asset -> find ( $ id ) ; $ image = $ asset -> images ( ) -> find ( $ imageId ) ; if ( $ image ) { return view ( 'assets.images.show' , compact ( 'asset' , 'image' ) ) ; } abort ( 404 ) ; }

Displays the asset image.

@param int|string $id
@param int|string $imageId

@return \Illuminate\View\View


public function update(AttachmentUpdateRequest $request, $id, $imageId)
    {
        $asset = $this->asset->find($id);

        $image = $this->image->update($request, $asset->images(), $imageId);

        if ($image) {
            $message = 'Successfully updated image.';

            return redirect()->route('maintenance.assets.images.show', [$asset->id, $image->id])->withSuccess($message);
        } else {
            $message = 'There was an issue updating this image. Please try again.';

            return redirect()->route('maintenance.assets.images.show', [$id, $imageId])->withErrors($message);
        }
    }

Updates the specified asset image upload.

@param AttachmentUpdateRequest $request
@param int|string              $id
@param int|string              $imageId

@return \Illuminate\Http\RedirectResponse

Updates the specified asset image upload .


public function index()
    {
        $metrics = $this->presenter->table($this->metric);

        $navbar = $this->presenter->navbar();

        return view('metrics.index', compact('metrics', 'navbar'));
    }

public function index ( ) { $ metrics = $ this -> presenter -> table ( $ this -> metric ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'metrics.index' , compact ( 'metrics' , 'navbar' ) ) ; }

Displays all metrics.

@return \Illuminate\View\View


public function store(MetricRequest $request)
    {
        $metric = $this->metric->newInstance();

        return $this->dispatch(new Store($request, $metric));
    }

public function store ( MetricRequest $ request ) { $ metric = $ this -> metric -> newInstance ( ) ; return $ this -> dispatch ( new Store ( $ request , $ metric ) ) ; }

Creates a new metric.

@param MetricRequest $request

@return mixed


public function edit($id)
    {
        $metric = $this->metric->findOrFail($id);

        $form = $this->presenter->form($metric);

        return view('metrics.edit', compact('form'));
    }

public function edit ( $ id ) { $ metric = $ this -> metric -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ metric ) ; return view ( 'metrics.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified metric.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified metric .


public function index()
    {
        $navbar = $this->presenter->navbar();

        $assets = $this->presenter->table($this->asset);

        return view('assets.index', compact('assets', 'navbar'));
    }

public function index ( ) { $ navbar = $ this -> presenter -> navbar ( ) ; $ assets = $ this -> presenter -> table ( $ this -> asset ) ; return view ( 'assets.index' , compact ( 'assets' , 'navbar' ) ) ; }

Displays all assets.

@return \Illuminate\View\View


public function store(AssetRequest $request)
    {
        $asset = $this->asset->newInstance();

        $asset->user_id = $this->guard->id();
        $asset->tag = $request->input('tag');
        $asset->category_id = $request->input('category');
        $asset->location_id = $request->input('location');
        $asset->name = $request->input('name');
        $asset->condition = $request->input('condition');
        $asset->vendor = $request->input('vendor');
        $asset->make = $request->input('make');
        $asset->model = $request->input('model');
        $asset->size = $request->input('size');
        $asset->weight = $request->input('weight');
        $asset->serial = $request->input('serial');
        $asset->acquired_at = $request->formatDateWithTime($request->input('acquired_at'));
        $asset->end_of_life = $request->formatDateWithTime($request->input('end_of_life'));

        return $asset->save();
    }

public function store ( AssetRequest $ request ) { $ asset = $ this -> asset -> newInstance ( ) ; $ asset -> user_id = $ this -> guard -> id ( ) ; $ asset -> tag = $ request -> input ( 'tag' ) ; $ asset -> category_id = $ request -> input ( 'category' ) ; $ asset -> location_id = $ request -> input ( 'location' ) ; $ asset -> name = $ request -> input ( 'name' ) ; $ asset -> condition = $ request -> input ( 'condition' ) ; $ asset -> vendor = $ request -> input ( 'vendor' ) ; $ asset -> make = $ request -> input ( 'make' ) ; $ asset -> model = $ request -> input ( 'model' ) ; $ asset -> size = $ request -> input ( 'size' ) ; $ asset -> weight = $ request -> input ( 'weight' ) ; $ asset -> serial = $ request -> input ( 'serial' ) ; $ asset -> acquired_at = $ request -> formatDateWithTime ( $ request -> input ( 'acquired_at' ) ) ; $ asset -> end_of_life = $ request -> formatDateWithTime ( $ request -> input ( 'end_of_life' ) ) ; return $ asset -> save ( ) ; }

Creates a new asset.

@param AssetRequest $request

@return bool


public function edit($id)
    {
        $asset = $this->asset->findOrFail($id);

        $form = $this->presenter->form($asset);

        return view('assets.edit', compact('form'));
    }

public function edit ( $ id ) { $ asset = $ this -> asset -> findOrFail ( $ id ) ; $ form = $ this -> presenter -> form ( $ asset ) ; return view ( 'assets.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified asset.

@param int|string $id

@return \Illuminate\View\View

Displays the form for editing the specified asset .


public function update(AssetRequest $request, $id)
    {
        $asset = $this->asset->findOrFail($id);

        $asset->tag = $request->input('tag');
        $asset->category_id = $request->input('category');
        $asset->location_id = $request->input('location');
        $asset->name = $request->input('name');
        $asset->condition = $request->input('condition');
        $asset->vendor = $request->input('vendor');
        $asset->make = $request->input('make');
        $asset->model = $request->input('model');
        $asset->size = $request->input('size');
        $asset->weight = $request->input('weight');
        $asset->serial = $request->input('serial');
        $asset->acquired_at = $request->formatDateWithTime($request->input('acquired_at'));
        $asset->end_of_life = $request->formatDateWithTime($request->input('end_of_life'));

        return $asset->save();
    }

public function update ( AssetRequest $ request , $ id ) { $ asset = $ this -> asset -> findOrFail ( $ id ) ; $ asset -> tag = $ request -> input ( 'tag' ) ; $ asset -> category_id = $ request -> input ( 'category' ) ; $ asset -> location_id = $ request -> input ( 'location' ) ; $ asset -> name = $ request -> input ( 'name' ) ; $ asset -> condition = $ request -> input ( 'condition' ) ; $ asset -> vendor = $ request -> input ( 'vendor' ) ; $ asset -> make = $ request -> input ( 'make' ) ; $ asset -> model = $ request -> input ( 'model' ) ; $ asset -> size = $ request -> input ( 'size' ) ; $ asset -> weight = $ request -> input ( 'weight' ) ; $ asset -> serial = $ request -> input ( 'serial' ) ; $ asset -> acquired_at = $ request -> formatDateWithTime ( $ request -> input ( 'acquired_at' ) ) ; $ asset -> end_of_life = $ request -> formatDateWithTime ( $ request -> input ( 'end_of_life' ) ) ; return $ asset -> save ( ) ; }

Updates the specified asset.

@param AssetRequest $request
@param int|string   $id

@return bool


public function scopeId($query, $id = null)
    {
        if (!is_null($id)) {
            $query->where('id', $id);
        }

        return $query;
    }

public function scopeId ( $ query , $ id = null ) { if ( ! is_null ( $ id ) ) { $ query -> where ( 'id' , $ id ) ; } return $ query ; }

Allows all tables extending from the base model to be scoped by ID.

@param object      $query
@param int /string $id

@return object

Allows all tables extending from the base model to be scoped by ID .


public function response()
    {
        if ($this->isAjax()) {
            if ($this->errors) {
                return $this->responseJson([
                    'errors' => $this->errors,
                ]);
            } else {
                return $this->responseJson([
                    'message'     => $this->message,
                    'messageType' => $this->messageType,
                    'redirect'    => $this->redirect,
                ]);
            }
        } else {
            if ($this->errors) {
                return redirect($this->redirect)
                    ->withInput()
                    ->withErrors($this->errors);
            } else {
                return redirect($this->redirect)
                    ->withInput()
                    ->with('message', $this->message)
                    ->with('messageType', $this->messageType);
            }
        }
    }

public function response ( ) { if ( $ this -> isAjax ( ) ) { if ( $ this -> errors ) { return $ this -> responseJson ( [ 'errors' => $ this -> errors , ] ) ; } else { return $ this -> responseJson ( [ 'message' => $ this -> message , 'messageType' => $ this -> messageType , 'redirect' => $ this -> redirect , ] ) ; } } else { if ( $ this -> errors ) { return redirect ( $ this -> redirect ) -> withInput ( ) -> withErrors ( $ this -> errors ) ; } else { return redirect ( $ this -> redirect ) -> withInput ( ) -> with ( 'message' , $ this -> message ) -> with ( 'messageType' , $ this -> messageType ) ; } } }

Returns the proper response to user. If the request was made from ajax, then an json response is sent.
If a request is a typical request without ajax, a user is sent a redirect with session flash messages.

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Returns the proper response to user . If the request was made from ajax then an json response is sent . If a request is a typical request without ajax a user is sent a redirect with session flash messages .


protected function input($name, $clean = false)
    {
        if ($this->inputHas($name)) {
            if ($clean) {
                return $this->clean(Input::get($name));
            } else {
                return Input::get($name);
            }
        }

        return;
    }

protected function input ( $ name , $ clean = false ) { if ( $ this -> inputHas ( $ name ) ) { if ( $ clean ) { return $ this -> clean ( Input :: get ( $ name ) ) ; } else { return Input :: get ( $ name ) ; } } return ; }

Returns input from the client. If clean is set to true, the input will be
ran through the purifier before it is returned.

@param string $name
@param bool   $clean

@return mixed

Returns input from the client . If clean is set to true the input will be ran through the purifier before it is returned .


public static function getSelectHierarchy($belongsTo = null)
    {
        $query = static::roots();

        if (!is_null($belongsTo)) {
            $query->where('belongs_to', $belongsTo);
        }

        $roots = $query->with('children')->get();

        $options = [0 => 'None'];

        foreach ($roots as $root) {
            $options = $options + static::getRenderedNode($root);
        }

        return $options;
    }

public static function getSelectHierarchy ( $ belongsTo = null ) { $ query = static :: roots ( ) ; if ( ! is_null ( $ belongsTo ) ) { $ query -> where ( 'belongs_to' , $ belongsTo ) ; } $ roots = $ query -> with ( 'children' ) -> get ( ) ; $ options = [ 0 => 'None' ] ; foreach ( $ roots as $ root ) { $ options = $ options + static :: getRenderedNode ( $ root ) ; } return $ options ; }

Returns the complete nested set table in a nested list.

@param string $belongsTo

@return array

Returns the complete nested set table in a nested list .


public static function getRenderedNode(Node $node)
    {
        $options = [];

        if ($node->isRoot()) {
            $name = $node->name;
        } else {
            $depth = str_repeat('--', $node->depth);

            $name = sprintf('%s %s', $depth, $node->name);
        }

        $options[$node->id] = $name;

        if ($node->children()->count() > 0) {
            foreach ($node->children as $child) {
                $options = $options + static::getRenderedNode($child);
            }
        }

        return $options;
    }

public
static
function
getRenderedNode
(
Node
$
node
)
{
$
options
=
[
]
;
if
(
$
node
->
isRoot
(
)
)
{
$
name
=
$
node
->
name
;
}
else
{
$
depth
=
str_repeat
(
'--'
,
$
node
->
depth
)
;
$
name
=
sprintf
(
'%s %s'
,
$
depth
,
$
node
->
name
)
;
}
$
options
[
$
node
->
id
]
=
$
name
;
if
(
$
node
->
children
(
)
->
count
(
)
>
0
)
{
foreach
(
$
node
->
children
as
$
child
)
{
$
options
=
$
options
+
static
::
getRenderedNode
(
$
child
)
;
}
}
return
$
options
;
}

Renders the specified category and it's children in single dimension array.

@param Node $node

@return array

Renders the specified category and it s children in single dimension array .


public function boot(Factory $view)
    {
        foreach ($this->composers as $callback => $views) {
            $view->composer($views, $callback);
        }
    }

public function boot ( Factory $ view ) { foreach ( $ this -> composers as $ callback => $ views ) { $ view -> composer ( $ views , $ callback ) ; } }

Registers view composers during boot.

@param Factory $view


public function handle(Filesystem $filesystem)
    {
        try {
            if ($filesystem->delete($this->attachment->getStorageFilePath())) {
                return $this->attachment->delete();
            }
        } catch (FileNotFoundException $e) {
            //
        }

        return false;
    }

public function handle ( Filesystem $ filesystem ) { try { if ( $ filesystem -> delete ( $ this -> attachment -> getStorageFilePath ( ) ) ) { return $ this -> attachment -> delete ( ) ; } } catch ( FileNotFoundException $ e ) { // } return false ; }

Deletes the current attachment as well as the file.

@param Filesystem $filesystem

@throws \Exception

@return bool

Deletes the current attachment as well as the file .


public function index($itemId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $navbar = $this->presenter->navbar($item);

        $stocks = $this->presenter->table($item);

        return view('inventory.stocks.index', compact('stocks', 'navbar'));
    }

public function index ( $ itemId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ navbar = $ this -> presenter -> navbar ( $ item ) ; $ stocks = $ this -> presenter -> table ( $ item ) ; return view ( 'inventory.stocks.index' , compact ( 'stocks' , 'navbar' ) ) ; }

Displays all stocks for the specified inventory item.

@param int|string $itemId

@return \Illuminate\View\View

Displays all stocks for the specified inventory item .


public function create($itemId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $form = $this->presenter->form($item, $item->stocks()->getRelated());

        return view('inventory.stocks.create', compact('form'));
    }

public function create ( $ itemId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ form = $ this -> presenter -> form ( $ item , $ item -> stocks ( ) -> getRelated ( ) ) ; return view ( 'inventory.stocks.create' , compact ( 'form' ) ) ; }

Displays the from for creating a stock for.

@param int|string $itemId

@return \Illuminate\View\View

Displays the from for creating a stock for .


public function store(InventoryStockRequest $request, $itemId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->getRelated();

        return $this->dispatch(new Store($request, $item, $stock));
    }

public function store ( InventoryStockRequest $ request , $ itemId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> getRelated ( ) ; return $ this -> dispatch ( new Store ( $ request , $ item , $ stock ) ) ; }

Creates a new stock on the specified item.

@param InventoryStockRequest $request
@param int|string            $itemId

@return bool

Creates a new stock on the specified item .


public function show($itemId, $stockId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        $movements = $this->presenter->tableMovements($item, $stock);

        return view('inventory.stocks.show', compact('item', 'stock', 'movements'));
    }

public function show ( $ itemId , $ stockId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; $ movements = $ this -> presenter -> tableMovements ( $ item , $ stock ) ; return view ( 'inventory.stocks.show' , compact ( 'item' , 'stock' , 'movements' ) ) ; }

Displays the specified items stock.

@param int|string $itemId
@param int|string $stockId

@return \Illuminate\View\View


public function edit($itemId, $stockId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        $form = $this->presenter->form($item, $stock);

        return view('inventory.stocks.edit', compact('form'));
    }

public function edit ( $ itemId , $ stockId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; $ form = $ this -> presenter -> form ( $ item , $ stock ) ; return view ( 'inventory.stocks.edit' , compact ( 'form' ) ) ; }

Displays the form for editing the specified items stock.

@param int|string $itemId
@param int|string $stockId

@return \Illuminate\View\View

Displays the form for editing the specified items stock .


public function update(InventoryStockRequest $request, $itemId, $stockId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        return $this->dispatch(new Update($request, $item, $stock));
    }

public function update ( InventoryStockRequest $ request , $ itemId , $ stockId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; return $ this -> dispatch ( new Update ( $ request , $ item , $ stock ) ) ; }

Updates the specified inventory stock.

@param InventoryStockRequest $request
@param int|string            $itemId
@param int|string            $stockId

@return bool


public function destroy($itemId, $stockId)
    {
        $item = $this->inventory->findOrFail($itemId);

        $stock = $item->stocks()->findOrFail($stockId);

        return $stock->delete();
    }

public function destroy ( $ itemId , $ stockId ) { $ item = $ this -> inventory -> findOrFail ( $ itemId ) ; $ stock = $ item -> stocks ( ) -> findOrFail ( $ stockId ) ; return $ stock -> delete ( ) ; }

Deletes the specified inventory stock.

@param int|string $itemId
@param int|string $stockId

@return bool


public function index($id)
    {
        $asset = $this->asset->model()->findOrFail($id);

        return view('assets.meters.index', compact('asset'));
    }

public function index ( $ id ) { $ asset = $ this -> asset -> model ( ) -> findOrFail ( $ id ) ; return view ( 'assets.meters.index' , compact ( 'asset' ) ) ; }

Displays all meters for the specified asset.

@param int|string $id

@return \Illuminate\View\View

Displays all meters for the specified asset .


public function create($id)
    {
        $asset = $this->asset->model()->findOrFail($id);

        return view('assets.meters.create', compact('asset'));
    }

public function create ( $ id ) { $ asset = $ this -> asset -> model ( ) -> findOrFail ( $ id ) ; return view ( 'assets.meters.create' , compact ( 'asset' ) ) ; }

Displays the form for creating a new meter for the specified asset.

@param int|string $id

@return \Illuminate\View\View

Displays the form for creating a new meter for the specified asset .


public function store(MeterRequest $request, $id)
    {
        $meter = $this->meter->create($request, $id);

        if ($meter) {
            $message = 'Successfully created meter.';

            return redirect()->route('maintenance.assets.meters.index', [$id])->withSuccess($message);
        } else {
            $message = 'There was an issue creating a meter. Please try again.';

            return redirect()->route('maintenance.assets.meters.create', [$id])->withErrors($message);
        }
    }

Creates a new meter for the specified asset.

@param MeterRequest $request
@param int|string   $id

@return \Illuminate\Http\RedirectResponse

Creates a new meter for the specified asset .


public function show($id, $meterId)
    {
        $asset = $this->asset->model()->findOrFail($id);

        $meter = $asset->meters()->findOrFail($meterId);

        return view('assets.meters.show', compact('asset', 'meter'));
    }

public function show ( $ id , $ meterId ) { $ asset = $ this -> asset -> model ( ) -> findOrFail ( $ id ) ; $ meter = $ asset -> meters ( ) -> findOrFail ( $ meterId ) ; return view ( 'assets.meters.show' , compact ( 'asset' , 'meter' ) ) ; }

Displays the specified meter for the specified asset.

@param int|string $id
@param int|string $meterId

@return \Illuminate\View\View

Displays the specified meter for the specified asset .


public function edit($id, $meterId)
    {
        $asset = $this->asset->model()->findOrFail($id);

        $meter = $asset->meters()->findOrFail($meterId);

        $lastReading = $meter->getLastReading();

        return view('assets.meters.edit', compact('asset', 'meter', 'lastReading'));
    }

public function edit ( $ id , $ meterId ) { $ asset = $ this -> asset -> model ( ) -> findOrFail ( $ id ) ; $ meter = $ asset -> meters ( ) -> findOrFail ( $ meterId ) ; $ lastReading = $ meter -> getLastReading ( ) ; return view ( 'assets.meters.edit' , compact ( 'asset' , 'meter' , 'lastReading' ) ) ; }

Displays the form for editing the
specified meter for the specified asset.

@param int|string $id
@param int|string $meterId

@return \Illuminate\View\View

Displays the form for editing the specified meter for the specified asset .


public function update(MeterRequest $request, $id, $meterId)
    {
        $meter = $this->meter->update($request, $id, $meterId);

        if ($meter) {
            $message = 'Successfully updated meter.';

            return redirect()->route('maintenance.assets.meters.show', [$id, $meter->id])->withSuccess($message);
        } else {
            $message = 'There was an issue updating this meter. Please try again.';

            return redirect()->route('maintenance.assets.meters.edit', [$id, $meterId])->withErrors($message);
        }
    }

Updates the specified meter attached to the specified asset.

@param MeterRequest $request
@param int|string   $id
@param int|string   $meterId

@return \Illuminate\Http\RedirectResponse

Updates the specified meter attached to the specified asset .


public function destroy($id, $meterId)
    {
        $asset = $this->asset->model()->findOrFail($id);

        $meter = $asset->meters()->findOrFail($meterId);

        if ($meter->delete()) {
            $message = 'Successfully deleted meter.';

            return redirect()->route('maintenance.assets.meters.index', [$id])->withSuccess($message);
        } else {
            $message = 'There was an issue deleting this meter. Please try again.';

            return redirect()->route('maintenance.assets.meters.show', [$id, $meterId])->withErrors($message);
        }
    }

Deletes the specified meter for the specified asset.

@param int|string $id
@param int|string $meterId

@return \Illuminate\Http\RedirectResponse

Deletes the specified meter for the specified asset .


public function store($workOrderId)
    {
        if ($this->workOrderNotificationValidator->passes()) {
            $workOrder = $this->workOrder->find($workOrderId);

            $data = $this->inputAll();
            $data['work_order_id'] = $workOrder->id;

            $this->workOrderNotification->setInput($data)->create();

            $this->message = 'Successfully updated notifications';
            $this->messageType = 'success';
            $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
        } else {
            $this->errors = $this->workOrderNotificationValidator->getErrors();
            $this->redirect = route('maintenance.work-orders.show', [$workOrderId]);
        }

        return $this->response();
    }

public
function
store
(
$
workOrderId
)
{
if
(
$
this
->
workOrderNotificationValidator
->
passes
(
)
)
{
$
workOrder
=
$
this
->
workOrder
->
find
(
$
workOrderId
)
;
$
data
=
$
this
->
inputAll
(
)
;
$
data
[
'work_order_id'
]
=
$
workOrder
->
id
;
$
this
->
workOrderNotification
->
setInput
(
$
data
)
->
create
(
)
;
$
this
->
message
=
'Successfully updated notifications'
;
$
this
->
messageType
=
'success'
;
$
this
->
redirect
=
route
(
'maintenance.work-orders.show'
,
[
$
workOrder
->
id
]
)
;
}
else
{
$
this
->
errors
=
$
this
->
workOrderNotificationValidator
->
getErrors
(
)
;
$
this
->
redirect
=
route
(
'maintenance.work-orders.show'
,
[
$
workOrderId
]
)
;
}
return
$
this
->
response
(
)
;
}

Creates a new notification for the specified work order.

@param string|int $workOrderId

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Creates a new notification for the specified work order .


public function update($workOrderId, $notificationId)
    {
        if ($this->workOrderNotificationValidator->passes()) {
            $workOrder = $this->workOrder->find($workOrderId);

            $notifications = $this->workOrderNotification->find($notificationId);

            $data = $this->inputAll();
            $data['work_order_id'] = $workOrder->id;

            $this->workOrderNotification->setInput($data)->update($notifications->id);

            $this->message = 'Successfully updated notifications';
            $this->messageType = 'success';
            $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
        } else {
            $this->errors = $this->workOrderNotificationValidator->getErrors();
            $this->redirect = route('maintenance.work-orders.show', [$workOrderId]);
        }

        return $this->response();
    }

public
function
update
(
$
workOrderId
,
$
notificationId
)
{
if
(
$
this
->
workOrderNotificationValidator
->
passes
(
)
)
{
$
workOrder
=
$
this
->
workOrder
->
find
(
$
workOrderId
)
;
$
notifications
=
$
this
->
workOrderNotification
->
find
(
$
notificationId
)
;
$
data
=
$
this
->
inputAll
(
)
;
$
data
[
'work_order_id'
]
=
$
workOrder
->
id
;
$
this
->
workOrderNotification
->
setInput
(
$
data
)
->
update
(
$
notifications
->
id
)
;
$
this
->
message
=
'Successfully updated notifications'
;
$
this
->
messageType
=
'success'
;
$
this
->
redirect
=
route
(
'maintenance.work-orders.show'
,
[
$
workOrder
->
id
]
)
;
}
else
{
$
this
->
errors
=
$
this
->
workOrderNotificationValidator
->
getErrors
(
)
;
$
this
->
redirect
=
route
(
'maintenance.work-orders.show'
,
[
$
workOrderId
]
)
;
}
return
$
this
->
response
(
)
;
}

Updates the specified notification for the specified work order.

@param string|int $workOrderId
@param string|int $notificationId

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse

Updates the specified notification for the specified work order .


public function startedAtFormatted()
    {
        if ($this->entity->started_at) {
            $date = new \DateTime();

            $date->setTimestamp(strtotime($this->entity->started_at));

            return $date->format('M dS Y - h:ia');
        }

        return;
    }

public
function
startedAtFormatted
(
)
{
if
(
$
this
->
entity
->
started_at
)
{
$
date
=
new
\
DateTime
(
)
;
$
date
->
setTimestamp
(
strtotime
(
$
this
->
entity
->
started_at
)
)
;
return
$
date
->
format
(
'M dS Y - h:ia'
)
;
}
return
;
}

The work order started at formatted string.

@return null|string

The work order started at formatted string .


public function completedAtFormatted()
    {
        if ($this->entity->completed_at) {
            $date = new \DateTime();

            $date->setTimestamp(strtotime($this->entity->completed_at));

            return $date->format('M dS Y - h:ia');
        }

        return;
    }

public
function
completedAtFormatted
(
)
{
if
(
$
this
->
entity
->
completed_at
)
{
$
date
=
new
\
DateTime
(
)
;
$
date
->
setTimestamp
(
strtotime
(
$
this
->
entity
->
completed_at
)
)
;
return
$
date
->
format
(
'M dS Y - h:ia'
)
;
}
return
;
}

The work order completed at formatted string.

@return null|string

The work order completed at formatted string .


public function index()
    {
        $workOrders = $this->presenter->tableAssigned($this->workOrder);

        $navbar = $this->presenter->navbar();

        return view('work-orders.assigned.index', compact('workOrders', 'navbar'));
    }

public function index ( ) { $ workOrders = $ this -> presenter -> tableAssigned ( $ this -> workOrder ) ; $ navbar = $ this -> presenter -> navbar ( ) ; return view ( 'work-orders.assigned.index' , compact ( 'workOrders' , 'navbar' ) ) ; }

Displays the current users assigned work orders.

@return \Illuminate\View\View

Displays the current users assigned work orders .


public function form(WorkOrder $workOrder, Comment $comment)
    {
        return $this->form->of('work-orders.comments', function (FormGrid $form) use ($workOrder, $comment) {
            if ($comment->exists) {
                $method = 'PATCH';
                $url = route('work-orders.comments.update', [$workOrder->getKey(), $comment->getKey()]);

                $form->submit = 'Save';
            } else {
                $method = 'POST';
                $url = route('work-orders.comments.store', [$workOrder->getKey()]);

                $form->submit = 'Create';
            }

            $form->attributes(compact('method', 'url'));

            $form->with($comment);

            $form->fieldset(function (Fieldset $fieldset) {

                $fieldset->control('input:text', 'content');

            });
        });
    }

public function form ( WorkOrder $ workOrder , Comment $ comment ) { return $ this -> form -> of ( 'work-orders.comments' , function ( FormGrid $ form ) use ( $ workOrder , $ comment ) { if ( $ comment -> exists ) { $ method = 'PATCH' ; $ url = route ( 'work-orders.comments.update' , [ $ workOrder -> getKey ( ) , $ comment -> getKey ( ) ] ) ; $ form -> submit = 'Save' ; } else { $ method = 'POST' ; $ url = route ( 'work-orders.comments.store' , [ $ workOrder -> getKey ( ) ] ) ; $ form -> submit = 'Create' ; } $ form -> attributes ( compact ( 'method' , 'url' ) ) ; $ form -> with ( $ comment ) ; $ form -> fieldset ( function ( Fieldset $ fieldset ) { $ fieldset -> control ( 'input:text' , 'content' ) ; } ) ; } ) ; }

Returns a new form for the specified comment.

@param WorkOrder $workOrder
@param Comment   $comment

@return \Orchestra\Contracts\Html\Builder

Returns a new form for the specified comment .


public function getHours()
    {
        if (array_key_exists('out', $this->attributes)) {
            if ($this->attributes['out']) {
                $hours = abs(round((strtotime($this->attributes['in']) - strtotime($this->attributes['out'])) / 3600, 2));

                return $hours;
            }
        }

        return;
    }

public function getHours ( ) { if ( array_key_exists ( 'out' , $ this -> attributes ) ) { if ( $ this -> attributes [ 'out' ] ) { $ hours = abs ( round ( ( strtotime ( $ this -> attributes [ 'in' ] ) - strtotime ( $ this -> attributes [ 'out' ] ) ) / 3600 , 2 ) ) ; return $ hours ; } } return ; }

Returns the number of hours a session lasted with decimals.

@return null|int

Returns the number of hours a session lasted with decimals .


public function startDateFormatted(Event $apiObject)
    {
        $start = new \DateTime();

        $start->setTimestamp(strtotime($apiObject->start));

        return $start->format('m/d/Y');
    }

public function startDateFormatted ( Event $ apiObject ) { $ start = new \ DateTime ( ) ; $ start -> setTimestamp ( strtotime ( $ apiObject -> start ) ) ; return $ start -> format ( 'm/d/Y' ) ; }

Presents the correct start date formatted for editing.

@param Event $apiObject

@return string

Presents the correct start date formatted for editing .


public function endDateFormatted(Event $apiObject)
    {
        $end = new \DateTime();

        $end->setTimestamp(strtotime($apiObject->start));

        return $end->format('m/d/Y');
    }

public function endDateFormatted ( Event $ apiObject ) { $ end = new \ DateTime ( ) ; $ end -> setTimestamp ( strtotime ( $ apiObject -> start ) ) ; return $ end -> format ( 'm/d/Y' ) ; }

Presents the correct end date formatted for editing.

@param Event $apiObject

@return string

Presents the correct end date formatted for editing .


public function endTimeFormatted(Event $apiObject)
    {
        if (!$apiObject->all_day) {
            $end = new \DateTime();

            $end->setTimestamp(strtotime($apiObject->start));

            return $end->format('h:i A');
        }

        return;
    }

public
function
endTimeFormatted
(
Event
$
apiObject
)
{
if
(
!
$
apiObject
->
all_day
)
{
$
end
=
new
\
DateTime
(
)
;
$
end
->
setTimestamp
(
strtotime
(
$
apiObject
->
start
)
)
;
return
$
end
->
format
(
'h:i A'
)
;
}
return
;
}

Presents the correct end time formatted for editing.

@param Event $apiObject

@return string|null

Presents the correct end time formatted for editing .


public function recurFrequencyFormatted(Event $apiObject)
    {
        if ($this->recurFrequency($apiObject)) {
            return ucfirst(strtolower($this->recurFrequency($apiObject)));
        }

        return 'None';
    }

public function recurFrequencyFormatted ( Event $ apiObject ) { if ( $ this -> recurFrequency ( $ apiObject ) ) { return ucfirst ( strtolower ( $ this -> recurFrequency ( $ apiObject ) ) ) ; } return 'None' ; }

Presents the API events recurrence frequency in a nicer format.

@param Event $apiObject

@return string

Presents the API events recurrence frequency in a nicer format .


public function recurFrequency(Event $apiObject)
    {
        if ($apiObject->rruleArray && array_key_exists('FREQ', $apiObject->rruleArray)) {
            $freq = $apiObject->rruleArray['FREQ'];

            return $freq;
        }

        return;
    }

public function recurFrequency ( Event $ apiObject ) { if ( $ apiObject -> rruleArray && array_key_exists ( 'FREQ' , $ apiObject -> rruleArray ) ) { $ freq = $ apiObject -> rruleArray [ 'FREQ' ] ; return $ freq ; } return ; }

Returns the API events actual recurrence frequency array.

@param Event $apiObject

@return array|null

Returns the API events actual recurrence frequency array .


public function recurDays(Event $apiObject)
    {
        if ($apiObject->rruleArray && array_key_exists('BYDAY', $apiObject->rruleArray)) {
            $freq = $apiObject->rruleArray['BYDAY'];

            return $freq;
        }

        return;
    }

public function recurDays ( Event $ apiObject ) { if ( $ apiObject -> rruleArray && array_key_exists ( 'BYDAY' , $ apiObject -> rruleArray ) ) { $ freq = $ apiObject -> rruleArray [ 'BYDAY' ] ; return $ freq ; } return ; }

Returns the API events actual recurring days array.

@return array|null

Returns the API events actual recurring days array .


public function tags()
    {
        /*
         * Make sure we pass in the parent event if this event is a recurrence
         * so we can use it's tags
         */
        if ($this->entity->parentEvent) {
            $event = $this->entity->parentEvent;
        } else {
            $event = $this->entity;
        }

        return view('viewers.event.tags', [
            'event' => $event,
        ]);
    }

Returns the events tags view.

@return \Illuminate\View\View


public function store(InventoryStockRequest $request, $itemId)
    {
        if ($this->processor->store($request, $itemId)) {
            flash()->success('Success!', 'Successfully created stock.');

            return redirect()->route('maintenance.inventory.stocks.index', [$itemId]);
        } else {
            flash()->error('Error!', 'There was an issue creating an inventory stock. Please try again.');

            return redirect()->route('maintenance.inventory.stocks.create', [$itemId]);
        }
    }

Create a new stock entry for the specified inventory item.

@param InventoryStockRequest $request
@param int|string            $itemId

@return \Illuminate\Http\RedirectResponse

Create a new stock entry for the specified inventory item .


public function update(InventoryStockRequest $request, $itemId, $stockId)
    {
        if ($this->processor->update($request, $itemId, $stockId)) {
            flash()->success('Success!', 'Successfully updated stock.');

            return redirect()->route('maintenance.inventory.stocks.show', [$itemId, $stockId]);
        } else {
            flash()->error('Error!', 'There was an issue updating this stock. Please try again.');

            return redirect()->route('maintenance.inventory.stocks.update', [$itemId, $stockId]);
        }
    }

Updates the specified stock for the specified inventory.

@param InventoryStockRequest $request
@param int|string            $itemId
@param int|string            $stockId

@return \Illuminate\Http\RedirectResponse

Updates the specified stock for the specified inventory .


public function destroy($itemId, $stockId)
    {
        if ($this->processor->destroy($itemId, $stockId)) {
            flash()->success('Success!', 'Successfully deleted stock.');

            return redirect()->route('maintenance.inventory.stocks.index', [$itemId]);
        } else {
            flash()->error('Error!', 'There was an issue deleting this stock. Please try again.');

            return redirect()->route('maintenance.inventory.stocks.show', [$itemId, $stockId]);
        }
    }

Removes the specified stock from the specified inventory.

@param int|string $itemId
@param int|string $stockId

@return \Illuminate\Http\RedirectResponse

Removes the specified stock from the specified inventory .


public function table(WorkOrder $workOrder)
    {
        $attachments = $workOrder->attachments();

        return $this->table->of('work-orders.attachments', function (TableGrid $table) use ($workOrder, $attachments) {
            $table->with($attachments)->paginate($this->perPage);

            $table->column('type', function (Column $column) {
                $column->value = function (Attachment $attachment) {
                    return $attachment->icon;
                };
            });

            $table->column('name', function (Column $column) use ($workOrder) {
                $column->value = function (Attachment $attachment) use ($workOrder) {
                    $route = 'maintenance.work-orders.attachments.show';

                    $params = [$workOrder->getKey(), $attachment->getKey()];

                    return link_to_route($route, $attachment->name, $params);
                };
            });

            $table->column('uploaded_by', function (Column $column) {
               $column->value = function (Attachment $attachment) {
                    if ($attachment->user instanceof User) {
                        return $attachment->user->getRecipientName();
                    }
               };
            });

            $table->column('Uploaded On', 'created_at');
        });
    }

Returns a new table of all the specified work orders attachments.

@param WorkOrder $workOrder

@return \Orchestra\Contracts\Html\Builder

Returns a new table of all the specified work orders attachments .


public function form(WorkOrder $workOrder, Attachment $attachment)
    {
        return $this->form->of('work-orders.attachments', function (FormGrid $form) use ($workOrder, $attachment) {
            $files = true;

            if ($attachment->exists) {
                $url = route('maintenance.work-orders.attachments.update', [$workOrder->getKey(), $attachment->getKey()]);
                $method = 'PATCH';
                $form->submit = 'Save';
                $form->with($attachment);
            } else {
                $url = route('maintenance.work-orders.attachments.store', [$workOrder->getKey()]);
                $method = 'POST';
                $form->submit = 'Upload';
            }

            $form->attributes(compact('url', 'method', 'files'));

            $form->fieldset(function (Fieldset $fieldset) use ($attachment) {
                if ($attachment->exists) {
                    // If the attachment exists we'll provide the ability
                    // to only change the attachments name.
                    $fieldset
                        ->control('input:text', 'name')
                        ->label('Attachment Name');
                } else {
                    // Otherwise we'll allow the user to upload multiple
                    // attachments at once for the specified work order.
                    $fieldset
                        ->control('input:file', 'files[]')
                        ->label('Files')
                        ->attributes([
                            'multiple' => true,
                        ]);
                }
            });
        });
    }

Returns a new form for the specified work order attachment.

@param WorkOrder  $workOrder
@param Attachment $attachment

@return \Orchestra\Contracts\Html\Builder

Returns a new form for the specified work order attachment .


public function authenticate(LoginRequest $request)
    {
        $throttles = $this->isUsingThrottlesLoginsTrait();

        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->getCredentials($request);

        try {
            if (Auth::attempt($credentials, $request->has('remember'))) {
                return $this->handleUserWasAuthenticated($request, $throttles);
            }
        } catch (Exception $e) {
            // Catch LDAP bind errors.
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }

        return redirect($this->loginPath())
            ->withInput($request->only($this->loginUsername(), 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }

Handle a login request to the application.

@param LoginRequest $request

@return \Illuminate\Http\Response

Handle a login request to the application .


protected function handleUserWasAuthenticated(Request $request, $throttles)
    {
        if ($throttles) {
            $this->clearLoginAttempts($request);
        }

        $user = auth()->user();

        if ($user instanceof User && $user->adldapUser instanceof AdldapUser) {
            $this->handleLdapUserWasAuthenticated($user, $user->adldapUser);
        }

        flash()->success('Success!', "You're logged in!");

        return redirect()->intended($this->redirectPath());
    }

protected
function
handleUserWasAuthenticated
(
Request
$
request
,
$
throttles
)
{
if
(
$
throttles
)
{
$
this
->
clearLoginAttempts
(
$
request
)
;
}
$
user
=
auth
(
)
->
user
(
)
;
if
(
$
user
instanceof
User
&&
$
user
->
adldapUser
instanceof
AdldapUser
)
{
$
this
->
handleLdapUserWasAuthenticated
(
$
user
,
$
user
->
adldapUser
)
;
}
flash
(
)
->
success
(
'Success!'
,
"You're logged in!"
)
;
return
redirect
(
)
->
intended
(
$
this
->
redirectPath
(
)
)
;
}

Send the response after the user was authenticated.

@param \Illuminate\Http\Request $request
@param bool                     $throttles

@return \Illuminate\Http\Response

Send the response after the user was authenticated .


protected function handleLdapUserWasAuthenticated(User $user, AdldapUser $adldapUser)
    {
        if ($adldapUser->inGroup('Help Desk')) {
            $admin = Role::admin();

            if ($admin instanceof Role) {
                $user->attachRole($admin->getKey());
            }
        }
    }

protected
function
handleLdapUserWasAuthenticated
(
User
$
user
,
AdldapUser
$
adldapUser
)
{
if
(
$
adldapUser
->
inGroup
(
'Help Desk'
)
)
{
$
admin
=
Role
::
admin
(
)
;
if
(
$
admin
instanceof
Role
)
{
$
user
->
attachRole
(
$
admin
->
getKey
(
)
)
;
}
}
}

Attaches roles depending on the users active directory group.

@param User       $user
@param AdldapUser $adldapUser

Attaches roles depending on the users active directory group .


public function deleted(InventoryStock $stock)
    {
        $movements = $stock->movements()->get();

        if (count($movements) > 0) {
            foreach ($movements as $movement) {
                $movement->delete();
            }
        }
    }

public function deleted ( InventoryStock $ stock ) { $ movements = $ stock -> movements ( ) -> get ( ) ; if ( count ( $ movements ) > 0 ) { foreach ( $ movements as $ movement ) { $ movement -> delete ( ) ; } } }

Captures the Inventory Stock models deleted event
and cascades the delete to all of it's movements.

@param InventoryStock $stock

Captures the Inventory Stock models deleted event and cascades the delete to all of it s movements .


public function restored(InventoryStock $stock)
    {
        $movements = $stock->movements()->onlyTrashed()->get();

        if (count($movements) > 0) {
            foreach ($movements as $movement) {
                $movement->restore();
            }
        }
    }

public function restored ( InventoryStock $ stock ) { $ movements = $ stock -> movements ( ) -> onlyTrashed ( ) -> get ( ) ; if ( count ( $ movements ) > 0 ) { foreach ( $ movements as $ movement ) { $ movement -> restore ( ) ; } } }

Captures the Inventory Stock models restored event
and cascades the restore to all of it's movements.

@param InventoryStock $stock

Captures the Inventory Stock models restored event and cascades the restore to all of it s movements .


public function table(Priority $priority)
    {
        return $this->table->of('work-orders.priorities', function (TableGrid $table) use ($priority) {
            $table->with($priority);

            $table->column('priority', function (Column $column) {
                $column->value = function (Priority $priority) {
                    return link_to_route('maintenance.work-orders.priorities.edit', $priority->getLabel(), [$priority->getKey()]);
                };
            });

            $table->column('created_at');

            $table->column('created_by', function (Column $column) {
                $column->value = function (Priority $priority) {
                    if ($priority->user instanceof User) {
                        return $priority->user->getRecipientName();
                    } else {
                        return HTML::create('em', 'None');
                    }
                };
            });
        });
    }

Returns a new table of all priorities.

@param Priority $priority

@return \Orchestra\Contracts\Html\Builder


public function form(Priority $priority)
    {
        return $this->form->of('work-orders.priorities', function (FormGrid $form) use ($priority) {
            if ($priority->exists) {
                $url = route('maintenance.work-orders.priorities.update', [$priority->getKey()]);
                $method = 'PATCH';
                $form->submit = 'Save';
            } else {
                $url = route('maintenance.work-orders.priorities.store');
                $method = 'POST';
                $form->submit = 'Create';
            }

            $colors = config('maintenance.colors', []);

            $form->attributes(compact('method', 'url'));

            $form->with($priority);

            $form->fieldset(function (Fieldset $fieldset) use ($colors) {
                $fieldset
                    ->control('input:text', 'name')
                    ->attributes([
                        'placeholder' => 'ex. High / Low',
                    ]);

                $fieldset
                    ->control('select', 'color')
                    ->options($colors)
                    ->value(function (Priority $priority) {
                        return $priority->color;
                    })
                    ->attributes([
                        'class' => 'select2-color',
                    ]);
            });
        });
    }

Returns a new form for priorities.

@param Priority $priority

@return \Orchestra\Contracts\Html\Builder