Adding super admin configuration for the minimum billable turnover functionality

This commit is contained in:
Lynne Davis
2016-03-17 12:54:03 +00:00
parent 240be2be0f
commit 30ed6df38d
4 changed files with 19 additions and 4 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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"}

View File

@@ -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) }