module Mks module Edm class EquipmentValuationsController < ApplicationController before_action :set_equipment_valuation, only: %i[show update] def index data = EquipmentValuation.where(equipment_item_id: params[:id]) render json: Mks::Common::MethodResponse.success_response(data) end def valuation data = EquipmentValuation.where(equipment_item_id: params[:id], is_current: true) render json: Mks::Common::MethodResponse.success_response(data) end def show render json: Mks::Common::MethodResponse.success_response(@equipment_valuation) end def create equipment_valuation = EquipmentValuation.new(equipment_valuation_params) if equipment_valuation.save response = Mks::Common::MethodResponse.success_response(equipment_valuation, 'Equipment valuation saved successfully!') render json: response, status: :created, location: equipment_valuation else response = Mks::Common::MethodResponse.failure_response(equipment_valuation) render json: response, status: :unprocessable_entity end end def update if @equipment_valuation.update(equipment_valuation_params) response = Mks::Common::MethodResponse.success_response(@equipment_valuation, 'Equipment valuation updated successfully!') render json: response else render json: Mks::Common::MethodResponse.failure_response(@equipment_valuation), status: :unprocessable_entity end end private def set_equipment_valuation @equipment_valuation = EquipmentValuation.find(params[:id]) end def equipment_valuation_params params.require(:equipment_valuation).permit(:equipment_item_id, :initial_cost, :residual_value, :work_hrs_per_yr, :life_year, :insurance_premium, :fuel_cost_per_hr, :oil_rate, :repair_rate, :rate_of_return, :dep_method) end end end end