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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/controllers/shoppy/shipments_controller.rb', line 27
def edit
@shipment = Shipment.find_by(id: params[:shipment_id])
(order = Order.find_by(id: params[:order_id])) if params[:order_id]
if @shipment
if params[:status] == "cancelled"
if @shipment.status == "Processing"
@shipment.status = "Cancelled"
@shipment.save
Log.newEvent("Shipments", "shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was cancelled", current_admin.name)
flash[:notice] = "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was cancelled"
elsif @shipment.status == "Cancelled"
flash[:warning] = "Shipment is already not cancelled"
elsif @shipment.status == "Shipped" || @shipment.status == "Delivered"
flash[:warning] = "Shipment is already shipped, so it can't be cancelled"
else
flash[:warning] = "Something went wrong. please try again later"
end
elsif params[:status] == "processing"
if @shipment.status == "Cancelled"
@shipment.status = "Processing"
@shipment.save
Log.newEvent("Shipment", "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked processing.", current_admin.name)
flash[:notice] = "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked processing."
elsif @shipment.status == "Processing"
flash[:warning] = "Shipment is already marked processing."
elsif @shipment.status == "Shipped"
flash[:warning] = "Shipment is already shipped, so it can't be edited"
else
flash[:warning] = "Something went wrong. please try again later"
end
elsif params[:status] == "shipped"
if @shipment.status == "Processing"
@shipment.status = "Shipped"
@shipment.save
Log.newEvent("Shipment", "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked shipped.", current_admin.name)
flash[:notice] = "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked shipped."
elsif @shipment.status == "Cancelled"
flash[:warning] = "Order is cancelled, hence can't be marked as shipped"
elsif @shipment.status = "Shipped"
flash[:notice] = "Shipment is already marked shipped."
else
flash[:warning] = "Something went wrong. please try again later"
end
elsif params[:status] == "delivered"
if @shipment.status == "Shipped"
@shipment.status = "Delivered"
@shipment.delivery_date = Date.today
@shipment.save
Log.newEvent("Shipment", "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked Delivered.", current_admin.name)
flash[:notice] = "Shipment no. #{@shipment.id} for order no. '#{@shipment.order.id}' was marked Delivered."
else
flash[:warning] = "Order has to be shipped first, before you mark it delivered"
end
else
flash[:warning] = "Something went wrong. please try again later"
end
if params[:view] == "show"
redirect_to "/shipments/#{@shipment.id}"
else
if order
redirect_to "/orders/#{order.id}/shipments"
else
redirect_to "/shipments"
end
end
else
page_not_found
end
end
|