Sha256: 5bca773eb8b0f4a2dcb26dcc1b4ff370cd7fac8256e94427f7da458fc72709a4

Contents?: true

Size: 1.94 KB

Versions: 9

Compression:

Stored size: 1.94 KB

Contents

module Logistics
  module Core
    class ContainerDemurageRatesController < ApplicationController
      def index
        rate_period_id = params[:rate_period_id]
        @container_demurage_rates = ContainerDemurrageRate.where('demurrage_rate_period_id' => rate_period_id)
        container_demurage_rate_array =[]
        @container_demurage_rates.each { |dr|
          container_demurage_rate_array.push({:id => dr.id, :container_size_name=> dr.container_size.name,
                                    :transaction_name => dr.transaction_type.name,
                                    :container_type_name => dr.container_type.name,
                                    :rate => dr.rate
                                   })
        }
        @response = Mks::Common::MethodResponse.new(true, nil, container_demurage_rate_array, nil, nil)
        render json: @response
      end

      def create
        ContainerDemurrageRate.generate_demurage_rate params[:rate_period_id]
        response = Mks::Common::MethodResponse.new(true, 'Container demurage rate matrix generated successfully !', nil, nil, nil)
        render json: response
      end

      def update
        container_demurage_rates = params[:container_demurage_rates]
        container_demurage_rates.each { |cdr|
          old_container_demurage_rate = ContainerDemurrageRate.find(cdr['id'])
          old_container_demurage_rate.rate = cdr['rate']
          old_container_demurage_rate.save
        }
        @response = Mks::Common::MethodResponse.new(true, 'Container demurage rate(s) updated successfully !', nil, nil, nil)
        render json: @response
      end

      private

      # Never trust parameters from the scary internet, only allow the white list through.
      def container_demurage_rate_params
        params.require(:container_demurage_rate).permit(:demurrage_rate_period_id, :rate, :container_size_id, :transaction_type_id, :container_type_id, :content_type_id)
      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/container_demurage_rates_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/container_demurage_rates_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/container_demurage_rates_controller.rb