diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 8d56d6715..fe03569ed 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -3,13 +3,29 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. - def gross_price - add_percent(price + deposit, tax) + def gross_price(include_deposit: true) + if include_deposit + add_percent(price + deposit, tax) + else + add_percent(price, tax) + end end # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price, FoodsoftConfig[:price_markup].to_i) + add_percent(gross_price(include_deposit: false), FoodsoftConfig[:price_markup]) + fc_deposit + end + + def gross_deposit + add_percent(deposit, tax) + end + + def fc_deposit + if FoodsoftConfig[:deposit_with_markup] || false + add_percent(gross_deposit, FoodsoftConfig[:price_markup]) + else + gross_deposit + end end private diff --git a/app/models/order.rb b/app/models/order.rb index 23c19baab..db2289f93 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -189,6 +189,14 @@ def articles_sort_by_category end end + def has_deposit? + order_articles.any? { |oa| oa.article.deposit > 0 } + end + + def has_tolerance? + order_articles.any? { |oa| oa.article.unit_quantity > 1 } + end + # Returns the defecit/benefit for the foodcoop # Requires a valid invoice, belonging to this order # FIXME: Consider order.foodcoop_result diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 9061bdf85..1f93071e7 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -77,11 +77,15 @@ %th{style: 'width:120px'}= heading_helper StockArticle, :supplier %th{style: "width:13px;"} %th{style: "width:4.5em;"}= t '.price' + - if @order.has_deposit? + %th{style: "width:4.5em;"}= t '.contains_deposit' %th{style: "width:4.5em;"}= heading_helper Article, :unit - unless @order.stockit? - %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true + - if @order.has_tolerance? + %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true %th#col_required= heading_helper GroupOrderArticle, :quantity - %th#col_tolerance= heading_helper GroupOrderArticle, :tolerance + - if @order.has_tolerance? + %th#col_tolerance= heading_helper GroupOrderArticle, :tolerance - else %th(style="width:20px")= heading_helper StockArticle, :available %th#col_required= heading_helper GroupOrderArticle, :quantity @@ -100,35 +104,43 @@ %td= truncate order_article.article.supplier.name, length: 15 %td= h order_article.article.origin %td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price]) + - if @order.has_deposit? + - deposit = order_article.article.fc_deposit + %td= number_to_currency(deposit) if deposit>0 %td= order_article.article.unit - %td - - if @order.stockit? - = @ordering_data[:order_articles][order_article.id][:quantity_available] - - else - %span{id: "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units] + - if @order.has_tolerance? || @order.stockit? + %td + - if @order.stockit? + = @ordering_data[:order_articles][order_article.id][:quantity_available] + - else + %span{id: "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units] %td.quantity %input{id: "q_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:quantity], 'data-min' => (@ordering_data[:order_articles][order_article.id][:quantity] if @order.boxfill?), 'data-max' => (@ordering_data[:order_articles][order_article.id][:quantity]+@ordering_data[:order_articles][order_article.id][:missing_units] if @order.boxfill?)}/ %span.used{id: "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity] - + - %span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity] + - if order_article.article.unit_quantity > 1 + + + %span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity] + - else + %span.unused{style: "color: transparent;"} + 0 .btn-group %a.btn.btn-ordering{'data-increase_quantity' => order_article.id} %i.icon-plus %a.btn.btn-ordering{'data-decrease_quantity' => order_article.id} %i.icon-minus - %td.tolerance{style: ('display:none' if @order.stockit?)} - %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ - - if (@ordering_data[:order_articles][order_article.id][:unit] > 1) - %span.used{id: "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance] - + - %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] - .btn-group - %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} - %i.icon-plus - %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} - %i.icon-minus + - if @order.has_tolerance? + %td.tolerance{style: ('display:none' if @order.stockit?)} + %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ + - if (@ordering_data[:order_articles][order_article.id][:unit] > 1) + %span.used{id: "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance] + + + %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] + .btn-group + %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} + %i.icon-plus + %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} + %i.icon-minus %td{id: "td_price_#{order_article.id}", style: "text-align:right; padding-right:10px; width:4em"} %span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price])