Convert expense type to char, translations for ExpenseType
This commit is contained in:
@@ -14,7 +14,7 @@ class ActiveState extends Enum
|
||||
public const ACTIVE = 1;
|
||||
|
||||
public static $labels = [
|
||||
ActiveState::INACTIVE => 'Inactive',
|
||||
ActiveState::ACTIVE => 'Active',
|
||||
ActiveState::ACTIVE => 'system.global.active',
|
||||
ActiveState::INACTIVE => 'system.global.inactive',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ use App\Interfaces\Enum;
|
||||
*/
|
||||
class ExpenseType extends Enum
|
||||
{
|
||||
public const FLIGHT = 0;
|
||||
public const DAILY = 1;
|
||||
public const MONTHLY = 2;
|
||||
public const FLIGHT = 'F';
|
||||
public const DAILY = 'D';
|
||||
public const MONTHLY = 'M';
|
||||
|
||||
protected static $labels = [
|
||||
ExpenseType::FLIGHT => 'Flight',
|
||||
ExpenseType::DAILY => 'Daily',
|
||||
ExpenseType::MONTHLY => 'Monthly',
|
||||
ExpenseType::FLIGHT => 'system.expenses.type.flight',
|
||||
ExpenseType::DAILY => 'system.expenses.type.daily',
|
||||
ExpenseType::MONTHLY => 'system.expenses.type.monthly',
|
||||
];
|
||||
|
||||
protected static $codes = [
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
use App\Interfaces\Model;
|
||||
use App\Models\Traits\ReferenceTrait;
|
||||
|
||||
/**
|
||||
* Class Expense
|
||||
@@ -14,6 +15,8 @@ use App\Interfaces\Model;
|
||||
*/
|
||||
class Expense extends Model
|
||||
{
|
||||
use ReferenceTrait;
|
||||
|
||||
public $table = 'expenses';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -32,33 +35,10 @@ class Expense extends Model
|
||||
'active' => 'boolean',
|
||||
'airline_id' => 'integer',
|
||||
'amount' => 'float',
|
||||
'type' => 'integer',
|
||||
'multiplier' => 'bool',
|
||||
'charge_to_user' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the referring object
|
||||
*/
|
||||
public function getReference()
|
||||
{
|
||||
if (!$this->ref_model || !$this->ref_model_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->ref_model === __CLASS__) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
try {
|
||||
$klass = new $this->ref_model;
|
||||
|
||||
return $klass->find($this->ref_model_id);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign Keys
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Models\Traits;
|
||||
/**
|
||||
* Trait ReferenceTrait
|
||||
* @property \App\Interfaces\Model $ref_model
|
||||
* @property mixed $ref_model_id
|
||||
* @property mixed $ref_model_id
|
||||
* @package App\Models\Traits
|
||||
*/
|
||||
trait ReferenceTrait
|
||||
@@ -29,12 +29,20 @@ trait ReferenceTrait
|
||||
*/
|
||||
public function getReferencedObject()
|
||||
{
|
||||
if ($classname = $this->ref_model) {
|
||||
$klass = new $this->ref_model;
|
||||
|
||||
return $klass->find($this->ref_model_id);
|
||||
if (!$this->ref_model || !$this->ref_model_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
if ($this->ref_model === __CLASS__) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
try {
|
||||
$klass = new $this->ref_model;
|
||||
$obj = $klass->find($this->ref_model_id);
|
||||
return $obj;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user