Fixing up enterprise user account page

This commit is contained in:
Rob Harrington
2015-12-10 12:31:05 +11:00
parent fe0652e243
commit ecd11702c3
4 changed files with 51 additions and 22 deletions

View File

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

View File

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

View File

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

View File

@@ -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
&nbsp;
.ten.columns
&nbsp;
.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 &nbsp;
%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 &nbsp;
%td= adjustment.label
%td.text-right= adjustment.display_amount
%tr.total
%td.text-center &nbsp;
%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