Account for fuel in the finance calculations #313

This commit is contained in:
Nabeel Shahzad
2019-07-23 08:41:20 -04:00
parent ee1c8ee3fa
commit 62a10224a0
31 changed files with 246 additions and 89 deletions

View File

@@ -13,7 +13,7 @@ use App\Repositories\JournalRepository;
use App\Services\FareService;
use App\Support\Math;
use App\Support\Money;
use Log;
use Illuminate\Support\Facades\Log;
/**
* Class FinanceService
@@ -70,6 +70,7 @@ class PirepFinanceService extends Service
Log::info('Finance: Starting PIREP pay for '.$pirep->id);
// Now start and pay from scratch
$this->payFuelCosts($pirep);
$this->payFaresForPirep($pirep);
$this->payExpensesForSubfleet($pirep);
$this->payExpensesForPirep($pirep);
@@ -132,6 +133,34 @@ class PirepFinanceService extends Service
}
}
/**
* Calculate the fuel used by the PIREP and add those costs in
*
* @param Pirep $pirep
*
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function payFuelCosts(Pirep $pirep): void
{
$ap = $pirep->dpt_airport;
$fuel_used = $pirep->block_fuel;
$debit = Money::createFromAmount($fuel_used * $ap->fuel_jeta_cost);
Log::info('Finance: Fuel cost, (fuel='.$fuel_used.', cost='.$ap->fuel_jeta_cost.') D='
.$debit->getAmount());
$this->journalRepo->post(
$pirep->airline->journal,
null,
$debit,
$pirep,
'Fuel Cost ('.$ap->fuel_jeta_cost.'/'.config('phpvms.internal_units.fuel').')',
null,
'Fuel',
'fuel'
);
}
/**
* Calculate what the cost is for the operating an aircraft
* in this subfleet, as-per the block time

View File

@@ -37,7 +37,7 @@ class FlightExporter extends ImportExport
// Modify special fields
$ret['airline'] = $ret['airline']->icao;
$ret['distance'] = $ret['distance'][config('phpvms.internal_units.distance')];
// $ret['distance'] = $ret['distance'][config('phpvms.internal_units.distance')];
$ret['dpt_airport'] = $flight->dpt_airport_id;
$ret['arr_airport'] = $flight->arr_airport_id;

View File

@@ -28,6 +28,7 @@ class MigrationService extends Service
public function syncAllSeeds(): void
{
$this->syncAllSettings();
$this->syncAllPermissions();
}
public function syncAllSettings(): void
@@ -43,6 +44,22 @@ class MigrationService extends Service
}
}
public function syncAllPermissions(): void
{
$data = file_get_contents(database_path('/seeds/permissions.yml'));
$yml = Yaml::parse($data);
foreach ($yml as $perm) {
$count = DB::table('permissions')->where('name', $perm['name'])->count('name');
if ($count === 0) {
DB::table('permissions')->insert($perm);
} else {
DB::table('settings')
->where('name', $perm['name'])
->update($perm);
}
}
}
/**
* @param $key
* @param $attrs