module Logistics module Core class ContractBreakBulkUnitRatesController < ApplicationController def index contract_break_bulk_unit_rate_array = [] @contract_break_bulk_unit_rates = ContractBreakBulkUnitRate.where(contract_id: params[:client_contract_id]) @contract_break_bulk_unit_rates.each { |contract_bbu_service_rate| contract_break_bulk_unit_rate_array.push({:id => contract_bbu_service_rate.id, :chargeable_service_name => contract_bbu_service_rate.chargeable_service_unit_of_charge.chargeable_service.name, :rate => contract_bbu_service_rate.rate, :margin => contract_bbu_service_rate.margin, :break_bulk_unit_id => contract_bbu_service_rate.break_bulk_unit_id, :break_bulk_unit_name => contract_bbu_service_rate.break_bulk_unit.name, :transaction_type_id => contract_bbu_service_rate.transaction_type_id, :transaction_type_name => contract_bbu_service_rate.transaction_type.name, :service_delivery_unit_id => contract_bbu_service_rate.chargeable_service_unit_of_charge.service_delivery_unit_id, :service_delivery_unit_name => contract_bbu_service_rate.chargeable_service_unit_of_charge.service_delivery_unit.name, :in_contract => contract_bbu_service_rate.in_contract, :contract_id => contract_bbu_service_rate.contract_id }) } @response = {:success => true, :message => '', :data => contract_break_bulk_unit_rate_array} render json: @response end # POST /service_rates # POST /service_rates.json def create ContractBreakBulkUnitRate.generate_rate_for_break_bulk_unit_service(params[:client_contract_id]) @response = {:success => true, :message => 'Rate table generated successfully', :data => []} render json: @response end # PATCH/PUT /service_rates/1 # PATCH/PUT /service_rates/1.json def update service_rates = params[:updated_service_rates] service_rates.each { |service_rate| old_service_rate = ContractBreakBulkUnitRate.find(service_rate['id']) old_service_rate.rate = service_rate['rate'] old_service_rate.in_contract = service_rate['in_contract'] old_service_rate.margin = service_rate['margin'] old_service_rate.save } @response = {:success => true, :message => 'Rate table updated successfully', :data => service_rates} render json: @response end private # Never trust parameters from the scary internet, only allow the white list through. def container_container_service_rate_params params.require(:service_rate).permit(:break_bulk_unit_id, :transaction_type_id, :in_contract, :rate, :client_contract_id) end end end end