diff --git a/app/Services/LegacyImporter/LedgerImporter.php b/app/Services/LegacyImporter/LedgerImporter.php deleted file mode 100644 index c04f54296..000000000 --- a/app/Services/LegacyImporter/LedgerImporter.php +++ /dev/null @@ -1,74 +0,0 @@ - Pirep::class, - ]; - - /** - * {@inheritdoc} - * - * @throws \Prettus\Validator\Exceptions\ValidatorException - */ - public function run($start = 0) - { - if (!$this->db->tableExists('ledger')) { - return; - } - - $this->comment('--- LEDGER IMPORT ---'); - - /** @var FinanceService $financeSvc */ - $financeSvc = app(FinanceService::class); - - $count = 0; - $rows = $this->db->readRows($this->table, $this->idField, $start); - foreach ($rows as $row) { - $pirep = Pirep::find($this->idMapper->getMapping('pireps', $row->pirepid)); - if (!$pirep) { - continue; - } - - $pilot_pay = Money::createFromAmount($row->amount); - $memo = 'Pilot payment'; - - $financeSvc->debitFromJournal( - $pirep->airline->journal, - $pilot_pay, - $pirep, - $memo, - 'Pilot Pay', - 'pilot_pay', - $row->submitdate - ); - - $financeSvc->creditToJournal( - $pirep->user->journal, - $pilot_pay, - $pirep, - $memo, - 'Pilot Pay', - 'pilot_pay', - $row->submitdate - ); - - $count++; - } - - $this->info('Imported '.$count.' ledger entries'); - } -} diff --git a/app/Services/LegacyImporter/PirepImporter.php b/app/Services/LegacyImporter/PirepImporter.php index 7678a0310..174fa7625 100644 --- a/app/Services/LegacyImporter/PirepImporter.php +++ b/app/Services/LegacyImporter/PirepImporter.php @@ -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 @@ -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); @@ -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' + ); } } diff --git a/app/Services/LegacyImporterService.php b/app/Services/LegacyImporterService.php index 0f9296c8d..2c8dde365 100644 --- a/app/Services/LegacyImporterService.php +++ b/app/Services/LegacyImporterService.php @@ -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; @@ -45,7 +44,6 @@ class LegacyImporterService extends Service UserImport::class, PirepImporter::class, ExpenseImporter::class, - LedgerImporter::class, SettingsImporter::class, FinalizeImporter::class, ];