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