daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PurchaseOrder
  2.   def initialize(product_list)
  3.     @product_list = product_list
  4.   end
  5.  
  6.   attr_reader :product_list
  7.  
  8.   def summary_data
  9.     product_list.products.map do |p|
  10.       { :item_number             => p.item_number,
  11.         :upc                     => p.upc,
  12.         :title                   => p.super_title,
  13.         :platform                => p.platform_code,
  14.         :vendor_name             => p.product_group.name,
  15.         :vendor_number           => p.extended_vendor_number,
  16.         :warehouse_pack_quantity => p.warehouse_pack_quantity,
  17.         :total_units             => p.total_order_units,
  18.         :unit_retail             => p.unit_retail.to_f,
  19.         :order_at_retail         => p.total_order_units.to_f * p.unit_retail,
  20.         :allocation              => nil, #TODO: Not yet implemented
  21.         :original_order          => nil, #TODO: Not yet implemented
  22.         :amount_cut              => nil, #TODO: Not yet implemented
  23.        }
  24.     end
  25.   end
  26.  
  27.   def generate
  28.     workbook = WriteExcel.new("#{RAILS_ROOT}/public/po.xls")
  29.  
  30.     summary  = workbook.add_worksheet("Summary")
  31.  
  32.     currency_format = workbook.add_format
  33.     currency_format.set_num_format("$0.00")
  34.  
  35.     headers = %w[Item\ Nbr UPC Title Platform Vendor\ Name Vendor\ Nbr
  36.                  WHPK\ QTY Total\ Units Unit\ Retail Order\ At\ Retail
  37.                  Allocation Original\ Order Amt\ Cut]
  38.  
  39.     headers.each_with_index do |header,col|
  40.       summary.write(0,col,header)
  41.     end
  42.  
  43.     summary_data.each_with_index do |record, index|
  44.       row = index + 1
  45.  
  46.       summary.write(row, 0,  record[:item_number])
  47.       summary.write(row, 1,  record[:upc])
  48.       summary.write(row, 2,  record[:title])
  49.       summary.write(row, 3,  record[:platform])
  50.       summary.write(row, 4,  record[:vendor_name])
  51.       summary.write(row, 5,  record[:vendor_number])
  52.       summary.write(row, 6,  record[:warehouse_pack_quantity])
  53.       summary.write(row, 7 , record[:total_units])
  54.       summary.write(row, 8,  record[:unit_retail], currency_format)
  55.       summary.write(row, 9 , record[:order_at_retail], currency_format)
  56.       summary.write(row, 10, record[:allocation])
  57.       summary.write(row, 11, record[:original_order])
  58.       summary.write(row, 12, record[:amount_cut])
  59.     end
  60.  
  61.     workbook.close
  62.   end
  63. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top