lib/models/trip_leg.rb in fossil-0.3.24 vs lib/models/trip_leg.rb in fossil-0.3.25
- old
+ new
@@ -44,11 +44,11 @@
# One to many associations with composite primary keys
o_to_n :crew_legs, :class=>:CrewLeg, :prefix=>'trip leg'
o_to_n :audit_trails, :class=>:AuditTrail, :prefix=>'owner'
o_to_n :flight_log_expenses, :class=>:FlightLogExpense, :prefix=>'trip leg'
-
+
# Code associations
code_association :approval_value, :'approval code', :trip_approval
code_association :base, :'base', :location
code_association :cancellation_code, :'cancel code', :cancellation_code
code_association :company_value, :'company', :company
@@ -622,10 +622,15 @@
column_alias :key6, :'key6'
column_alias :key7, :'key7'
column_alias :key8, :'key8'
#### END GENERATED SECTION ####
+ # delegators
+ delegate :lead_pax, :to => :trip
+ delegate :passenger_list, :to => :trip
+
+
# Column views
column_view :dept_date_act_gmt, :date, :actual_departure_date_gmt
column_view :dept_time_act_gmt, :time, :actual_departure_time_gmt
column_def_datetime :actual_departure_date_time_gmt, :'dept date act gmt', :'dept time act gmt'
@@ -636,11 +641,11 @@
end
column_view :arrival_date_gmt, :date, :actual_arrival_date_gmt
column_view :arriv_time_act_gmt, :time, :actual_arrival_time_gmt
column_def_datetime :actual_arrival_date_time_gmt, :'arr date act gmt', :'arriv time act gmt'
-
+
def actual_land_date_time_gmt
date = actual_arrival_date_gmt
date -= 1.day if land_time_act_gmt > arriv_time_act_gmt
date.to_datetime.advance(:minutes=>land_time_act_gmt)
end
@@ -686,10 +691,11 @@
column_view :t_o_time_act_gmt, :time, :actual_takeoff_time_gmt
column_view :land_time_act_gmt, :time, :actual_land_time_gmt
column_view :delay_1_time, :time, :delay_1_duration
column_view :delay_2_time, :time, :delay_2_duration
+
# get pic or sic or purser for this trip leg. type should be :pic or :sic or :pur
def pilot_code(type)
crew_leg = pilot_crew(type)
crew_leg ? crew_leg.crew : ''
end
@@ -700,6 +706,33 @@
return nil unless type
crew_legs.find{|cl| cl.position_code_code == type.to_s.upcase }
end
def pic_crew; pilot_crew(:pic); end
def sic_crew; pilot_crew(:sic); end
+
+ def ebt_time
+ minutes_between = (planned_arrival_date_time_gmt - planned_departure_date_time_gmt)/60;
+ Time.from_fos_time(minutes_between)
+ end
+
+ #### aliases and special methods #####
+ # This method guarantees an icao for a view that needs one. If there is an icao, use it, otherwise make
+ # it from the prefix and airport_id .. which works as an icao, but beware, because these put together
+ # icao's that you make are valid icao codes, but you can't search the airport based it, since these
+ # airport rows don't have an icao code at all, they only have the prefix and airport_id. whacky.
+ def departure_icao_val
+ departure_icao || depart_ap_prefix + depart_airport_id
+ end
+
+ # same comment as above
+ def arrival_icao_val
+ arrival_icao || arrival_ap_prefix + arrival_airport_id
+ end
+
+ def departure_icao_expanded
+ "#{departure_icao_val} #{departure_airport.name} #{departure_airport.city} ,#{departure_airport.state_abbreviation}"
+ end
+
+ def arrival_icao_expanded
+ "#{arrival_icao_val} #{arrival_airport.name} #{arrival_airport.city} ,#{arrival_airport.state_abbreviation}"
+ end
end
\ No newline at end of file