lib/models/trip_leg.rb in fossil-0.5.40 vs lib/models/trip_leg.rb in fossil-0.5.41

- old
+ new

@@ -933,6 +933,47 @@ end def total_fuel_purchased_quantity departure_fuel_purchased_quantity + arrival_fuel_purchased_quantity end + + + # Fuel Passdown Methods + class << self + def fuel_passdown_data start_date, end_date, fbo_keys + trip_legs = TripLeg.get_fuel_passdown_trip_legs( start_date, end_date ) + fuel_data_by_fbo_keys( trip_legs, fbo_keys ) + end + + def get_fuel_passdown_trip_legs start_date, end_date + start_date = start_date.to_fos_days + end_date = end_date.to_fos_days + TripLeg.filter(:cancelled => 0, :status => [0,1,2]). + filter(~{:'leg state' => 5}). + filter({:'dept date act local' => start_date..end_date, + :'depart date - local' => start_date...end_date}.sql_or).limit(10).all + end + + def fuel_data_by_fbo_keys trip_legs, fbo_keys + data = Hash.new + trip_legs.each do |leg| + leg.fuel_expenses.each do |expense| + + expense_type = expense_type_string( expense ) + fbo_name = leg.send( "#{expense_type}_fbo__name" ) + p fbo_name + if fbo_keys.include?(fbo_name) then # is this an fbo we are looking for? + expense_hash = calculate_expense( expense, leg ) + + if data.has_key?(fbo_name) + data[fbo_name].push(expense_hash) + else + data[fbo_name] = [expense_hash] + end + end + end + end + data + end + protected :fuel_data_by_fbo_keys + end end \ No newline at end of file