Class: Logistics::Core::TransportRatePeriodsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /rate_periods POST /rate_periods.json



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/logistics/core/transport_rate_periods_controller.rb', line 44

def create
  rate_period = TransportRatePeriod.new(rate_period_params)
  result = TransportRatePeriod.create_transport_rate_period rate_period
  if result[0]['success']
    response = Mks::Common::MethodResponse.new(result[0]['success'], result[0]['message'], result[0]['data'], nil, nil)
  else
    response = Mks::Common::MethodResponse.new(result[0]['success'], nil, nil, result[0]['errors'], nil)
  end
  render json: response
end

#get_current_rate_periodObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/logistics/core/transport_rate_periods_controller.rb', line 30

def get_current_rate_period
  rate_period = TransportRatePeriod.where("current_period" => true)
  result = []
  success = false
  if rate_period.length > 0
    result = rate_period
    success = true
  end
  response = Mks::Common::MethodResponse.new(success, nil, result, nil, nil)
  render json: response
end

#indexObject

GET /rate_periods GET /rate_periods.json



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/logistics/core/transport_rate_periods_controller.rb', line 11

def index
  rate_periods = TransportRatePeriod.all
  result = []
  rate_periods.each do |rate_period|
    if rate_period.current_period
      current_period = 'Yes'
    else
      current_period = 'No'
    end
    result.push({id: rate_period.id,
                 effective_date: rate_period.effective_date,
                 valid_until: rate_period.valid_until,
                 current_period: current_period
                })
  end
  response = Mks::Common::MethodResponse.new(true, nil, result, nil, nil)
  render json: response
end

#updateObject

PATCH/PUT /rate_periods/1 PATCH/PUT /rate_periods/1.json



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

def update
  rate_period = TransportRatePeriod.find(params[:id])
  new_rate_period = TransportRatePeriod.new(rate_period_params)
  result = TransportRatePeriod.update_transport_rate_period rate_period, new_rate_period, rate_period_params
  if result[0]['success']
    response = Mks::Common::MethodResponse.new(result[0]['success'], result[0]['message'], result[0]['data'], nil, nil)
  else
    response = Mks::Common::MethodResponse.new(result[0]['success'], nil, nil, result[0]['errors'], nil)
  end
  render json: response
end