Skip to content

Commit 73b4696

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 381f995 + e94087d commit 73b4696

File tree

6 files changed

+358
-5
lines changed

6 files changed

+358
-5
lines changed

app/controllers/admin/LicensesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function postCreate()
7878
$license->seats = e(Input::get('seats'));
7979
$license->purchase_date = e(Input::get('purchase_date'));
8080
$license->purchase_cost = e(Input::get('purchase_cost'));
81-
$license->depreciate = e(Input::get('depreciate'));
81+
$license->depreciation_id = e(Input::get('depreciation_id'));
8282
$license->user_id = Sentry::getId();
8383

8484
if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) {
@@ -181,6 +181,7 @@ public function postEdit($licenseId = null)
181181
$license->license_name = e(Input::get('license_name'));
182182
$license->notes = e(Input::get('notes'));
183183
$license->order_number = e(Input::get('order_number'));
184+
$license->depreciation_id = e(Input::get('depreciation_id'));
184185

185186
// Update the asset data
186187
if ( e(Input::get('purchase_date')) == '') {

app/macros.php

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
<?php
2+
/**
3+
* Macro helpers
4+
*
5+
*/
6+
7+
/**
8+
* Country macro
9+
* Generates the dropdown menu of countries for the profile form
10+
*/
11+
Form::macro('countries', function ($name = "country", $selected = null, $class = null) {
12+
13+
$countries = array(
14+
''=>"Select a Country",
15+
'ac'=>'Ascension Island',
16+
'ad'=>'Andorra',
17+
'ae'=>'United Arab Emirates',
18+
'af'=>'Afghanistan',
19+
'ag'=>'Antigua And Barbuda',
20+
'ai'=>'Anguilla',
21+
'al'=>'Albania',
22+
'am'=>'Armenia',
23+
'an'=>'Netherlands Antilles',
24+
'ao'=>'Angola',
25+
'aq'=>'Antarctica',
26+
'ar'=>'Argentina',
27+
'as'=>'American Samoa',
28+
'at'=>'Austria',
29+
'au'=>'Australia',
30+
'aw'=>'Aruba',
31+
'ax'=>'Ã…land',
32+
'az'=>'Azerbaijan',
33+
'ba'=>'Bosnia And Herzegovina',
34+
'bb'=>'Barbados',
35+
'be'=>'Belgium',
36+
'bd'=>'Bangladesh',
37+
'bf'=>'Burkina Faso',
38+
'bg'=>'Bulgaria',
39+
'bh'=>'Bahrain',
40+
'bi'=>'Burundi',
41+
'bj'=>'Benin',
42+
'bm'=>'Bermuda',
43+
'bn'=>'Brunei Darussalam',
44+
'bo'=>'Bolivia',
45+
'br'=>'Brazil',
46+
'bs'=>'Bahamas',
47+
'bt'=>'Bhutan',
48+
'bv'=>'Bouvet Island',
49+
'bw'=>'Botswana',
50+
'by'=>'Belarus',
51+
'bz'=>'Belize',
52+
'ca'=>'Canada',
53+
'cc'=>'Cocos (Keeling) Islands',
54+
'cd'=>'Congo (Democratic Republic)',
55+
'cf'=>'Central African Republic',
56+
'cg'=>'Congo (Republic)',
57+
'ch'=>'Switzerland',
58+
'ci'=>'Cote D’Ivoire',
59+
'ck'=>'Cook Islands',
60+
'cl'=>'Chile',
61+
'cm'=>'Cameroon',
62+
'cn'=>'People’s Republic of China',
63+
'co'=>'Colombia',
64+
'cr'=>'Costa Rica',
65+
'cu'=>'Cuba',
66+
'cv'=>'Cape Verde',
67+
'cx'=>'Christmas Island',
68+
'cy'=>'Cyprus',
69+
'cz'=>'Czech Republic',
70+
'de'=>'Germany',
71+
'dj'=>'Djibouti',
72+
'dk'=>'Denmark',
73+
'dm'=>'Dominica',
74+
'do'=>'Dominican Republic',
75+
'dz'=>'Algeria',
76+
'ec'=>'Ecuador',
77+
'ee'=>'Estonia',
78+
'eg'=>'Egypt',
79+
'er'=>'Eritrea',
80+
'es'=>'Spain',
81+
'et'=>'Ethiopia',
82+
'eU'=>'European Union',
83+
'fi'=>'Finland',
84+
'fj'=>'Fiji',
85+
'fk'=>'Falkland Islands (Malvinas)',
86+
'fm'=>'Micronesia, Federated States Of',
87+
'fo'=>'Faroe Islands',
88+
'fr'=>'France',
89+
'ga'=>'Gabon',
90+
'gb'=>'United Kingdom',
91+
'gd'=>'Grenada',
92+
'ge'=>'Georgia',
93+
'gf'=>'French Guiana',
94+
'gg'=>'Guernsey',
95+
'gh'=>'Ghana',
96+
'gi'=>'Gibraltar',
97+
'gl'=>'Greenland',
98+
'gm'=>'Gambia',
99+
'gn'=>'Guinea',
100+
'gp'=>'Guadeloupe',
101+
'gq'=>'Equatorial Guinea',
102+
'gr'=>'Greece',
103+
'gs'=>'South Georgia And The South Sandwich Islands',
104+
'gt'=>'Guatemala',
105+
'gu'=>'Guam',
106+
'gw'=>'Guinea-Bissau',
107+
'gy'=>'Guyana',
108+
'hk'=>'Hong Kong',
109+
'hm'=>'Heard And Mc Donald Islands',
110+
'hn'=>'Honduras',
111+
'hr'=>'Croatia (local name: Hrvatska)',
112+
'ht'=>'Haiti',
113+
'hu'=>'Hungary',
114+
'id'=>'Indonesia',
115+
'ie'=>'Ireland',
116+
'il'=>'Israel',
117+
'im'=>'Isle of Man',
118+
'in'=>'India',
119+
'io'=>'British Indian Ocean Territory',
120+
'iq'=>'Iraq',
121+
'ir'=>'Iran (Islamic Republic Of)',
122+
'is'=>'Iceland',
123+
'it'=>'Italy',
124+
'je'=>'Jersey',
125+
'jm'=>'Jamaica',
126+
'jo'=>'Jordan',
127+
'jp'=>'Japan',
128+
'ke'=>'Kenya',
129+
'kg'=>'Kyrgyzstan',
130+
'kh'=>'Cambodia',
131+
'ki'=>'Kiribati',
132+
'km'=>'Comoros',
133+
'kn'=>'Saint Kitts And Nevis',
134+
'kr'=>'Korea, Republic Of',
135+
'kw'=>'Kuwait',
136+
'ky'=>'Cayman Islands',
137+
'kz'=>'Kazakhstan',
138+
'la'=>'Lao People’s Democratic Republic',
139+
'lb'=>'Lebanon',
140+
'lc'=>'Saint Lucia',
141+
'li'=>'Liechtenstein',
142+
'lk'=>'Sri Lanka',
143+
'lr'=>'Liberia',
144+
'ls'=>'Lesotho',
145+
'lt'=>'Lithuania',
146+
'lu'=>'Luxembourg',
147+
'lv'=>'Latvia',
148+
'ly'=>'Libyan Arab Jamahiriya',
149+
'ma'=>'Morocco',
150+
'mc'=>'Monaco',
151+
'md'=>'Moldova, Republic Of',
152+
'me'=>'Montenegro',
153+
'mg'=>'Madagascar',
154+
'mh'=>'Marshall Islands',
155+
'mk'=>'Macedonia, The Former Yugoslav Republic Of',
156+
'ml'=>'Mali',
157+
'mm'=>'Myanmar',
158+
'mn'=>'Mongolia',
159+
'mo'=>'Macau',
160+
'mp'=>'Northern Mariana Islands',
161+
'mq'=>'Martinique',
162+
'mr'=>'Mauritania',
163+
'ms'=>'Montserrat',
164+
'mt'=>'Malta',
165+
'mu'=>'Mauritius',
166+
'mv'=>'Maldives',
167+
'mw'=>'Malawi',
168+
'mx'=>'Mexico',
169+
'my'=>'Malaysia',
170+
'mz'=>'Mozambique',
171+
'na'=>'Namibia',
172+
'nc'=>'New Caledonia',
173+
'ne'=>'Niger',
174+
'nf'=>'Norfolk Island',
175+
'ng'=>'Nigeria',
176+
'ni'=>'Nicaragua',
177+
'nl'=>'Netherlands',
178+
'no'=>'Norway',
179+
'np'=>'Nepal',
180+
'nr'=>'Nauru',
181+
'nu'=>'Niue',
182+
'nz'=>'New Zealand',
183+
'om'=>'Oman',
184+
'pa'=>'Panama',
185+
'pe'=>'Peru',
186+
'pf'=>'French Polynesia',
187+
'pg'=>'Papua New Guinea',
188+
'ph'=>'Philippines, Republic of the',
189+
'pk'=>'Pakistan',
190+
'pl'=>'Poland',
191+
'pm'=>'St. Pierre And Miquelon',
192+
'pn'=>'Pitcairn',
193+
'pr'=>'Puerto Rico',
194+
'ps'=>'Palestine',
195+
'pt'=>'Portugal',
196+
'pw'=>'Palau',
197+
'py'=>'Paraguay',
198+
'qa'=>'Qatar',
199+
're'=>'Reunion',
200+
'ro'=>'Romania',
201+
'rs'=>'Serbia',
202+
'ru'=>'Russian Federation',
203+
'rw'=>'Rwanda',
204+
'sa'=>'Saudi Arabia',
205+
'uk'=>'Scotland',
206+
'sb'=>'Solomon Islands',
207+
'sc'=>'Seychelles',
208+
'sd'=>'Sudan',
209+
'se'=>'Sweden',
210+
'sg'=>'Singapore',
211+
'sh'=>'St. Helena',
212+
'si'=>'Slovenia',
213+
'sj'=>'Svalbard And Jan Mayen Islands',
214+
'sk'=>'Slovakia (Slovak Republic)',
215+
'sl'=>'Sierra Leone',
216+
'sm'=>'San Marino',
217+
'sn'=>'Senegal',
218+
'so'=>'Somalia',
219+
'sr'=>'Suriname',
220+
'st'=>'Sao Tome And Principe',
221+
'su'=>'Soviet Union',
222+
'sv'=>'El Salvador',
223+
'sy'=>'Syrian Arab Republic',
224+
'sz'=>'Swaziland',
225+
'tc'=>'Turks And Caicos Islands',
226+
'td'=>'Chad',
227+
'tf'=>'French Southern Territories',
228+
'tg'=>'Togo',
229+
'th'=>'Thailand',
230+
'tj'=>'Tajikistan',
231+
'tk'=>'Tokelau',
232+
'ti'=>'East Timor (new code)',
233+
'tm'=>'Turkmenistan',
234+
'tn'=>'Tunisia',
235+
'to'=>'Tonga',
236+
'tp'=>'East Timor (old code)',
237+
'tr'=>'Turkey',
238+
'tt'=>'Trinidad And Tobago',
239+
'tv'=>'Tuvalu',
240+
'tw'=>'Taiwan',
241+
'tz'=>'Tanzania, United Republic Of',
242+
'ua'=>'Ukraine',
243+
'ug'=>'Uganda',
244+
'uk'=>'United Kingdom',
245+
'um'=>'United States Minor Outlying Islands',
246+
'us'=>'United States',
247+
'uy'=>'Uruguay',
248+
'uz'=>'Uzbekistan',
249+
'va'=>'Vatican City State (Holy See)',
250+
'vc'=>'Saint Vincent And The Grenadines',
251+
've'=>'Venezuela',
252+
'vg'=>'Virgin Islands (British)',
253+
'vi'=>'Virgin Islands (U.S.)',
254+
'vn'=>'Viet Nam',
255+
'vu'=>'Vanuatu',
256+
'wf'=>'Wallis And Futuna Islands',
257+
'ws'=>'Samoa',
258+
'ye'=>'Yemen',
259+
'yt'=>'Mayotte',
260+
'za'=>'South Africa',
261+
'zm'=>'Zambia',
262+
'zw'=>'Zimbabwe'
263+
);
264+
265+
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:350px">';
266+
267+
foreach ($countries as $abbr => $country) {
268+
$select .= '<option value="'.$abbr.'"'.($selected == $abbr ? ' selected="selected"' : '').'>'.$country.'</option> ';
269+
}
270+
271+
$select .= '</select>';
272+
273+
return $select;
274+
275+
});

app/models/License.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,65 @@ public function licenseseats()
118118
*/
119119
public function depreciation()
120120
{
121-
return $this->belongsTo('Depreciation','id');
121+
return $this->belongsTo('Depreciation','depreciation_id');
122+
}
123+
124+
125+
public function months_until_depreciated()
126+
{
127+
128+
$today = date("Y-m-d");
129+
130+
// @link http://www.php.net/manual/en/class.datetime.php
131+
$d1 = new DateTime($today);
132+
$d2 = new DateTime($this->depreciated_date());
133+
134+
// @link http://www.php.net/manual/en/class.dateinterval.php
135+
$interval = $d1->diff($d2);
136+
return $interval;
137+
138+
}
139+
140+
141+
public function depreciated_date()
142+
{
143+
$date = date_create($this->purchase_date);
144+
date_add($date, date_interval_create_from_date_string($this->depreciation->months.' months'));
145+
return date_format($date, 'Y-m-d');
146+
}
147+
148+
149+
150+
/**
151+
* Handle depreciation
152+
*/
153+
public function depreciate()
154+
{
155+
$depreciation_id = License::find($this->license_id)->depreciation_id;
156+
if ($depreciation_id) {
157+
$depreciation_term = Depreciation::find($depreciation_id)->months;
158+
if($depreciation_term>0) {
159+
160+
$purchase_date = strtotime($this->purchase_date);
161+
162+
$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
163+
$purchasemonthnumber=date("Y",$purchase_date)*12+(date("m",$purchase_date)-1); //purchase date calculated similarly
164+
$diff_months=$todaymonthnumber-$purchasemonthnumber;
165+
166+
// fraction of value left
167+
$current_value = round((( $depreciation_term - $diff_months) / ($depreciation_term)) * $this->purchase_cost,2);
168+
169+
if ($current_value < 0) {
170+
$current_value = 0;
171+
}
172+
return $current_value;
173+
} else {
174+
return $this->purchase_cost;
175+
}
176+
} else {
177+
return $this->purchase_cost;
178+
}
179+
122180
}
123181

124182

app/start/global.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@
9696
});
9797

9898
require app_path().'/filters.php';
99+
require app_path().'/macros.php';
99100
require app_path().'/validators.php';

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@
3939
<div class="col-md-6"><strong>@lang('admin/licenses/form.notes'): </strong>{{ $license->notes }}</div>
4040
@endif
4141

42+
@if ($license->depreciation)
43+
<div class="col-md-6"><strong>@lang('admin/hardware/form.depreciation'): </strong>
44+
{{ $license->depreciation->name }}
45+
({{{ $license->depreciation->months }}}
46+
@lang('admin/hardware/form.months')
47+
)</div>
48+
<div class="col-md-6"><strong>@lang('admin/hardware/form.depreciates_on'): </strong>
49+
{{{ $license->depreciated_date() }}} </div>
50+
<div class="col-md-6"><strong>@lang('admin/hardware/form.fully_depreciated'): </strong>
51+
{{{ $license->months_until_depreciated()->m }}}
52+
@lang('admin/hardware/form.months')
53+
@if ($license->months_until_depreciated()->y > 0)
54+
, {{{ $license->months_until_depreciated()->y }}}
55+
@lang('admin/hardware/form.years')
56+
@endif
57+
</div>
58+
@endif
4259

4360
<br><br><br>
4461
</div>

0 commit comments

Comments
 (0)