module Logistics module Core class BreakBulkStorageRatesController < ApplicationController def index rate_period_id = params[:rate_period_id] @break_bulk_storage_rates = BreakBulkStorageRate.where('warehouse_rate_period_id' => rate_period_id) break_bulk_storage_rate_array =[] @break_bulk_storage_rates.each { |bbsr| break_bulk_storage_rate_array.push({:id => bbsr.id, :break_bulk_unit_name => bbsr.break_bulk_unit.name, :transaction_name => bbsr.transaction_type.name, :content_type_name => bbsr.content_type.name, :rate => bbsr.rate, :effective_date => bbsr.effective_date }) } @response = Mks::Common::MethodResponse.new(true, nil, break_bulk_storage_rate_array, nil, nil) render json: @response end def create BreakBulkStorageRate.generate_storage_rate params[:rate_period_id], params[:effective_date] response = Mks::Common::MethodResponse.new(true, 'Break bulk storage rate matrix generated successfully !', nil, nil, nil) render json: response end def update break_bulk_storage_rates = params[:break_bulk_storage_rates] break_bulk_storage_rates.each { |bbsr| old_break_bulk_storage_rate = BreakBulkStorageRate.find(bbsr['id']) old_break_bulk_storage_rate.rate = bbsr['rate'] old_break_bulk_storage_rate.effective_date = bbsr['effective_date'] old_break_bulk_storage_rate.save } @response = Mks::Common::MethodResponse.new(true, 'Break bulk 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 break_bulk_storage_rate_params params.require(:break_bulk_storage_rate).permit(:warehouse_rate_period_id, :rate, :effective_date, :transaction_type_id, :break_bulk_unit_id) end end end end