mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Updating the admin account view to show use the new account_invoice model to display data
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user