module Logistics module Core class FreightTonStorageRatesController < ApplicationController def index rate_period_id = params[:rate_period_id] @freight_ton_storage_rates = FreightTonStorageRate.where('warehouse_rate_period_id' => rate_period_id) freight_ton_storage_rate_array =[] @freight_ton_storage_rates.each { |fsr| freight_ton_storage_rate_array.push({:id => fsr.id, :transaction_name => fsr.transaction_type.name, :content_type_name => fsr.content_type.name, :rate => fsr.rate, :effective_date => fsr.effective_date }) } @response = Mks::Common::MethodResponse.new(true, nil, freight_ton_storage_rate_array, nil, nil) render json: @response end def create FreightTonStorageRate.generate_storage_rate params[:rate_period_id], params[:effective_date] response = Mks::Common::MethodResponse.new(true, 'Freight ton storage rate matrix generated successfully !', nil, nil, nil) render json: response end def update freight_ton_storage_rates = params[:freight_ton_storage_rates] freight_ton_storage_rates.each { |fsr| old_freight_ton_storage_rate = FreightTonStorageRate.find(fsr['id']) old_freight_ton_storage_rate.rate = fsr['rate'] old_freight_ton_storage_rate.effective_date = fsr['effective_date'] old_freight_ton_storage_rate.save } @response = Mks::Common::MethodResponse.new(true, 'Freight ton storage 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 freight_ton_storage_rate_params params.require(:freight_ton_storage_rate).permit(:warehouse_rate_period_id, :rate, :effective_date, :transaction_type_id) end end end end