<% content_for :title, "Import Preview" %> <%= render "shared/aircraft_header", aircraft: @aircraft %> <% rows = @import.rows %> <% problems = rows.select { _1.status.in?(%i[error warning]) } %> <% last = @import.last_reading %>

Preview: <%= @filename %>

Columns found: <%= @import.columns.keys.map { _1.to_s.humanize }.join(", ") %>
<%= @import.importable.size %>
flights to import
<%= hours(@import.total_tach_hours) %>
tach hours
<%= @import.count(:warning) %>
warnings (imported)
<%= @import.count(:error) %>
errors (skipped)
<%= @import.count(:duplicate) %>
already imported
<% if @import.importable.any? %> <%= form_with url: confirm_aircraft_flight_import_path(@aircraft), class: "space-y-3 border-t border-slate-100 p-4", data: { turbo_confirm: "Import #{@import.importable.size} flights?" } do |f| %> <%= hidden_field_tag :token, @token %> <%= hidden_field_tag :filename, @filename %> <%= hidden_field_tag :starting_tach, @starting_tach %> <%= hidden_field_tag :starting_hobbs, @starting_hobbs %> <% if last && last.tach_in > @aircraft.tach_time %> <% elsif last %>

The aircraft's tach (<%= hours(@aircraft.tach_time) %>) is already at or past the last reading (<%= hours(last.tach_in) %>), so its hours won't change.

<% end %>
<%= f.submit "Import #{@import.importable.size} Flights", class: "btn-primary" %> <%= link_to "Upload a different file", new_aircraft_flight_import_path(@aircraft), class: "btn-secondary" %>
<% if @import.count(:error) > 0 %>

Rows with errors are skipped. The next good row absorbs their time, so total hours stay correct. To include them, fix the spreadsheet and upload it again. Rows already imported are skipped automatically.

<% end %> <% end %> <% else %>

Nothing to import. <%= link_to "Upload a different file", new_aircraft_flight_import_path(@aircraft), class: "link" %>

<% end %>
<% if problems.any? %>

Rows needing attention

<% problems.each do |r| %> <% end %>
RowDateRouteTachIssue
<%= r.line %><%= r.date || "—" %> <%= [r.from, r.to].compact.join(" → ") %><%= r.tach_in %> <%= tag.span(r.status == :error ? "Skipped" : "Warning", class: r.status == :error ? "badge-red" : "badge-orange") %> <%= r.messages.join("; ") %>
<% end %>
All <%= rows.size %> rows
<% rows.each do |r| %> <% end %>
RowDateFromToTachTach hrsHobbsHobbs hrsOilFuel
<%= r.line %><%= r.date %><%= r.from %><%= r.to %> <%= r.tach_in %><%= hours(r.tach_time) if r.tach_time %> <%= r.hobbs_in %><%= hours(r.hobbs_time) if r.hobbs_time %> <%= r.oil %><%= r.fuel %> <%= { ok: "", warning: tag.span("warning", class: "badge-orange"), error: tag.span("skipped", class: "badge-red"), duplicate: tag.span("duplicate", class: "badge-gray") }[r.status] %>