class SupplierController < Suppliers::ApplicationController
  def home
  end
=begin
  # 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(section_id: params[:section_id].presence)
          ho = {products: []}
          order_total = 0.0
          for product_order in order.product_orders
            order_total += (product_order.quantity * product_order.price).round(2)
            ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.quantity, price: product_order.price}
          end
          ho[:total_amount] = order_total.round(2)
          ho[:state] = order.state
          ho[:table_number] = order.table_number
          ho[:section_title] = order.list.table.section.try(:title)
          ho[:id] = order.id
          ho[:list_id] = order.list_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(section_id: params[:section_id].presence)
          hl = list.with_info_as_json
          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/remove_list_needs_payment
=end
end
