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

@@ -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.');
}
}