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