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

@@ -10,6 +10,7 @@ use App\Repositories\FlightRepository;
use App\Services\ImportExport\AircraftImporter;
use App\Services\ImportExport\AirportImporter;
use App\Services\ImportExport\ExpenseImporter;
use App\Services\ImportExport\FareImporter;
use App\Services\ImportExport\FlightImporter;
use App\Services\ImportExport\SubfleetImporter;
use Illuminate\Validation\ValidationException;
@@ -112,7 +113,6 @@ class ImportService extends Service
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws \League\Csv\Exception
* @throws ValidationException
*/
public function importAircraft($csv_file, bool $delete_previous = true)
@@ -135,7 +135,7 @@ class ImportService extends Service
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws \League\Csv\Exception
* @throws ValidationException
*/
public function importAirports($csv_file, bool $delete_previous = true)
{
@@ -157,7 +157,7 @@ class ImportService extends Service
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws \League\Csv\Exception
* @throws ValidationException
*/
public function importExpenses($csv_file, bool $delete_previous = true)
{
@@ -174,12 +174,35 @@ class ImportService extends Service
return $this->runImport($reader, $importer);
}
/**
* Import fares
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws ValidationException
*/
public function importFares($csv_file, bool $delete_previous = true)
{
if ($delete_previous) {
# TODO: Delete all from: fares
}
$reader = $this->openCsv($csv_file);
if (!$reader) {
# TODO: Throw an error
return false;
}
$importer = new FareImporter();
return $this->runImport($reader, $importer);
}
/**
* Import flights
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws \League\Csv\Exception
* @throws ValidationException
*/
public function importFlights($csv_file, bool $delete_previous = true)
{
@@ -202,7 +225,7 @@ class ImportService extends Service
* @param string $csv_file
* @param bool $delete_previous
* @return mixed
* @throws \League\Csv\Exception
* @throws ValidationException
*/
public function importSubfleets($csv_file, bool $delete_previous = true)
{