end of day commit for users and suppliers authenticated handling
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
class SupplierController < ApplicationController
|
||||
before_filter :authenticate_supplier!
|
||||
|
||||
# GET /suppliers/1/active_orders
|
||||
# GET /suppliers/1/active_orders.json
|
||||
def active_orders
|
||||
@supplier = current_supplier
|
||||
respond_to do |format|
|
||||
format.html { render layout: 'tablet' }
|
||||
format.json do
|
||||
h = @supplier.as_json
|
||||
h[:orders] = []
|
||||
list_total = 0.0
|
||||
for order in @supplier.active_orders
|
||||
ho = {products: []}
|
||||
order_total = 0.0
|
||||
for product_order in order.product_orders
|
||||
order_total += (product_order.amount * product_order.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.price}
|
||||
end
|
||||
ho[:total_amount] = order_total.round(2)
|
||||
ho[:state] = order.state
|
||||
ho[:table_number] = order.table_number
|
||||
ho[:id] = order.id
|
||||
list_total += ho[:total_amount]
|
||||
h[:orders] << ho
|
||||
end
|
||||
h[:total_amount] = list_total.round(2)
|
||||
render json: h, layout: 'tablet'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /suppliers/1/active_lists
|
||||
# GET /suppliers/1/active_lists.json
|
||||
def active_lists
|
||||
@supplier = current_supplier
|
||||
respond_to do |format|
|
||||
format.html { render layout: 'tablet' }
|
||||
format.json do
|
||||
h = @supplier.as_json
|
||||
h[:lists] = []
|
||||
grand_total = 0.0
|
||||
for list in @supplier.active_lists
|
||||
hl = list.as_json
|
||||
hl[:total_amount] = list.orders.inject(0.0){|sum, o| sum + o.product_orders.inject(0.0){|s, po| s + (po.amount * po.price).round(2)}}.round(2)
|
||||
grand_total += hl[:total_amount]
|
||||
h[:lists] << hl
|
||||
end
|
||||
h[:total_amount] = grand_total.round(2)
|
||||
render json: h, layout: 'tablet'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# POST /supplier/close_list
|
||||
def close_list
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:list_id])
|
||||
@list.close!
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /orders/1/is_helped
|
||||
def mark_list_as_helped
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:list_id])
|
||||
@list.needs_help = false
|
||||
@list.save
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /orders/1/is_being_processed
|
||||
def mark_order_in_process
|
||||
@order = Order.find_by_supplier_id_and_id(current_supplier.id, params[:order_id])
|
||||
@order.is_being_processed!
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /orders/1/is_delivered
|
||||
def order_is_delivered
|
||||
@order = Order.find_by_supplier_id_and_id(current_supplier.id, params[:order_id])
|
||||
@order.is_delivered!
|
||||
render nothing: true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user