我卡住合併一些哈希來得到我需要的結果。如何有條件地合併散列並添加值?
散列包含訂單總價格的細目,項目價格,稅收,&送貨,訂購中的所有訂單。我試圖動態執行此操作,因爲並非所有訂單都收取稅費,甚至不需要稅或運費。
這裏就是我稱之爲「最壞的情況」我正在處理:
#First order - has charges for Canadian GST and HST
{:orderhdr_id=>17654122, :order_item_seq=>1, :order_item_amt_break_seq=>1, :order_item_break_type=>0, :local_amount=>8.16, :base_amount=>8.16, :orig_base_amount=>149, :tax_delivery=>0, :tax_active=>0}
{:orderhdr_id=>17654122, :order_item_seq=>1, :order_item_amt_break_seq=>2, :order_item_break_type=>1, :local_amount=>0.41, :base_amount=>0.41, :state=>"ON", :tax_type=>"GST", :tax_rate_category=>"STD", :orig_base_amount=>7.45, :tax_rate=>5, :tax_delivery=>0, :tax_active=>1, :tx_incl=>1}
{:orderhdr_id=>17654122, :order_item_seq=>1, :order_item_amt_break_seq=>3, :order_item_break_type=>1, :local_amount=>0.65, :base_amount=>0.65, :state=>"ON", :tax_type=>"HST", :tax_rate_category=>"STD", :orig_base_amount=>11.92, :tax_rate=>8, :tax_delivery=>0, :tax_active=>1, :tx_incl=>1}
#Second order - has only one charge for tax
{:orderhdr_id=>1815296, :order_item_seq=>1, :order_item_amt_break_seq=>1, :order_item_break_type=>0, :local_amount=>76.52, :base_amount=>76.52, :orig_base_amount=>99.95, :tax_delivery=>0, :tax_active=>0}
{:orderhdr_id=>1815296, :order_item_seq=>1, :order_item_amt_break_seq=>2, :order_item_break_type=>1, :local_amount=>4.59, :base_amount=>4.59, :orig_base_amount=>6, :tax_delivery=>0, :tax_active=>1}
#Third order - has charge for shipping
{:orderhdr_id=>6112412, :order_item_seq=>1, :order_item_amt_break_seq=>1, :order_item_break_type=>0, :local_amount=>21.34, :base_amount=>21.34, :orig_base_amount=>99.95, :tax_delivery=>0, :tax_active=>0}
{:orderhdr_id=>6112412, :order_item_seq=>1, :order_item_amt_break_seq=>2, :order_item_break_type=>2, :local_amount=>4.7, :base_amount=>4.7, :orig_base_amount=>22, :tax_delivery=>0, :tax_active=>0}
的:order_item_break_type
決定了它是什麼類型的收費,項目,稅收,航運。
如果:order_item_break_type
爲0或2,然後從:orig_base_amount
減去:base_amount
並將其添加到該中斷類型的整體總。對於:order_item_break_type
等於1,我需要總結:orig_base_amount
和:base_amount
,的差異,但是我需要將不同的稅分開。
因此,這裏是我應該與上面的命令結束了一下:
:break_type = 0 | total = 242.88
:break_type = 1, :state = ON, :tax_type = GST, :tax_rate_category = STD | total = 7.04
:break_type = 1, :state = ON, :tax_type = HST, :tax_rate_category = STD | total = 11.27
:break_type = 1 | total = 1.41
:break_type = 2 | total = 17.30
我有叫@amounts
數組這些哈希值。
我有像merge!
,inject
,shift
和更多的方法,通過我的頭,但不能把它放在一起。
目前尚不清楚結果如何與訂單相關。也就是說,我看到三個訂單和五個結果。你能澄清一下嗎? –
結果是由':break_type',':state',':tax_type'和':tax_rate_category'的唯一組合組合的每次收費的':orig_base_amount - :base_amount'的總和。我傾向於看它的方式是,相對於有3個訂單和5個結果,有7個費用減少到5個結果。謝謝! –