Fix types and codes import

This commit is contained in:
Nabeel Shahzad
2018-03-22 19:59:35 -05:00
parent 112a72ac6f
commit 8b53ca2fdc
5 changed files with 47 additions and 4 deletions

View File

@@ -23,4 +23,12 @@ class AircraftStatus extends Enum
AircraftStatus::SCRAPPED => 'Scrapped',
AircraftStatus::WRITTEN_OFF => 'Written Off',
];
public static $codes = [
'S' => AircraftStatus::STORED,
'A' => AircraftStatus::ACTIVE,
'R' => AircraftStatus::RETIRED,
'C' => AircraftStatus::SCRAPPED,
'W' => AircraftStatus::WRITTEN_OFF,
];
}

View File

@@ -4,6 +4,7 @@ namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Aircraft;
use App\Models\Enums\AircraftStatus;
use App\Models\Flight;
/**
@@ -36,6 +37,7 @@ class AircraftExporter extends ImportExport
}
# Modify special fields
$ret['status'] = AircraftStatus::convertToCode($aircraft->status);
$ret['subfleet'] = $aircraft->subfleet->type;
return $ret;

View File

@@ -60,8 +60,11 @@ class AircraftImporter extends ImportExport
}
# Set a default status
if($row['status'] === null) {
$row['status'] = trim($row['status']);
if($row['status'] === null || $row['status'] === '') {
$row['status'] = AircraftStatus::ACTIVE;
} else {
$row['status'] = AircraftStatus::getFromCode($row['status']);
}
# Just set its state right now as parked

View File

@@ -50,6 +50,9 @@ class ExpenseImporter extends ImportExport
$row = $this->getRefClassInfo($row);
$row['type'] = ExpenseType::getFromCode($row['type']);
if(!$row['active']) {
$row['active'] = true;
}
$expense = Expense::firstOrNew([
'name' => $row['name'],

View File

@@ -3,6 +3,7 @@
namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Airport;
use App\Models\Enums\FlightType;
use App\Models\Fare;
use App\Models\Flight;
@@ -29,9 +30,9 @@ class FlightImporter extends ImportExport
'flight_number',
'route_code',
'route_leg',
'dpt_airport_id',
'arr_airport_id',
'alt_airport_id',
'dpt_airport',
'arr_airport',
'alt_airport',
'days',
'dpt_time',
'arr_time',
@@ -81,6 +82,13 @@ class FlightImporter extends ImportExport
'route_leg' => $row['route_leg'],
], $row);
// Airport atttributes
$flight->setAttribute('dpt_airport_id', $row['dpt_airport']);
$flight->setAttribute('arr_airport_id', $row['arr_airport']);
if ($row['alt_airport']) {
$flight->setAttribute('alt_airport_id', $row['alt_airport']);
}
// Any specific transformations
// Flight type can be set to P - Passenger, C - Cargo, or H - Charter
$flight->setAttribute('flight_type', FlightType::getFromCode($row['flight_type']));
@@ -93,6 +101,13 @@ class FlightImporter extends ImportExport
return false;
}
// Create/check that they exist
$this->processAirport($row['dpt_airport']);
$this->processAirport($row['arr_airport']);
if ($row['alt_airport']) {
$this->processAirport($row['alt_airport']);
}
$this->processSubfleets($flight, $row['subfleets']);
$this->processFares($flight, $row['fares']);
$this->processFields($flight, $row['fields']);
@@ -101,6 +116,18 @@ class FlightImporter extends ImportExport
return true;
}
/**
* Process the airport
* @param $airport
* @return \Illuminate\Database\Eloquent\Model
*/
protected function processAirport($airport)
{
return Airport::firstOrCreate([
'icao' => $airport,
], ['name' => $airport]);
}
/**
* Parse out all of the subfleets and associate them to the flight
* The subfleet is created if it doesn't exist