module Logistics module Core class ChargeableServicesController < ApplicationController before_action :set_chargeable_service, only: [:update] # GET /chargeable_services # GET /chargeable_services.json def index @chargeable_services = ChargeableService.order(:order) chargeable_service_array = [] @chargeable_services.each{ |chargeable_service| transport_service_name = nil if chargeable_service.transport_service_type_id != nil transport_service_type = chargeable_service.transport_service_type.name end chargeable_service_array.push({:id => chargeable_service.id, :name => chargeable_service.name, :code => chargeable_service.code, :order => chargeable_service.order, :chargeable_service_type_name => chargeable_service.chargeable_service_type.name, :chargeable_service_type_id => chargeable_service.chargeable_service_type_id, :transport_service_type_id => chargeable_service.transport_service_type_id, :transport_service_type => transport_service_type}) } @response = {:success => true, :message => '', :data => chargeable_service_array} render json: @response end # POST /chargeable_services # POST /chargeable_services.json def create @chargeable_service = ChargeableService.new(chargeable_service_params) #respond_to do |format| #format.json do if @chargeable_service.valid? @chargeable_service.save @response = Mks::Common::MethodResponse.new(true, 'Chargeable service saved successfully!',nil, nil, nil ) render json: @response else errors = Mks::Common::Util.error_messages @chargeable_service, 'Chargeable service' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end #end #end end # PATCH/PUT /chargeable_services/1 # PATCH/PUT /chargeable_services/1.json def update @chargeable_service.update_attributes(chargeable_service_params) if @chargeable_service.save @response = Mks::Common::MethodResponse.new(true, 'Chargeable service updated successfully!', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages @chargeable_service, 'Chargeable service' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end private # Use callbacks to share common setup or constraints between actions. def set_chargeable_service @chargeable_service = ChargeableService.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def chargeable_service_params params.require(:chargeable_service).permit(:code, :name, :order, :transport_service_type_id, :chargeable_service_type_id) end end end end