Last active
April 11, 2018 20:47
-
-
Save giom/9dc4cedff554cb1b55a2288ebaa418c6 to your computer and use it in GitHub Desktop.
This list the inventory and state of a product including waiting POs, received POs, sent QTYs, etc...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ss is the list of sizes to analyze | |
csv_file = CSV.generate do |csv| | |
csv << ["SKU", "ITEM NO", "PRODUCT", "STYLE", "SIZE", "UPC", "STARTING QTY", "ADDED QTY", "PO RECEIVED QTY", "PO WAITING QY", "MERCEDES QTY", "SENT QTY", "TO SEND QTY", "SOLD QTY", "UPC SIZE QTY", "UPC SIZE EXPECTED QTY", "GLITCHED QTY", "RECEIVED POS #", "AWAITING POS #"] | |
ss.each do |s| | |
auc = s.associated_upc_size | |
a = [] | |
a << s.retail_pro_id | |
a << s.product.item_no | |
a << s.product.name | |
a << s.style.name | |
a << s.name | |
a << auc.upc | |
a << s.starting_stock_level | |
a << s.added | |
a << auc.purchase_order_sizes.sum(:actual_qty) | |
a << auc.purchase_order_sizes.includes(:purchase_order).where("purchase_orders.status" => "sent").sum(:inventory_qty) | |
a << auc.inventory_qty | |
a << Purchase.paid.where(:size_id => s).where("orders.order_batch_id is not null").sum(:quantity) | |
a << Purchase.paid.where(:size_id => s).where("orders.order_batch_id is null").sum(:quantity) | |
a << Purchase.paid.where(:size_id => s).count | |
a << auc.qty | |
a << s.associated_upc_size.purchase_order_sizes.sum(:actual_qty) - Purchase.where(:size_id => s).paid.where("orders.order_batch_id is not null").sum(:quantity) | |
a << s.associated_upc_size.purchase_order_sizes.sum(:actual_qty) - Purchase.where(:size_id => s).paid.where("orders.order_batch_id is not null").sum(:quantity) - auc.qty | |
a << auc.purchase_order_sizes.includes(:purchase_order).where("purchase_orders.status" => "received").map(&:purchase_order_id).uniq.join(",") | |
a << auc.purchase_order_sizes.includes(:purchase_order).where("purchase_orders.status" => "sent").map(&:purchase_order_id).uniq.join(",") | |
csv << a | |
end | |
end | |
File.open("incorrect_sizes.csv", "w") {|f| f.write(csv_file)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment