Adding an example bill calculator to business model config edit page

To allow super admin to see the effects of any changes they make to BMC settings
This commit is contained in:
Rob Harrington
2015-11-19 08:37:51 +11:00
parent 76d4f74f6b
commit 0ed8cf973d
8 changed files with 119 additions and 34 deletions

View File

@@ -1 +1 @@
angular.module("admin.accounts_and_billing_settings", [])
angular.module("admin.accounts_and_billing_settings", ["admin.utils"])

View File

@@ -23,6 +23,7 @@
//= require_tree ../templates/admin
//= require ./admin
//= require ./accounts_and_billing_settings/accounts_and_billing_settings
//= require ./business_model_configuration/business_model_configuration
//= require ./customers/customers
//= require ./dropdown/dropdown
//= require ./enterprises/enterprises

View File

@@ -0,0 +1 @@
angular.module("admin.businessModelConfiguration", ["admin.utils"])

View File

@@ -0,0 +1,21 @@
angular.module("admin.businessModelConfiguration").controller "BusinessModelConfigCtrl", ($scope, $filter) ->
$scope.turnover = 1000
$scope.bill = ->
return $filter('currency')(0) unless $scope.fixed || $scope.rate
Number($scope.fixed) + Number($scope.turnover) * Number($scope.rate)
$scope.cappedBill = ->
return $scope.bill() if !$scope.cap? || Number($scope.cap) == 0
Math.min($scope.bill(), Number($scope.cap))
$scope.capReached = ->
return "No" if !$scope.cap? || Number($scope.cap) == 0
if $scope.bill() >= Number($scope.cap) then "Yes" else "No"
$scope.includedTax = ->
return 0 if !$scope.taxRate? || Number($scope.taxRate) == 0
($scope.cappedBill() * Number($scope.taxRate))
$scope.total = ->
$scope.cappedBill() + $scope.includedTax()

View File

@@ -1,4 +1,4 @@
angular.module("admin.accounts_and_billing_settings").directive "watchValueAs", ->
angular.module("admin.utils").directive "watchValueAs", ->
restrict: 'A'
scope: {
value: "=watchValueAs"

View File

@@ -56,3 +56,21 @@ div#group_buy_calculation {
text-align: center;
}
}
.input-symbol {
position: relative;
&.before {
span {
position: absolute;
transform: translate(0,-50%);
top:50%;
pointer-events:none;
margin-left: 1em;
}
input {
text-indent:1em;
}
}
}

View File

@@ -6,36 +6,79 @@
= render 'spree/shared/error_messages', target: @settings
%fieldset.no-border-bottom
%legend=t(:monthly_bill_calculation_settings)
= form_for @settings, as: :settings, url: main_app.admin_business_model_configuration_path, :method => :put do |f|
.row
.three.columns.alpha
= f.label :account_invoices_monthly_fixed, t(:fixed_charge)
%span.with-tip.icon-question-sign{'data-powertip' => "A fixed monthly charge for ALL enterprises who are set up as a shop, regardless of how much produce they sell."}
.two.columns
= f.number_field :account_invoices_monthly_fixed, min: 0.0, class: "fullwidth"
.two.columns
 
.three.columns
= f.label :account_invoices_monthly_rate, t(:percentage_of_turnover)
%span.with-tip.icon-question-sign{'data-powertip' => "When greater than zero, this rate (0.0 - 1.0) will be applied to the total turnover of each shop and added to any fixed charges (to the left) to calculate the monthly bill."}
.two.columns.omega
= f.number_field :account_invoices_monthly_rate, min: 0.0, max: 1.0, step: 0.01, class: "fullwidth"
.row
.three.columns.alpha
= f.label :account_invoices_monthly_cap, t(:monthly_cap_excl_tax)
%span.with-tip.icon-question-sign{'data-powertip' => "When greater than zero, this value will be used as a cap on the amount that shops will be charged each month."}
.two.columns
= f.number_field :account_invoices_monthly_cap, min: 0.0, class: "fullwidth"
.two.columns
 
.three.columns
= f.label :account_invoices_tax_rate, t(:tax_rate)
%span.with-tip.icon-question-sign{'data-powertip' => "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"
.row{ ng: { app: 'admin.businessModelConfiguration', controller: "BusinessModelConfigCtrl" } }
.five.columns.omega
%fieldset.no-border-bottom
%legend=t(:bill_calculation_settings)
%p
Adjust the amount that enterprises will be billed each month for use of the OFN.
%br
= form_for @settings, as: :settings, url: main_app.admin_business_model_configuration_path, :method => :put do |f|
.row
.three.columns.alpha
= f.label :account_invoices_monthly_fixed, t(:fixed_monthly_charge)
%span.with-tip.icon-question-sign{'data-powertip' => "A fixed monthly charge for ALL enterprises who are set up as a shop, regardless of how much produce they sell."}
.two.columns.omega
.input-symbol.before
%span= Spree::Money.currency_symbol
= f.number_field :account_invoices_monthly_fixed, min: 0.0, class: "fullwidth", 'watch-value-as' => 'fixed'
.row
.three.columns.alpha
= f.label :account_invoices_monthly_rate, t(:percentage_of_turnover)
%span.with-tip.icon-question-sign{'data-powertip' => "When greater than zero, this rate (0.0 - 1.0) will be applied to the total turnover of each shop and added to any fixed charges (to the left) to calculate the monthly bill."}
.two.columns.omega
= f.number_field :account_invoices_monthly_rate, min: 0.0, max: 1.0, step: 0.01, class: "fullwidth", 'watch-value-as' => 'rate'
.row
.three.columns.alpha
= f.label :account_invoices_monthly_cap, t(:monthly_cap_excl_tax)
%span.with-tip.icon-question-sign{'data-powertip' => "When greater than zero, this value will be used as a cap on the amount that shops will be charged each month."}
.two.columns.omega
.input-symbol.before
%span= Spree::Money.currency_symbol
= f.number_field :account_invoices_monthly_cap, min: 0.0, class: "fullwidth", 'watch-value-as' => 'cap'
.row
.three.columns.alpha
= f.label :account_invoices_tax_rate, t(:tax_rate)
%span.with-tip.icon-question-sign{'data-powertip' => "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
.twelve.columns.alpha.omega.form-buttons{"data-hook" => "buttons"}
= button t(:update), 'icon-refresh', value: "update"
.row
.five.columns.alpha.omega.form-buttons{"data-hook" => "buttons"}
= button t(:update), 'icon-refresh', value: "update"
.two.columns
 
.five.columns.alpha
%fieldset.no-border-bottom
%legend=t(:example_bill_calculator)
%p
Alter the example turnover to visualise the effect of the settings to the left.
%br
.row
.three.columns.alpha
= label_tag :turnover, t(:example_monthly_turnover)
%span.with-tip.icon-question-sign{'data-powertip' => "An example monthly turnover for an enterprise which will be used to generate calculate an example monthly bill below."}
.two.columns.omega
.input-symbol.before
%span= Spree::Money.currency_symbol
%input.fullwidth{ id: 'turnover', type: "number", ng: { model: 'turnover' } }
.row
.three.columns.alpha
= label_tag :cap_reached, t(:cap_reached?)
%span.with-tip.icon-question-sign{'data-powertip' => "Whether the cap (specified to the left) has been reached, given the settings and the turnover provided."}
.two.columns.omega
%input.fullwidth{ id: 'cap_reached', type: "text", readonly: true, ng: { value: 'capReached()' } }
.row
.three.columns.alpha
= label_tag :included_tax, t(:included_tax)
%span.with-tip.icon-question-sign{'data-powertip' => "The total tax included in the example monthly bill, given the settings and the turnover provided."}
.two.columns.omega
%input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax() | currency' } }
.row
.three.columns.alpha
= label_tag :total_incl_tax, t(:total_monthly_bill_incl_tax)
%span.with-tip.icon-question-sign{'data-powertip' => "The example total monthly bill with tax included, given the settings and the turnover provided."}
.two.columns.omega
%input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total() | currency' } }

View File

@@ -38,6 +38,7 @@ en:
per_month: "per month"
free: "free"
plus_tax: "plus GST"
total_monthly_bill_incl_tax: "Total Monthly Bill (Incl. Tax)"
sort_order_cycles_on_shopfront_by: "Sort Order Cycles On Shopfront By"