module Logistics module Core class DemurageRatePeriodsController < ApplicationController before_action :set_demurage_rate_period, only: [:update] def index carrier_agent_id = params[:carrier_agent_id] @demurage_rate_periods = DemurrageRatePeriod.where('carrier_agent_id' => carrier_agent_id) demurage_rate_period_array =[] @demurage_rate_periods.each { |drp| ca = CarrierAgent.find(drp.carrier_agent_id) demurage_rate_period_array.push({:id => drp.id, :name => ca.carrier.name + ' ' +ca.agent.name, :from => drp.from, :to => drp.to, :rate_period => drp.rate_period, :carrier_agent_id => drp.carrier_agent_id }) } @response = Mks::Common::MethodResponse.new(true, nil, demurage_rate_period_array, nil, nil) render json: @response end def create @demurage_rate_period = DemurrageRatePeriod.new(demurage_rate_period_params) if @demurage_rate_period.valid? @demurage_rate_period.save @response = Mks::Common::MethodResponse.new(true, 'Demurage rate period saved successfully !',nil,nil,nil); render json: @response else errors = Mks::Common::Util.error_messages @demurage_rate_period, 'DemurrageRatePeriod' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end def update if @demurage_rate_period.update_attributes(demurage_rate_period_params) @demurage_rate_period.save @response = Mks::Common::MethodResponse.new(true, 'Demurage rate period updated successfully !', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages @demurage_rate_period, 'DemurrageRatePeriod' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end private # Use callbacks to share common setup or constraints between actions. def set_demurage_rate_period @demurage_rate_period = DemurrageRatePeriod.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def demurage_rate_period_params params.require(:demurage_rate_period).permit(:carrier_agent_id, :rate_period, :from, :to) end end end end