From ecd11702c391c5df7b7b7cb9c3a5ad6f0d1295f2 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 10 Dec 2015 12:31:05 +1100 Subject: [PATCH] Fixing up enterprise user account page --- app/controllers/admin/account_controller.rb | 3 -- app/helpers/admin/account_helper.rb | 14 ++++++ app/models/spree/ability_decorator.rb | 5 ++ app/views/admin/account/show.html.haml | 51 +++++++++++++-------- 4 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 app/helpers/admin/account_helper.rb diff --git a/app/controllers/admin/account_controller.rb b/app/controllers/admin/account_controller.rb index a752b2cfdd..00531cd426 100644 --- a/app/controllers/admin/account_controller.rb +++ b/app/controllers/admin/account_controller.rb @@ -2,8 +2,5 @@ class Admin::AccountController < Spree::Admin::BaseController def show @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 end diff --git a/app/helpers/admin/account_helper.rb b/app/helpers/admin/account_helper.rb new file mode 100644 index 0000000000..0292522b74 --- /dev/null +++ b/app/helpers/admin/account_helper.rb @@ -0,0 +1,14 @@ +module Admin + module AccountHelper + def invoice_description_for(invoice) + month = t(:abbr_month_names, :scope => :date)[invoice.month] + year = invoice.year + star = invoice.order.nil? || invoice.order.completed? ? "" : "*" + "#{month} #{year}#{star}" + end + + def invoice_total_for(invoice) + invoice.order.andand.display_total || Spree::Money.new(0, { :currency => Spree::Config[:currency] }) + end + end +end diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index 82054ad792..25e0ced2cc 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -92,6 +92,11 @@ class AbilityDecorator can [:admin, :known_users], :search can [:admin, :show], :account + + # For printing own account invoice orders + can [:print], Spree::Order do |order| + order.user == user + end end def add_product_management_abilities(user) diff --git a/app/views/admin/account/show.html.haml b/app/views/admin/account/show.html.haml index 809d52eb2f..09a6862d2e 100644 --- a/app/views/admin/account/show.html.haml +++ b/app/views/admin/account/show.html.haml @@ -7,34 +7,47 @@ %h4= t(:no_invoices_to_display) - @invoices.order('year DESC, month DESC').each do |invoice| - - order = invoice.order .row.invoice_title - .eight.columns.alpha - %h4= "#{t(:abbr_month_names, :scope => :date)[invoice.month]} #{invoice.year}#{invoice.order.completed? ? "" : "*"}" - .eight.columns.omega.text-right - %h4.balance= invoice.order.display_total + .two.columns.alpha + %h4= invoice_description_for(invoice) + .two.columns.text-right + %h5 + - if invoice.order.andand.complete? + %a{ href: print_admin_order_url(invoice.order), :target => "_blank"} + %i.icon-print + = t(:print) + - else +   + .ten.columns +   + .two.columns.omega.text-right + %h4.balance= invoice_total_for(invoice) %table.invoice_summary - %col{ width: '20%' } - %col{ width: '60%' } - %col{ width: '20%' } + %col{ width: '25%' } + %col{ width: '62.5%' } + %col{ width: '12.5%' } %thead %th Date %th= t(:description) %th= t(:charge) - - invoice.billable_periods.select{ |bp| bp.bill > 0}.each do |billable_period| - %tr - %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.text-center   - %td= adjustment.label - %td.text-right= adjustment.display_amount + - if order = invoice.order + - invoice.billable_periods.select{ |bp| bp.bill > 0}.each do |billable_period| + %tr + %td.text-center= "#{billable_period.begins_at.strftime("%d/%m/%Y")}" + %td= billable_period.label + -# Using amount from the actual adjustment on the order here so that we avoid recalculating the bill + -# at a future date with different settings to those used at the time the invoice was finalized + %td.text-right= billable_period.adjustment.display_amount + - order.adjustments.where('source_type <> (?)', "BillablePeriod").reject{ |a| a.amount == 0 }.each do |adjustment| + %tr + %td.text-center   + %td= adjustment.label + %td.text-right= adjustment.display_amount %tr.total %td.text-center   %td= t(:total).upcase - %td.text-right= order.display_total + %td.text-right= invoice_total_for(invoice) + -# - if @enterprises.empty? -# %h4 No enterprises to display