diff --git a/app/Console/Commands/PirepExport.php b/app/Console/Commands/PirepExport.php new file mode 100644 index 00000000..637079b5 --- /dev/null +++ b/app/Console/Commands/PirepExport.php @@ -0,0 +1,52 @@ +argument('id'); + if (empty($pirep_id)) { + $this->error('No PIREP ID specified'); + exit(); + } + + // List the tables to export and the column name for the pirep id + $tables = [ + 'pireps' => 'id', + 'acars' => 'pirep_id', + 'pirep_comments' => 'pirep_id', + 'pirep_fares' => 'pirep_id', + 'pirep_field_values' => 'pirep_id', + 'expenses' => 'ref_model_id', + 'journal_transactions' => 'ref_model_id', + ]; + + $export_tables = []; + foreach ($tables as $table => $key) { + $export_tables[$table] = []; + + $rows = DB::table($table) + ->where($key, '=', $pirep_id) + ->get(); + + foreach ($rows as $row) { + $export_tables[$table][] = (array) $row; + } + } + + $yaml = Yaml::dump($export_tables, 4, 2); + echo $yaml; + } +}