From 4468cbd096e9990300240205baf7139eafbc423c Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 10 Dec 2013 04:48:40 -0500 Subject: [PATCH] Fixes #112 --- app/controllers/admin/ModelsController.php | 24 ++++++++++++---------- app/lang/en/admin/hardware/table.php | 1 + app/lang/en/admin/models/table.php | 1 + app/models/Asset.php | 24 ++++++++++++++++++++++ app/models/Model.php | 9 ++++---- app/views/backend/hardware/index.blade.php | 10 +++++++-- app/views/backend/hardware/view.blade.php | 10 +++++++++ app/views/backend/models/edit.blade.php | 13 ++++++++++++ app/views/backend/models/index.blade.php | 15 ++++++++++++-- app/views/backend/models/view.blade.php | 4 ++++ 10 files changed, 91 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index 3e239d7ec71a..cbc068bdfb01 100644 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -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? @@ -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? diff --git a/app/lang/en/admin/hardware/table.php b/app/lang/en/admin/hardware/table.php index 4def3fcfa30e..896787322c91 100755 --- a/app/lang/en/admin/hardware/table.php +++ b/app/lang/en/admin/hardware/table.php @@ -13,5 +13,6 @@ 'checkoutto' => 'Checked Out', 'change' => 'In/Out', 'location' => 'Location', + 'eol' => 'EOL', ); diff --git a/app/lang/en/admin/models/table.php b/app/lang/en/admin/models/table.php index 19f1969f313a..f6ed847723e3 100755 --- a/app/lang/en/admin/models/table.php +++ b/app/lang/en/admin/models/table.php @@ -6,5 +6,6 @@ 'modelnumber' => 'Model No.', 'created_at' => 'Created at', 'numassets' => 'Assets', + 'eol' => 'EOL', ); diff --git a/app/models/Asset.php b/app/models/Asset.php index a5ba10fe0fcc..868d29399c16 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -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'); + } + + } diff --git a/app/models/Model.php b/app/models/Model.php index 62cc54eb8b61..b24b2cd41582 100644 --- a/app/models/Model.php +++ b/app/models/Model.php @@ -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() @@ -35,6 +36,4 @@ public function manufacturer() return $this->belongsTo('Manufacturer','manufacturer_id'); } - - } diff --git a/app/views/backend/hardware/index.blade.php b/app/views/backend/hardware/index.blade.php index 75f905b093e6..d6d52cae2d73 100755 --- a/app/views/backend/hardware/index.blade.php +++ b/app/views/backend/hardware/index.blade.php @@ -54,7 +54,7 @@ - + @if (Input::get('Pending') || Input::get('Undeployable') || Input::get('RTD')) @@ -63,7 +63,7 @@ @endif - + @@ -108,6 +108,12 @@ @endif + + + @foreach ($models as $model) - + + + +
@lang('admin/hardware/table.asset_tag')@lang('admin/hardware/table.asset_tag') @lang('admin/hardware/table.title') @lang('admin/hardware/table.serial')@lang('admin/hardware/table.checkoutto') @lang('admin/hardware/table.location')@lang('admin/hardware/table.eol') @lang('admin/hardware/table.change') @lang('table.actions')
+ @if ($asset->model->eol) + {{ $asset->eol_date() }} + @endif + @if ($asset->status_id < 1 ) @if ($asset->assigned_to != 0) diff --git a/app/views/backend/hardware/view.blade.php b/app/views/backend/hardware/view.blade.php index 1b0d38a79481..872ba027af05 100644 --- a/app/views/backend/hardware/view.blade.php +++ b/app/views/backend/hardware/view.blade.php @@ -74,6 +74,16 @@ {{ $asset->months_until_depreciated()->y }} years @endif + @if ($asset->model->eol) +
EOL Rate: {{ $asset->model->eol }} months
+
EOL Date: {{ $asset->eol_date() }} + @if ($asset->months_until_eol()) + ({{ $asset->months_until_eol()->y }} years, + {{ $asset->months_until_eol()->m }} months) + @endif +
+ @endif + diff --git a/app/views/backend/models/edit.blade.php b/app/views/backend/models/edit.blade.php index 5fcae473c873..237e19d1d701 100755 --- a/app/views/backend/models/edit.blade.php +++ b/app/views/backend/models/edit.blade.php @@ -78,6 +78,19 @@ + +
+ +
+
+ months + {{ $errors->first('eol', ' :message') }} +
+
+
+ + +
diff --git a/app/views/backend/models/index.blade.php b/app/views/backend/models/index.blade.php index ee007147d837..a1b78b5c6775 100755 --- a/app/views/backend/models/index.blade.php +++ b/app/views/backend/models/index.blade.php @@ -25,18 +25,18 @@
@lang('admin/models/table.numassets') Depreciation CategoryEOL @lang('table.actions')
{{{ $model->name }}}{{{ $model->name }}} {{ $model->modelno }} {{ ($model->assets->count()) }} - @if (($model->depreciation) && ($model->depreciation->id > 0)) {{ $model->depreciation->name }} ({{ $model->depreciation->months }} months) @@ -50,6 +50,17 @@ {{ $model->category->name }} @endif + + @if ($model->eol) + {{ $model->eol }} months + @else + -- + @endif + + diff --git a/app/views/backend/models/view.blade.php b/app/views/backend/models/view.blade.php index 418640af358f..68188f4d08ad 100644 --- a/app/views/backend/models/view.blade.php +++ b/app/views/backend/models/view.blade.php @@ -90,6 +90,10 @@
  • Depreciation: {{ $model->depreciation->name }} ({{ $model->depreciation->months }} months)
  • @endif + @if ($model->eol) +
  • EOL: {{ $model->eol }} months
  • + @endif +