Class: Logistics::Core::ChargeableServiceUnitOfChargesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /chargeable_service_unit_of_charges POST /chargeable_service_unit_of_charges.json



32
33
34
35
36
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 32

def create
  ChargeableServiceUnitOfCharge.generate_chargeable_service_units
  response = Mks::Common::MethodResponse.new(true, 'Chargeable services and unit of charges associated successfully!',nil,nil,nil)
  render json: response
end

#get_cs_by_sduObject



89
90
91
92
93
94
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 89

def get_cs_by_sdu
  result = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:sdu_id])
  data = ActiveModelSerializers::SerializableResource.new(result).as_json
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#get_cs_by_sdu_and_codeObject



83
84
85
86
87
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 83

def get_cs_by_sdu_and_code
  cs = ChargeableServiceUnitOfCharge.get_chargeable_services_with_specific_sdu_and_uoc(params[:sdu_id], params[:code])
  res = Mks::Common::MethodResponse.new(true, nil, cs, nil, nil)
  render json: cs
end

#get_sdus_by_cs_codeObject



77
78
79
80
81
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 77

def get_sdus_by_cs_code
  sdus = ChargeableServiceUnitOfCharge.get_sdus_with_specific_unit_of_charge(params[:code])
  res = Mks::Common::MethodResponse.new(true, nil, sdus, nil, nil)
  render json: res
end

#incrementsObject



63
64
65
66
67
68
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 63

def increments
  @cs_service_unit_of_charge = ChargeableServiceUnitOfCharge.find(params[:id])
  service_increments = @cs_service_unit_of_charge.service_increments
  response = Mks::Common::MethodResponse.new(true,nil,service_increments,nil,nil)
  render json: response
end

#indexObject

GET /chargeable_service_unit_of_charges GET /chargeable_service_unit_of_charges.json



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

def index
  @chargeable_service_unit_of_charges = ChargeableServiceUnitOfCharge.all
  chargeable_service_units_array = []
  @chargeable_service_unit_of_charges.each { |csuoc|
    unit_of_charge_name = nil
    unit_of_charge_id = nil
    if csuoc.unit_of_charge_id != nil
      unit_of_charge_id = csuoc.unit_of_charge_id
      unit_of_charge_name = csuoc.unit_of_charge.name
    end
    chargeable_service_units_array.push({:id => csuoc.id, :service_delivery_unit_id => csuoc.service_delivery_unit_id,
                                        :service_delivery_unit_name => csuoc.service_delivery_unit.name,
                                        :chargeable_service_id => csuoc.chargeable_service_id,
                                        :chargeable_service_name => csuoc.chargeable_service.name,
                                        :unit_of_charge_id => unit_of_charge_id,
                                        :unit_of_charge_name => unit_of_charge_name,
                                        :has_increment => csuoc.has_increment,
                                        :has_container_special_increment => csuoc.has_container_special_increment,
                                        :has_content_special_increment => csuoc.has_content_special_increment})
  }
  response = Mks::Common::MethodResponse.new(true,nil,chargeable_service_units_array,nil,nil)
  render json: response
end

#unassigned_incrementsObject



70
71
72
73
74
75
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 70

def unassigned_increments
  assigned_increments = ChargeableServiceIncrement.select('service_increment_id').where('chargeable_service_unit_of_charge_id'=>params[:id])
  unassigned_increments = ServiceIncrement.where.not(id: assigned_increments)
  response = Mks::Common::MethodResponse.new(true,nil,unassigned_increments,nil,nil)
  render json: response
end

#update_changesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/logistics/core/chargeable_service_unit_of_charges_controller.rb', line 38

def update_changes
  if not params[:updated_unit_of_charges].nil?
    updated_unit_of_charges = params[:updated_unit_of_charges]

    updated_unit_of_charges.each { |unit_of_charge|
      if unit_of_charge['unit_of_charge_id'].nil?
        old_cs_uoc = ChargeableServiceUnitOfCharge.find(unit_of_charge['id'])
        old_cs_uoc.has_increment = unit_of_charge['has_increment']
        old_cs_uoc.has_container_special_increment = unit_of_charge['has_container_special_increment']
        old_cs_uoc.has_content_special_increment = unit_of_charge['has_content_special_increment']
        old_cs_uoc.save
      else
        old_cs_uoc = ChargeableServiceUnitOfCharge.find(unit_of_charge['id'])
        old_cs_uoc.unit_of_charge_id = unit_of_charge['unit_of_charge_id']
        old_cs_uoc.has_increment = unit_of_charge['has_increment']
        old_cs_uoc.has_container_special_increment = unit_of_charge['has_container_special_increment']
        old_cs_uoc.has_content_special_increment = unit_of_charge['has_content_special_increment']
        old_cs_uoc.save
      end
    }
  end
  response = Mks::Common::MethodResponse.new(true, 'Chargeable services unit of charges updated successfully!')
  render json: response
end