module Logistics module Core class ContractKilogramMinimumRatesController < ApplicationController before_action :set_contract_kilogram_minimum_rate, only: [:update] def index kg_rates = ContractKilogramMinimumRate.where(contract_id: params[:client_contract_id]) data = ActiveModelSerializers::SerializableResource.new(kg_rates).as_json render json: data end def create kg_minimum_rate = ContractKilogramMinimumRate.new(contract_kilogram_minimum_rate_params) cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:contract_kilogram_minimum_rate][:service_delivery_unit_id], chargeable_service_id: params[:contract_kilogram_minimum_rate][:chargeable_service_id]) kg_minimum_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id if kg_minimum_rate.valid? kg_minimum_rate.save res = Mks::Common::MethodResponse.new(true, 'Minimum rate set successfully !', nil, nil, nil) else errors = Mks::Common::Util.error_messages(kg_minimum_rate, 'Kilogram Minimum Rate') res = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: res end def update cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:contract_kilogram_minimum_rate][:service_delivery_unit_id], chargeable_service_id: params[:contract_kilogram_minimum_rate][:chargeable_service_id]) @kg_minimum_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id if @kg_minimum_rate.update(contract_kilogram_minimum_rate_params) res = Mks::Common::MethodResponse.new(true, 'Minimum rate updated successfully !', nil, nil) else errors = Mks::Common::Util.error_messages(@kg_minimum_rate, 'Kilogram Minimum Rate') res = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: res end private def contract_kilogram_minimum_rate_params params.require('contract_kilogram_minimum_rate').permit(:transaction_type_id, :minimum_price, :contract_id) end def set_contract_kilogram_minimum_rate @kg_minimum_rate = ContractKilogramMinimumRate.find(params[:id]) end end end end