Convert expense type to char, translations for ExpenseType
This commit is contained in:
@@ -14,7 +14,7 @@ class CreateExpensesTable extends Migration
|
|||||||
|
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->unsignedInteger('amount');
|
$table->unsignedInteger('amount');
|
||||||
$table->unsignedTinyInteger('type');
|
$table->char('type');
|
||||||
$table->boolean('charge_to_user')->nullable()->default(false);
|
$table->boolean('charge_to_user')->nullable()->default(false);
|
||||||
$table->boolean('multiplier')->nullable()->default(0);
|
$table->boolean('multiplier')->nullable()->default(0);
|
||||||
$table->boolean('active')->nullable()->default(true);
|
$table->boolean('active')->nullable()->default(true);
|
||||||
|
|||||||
@@ -192,35 +192,35 @@ aircraft:
|
|||||||
expenses:
|
expenses:
|
||||||
- name: Per-Flight (no muliplier)
|
- name: Per-Flight (no muliplier)
|
||||||
amount: 100
|
amount: 100
|
||||||
type: 0
|
type: F
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Expense
|
ref_model: App\Models\Expense
|
||||||
- name: Per-Flight (multiplier)
|
- name: Per-Flight (multiplier)
|
||||||
amount: 100
|
amount: 100
|
||||||
type: 0
|
type: F
|
||||||
multiplier: 1
|
multiplier: 1
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Expense
|
ref_model: App\Models\Expense
|
||||||
- name: Per-Flight (multiplier, on airline)
|
- name: Per-Flight (multiplier, on airline)
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
amount: 200
|
amount: 200
|
||||||
type: 0
|
type: F
|
||||||
multiplier: 1
|
multiplier: 1
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Expense
|
ref_model: App\Models\Expense
|
||||||
- name: A daily fee
|
- name: A daily fee
|
||||||
amount: 800
|
amount: 800
|
||||||
type: 1
|
type: D
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Expense
|
ref_model: App\Models\Expense
|
||||||
- name: A monthly fee
|
- name: A monthly fee
|
||||||
amount: 5000
|
amount: 5000
|
||||||
type: 2
|
type: M
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Expense
|
ref_model: App\Models\Expense
|
||||||
- name: Catering
|
- name: Catering
|
||||||
amount: 1000
|
amount: 1000
|
||||||
type: 0
|
type: F
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Subfleet
|
ref_model: App\Models\Subfleet
|
||||||
ref_model_id: 1
|
ref_model_id: 1
|
||||||
@@ -228,7 +228,7 @@ expenses:
|
|||||||
updated_at: now
|
updated_at: now
|
||||||
- name: Catering Staff
|
- name: Catering Staff
|
||||||
amount: 1000
|
amount: 1000
|
||||||
type: 1
|
type: D
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Subfleet
|
ref_model: App\Models\Subfleet
|
||||||
ref_model_id: 1
|
ref_model_id: 1
|
||||||
@@ -236,7 +236,7 @@ expenses:
|
|||||||
updated_at: now
|
updated_at: now
|
||||||
- name: Maintenance
|
- name: Maintenance
|
||||||
amount: 1000
|
amount: 1000
|
||||||
type: 1
|
type: D
|
||||||
active: 1
|
active: 1
|
||||||
ref_model: App\Models\Aircraft
|
ref_model: App\Models\Aircraft
|
||||||
ref_model_id: 1
|
ref_model_id: 1
|
||||||
@@ -518,7 +518,7 @@ journal_transactions:
|
|||||||
debit: null
|
debit: null
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Pilot Payment @ 50'
|
memo: 'Pilot Payment @ 50'
|
||||||
tags: '"pilot_pay"'
|
tags: "pilot_pay"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -532,7 +532,7 @@ journal_transactions:
|
|||||||
debit: 10000
|
debit: 10000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Expense: Per-Flight (no muliplier)'
|
memo: 'Expense: Per-Flight (no muliplier)'
|
||||||
tags: '"expense"'
|
tags: "expense"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -546,7 +546,7 @@ journal_transactions:
|
|||||||
debit: 0
|
debit: 0
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Fares Y300; price: 200, cost: 0'
|
memo: 'Fares Y300; price: 200, cost: 0'
|
||||||
tags: '"fare"'
|
tags: "fare"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -560,7 +560,7 @@ journal_transactions:
|
|||||||
debit: 20000
|
debit: 20000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Expense: Per-Flight (multiplier, on airline)'
|
memo: 'Expense: Per-Flight (multiplier, on airline)'
|
||||||
tags: '"expense"'
|
tags: "expense"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -574,7 +574,7 @@ journal_transactions:
|
|||||||
debit: 10000
|
debit: 10000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Expense: Per-Flight (multiplier)'
|
memo: 'Expense: Per-Flight (multiplier)'
|
||||||
tags: '"expense"'
|
tags: "expense"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -588,7 +588,7 @@ journal_transactions:
|
|||||||
debit: 100000
|
debit: 100000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Subfleet Expense: Catering (747-43X RB211-524G)'
|
memo: 'Subfleet Expense: Catering (747-43X RB211-524G)'
|
||||||
tags: '"subfleet"'
|
tags: "subfleet"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -602,7 +602,7 @@ journal_transactions:
|
|||||||
debit: 0
|
debit: 0
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Fares F10; price: 1000, cost: 0'
|
memo: 'Fares F10; price: 1000, cost: 0'
|
||||||
tags: '"fare"'
|
tags: "fare"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: '2018-03-06 12:34:15'
|
created_at: '2018-03-06 12:34:15'
|
||||||
@@ -616,7 +616,7 @@ journal_transactions:
|
|||||||
debit: 15000
|
debit: 15000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Pilot Payment @ 50'
|
memo: 'Pilot Payment @ 50'
|
||||||
tags: '"pilot_pay"'
|
tags: "pilot_pay"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: now
|
created_at: now
|
||||||
@@ -630,7 +630,7 @@ journal_transactions:
|
|||||||
debit: 0
|
debit: 0
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Fares B10; price: 1100, cost: 0'
|
memo: 'Fares B10; price: 1100, cost: 0'
|
||||||
tags: '"fare"'
|
tags: "fare"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: now
|
created_at: now
|
||||||
@@ -644,7 +644,7 @@ journal_transactions:
|
|||||||
debit: 75000
|
debit: 75000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Ground Handling'
|
memo: 'Ground Handling'
|
||||||
tags: '"ground_handling"'
|
tags: "ground_handling"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: now
|
created_at: now
|
||||||
@@ -659,7 +659,7 @@ journal_transactions:
|
|||||||
debit: 300000
|
debit: 300000
|
||||||
currency: USD
|
currency: USD
|
||||||
memo: 'Subfleet 744-3X-RB211: Block Time Cost'
|
memo: 'Subfleet 744-3X-RB211: Block Time Cost'
|
||||||
tags: '"subfleet"'
|
tags: "subfleet"
|
||||||
ref_model: App\Models\Pirep
|
ref_model: App\Models\Pirep
|
||||||
ref_model_id: pirepid_1
|
ref_model_id: pirepid_1
|
||||||
created_at: now
|
created_at: now
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class ActiveState extends Enum
|
|||||||
public const ACTIVE = 1;
|
public const ACTIVE = 1;
|
||||||
|
|
||||||
public static $labels = [
|
public static $labels = [
|
||||||
ActiveState::INACTIVE => 'Inactive',
|
ActiveState::ACTIVE => 'system.global.active',
|
||||||
ActiveState::ACTIVE => 'Active',
|
ActiveState::INACTIVE => 'system.global.inactive',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ use App\Interfaces\Enum;
|
|||||||
*/
|
*/
|
||||||
class ExpenseType extends Enum
|
class ExpenseType extends Enum
|
||||||
{
|
{
|
||||||
public const FLIGHT = 0;
|
public const FLIGHT = 'F';
|
||||||
public const DAILY = 1;
|
public const DAILY = 'D';
|
||||||
public const MONTHLY = 2;
|
public const MONTHLY = 'M';
|
||||||
|
|
||||||
protected static $labels = [
|
protected static $labels = [
|
||||||
ExpenseType::FLIGHT => 'Flight',
|
ExpenseType::FLIGHT => 'system.expenses.type.flight',
|
||||||
ExpenseType::DAILY => 'Daily',
|
ExpenseType::DAILY => 'system.expenses.type.daily',
|
||||||
ExpenseType::MONTHLY => 'Monthly',
|
ExpenseType::MONTHLY => 'system.expenses.type.monthly',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static $codes = [
|
protected static $codes = [
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
use App\Interfaces\Model;
|
use App\Interfaces\Model;
|
||||||
|
use App\Models\Traits\ReferenceTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Expense
|
* Class Expense
|
||||||
@@ -14,6 +15,8 @@ use App\Interfaces\Model;
|
|||||||
*/
|
*/
|
||||||
class Expense extends Model
|
class Expense extends Model
|
||||||
{
|
{
|
||||||
|
use ReferenceTrait;
|
||||||
|
|
||||||
public $table = 'expenses';
|
public $table = 'expenses';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
@@ -32,33 +35,10 @@ class Expense extends Model
|
|||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
'airline_id' => 'integer',
|
'airline_id' => 'integer',
|
||||||
'amount' => 'float',
|
'amount' => 'float',
|
||||||
'type' => 'integer',
|
|
||||||
'multiplier' => 'bool',
|
'multiplier' => 'bool',
|
||||||
'charge_to_user' => '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
|
* Foreign Keys
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace App\Models\Traits;
|
|||||||
/**
|
/**
|
||||||
* Trait ReferenceTrait
|
* Trait ReferenceTrait
|
||||||
* @property \App\Interfaces\Model $ref_model
|
* @property \App\Interfaces\Model $ref_model
|
||||||
* @property mixed $ref_model_id
|
* @property mixed $ref_model_id
|
||||||
* @package App\Models\Traits
|
* @package App\Models\Traits
|
||||||
*/
|
*/
|
||||||
trait ReferenceTrait
|
trait ReferenceTrait
|
||||||
@@ -29,12 +29,20 @@ trait ReferenceTrait
|
|||||||
*/
|
*/
|
||||||
public function getReferencedObject()
|
public function getReferencedObject()
|
||||||
{
|
{
|
||||||
if ($classname = $this->ref_model) {
|
if (!$this->ref_model || !$this->ref_model_id) {
|
||||||
$klass = new $this->ref_model;
|
return null;
|
||||||
|
|
||||||
return $klass->find($this->ref_model_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,15 @@ class ExpenseRepository extends Repository implements CacheableInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($ref_model) {
|
if ($ref_model) {
|
||||||
$where['ref_model'] = $ref_model;
|
if (\is_object($ref_model)) {
|
||||||
|
$ref_model_type = \get_class($ref_model);
|
||||||
|
} else {
|
||||||
|
$ref_model_type = $ref_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ref_model) {
|
||||||
|
$where['ref_model'] = $ref_model_type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$expenses = $this->findWhere($where);
|
$expenses = $this->findWhere($where);
|
||||||
@@ -49,7 +57,7 @@ class ExpenseRepository extends Repository implements CacheableInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($ref_model) {
|
if ($ref_model) {
|
||||||
$where['ref_model'] = $ref_model;
|
$where['ref_model'] = $ref_model_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
$airline_expenses = $this->findWhere($where);
|
$airline_expenses = $this->findWhere($where);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class RecurringFinanceService extends Service
|
|||||||
if ($expense->ref_model) {
|
if ($expense->ref_model) {
|
||||||
$ref = explode('\\', $expense->ref_model);
|
$ref = explode('\\', $expense->ref_model);
|
||||||
$klass = end($ref);
|
$klass = end($ref);
|
||||||
$obj = $expense->getReference();
|
$obj = $expense->getReferencedObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($klass === 'Airport') {
|
if ($klass === 'Airport') {
|
||||||
|
|||||||
@@ -44,15 +44,13 @@ class ExpenseExporter extends ImportExport
|
|||||||
$ret['airline'] = $expense->airline->icao;
|
$ret['airline'] = $expense->airline->icao;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret['type'] = ExpenseType::convertToCode($ret['type']);
|
|
||||||
|
|
||||||
// For the different expense types, instead of exporting
|
// For the different expense types, instead of exporting
|
||||||
// the ID, export a specific column
|
// the ID, export a specific column
|
||||||
if ($expense->ref_model === Expense::class) {
|
if ($expense->ref_model === Expense::class) {
|
||||||
$ret['ref_model'] = '';
|
$ret['ref_model'] = '';
|
||||||
$ret['ref_model_id'] = '';
|
$ret['ref_model_id'] = '';
|
||||||
} else {
|
} else {
|
||||||
$obj = $expense->getReference();
|
$obj = $expense->getReferencedObject();
|
||||||
if(!$obj) { // bail out
|
if(!$obj) { // bail out
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class ExpenseImporter extends ImportExport
|
|||||||
# Figure out what this is referring to
|
# Figure out what this is referring to
|
||||||
$row = $this->getRefClassInfo($row);
|
$row = $this->getRefClassInfo($row);
|
||||||
|
|
||||||
$row['type'] = ExpenseType::getFromCode($row['type']);
|
|
||||||
if(!$row['active']) {
|
if(!$row['active']) {
|
||||||
$row['active'] = true;
|
$row['active'] = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
'global' => [
|
||||||
|
'active' => 'Active',
|
||||||
|
'inactive' => 'Inactive'
|
||||||
|
],
|
||||||
|
|
||||||
'aircraft' => [
|
'aircraft' => [
|
||||||
'status' => [
|
'status' => [
|
||||||
'active' => 'Active',
|
'active' => 'Active',
|
||||||
@@ -22,6 +27,14 @@ return [
|
|||||||
'sun' => 'Sunday',
|
'sun' => 'Sunday',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'expenses' => [
|
||||||
|
'type' => [
|
||||||
|
'flight' => 'Flight',
|
||||||
|
'daily' => 'Daily',
|
||||||
|
'monthly' => 'Monthly',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
'flights' => [
|
'flights' => [
|
||||||
'type' => [
|
'type' => [
|
||||||
'pass_scheduled' => 'Passenger - Scheduled',
|
'pass_scheduled' => 'Passenger - Scheduled',
|
||||||
|
|||||||
@@ -603,18 +603,25 @@ class FinanceTest extends TestCase
|
|||||||
* Test the subfleet class
|
* Test the subfleet class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||||
factory(App\Models\Expense::class)->create([
|
factory(App\Models\Expense::class)->create([
|
||||||
'airline_id' => null,
|
'airline_id' => null,
|
||||||
'ref_model' => \App\Models\Subfleet::class,
|
'ref_model' => \App\Models\Subfleet::class,
|
||||||
|
'ref_model_id' => $subfleet->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$expenses = $this->expenseRepo->getAllForType(
|
$expenses = $this->expenseRepo->getAllForType(
|
||||||
ExpenseType::FLIGHT,
|
ExpenseType::FLIGHT,
|
||||||
$airline->id,
|
$airline->id,
|
||||||
\App\Models\Subfleet::class
|
$subfleet
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertCount(1, $expenses);
|
$this->assertCount(1, $expenses);
|
||||||
|
|
||||||
|
$expense = $expenses->random();
|
||||||
|
$this->assertEquals(\App\Models\Subfleet::class, $expense->ref_model);
|
||||||
|
$obj = $expense->getReferencedObject();
|
||||||
|
$this->assertEquals($obj->id, $expense->ref_model_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user