Class: Logistics::Core::OutOfGaugeCntRatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/out_of_gauge_cnt_rates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /out_of_gauge_cnt_rates POST /out_of_gauge_cnt_rates.json



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/logistics/core/out_of_gauge_cnt_rates_controller.rb', line 26

def create
  out_of_gauge_cnt_rate = OutOfGaugeCntRate.new(out_of_gauge_cnt_rate_params)
  margin = out_of_gauge_cnt_rate_params[:margin]
  rate = out_of_gauge_cnt_rate_params[:rate]
  new_rate = rate + (rate * margin/100)
  out_of_gauge_cnt_rate.rate = new_rate


  if out_of_gauge_cnt_rate.save
    response = Mks::Common::MethodResponse.new(true, "Containerized Out of Gauge rate information saved successfully!", out_of_gauge_cnt_rate, nil, nil)
  else
    errors = Mks::Common::Util.error_messages out_of_gauge_cnt_rate,"Containerized Out of Gauge Rate"
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end

#indexObject

GET /out_of_gauge_cnt_rates GET /out_of_gauge_cnt_rates.json



11
12
13
14
15
# File 'app/controllers/logistics/core/out_of_gauge_cnt_rates_controller.rb', line 11

def index
  out_of_gauge_cnt_rates = OutOfGaugeCntRate.fetch_all
  response = Mks::Common::MethodResponse.new(true, nil, out_of_gauge_cnt_rates, nil, nil)
  render json: response
end

#search_routeObject



17
18
19
20
21
22
# File 'app/controllers/logistics/core/out_of_gauge_cnt_rates_controller.rb', line 17

def search_route
  route_id = params[:route][:id]
  route = Route.find(route_id)
  response = Mks::Common::MethodResponse.new(true, nil, route.margin, nil, nil)
  render json: response
end

#updateObject

PATCH/PUT /out_of_gauge_cnt_rates/1 PATCH/PUT /out_of_gauge_cnt_rates/1.json



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/logistics/core/out_of_gauge_cnt_rates_controller.rb', line 45

def update
  out_of_gauge_cnt_rate = OutOfGaugeCntRate.find(params[:id])
  margin = out_of_gauge_cnt_rate_params[:margin]
  if margin > out_of_gauge_cnt_rate.margin
    rate = out_of_gauge_cnt_rate_params[:rate]
    margin = margin - out_of_gauge_cnt_rate.margin
    new_rate = rate + (rate * margin/100)
    params[:out_of_gauge_cnt_rate][:rate] = new_rate
  end

  if out_of_gauge_cnt_rate.update(out_of_gauge_cnt_rate_params)
    response = Mks::Common::MethodResponse.new(true, "Containerized Out of Gauge rate information updated successfully!", out_of_gauge_cnt_rate, nil, nil)
  else
    errors = Mks::Common::Util.error_messages out_of_gauge_cnt_rate,"Containerized Out of Gauge Rate"
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end