Skip to content

Commit

Permalink
Improve pilot pay import from v5 (#1801)
Browse files Browse the repository at this point in the history
* Improve pilot pay import from v5

* Apply fixes from StyleCI

---------

Co-authored-by: arthurpar06 <arthurpar06@users.noreply.github.com>
  • Loading branch information
arthurpar06 and arthurpar06 authored May 1, 2024
1 parent 8554a3b commit 2040c99
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 78 deletions.
74 changes: 0 additions & 74 deletions app/Services/LegacyImporter/LedgerImporter.php

This file was deleted.

30 changes: 28 additions & 2 deletions app/Services/LegacyImporter/PirepImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function run($start = 0)
'fuelprice',
'expenses',
'gross',
'pilotpay',
];

// See if there's a flightlevel column, export that if there is
Expand Down Expand Up @@ -131,6 +132,14 @@ public function run($start = 0)
// TODO: Add extra fields in as PIREP fields
$this->idMapper->addMapping('pireps', $row->pirepid, $pirep->id);

if ($pirep->wasRecentlyCreated) {
$count++;
}

if (!$pirep->airline || !$pirep->airline->journal) {
continue;
}

// Some financial imports
if ($row->fuelprice && $row->fuelprice != 0) {
$fuel_price = Money::createFromAmount($row->fuelprice);
Expand Down Expand Up @@ -168,8 +177,25 @@ public function run($start = 0)
);
}

if ($pirep->wasRecentlyCreated) {
$count++;
if ($row->pilotpay && $row->pilotpay != 0) {
$pilot_pay = Money::createFromAmount($row->pilotpay * $duration / 60);
$financeSvc->debitFromJournal(
$pirep->airline->journal,
$pilot_pay,
$pirep,
'Pilot payment',
'Pilot Pay',
'pilot_pay'
);

$financeSvc->creditToJournal(
$pirep->user->journal,
$pilot_pay,
$pirep,
'Pilot payment',
'Pilot Pay',
'pilot_pay'
);
}
}

Expand Down
2 changes: 0 additions & 2 deletions app/Services/LegacyImporterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use App\Services\LegacyImporter\FinalizeImporter;
use App\Services\LegacyImporter\FlightImporter;
use App\Services\LegacyImporter\GroupImporter;
use App\Services\LegacyImporter\LedgerImporter;
use App\Services\LegacyImporter\PirepImporter;
use App\Services\LegacyImporter\RankImport;
use App\Services\LegacyImporter\SettingsImporter;
Expand Down Expand Up @@ -45,7 +44,6 @@ class LegacyImporterService extends Service
UserImport::class,
PirepImporter::class,
ExpenseImporter::class,
LedgerImporter::class,
SettingsImporter::class,
FinalizeImporter::class,
];
Expand Down

0 comments on commit 2040c99

Please sign in to comment.