Class: Logistics::Core::CargoDetail

Inherits:
ApplicationRecord show all
Defined in:
app/models/logistics/core/cargo_detail.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

as_json

Instance Method Details

#change_to_hash(items) ⇒ Object



46
47
48
49
50
51
52
# File 'app/models/logistics/core/cargo_detail.rb', line 46

def change_to_hash(items)
  data = []
  items.each { |item|
    data.push item.to_json
  }
  return data
end

#get_containerized_cargo_by_status_and_request(status, bol_id) ⇒ Object



40
41
42
43
44
# File 'app/models/logistics/core/cargo_detail.rb', line 40

def get_containerized_cargo_by_status_and_request(status, bol_id)
  containerized_cargo = CargoDetail.where(status: status, offer_request_id: bol_id)
  containerized_cargo = change_to_hash(containerized_cargo)
  return containerized_cargo
end

#to_jsonObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/logistics/core/cargo_detail.rb', line 13

def to_json
  JSON.parse(
      Jbuilder.encode do |json|
        json.id self.id
        json.weight self.weight
        json.quantity self.quantity
        json.content_type_id self.content_type_id
        json.content_type_name self.content_type ? self.content_type.name : nil
        json.offer_request_id self.offer_request_id
        json.cargo_type_id self.cargo_type_id
        json.cargo_type_name self.cargo_type ? self.cargo_type.name : nil
        json.description self.description
        json.cargo_name self.container_size ? self.container_size.name : nil
        json.container_type_id self.container_type_id
        json.container_type_name self.container_type ? self.container_type.name : nil
        json.container_size_id self.container_size_id
        json.container_size_name self.container_size ? self.container_size.name : nil
        json.truck_number self.truck_number
        json.length self.length
        json.height self.height
        json.width self.width
        json.service_delivery_unit_id self.service_delivery_unit_id
        json.service_delivery_unit_name self.service_delivery_unit ? self.service_delivery_unit.name : nil
      end
  )
end