6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/rawbotz/routes/orders/stock.rb', line 6
def self.registered(app)
show_stock_order = lambda do
@order = Order.find(params[:id])
@refunds = {}
if @order.supplier == settings.supplier && @order.remote_order_link.blank?
add_flash :message, "You need to select a remote order"
redirect "/order/#{@order.id}/link_to_remote"
else
if @order.supplier == settings.supplier
order_linker = Rawbotz::OrderLinker.new @order
order_linker.link!
@orphans = order_linker.orphans
@refunds = order_linker.refunds
end
haml "order/stock".to_sym
end
end
stock_order = lambda do
@order = Order.find(params[:id])
@order.remote_order_id = params[:remote_order_id]
@order.remote_order_link = params[:remote_order_link]
stock_processor = Rawbotz::StockProcessor.new @order, params
errors = stock_processor.process!
if errors.empty?
add_flash :success, "Stocked this order"
else
errors.each{|e| add_flash :error, e}
end
@refunds = {}
if @order.supplier == settings.supplier
order_linker = Rawbotz::OrderLinker.new @order
order_linker.link!
@orphans = order_linker.orphans
@refunds = order_linker.refunds
end
haml "order/stock".to_sym
end
show_link_to_remote_order = lambda do
@order = Order.find(params[:id])
@last_orders = Rawbotz.mech.last_orders
haml "order/link_to_remote".to_sym
end
link_to_remote_order = lambda do
@order = Order.find(params[:id])
@order.remote_order_id = params[:remote_order_id]
@order.remote_order_link = params[:remote_order_link]
@order.save
redirect "/order/#{@order.id}/stock"
end
app.get '/order/:id/stock', &show_stock_order
app.post '/order/:id/stock', &stock_order
app.get '/order/:id/link_to_remote', &show_link_to_remote_order
app.post '/order/:id/link_to_remote', &link_to_remote_order
end
|