* 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:
48
modules/Importer/Services/Importers/ExpenseImporter.php
Normal file
48
modules/Importer/Services/Importers/ExpenseImporter.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Importer\Services\Importers;
|
||||
|
||||
use App\Models\Enums\ExpenseType;
|
||||
use App\Models\Expense;
|
||||
use Modules\Importer\Services\BaseImporter;
|
||||
|
||||
class ExpenseImporter extends BaseImporter
|
||||
{
|
||||
protected $table = 'expenses';
|
||||
|
||||
private $expense_types = [
|
||||
'M' => ExpenseType::MONTHLY,
|
||||
'F' => ExpenseType::FLIGHT,
|
||||
'P' => ExpenseType::MONTHLY, // percent, monthly
|
||||
'G' => ExpenseType::FLIGHT, // percent, per-flight
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run($start = 0)
|
||||
{
|
||||
$this->comment('--- EXPENSES IMPORT ---');
|
||||
|
||||
$count = 0;
|
||||
$rows = $this->db->readRows($this->table, $this->idField, $start);
|
||||
foreach ($rows as $row) {
|
||||
$attrs = [
|
||||
'airline_id' => null,
|
||||
'name' => $row->name,
|
||||
'amount' => $row->amount,
|
||||
'type' => $this->expense_types[$row->type],
|
||||
'active' => 1,
|
||||
'ref_model' => Expense::class,
|
||||
];
|
||||
|
||||
$expense = Expense::updateOrCreate(['name' => $row->name], $attrs);
|
||||
$this->idMapper->addMapping('expenses', $row->id, $expense->id);
|
||||
$this->idMapper->addMapping('expenses', $row->name, $expense->id);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$this->info('Imported '.$count.' expenses');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user