module Logistics module Core class ServiceIncrementsController < ApplicationController before_action :set_service_increment, only: [:update] # GET /service_increments # GET /service_increments.json def index @service_increments = Logistics::Core::ServiceIncrement.all @response = {:success => true, :message => '', :data => @service_increments} render json: @response end # POST /service_increments # POST /service_increments.json def create @service_increment = Logistics::Core::ServiceIncrement.new(service_increment_params) #respond_to do |format| #format.json do if @service_increment.valid? @service_increment.save @response = Mks::Common::MethodResponse.new(true, 'Increment recorded successfully', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages(@service_increment, 'Increment') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) render json: response end #end #end end # PATCH/PUT /service_increments/1 # PATCH/PUT /service_increments/1.json def update @service_increment.update_attributes(service_increment_params) if @service_increment.save @response = Mks::Common::MethodResponse.new(true,'Increment updated successfully',nil,nil,nil) render json: @response else errors = Mks::Common::Util.error_messages(@service_increment, 'Increment') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) render json: response end end def increments service_increment_id = params[:id] service_increment = Logistics::Core::ServiceIncrement.find(service_increment_id) @response = {:success => true, :message => '', :data => service_increment.additions} render json: @response end def unassigned_increments service_increment_id = params[:id] assigned_increment_ids = [] assigned_increment_ids.push(params[:id]) assigned_increments = Logistics::Core::Addendum.where('service_increment_id' => service_increment_id) if assigned_increments.count > 0 assigned_increments.each { |ai| assigned_increment_ids.push(ai.addition_id) } end unassigned_increments = Logistics::Core::ServiceIncrement.where.not(id: assigned_increment_ids) @response ={:success =>true, :message => '', :data => unassigned_increments} render json: @response end private # Use callbacks to share common setup or constraints between actions. def set_service_increment @service_increment = Logistics::Core::ServiceIncrement.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def service_increment_params params.require(:service_increment).permit(:code, :name, :has_increment) end end end end