fossil 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/fossil.gemspec +3 -1
- data/lib/fossil.rb +46 -0
- data/lib/models/aircraft.rb +0 -4
- data/lib/models/airport.rb +0 -10
- data/lib/models/one_cost.rb +0 -10
- data/lib/models/passenger.rb +0 -5
- data/lib/models/quote.rb +0 -129
- data/lib/models/quote_leg.rb +0 -62
- data/lib/models/trip.rb +0 -72
- data/lib/models/trip_leg.rb +1 -523
- data/lib/number_helper.rb +303 -0
- data/lib/sequel/model_patch.rb +0 -2
- metadata +3 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/fossil.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fossil}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
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"]
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
"Rakefile",
|
17
17
|
"VERSION",
|
18
18
|
"fossil.gemspec",
|
19
|
+
"lib/fossil.rb",
|
19
20
|
"lib/models/ac_qualification.rb",
|
20
21
|
"lib/models/aircraft.rb",
|
21
22
|
"lib/models/aircraft_cost.rb",
|
@@ -108,6 +109,7 @@ Gem::Specification.new do |s|
|
|
108
109
|
"lib/models/vendor.rb",
|
109
110
|
"lib/models/vendor_document.rb",
|
110
111
|
"lib/models/visa.rb",
|
112
|
+
"lib/number_helper.rb",
|
111
113
|
"lib/sequel/code_group.rb",
|
112
114
|
"lib/sequel/fos_dates.rb",
|
113
115
|
"lib/sequel/metaprogramming.rb",
|
data/lib/fossil.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
gem 'sequel', '=3.5.0'
|
5
|
+
p require 'sequel'
|
6
|
+
rescue LoadError => e
|
7
|
+
warn 'To use Fossil you need the sequel gem:'
|
8
|
+
warn '$ sudo gem install sequel -v=3.5.0'
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
gem 'activesupport', '=2.3.5'
|
14
|
+
p require 'active_support'
|
15
|
+
rescue LoadError => e
|
16
|
+
p e
|
17
|
+
warn 'To use Fossil you need the active_support gem:'
|
18
|
+
warn '$ sudo gem install active_support -v=2.3.5'
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
files = [File.join('lib','number_helper.rb')] +
|
23
|
+
[File.join('lib','sequel','serializer','serializer.rb')] +
|
24
|
+
Dir.glob(File.join('lib','sequel','*.rb')) +
|
25
|
+
Dir.glob(File.join('lib','models','*.rb'))
|
26
|
+
|
27
|
+
class MockDataset < Sequel::Dataset
|
28
|
+
def insert(*args); end
|
29
|
+
def insert_select(*args); end
|
30
|
+
def update(*args); end
|
31
|
+
def fetch_rows(sql); end
|
32
|
+
def quoted_identifier(c); end
|
33
|
+
end
|
34
|
+
|
35
|
+
class MockDatabase < Sequel::Database
|
36
|
+
def execute(sql, opts={}); end
|
37
|
+
def reset; end
|
38
|
+
def transaction(opts={}); end
|
39
|
+
def dataset; MockDataset.new(self); end
|
40
|
+
end
|
41
|
+
|
42
|
+
MOCK_DB = MockDatabase.new unless defined?(MOCK_DB)
|
43
|
+
|
44
|
+
Sequel::Model.db = MOCK_DB
|
45
|
+
|
46
|
+
files.each{|file| p file;require file}
|
data/lib/models/aircraft.rb
CHANGED
@@ -389,9 +389,5 @@ class Aircraft < Sequel::Model(:'aircraft')
|
|
389
389
|
column_alias :key9, :'key9'
|
390
390
|
#### END GENERATED SECTION ####
|
391
391
|
|
392
|
-
AIRCRAFT_TYPES_IN_USE = ['C750','CL30','PRM1']
|
393
|
-
def self.in_use
|
394
|
-
filter(~:serial_number => '', :type_id => AIRCRAFT_TYPES_IN_USE).select(:aircraft_id, :type_id, :tail_number).order(:type_id, :tail_number).all
|
395
|
-
end
|
396
392
|
end
|
397
393
|
|
data/lib/models/airport.rb
CHANGED
@@ -243,14 +243,4 @@ class Airport < Sequel::Model(:'airport')
|
|
243
243
|
column_alias :key9, :'key9'
|
244
244
|
#### END GENERATED SECTION ####
|
245
245
|
|
246
|
-
INFO_BY_ICAO_FIELDS =
|
247
|
-
[:iata, :icao, :time_zone, :city, :state, :country, :runway_length, :runway_width, :elevation,
|
248
|
-
:runways, :instruments, :latitude, :longitude, :clearance_frequency,
|
249
|
-
:ground_frequency, :tower_frequency, :atis_frequency, :awos_frequency, :awos_phone]
|
250
|
-
|
251
|
-
#Information about an Airport given its ICAO code
|
252
|
-
def self.info_by_icao(icao)
|
253
|
-
airport = Airport.filter(:icao => icao.upcase).select(*INFO_BY_ICAO_FIELDS).first
|
254
|
-
airport ? airport.fill_hash(INFO_BY_ICAO_FIELDS) : {}
|
255
|
-
end
|
256
246
|
end
|
data/lib/models/one_cost.rb
CHANGED
@@ -85,14 +85,4 @@ class OneCost < Sequel::Model(:'one cost')
|
|
85
85
|
column_alias :key1, :'key1'
|
86
86
|
#### END GENERATED SECTION ####
|
87
87
|
|
88
|
-
####### for GetAdditionalCostsDetail web service #######
|
89
|
-
column_view :item_total, :precision
|
90
|
-
|
91
|
-
ONE_COST_FIELDS = {
|
92
|
-
'cost_type_value_code' => 'CostType',
|
93
|
-
'item_total_precision' => 'ItemTotal',
|
94
|
-
'quantity' => 'Quantity'
|
95
|
-
}
|
96
|
-
ONE_COST_FIELDS.each{|k,v| alias_method v, k }
|
97
|
-
####### end GetAdditionalCostsDetail web service #######
|
98
88
|
end
|
data/lib/models/passenger.rb
CHANGED
@@ -328,9 +328,4 @@ class Passenger < Sequel::Model(:'passengers')
|
|
328
328
|
column_alias :key9, :'key9'
|
329
329
|
#### END GENERATED SECTION ####
|
330
330
|
|
331
|
-
def self.requesters
|
332
|
-
requesters = filter(:pax_is_a_requester=>1).select(:kid_date,:kid_time,:kid_mult,:kid_comm,:name).order(:name).all
|
333
|
-
requesters.each{|r| r.name= r.name.strip} # some names have white space at the beginning
|
334
|
-
requesters
|
335
|
-
end
|
336
331
|
end
|
data/lib/models/quote.rb
CHANGED
@@ -333,133 +333,4 @@ class Quote < Sequel::Model(:'quotes - original')
|
|
333
333
|
column_alias :unused_quote_number, :'unused quote number'
|
334
334
|
#### END GENERATED SECTION ####
|
335
335
|
|
336
|
-
######## for ipc Quote Web Service ##########
|
337
|
-
column_view :deadhead_flight_time, :time
|
338
|
-
column_view :deadhead_ft, :time
|
339
|
-
column_view :deadhead_bt, :time
|
340
|
-
column_view :dh_taxi, :time
|
341
|
-
column_view :standby_elap_time, :time, :standby_elapsed_time
|
342
|
-
column_view :pass_flight_time, :time
|
343
|
-
column_view :time_quoted, :time
|
344
|
-
column_view :taxi, :time
|
345
|
-
column_view :eft, :time, :estimated_flight_time
|
346
|
-
column_view :ete, :time, :estimated_time_enroute
|
347
|
-
column_view :date_quoted, :date
|
348
|
-
column_view :invoice_date, :date
|
349
|
-
column_view :sched_date, :date
|
350
|
-
column_view :federal_tax, :precision
|
351
|
-
column_view :federal_tax, :precision
|
352
|
-
column_view :dh_legs_cost, :precision
|
353
|
-
column_view :day_trip_addon_cost, :precision
|
354
|
-
column_view :pax_legs_cost, :precision
|
355
|
-
column_view :layover_cost, :precision
|
356
|
-
column_view :standby_cost, :precision
|
357
|
-
column_view :ron_cost, :precision
|
358
|
-
column_view :delta_leg_cost, :precision
|
359
|
-
column_view :delta_trip_cost, :precision
|
360
|
-
column_view :ac_cost_subtotal, :precision
|
361
|
-
column_view :rate_percent_adjust, :precision
|
362
|
-
column_view :ac_cost_total, :precision
|
363
|
-
column_view :fuel_cost, :precision
|
364
|
-
column_view :additional_cost, :precision
|
365
|
-
column_view :total_tax, :precision
|
366
|
-
column_view :quote_total_cost, :precision
|
367
|
-
column_view :rate_percent, :precision
|
368
|
-
column_view :equivalent_rate_cost, :precision
|
369
|
-
column_view :state_tax, :precision
|
370
|
-
column_view :ac_rate, :precision
|
371
|
-
column_view :dh_rate, :precision
|
372
|
-
column_view :day_trip_addon_cost, :precision
|
373
|
-
column_view :paid, :boolean
|
374
|
-
column_view :actual_times, :boolean
|
375
|
-
column_view :scheduled_itinerary, :boolean
|
376
|
-
column_view :approved, :boolean
|
377
|
-
column_view :scheduled, :boolean
|
378
|
-
column_view :invoiced, :boolean
|
379
|
-
column_view :invoice_ready, :boolean
|
380
|
-
column_view :pass_ft_fixed, :boolean
|
381
|
-
column_view :confirmed, :boolean
|
382
|
-
|
383
|
-
delegate :employee_number, :to => :requester, :prefix => true, :allow_nil => true
|
384
|
-
delegate :terms, :to => :requester, :prefix => true, :allow_nil => true
|
385
|
-
delegate :bill_department, :to => :requester, :prefix => true, :allow_nil => true
|
386
|
-
delegate :bill_name, :to => :requester, :prefix => true, :allow_nil => true
|
387
|
-
delegate :costs, :to => :group_cost, :prefix => :one_cost, :allow_nil => true
|
388
|
-
delegate :company_code_value_description, :to => :aircraft, :prefix => :aircraft, :allow_nil => true
|
389
|
-
delegate :base_code_value_description, :to => :aircraft, :prefix => :aircraft, :allow_nil => true
|
390
|
-
|
391
|
-
QUOTE_FIELD_MAP = {
|
392
|
-
'confirmation_number' => 'ConfirmationNumber',
|
393
|
-
'requester_employee_number' => 'ClientNumber',
|
394
|
-
'invoice_number' => 'InvoiceNumber',
|
395
|
-
'date_quoted_date_view_mdy_ipc' => 'DateQuoted',
|
396
|
-
'quoted_trip_departure_date_view_mdy_ipc' => 'TripDepartureDate',
|
397
|
-
'contact_key' => 'ContactKey',
|
398
|
-
'company_key' => 'CompanyKey',
|
399
|
-
'quoted_for_company' => 'QuotedForCompany',
|
400
|
-
'requester_bill_name' => 'CompanyBillToName',
|
401
|
-
'quoted_trip_arrival_date_view_mdy_ipc' => 'TripArrivalDate',
|
402
|
-
'time_quoted_time_view' => 'TimeQuoted',
|
403
|
-
'pax_legs_cost_precision' => 'PaxLegsCost',
|
404
|
-
'pax_legs_addon' => 'PaxLegsAddon',
|
405
|
-
'dh_legs_cost_precision' => 'DHLegsCost',
|
406
|
-
'dh_legs_addon' => 'DHLegsAddon',
|
407
|
-
'standby_cost_precision' => 'StandbyCost',
|
408
|
-
'layover_cost_precision' => 'LayoverCost',
|
409
|
-
'ron_cost_precision' => 'RONCost',
|
410
|
-
'day_trip_addon_cost_precision' => 'Day_TripAddonCost',
|
411
|
-
'delta_leg_cost_precision' => 'DeltaLegCost',
|
412
|
-
'delta_trip_cost_precision' => 'DeltaTripCost',
|
413
|
-
'ac_cost_subtotal_precision' => 'AircraftCostSubtotal',
|
414
|
-
'rate_percent_adjust_precision' => 'RatePercentAdjust',
|
415
|
-
'ac_cost_total_precision' => 'AircraftCostTotal',
|
416
|
-
'fuel_cost_precision' => 'FuelCost',
|
417
|
-
'additional_cost_precision' => 'AdditionalCost',
|
418
|
-
'total_tax_precision' => 'TotalTax',
|
419
|
-
'quote_total_cost_precision' => 'QuoteTotalCost',
|
420
|
-
'nautical_miles' => 'NauticalMiles',
|
421
|
-
'statute_miles' => 'StatuteMiles',
|
422
|
-
'standby_elapsed_time_view' => 'StandbyElapsedTime',
|
423
|
-
'estimated_flight_time_view' => 'EstimatedFlightTime',
|
424
|
-
'taxi_time_view' => 'Taxi',
|
425
|
-
'estimated_time_enroute_view' => 'EstimatedTimeEnroute',
|
426
|
-
'pax' => 'Pax',
|
427
|
-
'crew' => 'Crew',
|
428
|
-
'rate_percent' => 'RatePercent',
|
429
|
-
'quoted_by' => 'QuotedBy',
|
430
|
-
'aircraft_type_id' => 'AircraftTypeID',
|
431
|
-
'aircraft_id' => 'AircraftID',
|
432
|
-
'confirmed_boolean_view' => 'Confirmed',
|
433
|
-
'scheduled_boolean_view' => 'Scheduled',
|
434
|
-
'pass_flight_time_time_view' => 'PassFlightTime',
|
435
|
-
'deadhead_flight_time_time_view' => 'DHFlightTime',
|
436
|
-
'equivalent_rate_cost_precision' => 'EquivalentRateCost',
|
437
|
-
'invoiced_boolean_view' => 'Invoiced',
|
438
|
-
'paid_boolean_view' => 'Paid',
|
439
|
-
'actual_times_boolean_view' => 'ActualTimes',
|
440
|
-
'scheduled_itinerary_boolean_view'=> 'ScheduledItinerary',
|
441
|
-
'invoice_date_date_view_mdy_ipc' => 'InvoiceDate',
|
442
|
-
'approved_boolean_view' => 'Approved',
|
443
|
-
'invoice_ready_boolean_view' => 'InvoiceReady',
|
444
|
-
'ac_base_code_value_description' => 'AircraftBaseCode',
|
445
|
-
'aircraft_company_code_value_description' => 'AircraftCompanyCode',
|
446
|
-
'trip_type_value_description' => 'TripType',
|
447
|
-
'purpose_code' => 'TripPurpose',
|
448
|
-
'federal_tax_precision' => 'FederalTax',
|
449
|
-
'state_tax_precision' => 'StateTax',
|
450
|
-
'ac_rate_precision' => 'AircraftRate',
|
451
|
-
'dh_rate_precision' => 'DHRate',
|
452
|
-
'deadhead_ft_time_view' => 'DHFT',
|
453
|
-
'deadhead_bt_time_view' => 'DHBT',
|
454
|
-
'sched_date_date_view_mdy_ipc' => 'SchedDate',
|
455
|
-
'dh_taxi_time_view' => 'DHTaxi',
|
456
|
-
'ac_cost_rate_ft' => 'AircraftCostRateFt',
|
457
|
-
}
|
458
|
-
QUOTE_FIELD_MAP.each{|k,v| alias_method v, k }
|
459
|
-
|
460
|
-
delegate :comment, :to => :client_invoice_comment, :prefix => true, :allow_nil => true
|
461
|
-
CLIENT_INVOICE_MAP = {
|
462
|
-
'client_invoice_comment_comment' => 'Comment' }
|
463
|
-
CLIENT_INVOICE_MAP.each{|k,v| alias_method v, k }
|
464
|
-
######## for for Quote Web Service ##########
|
465
336
|
end
|
data/lib/models/quote_leg.rb
CHANGED
@@ -336,66 +336,4 @@ class QuoteLeg < Sequel::Model(:'quote legs original')
|
|
336
336
|
column_alias :column_2, :'column_2'
|
337
337
|
#### END GENERATED SECTION ####
|
338
338
|
|
339
|
-
def airframe_hours
|
340
|
-
aircraft_hours/60
|
341
|
-
end
|
342
|
-
|
343
|
-
######## Fields and view mapping for QuoteLeg Web Service ##########
|
344
|
-
column_view :arrival_date_local, :date, :planned_arrival_date_local
|
345
|
-
column_view :depart_date_local, :date, :planned_departure_date_local
|
346
|
-
column_view :eta_gmt, :time, :planned_arrival_time_gmt
|
347
|
-
column_view :etd_gmt, :time, :planned_departure_time_gmt
|
348
|
-
column_view :eta_local, :time, :planned_arrival_time_local
|
349
|
-
column_view :etd_local, :time, :planned_departure_time_local
|
350
|
-
column_view :arrival_date_gmt, :date, :planned_arrival_date_gmt
|
351
|
-
column_view :dept_date_gmt, :date, :planned_departure_date_gmt
|
352
|
-
column_view :ete, :time
|
353
|
-
column_view :egt, :time
|
354
|
-
column_view :eft, :time
|
355
|
-
column_view :taxi_time, :time
|
356
|
-
column_view :additional_time, :time
|
357
|
-
column_view :deadhead, :boolean
|
358
|
-
column_view :status, :boolean
|
359
|
-
column_view :closed, :boolean
|
360
|
-
column_view :restricted, :boolean
|
361
|
-
column_view :never_scheduled, :boolean
|
362
|
-
column_view :international_leg, :boolean
|
363
|
-
|
364
|
-
QUOTE_LEGS_FIELD_MAP = {
|
365
|
-
'leg_number' => 'LegNumber',
|
366
|
-
'aircraft_type_id' => 'AircraftTypeID',
|
367
|
-
'time_zone_change' => 'TimeZoneChange',
|
368
|
-
'requester_name_key' => 'RequesterNameKey',
|
369
|
-
'aircraft_id' => 'AircraftID',
|
370
|
-
'departure_icao' => 'DepartureICAO',
|
371
|
-
'arrival_icao' => 'ArrivalICAO',
|
372
|
-
'planned_departure_time_gmt_view' => 'ETDGMT',
|
373
|
-
'planned_arrival_time_gmt_view' => 'ETAGMT',
|
374
|
-
'planned_departure_date_gmt_view_mdy_ipc' => 'DeptDateGMT',
|
375
|
-
'planned_arrival_date_gmt_view_mdy_ipc' => 'ArrivalDateGMT',
|
376
|
-
'planned_departure_time_local_view' => 'ETDLocal',
|
377
|
-
'planned_arrival_time_local_view' => 'ETALocal',
|
378
|
-
'planned_departure_date_local_view_mdy_ipc' => 'DepartDateLocal',
|
379
|
-
'planned_arrival_date_local_view_mdy_ipc' => 'ArrivalDateLocal',
|
380
|
-
'egt_time_view' => 'EGT',
|
381
|
-
'eft_time_view' => 'EFT',
|
382
|
-
'taxi_time_time_view' => 'TaxiTime',
|
383
|
-
'additional_time_time_view' => 'AdditionalTime',
|
384
|
-
'ete_time_view' => 'ETE',
|
385
|
-
'pax_count' => 'PaxCount',
|
386
|
-
'nautical_miles' => 'NauticalMiles',
|
387
|
-
'statute_miles' => 'StatuteMiles',
|
388
|
-
'leg_type_value_description' => 'LegTypeCode',
|
389
|
-
'leg_purpose_value_code' => 'LegPurposeCode',
|
390
|
-
'deadhead_boolean_view' => 'Deadhead',
|
391
|
-
'status_boolean_view' => 'Status',
|
392
|
-
'closed_boolean_view' => 'IsClosed',
|
393
|
-
'restricted_boolean_view' => 'Restricted',
|
394
|
-
'never_scheduled_boolean_view' => 'NeverScheduled',
|
395
|
-
'international_leg_boolean_view' => 'InternationalLeg',
|
396
|
-
'regulation_code_description' => 'Regulation'
|
397
|
-
}
|
398
|
-
|
399
|
-
QUOTE_LEGS_FIELD_MAP.each{|k,v| alias_method v, k }
|
400
|
-
######## end Fields and view mapping for QuoteLeg Web Service ##########
|
401
339
|
end
|
data/lib/models/trip.rb
CHANGED
@@ -52,9 +52,6 @@ class Trip < Sequel::Model(:'trips')
|
|
52
52
|
code_association :approval_code, :'approval_code', :trip_approval
|
53
53
|
code_association :special_qualification, :'specialqualification', :special_qualification
|
54
54
|
|
55
|
-
# Column views
|
56
|
-
column_view :kid_date, :date, :scheduled_date
|
57
|
-
|
58
55
|
#### BEGIN GENERATED SECTION ####
|
59
56
|
set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time']
|
60
57
|
|
@@ -270,73 +267,4 @@ class Trip < Sequel::Model(:'trips')
|
|
270
267
|
column_alias :reserved_3, :'reserved 3'
|
271
268
|
#### END GENERATED SECTION ####
|
272
269
|
|
273
|
-
def passenger_list
|
274
|
-
return '' unless passengers
|
275
|
-
pax_list = passengers.collect{|v| (v.lead_pax==1 ? "Lead Pax " : '' ) + v.name}.uniq!
|
276
|
-
pax_list ? pax_list.join(" : ") : ''
|
277
|
-
end
|
278
|
-
|
279
|
-
##### start trip_invoicing_report #######
|
280
|
-
TRIP_INVOICING_REPORT_PATH = File.join(RAILS_ROOT,'public','system','reports')
|
281
|
-
TRIP_INVOICING_FILE_NAME = 'AccountsReceiveableTripInvoicing.csv'
|
282
|
-
TRIP_INVOICING_REPORT_FILE_PATH = File.join(TRIP_INVOICING_REPORT_PATH,TRIP_INVOICING_FILE_NAME)
|
283
|
-
|
284
|
-
delegate :invoice_ready, :to=> :quote, :prefix => true, :allow_nil => true
|
285
|
-
|
286
|
-
column_view :status, :boolean
|
287
|
-
column_view :status_closed, :boolean
|
288
|
-
column_view :cancel_code, :boolean
|
289
|
-
column_view :arrival_date_gmt, :date, :planned_arrival_date_gmt
|
290
|
-
|
291
|
-
def quote_status
|
292
|
-
( quote_invoice_ready == 1 ) ? "Ready" : "Not Ready"
|
293
|
-
end
|
294
|
-
|
295
|
-
def date_difference(to_date)
|
296
|
-
(to_date - planned_arrival_date_gmt).to_i
|
297
|
-
end
|
298
|
-
|
299
|
-
def trip_requester_name
|
300
|
-
name = trip_requester.name if trip_requester
|
301
|
-
name || requester_name
|
302
|
-
end
|
303
|
-
|
304
|
-
TRIP_INVOICING_HEADERS =
|
305
|
-
['Date Trip Completed', 'Trip Number', 'Tail Number', 'Client', 'Trip Completed',
|
306
|
-
'Trip Cancelled', 'Trip Closed', 'Quote Status', 'Trip Type', "Number of Days from PCS to AR"]
|
307
|
-
|
308
|
-
TRIP_INVOICING_FIELDS =
|
309
|
-
[:planned_arrival_date_gmt_view_mdy, :trip_number, :ac_tail_number, :trip_requester_name,
|
310
|
-
:status_boolean_view, :cancel_code_boolean_view, :status_closed_boolean_view,
|
311
|
-
:quote_status, :trip_type_value_description]
|
312
|
-
|
313
|
-
def self.create_trip_invoicing_report(to_date)
|
314
|
-
from_date = to_date - 30
|
315
|
-
trips = trip_invoicing_report_query(from_date, to_date).sort_by{|t| t.date_difference(to_date) }
|
316
|
-
# write the csv file
|
317
|
-
FasterCSV.open(TRIP_INVOICING_REPORT_FILE_PATH, "w") do |csv|
|
318
|
-
csv << TRIP_INVOICING_HEADERS
|
319
|
-
trips.each do |trip|
|
320
|
-
csv << TRIP_INVOICING_FIELDS.collect{|field| trip.send(field)} + [trip.date_difference(to_date)]
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
def self.trip_invoicing_report_query(from_date, to_date)
|
326
|
-
unless @trip_invoicing_report_ps
|
327
|
-
ds = Trip.
|
328
|
-
filter( :arrival_date_gmt >= :$from_date).filter( :arrival_date_gmt <= :$to_date ).
|
329
|
-
filter( :trip_number > 0 ).
|
330
|
-
eager_graph(:trip_requester, :quote, :trip_type_value).
|
331
|
-
select_fields(
|
332
|
-
:self => [:trip_number, :requester_name, :arrival_date_gmt, :trip_number, :trip_type_code,
|
333
|
-
:ac_tail_number, :status, :status_closed, :cancel_code],
|
334
|
-
:quote => [:invoice_ready],
|
335
|
-
:trip_type_value => [:code, :description],
|
336
|
-
:trip_requester => [:name])
|
337
|
-
@trip_invoicing_report_ps = ds.prepare(:select, :trip_invoicing_report_ps)
|
338
|
-
end
|
339
|
-
@trip_invoicing_report_ps.call(:from_date=> from_date.to_fos_days, :to_date => (to_date+1).to_fos_days)
|
340
|
-
end
|
341
|
-
##### end trip_invoicing_report #######
|
342
270
|
end
|
data/lib/models/trip_leg.rb
CHANGED
@@ -63,95 +63,6 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
63
63
|
code_association :trip_type, :'leg type code', :trip_type
|
64
64
|
code_association :special_qualification, :'specialqualification', :special_qualification
|
65
65
|
|
66
|
-
# Column alias overrides
|
67
|
-
column_view :dept_date_act_gmt, :date, :actual_departure_date_gmt
|
68
|
-
column_view :dept_time_act_gmt, :time, :actual_departure_time_gmt
|
69
|
-
column_def_datetime :actual_departure_date_time_gmt, :'dept date act gmt', :'dept time act gmt'
|
70
|
-
|
71
|
-
column_view :arrival_date_gmt, :date, :actual_arrival_date_gmt
|
72
|
-
column_view :arriv_time_act_gmt, :time, :actual_arrival_time_gmt
|
73
|
-
column_def_datetime :actual_arrival_date_time_gmt, :'arr date act gmt', :'arriv time act gmt'
|
74
|
-
|
75
|
-
column_view :dept_date_act_local, :date, :actual_departure_date_local
|
76
|
-
column_view :dept_time_act_local, :time, :actual_departure_time_local
|
77
|
-
column_def_datetime :actual_departure_date_time_local, :'dept date act local', :'dept time act local'
|
78
|
-
|
79
|
-
column_view :arrival_date_local, :date, :actual_arrival_date_local
|
80
|
-
column_view :arriv_time_act_local, :time, :actual_arrival_time_local
|
81
|
-
column_def_datetime :actual_arrival_date_time_local, :'arr date act local', :'arriv time act local'
|
82
|
-
|
83
|
-
column_view :dept_date_gmt, :date, :planned_departure_date_gmt
|
84
|
-
column_view :etd_gmt, :time, :planned_departure_time_gmt
|
85
|
-
column_def_datetime :planned_departure_date_time_gmt, :'dept date gmt', :'etd - gmt'
|
86
|
-
|
87
|
-
column_view :depart_date_local, :date, :planned_departure_date_local
|
88
|
-
column_view :etd_local, :time, :planned_departure_time_local
|
89
|
-
column_def_datetime :planned_departure_date_time_local, :'depart date - local', :'etd - local'
|
90
|
-
|
91
|
-
column_view :arrival_date_gmt, :date, :planned_arrival_date_gmt
|
92
|
-
column_view :eta_gmt, :time, :planned_arrival_time_gmt
|
93
|
-
column_def_datetime :planned_arrival_date_time_gmt, :'arrival date gmt', :'eta - gmt'
|
94
|
-
|
95
|
-
column_view :arrival_date_local, :date, :planned_arrival_date_local
|
96
|
-
column_view :eta_local, :time, :planned_arrival_time_local
|
97
|
-
column_def_datetime :planned_arrival_date_time_local, :'arrival date - local', :'eta - local'
|
98
|
-
|
99
|
-
column_view :dept_date_act_home, :date, :actual_departure_date_base
|
100
|
-
column_view :depart_time_act_home, :time, :actual_departure_time_base
|
101
|
-
column_def_datetime :actual_departure_date_time_base_old, :'dept date act home', :'depart time act home'
|
102
|
-
def actual_departure_date_time_base() actual_departure_date_time_gmt + (home_tz_gmt_offset*360); end
|
103
|
-
|
104
|
-
column_view :arr_date_act_home, :date, :actual_arrival_date_base
|
105
|
-
column_view :arrival_time_act_hom, :time, :actual_arrival_time_base
|
106
|
-
column_def_datetime :actual_arrival_date_time_base_old, :'arr date act home', :'arrival time act hom'
|
107
|
-
def actual_arrival_date_time_base() actual_arrival_date_time_gmt + (home_tz_gmt_offset*360); end
|
108
|
-
|
109
|
-
#Time Formatting Methods
|
110
|
-
column_view :ete, :time
|
111
|
-
column_view :eft, :time
|
112
|
-
column_view :flight_time_actual, :time, :aft_time
|
113
|
-
column_view :block_time_actual, :time, :abt_time
|
114
|
-
column_view :t_o_time_act_gmt, :time, :actual_takeoff_time_gmt
|
115
|
-
column_view :land_time_act_gmt, :time, :actual_land_time_gmt
|
116
|
-
column_view :delay_1_time, :time, :delay_1_duration
|
117
|
-
column_view :delay_2_time, :time, :delay_2_duration
|
118
|
-
|
119
|
-
|
120
|
-
delegate :tail_number, :to => :aircraft
|
121
|
-
delegate :max_pax, :to => :aircraft
|
122
|
-
delegate :name, :to => :airport_fbo, :prefix => true, :allow_nil => true
|
123
|
-
delegate :name, :to => :fueler, :prefix => true, :allow_nil => true
|
124
|
-
delegate :name, :to => :lead_passenger, :prefix => true, :allow_nil => true
|
125
|
-
delegate :name, :to => :trip_requester, :prefix => true, :allow_nil => true
|
126
|
-
delegate :lead_pax, :to => :trip
|
127
|
-
delegate :passenger_list, :to => :trip
|
128
|
-
delegate :name, :to => :lead_pax, :prefix => true, :allow_nil => true
|
129
|
-
|
130
|
-
# :'status' utility methods
|
131
|
-
@@Statuses = {
|
132
|
-
'Scheduled Flight'=>0,
|
133
|
-
'Leg Verified'=>1,
|
134
|
-
'Cancelled'=>10,
|
135
|
-
'Reserved'=>20,
|
136
|
-
'Maintenance'=>21,
|
137
|
-
'Available'=>22,
|
138
|
-
'All Legs Cancelled'=>23,
|
139
|
-
'Standby'=>24,
|
140
|
-
'Note'=>31
|
141
|
-
}
|
142
|
-
|
143
|
-
def TripLeg.get_all_statuses
|
144
|
-
@@Statuses
|
145
|
-
end
|
146
|
-
|
147
|
-
def TripLeg.to_leg_status_values(names)
|
148
|
-
names.map{ |name| @@Statuses[name] }
|
149
|
-
end
|
150
|
-
|
151
|
-
def status_name
|
152
|
-
@@Statuses.index(self[:status])
|
153
|
-
end
|
154
|
-
|
155
66
|
|
156
67
|
#### BEGIN GENERATED SECTION ####
|
157
68
|
set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time']
|
@@ -713,437 +624,4 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
713
624
|
column_alias :key8, :'key8'
|
714
625
|
#### END GENERATED SECTION ####
|
715
626
|
|
716
|
-
|
717
|
-
def client_name
|
718
|
-
theStatus = trip_status
|
719
|
-
!(theStatus=='MAINT' || theStatus=='RESVD') ? requester : ''
|
720
|
-
end
|
721
|
-
|
722
|
-
def ebt_time
|
723
|
-
theStatus = trip_status
|
724
|
-
if theStatus='SCHED' || theStatus='VERI' || (arrival_ap_prefix != departure_ap_prefix)
|
725
|
-
minutes_between = (planned_arrival_date_time_gmt - planned_departure_date_time_gmt)/60;
|
726
|
-
return Time.from_fos_time(minutes_between)
|
727
|
-
end
|
728
|
-
Time.from_fos_time(0)
|
729
|
-
end
|
730
|
-
|
731
|
-
# get pic or sic or purser for this trip leg. type should be :pic or :sic or :pur
|
732
|
-
def pilot_code(type)
|
733
|
-
return '' unless type
|
734
|
-
cl = crew_legs.find{|cl| cl.position_code_code == type.to_s.upcase }
|
735
|
-
return cl ? cl.crew : ''
|
736
|
-
end
|
737
|
-
def pic; pilot_code(:pic); end
|
738
|
-
def sic; pilot_code(:sic); end
|
739
|
-
|
740
|
-
|
741
|
-
##### for the web service TripLegsByDate #######
|
742
|
-
column_view :closed, :boolean
|
743
|
-
column_view :cancelled, :boolean
|
744
|
-
column_view :never_scheduled, :boolean
|
745
|
-
column_view :trip_request, :boolean
|
746
|
-
column_view :is_deadhead?, :boolean
|
747
|
-
|
748
|
-
def status_code
|
749
|
-
return "Cancelled" if cancel_code != 0
|
750
|
-
case status
|
751
|
-
when 0 then "Scheduled"
|
752
|
-
when 1 then "Leg Verified"
|
753
|
-
when 10 then "Cancelled"
|
754
|
-
when 23 then "All Legs Cancelled"
|
755
|
-
when 21 then "Maintenance"
|
756
|
-
when 20 then "Reserved"
|
757
|
-
else "[#{status}]"
|
758
|
-
end
|
759
|
-
end
|
760
|
-
|
761
|
-
TRIP_LEGS_FIELD_MAP =
|
762
|
-
{
|
763
|
-
'status_code' => 'TripLegStatus',
|
764
|
-
'leg_number' => 'leg',
|
765
|
-
'trip_requester_name' => 'Requester',
|
766
|
-
'requester_name_key' => 'reqnamekey',
|
767
|
-
'aircraft_id' => 'AircraftID',
|
768
|
-
'leg_count' => 'LegCount',
|
769
|
-
'departure_icao' => 'DepartICAO',
|
770
|
-
'arrival_icao' => 'ArrivalICAO',
|
771
|
-
'planned_departure_date_gmt_view_mdy_ipc' => 'DepartDateZulu',
|
772
|
-
'planned_arrival_date_gmt_view_mdy_ipc' => 'ArriveDateZulu',
|
773
|
-
'planned_departure_date_local_view_mdy_ipc' => 'DepartDateLocal',
|
774
|
-
'planned_arrival_date_local_view_mdy_ipc' => 'ArriveDateLocal',
|
775
|
-
'planned_departure_time_gmt_view' => 'DepartTimeZulu',
|
776
|
-
'planned_arrival_time_gmt_view' => 'ArriveTimeZulu',
|
777
|
-
'planned_departure_time_local_view' => 'DepartTimeLocal',
|
778
|
-
'planned_arrival_time_local_view' => 'ArriveTimeLocal',
|
779
|
-
'pax_count' => 'PaxCount',
|
780
|
-
'is_deadhead?_boolean_view' => 'Deadhead',
|
781
|
-
'status' => 'Status',
|
782
|
-
'closed_boolean_view' => 'Closed',
|
783
|
-
'cancelled_boolean_view' => 'Cancelled',
|
784
|
-
'cancel_code' => 'CancelCode',
|
785
|
-
'never_scheduled_boolean_view' => 'NeverScheduled',
|
786
|
-
'trip_request_boolean_view' => 'TripRequest',
|
787
|
-
'trip_number' => 'TripNumber',
|
788
|
-
'tail_number' => 'TailNumber',
|
789
|
-
'aircraft_type_id' => 'AircraftType',
|
790
|
-
'fueler_name' => 'DEPFBOName',
|
791
|
-
'airport_fbo_name' => 'ARRFBOName',
|
792
|
-
'pic' => 'CrewPIC',
|
793
|
-
'sic' => 'CrewSIC',
|
794
|
-
'lead_pax_name' => 'LeadPax'
|
795
|
-
}
|
796
|
-
|
797
|
-
|
798
|
-
TRIP_LEGS_FIELD_MAP.each{|k,v| alias_method v, k }
|
799
|
-
##### END for web service TripLegsByDate #######
|
800
|
-
|
801
|
-
subset(:live_departures, :'trip legs__status'=>[0,1], :'trip legs__cancel_code'=>0, ~:leg_type_code=>[7, 103, 113])
|
802
|
-
subset(:maintenance_legs, :status=>21, :leg_type_code=>7 )
|
803
|
-
|
804
|
-
def self.trip_legs_by_date_range(from_date, to_date)
|
805
|
-
unless @trip_legs_by_date_ps
|
806
|
-
ds = TripLeg.
|
807
|
-
filter( :depart_date_key >= :$from_date).filter( :depart_date_key <= :$to_date ).
|
808
|
-
filter( ~:'trip legs__status'=> 31 ). # exclude comments which have status 31
|
809
|
-
eager_graph(:crew_legs => :position_code).eager_graph(:aircraft, :fueler, :airport_fbo, :trip_requester, :trip).
|
810
|
-
select_fields(
|
811
|
-
:self => [:trip_number, :leg_number, :arrival_icao, :departure_icao, :depart_ap_prefix,
|
812
|
-
:arrival_icao_iata_id, :arrival_icao, :arrival_iata, :arrival_ap_prefix, :arrival_airport_id,
|
813
|
-
:time_zone_change, :dept_date_gmt, :arrival_date_gmt, :depart_date_local,
|
814
|
-
:arrival_date_local, :ete, :etd_local, :eta_local, :etd_gmt, :eta_gmt,
|
815
|
-
:passengers_actual, :pax_count, :leg_count, :requester, :requester_name_key,
|
816
|
-
:aircraft_type_id, :leg_type_code, :trip_request, :fuel_burned, :deadhead,
|
817
|
-
:status, :closed, :cancelled, :cancel_code, :never_scheduled],
|
818
|
-
:crew_legs => [:crew, :position],
|
819
|
-
:crew_legs__position_code => [:code],
|
820
|
-
:aircraft => [:max_pax, :tail_number, :aircraft_id],
|
821
|
-
:fueler => [:name],
|
822
|
-
:airport_fbo => [:name],
|
823
|
-
:trip_requester => [:name],
|
824
|
-
:trip => [:approval_code]).
|
825
|
-
order(:'trip legs__trip_number',:'trip legs__leg_number')
|
826
|
-
@trip_legs_by_date_ps = ds.prepare(:select, :trip_legs_by_date_ps)
|
827
|
-
end
|
828
|
-
@trip_legs_by_date_ps.call(:from_date=> from_date.to_fos_days, :to_date => to_date.to_fos_days)
|
829
|
-
end
|
830
|
-
|
831
|
-
def pic_val; pic.blank? ? "N/A" : pic; end
|
832
|
-
def sic_val; sic.blank? ? "N/A" : sic; end
|
833
|
-
|
834
|
-
CRES_LIVE_DEPARTURES_FIELDS = [
|
835
|
-
:trip_number, :leg_number, :arrival_icao, :departure_icao, :time_zone_change,
|
836
|
-
:pax_count, :passengers_actual, :tail_number, :max_pax,
|
837
|
-
:pic_val, :sic_val, :requester, :ete_time_view,
|
838
|
-
:actual_departure_date_gmt, :planned_arrival_date_gmt,
|
839
|
-
:planned_departure_time_local_view, :planned_arrival_time_local_view
|
840
|
-
]
|
841
|
-
|
842
|
-
IROPS_LIVE_DEPARTURES_FIELDS = CRES_LIVE_DEPARTURES_FIELDS.dup << :lead_pax_name
|
843
|
-
|
844
|
-
def self.live_departures_by_date_range(from_date, to_date)
|
845
|
-
unless @live_departures_by_date_ps
|
846
|
-
ds = TripLeg.live_departures.
|
847
|
-
filter( :depart_date_key >= :$from_date).filter( :depart_date_key <= :$to_date ).
|
848
|
-
eager_graph(:crew_legs => :position_code).eager_graph(:aircraft,:trip).
|
849
|
-
select_fields(
|
850
|
-
:self => [:trip_number, :leg_number, :arrival_icao, :departure_icao, :requester,
|
851
|
-
:time_zone_change, :dept_date_gmt, :arrival_date_gmt, :depart_date_local,
|
852
|
-
:arrival_date_local, :ete, :etd_local, :eta_local, :etd_gmt, :eta_gmt, :dept_date_act_gmt,
|
853
|
-
:status, :closed, :cancelled, :cancel_code, :passengers_actual, :pax_count],
|
854
|
-
:crew_legs => [:crew, :position],
|
855
|
-
:crew_legs__position_code => [:code],
|
856
|
-
:trip => [:approval_code], # picked just any field so i can get the primary key fields also
|
857
|
-
:aircraft => [:max_pax, :tail_number]).
|
858
|
-
order(:'trip legs__trip_number',:'trip legs__leg_number')
|
859
|
-
@live_departures_by_date_ps = ds.prepare(:select, :live_departures_by_date_ps)
|
860
|
-
end
|
861
|
-
@live_departures_by_date_ps.call(:from_date=> from_date.to_fos_days, :to_date => to_date.to_fos_days)
|
862
|
-
end
|
863
|
-
|
864
|
-
def self.live_departures_by_date(date)
|
865
|
-
live_departures_by_date_range(date, date)
|
866
|
-
end
|
867
|
-
|
868
|
-
def self.daily_report_by_date_range(from_date, to_date)
|
869
|
-
unless @daily_report_by_date_ps
|
870
|
-
ds = TripLeg.live_departures.
|
871
|
-
filter( :depart_date_key >= :$from_date).filter( :depart_date_key <= :$to_date ).
|
872
|
-
filter( :cancel_code => 0).
|
873
|
-
eager_graph(:crew_legs => :position_code).eager_graph(:aircraft).
|
874
|
-
select_fields(
|
875
|
-
:self => [:trip_number, :leg_number, :arrival_icao, :departure_icao, :requester,
|
876
|
-
:time_zone_change, :dept_date_gmt, :arrival_date_gmt, :depart_date_local,
|
877
|
-
:arrival_date_local, :ete, :etd_local, :eta_local, :etd_gmt, :eta_gmt,
|
878
|
-
:status, :closed, :cancelled, :cancel_code, :passengers_actual, :pax_count],
|
879
|
-
:crew_legs => [:crew, :position],
|
880
|
-
:crew_legs__position_code => [:code],
|
881
|
-
:aircraft => [:max_pax, :tail_number]).
|
882
|
-
order(:'trip legs__trip_number',:'trip legs__leg_number')
|
883
|
-
@daily_report_by_date_ps = ds.prepare(:select, :daily_report_by_date_ps)
|
884
|
-
end
|
885
|
-
@daily_report_by_date_ps.call(:from_date=> from_date.to_fos_days, :to_date => to_date.to_fos_days)
|
886
|
-
end
|
887
|
-
|
888
|
-
def self.daily_report_by_date(date)
|
889
|
-
daily_report_by_date_range(date, date)
|
890
|
-
end
|
891
|
-
|
892
|
-
def self.scheduled_maintenance_in_date_range(from_date, to_date)
|
893
|
-
maintenance_leg.filter(:depart_date_key => from_date.to_fos_days..to_date.to_fos_days)
|
894
|
-
end
|
895
|
-
|
896
|
-
##### for the trip_report query/service on crewres #######
|
897
|
-
# fields to return
|
898
|
-
TRIP_REPORT_FIELDS = [:trip_number, :leg_number,
|
899
|
-
:departure_icao_val, :arrival_icao_val, :aircraft_type_id, :tail_number,
|
900
|
-
:statute_miles, :trip_total_statute_miles, :miles, :fuel_burned,
|
901
|
-
:passengers_actual, :pax_count, :trip_status,
|
902
|
-
:planned_departure_date_local, :planned_departure_time_local_view,
|
903
|
-
:actual_arrival_date_local, :planned_arrival_time_local_view,
|
904
|
-
:actual_departure_time_gmt_view, :actual_arrival_time_gmt_view,
|
905
|
-
:actual_takeoff_time_gmt_view, :actual_land_time_gmt_view,
|
906
|
-
:eft_time, :ebt_time, :aft_time, :abt_time ]
|
907
|
-
|
908
|
-
def self.trip_report(from_date, to_date, hash)
|
909
|
-
extra_fields = hash['extra_fields'] ? hash['extra_fields'] : []
|
910
|
-
filters = []
|
911
|
-
filters << [const_get(hash['status_filter'])] if hash['status_filter']
|
912
|
-
filters << [LIMIT_AIRCRAFT_IDS, hash['aircraft_id_filter']] if hash['aircraft_id_filter']
|
913
|
-
filters << [LIMIT_REPORT_REQUESTER, hash['requester_filter']] if hash['requester_filter']
|
914
|
-
filters << [const_get(hash['regional_filter'])] if hash['regional_filter']
|
915
|
-
filters << [const_get(hash['icao_filter'][0]), hash['icao_filter'][1].split(',')] if hash['icao_filter']
|
916
|
-
# perform query and use filters ( if any ) to select trips that match
|
917
|
-
trip_legs = trip_report_query(from_date, to_date, extra_fields).select do |tl|
|
918
|
-
# all filters applied must be true, so finding one being false will deselect this trip leg
|
919
|
-
!filters.find{|filter, args| filter.call(tl,args) == false}
|
920
|
-
end
|
921
|
-
return trip_legs, {:methods=>(TRIP_REPORT_FIELDS + extra_fields)}
|
922
|
-
end
|
923
|
-
|
924
|
-
TRIP_REPORT_SELECT_FIELDS = { # fields to select in the query
|
925
|
-
:self => [:status, :cancel_code, :trip_number, :leg_number,
|
926
|
-
:requester_kid_date, :requester_kid_time, :requester_kid_mult, :requester_kid_comm,
|
927
|
-
:arrival_icao, :departure_icao, :depart_ap_prefix, :depart_airport_id, :aircraft_type_id,
|
928
|
-
:arrival_ap_prefix, :arrival_airport_id, :arrival_iata, :departure_iata,
|
929
|
-
:statute_miles, :fuel_burned, :regulation, :leg_type_code, :passengers_actual, :pax_count,
|
930
|
-
:dept_date_gmt, :dept_time_act_gmt, :arrival_date_gmt, :depart_date_local, :arriv_time_act_gmt,
|
931
|
-
:arrival_date_gmt, :arrival_date_local, :ete, :etd_local, :eta_local, :etd_gmt, :eta_gmt,
|
932
|
-
:t_o_time_act_gmt, :land_time_act_gmt, :eft, :flight_time_actual, :block_time_actual],
|
933
|
-
:aircraft => [:type_id, :tail_number, :aircraft_id],
|
934
|
-
:trip => [:total_statute_miles] }
|
935
|
-
|
936
|
-
EAGER_GRAPH_OPTIONS = [:aircraft, :trip]
|
937
|
-
|
938
|
-
def self.trip_report_query(from_date, to_date, extra_fields)
|
939
|
-
filter_args = {~:'trip legs__status'=> 31, :depart_date_key => from_date.to_fos_days..to_date.to_fos_days}
|
940
|
-
selecting_fields = TRIP_REPORT_SELECT_FIELDS.dup
|
941
|
-
eager_graph_options = EAGER_GRAPH_OPTIONS.dup
|
942
|
-
if extra_fields.include?('pic')
|
943
|
-
selecting_fields.merge!(:crew_legs => [:crew, :position],:crew_legs__position_code => [:code])
|
944
|
-
eager_graph_options += [{:crew_legs => :position_code}]
|
945
|
-
elsif extra_fields.include?('trip_requester_name')
|
946
|
-
selecting_fields.merge!(:trip_requester => [:name])
|
947
|
-
eager_graph_options += [:trip_requester]
|
948
|
-
end
|
949
|
-
TripLeg.filter(filter_args).eager_graph(eager_graph_options).select_fields(selecting_fields).all
|
950
|
-
end
|
951
|
-
|
952
|
-
#### aliases and special methods #####
|
953
|
-
# This method guarantees an icao for a view that needs one. If there is an icao, use it, otherwise make
|
954
|
-
# it from the prefix and airport_id .. which works as an icao, but beware, because these put together
|
955
|
-
# icao's that you make are valid icao codes, but you can't search the airport based it, since these
|
956
|
-
# airport rows don't have an icao code at all, they only have the prefix and airport_id. whacky.
|
957
|
-
def departure_icao_val
|
958
|
-
departure_icao || depart_ap_prefix + depart_airport_id
|
959
|
-
end
|
960
|
-
|
961
|
-
# same comment as above
|
962
|
-
def arrival_icao_val
|
963
|
-
arrival_icao || arrival_ap_prefix + arrival_airport_id
|
964
|
-
end
|
965
|
-
|
966
|
-
def departure_icao_expanded
|
967
|
-
"#{departure_icao_val} #{departure_airport.name} #{departure_airport.city} ,#{departure_airport.state_abbreviation}"
|
968
|
-
end
|
969
|
-
|
970
|
-
def arrival_icao_expanded
|
971
|
-
"#{arrival_icao_val} #{arrival_airport.name} #{arrival_airport.city} ,#{arrival_airport.state_abbreviation}"
|
972
|
-
end
|
973
|
-
|
974
|
-
def trip_status
|
975
|
-
return "CANC" if cancel_code != 0
|
976
|
-
case status
|
977
|
-
when 0 then "SCHED"
|
978
|
-
when 1 then "VERI"
|
979
|
-
when 10 then "CANC"
|
980
|
-
when 23 then "CANC"
|
981
|
-
when 21 then "MAINT"
|
982
|
-
when 20 then "SCHED" #was "RESVD"
|
983
|
-
else "[#{status}]"
|
984
|
-
end
|
985
|
-
end
|
986
|
-
|
987
|
-
def trip_total_statute_miles
|
988
|
-
trip ? trip.total_statute_miles.to_f/10.0 : 0
|
989
|
-
end
|
990
|
-
|
991
|
-
alias miles statute_miles
|
992
|
-
|
993
|
-
# special id which mushes 4 of the requester kids together.
|
994
|
-
# don't need 5th one( kid_user ) to get unique value, so not using it
|
995
|
-
def requester_id
|
996
|
-
[requester_kid_date,requester_kid_time,requester_kid_mult,requester_kid_comm].join('|')
|
997
|
-
end
|
998
|
-
|
999
|
-
#### status filters ##### ["CANC","SCHED", "VERI"]
|
1000
|
-
LIMIT_REPORT_STATUS_ONLY_UNVERIFIED = lambda {|v,args| ["CANC","SCHED"].include?(v.trip_status) }
|
1001
|
-
LIMIT_REPORT_STATUS_ONLY_VERIFIED = lambda {|v,args| ["VERI"].include?(v.trip_status) }
|
1002
|
-
LIMIT_REPORT_STATUS_ONLY_SCHEDULED = lambda {|v,args| ["SCHED"].include?(v.trip_status) }
|
1003
|
-
LIMIT_REPORT_STATUS_ONLY_UNVERIFIED_SHOW_CANCELLED_LEGS = lambda {|v,args| ["CANC","SCHED"].include?(v.trip_status) }
|
1004
|
-
LIMIT_REPORT_STATUS_ONLY_VERIFIED_SHOW_CANCELLED_LEGS = lambda {|v,args| ["CANC","VERI"].include?(v.trip_status) }
|
1005
|
-
LIMIT_REPORT_STATUS_ONLY_SCHEDULED_SHOW_CANCELLED_LEGS = lambda {|v,args| ["CANC","SCHED"].include?(v.trip_status) }
|
1006
|
-
SHOW_CANCELLED_LEGS = lambda {|v,args| ["CANC"].include?(v.trip_status) }
|
1007
|
-
#### region filters #####
|
1008
|
-
US_PREFIXES = ["K","PA","PF","PO","PP","PH"]
|
1009
|
-
LIMIT_REPORT_REGION_ONLY_INTERNATIONAL = lambda {|v,args| !US_PREFIXES.include?(v.depart_ap_prefix) }
|
1010
|
-
LIMIT_REPORT_REGION_ONLY_USA = lambda {|v,args| US_PREFIXES.include?(v.depart_ap_prefix) }
|
1011
|
-
#### request filter #####
|
1012
|
-
LIMIT_REPORT_REQUESTER = lambda {|v,requester_id| v.requester_id == requester_id }
|
1013
|
-
#### aircraft id filter #####
|
1014
|
-
LIMIT_AIRCRAFT_IDS = lambda {|v,aircraft_ids| aircraft_ids.include?(v.aircraft_id) }
|
1015
|
-
#### city pair filters #####
|
1016
|
-
LIMIT_CITY_PAIR_FROM_ICAO = lambda {|trip_leg,icao_arr| icao_arr.include?(trip_leg.departure_icao_val) }
|
1017
|
-
LIMIT_CITY_PAIR_TO_ICAO = lambda {|trip_leg,icao_arr| icao_arr.include?(trip_leg.arrival_icao_val) }
|
1018
|
-
LIMIT_CITY_PAIR_FROM_ICAO_COUNTRY_CODE = lambda {|trip_leg,country_codes| country_codes.include?(trip_leg.depart_ap_prefix) }
|
1019
|
-
LIMIT_CITY_PAIR_TO_ICAO_COUNTRY_CODE = lambda {|trip_leg,country_codes| country_codes.include?(trip_leg.arrival_ap_prefix) }
|
1020
|
-
CITY_PAIR_SPECIFIC_FIELDS = [:depart_ap_prefix, :departure_iata, :arrival_ap_prefix, :arrival_iata]
|
1021
|
-
# The vars param is an array of filters for the 4 fields that correspond to CITY_PAIR_SPECIFIC_FIELDS.
|
1022
|
-
# If the vars array is ['K','SFO'] then this filter should check that the depart_ap_prefix matches 'K'
|
1023
|
-
# and the depart_iata matches 'SFO'.
|
1024
|
-
LIMIT_CITY_PAIR_SPECIFIC = lambda {|trip_leg,vars|
|
1025
|
-
CITY_PAIR_SPECIFIC_FIELDS.enum_with_index.find{|field,idx|
|
1026
|
-
# check to see if the field value is not equal to the filter but only check if there is a filter for that field
|
1027
|
-
trip_leg.send(field) != vars[idx] unless vars[idx].blank?
|
1028
|
-
}.blank?
|
1029
|
-
# if all matched ok, then returns nil, and if one of the filters did not match then will have
|
1030
|
-
# the value of that non matching field. So, if result is blank?, this trip leg is valid
|
1031
|
-
}
|
1032
|
-
##### END the trip_report query/service on crewres #######
|
1033
|
-
|
1034
|
-
|
1035
|
-
############ kbi report ###############
|
1036
|
-
def is_deadhead?
|
1037
|
-
status==1 and (deadhead==1 or pax_count==0) and [107, 115, 108, 104].include? leg_type_code
|
1038
|
-
end
|
1039
|
-
|
1040
|
-
def is_owner_occupied?
|
1041
|
-
status==1 and deadhead==0 and pax_count>0 and [107, 115, 108, 104].include? leg_type_code
|
1042
|
-
end
|
1043
|
-
|
1044
|
-
def self.kbi_stats(date)
|
1045
|
-
start_date_month, end_date_month = date.beginning_of_month, date.end_of_month
|
1046
|
-
start_date_week, end_date_week = date.beginning_of_week.to_fos_days, date.end_of_week.to_fos_days
|
1047
|
-
|
1048
|
-
hash = Hash.new {|k,v| k[v]=0}
|
1049
|
-
|
1050
|
-
trips = TripLeg.filter(:arrival_date_home=>start_date_month.to_fos_days..end_date_month.to_fos_days).
|
1051
|
-
select(:arrival_date_home, :aircraft_type_id, :flight_time_actual, :eft, :status, :pax_count, :deadhead, :leg_type_code)
|
1052
|
-
|
1053
|
-
occupied_hours = 0
|
1054
|
-
|
1055
|
-
trips.each do |trip|
|
1056
|
-
# hours scheduled/flown per aircraft type
|
1057
|
-
if ["C750","CL30"].include? trip.aircraft_type_id
|
1058
|
-
# month totals
|
1059
|
-
hash["hours_scheduled_month_#{trip.aircraft_type_id}"] += trip.eft / 60.0
|
1060
|
-
hash["hours_flown_month_#{trip.aircraft_type_id}"] += (trip.flight_time_actual / 60.0) if trip.status == 1
|
1061
|
-
# week totals
|
1062
|
-
if trip.arrival_date_home.between? start_date_week,end_date_week
|
1063
|
-
hash["hours_scheduled_week_#{trip.aircraft_type_id}"] += trip.eft / 60.0
|
1064
|
-
end
|
1065
|
-
end
|
1066
|
-
# month charter hours scheduled/flown
|
1067
|
-
if [100,11].include? trip.leg_type_code
|
1068
|
-
hash["hours_scheduled_month_charter"] += trip.eft / 60.0
|
1069
|
-
hash["hours_flown_month_charter"] += (trip.flight_time_actual / 60.0) if trip.status == 1
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
# owner deadhead month hours flown
|
1073
|
-
hash[:hours_flown_month_deadhead] += trip.flight_time_actual / 60.0 if trip.is_deadhead?
|
1074
|
-
# owner deadhead month hours flown
|
1075
|
-
hash[:hours_flown_month_owner] += trip.flight_time_actual / 60.0 if trip.is_owner_occupied?
|
1076
|
-
|
1077
|
-
# other hours flown month
|
1078
|
-
hash[:hours_flown_month_other] += trip.flight_time_actual / 60.0 if !([100,11,107,115,108,104].include? trip.leg_type_code)
|
1079
|
-
|
1080
|
-
# monthly passenger occupied hours
|
1081
|
-
if trip.pax_count > 0 && trip.deadhead == 0 and trip.status == 1
|
1082
|
-
occupied_hours += trip.flight_time_actual / 60.0
|
1083
|
-
end
|
1084
|
-
end
|
1085
|
-
|
1086
|
-
# calculate passenger utilization
|
1087
|
-
hours_flown = hash["hours_flown_month_C750"] + hash["hours_flown_month_CL30"]
|
1088
|
-
hash[:passenger_utilization] = (occupied_hours / hours_flown)*100 rescue 0
|
1089
|
-
# owner guaranteed deadhead percentage month
|
1090
|
-
hash[:owner_guarantee_deadhead] = (hash[:hours_flown_month_deadhead] / (hash[:hours_flown_month_deadhead] + hash[:hours_flown_month_owner])) * 100 rescue 0
|
1091
|
-
hash
|
1092
|
-
end
|
1093
|
-
|
1094
|
-
CUST_SATISFACTION_FIELDS =
|
1095
|
-
[:status_code, :actual_departure_date_gmt, :actual_departure_trip]
|
1096
|
-
|
1097
|
-
# filtering on these leg_type codes ["FXL", 107], ["FXM", 115], ["FXO", 108], ["TPGC", 121], ["TPGP", 122], ["XOLP", 104]
|
1098
|
-
#
|
1099
|
-
def customer_satisfaction_trip_report(date)
|
1100
|
-
trips = Trip.filter(:status=>1, ~:cancel_code=>1, :leg_type_code=> [104,107,108,115,121,122], :arrival_date_gmt=>date.to_fos_days).all
|
1101
|
-
|
1102
|
-
# :status, :dept_date_act_local, :dept_time_act_local, :requester
|
1103
|
-
# :leg_requestor => [:name, :authorizer_string ]
|
1104
|
-
|
1105
|
-
|
1106
|
-
# :status_code
|
1107
|
-
# :actual_departure_date_local, :actual_departure_time_local,
|
1108
|
-
# leg_requestor_name, :lead_pax_name
|
1109
|
-
# lead pax info: lead_pax.passenger.pax_office_phone, pax_email
|
1110
|
-
# planner info: lead_pax.passenger.travel_planner, pl_office_phone , pl_email
|
1111
|
-
# :depture_icao, :arrival_icao,
|
1112
|
-
# :leg_number
|
1113
|
-
# leg_requestor.authorizer_string, leg_requestor.name
|
1114
|
-
#
|
1115
|
-
# delay_1_time, :delay_1_reson
|
1116
|
-
# :statute_miles
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
#pp ts.collect{|t| t.trip_legs.collect{|tl| [tl.trip_number,tl.leg_number,tl.arrival_date_gmt,tl.arriv_time_act_gmt,tl.leg_type_code,tl.leg_type_value_code,tl.is_deadhead?]}}
|
1120
|
-
|
1121
|
-
# [[[68302, 1, 39928, 996, 11, "WHSL", false],
|
1122
|
-
# [68302, 2, 39928, 1332, 11, "WHSL", false]],
|
1123
|
-
# [[68085, 1, 39924, 684, 11, "WHSL", false],
|
1124
|
-
# [68085, 2, 39924, 930, 11, "WHSL", false],
|
1125
|
-
# [68085, 3, 39928, 1224, 11, "WHSL", false]],
|
1126
|
-
# [[68206, 1, 39927, 1050, 107, "FXL", true],
|
1127
|
-
# [68206, 2, 39928, 1218, 107, "FXL", false],
|
1128
|
-
# [68206, 3, 39928, 1242, 107, "FXL", true]],
|
1129
|
-
# [[68376, 1, 39928, 216, 107, "FXL", false],
|
1130
|
-
# [68376, 2, 39928, 222, 107, "FXL", true]],
|
1131
|
-
# [[68437, 1, 39928, 1068, 107, "FXL", true],
|
1132
|
-
# [68437, 2, 39928, 1308, 107, "FXL", false]],
|
1133
|
-
# [[68550, 1, 39928, 1164, 107, "FXL", true],
|
1134
|
-
# [68550, 2, 39928, 1398, 107, "FXL", false]],
|
1135
|
-
# [[68552, 1, 39928, 1332, 107, "FXL", false]],
|
1136
|
-
# [[68576, 1, 39928, 1404, 107, "FXL", false]],
|
1137
|
-
# [[68604, 1, 39928, 876, 107, "FXL", true],
|
1138
|
-
# [68604, 2, 39928, 1218, 107, "FXL", false]],
|
1139
|
-
# [[68607, 1, 39927, 1104, 107, "FXL", true],
|
1140
|
-
# [68607, 2, 39928, 738, 107, "FXL", false],
|
1141
|
-
# [68607, 3, 39928, 1026, 107, "FXL", false],
|
1142
|
-
# [68607, 4, 39928, 1074, 107, "FXL", true]],
|
1143
|
-
# [[68610, 1, 39928, 1122, 11, "WHSL", false],
|
1144
|
-
# [68610, 2, 39928, 1356, 11, "WHSL", false],
|
1145
|
-
# [68610, 3, 39928, 1374, 11, "WHSL", false]]]
|
1146
|
-
end
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
627
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers #:nodoc:
|
3
|
+
# Provides methods for converting numbers into formatted strings.
|
4
|
+
# Methods are provided for phone numbers, currency, percentage,
|
5
|
+
# precision, positional notation, and file size.
|
6
|
+
module NumberHelper
|
7
|
+
# Formats a +number+ into a US phone number (e.g., (555) 123-9876). You can customize the format
|
8
|
+
# in the +options+ hash.
|
9
|
+
#
|
10
|
+
# ==== Options
|
11
|
+
# * <tt>:area_code</tt> - Adds parentheses around the area code.
|
12
|
+
# * <tt>:delimiter</tt> - Specifies the delimiter to use (defaults to "-").
|
13
|
+
# * <tt>:extension</tt> - Specifies an extension to add to the end of the
|
14
|
+
# generated number.
|
15
|
+
# * <tt>:country_code</tt> - Sets the country code for the phone number.
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
# number_to_phone(5551234) # => 555-1234
|
19
|
+
# number_to_phone(1235551234) # => 123-555-1234
|
20
|
+
# number_to_phone(1235551234, :area_code => true) # => (123) 555-1234
|
21
|
+
# number_to_phone(1235551234, :delimiter => " ") # => 123 555 1234
|
22
|
+
# number_to_phone(1235551234, :area_code => true, :extension => 555) # => (123) 555-1234 x 555
|
23
|
+
# number_to_phone(1235551234, :country_code => 1) # => +1-123-555-1234
|
24
|
+
#
|
25
|
+
# number_to_phone(1235551234, :country_code => 1, :extension => 1343, :delimiter => ".")
|
26
|
+
# => +1.123.555.1234 x 1343
|
27
|
+
def number_to_phone(number, options = {})
|
28
|
+
number = number.to_s.strip unless number.nil?
|
29
|
+
options = options.symbolize_keys
|
30
|
+
area_code = options[:area_code] || nil
|
31
|
+
delimiter = options[:delimiter] || "-"
|
32
|
+
extension = options[:extension].to_s.strip || nil
|
33
|
+
country_code = options[:country_code] || nil
|
34
|
+
|
35
|
+
begin
|
36
|
+
str = ""
|
37
|
+
str << "+#{country_code}#{delimiter}" unless country_code.blank?
|
38
|
+
str << if area_code
|
39
|
+
number.gsub!(/([0-9]{1,3})([0-9]{3})([0-9]{4}$)/,"(\\1) \\2#{delimiter}\\3")
|
40
|
+
else
|
41
|
+
number.gsub!(/([0-9]{0,3})([0-9]{3})([0-9]{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
|
42
|
+
number.starts_with?('-') ? number.slice!(1..-1) : number
|
43
|
+
end
|
44
|
+
str << " x #{extension}" unless extension.blank?
|
45
|
+
str
|
46
|
+
rescue
|
47
|
+
number
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Formats a +number+ into a currency string (e.g., $13.65). You can customize the format
|
52
|
+
# in the +options+ hash.
|
53
|
+
#
|
54
|
+
# ==== Options
|
55
|
+
# * <tt>:precision</tt> - Sets the level of precision (defaults to 2).
|
56
|
+
# * <tt>:unit</tt> - Sets the denomination of the currency (defaults to "$").
|
57
|
+
# * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
|
58
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
|
59
|
+
# * <tt>:format</tt> - Sets the format of the output string (defaults to "%u%n"). The field types are:
|
60
|
+
#
|
61
|
+
# %u The currency unit
|
62
|
+
# %n The number
|
63
|
+
#
|
64
|
+
# ==== Examples
|
65
|
+
# number_to_currency(1234567890.50) # => $1,234,567,890.50
|
66
|
+
# number_to_currency(1234567890.506) # => $1,234,567,890.51
|
67
|
+
# number_to_currency(1234567890.506, :precision => 3) # => $1,234,567,890.506
|
68
|
+
#
|
69
|
+
# number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
|
70
|
+
# # => £1234567890,50
|
71
|
+
# number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u")
|
72
|
+
# # => 1234567890,50 £
|
73
|
+
def number_to_currency(number, options = {})
|
74
|
+
options.symbolize_keys!
|
75
|
+
|
76
|
+
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
|
77
|
+
currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :raise => true) rescue {}
|
78
|
+
defaults = defaults.merge(currency)
|
79
|
+
|
80
|
+
precision = options[:precision] || defaults[:precision]
|
81
|
+
unit = options[:unit] || defaults[:unit]
|
82
|
+
separator = options[:separator] || defaults[:separator]
|
83
|
+
delimiter = options[:delimiter] || defaults[:delimiter]
|
84
|
+
format = options[:format] || defaults[:format]
|
85
|
+
separator = '' if precision == 0
|
86
|
+
|
87
|
+
begin
|
88
|
+
format.gsub(/%n/, number_with_precision(number,
|
89
|
+
:precision => precision,
|
90
|
+
:delimiter => delimiter,
|
91
|
+
:separator => separator)
|
92
|
+
).gsub(/%u/, unit)
|
93
|
+
rescue
|
94
|
+
number
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Formats a +number+ as a percentage string (e.g., 65%). You can customize the
|
99
|
+
# format in the +options+ hash.
|
100
|
+
#
|
101
|
+
# ==== Options
|
102
|
+
# * <tt>:precision</tt> - Sets the level of precision (defaults to 3).
|
103
|
+
# * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
|
104
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
|
105
|
+
#
|
106
|
+
# ==== Examples
|
107
|
+
# number_to_percentage(100) # => 100.000%
|
108
|
+
# number_to_percentage(100, :precision => 0) # => 100%
|
109
|
+
# number_to_percentage(1000, :delimiter => '.', :separator => ',') # => 1.000,000%
|
110
|
+
# number_to_percentage(302.24398923423, :precision => 5) # => 302.24399%
|
111
|
+
def number_to_percentage(number, options = {})
|
112
|
+
options.symbolize_keys!
|
113
|
+
|
114
|
+
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
|
115
|
+
percentage = I18n.translate(:'number.percentage.format', :locale => options[:locale], :raise => true) rescue {}
|
116
|
+
defaults = defaults.merge(percentage)
|
117
|
+
|
118
|
+
precision = options[:precision] || defaults[:precision]
|
119
|
+
separator = options[:separator] || defaults[:separator]
|
120
|
+
delimiter = options[:delimiter] || defaults[:delimiter]
|
121
|
+
|
122
|
+
begin
|
123
|
+
number_with_precision(number,
|
124
|
+
:precision => precision,
|
125
|
+
:separator => separator,
|
126
|
+
:delimiter => delimiter) + "%"
|
127
|
+
rescue
|
128
|
+
number
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can
|
133
|
+
# customize the format in the +options+ hash.
|
134
|
+
#
|
135
|
+
# ==== Options
|
136
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
|
137
|
+
# * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
|
138
|
+
#
|
139
|
+
# ==== Examples
|
140
|
+
# number_with_delimiter(12345678) # => 12,345,678
|
141
|
+
# number_with_delimiter(12345678.05) # => 12,345,678.05
|
142
|
+
# number_with_delimiter(12345678, :delimiter => ".") # => 12.345.678
|
143
|
+
# number_with_delimiter(12345678, :separator => ",") # => 12,345,678
|
144
|
+
# number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",")
|
145
|
+
# # => 98 765 432,98
|
146
|
+
#
|
147
|
+
# You can still use <tt>number_with_delimiter</tt> with the old API that accepts the
|
148
|
+
# +delimiter+ as its optional second and the +separator+ as its
|
149
|
+
# optional third parameter:
|
150
|
+
# number_with_delimiter(12345678, " ") # => 12 345.678
|
151
|
+
# number_with_delimiter(12345678.05, ".", ",") # => 12.345.678,05
|
152
|
+
def number_with_delimiter(number, *args)
|
153
|
+
options = args.extract_options!
|
154
|
+
options.symbolize_keys!
|
155
|
+
|
156
|
+
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
|
157
|
+
|
158
|
+
unless args.empty?
|
159
|
+
ActiveSupport::Deprecation.warn('number_with_delimiter takes an option hash ' +
|
160
|
+
'instead of separate delimiter and precision arguments.', caller)
|
161
|
+
delimiter = args[0] || defaults[:delimiter]
|
162
|
+
separator = args[1] || defaults[:separator]
|
163
|
+
end
|
164
|
+
|
165
|
+
delimiter ||= (options[:delimiter] || defaults[:delimiter])
|
166
|
+
separator ||= (options[:separator] || defaults[:separator])
|
167
|
+
|
168
|
+
begin
|
169
|
+
parts = number.to_s.split('.')
|
170
|
+
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
|
171
|
+
parts.join(separator)
|
172
|
+
rescue
|
173
|
+
number
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Formats a +number+ with the specified level of <tt>:precision</tt> (e.g., 112.32 has a precision of 2).
|
178
|
+
# You can customize the format in the +options+ hash.
|
179
|
+
#
|
180
|
+
# ==== Options
|
181
|
+
# * <tt>:precision</tt> - Sets the level of precision (defaults to 3).
|
182
|
+
# * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
|
183
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
|
184
|
+
#
|
185
|
+
# ==== Examples
|
186
|
+
# number_with_precision(111.2345) # => 111.235
|
187
|
+
# number_with_precision(111.2345, :precision => 2) # => 111.23
|
188
|
+
# number_with_precision(13, :precision => 5) # => 13.00000
|
189
|
+
# number_with_precision(389.32314, :precision => 0) # => 389
|
190
|
+
# number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.')
|
191
|
+
# # => 1.111,23
|
192
|
+
#
|
193
|
+
# You can still use <tt>number_with_precision</tt> with the old API that accepts the
|
194
|
+
# +precision+ as its optional second parameter:
|
195
|
+
# number_with_precision(number_with_precision(111.2345, 2) # => 111.23
|
196
|
+
def number_with_precision(number, *args)
|
197
|
+
options = args.extract_options!
|
198
|
+
options.symbolize_keys!
|
199
|
+
|
200
|
+
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
|
201
|
+
precision_defaults = I18n.translate(:'number.precision.format', :locale => options[:locale],
|
202
|
+
:raise => true) rescue {}
|
203
|
+
defaults = defaults.merge(precision_defaults)
|
204
|
+
|
205
|
+
unless args.empty?
|
206
|
+
ActiveSupport::Deprecation.warn('number_with_precision takes an option hash ' +
|
207
|
+
'instead of a separate precision argument.', caller)
|
208
|
+
precision = args[0] || defaults[:precision]
|
209
|
+
end
|
210
|
+
|
211
|
+
precision ||= (options[:precision] || defaults[:precision])
|
212
|
+
separator ||= (options[:separator] || defaults[:separator])
|
213
|
+
delimiter ||= (options[:delimiter] || defaults[:delimiter])
|
214
|
+
|
215
|
+
begin
|
216
|
+
rounded_number = (Float(number) * (10 ** precision)).round.to_f / 10 ** precision
|
217
|
+
number_with_delimiter("%01.#{precision}f" % rounded_number,
|
218
|
+
:separator => separator,
|
219
|
+
:delimiter => delimiter)
|
220
|
+
rescue
|
221
|
+
number
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb].freeze
|
226
|
+
|
227
|
+
# Formats the bytes in +size+ into a more understandable representation
|
228
|
+
# (e.g., giving it 1500 yields 1.5 KB). This method is useful for
|
229
|
+
# reporting file sizes to users. This method returns nil if
|
230
|
+
# +size+ cannot be converted into a number. You can customize the
|
231
|
+
# format in the +options+ hash.
|
232
|
+
#
|
233
|
+
# ==== Options
|
234
|
+
# * <tt>:precision</tt> - Sets the level of precision (defaults to 1).
|
235
|
+
# * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
|
236
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
|
237
|
+
#
|
238
|
+
# ==== Examples
|
239
|
+
# number_to_human_size(123) # => 123 Bytes
|
240
|
+
# number_to_human_size(1234) # => 1.2 KB
|
241
|
+
# number_to_human_size(12345) # => 12.1 KB
|
242
|
+
# number_to_human_size(1234567) # => 1.2 MB
|
243
|
+
# number_to_human_size(1234567890) # => 1.1 GB
|
244
|
+
# number_to_human_size(1234567890123) # => 1.1 TB
|
245
|
+
# number_to_human_size(1234567, :precision => 2) # => 1.18 MB
|
246
|
+
# number_to_human_size(483989, :precision => 0) # => 473 KB
|
247
|
+
# number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,18 MB
|
248
|
+
#
|
249
|
+
# You can still use <tt>number_to_human_size</tt> with the old API that accepts the
|
250
|
+
# +precision+ as its optional second parameter:
|
251
|
+
# number_to_human_size(1234567, 2) # => 1.18 MB
|
252
|
+
# number_to_human_size(483989, 0) # => 473 KB
|
253
|
+
def number_to_human_size(number, *args)
|
254
|
+
return nil if number.nil?
|
255
|
+
|
256
|
+
options = args.extract_options!
|
257
|
+
options.symbolize_keys!
|
258
|
+
|
259
|
+
defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {}
|
260
|
+
human = I18n.translate(:'number.human.format', :locale => options[:locale], :raise => true) rescue {}
|
261
|
+
defaults = defaults.merge(human)
|
262
|
+
|
263
|
+
unless args.empty?
|
264
|
+
ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' +
|
265
|
+
'instead of a separate precision argument.', caller)
|
266
|
+
precision = args[0] || defaults[:precision]
|
267
|
+
end
|
268
|
+
|
269
|
+
precision ||= (options[:precision] || defaults[:precision])
|
270
|
+
separator ||= (options[:separator] || defaults[:separator])
|
271
|
+
delimiter ||= (options[:delimiter] || defaults[:delimiter])
|
272
|
+
|
273
|
+
storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
|
274
|
+
|
275
|
+
if number.to_i < 1024
|
276
|
+
unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => number.to_i, :raise => true)
|
277
|
+
storage_units_format.gsub(/%n/, number.to_i.to_s).gsub(/%u/, unit)
|
278
|
+
else
|
279
|
+
max_exp = STORAGE_UNITS.size - 1
|
280
|
+
number = Float(number)
|
281
|
+
exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024
|
282
|
+
exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
|
283
|
+
number /= 1024 ** exponent
|
284
|
+
|
285
|
+
unit_key = STORAGE_UNITS[exponent]
|
286
|
+
unit = I18n.translate(:"number.human.storage_units.units.#{unit_key}", :locale => options[:locale], :count => number, :raise => true)
|
287
|
+
|
288
|
+
begin
|
289
|
+
escaped_separator = Regexp.escape(separator)
|
290
|
+
formatted_number = number_with_precision(number,
|
291
|
+
:precision => precision,
|
292
|
+
:separator => separator,
|
293
|
+
:delimiter => delimiter
|
294
|
+
).sub(/(\d)(#{escaped_separator}[1-9]*)?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '')
|
295
|
+
storage_units_format.gsub(/%n/, formatted_number).gsub(/%u/, unit)
|
296
|
+
rescue
|
297
|
+
number
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
data/lib/sequel/model_patch.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fossil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Lardin, Daniel Sudol
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- VERSION
|
27
27
|
- fossil.gemspec
|
28
|
+
- lib/fossil.rb
|
28
29
|
- lib/models/ac_qualification.rb
|
29
30
|
- lib/models/aircraft.rb
|
30
31
|
- lib/models/aircraft_cost.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/models/vendor.rb
|
118
119
|
- lib/models/vendor_document.rb
|
119
120
|
- lib/models/visa.rb
|
121
|
+
- lib/number_helper.rb
|
120
122
|
- lib/sequel/code_group.rb
|
121
123
|
- lib/sequel/fos_dates.rb
|
122
124
|
- lib/sequel/metaprogramming.rb
|