module Mks module Rate class ChargeableServicesController < ApplicationController before_action :set_chargeable_service, only: [:update] def index result = ChargeableService.includes(:service_delivery_unit).order(:name) render json: result end def create cs = ChargeableService.new(chargeable_service_params) if cs.save render json: Mks::Common::MethodResponse.success_response(cs, 'Chargeable service saved successfully !') else render json: Mks::Common::MethodResponse.failure_response(cs), status: :unprocessable_entity end end def update if @cs.update(chargeable_service_params) render json: Mks::Common::MethodResponse.success_response(@cs, 'Chargeable service updated successfully !') else render json: Mks::Common::MethodResponse.failure_response(@cs), status: :unprocessable_entity end end def sdu_services result = ChargeableService.where(service_delivery_unit_id: params[:id]) render json: result end def filter search = "%#{params[:search].downcase}%" services = ChargeableService.joins(:service_delivery_unit) .where('lower(mks_rate_chargeable_services.name) LIKE ? OR lower(mks_rate_service_delivery_units.name) LIKE ?', search, search) render json: ApplicationRecord.as_json(services) end private def chargeable_service_params params.require(:chargeable_service).permit(:id, :code, :name, :service_delivery_unit_id, :base_unit_id, :utilization_unit_id, :service_type_id) end def set_chargeable_service @cs = ChargeableService.find(params[:id]) end end end end