Class: Logistics::Core::BreakBulkRatesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /break_bulk_rates POST /break_bulk_rates.json



27
28
29
30
31
# File 'app/controllers/logistics/core/break_bulk_rates_controller.rb', line 27

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

#indexObject

GET /break_bulk_rates GET /break_bulk_rates.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/logistics/core/break_bulk_rates_controller.rb', line 8

def index
  @break_bulk_rates = BreakBulkRate.all
  break_bulk_rate_array =[]
  @break_bulk_rates.each { |bbr|
    break_bulk_rate_array.push({:id =>bbr.id, :service_delivery_unit_id => bbr.chargeable_service_unit_of_charge.service_delivery_unit_id,
                               :service_delivery_unit_name => bbr.chargeable_service_unit_of_charge.service_delivery_unit.name,
                               :transaction_type_id => bbr.transaction_type_id,:transaction_type_name => bbr.transaction_type.name,
                               :chargeable_service_id => bbr.chargeable_service_unit_of_charge.chargeable_service_id,
                               :chargeable_service_name => bbr.chargeable_service_unit_of_charge.chargeable_service.name,
                               :low => bbr.low, :medium => bbr.medium, :margin => bbr.margin,
                               :high => bbr.high, :effective_date => bbr.effective_date})
  }
  @response = {:success => true, :message => '', :data =>break_bulk_rate_array}
  render json: @response
end

#updateObject

PATCH/PUT /break_bulk_rates/1 PATCH/PUT /break_bulk_rates/1.json



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/logistics/core/break_bulk_rates_controller.rb', line 35

def update
  service_rates = params[:updated_service_rates]
  service_rates.each { |service_rate|
    old_service_rate = BreakBulkRate.find(service_rate['id'])
    old_service_rate.medium = service_rate['medium']
    old_service_rate.high = service_rate['high']
    old_service_rate.low = service_rate['low']
    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