* Fix rank importing with PIREP pay #443 * Import ledger information #443 * Uncomment out testing importers * Import expense log and settings #443 * Formatting
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Importer\Services\Importers;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use App\Services\FinanceService;
|
||||
use App\Support\Money;
|
||||
use Modules\Importer\Services\BaseImporter;
|
||||
|
||||
class LedgerImporter extends BaseImporter
|
||||
{
|
||||
protected $table = 'ledger';
|
||||
|
||||
/**
|
||||
* Legacy ID to the current ledger ref_model mapping
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $legacy_paysource = [
|
||||
1 => 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 * 100);
|
||||
$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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user