class Gentle::Documents::Request::ShipmentOrder
Constants
- DATEFORMAT
- NAMESPACE
Attributes
client[R]
shipment[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 24 def initialize(options = {}) @client = options.fetch(:client) @shipment = options.fetch(:shipment) @shipment_number = @shipment.number end
Public Instance Methods
add_individual_phase_1_items(phase_1_item)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 102 def add_individual_phase_1_items(phase_1_item) phase_1 = Phase1Set.new(phase_1_item).included_items phase_1.map { |item| line_item_hash(item) } end
add_item_parts(part_line_items)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 98 def add_item_parts(part_line_items) part_line_items.map { |part| part_line_item_hash(part) } end
add_items_to_shipment_order(items, xml)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 65 def add_items_to_shipment_order(items, xml) item_hashes = convert_to_hashes(items) grouped_items = group_items_by_sku(item_hashes) grouped_items.each_with_index do |hash, index| hash['Line'] = index + 1 xml.OrderDetails(hash) end end
bill_address()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 128 def bill_address @shipment.order.bill_address end
contain_parts?(item)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 94 def contain_parts?(item) item.part_line_items && !item.part_line_items.empty? end
convert_to_hashes(items)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 74 def convert_to_hashes(items) items.map do |item| if Phase1Set.match(item) add_individual_phase_1_items(item) elsif contain_parts? item add_item_parts(item.part_line_items) else line_item_hash(item) end end.flatten end
date()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 152 def date @shipment.created_at end
date_stamp()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 140 def date_stamp Time.now.strftime('%Y%m%d_%H%M%3N') end
document_number()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 148 def document_number @shipment_number end
filename()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 156 def filename "#{business_unit}_#{type}_#{document_number}_#{date.strftime(DATEFORMAT)}.xml" end
full_name()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 132 def full_name @shipment.address.full_name end
group_items_by_sku(item_hashes)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 86 def group_items_by_sku(item_hashes) grouped = item_hashes.group_by {|hash| hash['ItemNumber'] } grouped.values.map do |hashes| hash = hashes.first update_quantity(hash, total_quantity(hashes)) end end
message()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 136 def message "Succesfully Sent Shipment #{@shipment_number} to Quiet Logistics" end
message_id()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 160 def message_id SecureRandom.uuid end
order_items()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 116 def order_items @shipment.order.line_items end
order_type()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 120 def order_type 'SO' end
ship_address()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 124 def ship_address @shipment.address end
to_xml()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 30 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.ShipOrderDocument('xmlns' => 'http://schemas.quietlogistics.com/V2/ShipmentOrder.xsd') { xml.ClientID client_id xml.BusinessUnit business_unit xml.OrderHeader('OrderNumber' => @shipment_number, 'OrderType' => order_type, 'OrderDate' => @shipment.created_at.utc.iso8601) { xml.Extension @shipment.order.number xml.Comments @shipment.order.special_instructions xml.ShipMode('Carrier' => @shipment.shipping_method.carrier, 'ServiceLevel' => @shipment.shipping_method.service_level) xml.ShipTo(ship_to_hash) xml.BillTo(bill_to_hash) if @shipment.respond_to?(:value_added_services) @shipment.value_added_services.each do |service| xml.ValueAddedService('Service' => service[:service], 'ServiceType' => service[:service_type]) end end } add_items_to_shipment_order(order_items, xml) } end builder.to_xml end
total_quantity(hashes)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 112 def total_quantity(hashes) hashes.map{ |hash| hash['QuantityOrdered'] }.reduce(:+) end
type()
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 144 def type 'ShipmentOrder' end
update_quantity(hash, quantity)
click to toggle source
# File lib/gentle/documents/request/shipment_order.rb, line 107 def update_quantity(hash, quantity) hash['QuantityOrdered'] = hash['QuantityToShip'] = quantity hash end