Post fares/expenses on PIREP to Airline journal #130

This commit is contained in:
Nabeel Shahzad
2018-03-01 16:20:13 -06:00
parent f1b9ea94dc
commit 2c52a2f7e6
22 changed files with 625 additions and 85 deletions

View File

@@ -2,12 +2,16 @@
namespace App\Models;
use App\Models\Traits\JournalTrait;
/**
* Class Airline
* @package App\Models
*/
class Airline extends BaseModel
{
use JournalTrait;
public $table = 'airlines';
public $fillable = [
@@ -68,5 +72,12 @@ class Airline extends BaseModel
$model->icao = strtoupper($model->icao);
}
});
/**
* Make sure a new journal object is created
*/
static::created(function(Airline $model) {
$model->initJournal(config('phpvms.currency'));
});
}
}

View File

@@ -23,7 +23,7 @@ class Expense extends BaseModel
'active' => 'boolean',
'airline_id' => 'integer',
'amount' => 'float',
'multiplier' => 'integer',
'multiplier' => 'bool',
'type' => 'integer',
];

View File

@@ -13,6 +13,13 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/**
* Class Pirep
*
* @property integer airline_id
* @property Airline airline
* @property Airport arr_airport
* @property Airport dep_airport
* @property mixed flight_number
* @property mixed route_code
* @property mixed route_leg
* @package App\Models
*/
class Pirep extends BaseModel

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models\Traits;
use App\Models\Journal;
trait JournalTrait
{
/**
* Morph to Journal.
*
* @return mixed
*/
public function journal()
{
return $this->morphOne(Journal::class, 'morphed');
}
/**
* Initialize a journal for a given model object
*
* @param string $currency_code
* @return Journal
* @throws \Exception
*/
public function initJournal($currency_code = 'USD')
{
if (!$this->journal) {
$journal = new Journal();
$journal->currency = $currency_code;
$journal->balance = 0;
$this->journal()->save($journal);
$journal->refresh();
return $journal;
}
throw new \Exception('Journal already exists.');
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Models\Enums\PirepState;
use App\Models\Traits\JournalTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laratrust\Traits\LaratrustUserTrait;
@@ -23,9 +24,9 @@ use Laratrust\Traits\LaratrustUserTrait;
*/
class User extends Authenticatable
{
use Notifiable;
use JournalTrait;
use LaratrustUserTrait;
//use SoftDeletes;
use Notifiable;
public $table = 'users';