diff --git a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php index 3628407a..5a7024bd 100644 --- a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php +++ b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php @@ -16,6 +16,7 @@ class CreateExpensesTable extends Migration $table->string('name'); $table->unsignedInteger('amount'); $table->unsignedTinyInteger('type'); + $table->boolean('charge_to_user')->nullable()->default(false); $table->boolean('multiplier')->nullable()->default(0); $table->boolean('active')->nullable()->default(true); diff --git a/app/Listeners/ExpenseListener.php b/app/Listeners/ExpenseListener.php index 5360b6c4..e63cfcd1 100644 --- a/app/Listeners/ExpenseListener.php +++ b/app/Listeners/ExpenseListener.php @@ -24,6 +24,7 @@ class ExpenseListener 'type' => ExpenseType::FLIGHT, 'amount' => 15000, # $150 'transaction_group' => '', + 'charge_to_user' => true|false ]);*/ return $expenses; diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 27301a8b..9dca8737 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -18,17 +18,19 @@ class Expense extends BaseModel 'amount', 'type', 'multiplier', + 'charge_to_user', 'ref_class', 'ref_class_id', 'active', ]; public static $rules = [ - 'active' => 'boolean', - 'airline_id' => 'integer', - 'amount' => 'float', - 'multiplier' => 'bool', - 'type' => 'integer', + 'active' => 'boolean', + 'airline_id' => 'integer', + 'amount' => 'float', + 'type' => 'integer', + 'multiplier' => 'bool', + 'charge_to_user' => 'bool', ]; /** diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index 2eb9e73d..e45012ef 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -173,8 +173,16 @@ class PirepFinanceService extends BaseService } $debit = Money::createFromAmount($expense->amount); + + # If the expense is marked to charge it to a user (only applicable to Flight) + # then change the journal to the user's to debit there + $journal = $pirep->airline->journal; + if ($expense->charge_to_user) { + $journal = $pirep->user->journal; + } + $this->journalRepo->post( - $pirep->airline->journal, + $journal, null, $debit, $pirep,