Add cost_block_hour tests; extra logging

This commit is contained in:
Nabeel Shahzad
2018-03-29 14:55:25 -05:00
parent 2090f05236
commit 08d3578d38
5 changed files with 26 additions and 14 deletions

View File

@@ -15,8 +15,8 @@ class CreateSubfleetTables extends Migration
$table->unsignedInteger('airline_id')->nullable(); $table->unsignedInteger('airline_id')->nullable();
$table->string('type', 50)->unique(); $table->string('type', 50)->unique();
$table->string('name', 50); $table->string('name', 50);
$table->unsignedDecimal('cost_block_hour'); $table->unsignedDecimal('cost_block_hour')->default(0)->nullable();
$table->unsignedDecimal('cost_delay_minute'); $table->unsignedDecimal('cost_delay_minute')->default(0)->nullable();
$table->unsignedTinyInteger('fuel_type')->nullable(); $table->unsignedTinyInteger('fuel_type')->nullable();
$table->unsignedDecimal('ground_handling_multiplier')->nullable()->default(100); $table->unsignedDecimal('ground_handling_multiplier')->nullable()->default(100);
$table->unsignedDecimal('cargo_capacity')->nullable(); $table->unsignedDecimal('cargo_capacity')->nullable();

View File

@@ -9,6 +9,7 @@ use App\Interfaces\Model;
* @property float cost * @property float cost
* @property float price * @property float price
* @property mixed code * @property mixed code
* @property mixed count Only when merged with pivot
* @package App\Models * @package App\Models
*/ */
class Fare extends Model class Fare extends Model

View File

@@ -14,7 +14,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/** /**
* Class Pirep * Class Pirep
* * @property string id
* @property string flight_number * @property string flight_number
* @property string route_code * @property string route_code
* @property string route_leg * @property string route_leg

View File

@@ -14,7 +14,6 @@ use App\Services\FareService;
use App\Services\PirepService; use App\Services\PirepService;
use App\Support\Math; use App\Support\Math;
use App\Support\Money; use App\Support\Money;
use App\Support\Units\Time;
use Log; use Log;
/** /**
@@ -72,6 +71,8 @@ class PirepFinanceService extends Service
# Clean out the expenses first # Clean out the expenses first
$this->deleteFinancesForPirep($pirep); $this->deleteFinancesForPirep($pirep);
Log::info('Finance: Starting PIREP pay for '.$pirep->id);
# Now start and pay from scratch # Now start and pay from scratch
$this->payFaresForPirep($pirep); $this->payFaresForPirep($pirep);
$this->payExpensesForSubfleet($pirep); $this->payExpensesForSubfleet($pirep);
@@ -93,7 +94,7 @@ class PirepFinanceService extends Service
/** /**
* @param Pirep $pirep * @param Pirep $pirep
*/ */
public function deleteFinancesForPirep(Pirep $pirep) public function deleteFinancesForPirep(Pirep $pirep): void
{ {
$this->journalRepo->deleteAllForObject($pirep); $this->journalRepo->deleteAllForObject($pirep);
} }
@@ -109,13 +110,16 @@ class PirepFinanceService extends Service
public function payFaresForPirep($pirep): void public function payFaresForPirep($pirep): void
{ {
$fares = $this->getReconciledFaresForPirep($pirep); $fares = $this->getReconciledFaresForPirep($pirep);
/** @var \App\Models\Fare $fare */ /** @var \App\Models\Fare $fare */
foreach ($fares as $fare) { foreach ($fares as $fare) {
Log::info('Finance: PIREP: '.$pirep->id.', fare:', $fare->toArray()); Log::info('Finance: PIREP: '.$pirep->id.', Fare:', $fare->toArray());
$credit = Money::createFromAmount($fare->count * $fare->price); $credit = Money::createFromAmount($fare->count * $fare->price);
$debit = Money::createFromAmount($fare->count * $fare->cost); $debit = Money::createFromAmount($fare->count * $fare->cost);
Log::info('Finance: Calculate: C='.$credit->toAmount().', D='.$debit->toAmount());
$this->journalRepo->post( $this->journalRepo->post(
$pirep->airline->journal, $pirep->airline->journal,
$credit, $credit,
@@ -142,7 +146,6 @@ class PirepFinanceService extends Service
{ {
$sf = $pirep->aircraft->subfleet; $sf = $pirep->aircraft->subfleet;
Log::info('subfleet: ', $sf->toArray());
# Haven't entered a cost # Haven't entered a cost
if (!filled($sf->cost_block_hour)) { if (!filled($sf->cost_block_hour)) {
return; return;
@@ -155,10 +158,12 @@ class PirepFinanceService extends Service
# flight time if that hasn't been used # flight time if that hasn't been used
$block_time = $pirep->block_time; $block_time = $pirep->block_time;
if(!filled($block_time)) { if(!filled($block_time)) {
Log::info('Finance: No block time, using PIREP flight time');
$block_time = $pirep->flight_time; $block_time = $pirep->flight_time;
} }
$debit = Money::createFromAmount($cost_per_min * $block_time); $debit = Money::createFromAmount($cost_per_min * $block_time);
Log::info('Finance: Subfleet Block Hourly, D='.$debit->getAmount());
$this->journalRepo->post( $this->journalRepo->post(
$pirep->airline->journal, $pirep->airline->journal,
@@ -175,7 +180,6 @@ class PirepFinanceService extends Service
/** /**
* Collect all of the expenses and apply those to the journal * Collect all of the expenses and apply those to the journal
* @param Pirep $pirep * @param Pirep $pirep
* @throws \Prettus\Validator\Exceptions\ValidatorException
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
@@ -271,8 +275,12 @@ class PirepFinanceService extends Service
continue; continue;
} }
Log::info('Finance: Expense from listener, N="'
.$expense->name.'", A='.$expense->amount);
# If an airline_id is filled, then see if it matches # If an airline_id is filled, then see if it matches
if ($expense->airline_id !== $pirep->airline_id) { if(filled($expense->airline_id) && $expense->airline_id !== $pirep->airline_id) {
Log::info('Finance: Expense has an airline ID and it doesn\'t match, skipping');
continue; continue;
} }
@@ -299,7 +307,7 @@ class PirepFinanceService extends Service
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \Prettus\Validator\Exceptions\ValidatorException * @throws \Prettus\Validator\Exceptions\ValidatorException
*/ */
public function payGroundHandlingForPirep(Pirep $pirep) public function payGroundHandlingForPirep(Pirep $pirep): void
{ {
$ground_handling_cost = $this->getGroundHandlingCost($pirep); $ground_handling_cost = $this->getGroundHandlingCost($pirep);
Log::info('Finance: PIREP: '.$pirep->id.'; ground handling: '.$ground_handling_cost); Log::info('Finance: PIREP: '.$pirep->id.'; ground handling: '.$ground_handling_cost);
@@ -323,7 +331,7 @@ class PirepFinanceService extends Service
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \Prettus\Validator\Exceptions\ValidatorException * @throws \Prettus\Validator\Exceptions\ValidatorException
*/ */
public function payPilotForPirep(Pirep $pirep) public function payPilotForPirep(Pirep $pirep): void
{ {
$pilot_pay = $this->getPilotPay($pirep); $pilot_pay = $this->getPilotPay($pirep);
$pilot_pay_rate = $this->getPilotPayRateForPirep($pirep); $pilot_pay_rate = $this->getPilotPayRateForPirep($pirep);

View File

@@ -45,6 +45,9 @@ class FinanceTest extends TestCase
* Setup tests * Setup tests
*/ */
$subfleet = $this->createSubfleetWithAircraft(2); $subfleet = $this->createSubfleetWithAircraft(2);
$subfleet['subfleet']->cost_block_hour = 10;
$subfleet['subfleet']->save();
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$rank->acars_base_pay_rate = 10; $rank->acars_base_pay_rate = 10;
$rank->save(); $rank->save();
@@ -642,15 +645,15 @@ class FinanceTest extends TestCase
$transactions = $journalRepo->getAllForObject($pirep); $transactions = $journalRepo->getAllForObject($pirep);
$this->assertCount(8, $transactions['transactions']); $this->assertCount(9, $transactions['transactions']);
$this->assertEquals(3020, $transactions['credits']->getValue()); $this->assertEquals(3020, $transactions['credits']->getValue());
$this->assertEquals(1840, $transactions['debits']->getValue()); $this->assertEquals(1860, $transactions['debits']->getValue());
# Check that all the different transaction types are there # Check that all the different transaction types are there
# test by the different groups that exist # test by the different groups that exist
$transaction_tags = [ $transaction_tags = [
'expense' => 1, 'expense' => 1,
'subfleet' => 1, 'subfleet' => 2,
'fare' => 3, 'fare' => 3,
'ground_handling' => 1, 'ground_handling' => 1,
'pilot_pay' => 2, # debit on the airline, credit to the pilot 'pilot_pay' => 2, # debit on the airline, credit to the pilot