add filtering by fee name

This commit is contained in:
Mohamed ABDELLANI
2023-06-12 15:20:00 +01:00
parent f66d9b9626
commit 9d53d775a6
2 changed files with 34 additions and 12 deletions

View File

@@ -544,11 +544,8 @@ module Spree
shipment_adjustments.reload.tax.sum(:amount)
end
def enterprise_fee_tax(included: false,added: false)
query = all_adjustments.tax
query = query.inclusive if included == true
query = query.additional if added == true
query.where(adjustable: all_adjustments.enterprise_fee).sum(:amount)
def enterprise_fee_tax
all_adjustments.tax.where(adjustable: all_adjustments.enterprise_fee).sum(:amount)
end
def total_tax

View File

@@ -8,10 +8,7 @@ module Reporting
def initialize(user, params = {}, render: false)
super(user, params, render: render)
@parameters = Parameters.new(p || {})
@parameters.validate!
@permissions = Permissions.new(user)
@parameters.authorize!(@permissions)
end
def search
@@ -45,6 +42,7 @@ module Reporting
.enterprise_fee
.group('originator_id')
.pluck("originator_id", 'array_agg(id)')
.filter(&method(:filter_enterprise_fee))
.map do |enterprise_fee_id, enterprise_fee_adjustment_ids|
{
enterprise_fee_id: enterprise_fee_id,
@@ -55,6 +53,14 @@ module Reporting
end
end
# [enteperise_fee_id, [adjustment_ids]]
def filter_enterprise_fee(arg)
return true if ransack_params[:enterprise_fee_id_in].reject(&:blank?).empty?
enterprise_fee_id = arg.first.to_s
enterprise_fee_id.in?(ransack_params[:enterprise_fee_id_in])
end
def join_tax_rate
proc do |item|
tax_rate_ids = item[:order].all_adjustments.tax.where(
@@ -119,11 +125,11 @@ module Reporting
summary_row: proc do |_key, items, _rows|
item = items.first
order = item.second
enterprise_fees = order.all_adjustments.enterprise_fee.sum(:amount)
enterprise_fees = enterprise_fees_sum(order)
{
total_excl_tax: enterprise_fees - order.enterprise_fee_tax(included: true),
tax: order.enterprise_fee_tax,
total_incl_tax: enterprise_fees + order.enterprise_fee_tax(added: true),
total_excl_tax: enterprise_fees - enterprise_fee_tax(order, included: true),
tax: enterprise_fee_tax(order),
total_incl_tax: enterprise_fees + enterprise_fee_tax(order, added: true),
customer_first_name: order.customer&.first_name,
customer_last_name: order.customer&.last_name,
customer_code: order.customer&.code,
@@ -134,6 +140,25 @@ module Reporting
]
end
def enterprise_fees_sum(order)
enterprise_fees(order).sum(:amount)
end
def enterprise_fees(order)
query = order.all_adjustments.enterprise_fee
unless ransack_params[:enterprise_fee_id_in].reject(&:blank?).empty?
query = query.where(originator_id: ransack_params[:enterprise_fee_id_in])
end
query
end
def enterprise_fee_tax(order, included: false, added: false)
query = order.all_adjustments.tax
query = query.inclusive if included == true
query = query.additional if added == true
query.where(adjustable: enterprise_fees(order)).sum(:amount)
end
def distributor(query_result_row)
order(query_result_row).distributor&.name
end