Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. To get [order_id | order_subtotal | sum_of_order_items | sum_of_markdown]
  2.  
  3. results = Order.find_each do |order|
  4. [order.id, order.subtotal, order.order_items.collect{|oi| unit_price(order, oi)}.sum, order.order_items.collect{|oi| markdown(oi)}.sum]
  5. end
  6.  
  7. def unit_price(order, item)
  8. if order.is_a?(Orders::DsrOrder) && item.eligible_for_dsr_discount?
  9. item.stylist_price
  10. else
  11. item.price
  12. end
  13. end
  14.  
  15. def markdown(item)
  16. discount = Money.new(0)
  17. discount += item.promotional_discount if item.promotional_discount > 0
  18. discount += item.hostess_discount_value if item.hostess_discount? && item.hostess_discount_value
  19. discount
  20. end
  21.  
  22.  
  23. To get [order_id | order_tax | sum_of_order_items_tax]
  24.  
  25. tax_results = Order.find_each do |order|
  26. [order.id, order.tax_cents, order.order_items.collect{|oi| oi.tax_cents}.sum]
  27. end
  28.  
  29.  
  30.  
  31. order = Order.find_by(public_order_id: public_order_id)
  32. pc = order.order_items.collect{|oi| product_credit(oi)}.sum
  33. disc = order.order_items.collect{|oi| markdown(oi)}.sum
  34. oi_st = order.order_items.collect{|oi| oi.eligible_for_dsr_discount? ? oi.stylist_price : oi.price}.sum
  35.  
  36. subtotal = oi_st - pc
  37. this subtotal is mentioned in the GP sheet
  38.  
  39. product_credit, markdown are defined in hdr.rb in oms_service
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. =================================================================================================
  48.  
  49. def prev_product_credit(item)
  50. item.product_credits * (item.stylist_price/item.price)
  51. end
  52.  
  53. def new_product_credit(item)
  54. Money.new((item.product_credits_cents * item.stylist_price_cents) / item.price_cents)
  55. end
  56.  
  57. def order_prev_st(o)
  58. o.order_items.collect{|oi| prev_product_credit(oi)}.sum
  59. end
  60.  
  61. def order_st(o)
  62. o.order_items.collect{|oi| new_product_credit(oi)}.sum
  63. end
  64.  
  65. def sub_total(o)
  66. o.order_items.collect{|oi| o.is_a?(Orders::DsrOrder) && oi.eligible_for_dsr_discount? ? oi.stylist_price : oi.price}.sum
  67. end
  68.  
  69. def res_prev(o)
  70. sub_total(o) - order_prev_st(o)
  71. end
  72.  
  73. def res(o)
  74. sub_total(o) - order_st(o)
  75. end
  76.  
  77. def diff(a, b)
  78. a - b
  79. end
  80.  
  81.  
  82. orders = Order.where(public_order_id: [15169, 33365, 35201, 38449, 44929, 45793, 48619, 53639, 55411, 55741, 57805, 60615, 62001, 63367, 68109, 69423, 69695, 69721, 70159, 70183, 70325, 70421, 71241, 71715, 72185, 72205, 72407, 73345, 73793, 74871, 76001, 76357, 76463, 78971, 79381, 79765, 79975, 80101, 80103, 80207, 80235, 80515, 80699, 80759, 80905, 80921, 80951, 80987, 81037, 81043, 81059, 81069, 81093, 81113, 81155, 81157, 81163, 81189, 81193, 81197, 81203, 81409, 81421, 81439, 81453, 81463, 81499, 81523, 81525, 81545, 81587, 81601, 81649, 81719, 81763, 81767, 81795, 81815, 81877, 81913, 81937, 81973, 82083, 82111, 82129, 82171, 82217, 82311, 82371, 82385])
  83.  
  84. orders.collect{|o| [o.public_order_id, o.total.cents, o.tax.cents, res_prev(o).cents, res(o).cents, diff(o.subtotal, res(o)).cents, diff(o.subtotal, res_prev(o)).cents]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement