').appendTo(table) unless tbody.length
tbody.find('tr').remove()
total = 0.0
- for product_id, info of window.active_list
+ for product_id, info of window.active_products_list
total += info.product.price * info.number
row = $('
').appendTo(row)
- icons_td.append('') if list.need_help # or icon-bell
- icons_td.append('') if list.needs_payment
+ icons_td.append('').append(' ') if list.needs_help # or icon-bell
+ icons_td.append('') if list.needs_payment
row.append($('
').appendTo(body)
tbody = $('').appendTo(table)
- for product_id, info of window.active_list
+ for product_id, info of window.active_products_list
row = $('
').appendTo(tbody)
row.append('
'+info.product.name+'
')
row.append('
'+info.number+'
')
diff --git a/app/assets/stylesheets/phone/structure.css.sass b/app/assets/stylesheets/phone/structure.css.sass
index 59ee6ae5..e2a448ee 100644
--- a/app/assets/stylesheets/phone/structure.css.sass
+++ b/app/assets/stylesheets/phone/structure.css.sass
@@ -1,7 +1,13 @@
+$side-spacing: 5px
body
- padding-left: 0px
- padding-right: 0px
+ padding-left: $side-spacing
+ padding-right: $side-spacing
//padding-top: 50px
.navbar-fixed-top
- margin-left: 0px
- margin-right: 0px
+ margin-left: -$side-spacing
+ margin-right: -$side-spacing
+ margin-bottom: 3px
+ .page-header
+ margin-top: 4px
+ margin-bottom: 6px
+ padding-bottom: 0
diff --git a/app/assets/stylesheets/structure.css.sass b/app/assets/stylesheets/structure.css.sass
index b3d14642..2529a79d 100644
--- a/app/assets/stylesheets/structure.css.sass
+++ b/app/assets/stylesheets/structure.css.sass
@@ -5,6 +5,7 @@ table
text-align: right
tbody
td
+ &.status-icons
&.currency
text-align: right
&.numeric
@@ -61,3 +62,10 @@ table
top: 100px
width: 880px
height: 590px
+
+#list-needs-help-button
+ button
+ margin-left: 5px
+#list-needs-payment-button
+ button
+ margin-left: 5px
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 450d8692..2c256b8f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
if session[:active_list_id]
unless active_list.active?
session[:active_list_id] = nil
- redirect_to root_path, alert: t('messages.the_list_has_been_closed')
+ redirect_to phone_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
end
end
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index b128434f..36688fb3 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -5,6 +5,7 @@ class DashboardController < ApplicationController
end
def phone_home
+ flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
render layout: 'phone'
end
@@ -32,7 +33,7 @@ class DashboardController < ApplicationController
render layout: 'phone'
end
- def order_active_list
+ def order_active_products_list
respond_to do |format|
format.html do
redirect_to(root_path, alert: t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
@@ -62,7 +63,7 @@ class DashboardController < ApplicationController
render layout: 'phone'
end
- def list_info
+ def user_list_info
respond_to do |format|
format.json do
render json: {list_active: false} and return unless session[:active_list_id].present?
@@ -78,4 +79,16 @@ class DashboardController < ApplicationController
def supplier_lists
redirect_to active_lists_supplier_path(Supplier.first)
end
+
+ # POST /active_user_list_needs_help
+ def active_user_list_needs_help
+ respond_to do |format|
+ format.json do
+ render json: {list_active: false} and return unless session[:active_list_id].present?
+ active_list.needs_help = true
+ active_list.save
+ render json: active_list.as_json.merge(list_active: true)
+ end
+ end
+ end
end
diff --git a/app/controllers/lists_controller.rb b/app/controllers/lists_controller.rb
index 47570537..0e57e00b 100644
--- a/app/controllers/lists_controller.rb
+++ b/app/controllers/lists_controller.rb
@@ -94,8 +94,8 @@ class ListsController < ApplicationController
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}
+ 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
@@ -110,12 +110,20 @@ class ListsController < ApplicationController
end
- # POST /orders/1/is_delivered
+ # POST /orders/1/is_closed
def is_closed
@list = List.find(params[:id])
@list.close!
render nothing: true
end
+
+ # POST /orders/1/is_helped
+ def is_helped
+ @list = List.find(params[:id])
+ @list.needs_help = false
+ @list.save
+ render nothing: true
+ end
private
def set_relation_options
diff --git a/app/controllers/suppliers_controller.rb b/app/controllers/suppliers_controller.rb
index 83b93934..0b560ff5 100644
--- a/app/controllers/suppliers_controller.rb
+++ b/app/controllers/suppliers_controller.rb
@@ -113,8 +113,8 @@ class SuppliersController < ApplicationController
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}
+ 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
@@ -141,7 +141,7 @@ class SuppliersController < ApplicationController
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)
+ 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
@@ -150,6 +150,7 @@ class SuppliersController < ApplicationController
end
end
end
+
private
def set_relation_options
diff --git a/app/models/list.rb b/app/models/list.rb
index 17e35f52..dad1a17d 100644
--- a/app/models/list.rb
+++ b/app/models/list.rb
@@ -2,7 +2,7 @@ class List
include SimplyStored::Couch
property :state, default: 'active' # active, #closed
- property :need_help, type: :boolean, default: false
+ property :needs_help, type: :boolean, default: false
property :needs_payment, type: :boolean, default: false
property :closed_at, type: Time
has_many :orders, dependent: :destroy
@@ -34,9 +34,11 @@ class List
return unless products.any?
@order = Order.create list: self, supplier: supplier
return unless @order.id
+ loaded_products = self.class.database.load_document products.keys
products.each do |product_id, number|
number = number.to_i
- ProductOrder.create order: @order, product_id: product_id, amount: number if number > 0
+ product = loaded_products.find{|p| p.id == product_id} # to get the price
+ ProductOrder.create order: @order, product_id: product_id, amount: number, price: product.price if number > 0
end
end
diff --git a/app/models/product_order.rb b/app/models/product_order.rb
index 76a1b54c..55645929 100644
--- a/app/models/product_order.rb
+++ b/app/models/product_order.rb
@@ -2,6 +2,7 @@ class ProductOrder
include SimplyStored::Couch
property :amount, type: Fixnum
+ property :price, type: Float
belongs_to :product
belongs_to :order
diff --git a/app/views/dashboard/show_products.html.slim b/app/views/dashboard/show_products.html.slim
index 8c008dfa..6ef68332 100644
--- a/app/views/dashboard/show_products.html.slim
+++ b/app/views/dashboard/show_products.html.slim
@@ -1,3 +1,7 @@
+.page-header
+ h4= t('user.show_products.title', products: Product.model_name.human_plural)
+= link_to t('helpers.links.show_active_list', list: List.model_name.human), user_active_list_path, class: ['btn btn']
+span#list-needs-help-button
table#products-table.table.table-striped.table-hover
tbody
-# content_for :sidebar do
@@ -12,7 +16,7 @@ table#active-order-table.table.table-striped.hide
tfoot
tr
td colspan=2
- button class="btn btn-primary" onClick="Qrammer.order_active_list('/order_active_list')" Bestellen
+ button class="btn btn-primary" onClick="Qrammer.handle_active_user_list(function(){Qrammer.order_active_products_list('/order_active_products_list')})" Bestellen
|
button class="btn btn btn-warning" onClick="Qrammer.clear_active_list()" Clear
td.currency
@@ -21,26 +25,29 @@ table#active-order-table.table.table-striped.hide
- content_for :footer do
javascript:
jQuery(function(){
- $.get('#{product_list_supplier_path(@supplier, format: :json).html_safe}', function(res){
- window.products = res
- body = $('#products-table tbody')
- for(var category in window.products){
- body.append('