Sha256: a59cc672a83eb62886d154b0386a66ddb3c7aa60ef8fd50699ba6ddd24d47ca2

Contents?: true

Size: 1.95 KB

Versions: 9

Compression:

Stored size: 1.95 KB

Contents

module Logistics
  module Core
    class ItemRatesController < ApplicationController

      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

      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

      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

      private

      # Never trust parameters from the scary internet, only allow the white list through.
      def item_rate_params
        params.require(:item_rate).permit(:chargeable_service_unit_of_charge_id, :effective_date, :minimum_quantity, :rate)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/item_rates_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/item_rates_controller.rb