end of day commit
This commit is contained in:
@@ -98,6 +98,58 @@ class SuppliersController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /suppliers/1/active_order_list
|
||||
# GET /suppliers/1/active_order_list.json
|
||||
def active_order_list
|
||||
@supplier = Supplier.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
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.product.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.product.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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /suppliers/1/active_lists
|
||||
# GET /suppliers/1/active_lists.json
|
||||
def active_lists
|
||||
@supplier = Supplier.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
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.product.price).round(2)}}.round(2)
|
||||
grand_total += hl[:total_amount]
|
||||
h[:lists] << hl
|
||||
end
|
||||
h[:total_amount] = grand_total.round(2)
|
||||
render json: h
|
||||
end
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def set_relation_options
|
||||
|
||||
Reference in New Issue
Block a user