Skip to content

Commit

Permalink
Fixes #112
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Dec 10, 2013
1 parent 4c3e2a9 commit 4468cbd
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 20 deletions.
24 changes: 13 additions & 11 deletions app/controllers/admin/ModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ public function postCreate()
{

// Save the model data
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
$model->depreciation_id = e(Input::get('depreciation_id'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->user_id = Sentry::getId();
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
$model->depreciation_id = e(Input::get('depreciation_id'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->user_id = Sentry::getId();
$model->eol = e(Input::get('eol'));


// Was it created?
Expand Down Expand Up @@ -145,11 +146,12 @@ public function postEdit($modelId = null)
{

// Update the model data
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
$model->depreciation_id = e(Input::get('depreciation_id'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
$model->depreciation_id = e(Input::get('depreciation_id'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->eol = e(Input::get('eol'));


// Was it created?
Expand Down
1 change: 1 addition & 0 deletions app/lang/en/admin/hardware/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
'checkoutto' => 'Checked Out',
'change' => 'In/Out',
'location' => 'Location',
'eol' => 'EOL',

);
1 change: 1 addition & 0 deletions app/lang/en/admin/models/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
'modelnumber' => 'Model No.',
'created_at' => 'Created at',
'numassets' => 'Assets',
'eol' => 'EOL',

);
24 changes: 24 additions & 0 deletions app/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,28 @@ public function model()
return $this->belongsTo('Model','model_id');
}

public function months_until_eol()
{
$today = date("Y-m-d");
$d1 = new DateTime($today);
$d2 = new DateTime($this->eol_date());

if ($this->eol_date() > $today)
{
$interval = $d2->diff($d1);
} else {
$interval = NULL;
}

return $interval;
}

public function eol_date()
{
$date = date_create($this->purchase_date);
date_add($date, date_interval_create_from_date_string($this->model->eol.' months'));
return date_format($date, 'Y-m-d');
}


}
9 changes: 4 additions & 5 deletions app/models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Model extends Elegant {

// Declare the rules for the form validation
protected $rules = array(
'name' => 'required|alpha_space|min:3',
'modelno' => 'alpha_space|min:1',
'category_id' => 'required|integer',
'name' => 'required|alpha_space|min:3',
'modelno' => 'alpha_space|min:1',
'category_id' => 'required|integer',
'manufacturer_id' => 'required|integer',
'eol' => 'integer',
);

public function assets()
Expand Down Expand Up @@ -35,6 +36,4 @@ public function manufacturer()
return $this->belongsTo('Manufacturer','manufacturer_id');
}



}
10 changes: 8 additions & 2 deletions app/views/backend/hardware/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<table id="example">
<thead>
<tr role="row">
<th class="col-md-2" bSortable="true">@lang('admin/hardware/table.asset_tag')</th>
<th class="col-md-1" bSortable="true">@lang('admin/hardware/table.asset_tag')</th>
<th class="col-md-3" bSortable="true">@lang('admin/hardware/table.title')</th>
<th class="col-md-2" bSortable="true">@lang('admin/hardware/table.serial')</th>
@if (Input::get('Pending') || Input::get('Undeployable') || Input::get('RTD'))
Expand All @@ -63,7 +63,7 @@
<th class="col-md-2" bSortable="true">@lang('admin/hardware/table.checkoutto')</th>
<th class="col-md-2" bSortable="true">@lang('admin/hardware/table.location')</th>
@endif

<th class="col-md-2">@lang('admin/hardware/table.eol')</th>
<th class="col-md-1">@lang('admin/hardware/table.change')</th>
<th class="col-md-2 actions" bSortable="false">@lang('table.actions')</th>
</tr>
Expand Down Expand Up @@ -108,6 +108,12 @@

@endif

<td>
@if ($asset->model->eol)
{{ $asset->eol_date() }}
@endif
</td>

<td>
@if ($asset->status_id < 1 )
@if ($asset->assigned_to != 0)
Expand Down
10 changes: 10 additions & 0 deletions app/views/backend/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
{{ $asset->months_until_depreciated()->y }} years</div>
@endif

@if ($asset->model->eol)
<div class="col-md-6"><strong>EOL Rate: </strong> {{ $asset->model->eol }} months </div>
<div class="col-md-6"><strong>EOL Date: </strong> {{ $asset->eol_date() }}
@if ($asset->months_until_eol())
({{ $asset->months_until_eol()->y }} years,
{{ $asset->months_until_eol()->m }} months)
@endif
</div>
@endif

</div>


Expand Down
13 changes: 13 additions & 0 deletions app/views/backend/models/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
</div>
</div>

<!-- EOL -->
<div class="form-group {{ $errors->has('eol') ? ' has-error' : '' }}">
<label for="eol" class="col-md-2 control-label">EOL</label>
<div class="col-md-2">
<div class="input-group">
<input class="col-md-1 form-control" type="text" name="eol" id="eol" value="{{ Input::old('eol', $model->eol) }}" /> <span class="input-group-addon">months</span>
{{ $errors->first('eol', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
</div>



<!-- Form actions -->
<div class="form-group">
<label class="col-md-2 control-label"></label>
Expand Down
15 changes: 13 additions & 2 deletions app/views/backend/models/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
<th class="col-md-1">@lang('admin/models/table.numassets')</th>
<th class="col-md-2">Depreciation</th>
<th class="col-md-2">Category</th>
<th class="col-md-2">EOL</th>
<th class="col-md-2 actions">@lang('table.actions')</th>
</tr>
</thead>
<tbody>
@foreach ($models as $model)
<tr>
<td><a href="{{ route('update/model', $model->id) }}">{{{ $model->name }}}</a></td>
<td><a href="{{ route('view/model', $model->id) }}">{{{ $model->name }}}</a></td>
<td>{{ $model->modelno }}</td>
<td><a href="{{ route('view/model', $model->id) }}">{{ ($model->assets->count()) }}</a></td>
<td>


@if (($model->depreciation) && ($model->depreciation->id > 0))
{{ $model->depreciation->name }}
({{ $model->depreciation->months }} months)
Expand All @@ -50,6 +50,17 @@
{{ $model->category->name }}
@endif
</td>

<td>

@if ($model->eol)
{{ $model->eol }} months
@else
--
@endif

</td>

<td>
<a href="{{ route('update/model', $model->id) }}" class="btn btn-warning"><i class="icon-pencil icon-white"></i></a>
<a data-html="false" class="btn delete-asset btn-danger" data-toggle="modal" href="{{ route('delete/model', $model->id) }}" data-content="Are you sure you wish to delete this model?" data-title="Delete {{ htmlspecialchars($model->name) }}?" onClick="return false;"><i class="icon-trash icon-white"></i></a>
Expand Down
4 changes: 4 additions & 0 deletions app/views/backend/models/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<li>Depreciation: {{ $model->depreciation->name }} ({{ $model->depreciation->months }} months)</li>
@endif

@if ($model->eol)
<li>EOL: {{ $model->eol }} months</li>
@endif

</ul>


Expand Down

0 comments on commit 4468cbd

Please sign in to comment.