Class: Logistics::Core::ServiceIncrementsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/service_increments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /service_increments POST /service_increments.json



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/logistics/core/service_increments_controller.rb', line 16

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

#incrementsObject



48
49
50
51
52
53
# File 'app/controllers/logistics/core/service_increments_controller.rb', line 48

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

#indexObject

GET /service_increments GET /service_increments.json



8
9
10
11
12
# File 'app/controllers/logistics/core/service_increments_controller.rb', line 8

def index
  @service_increments = Logistics::Core::ServiceIncrement.all
  @response = {:success => true, :message => '', :data => @service_increments}
  render  json: @response
end

#unassigned_incrementsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/logistics/core/service_increments_controller.rb', line 55

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

#updateObject

PATCH/PUT /service_increments/1 PATCH/PUT /service_increments/1.json



36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/logistics/core/service_increments_controller.rb', line 36

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