Method: Logistics::Core::ContractKilogramRatesController#create

Defined in:
app/controllers/logistics/core/contract_kilogram_rates_controller.rb

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/logistics/core/contract_kilogram_rates_controller.rb', line 25

def create
  cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:contract_kilogram_rate][:service_delivery_unit_id],
          chargeable_service_id: params[:contract_kilogram_rate][:chargeable_service_id])
  contract_kilogram_rate = ContractKilogramRate.new(contract_kilogram_rate_params)
  contract_kilogram_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id unless cs_uoc.empty?
  if contract_kilogram_rate.valid?
    contract_kilogram_rate.save
    result = Mks::Common::MethodResponse.new(true, 'Rate saved successfully !', nil, nil, nil)
  else
    errors = Mks::Common::Util.error_messages contract_kilogram_rate, 'Contract kilogram rate'
    result = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: result
end