module Logistics module Core class CargoDetail < ApplicationRecord belongs_to :container_type belongs_to :container_size belongs_to :content_type belongs_to :offer_request belongs_to :cargo_type belongs_to :service_delivery_unit #has_many :item_transport_requests, as: :transport_detail has_many :review_notes, as: :correspondence 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 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 def change_to_hash(items) data = [] items.each { |item| data.push item.to_json } return data end end end end