Skip to content

Commit

Permalink
Merge pull request #12879 from chahmedejaz/task/12776-pay-suppliers-r…
Browse files Browse the repository at this point in the history
…eport

[Flower Farms] - Pay Suppliers Report
  • Loading branch information
RachL authored Nov 15, 2024
2 parents 8c6c1e2 + ed76852 commit db79af4
Show file tree
Hide file tree
Showing 10 changed files with 667 additions and 91 deletions.
2 changes: 1 addition & 1 deletion app/models/spree/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def add_product_management_abilities(user)
can [:admin, :index, :show, :create], ::Admin::ReportsController
can [:admin, :show, :create, :customers, :orders_and_distributors, :group_buys, :payments,
:orders_and_fulfillment, :products_and_inventory, :order_cycle_management,
:packing, :enterprise_fee_summary, :bulk_coop], :report
:packing, :enterprise_fee_summary, :bulk_coop, :suppliers], :report
end

def add_order_cycle_management_abilities(user)
Expand Down
14 changes: 14 additions & 0 deletions app/views/admin/reports/filters/_suppliers.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
= render 'admin/reports/date_range_form', f: f

.row
.alpha.two.columns= label_tag nil, t(:report_hubs)
.omega.fourteen.columns= f.collection_select(:distributor_id_in, @data.orders_distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true})

.row
.alpha.two.columns= label_tag nil, t(:report_producers)
.omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@data.orders_suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true})

.row
.alpha.two.columns= label_tag nil, t(:report_customers_cycle)
.omega.fourteen.columns
= f.select(:order_cycle_id_in, report_order_cycle_options(@data.order_cycles), {selected: params.dig(:q, :order_cycle_id_in)}, {class: "select2 fullwidth", multiple: true})
13 changes: 13 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,7 @@ en:
pack_by_customer: Pack By Customer
pack_by_supplier: Pack By Supplier
pack_by_product: Pack By Product
pay_your_suppliers: Pay your suppliers
display:
report_is_big: "This report is big and may slow down your device."
display_anyway: "Display anyway"
Expand Down Expand Up @@ -1814,6 +1815,8 @@ en:
enterprise_fee_summary:
name: "Enterprise Fee Summary"
description: "Summary of Enterprise Fees collected"
suppliers:
name: Suppliers
enterprise_fees_with_tax_report_by_order: "Enterprise Fees With Tax Report By Order"
enterprise_fees_with_tax_report_by_producer: "Enterprise Fees With Tax Report By Producer"
errors:
Expand Down Expand Up @@ -3172,6 +3175,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_render_options: Rendering Options
report_header_ofn_uid: OFN UID
report_header_order_cycle: Order Cycle
report_header_order_cycle_start_date: OC Start Date
report_header_order_cycle_end_date: OC End Date
report_header_user: User
report_header_email: Email
report_header_status: Status
Expand All @@ -3192,6 +3197,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_hub_legal_name: "Hub Legal Name"
report_header_hub_contact_name: "Hub Contact Name"
report_header_hub_email: "Hub Public Email"
report_header_hub_contact_email: Hub Contact Email
report_header_hub_owner_email: Hub Owner Email
report_header_hub_phone: "Hub Phone Number"
report_header_hub_address_line1: "Hub Address Line 1"
Expand Down Expand Up @@ -3252,6 +3258,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_quantity: Quantity
report_header_max_quantity: Max Quantity
report_header_variant: Variant
report_header_variant_unit_name: Variant Unit Name
report_header_variant_value: Variant Value
report_header_variant_unit: Variant Unit
report_header_total_available: Total available
Expand All @@ -3263,6 +3270,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_producer_suburb: Producer Suburb
report_header_producer_tax_status: Producer Tax Status
report_header_producer_charges_sales_tax?: GST/VAT Registered
report_header_producer_abn_acn: Producer ABN/ACN
report_header_producer_address: Producer Address
report_header_unit: Unit
report_header_group_buy_unit_quantity: Group Buy Unit Quantity
report_header_cost: Cost
Expand Down Expand Up @@ -3323,7 +3332,11 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_total_units: Total Units
report_header_sum_max_total: "Sum Max Total"
report_header_total_excl_vat: "Total excl. tax (%{currency_symbol})"
report_header_total_fees_excl_tax: "Total fees excl. tax (%{currency_symbol})"
report_header_total_tax_on_fees: "Total tax on fees (%{currency_symbol})"
report_header_total: "Total (%{currency_symbol})"
report_header_total_incl_vat: "Total incl. tax (%{currency_symbol})"
report_header_total_excl_fees_and_tax: "Total excl. fees and tax (%{currency_symbol})"
report_header_temp_controlled: TempControlled?
report_header_is_producer: Producer?
report_header_not_confirmed: Not Confirmed
Expand Down
93 changes: 3 additions & 90 deletions lib/reporting/reports/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Reporting
module Reports
class List
include ReportTypes

def self.all
new.all
end
Expand All @@ -22,98 +24,9 @@ def all
xero_invoices: xero_report_types,
packing: packing_report_types,
revenues_by_hub: [],
suppliers: suppliers_report_types,
}
end

protected

def orders_and_fulfillment_report_types
[
[i18n_translate("supplier_totals"), :order_cycle_supplier_totals],
[i18n_translate("supplier_totals_by_distributor"),
:order_cycle_supplier_totals_by_distributor],
[i18n_translate("totals_by_supplier"), :order_cycle_distributor_totals_by_supplier],
[i18n_translate("customer_totals"), :order_cycle_customer_totals]
]
end

def products_and_inventory_report_types
[
[i18n_translate("all_products"), :all_products],
[i18n_translate("inventory"), :inventory, { deprecated: true }],
[i18n_translate("lettuce_share"), :lettuce_share]
]
end

def payments_report_types
[
[I18n.t(:report_payment_by), :payments_by_payment_type],
[I18n.t(:report_itemised_payment), :itemised_payment_totals],
[I18n.t(:report_payment_totals), :payment_totals]
]
end

def enterprise_fee_summary
[
[i18n_translate('enterprise_fee_summary.name'), :fee_summary],
[
i18n_translate('enterprise_fees_with_tax_report_by_order'),
:enterprise_fees_with_tax_report_by_order
],
[
i18n_translate('enterprise_fees_with_tax_report_by_producer'),
:enterprise_fees_with_tax_report_by_producer
],
]
end

def order_cycle_management_report_types
[
[i18n_translate("payment_methods"), :payment_methods],
[i18n_translate("delivery"), :delivery]
]
end

def sales_tax_report_types
[
[i18n_translate("tax_types"), :tax_types],
[i18n_translate("tax_rates"), :tax_rates],
[i18n_translate("sales_tax_totals_by_producer"), :sales_tax_totals_by_producer],
[i18n_translate("sales_tax_totals_by_order"), :sales_tax_totals_by_order]
]
end

def packing_report_types
[
[i18n_translate("pack_by_customer"), :customer],
[i18n_translate("pack_by_supplier"), :supplier],
[i18n_translate("pack_by_product"), :product]
]
end

def xero_report_types
[
[I18n.t(:summary), 'summary'],
[I18n.t(:detailed), 'detailed']
]
end

def bulk_coop_report_types
[
bulk_coop_item(:supplier_report),
bulk_coop_item(:allocation),
bulk_coop_item(:packing_sheets),
bulk_coop_item(:customer_payments)
]
end

def bulk_coop_item(key)
[I18n.t("order_management.reports.bulk_coop.filters.bulk_coop_#{key}"), key]
end

def i18n_translate(key)
I18n.t(key, scope: "admin.reports")
end
end
end
end
103 changes: 103 additions & 0 deletions lib/reporting/reports/report_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

module Reporting
module Reports
module ReportTypes
protected

def orders_and_fulfillment_report_types
[
[i18n_translate("supplier_totals"), :order_cycle_supplier_totals],
[i18n_translate("supplier_totals_by_distributor"),
:order_cycle_supplier_totals_by_distributor],
[i18n_translate("totals_by_supplier"), :order_cycle_distributor_totals_by_supplier],
[i18n_translate("customer_totals"), :order_cycle_customer_totals]
]
end

def products_and_inventory_report_types
[
[i18n_translate("all_products"), :all_products],
[i18n_translate("inventory"), :inventory, { deprecated: true }],
[i18n_translate("lettuce_share"), :lettuce_share]
]
end

def payments_report_types
[
[I18n.t(:report_payment_by), :payments_by_payment_type],
[I18n.t(:report_itemised_payment), :itemised_payment_totals],
[I18n.t(:report_payment_totals), :payment_totals]
]
end

def enterprise_fee_summary
[
[i18n_translate('enterprise_fee_summary.name'), :fee_summary],
[
i18n_translate('enterprise_fees_with_tax_report_by_order'),
:enterprise_fees_with_tax_report_by_order
],
[
i18n_translate('enterprise_fees_with_tax_report_by_producer'),
:enterprise_fees_with_tax_report_by_producer
],
]
end

def order_cycle_management_report_types
[
[i18n_translate("payment_methods"), :payment_methods],
[i18n_translate("delivery"), :delivery]
]
end

def sales_tax_report_types
[
[i18n_translate("tax_types"), :tax_types],
[i18n_translate("tax_rates"), :tax_rates],
[i18n_translate("sales_tax_totals_by_producer"), :sales_tax_totals_by_producer],
[i18n_translate("sales_tax_totals_by_order"), :sales_tax_totals_by_order]
]
end

def packing_report_types
[
[i18n_translate("pack_by_customer"), :customer],
[i18n_translate("pack_by_supplier"), :supplier],
[i18n_translate("pack_by_product"), :product]
]
end

def xero_report_types
[
[I18n.t(:summary), 'summary'],
[I18n.t(:detailed), 'detailed']
]
end

def bulk_coop_report_types
[
bulk_coop_item(:supplier_report),
bulk_coop_item(:allocation),
bulk_coop_item(:packing_sheets),
bulk_coop_item(:customer_payments)
]
end

def suppliers_report_types
[
[i18n_translate(:pay_your_suppliers), :pay_your_suppliers]
]
end

def bulk_coop_item(key)
[I18n.t("order_management.reports.bulk_coop.filters.bulk_coop_#{key}"), key]
end

def i18n_translate(key)
I18n.t(key, scope: "admin.reports")
end
end
end
end
99 changes: 99 additions & 0 deletions lib/reporting/reports/suppliers/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# frozen_string_literal: true

module Reporting
module Reports
module Suppliers
class Base < ReportTemplate
include Helpers::ColumnsHelper

def default_params
{
q: {
completed_at_gt: 1.month.ago.beginning_of_day,
completed_at_lt: 1.day.from_now.beginning_of_day
}
}
end

def search
report_line_items.orders
end

def query_result
report_line_items.list(line_item_includes)
end

def columns
{
producer:,
producer_address:,
producer_abn_acn:,
email:,
hub:,
hub_address:,
hub_contact_email:,
order_number:,
order_date:,
order_cycle:,
order_cycle_start_date:,
order_cycle_end_date:,
product:,
variant_unit_name:,
quantity:,
total_excl_fees_and_tax:,
total_excl_vat:,
total_fees_excl_tax:,
total_tax_on_fees:,
total_tax:,
total:,
}
end

def rules
[
{
group_by: :producer,
header: true,
summary_row: proc do |_key, line_items|
summary_hash = Hash.new(0)

line_items.each do |line_item|
summary_hash[:total_excl_fees_and_tax] += total_excl_fees_and_tax.call(line_item)
summary_hash[:total_excl_vat] += total_excl_vat.call(line_item)
summary_hash[:total_fees_excl_tax] += total_fees_excl_tax.call(line_item)
summary_hash[:total_tax_on_fees] += total_tax_on_fees.call(line_item)
summary_hash[:total_tax] += total_tax.call(line_item)
summary_hash[:total] += total.call(line_item)
end

summary_hash
end
}
]
end

private

def order_permissions
return @order_permissions unless @order_permissions.nil?

@order_permissions = ::Permissions::Order.new(@user, ransack_params)
end

def report_line_items
@report_line_items ||= Reporting::LineItems.new(order_permissions, params)
end

def line_item_includes
[{
order: [
:distributor,
:adjustments,
],
variant: [:product, :supplier]
}]
end
end
end
end
end
Loading

0 comments on commit db79af4

Please sign in to comment.