Class: Logistics::Core::ItemRatesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  effective_date = params[:effective_date]
  ItemRate.generate_rate_for_item_services(effective_date)
  @response = Mks::Common::MethodResponse.new(true, 'Rate generated successfully !', nil, nil, nil)
  render json: @response
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/logistics/core/item_rates_controller.rb', line 5

def index
  @items_rate = ItemRate.all
  items_rate_array =[]
  @items_rate.each { |ir|
    items_rate_array.push({:id => ir.id, :service_delivery_unit_name => ir.chargeable_service_unit_of_charge.service_delivery_unit.name,
                          :transaction_type_name => ir.transaction_type.name,
                          :chargeable_service_name => ir.chargeable_service_unit_of_charge.chargeable_service.name,
                          :minimum_quantity => ir.minimum_quantity, :rate => ir.rate, :margin => ir.margin})
  }
  @response = Mks::Common::MethodResponse.new(true,nil,items_rate_array,nil,nil);
  render json: @response
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/logistics/core/item_rates_controller.rb', line 25

def update
  service_rates = params[:updated_service_rates]
  service_rates.each { |service_rate|
    old_service_rate = ItemRate.find(service_rate['id'])
    old_service_rate.minimum_quantity = service_rate['minimum_quantity']
    old_service_rate.rate = service_rate['rate']
    old_service_rate.margin = service_rate['margin']
    old_service_rate.effective_date = service_rate['effective_date']
    old_service_rate.save
  }
  @response = Mks::Common::MethodResponse.new(true, 'Rate updated successfully !', nil,nil,nil)
  render json: @response
end