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
|
# File 'app/models/logistics/core/car_carrier_rate.rb', line 45
def self.generate_car_carrier_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 = 'ICCarrier'
else
rate_type = 'WCCarrier'
end
new_car_carrier_rate_arr = []
current_car_carrier_rate = CarCarrierRate.where rate_type: rate_type
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_car_carrier_rate = { transporter_id: transporter.id, route_id: route.id,
break_bulk_unit_id: break_bulk_unit.id, transport_rate_period_id: rate_period[0].id,
rate_type: rate_type }
check_existing_rate = check_for_existing_rate current_car_carrier_rate, new_car_carrier_rate
if !check_existing_rate
new_car_carrier_rate = { transporter_id: transporter.id, route_id: route.id,
break_bulk_unit_id: break_bulk_unit.id, transport_rate_period_id: rate_period[0].id,
rate_type: rate_type, rate: 0, margin: route.margin }
new_car_carrier_rate_arr << new_car_carrier_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_car_carrier_rate_arr.count > 0
CarCarrierRate.create(new_car_carrier_rate_arr)
message = route_type + " Car Carrier Rate Generated Successfully!"
end
elsif rate_period.length == 0
message = "Transport Rate Period"
else
message = "Transporter"
end
if message == route_type + " Car Carrier 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
|