Class: Logistics::Core::ServiceRatesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /service_rates POST /service_rates.json



31
32
33
34
35
# File 'app/controllers/logistics/core/service_rates_controller.rb', line 31

def create
  ServiceRate.generate_rate_for_containerized_chargeable_service(params[:effective_date])
  @response = {:success => true, :message => 'Rate table generated successfully', :data => []}
  render json: @response
end

#indexObject

GET /service_rates GET /service_rates.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/logistics/core/service_rates_controller.rb', line 8

def index
  service_rate_array = []
  @service_rates = ServiceRate.all#includes('chargeable_service').order("chargeable_services.order")
  @service_rates.each { |service_rate|
    service_rate_array.push({:id => service_rate.id,
                            :chargeable_service_name => service_rate.chargeable_service_unit_of_charge.chargeable_service.name,
                            :effective_date => service_rate.effective_date,:low => service_rate.low,
                            :medium => service_rate.medium, :high => service_rate.high,
                            :margin => service_rate.margin,
                            :container_size_id => service_rate.container_size_id,
                            :container_size_name => service_rate.container_size.name,
                            :transaction_type_id => service_rate.transaction_type_id,
                            :transaction_type_name => service_rate.transaction_type.name,
                            :service_delivery_unit_id => service_rate.chargeable_service_unit_of_charge.service_delivery_unit_id,
                            :service_delivery_unit_name => service_rate.chargeable_service_unit_of_charge.service_delivery_unit.name,
                            })
  }
  @response = {:success => true, :message => '', :data => service_rate_array}
  render json: @response
end

#updateObject

PATCH/PUT /service_rates/1 PATCH/PUT /service_rates/1.json



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/logistics/core/service_rates_controller.rb', line 39

def update
  service_rates = params[:updated_service_rates]
  service_rates.each { |service_rate|
    old_service_rate = ServiceRate.find(service_rate['id'])
    old_service_rate.low = service_rate['low']
    old_service_rate.medium = service_rate['medium']
    old_service_rate.high = service_rate['high']
    old_service_rate.margin = service_rate['margin']
    old_service_rate.effective_date = service_rate['effective_date']
    old_service_rate.save
  }
  @response = {:success => true, :message => 'Rate table updated successfully', :data => service_rates}
  render json: @response
end