Add fare import/exporter #194

This commit is contained in:
Nabeel Shahzad
2018-03-22 17:48:57 -05:00
parent a44204b185
commit 46d8fb125a
17 changed files with 322 additions and 58 deletions

View File

@@ -3,7 +3,9 @@
namespace App\Services\ImportExport;
use App\Interfaces\ImportExport;
use App\Models\Fare;
use App\Models\Subfleet;
use App\Services\FareService;
/**
* Import subfleets
@@ -21,8 +23,19 @@ class SubfleetImporter extends ImportExport
'airline',
'type',
'name',
'fares',
];
private $fareSvc;
/**
* FlightImportExporter constructor.
*/
public function __construct()
{
$this->fareSvc = app(FareService::class);
}
/**
* Import a flight, parse out the different rows
* @param array $row
@@ -45,7 +58,28 @@ class SubfleetImporter extends ImportExport
return false;
}
$this->processFares($subfleet, $row['fares']);
$this->log('Imported '.$row['type']);
return true;
}
/**
* Parse all of the fares in the multi-format
* @param Subfleet $subfleet
* @param $col
*/
protected function processFares(Subfleet &$subfleet, $col): void
{
$fares = $this->parseMultiColumnValues($col);
foreach ($fares as $fare_code => $fare_attributes) {
if (\is_int($fare_code)) {
$fare_code = $fare_attributes;
$fare_attributes = [];
}
$fare = Fare::firstOrCreate(['code' => $fare_code], ['name' => $fare_code]);
$this->fareSvc->setForSubfleet($subfleet, $fare, $fare_attributes);
}
}
}