Class: Logistics::Core::KilogramRatesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /air_weigh_bills POST /air_weigh_bills.json



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

def create
  cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:kilogram_rate][:service_delivery_unit_id],
                                               chargeable_service_id: params[:kilogram_rate][:chargeable_service_id])
  @kilogram_rate = KilogramRate.new(kilogram_rate_params)
  @kilogram_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id unless cs_uoc.empty?
  if @kilogram_rate.valid?
    @kilogram_rate.save
    @response = Mks::Common::MethodResponse.new(true, 'Kilogram rate saved successfully !',nil,nil,nil);
    render json: @response
  else
    @response = {:success => false, :message => 'Error saving kilogram rate', :data => []}
    render json: @response
  end
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/logistics/core/kilogram_rates_controller.rb', line 6

def index
  @kilogram_rates = KilogramRate.all
  kilogram_rates_array =[]
  @kilogram_rates.each do |kg|
    cs_id = kg.chargeable_service_unit_of_charge&.chargeable_service_id
    cs_name = kg.chargeable_service_unit_of_charge&.chargeable_service&.name
    sdu_id = kg.chargeable_service_unit_of_charge&.service_delivery_unit_id
    sdu_name = kg.chargeable_service_unit_of_charge&.service_delivery_unit&.name
    transaction_name = kg.transaction_type&.name
    kilogram_rates_array.push({id: kg.id, high: kg.high, low: kg.low, medium: kg.medium, effective_date: kg.effective_date,
                                from: kg.from, to: kg.to, margin: kg.margin, chargeable_service_id: cs_id,
                                chargeable_service_name: cs_name, service_delivery_unit_id: sdu_id,
                                service_delivery_unit_name: sdu_name, transaction_type_id: kg.transaction_type_id,
                                transaction_type_name: transaction_name
                             })
  end
  @response = {:success => true, :message => '', :data => kilogram_rates_array}
  render json: @response
end

#updateObject

PATCH/PUT /air_weigh_bills/1 PATCH/PUT /air_weigh_bills/1.json



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/logistics/core/kilogram_rates_controller.rb', line 45

def update
  cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:kilogram_rate][:service_delivery_unit_id],
                                               chargeable_service_id: params[:kilogram_rate][:chargeable_service_id])
  @kilogram_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id unless cs_uoc.empty?
  if @kilogram_rate.update_attributes(kilogram_rate_params)
    @kilogram_rate.save
    @response = {:success => true, :message => 'Kilogram rate updated successfully', :data => []}
    render json: @response
  else
    @response = {:success => false, :message => 'Error updating kilogram rate', :data => []}
    render json: @response
  end
end