Post fares/expenses on PIREP to Airline journal #130
This commit is contained in:
@@ -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'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Expense extends BaseModel
|
||||
'active' => 'boolean',
|
||||
'airline_id' => 'integer',
|
||||
'amount' => 'float',
|
||||
'multiplier' => 'integer',
|
||||
'multiplier' => 'bool',
|
||||
'type' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
39
app/Models/Traits/JournalTrait.php
Normal file
39
app/Models/Traits/JournalTrait.php
Normal 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.');
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user