Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To get [order_id | order_subtotal | sum_of_order_items | sum_of_markdown]
- results = Order.find_each do |order|
- [order.id, order.subtotal, order.order_items.collect{|oi| unit_price(order, oi)}.sum, order.order_items.collect{|oi| markdown(oi)}.sum]
- end
- def unit_price(order, item)
- if order.is_a?(Orders::DsrOrder) && item.eligible_for_dsr_discount?
- item.stylist_price
- else
- item.price
- end
- end
- def markdown(item)
- discount = Money.new(0)
- discount += item.promotional_discount if item.promotional_discount > 0
- discount += item.hostess_discount_value if item.hostess_discount? && item.hostess_discount_value
- discount
- end
- To get [order_id | order_tax | sum_of_order_items_tax]
- tax_results = Order.find_each do |order|
- [order.id, order.tax_cents, order.order_items.collect{|oi| oi.tax_cents}.sum]
- end
- order = Order.find_by(public_order_id: public_order_id)
- pc = order.order_items.collect{|oi| product_credit(oi)}.sum
- disc = order.order_items.collect{|oi| markdown(oi)}.sum
- oi_st = order.order_items.collect{|oi| oi.eligible_for_dsr_discount? ? oi.stylist_price : oi.price}.sum
- subtotal = oi_st - pc
- this subtotal is mentioned in the GP sheet
- product_credit, markdown are defined in hdr.rb in oms_service
- =================================================================================================
- def prev_product_credit(item)
- item.product_credits * (item.stylist_price/item.price)
- end
- def new_product_credit(item)
- Money.new((item.product_credits_cents * item.stylist_price_cents) / item.price_cents)
- end
- def order_prev_st(o)
- o.order_items.collect{|oi| prev_product_credit(oi)}.sum
- end
- def order_st(o)
- o.order_items.collect{|oi| new_product_credit(oi)}.sum
- end
- def sub_total(o)
- o.order_items.collect{|oi| o.is_a?(Orders::DsrOrder) && oi.eligible_for_dsr_discount? ? oi.stylist_price : oi.price}.sum
- end
- def res_prev(o)
- sub_total(o) - order_prev_st(o)
- end
- def res(o)
- sub_total(o) - order_st(o)
- end
- def diff(a, b)
- a - b
- end
- 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])
- 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