Skip to content

Commit 43cdace

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 1f0f9c2 + a04af4a commit 43cdace

21 files changed

+14948
-141
lines changed

app/controllers/admin/SettingsController.php

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function postEdit()
8686
$setting->per_page = e(Input::get('per_page'));
8787
$setting->qr_code = e(Input::get('qr_code', '0'));
8888
$setting->display_eol = e(Input::get('display_eol', '0'));
89+
$setting->load_remote = e(Input::get('load_remote', '0'));
8990
$setting->qr_text = e(Input::get('qr_text'));
9091
$setting->auto_increment_prefix = e(Input::get('auto_increment_prefix'));
9192
$setting->auto_increment_assets = e(Input::get('auto_increment_assets', '0'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddLocalonlyToSettings extends Migration {
7+
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
//
16+
Schema::table('settings', function ($table) {
17+
$table->boolean('load_remote')->default(1);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
//
29+
Schema::table('settings', function ($table) {
30+
$table->dropColumn('load_remote');
31+
});
32+
33+
}
34+
35+
}

app/lang/en/admin/settings/general.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'display_qr' => 'Display QR Codes',
1111
'info' => 'These settings let you customize certain aspects of your installation.',
1212
'laravel' => 'Laravel Version',
13+
'load_remote' => 'This Snipe-IT install can load scripts from the outside world.',
1314
'per_page' => 'Results Per Page',
1415
'php' => 'PHP Version',
1516
'php_gd_info' => 'You must install php-gd to display QR codes, see install instructions.',

app/lang/en/general.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
'gravatar_email' => 'Gravatar Email Address',
5050
'history_for' => 'History for',
5151
'id' => 'ID',
52-
'image_delete' => 'Delete Image',
53-
'image_upload' => 'Upload Image',
52+
'image_delete' => 'Delete Image',
53+
'image_upload' => 'Upload Image',
5454
'last_name' => 'Last Name',
5555
'license' => 'License',
5656
'license_report' => 'License Report',

app/models/Asset.php

+12-44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class Asset extends Elegant
3+
class Asset extends Depreciable
44
{
55
use SoftDeletingTrait;
66
protected $dates = ['deleted_at'];
@@ -15,24 +15,19 @@ class Asset extends Elegant
1515
'notes' => 'alpha_space',
1616
'pysical' => 'integer',
1717
'supplier_id' => 'integer',
18-
//'asset_tag' => 'required|alpha_space|min:3|max:255|unique:assets,asset_tag,{id},deleted_at,NULL',
19-
//'email' => 'required|email|unique:users,email,NULL,id,deleted_at,NULL',
20-
//'asset_tag' => 'required|alpha_space|min:2|max:255|unique:assets,asset_tag,deleted_at,NULL',
2118
'asset_tag' => 'required|alpha_space|min:3|max:255|unique:assets,asset_tag,{id}',
22-
'serial' => 'required|alpha_dash|min:3|max:255|unique:assets,serial,{id}',
19+
//'serial' => 'required|alpha_dash|min:3|max:255|unique:assets,serial,{id}',
2320
'status' => 'integer'
2421
);
2522

26-
/**
27-
* Handle depreciation
28-
*/
29-
public function depreciate()
23+
public function depreciation()
3024
{
31-
return $this->getCurrentValue(
32-
Model::find($this->model_id)->depreciation_id,
33-
$this->purchase_cost,
34-
$this->purchase_date
35-
);
25+
return $this->model->belongsTo('Depreciation','depreciation_id');
26+
}
27+
28+
public function get_depreciation()
29+
{
30+
return $this->model->depreciation;
3631
}
3732

3833
/**
@@ -132,33 +127,6 @@ public function warrantee_expires()
132127
return date_format($date, 'Y-m-d');
133128
}
134129

135-
public function months_until_depreciated()
136-
{
137-
$today = date("Y-m-d");
138-
139-
// @link http://www.php.net/manual/en/class.datetime.php
140-
$d1 = new DateTime($today);
141-
$d2 = new DateTime($this->depreciated_date());
142-
143-
// @link http://www.php.net/manual/en/class.dateinterval.php
144-
$interval = $d1->diff($d2);
145-
return $interval;
146-
}
147-
148-
149-
public function depreciated_date()
150-
{
151-
$date = date_create($this->purchase_date);
152-
date_add($date, date_interval_create_from_date_string($this->depreciation->months.' months'));
153-
return date_format($date, 'Y-m-d');
154-
}
155-
156-
157-
public function depreciation()
158-
{
159-
return $this->model->belongsTo('Depreciation','depreciation_id');
160-
}
161-
162130
public function model()
163131
{
164132
return $this->belongsTo('Model','model_id');
@@ -167,13 +135,13 @@ public function model()
167135
/**
168136
* Get the license seat information
169137
**/
170-
public function licenses()
138+
public function licenses()
171139
{
172140
return $this->belongsToMany('License', 'license_seats', 'asset_id', 'license_id');
173141

174142
}
175143

176-
public function licenseseats()
144+
public function licenseseats()
177145
{
178146
return $this->hasMany('LicenseSeat', 'asset_id');
179147
}
@@ -210,7 +178,7 @@ public function eol_date()
210178
/**
211179
* Get total assets
212180
*/
213-
public static function autoincrement_asset()
181+
public static function autoincrement_asset()
214182
{
215183
$settings = Setting::getSettings();
216184

app/models/Depreciable.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
class Depreciable extends Elegant
4+
{
5+
/**
6+
* Depreciation Relation, and associated helper methods
7+
*/
8+
9+
//REQUIRES a purchase_date field
10+
// and a purchase_cost field
11+
12+
//REQUIRES a get_depreciation method,
13+
//which will return the deprecation.
14+
//this is needed because assets get
15+
//their depreciation from a model,
16+
//whereas licenses have deprecations
17+
//directly associated with them.
18+
19+
//assets will override the following
20+
//two methods in order to inherit from
21+
//their model instead of directly (like
22+
//here)
23+
24+
public function depreciation()
25+
{
26+
return $this->belongsTo('Depreciation','depreciation_id');
27+
}
28+
29+
public function get_depreciation()
30+
{
31+
return $this->depreciation;
32+
}
33+
34+
/**
35+
* @param $purchase_cost
36+
* @param $purchase_date1
37+
* @return float|int
38+
*/
39+
40+
public function getDepreciatedValue()
41+
{
42+
if (!$this->get_depreciation()) { // will never happen
43+
return $this->purchase_cost;
44+
}
45+
46+
if ($this->get_depreciation()->months <= 0) {
47+
return $this->purchase_cost;
48+
}
49+
50+
// fraction of value left
51+
$months_remaining = $this->time_until_depreciated()->m + $this->time_until_depreciated()->y; //UGlY
52+
$current_value = round(($months_remaining/ $this->get_depreciation()->months) * $this->purchase_cost, 2);
53+
54+
if ($current_value < 0) {
55+
$current_value = 0;
56+
}
57+
return $current_value;
58+
}
59+
60+
public function time_until_depreciated()
61+
{
62+
// @link http://www.php.net/manual/en/class.datetime.php
63+
$d1 = new DateTime();
64+
$d2 = $this->depreciated_date();
65+
66+
// @link http://www.php.net/manual/en/class.dateinterval.php
67+
$interval = $d1->diff($d2);
68+
if(!$interval->invert) {
69+
return $interval;
70+
} else {
71+
return new DateInterval("PT0S"); //null interval (zero seconds from now)
72+
}
73+
}
74+
75+
public function depreciated_date()
76+
{
77+
$date = date_create($this->purchase_date);
78+
date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months . ' months'));
79+
return $date; //date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
80+
}
81+
}

app/models/Depreciation.php

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ public function has_models()
1212
{
1313
return $this->hasMany('Model', 'depreciation_id')->count();
1414
}
15+
16+
public function has_licenses()
17+
{
18+
return $this->hasMany('License','depreciation_id')->count();
19+
}
1520
}

app/models/Elegant.php

-32
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,4 @@ public function validationRules($id = '0')
3030
{
3131
return str_replace("{id}", $id, $this->rules);
3232
}
33-
34-
/**
35-
* @param $depreciation_id
36-
* @param $purchase_cost
37-
* @param $purchase_date1
38-
* @return float|int
39-
*/
40-
protected function getCurrentValue($depreciation_id, $purchase_cost, $purchase_date1)
41-
{
42-
if (!$depreciation_id) {
43-
return $purchase_cost;
44-
}
45-
46-
$depreciation_term = Depreciation::find($depreciation_id)->months;
47-
if ($depreciation_term <= 0) {
48-
return $purchase_cost;
49-
}
50-
51-
$purchase_date = strtotime($purchase_date1);
52-
53-
$todaymonthnumber = date("Y") * 12 + (date("m") - 1); //calculate the month number for today as YEAR*12 + (months-1) - number of months since January year 0
54-
$purchasemonthnumber = date("Y", $purchase_date) * 12 + (date("m", $purchase_date) - 1); //purchase date calculated similarly
55-
$diff_months = $todaymonthnumber - $purchasemonthnumber;
56-
57-
// fraction of value left
58-
$current_value = round((($depreciation_term - $diff_months) / ($depreciation_term)) * $purchase_cost, 2);
59-
60-
if ($current_value < 0) {
61-
$current_value = 0;
62-
}
63-
return $current_value;
64-
}
6533
}

app/models/License.php

+2-42
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
class License extends Elegant
3+
class License extends Depreciable
44
{
55
use SoftDeletingTrait;
66
protected $dates = ['deleted_at'];
77

8-
public $timestamps = true;
8+
public $timestamps = true;
99

1010
protected $guarded = 'id';
1111
protected $table = 'licenses';
@@ -155,44 +155,4 @@ public function supplier()
155155
{
156156
return $this->belongsTo('Supplier','supplier_id');
157157
}
158-
159-
/**
160-
* Get depreciation class
161-
*/
162-
public function depreciation()
163-
{
164-
return $this->belongsTo('Depreciation','depreciation_id');
165-
}
166-
167-
public function months_until_depreciated()
168-
{
169-
$today = date("Y-m-d");
170-
171-
// @link http://www.php.net/manual/en/class.datetime.php
172-
$d1 = new DateTime($today);
173-
$d2 = new DateTime($this->depreciated_date());
174-
175-
// @link http://www.php.net/manual/en/class.dateinterval.php
176-
$interval = $d1->diff($d2);
177-
return $interval;
178-
}
179-
180-
public function depreciated_date()
181-
{
182-
$date = date_create($this->purchase_date);
183-
date_add($date, date_interval_create_from_date_string($this->depreciation->months . ' months'));
184-
return date_format($date, 'Y-m-d');
185-
}
186-
187-
/**
188-
* Handle depreciation
189-
*/
190-
public function depreciate()
191-
{
192-
return $this->getCurrentValue(
193-
License::find($this->license_id)->depreciation_id,
194-
$this->purchase_cost,
195-
$this->purchase_date
196-
);
197-
}
198158
}

app/views/backend/hardware/view.blade.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@
119119
@lang('admin/hardware/form.months')
120120
)</div>
121121
<div class="col-md-12" style="padding-bottom: 5px;"><strong>@lang('admin/hardware/form.fully_depreciated'): </strong>
122-
{{{ $asset->months_until_depreciated()->m }}}
123-
@lang('admin/hardware/form.months')
124-
@if ($asset->months_until_depreciated()->y > 0)
125-
, {{{ $asset->months_until_depreciated()->y }}}
126-
@lang('admin/hardware/form.years')
122+
@if ($asset->time_until_depreciated()->y > 0)
123+
{{{ $asset->time_until_depreciated()->y }}}
124+
@lang('admin/hardware/form.years'),
127125
@endif
128-
({{{ $asset->depreciated_date() }}})
126+
{{{ $asset->time_until_depreciated()->m }}}
127+
@lang('admin/hardware/form.months')
128+
({{{ $asset->depreciated_date()->format('Y-m-d') }}})
129129
</div>
130130
@endif
131131

0 commit comments

Comments
 (0)