fossil 0.5.30 → 0.5.31

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.30
1
+ 0.5.31
data/fossil.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fossil}
8
- s.version = "0.5.30"
8
+ s.version = "0.5.31"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Patrick Lardin, Daniel Sudol"]
12
- s.date = %q{2011-03-08}
12
+ s.date = %q{2011-03-09}
13
13
  s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
14
14
  s.email = %q{plardin@xojet.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  "Rakefile",
21
21
  "VERSION",
22
22
  "fossil.gemspec",
23
+ "lib/dbr_models/flight_log_expense.rb",
23
24
  "lib/dbr_models/group_cost.rb",
24
25
  "lib/dbr_models/personnel.rb",
25
26
  "lib/dbr_models/quote.rb",
@@ -146,6 +147,7 @@ Gem::Specification.new do |s|
146
147
  "spec/helper_methods.rb",
147
148
  "spec/models/airport_fbo_spec.rb",
148
149
  "spec/models/code_spec.rb",
150
+ "spec/models/flight_log_expense_spec.rb",
149
151
  "spec/models/quote_spec.rb",
150
152
  "spec/models/trip_leg_spec.rb",
151
153
  "spec/models/trip_spec.rb",
@@ -184,6 +186,7 @@ Gem::Specification.new do |s|
184
186
  "spec/helper_classes.rb",
185
187
  "spec/models/code_spec.rb",
186
188
  "spec/models/trip_leg_spec.rb",
189
+ "spec/models/flight_log_expense_spec.rb",
187
190
  "spec/models/quote_spec.rb",
188
191
  "spec/models/vendor_document_spec.rb",
189
192
  "spec/models/trip_spec.rb",
@@ -0,0 +1,3 @@
1
+ class FlightLogExpense
2
+ many_to_one :trip_leg, :class=>:TripLeg, :key=>:trip_leg_id
3
+ end
@@ -1,120 +1,132 @@
1
1
  class FlightLogExpense < Sequel::Model(:'flight log expenses')
2
2
 
3
- code_association :expense_type_value, :'type', :flight_log_expense_type
3
+ code_association :expense_type_value, :'type', :flight_log_expense_type
4
+
5
+ #Many to one association with composite keys
6
+ n_to_o :trip_leg, :class=>:TripLeg, :prefix=>'trip leg'
4
7
 
5
- #Many to one association with composite keys
6
- n_to_o :trip_leg, :class=>:TripLeg, :prefix=>'trip leg'
7
-
8
8
  #### BEGIN GENERATED SECTION ####
9
- set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time']
9
+ set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time']
10
10
 
11
- column_alias :ac_curr_bill_amount, :'ac curr bill amount'
12
- column_alias :ac_curr_cost, :'ac curr cost'
13
- column_alias :ac_currency_type, :'ac currency type'
14
- column_alias :ac_quantity, :'ac quantity'
15
- column_alias :ac_quantity_tenths, :'ac quantity tenths'
16
- column_alias :ac_unit, :'ac unit'
17
- column_alias :account_number, :'account number'
18
- column_alias :aircraft, :'aircraft'
19
- column_alias :allow_0_cost, :'allow 0 cost'
20
- column_alias :approved, :'approved'
21
- column_alias :arrival_airport, :'arrival airport'
22
- column_alias :auto_create, :'auto create'
23
- column_alias :bill_amount, :'bill amount'
24
- column_alias :billable, :'billable'
25
- column_alias :comment_req, :'comment req'
26
- column_alias :cost, :'cost'
27
- column_alias :cost_center, :'cost center'
28
- column_alias :cost_kid_comm, :'cost kid - comm'
29
- column_alias :cost_kid_date, :'cost kid - date'
30
- column_alias :cost_kid_mult, :'cost kid - mult'
31
- column_alias :cost_kid_time, :'cost kid - time'
32
- column_alias :cost_kid_user, :'cost kid - user'
33
- column_alias :crew_id, :'crew id'
34
- column_alias :currency_type, :'currency type'
35
- column_alias :description, :'description'
36
- column_alias :discount, :'discount'
37
- column_alias :discount_date, :'discount date'
38
- column_alias :estimated_cost, :'estimated cost'
39
- column_alias :fet_tax, :'fet tax'
40
- column_alias :fed_tax_rate, :'fed tax rate'
41
- column_alias :image_name, :'image name'
42
- column_alias :internal_1, :'internal 1'
43
- column_alias :internal_6, :'internal 6'
44
- column_alias :internal0, :'internal0'
45
- column_alias :internal01, :'internal01'
46
- column_alias :internal02, :'internal02'
47
- column_alias :internal03, :'internal03'
48
- column_alias :inv_received_date, :'inv received date'
49
- column_alias :invoice, :'invoice'
50
- column_alias :invoice_date, :'invoice date'
51
- column_alias :invoice_paid, :'invoice paid'
52
- column_alias :invoice_paid_date, :'invoice paid date'
53
- column_alias :invoice_received, :'invoice received'
54
- column_alias :invoiced, :'invoiced'
55
- column_alias :kid_comm, :'kid - comm'
56
- column_alias :kid_date, :'kid - date'
57
- column_alias :kid_mult, :'kid - mult'
58
- column_alias :kid_time, :'kid - time'
59
- column_alias :kid_user, :'kid - user'
60
- column_alias :leg_date, :'leg date'
61
- column_alias :onecost_type_code, :'onecost type code'
62
- column_alias :pay_method, :'pay method'
63
- column_alias :percent_markup, :'percent markup'
64
- column_alias :problem, :'problem'
65
- column_alias :quantity, :'quantity'
66
- column_alias :quantity_tenths, :'quantity tenths'
67
- column_alias :receipt, :'receipt'
68
- column_alias :receipt_number, :'receipt number'
69
- column_alias :receipt_req, :'receipt req'
70
- column_alias :reimburs, :'reimburs'
71
- column_alias :serv_kid_comm, :'serv kid - comm'
72
- column_alias :serv_kid_date, :'serv kid - date'
73
- column_alias :serv_kid_mult, :'serv kid - mult'
74
- column_alias :serv_kid_time, :'serv kid - time'
75
- column_alias :serv_kid_user, :'serv kid - user'
76
- column_alias :service_index, :'service index'
77
- column_alias :tax, :'tax'
78
- column_alias :taxable, :'taxable'
79
- column_alias :total_cost_fixed, :'total cost fixed'
80
- column_alias :trip_leg_kid_comm, :'trip leg kid - comm'
81
- column_alias :trip_leg_kid_date, :'trip leg kid - date'
82
- column_alias :trip_leg_kid_mult, :'trip leg kid - mult'
83
- column_alias :trip_leg_kid_time, :'trip leg kid - time'
84
- column_alias :trip_leg_kid_user, :'trip leg kid - user'
85
- column_alias :type, :'type'
86
- column_alias :unit, :'unit'
87
- column_alias :unit_cost, :'unit cost'
88
- column_alias :vendor_id, :'vendor id'
89
- column_alias :vendor_req, :'vendor req'
90
- column_alias :key0, :'key0'
91
- column_alias :key1, :'key1'
92
- column_alias :key2, :'key2'
11
+ column_alias :ac_curr_bill_amount, :'ac curr bill amount'
12
+ column_alias :ac_curr_cost, :'ac curr cost'
13
+ column_alias :ac_currency_type, :'ac currency type'
14
+ column_alias :ac_quantity, :'ac quantity'
15
+ column_alias :ac_quantity_tenths, :'ac quantity tenths'
16
+ column_alias :ac_unit, :'ac unit'
17
+ column_alias :account_number, :'account number'
18
+ column_alias :aircraft, :'aircraft'
19
+ column_alias :allow_0_cost, :'allow 0 cost'
20
+ column_alias :approved, :'approved'
21
+ column_alias :arrival_airport, :'arrival airport'
22
+ column_alias :auto_create, :'auto create'
23
+ column_alias :bill_amount, :'bill amount'
24
+ column_alias :billable, :'billable'
25
+ column_alias :comment_req, :'comment req'
26
+ column_alias :cost, :'cost'
27
+ column_alias :cost_center, :'cost center'
28
+ column_alias :cost_kid_comm, :'cost kid - comm'
29
+ column_alias :cost_kid_date, :'cost kid - date'
30
+ column_alias :cost_kid_mult, :'cost kid - mult'
31
+ column_alias :cost_kid_time, :'cost kid - time'
32
+ column_alias :cost_kid_user, :'cost kid - user'
33
+ column_alias :crew_id, :'crew id'
34
+ column_alias :currency_type, :'currency type'
35
+ column_alias :description, :'description'
36
+ column_alias :discount, :'discount'
37
+ column_alias :discount_date, :'discount date'
38
+ column_alias :estimated_cost, :'estimated cost'
39
+ column_alias :fet_tax, :'fet tax'
40
+ column_alias :fed_tax_rate, :'fed tax rate'
41
+ column_alias :image_name, :'image name'
42
+ column_alias :internal_1, :'internal 1'
43
+ column_alias :internal_6, :'internal 6'
44
+ column_alias :internal0, :'internal0'
45
+ column_alias :internal01, :'internal01'
46
+ column_alias :internal02, :'internal02'
47
+ column_alias :internal03, :'internal03'
48
+ column_alias :inv_received_date, :'inv received date'
49
+ column_alias :invoice, :'invoice'
50
+ column_alias :invoice_date, :'invoice date'
51
+ column_alias :invoice_paid, :'invoice paid'
52
+ column_alias :invoice_paid_date, :'invoice paid date'
53
+ column_alias :invoice_received, :'invoice received'
54
+ column_alias :invoiced, :'invoiced'
55
+ column_alias :kid_comm, :'kid - comm'
56
+ column_alias :kid_date, :'kid - date'
57
+ column_alias :kid_mult, :'kid - mult'
58
+ column_alias :kid_time, :'kid - time'
59
+ column_alias :kid_user, :'kid - user'
60
+ column_alias :leg_date, :'leg date'
61
+ column_alias :onecost_type_code, :'onecost type code'
62
+ column_alias :pay_method, :'pay method'
63
+ column_alias :percent_markup, :'percent markup'
64
+ column_alias :problem, :'problem'
65
+ column_alias :quantity, :'quantity'
66
+ column_alias :quantity_tenths, :'quantity tenths'
67
+ column_alias :receipt, :'receipt'
68
+ column_alias :receipt_number, :'receipt number'
69
+ column_alias :receipt_req, :'receipt req'
70
+ column_alias :reimburs, :'reimburs'
71
+ column_alias :serv_kid_comm, :'serv kid - comm'
72
+ column_alias :serv_kid_date, :'serv kid - date'
73
+ column_alias :serv_kid_mult, :'serv kid - mult'
74
+ column_alias :serv_kid_time, :'serv kid - time'
75
+ column_alias :serv_kid_user, :'serv kid - user'
76
+ column_alias :service_index, :'service index'
77
+ column_alias :tax, :'tax'
78
+ column_alias :taxable, :'taxable'
79
+ column_alias :total_cost_fixed, :'total cost fixed'
80
+ column_alias :trip_leg_kid_comm, :'trip leg kid - comm'
81
+ column_alias :trip_leg_kid_date, :'trip leg kid - date'
82
+ column_alias :trip_leg_kid_mult, :'trip leg kid - mult'
83
+ column_alias :trip_leg_kid_time, :'trip leg kid - time'
84
+ column_alias :trip_leg_kid_user, :'trip leg kid - user'
85
+ column_alias :type, :'type'
86
+ column_alias :unit, :'unit'
87
+ column_alias :unit_cost, :'unit cost'
88
+ column_alias :vendor_id, :'vendor id'
89
+ column_alias :vendor_req, :'vendor req'
90
+ column_alias :key0, :'key0'
91
+ column_alias :key1, :'key1'
92
+ column_alias :key2, :'key2'
93
93
  #### END GENERATED SECTION ####
94
94
 
95
- def fuel_rate # Takes a FlightLogExpense for fuel
96
- return 0 if type != 1
97
- my_type = (arrival_airport == 1 ? "ARRIVAL" : "DEPART")
98
- airport_fuel = airport_fuel_lookup vendor_id, my_type
99
- (airport_fuel ? fuel_rate_by_quantity(quantity, airport_fuel) : 0)
95
+ # For Fuel Flight Log expenses
96
+ def fuel_cost
97
+ qty = quantity.to_i # Don't want to do this but its treating this has string for some reason
98
+ return 0.0 if type.to_i != 1 or qty == 0
99
+ fuel_rate * qty.to_i
100
+ end
101
+
102
+ def is_departure_expense?
103
+ arrival_airport == 0
100
104
  end
101
105
 
102
- def airport_fuel_lookup vendor_id, type #ARRIVAL or DEPART
103
- str = (type == "DEPART" ? "DEPT" : "ARR")
104
- prefix = (type == "DEPART" ? "FUELER" : "FBO")
106
+ def airport_fuel_lookup
107
+ if !is_departure_expense? then
108
+ ap_str = "ARRIVAL"
109
+ act_str = "ARR"
110
+ prefix = "FBO"
111
+ else
112
+ ap_str = "DEPART"
113
+ act_str = "DEPT"
114
+ prefix = "FUELER"
115
+ end
116
+
105
117
  sql = <<-SQL
106
- SELECT TOP 1 TL."TRIP NUMBER",TL."LEG NUMBER", TL."#{type} AIRPORT ID",
118
+ SELECT TOP 1 TL."TRIP NUMBER",TL."LEG NUMBER", TL." #{ap_str} AIRPORT ID",
107
119
  AF."COST 1", AF."QTY 1", AF."COST 2", AF."QTY 2", AF."COST 3", AF."QTY 3", AF."COST 4", AF."QTY 4",
108
120
  AF."COST 5", AF."QTY 5", AF."COST 6", AF."QTY 6", AF."COST 7", AF."QTY 7", AF."COST 8", AF."QTY 8",
109
121
  AF."COST 9", AF."QTY 9", AF."COST 10", AF."QTY 10", AF."EFFECTIVE DATE"
110
122
  FROM "TRIP LEGS" AS TL, "AIRPORT FUEL" AS AF
111
- WHERE (AF."FBO KID - DATE" = TL."#{prefix} KID - DATE"
112
- AND AF."FBO KID - TIME" = TL."#{prefix} KID - TIME"
113
- AND AF."FBO KID - MULT" = TL."#{prefix} KID - MULT"
114
- AND AF."FBO KID - COMM" = TL."#{prefix} KID - COMM"
115
- AND AF."FBO KID - USER" = TL."#{prefix} KID - USER"
116
- AND AF."VENDOR ID" = '#{vendor_id}'
117
- AND (AF."EFFECTIVE DATE" <= TL."#{str} DATE ACT LOCAL" OR AF."EFFECTIVE DATE" <= TL."#{type} DATE - LOCAL"))
123
+ WHERE (AF."FBO KID - DATE" = TL." #{prefix} KID - DATE"
124
+ AND AF."FBO KID - TIME" = TL." #{prefix} KID - TIME"
125
+ AND AF."FBO KID - MULT" = TL." #{prefix} KID - MULT"
126
+ AND AF."FBO KID - COMM" = TL." #{prefix} KID - COMM"
127
+ AND AF."FBO KID - USER" = TL." #{prefix} KID - USER"
128
+ AND AF."VENDOR ID" = ' #{vendor_id} '
129
+ AND (AF."EFFECTIVE DATE" <= TL." #{act_str} DATE ACT LOCAL" OR AF."EFFECTIVE DATE" <= TL." #{ap_str} DATE - LOCAL"))
118
130
  AND (TL."TRIP NUMBER" = ? AND TL."LEG NUMBER" = ?)
119
131
  ORDER BY AF."EFFECTIVE DATE" DESC
120
132
  SQL
@@ -129,12 +141,13 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
129
141
  h
130
142
  end
131
143
 
132
- def fuel_rate_by_quantity qty, airport_fuel # gives the cost associated with the qty of fuel purchased
133
- return 0 if qty == nil or qty == 0 or airport_fuel == nil
144
+ def fuel_rate
145
+ airport_fuel = airport_fuel_lookup
146
+ return 0.0 if airport_fuel.nil? or airport_fuel == {}
134
147
  h = build_fuel_tier_hash airport_fuel
135
148
  h.keys.sort.reverse.each do |key|
136
- return (h[key] / 100.0) if (qty and key) and qty >= key
149
+ return (h[key] / 100.0) if quantity.to_i >= key
137
150
  end
138
- 0
151
+ 0.0
139
152
  end
140
153
  end
@@ -879,10 +879,6 @@ class TripLeg < Sequel::Model(:'trip legs')
879
879
  $1
880
880
  end
881
881
 
882
- def fuel_expense
883
- flight_log_expenses.find{|expense| expense.type == 1}
884
- end
885
-
886
882
  def departure_diff_in_minutes
887
883
  (leg_status == "VERI" or leg_status == "FLOG") ? ((actual_departure_date_time_local - planned_departure_date_time_local)*1440).to_i : nil
888
884
  end
@@ -905,7 +901,28 @@ class TripLeg < Sequel::Model(:'trip legs')
905
901
  my_class
906
902
  end
907
903
 
904
+ # Fuel Expense Stuff
908
905
  def fuel_expenses
909
- flight_log_expenses.find_all {|expense| expense.type == 1}
906
+ flight_log_expenses.find_all { |expense| expense.type == 1 }
907
+ end
908
+
909
+ def departure_fuel_expenses
910
+ fuel_expenses.select { |expense| expense.arrival_airport == 0 }
911
+ end
912
+
913
+ def arrival_fuel_expenses
914
+ fuel_expenses.select { |expense| expense.arrival_airport == 1 }
915
+ end
916
+
917
+ def departure_fuel_cost
918
+ departure_fuel_expenses.inject(0) { |sum, e| sum + e.fuel_cost }
919
+ end
920
+
921
+ def arrival_fuel_cost
922
+ arrival_fuel_expenses.inject(0) { |sum, e| sum + e.fuel_cost }
923
+ end
924
+
925
+ def total_fuel_cost
926
+ arrival_fuel_cost + departure_fuel_cost
910
927
  end
911
928
  end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe FlightLogExpense do
4
+
5
+ describe 'fuel expense' do
6
+
7
+ before :each do
8
+ @fe = FlightLogExpense.new(:type => 1)
9
+ end
10
+
11
+ describe 'fuel cost' do
12
+
13
+ it 'should not have a cost if it doesnt have a quantity' do
14
+ @fe.quantity = 0
15
+
16
+ @fe.fuel_cost.should == 0.0
17
+ end
18
+
19
+ it 'should calculate cost based on quantity and rate' do
20
+ @fe.quantity = 100
21
+ stub(@fe).fuel_rate { 4.0 }
22
+
23
+ @fe.fuel_cost.should == 400.0
24
+ end
25
+ end
26
+
27
+ describe 'fuel rate' do
28
+
29
+ it 'should not have a rate if the airport fuel pricing cannnot be determined' do
30
+ @fe.quantity = 100
31
+ stub(@fe).airport_fuel_lookup { {} }
32
+
33
+ @fe.fuel_rate.should == 0.0
34
+ end
35
+
36
+ describe 'different fuel tiers' do
37
+
38
+ before :each do
39
+ airport_fuel = {
40
+ :"qty 1"=>1, :"cost 1"=>393,
41
+ :"qty 2"=>1000, :"cost 2"=>373,
42
+ :"qty 3"=>2000, :"cost 3"=>362,
43
+ :"qty 4"=>0, :"cost 4"=>0,
44
+ :"qty 5"=>0, :"cost 5"=>0,
45
+ :"qty 6"=>0, :"cost 6"=>0,
46
+ :"qty 7"=>0, :"cost 7"=>0,
47
+ :"qty 8"=>0, :"cost 8"=>0,
48
+ :"qty 9"=>0, :"cost 9"=>0,
49
+ :"qty 10"=>0, :"cost 10"=>0
50
+ }
51
+ stub(@fe).airport_fuel_lookup { airport_fuel }
52
+ end
53
+
54
+ it 'find rate for quantity at lowest tier' do
55
+ @fe.quantity = 100
56
+ @fe.fuel_rate.should == 3.93
57
+ end
58
+
59
+ it 'find rate for quantity at middle tier' do
60
+ @fe.quantity = 1001
61
+ @fe.fuel_rate.should == 3.73
62
+ end
63
+
64
+ it 'find rate for quantity at highest tier' do
65
+ @fe.quantity = 2002
66
+ @fe.fuel_rate.should == 3.62
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -89,7 +89,7 @@ describe TripLeg do
89
89
 
90
90
  it "actual landing date_time dates are the same as arr_date_act_gmt if on time time is NOT greater than landing time" do
91
91
  tl = TripLeg.new(:arr_date_act_gmt=> Date.new(1900, 1, 2).to_fos_days,
92
- :land_time_act_gmt=> 20,
92
+ :land_time_act_gmt=> 20,
93
93
  :arriv_time_act_gmt=> 40)
94
94
  tl.actual_land_date_time_gmt.should == DateTime.new(1900, 1, 2, 0, 20, 0)
95
95
  end
@@ -107,7 +107,7 @@ describe TripLeg do
107
107
  end
108
108
 
109
109
  it "has the new 'arr date act gmt' field set" do
110
- tl = TripLeg.new(:arr_date_act_gmt=> 2, # new field is set, so use this one
110
+ tl = TripLeg.new(:arr_date_act_gmt=> 2, # new field is set, so use this one
111
111
  :arriv_time_act_gmt=> 10,
112
112
  :arrival_date_gmt=> 0)
113
113
  tl.actual_arrival_date_time_gmt.should == DateTime.new(1900, 1, 2, 0, 10, 0)
@@ -126,7 +126,7 @@ describe TripLeg do
126
126
 
127
127
  it "actual_arrival_date_time_base are correctly calculating the tz offset" do
128
128
  # this makes an actual_arrival_date_time_gmt date of: 1900-01-02 23:40:00
129
- arr_date_act_gmt, arriv_time_act_gmt = Date.new(1900, 1, 2).to_fos_days , 1420
129
+ arr_date_act_gmt, arriv_time_act_gmt = Date.new(1900, 1, 2).to_fos_days, 1420
130
130
  home_tz_gmt_offset = -70
131
131
  # home_tz_gmt_offset should make actual_arrival_date_time_base of: 1900-01-02 16:40:00
132
132
  tl = TripLeg.new(:arr_date_act_gmt => arr_date_act_gmt,
@@ -138,7 +138,7 @@ describe TripLeg do
138
138
 
139
139
  it "actual_departure_date_time_base are correctly calculating the tz offset" do
140
140
  # this makes an actual_arrival_date_time_gmt date of: 1900-01-02 23:40:00
141
- dept_date_act_gmt, dept_time_act_gmt = Date.new(1900, 1, 2).to_fos_days , 1420
141
+ dept_date_act_gmt, dept_time_act_gmt = Date.new(1900, 1, 2).to_fos_days, 1420
142
142
  home_tz_gmt_offset = -70
143
143
  # home_tz_gmt_offset should make actual_arrival_date_time_base of: 1900-01-02 16:40:00
144
144
  tl = TripLeg.new(:dept_date_act_gmt => dept_date_act_gmt,
@@ -229,188 +229,135 @@ describe TripLeg do
229
229
  end
230
230
  end
231
231
 
232
+ describe 'fuel expenses' do
232
233
 
233
- ## NEED TO REMOVE, TESTS SHOULD BE IN FlightLogExpense spec
234
- # describe "fuel passdown data columns" do
235
- #
236
- # it "query fuel info from real trip leg actually works" do
237
- # set_fos_db([TripLeg,AirportFuel,AirportFbo,FlightLogExpense])
238
- ## trip_leg = TripLeg.first(:trip_number=>67579,:leg_number=>3)
239
- # trip_leg = TripLeg.first(:trip_number=>79203,:leg_number=>1)
240
- ## trip_leg = TripLeg.select(:'trip legs__trip_number').
241
- ## filter(:trip_number=>67579,:leg_number=>3).
242
- ## inner_join(:flight_log_expense,)
243
- ## first
244
- ## p trip_leg.trip_number
245
- # trip_leg.dept_fuel_quantity.should == 433
246
- # trip_leg.dept_fuel_cost.should == 1437.56
247
- # trip_leg.dept_fuel_rate.should == 3.32
248
- # trip_leg.arr_fuel_quantity.should == 0
249
- # trip_leg.arr_fuel_cost.should == 0
250
- # trip_leg.arr_fuel_rate.should == 0
251
- # end
252
- #
253
- # describe "with airport fuel data" do
254
- # before :each do
255
- # #expect the method airport_fuel_lookup to be called and return a prepopulated hash
256
- # hash_with_airport_fuel = {:"qty 1"=>1, :"cost 1"=>393,
257
- # :"qty 2"=>1000, :"cost 2"=>373,
258
- # :"qty 3"=>2000, :"cost 3"=>362,
259
- # :"qty 4"=>0, :"cost 4"=>0,
260
- # :"qty 5"=>0, :"cost 5"=>0,
261
- # :"qty 6"=>0, :"cost 6"=>0,
262
- # :"qty 7"=>0, :"cost 7"=>0,
263
- # :"qty 8"=>0, :"cost 8"=>0,
264
- # :"qty 9"=>0, :"cost 9"=>0,
265
- # :"qty 10"=>0, :"cost 10"=>0,
266
- # :quantity=>970}
267
- # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970)
268
- # @tl = TripLeg.new
269
- # mock(@tl).airport_fuel_lookup(is_a(String)) {hash_with_airport_fuel}
270
- # stub(@tl).fuel_expense {fe}
271
- # end
272
- #
273
- # it "fuel quantity for leg with airport fuel" do
274
- # @tl.dept_fuel_quantity.should == 970
275
- # @tl.arr_fuel_quantity.should == 0
276
- # end
277
- #
278
- # it "fuel rate for leg with airport fuel" do
279
- # @tl.dept_fuel_rate.should == 3.93
280
- # @tl.arr_fuel_rate.should == 0
281
- # end
282
- #
283
- # it "fuel cost for leg with airport fuel" do
284
- # @tl.dept_fuel_cost.to_s.should == "3812.1"
285
- # @tl.arr_fuel_cost.to_s.should == "0"
286
- # end
287
- # end
288
- #
289
- # describe "without airport fuel data" do
290
- # before :each do
291
- # #expect the method airport_fuel_lookup to be called and return a prepopulated hash
292
- # hash_without_airport_fuel = {:quantity=>970}
293
- # @tl = TripLeg.new
294
- # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970)
295
- # mock(@tl).airport_fuel_lookup(is_a(String)) {hash_without_airport_fuel}
296
- # stub(@tl).fuel_expense {fe}
297
- # end
298
- #
299
- # it "fuel quantity for leg without airport fuel" do
300
- # @tl.dept_fuel_quantity.should == 970
301
- # @tl.arr_fuel_quantity.should == 0
302
- # end
303
- #
304
- # it "fuel rate for leg without airport fuel" do
305
- # @tl.dept_fuel_rate.should == 0
306
- # @tl.arr_fuel_rate.should == 0
307
- # end
308
- #
309
- # it "fuel cost for leg without airport fuel" do
310
- # @tl.dept_fuel_cost.should == 0
311
- # @tl.arr_fuel_cost.should == 0
312
- # end
313
- # end
314
- # end
315
- #
316
- # describe "without any data at all" do
317
- # before :each do
318
- ## hash_without_any_data = nil
319
- # @tl = TripLeg.new
320
- # fe = nil
321
- ## mock(@tl).airport_fuel_lookup(is_a(String)) {hash_without_any_data}
322
- # stub(@tl).fuel_expense {fe}
323
- # end
324
- #
325
- # it "fuel quantity for leg without any data" do
326
- # @tl.dept_fuel_quantity.should == 0
327
- # @tl.arr_fuel_quantity.should == 0
328
- # end
329
- #
330
- # it "fuel rate for leg without any data" do
331
- # @tl.dept_fuel_rate.should == 0
332
- # @tl.arr_fuel_rate.should == 0
333
- # end
334
- #
335
- # it "fuel cost for leg without any data" do
336
- # @tl.dept_fuel_cost.should == 0
337
- # @tl.arr_fuel_cost.should == 0
338
- # end
339
- # end
340
-
341
- # # FUEL PASSDOWN SPECS
342
- # describe "different tier pricing selection" do
343
- # it "has fuel qty <= second lowest tier" do
344
- # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393,
345
- # :"qty 2"=>1000, :"cost 2"=>373,
346
- # :"qty 3"=>2000, :"cost 3"=>362,
347
- # :"qty 4"=>0, :"cost 4"=>0,
348
- # :"qty 5"=>0, :"cost 5"=>0,
349
- # :"qty 6"=>0, :"cost 6"=>0,
350
- # :"qty 7"=>0, :"cost 7"=>0,
351
- # :"qty 8"=>0, :"cost 8"=>0,
352
- # :"qty 9"=>0, :"cost 9"=>0,
353
- # :"qty 10"=>0, :"cost 10"=>0,
354
- # :quantity=>970}
355
- # tl = TripLeg.new
356
- # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970)
357
- # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash}
358
- # stub(tl).fuel_expense {fe}
359
- # tl.dept_fuel_cost.to_s.should == "3812.1"
360
- #
361
- # fe.arrival_airport = 1
362
- # stub(tl).fuel_expense {fe}
363
- # tl.arr_fuel_cost.to_s.should == "3812.1"
364
- # end
365
- #
366
- # it "has fuel qty >= highest tier" do
367
- # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393,
368
- # :"qty 2"=>1000, :"cost 2"=>373,
369
- # :"qty 3"=>2000, :"cost 3"=>362,
370
- # :"qty 4"=>3000, :"cost 4"=>352,
371
- # :"qty 5"=>4000, :"cost 5"=>342,
372
- # :"qty 6"=>5000, :"cost 6"=>332,
373
- # :"qty 7"=>6000, :"cost 7"=>322,
374
- # :"qty 8"=>7000, :"cost 8"=>312,
375
- # :"qty 9"=>8000, :"cost 9"=>302,
376
- # :"qty 10"=>9000, :"cost 10"=>292,
377
- # :quantity=>10000}
378
- # tl = TripLeg.new
379
- # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity=>10000)
380
- # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash}
381
- # stub(tl).fuel_expense {fe}
382
- #
383
- # tl.dept_fuel_cost.should == 29200
384
- #
385
- # fe.arrival_airport = 1
386
- # stub(tl).fuel_expense {fe}
387
- # tl.arr_fuel_cost.should == 29200
388
- # end
389
- #
390
- # it "has fuel qty in the middle of fuel tiers" do
391
- # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393,
392
- # :"qty 2"=>1000, :"cost 2"=>373,
393
- # :"qty 3"=>2000, :"cost 3"=>362,
394
- # :"qty 4"=>0, :"cost 4"=>0,
395
- # :"qty 5"=>0, :"cost 5"=>0,
396
- # :"qty 6"=>0, :"cost 6"=>0,
397
- # :"qty 7"=>0, :"cost 7"=>0,
398
- # :"qty 8"=>0, :"cost 8"=>0,
399
- # :"qty 9"=>0, :"cost 9"=>0,
400
- # :"qty 10"=>0, :"cost 10"=>0,
401
- # :quantity=>1100}
402
- # tl = TripLeg.new
403
- # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity=>1100)
404
- # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash}
405
- # stub(tl).fuel_expense {fe}
406
- #
407
- # tl.dept_fuel_cost.should == 4103
408
- #
409
- # fe.arrival_airport = 1
410
- # stub(tl).fuel_expense {fe}
411
- # tl.arr_fuel_cost.should == 4103
412
- # end
413
- # end
414
- # END FUEL PASSDOWN RELATED TESTS ####
415
- end
234
+ before :each do
235
+ @tl = TripLeg.new
236
+ end
237
+
238
+ describe 'arrival fuel costs' do
239
+
240
+ it 'should not have a cost if there are no fuel flight log expenses' do
241
+ @tl.arrival_fuel_cost.should == 0.0
242
+ end
243
+
244
+ it 'should have a cost if there is an arrival fuel flight log expense' do
245
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
246
+ stub(fe).fuel_cost { 300.0 }
247
+ stub(@tl).fuel_expenses { [fe] }
248
+
249
+ @tl.arrival_fuel_cost.should == 300.0
250
+ end
251
+
252
+ it 'should not have a cost if the fuel flight log expense is not arrival' do
253
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
254
+ stub(fe).fuel_cost { 300.0 }
255
+ stub(@tl).fuel_expenses { [fe] }
256
+
257
+ @tl.arrival_fuel_cost.should == 0.0
258
+ end
259
+
260
+ it 'should total the costs if there are more than one fuel flight log expenses' do
261
+ fles = []
262
+ (1..4).each do |n|
263
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
264
+ stub(fe).fuel_cost { n * 100 }
265
+ fles << fe
266
+ end
267
+ stub(@tl).fuel_expenses { fles }
268
+
269
+ @tl.arrival_fuel_cost.should == 1000.0
270
+ end
271
+
272
+ it 'should total the costs but only for fuel expenses that are arrival, ignoring departures' do
273
+ fles = []
274
+ (1..4).each do |n|
275
+ arrival = (n > 2 ? 1 : 0)
276
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => arrival)
277
+ stub(fe).fuel_cost { n * 100 }
278
+ fles << fe
279
+ end
280
+ stub(@tl).fuel_expenses { fles }
281
+
282
+ @tl.arrival_fuel_cost.should == 700.0
283
+ end
284
+ end
285
+
286
+ describe 'departure fuel costs' do
287
+ it 'should not have a cost if there are no fuel flight log expenses' do
288
+ @tl.departure_fuel_cost.should == 0.0
289
+ end
290
+
291
+ it 'should have a cost if there is a departure fuel flight log expense' do
292
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
293
+ stub(fe).fuel_cost { 300.0 }
294
+ stub(@tl).fuel_expenses { [fe] }
295
+
296
+ @tl.departure_fuel_cost.should == 300.0
297
+ end
298
+
299
+ it 'should not have a cost if the fuel flight log expense is not departure' do
300
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
301
+ stub(fe).fuel_cost { 300.0 }
302
+ stub(@tl).fuel_expenses { [fe] }
303
+
304
+ @tl.departure_fuel_cost.should == 0.0
305
+ end
306
+
307
+ it 'should total the costs if there are more than one fuel flight log expenses' do
308
+ fles = []
309
+ (1..4).each do |n|
310
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
311
+ stub(fe).fuel_cost { n * 100 }
312
+ fles << fe
313
+ end
314
+ stub(@tl).fuel_expenses { fles }
315
+
316
+ @tl.departure_fuel_cost.should == 1000.0
317
+ end
318
+
319
+ it 'should total the costs but only for fuel expenses that are arrival, ignoring departures' do
320
+ fles = []
321
+ (1..4).each do |n|
322
+ arrival = (n <= 2 ? 1 : 0)
323
+ fe = FlightLogExpense.new(:type => 1, :arrival_airport => arrival)
324
+ stub(fe).fuel_cost { n * 100 }
325
+ fles << fe
326
+ end
327
+ stub(@tl).fuel_expenses { fles }
328
+
329
+ @tl.departure_fuel_cost.should == 700.0
330
+ end
331
+ end
332
+
333
+ describe 'total fuel costs' do
334
+ it 'should not have a total cost if there are no fuel flight log expenses' do
335
+ stub(@tl).departure_fuel_cost { 0.0 }
336
+ stub(@tl).arrival_fuel_cost { 0.0 }
337
+
338
+ @tl.total_fuel_cost.should == 0.0
339
+ end
416
340
 
341
+ it 'should have a total cost if there are departure fuel expense costs' do
342
+ stub(@tl).departure_fuel_cost { 100.0 }
343
+ stub(@tl).arrival_fuel_cost { 0.0 }
344
+
345
+ @tl.total_fuel_cost.should == 100.0
346
+ end
347
+
348
+ it 'should have a total cost if there are arrival fuel expense costs' do
349
+ stub(@tl).departure_fuel_cost { 0.0 }
350
+ stub(@tl).arrival_fuel_cost { 100.0 }
351
+
352
+ @tl.total_fuel_cost.should == 100.0
353
+ end
354
+
355
+ it 'should have a total cost if there are both arrival and departure fuel expense costs' do
356
+ stub(@tl).departure_fuel_cost { 100.0 }
357
+ stub(@tl).arrival_fuel_cost { 100.0 }
358
+
359
+ @tl.total_fuel_cost.should == 200.0
360
+ end
361
+ end
362
+ end
363
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 30
9
- version: 0.5.30
8
+ - 31
9
+ version: 0.5.31
10
10
  platform: ruby
11
11
  authors:
12
12
  - Patrick Lardin, Daniel Sudol
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-08 00:00:00 -08:00
17
+ date: 2011-03-09 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ files:
71
71
  - Rakefile
72
72
  - VERSION
73
73
  - fossil.gemspec
74
+ - lib/dbr_models/flight_log_expense.rb
74
75
  - lib/dbr_models/group_cost.rb
75
76
  - lib/dbr_models/personnel.rb
76
77
  - lib/dbr_models/quote.rb
@@ -197,6 +198,7 @@ files:
197
198
  - spec/helper_methods.rb
198
199
  - spec/models/airport_fbo_spec.rb
199
200
  - spec/models/code_spec.rb
201
+ - spec/models/flight_log_expense_spec.rb
200
202
  - spec/models/quote_spec.rb
201
203
  - spec/models/trip_leg_spec.rb
202
204
  - spec/models/trip_spec.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/helper_classes.rb
263
265
  - spec/models/code_spec.rb
264
266
  - spec/models/trip_leg_spec.rb
267
+ - spec/models/flight_log_expense_spec.rb
265
268
  - spec/models/quote_spec.rb
266
269
  - spec/models/vendor_document_spec.rb
267
270
  - spec/models/trip_spec.rb