module Logistics module Core class TwentyFeetEquivalentUnitRatesController < ApplicationController def index @twenty_feet_equivalence_unit_rates = TwentyFootEquivalenceUnitRate.all twenty_feet_equivalence_unit_rates_array =[] @twenty_feet_equivalence_unit_rates.each { |tfeur| twenty_feet_equivalence_unit_rates_array.push({:id => tfeur.id, :high => tfeur.high, :low => tfeur.low, :medium => tfeur.medium, :margin => tfeur.margin,:effective_date => tfeur.effective_date, :service_delivery_unit_name => tfeur.chargeable_service_unit_of_charge.service_delivery_unit.name, :transaction_type_name => tfeur.transaction_type.name, :chargeable_service_name => tfeur.chargeable_service_unit_of_charge.chargeable_service.name}) } @response = Mks::Common::MethodResponse.new(true, nil, twenty_feet_equivalence_unit_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] TwentyFootEquivalenceUnitRate.generate_rate_for_twenty_feet_equivalence_unit_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 = TwentyFootEquivalenceUnitRate.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 table successfully updated !', nil, nil, nil) render json: @response end end end end