mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Fixing up enterprise user account page
This commit is contained in:
@@ -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
|
||||
|
||||
14
app/helpers/admin/account_helper.rb
Normal file
14
app/helpers/admin/account_helper.rb
Normal 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
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user