diff --git a/app/controllers/admin/account_controller.rb b/app/controllers/admin/account_controller.rb index 63114b05f8..a752b2cfdd 100644 --- a/app/controllers/admin/account_controller.rb +++ b/app/controllers/admin/account_controller.rb @@ -1,8 +1,8 @@ class Admin::AccountController < Spree::Admin::BaseController def show - @invoices = spree_current_user.orders.where(distributor_id: Spree::Config[:accounts_distributor_id]) - @enterprises = Enterprise.where(id: BillablePeriod.where(owner_id: spree_current_user).map(&:enterprise_id)) + @invoices = spree_current_user.account_invoices + # @enterprises = Enterprise.where(id: BillablePeriod.where(owner_id: spree_current_user).map(&:enterprise_id)) # .group_by('enterprise.id').joins(:billable_periods) # .select('SUM(billable_periods.turnover) AS turnover').order('turnover DESC') end diff --git a/app/models/billable_period.rb b/app/models/billable_period.rb index 1fd243c22f..8ea3829440 100644 --- a/app/models/billable_period.rb +++ b/app/models/billable_period.rb @@ -25,14 +25,19 @@ class BillablePeriod < ActiveRecord::Base end end - def adjustment_label + def label enterprise_version = enterprise.version_at(begins_at) category = enterprise_version.category.to_s.titleize category += (trial ? " Trial" : "") + + "#{enterprise_version.name} (#{category})" + end + + def adjustment_label begins = begins_at.localtime.strftime("%d/%m/%y") ends = ends_at.localtime.strftime("%d/%m/%y") - "#{enterprise_version.name} (#{category}) [#{begins} - #{ends}]" + "#{label} [#{begins} - #{ends}]" end def delete diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 1b31230fea..b724a41d1b 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -7,6 +7,7 @@ Spree.user_class.class_eval do has_many :enterprises, through: :enterprise_roles has_many :owned_enterprises, class_name: 'Enterprise', foreign_key: :owner_id, inverse_of: :owner has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner + has_many :account_invoices has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner has_one :cart has_many :customers diff --git a/app/views/admin/account/show.html.haml b/app/views/admin/account/show.html.haml index b209e51e11..48aefd2fc5 100644 --- a/app/views/admin/account/show.html.haml +++ b/app/views/admin/account/show.html.haml @@ -6,13 +6,13 @@ - if @invoices.empty? %h4 No invoices to display -- @invoices.order('created_at DESC').each do |invoice| - - month = (invoice.created_at.localtime) +- @invoices.order('year DESC, month DESC').each do |invoice| + - order = invoice.order .row.invoice_title .eight.columns.alpha - %h4= "#{month.strftime("%b %Y")}#{( invoice.completed_at ? '' : '*' )}" + %h4= "#{Date::ABBR_MONTHNAMES[invoice.month]} #{invoice.year}" .eight.columns.omega.text-right - %h4.balance= invoice.display_total + %h4.balance= invoice.order.display_total %table.invoice_summary %col{ width: '20%' } %col{ width: '60%' } @@ -21,22 +21,20 @@ %th Date %th Description %th Charge - - invoice.adjustments.where(source_type: 'BillablePeriod').each do |adjustment| - - date = adjustment.label.slice!(/\[[^\]]*\]$/) - - date = date.slice(1,date.length-2) + - invoice.billable_periods.select{ |bp| bp.bill > 0}.each do |billable_period| %tr - %td= date - %td= adjustment.label - %td= adjustment.display_amount - - invoice.adjustments.where('source_type <> (?)', "BillablePeriod").each do |adjustment| + %td.text-center= "#{billable_period.begins_at.strftime("%d/%m/%Y")}" + %td= billable_period.label + %td.text-right= billable_period.display_bill + - order.adjustments.where('source_type <> (?)', "BillablePeriod").each do |adjustment| %tr - %td   + %td.text-center   %td= adjustment.label - %td= adjustment.display_amount + %td.text-right= adjustment.display_amount %tr.total - %td   + %td.text-center   %td TOTAL - %td= invoice.display_total + %td.text-right= order.display_total -# - if @enterprises.empty? -# %h4 No enterprises to display