Class: FlightLogExpense

Inherits:
Object show all
Defined in:
lib/models/flight_log_expense.rb,
lib/dbr_models/flight_log_expense.rb

Instance Method Summary collapse

Instance Method Details

#airport_fuel_lookupObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/models/flight_log_expense.rb', line 111

def airport_fuel_lookup
  if !is_departure_expense? then
    ap_str = "ARRIVAL"
    act_str = "ARR"
    prefix = "FBO"
  else
    ap_str = "DEPART"
    act_str = "DEPT"
    prefix = "FUELER"
  end

  sql = <<-SQL
  SELECT TOP 1 TL."TRIP NUMBER",TL."LEG NUMBER", TL."#{ap_str} AIRPORT ID",
    AF."COST 1", AF."QTY 1", AF."COST 2", AF."QTY 2", AF."COST 3", AF."QTY 3", AF."COST 4", AF."QTY 4",
    AF."COST 5", AF."QTY 5", AF."COST 6", AF."QTY 6", AF."COST 7", AF."QTY 7", AF."COST 8", AF."QTY 8",
    AF."COST 9", AF."QTY 9", AF."COST 10", AF."QTY 10", AF."EFFECTIVE DATE"
  FROM "TRIP LEGS" AS TL, "AIRPORT FUEL" AS AF
    WHERE (AF."FBO KID - DATE" = TL."#{prefix} KID - DATE"
    AND AF."FBO KID - TIME" = TL."#{prefix} KID - TIME"
    AND AF."FBO KID - MULT" = TL."#{prefix} KID - MULT"
    AND AF."FBO KID - COMM" = TL."#{prefix} KID - COMM"
    AND AF."FBO KID - USER" = TL."#{prefix} KID - USER"
    AND AF."VENDOR ID" = '#{vendor_id}'
    AND (AF."EFFECTIVE DATE" <= TL."#{act_str} DATE ACT LOCAL" OR AF."EFFECTIVE DATE" <= TL."#{ap_str} DATE - LOCAL"))
  AND   (TL."TRIP NUMBER" = ? AND TL."LEG NUMBER" = ?)
  ORDER BY AF."EFFECTIVE DATE" DESC
  SQL
  return db.fetch(sql, trip_leg.trip_number, trip_leg.leg_number).first
end

#build_fuel_tier_hash(airport_fuel) ⇒ Object

creates a hash table of the qty and fuel prices for each tier



141
142
143
144
145
146
147
# File 'lib/models/flight_log_expense.rb', line 141

def build_fuel_tier_hash airport_fuel # creates a hash table of the qty and fuel prices for each tier
  h = Hash.new
  (1..10).each do |n|
    h[airport_fuel[:"qty #{n}"]] = airport_fuel[:"cost #{n}"]
  end
  h
end

#fuel_costObject

For Fuel Flight Log expenses



97
98
99
100
101
# File 'lib/models/flight_log_expense.rb', line 97

def fuel_cost
  qty = quantity.to_i # Don't want to do this but its treating this has string for some reason
  return 0.0 if type.to_i != 1 or qty == 0
  fuel_rate * qty.to_i
end

#fuel_passdown_hashObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/models/flight_log_expense.rb', line 159

def fuel_passdown_hash
  expense_type = type_string
  leg          = trip_leg
  vendor_name  = vendor__company_2
  vendor_name  = vendor__company_1 if !vendor_name or vendor_name == ""
  vendor_name  = vendor__vendor_id if !vendor_name or vendor_name == ""
  airport      = leg.send("#{expense_type}_icao_val")
  fbo          = leg.send("#{expense_type}_fbo__name")
  leg_date     = (leg.dept_date_act_local and leg.dept_date_act_local != 0 ? leg.dept_date_act_local : leg.depart_date_local)

  {
    :leg_date      => leg_date,
    :trip_number   => leg.trip_number,
    :leg_number    => leg.leg_number,
    :ac            => leg.tail_number,
    :airport       => airport,
    :fbo           => fbo,
    :vendor        => vendor_name,
    :fuel_rate     => fuel_rate,
    :fuel_quantity => quantity,
    :fuel_cost     => fuel_cost
  }
end

#fuel_rateObject



149
150
151
152
153
154
155
156
157
# File 'lib/models/flight_log_expense.rb', line 149

def fuel_rate
  airport_fuel = airport_fuel_lookup
  return 0.0 if airport_fuel.nil? or airport_fuel == {}
  h = build_fuel_tier_hash airport_fuel
  h.keys.sort.reverse.each do |key|
    return (h[key] / 100.0) if quantity.to_i >= key
  end
  0.0
end

#is_departure_expense?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/models/flight_log_expense.rb', line 103

def is_departure_expense?
  arrival_airport == 0
end

#type_stringObject



107
108
109
# File 'lib/models/flight_log_expense.rb', line 107

def type_string
  is_departure_expense? ? "departure" : "arrival"
end