Add setting to include transfer hours in calculations (#350)

* Add setting to include transfer hours in calculations

* Add some extra tests to check versions

* A couple of more version test cases
This commit is contained in:
Nabeel S
2019-08-08 12:50:43 -04:00
committed by GitHub
parent ff6ba4c29a
commit a08c9db284
12 changed files with 169 additions and 83 deletions

View File

@@ -15,76 +15,6 @@ roles:
- name: fleet-only
display_name: Edit Fleet
users:
- id: 1
pilot_id: 1
name: Admin User
email: admin@phpvms.net
password: admin
api_key: testadminapikey
airline_id: 1
rank_id: 1
country: us
home_airport_id: KAUS
curr_airport_id: KJFK
last_pirep_id: pirepid_3
flights: 3
flight_time: 0
timezone: America/Chicago
state: 1
opt_in: 1
toc_accepted: 1
created_at: now
updated_at: now
- id: 2
pilot_id: 2
name: Carla Walters
email: carla.walters68@example.com
password: admin
api_key: testuserapikey1
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KJFK
flights: 1
flight_time: 4320
created_at: now
updated_at: now
state: 0
opt_in: 1
toc_accepted: 1
- id: 3
pilot_id: 3
name: Raymond Pearson
email: raymond.pearson56@example.com
password: admin
api_key: testuserapikey2
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KAUS
flights: 1
flight_time: 4320
created_at: now
updated_at: now
state: 1
opt_in: 0
toc_accepted: 1
role_user:
- user_id: 1
role_id: 1
user_type: App\Models\User
- user_id: 1
role_id: 2
user_type: App\Models\User
- user_id: 2
role_id: 2
user_type: App\Models\User
- user_id: 3
role_id: 2
user_type: App\Models\User
awards:
- id: 1
name: Pilot 50 flights

View File

@@ -0,0 +1,71 @@
users:
- id: 1
pilot_id: 1
name: Admin User
email: admin@phpvms.net
password: admin
api_key: testadminapikey
airline_id: 1
rank_id: 1
country: us
home_airport_id: KAUS
curr_airport_id: KJFK
last_pirep_id: pirepid_3
flights: 3
flight_time: 0
timezone: America/Chicago
state: 1
opt_in: 1
toc_accepted: 1
created_at: now
updated_at: now
- id: 2
pilot_id: 2
name: Carla Walters
email: carla.walters68@example.com
password: admin
api_key: testuserapikey1
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KJFK
flights: 1
flight_time: 4320
transfer_time: 360
created_at: now
updated_at: now
state: 0
opt_in: 1
toc_accepted: 1
- id: 3
pilot_id: 3
name: Raymond Pearson
email: raymond.pearson56@example.com
password: admin
api_key: testuserapikey2
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KAUS
flights: 1
flight_time: 4320
transfer_time: 120
created_at: now
updated_at: now
state: 1
opt_in: 0
toc_accepted: 1
role_user:
- user_id: 1
role_id: 1
user_type: App\Models\User
- user_id: 1
role_id: 2
user_type: App\Models\User
- user_id: 2
role_id: 2
user_type: App\Models\User
- user_id: 3
role_id: 2
user_type: App\Models\User

View File

@@ -194,3 +194,10 @@
options: ''
type: boolean
description: 'Allow specifying transfer hours on registration page and displayed on profile page'
- key: pilots.count_transfer_hours
name: 'Count transfer hours in calculations'
group: pilots
value: false
options: ''
type: boolean
description: 'Count transfer hours in calculations, like ranks and the total hours'

View File

@@ -10,12 +10,12 @@ use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Services\UserService;
use App\Support\Countries;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Jackiedo\Timezonelist\Facades\Timezonelist;
use Log;
use Validator;
/**
* Class RegisterController

View File

@@ -11,6 +11,7 @@ use App\Contracts\Model;
* @property int hours
* @property float manual_base_pay_rate
* @property float acars_base_pay_rate
* @property bool auto_promote
*/
class Rank extends Model
{

View File

@@ -22,7 +22,8 @@ use Laratrust\Traits\LaratrustUserTrait;
* @property string home_airport_id
* @property Airline airline
* @property Flight[] flights
* @property string flight_time
* @property int flight_time
* @property int transfer_time
* @property string remember_token
* @property \Carbon\Carbon created_at
* @property \Carbon\Carbon updated_at

View File

@@ -17,8 +17,8 @@ use App\Repositories\AircraftRepository;
use App\Repositories\SubfleetRepository;
use App\Support\Units\Time;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use function is_array;
use Log;
/**
* Class UserService
@@ -258,7 +258,12 @@ class UserService extends Service
return $user;
}
$pilot_hours = new Time($user->flight_time);
// If we should count their transfer hours?
if (setting('pilots.count_transfer_hours') === true) {
$pilot_hours = new Time($user->flight_time + $user->transfer_time);
} else {
$pilot_hours = new Time($user->flight_time);
}
// The current rank's hours are over the pilot's current hours,
// so assume that they were "placed" here by an admin so don't

View File

@@ -179,11 +179,10 @@ class VersionService extends Service
$current_version = $this->cleanVersionString($current_version);
}
$current_version = Version::fromString($current_version);
$latest_version = Version::fromString($this->getLatestVersion());
$latest_version = $this->getLatestVersion();
// Convert to semver
if ($latest_version->isGreaterThan($current_version)) {
if ($this->isGreaterThan($latest_version, $current_version)) {
$this->kvpRepo->save('new_version_available', true);
return true;
}
@@ -191,4 +190,17 @@ class VersionService extends Service
$this->kvpRepo->save('new_version_available', false);
return false;
}
/**
* @param string $version1
* @param string $version2
*
* @return bool If $version1 is greater than $version2
*/
public function isGreaterThan($version1, $version2): bool
{
$version1 = Version::fromString($version1);
$version2 = Version::fromString($version2);
return $version1->isGreaterThan($version2);
}
}