module Logistics module Core class ConvoyRatesController < ApplicationController def index @convoy_rates = ConvoyRate.all convoy_rates_array =[] @convoy_rates.each { |cr| convoy_rates_array.push({:id => cr.id, :high => cr.high, :low => cr.low, :medium => cr.medium, :effective_date => cr.effective_date, :service_delivery_unit_name => cr.chargeable_service_unit_of_charge.service_delivery_unit.name, :transaction_type_name => cr.transaction_type.name, :margin => cr.margin, :chargeable_service_name => cr.chargeable_service_unit_of_charge.chargeable_service.name}) } @response = Mks::Common::MethodResponse.new(true, nil, convoy_rates_array, nil, nil) render json: @response end # POST /bill_of_loading_rates # POST /bill_of_loading_rates.json def create effective_date = params[:effective_date] ConvoyRate.generate_rate_for_convoy_services(effective_date) @response = Mks::Common::MethodResponse.new(true, 'Rate generated successfully', nil, nil, nil) render json: @response end # PATCH/PUT /bill_of_loading_rates/1 # PATCH/PUT /bill_of_loading_rates/1.json def update service_rates = params[:updated_service_rates] service_rates.each { |service_rate| old_service_rate = ConvoyRate.find(service_rate['id']) old_service_rate.low = service_rate['low'] old_service_rate.medium = service_rate['medium'] old_service_rate.high = service_rate['high'] 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 !'); render json: @response end # Never trust parameters from the scary internet, only allow the white list through. def bill_of_loading_rate_params params.require(:convoy_rate).permit(:chargeable_service_unit_of_charge_id, :transaction_type_id, :low, :medium, :high, :effective_date) end end end end