diff --git a/app/controllers/admin/account_controller.rb b/app/controllers/admin/account_controller.rb new file mode 100644 index 0000000000..fd33857e05 --- /dev/null +++ b/app/controllers/admin/account_controller.rb @@ -0,0 +1,8 @@ +class Admin::AccountController < Spree::Admin::BaseController + + def show + @enterprises = spree_current_user.owned_enterprises + # .group_by('enterprise.id').joins(:billable_periods) + # .select('SUM(billable_periods.turnover) AS turnover').order('turnover DESC') + end +end diff --git a/app/models/billable_period.rb b/app/models/billable_period.rb index 836901fe63..c7a9074a87 100644 --- a/app/models/billable_period.rb +++ b/app/models/billable_period.rb @@ -4,6 +4,14 @@ class BillablePeriod < ActiveRecord::Base default_scope where(deleted_at: nil) + def display_turnover + Spree::Money.new(turnover, {currency: Spree::Config[:currency]}) + end + + def display_bill + Spree::Money.new(bill, {currency: Spree::Config[:currency]}) + end + def bill # Will make this more sophisicated in the future in that it will use global config variables to calculate return 0 if trial? diff --git a/app/views/admin/account/show.html.haml b/app/views/admin/account/show.html.haml new file mode 100644 index 0000000000..2d02f535e3 --- /dev/null +++ b/app/views/admin/account/show.html.haml @@ -0,0 +1,22 @@ + +- content_for :page_title do + = t(:account) + +- @enterprises.each do |enterprise| + %h2= enterprise.name + %table + %thead + %th Begins + %th Ends + %th Sells + %th Trial? + %th Turnover + %th Bill + - enterprise.billable_periods.each do |billable_period| + %tr + %td= billable_period.begins_at.strftime("%F %T") + %td= billable_period.ends_at.strftime("%F %T") + %td= billable_period.sells + %td= billable_period.trial? + %td= billable_period.display_turnover + %td= billable_period.display_bill diff --git a/spec/features/admin/account_spec.rb b/spec/features/admin/account_spec.rb new file mode 100644 index 0000000000..f2be99c3a3 --- /dev/null +++ b/spec/features/admin/account_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +feature 'Account Page' do + include AuthenticationWorkflow + + describe "updating" do + let!(:user) { create(:user) } + let!(:enterprise) { create(:distributor_enterprise, owner: user) } + + before do + quick_login_as user + end + + context "as an enterprise user" do + it "loads the page" do + visit admin_account_path + expect(page).to have_content "Account" + end + end + end +end