45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/models/logistics/core/self_driving_rate.rb', line 45
def self.generate_self_driving_rate route_type
message = ''
count = 0
routes = Route.where(route_type: route_type)
break_bulk_units = BreakBulkUnit.all
transporters = Transporter.where.not(name: 'Reference Transporter')
rate_period = TransportRatePeriod.where(current_period: true)
if route_type == 'Inter City'
rate_type = 'ICDriving'
else
rate_type = 'WCDriving'
end
current_self_driving_rate = SelfDrivingRate.where rate_type: rate_type
new_self_driving_rate_arr = []
if transporters.length > 0 && rate_period.length > 0
transporters.each do |transporter|
if routes.length > 0
routes.each do |route|
if break_bulk_units.length > 0
break_bulk_units.each do |break_bulk_unit|
new_self_driving_rate = { transporter_id: transporter.id,
route_id: route.id,
break_bulk_unit_id: break_bulk_unit.id,
rate_period_id: rate_period[0].id,
rate_type: rate_type }
check_existing_rate = check_for_existing_rate current_self_driving_rate, new_self_driving_rate
if !check_existing_rate
new_self_driving_rate = { transporter_id: transporter.id,
route_id: route.id,
break_bulk_unit_id: break_bulk_unit.id,
rate: 0,
margin: route.margin,
rate_period_id: rate_period[0].id,
rate_type: rate_type }
new_self_driving_rate_arr << new_self_driving_rate
else
count += 1
end
end
else
message = "Break Bulk Unit Types!"
break
end
end
else
message = route_type + " Transport Route!"
break
end
end
if new_self_driving_rate_arr.count > 0
SelfDrivingRate.create! new_self_driving_rate_arr
message = route_type + " Self Driving Rate Generated Successfully!"
end
elsif rate_period.length == 0
message = "Transport Rate Period!"
else
message = "Transporter!"
end
if message == route_type + " Self Driving Rate Generated Successfully!" || count > 0
message2 = ["A total of <b>" + count.to_s + "</b> Records have been skipped!"]
return {ind: 1, value: "", message: message, errors: message2}
else
error = ["No Record Found for <b>" + message + "</b>."]
return {ind: 0, value: "", message: error}
end
end
|