From 30ed6df38d68931ea8b52fc72afb84cdc4fc551b Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Thu, 17 Mar 2016 12:54:03 +0000 Subject: [PATCH] Adding super admin configuration for the minimum billable turnover functionality --- .../business_model_configuration_controller.js.coffee | 6 +++++- .../admin/business_model_configuration_controller.rb | 4 +++- .../admin/business_model_configuration/edit.html.haml | 10 +++++++++- .../business_model_configuration_validator.rb | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/business_model_configuration/controllers/business_model_configuration_controller.js.coffee b/app/assets/javascripts/admin/business_model_configuration/controllers/business_model_configuration_controller.js.coffee index ca757c673d..8229def620 100644 --- a/app/assets/javascripts/admin/business_model_configuration/controllers/business_model_configuration_controller.js.coffee +++ b/app/assets/javascripts/admin/business_model_configuration/controllers/business_model_configuration_controller.js.coffee @@ -9,6 +9,10 @@ angular.module("admin.businessModelConfiguration").controller "BusinessModelConf return $scope.bill() if !$scope.cap? || Number($scope.cap) == 0 Math.min($scope.bill(), Number($scope.cap)) + $scope.finalBill = -> + return 0 if Number($scope.turnover) <= Number($scope.min_bill_to) + $scope.cappedBill() + $scope.capReached = -> return "No" if !$scope.cap? || Number($scope.cap) == 0 if $scope.bill() >= Number($scope.cap) then "Yes" else "No" @@ -18,4 +22,4 @@ angular.module("admin.businessModelConfiguration").controller "BusinessModelConf ($scope.cappedBill() * Number($scope.taxRate)) $scope.total = -> - $scope.cappedBill() + $scope.includedTax() + $scope.finalBill() + $scope.includedTax() diff --git a/app/controllers/admin/business_model_configuration_controller.rb b/app/controllers/admin/business_model_configuration_controller.rb index 967238b347..b3c3c67ab8 100644 --- a/app/controllers/admin/business_model_configuration_controller.rb +++ b/app/controllers/admin/business_model_configuration_controller.rb @@ -22,7 +22,9 @@ class Admin::BusinessModelConfigurationController < Spree::Admin::BaseController account_invoices_monthly_fixed: Spree::Config[:account_invoices_monthly_fixed], account_invoices_monthly_rate: Spree::Config[:account_invoices_monthly_rate], account_invoices_monthly_cap: Spree::Config[:account_invoices_monthly_cap], - account_invoices_tax_rate: Spree::Config[:account_invoices_tax_rate] + account_invoices_tax_rate: Spree::Config[:account_invoices_tax_rate], + minimum_billable_turnover: Spree::Config[:minimum_billable_turnover] + }) end diff --git a/app/views/admin/business_model_configuration/edit.html.haml b/app/views/admin/business_model_configuration/edit.html.haml index 4794c536b4..8a5c368444 100644 --- a/app/views/admin/business_model_configuration/edit.html.haml +++ b/app/views/admin/business_model_configuration/edit.html.haml @@ -26,7 +26,7 @@ .row .three.columns.alpha = f.label :account_invoices_monthly_fixed, t(:fixed_monthly_charge) - %span.icon-question-sign{'ofn-with-tip' => "A fixed monthly charge for ALL enterprises who are set up as a shop, regardless of how much produce they sell."} + %span.icon-question-sign{'ofn-with-tip' => "A fixed monthly charge for all enterprises who are set up as a shop and have exceeded the minimum billable turnover (if set)."} .two.columns.omega .input-symbol.before %span= Spree::Money.currency_symbol @@ -51,6 +51,14 @@ %span.icon-question-sign{'ofn-with-tip' => "Tax rate that applies to the the monthly bill that enterprises are charged for using the system."} .two.columns.omega = f.number_field :account_invoices_tax_rate, min: 0.0, max: 1.0, step: 0.01, class: "fullwidth", 'watch-value-as' => 'taxRate' + .row + .three.columns.alpha + = f.label :minimum_billable_turnover, t(:minimum_monthly_billable_turnover) + %span.icon-question-sign{'ofn-with-tip' => "Minimum monthly turnover before a shopfront will be charged for using OFN. Enterprises turning over less than this amount in a month will not be charged, either as a percentage or fixed rate. When set to -1 enterprises with no turnover will be charge the fixed rate as specified."} + .two.columns.omega + .input-symbol.before + %span= Spree::Money.currency_symbol + = f.number_field :minimum_billable_turnover, min: -1.0, class: "fullwidth", 'watch-value-as' => 'min_bill_to' .row .five.columns.alpha.omega.form-buttons{"data-hook" => "buttons"} diff --git a/lib/open_food_network/business_model_configuration_validator.rb b/lib/open_food_network/business_model_configuration_validator.rb index 0d6b4d9f83..1e1c077808 100644 --- a/lib/open_food_network/business_model_configuration_validator.rb +++ b/lib/open_food_network/business_model_configuration_validator.rb @@ -5,13 +5,14 @@ module OpenFoodNetwork class BusinessModelConfigurationValidator include ActiveModel::Validations - attr_accessor :shop_trial_length_days, :account_invoices_monthly_fixed, :account_invoices_monthly_rate, :account_invoices_monthly_cap, :account_invoices_tax_rate + attr_accessor :shop_trial_length_days, :account_invoices_monthly_fixed, :account_invoices_monthly_rate, :account_invoices_monthly_cap, :account_invoices_tax_rate, :minimum_billable_turnover validates :shop_trial_length_days, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :account_invoices_monthly_fixed, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :account_invoices_monthly_rate, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 } validates :account_invoices_monthly_cap, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :account_invoices_tax_rate, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 } + validates :minimum_billable_turnover, presence: true, numericality: { greater_than_or_equal_to: -1 } def initialize(attr, button=nil) attr.each { |k,v| instance_variable_set("@#{k}", v) }