From 6a613a2203f672c98cbe69f7b5973846f38ba6b4 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Thu, 5 Dec 2024 18:53:35 +0500 Subject: [PATCH 1/6] 13013: add producer charges gst column --- config/locales/en.yml | 1 + lib/reporting/reports/suppliers/base.rb | 1 + lib/reporting/reports/suppliers/helpers/columns_helper.rb | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 07a974d49a..b67986c78c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3320,6 +3320,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_item_fees_price: "Item + Fees (%{currency})" report_header_admin_handling_fees: "Admin & Handling (%{currency})" report_header_ship_price: "Ship (%{currency})" + report_header_producer_charges_gst: Producer charges GST? report_header_pay_fee_price: "Pay fee (%{currency})" report_header_total_price: "Total (%{currency})" report_header_product_total_price: "Product Total (%{currency})" diff --git a/lib/reporting/reports/suppliers/base.rb b/lib/reporting/reports/suppliers/base.rb index f6723ffdc8..dadc4a2b78 100644 --- a/lib/reporting/reports/suppliers/base.rb +++ b/lib/reporting/reports/suppliers/base.rb @@ -28,6 +28,7 @@ module Reporting producer:, producer_address:, producer_abn_acn:, + producer_charges_gst:, email:, hub:, hub_address:, diff --git a/lib/reporting/reports/suppliers/helpers/columns_helper.rb b/lib/reporting/reports/suppliers/helpers/columns_helper.rb index 2405a5442a..f110822cbd 100644 --- a/lib/reporting/reports/suppliers/helpers/columns_helper.rb +++ b/lib/reporting/reports/suppliers/helpers/columns_helper.rb @@ -23,6 +23,12 @@ module Reporting end end + def producer_charges_gst + proc do |line_items| + supplier(line_items).charges_sales_tax ? I18n.t(:yes) : I18n.t(:no) + end + end + def email proc { |line_item| supplier(line_item).email_address } end From 71b2b7f97f4740592d02cae9b1060866a0910e37 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sun, 8 Dec 2024 00:29:48 +0500 Subject: [PATCH 2/6] 13013: add tax on product column --- config/locales/en.yml | 1 + lib/reporting/reports/suppliers/base.rb | 1 + .../suppliers/helpers/columns_helper.rb | 28 +++++++++---------- .../helpers/line_items_access_helper.rb | 7 ++++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index b67986c78c..26d12688c5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3321,6 +3321,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_admin_handling_fees: "Admin & Handling (%{currency})" report_header_ship_price: "Ship (%{currency})" report_header_producer_charges_gst: Producer charges GST? + report_header_total_tax_on_product: Total tax on product report_header_pay_fee_price: "Pay fee (%{currency})" report_header_total_price: "Total (%{currency})" report_header_product_total_price: "Product Total (%{currency})" diff --git a/lib/reporting/reports/suppliers/base.rb b/lib/reporting/reports/suppliers/base.rb index dadc4a2b78..e1e8cc0d0d 100644 --- a/lib/reporting/reports/suppliers/base.rb +++ b/lib/reporting/reports/suppliers/base.rb @@ -44,6 +44,7 @@ module Reporting total_excl_fees_and_tax:, total_excl_vat:, total_fees_excl_tax:, + total_tax_on_product:, total_tax_on_fees:, total_tax:, total:, diff --git a/lib/reporting/reports/suppliers/helpers/columns_helper.rb b/lib/reporting/reports/suppliers/helpers/columns_helper.rb index f110822cbd..6e853d8969 100644 --- a/lib/reporting/reports/suppliers/helpers/columns_helper.rb +++ b/lib/reporting/reports/suppliers/helpers/columns_helper.rb @@ -25,7 +25,7 @@ module Reporting def producer_charges_gst proc do |line_items| - supplier(line_items).charges_sales_tax ? I18n.t(:yes) : I18n.t(:no) + supplier(line_items).charges_sales_tax end end @@ -86,8 +86,7 @@ module Reporting def total_excl_vat proc do |line_item| - total_fees = adjustments_by_type(line_item, :fees) - total_excl_fees_and_tax.call(line_item) + total_fees + total_excl_fees_and_tax.call(line_item) + total_fees_excl_tax.call(line_item) end end @@ -98,11 +97,7 @@ module Reporting end end - def total_tax_on_fees - proc { |line_item| tax_on_fees(line_item) + tax_on_fees(line_item, included: true) } - end - - def total_tax + def total_tax_on_product proc do |line_item| excluded_tax = adjustments_by_type(line_item, :tax) included_tax = adjustments_by_type(line_item, :tax, included: true) @@ -111,14 +106,19 @@ module Reporting end end + def total_tax_on_fees + proc { |line_item| tax_on_fees(line_item) + tax_on_fees(line_item, included: true) } + end + + def total_tax + proc do |line_item| + total_tax_on_product.call(line_item) + total_tax_on_fees.call(line_item) + end + end + def total proc do |line_item| - total_price = total_excl_fees_and_tax.call(line_item) - total_fees = total_fees_excl_tax.call(line_item) - total_fees_tax = total_tax_on_fees.call(line_item) - tax = total_tax.call(line_item) - - total_price + total_fees + total_fees_tax + tax + total_excl_vat.call(line_item) + total_tax.call(line_item) end end end diff --git a/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb b/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb index 3152cac7dd..4b1f16a35c 100644 --- a/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb +++ b/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb @@ -38,8 +38,11 @@ module Reporting end def adjustments_by_type(line_item, type, included: false) + is_tax = type == :tax + return 0.0 if is_tax && !supplier(line_item).charges_sales_tax + total_amount = 0.0 - adjustment_type = type == :tax ? 'Spree::TaxRate' : 'EnterpriseFee' + adjustment_type = is_tax ? 'Spree::TaxRate' : 'EnterpriseFee' suppliers_adjustments(line_item, adjustment_type).each do |adjustment| amount = included == adjustment.included ? adjustment.amount : 0.0 total_amount += amount @@ -49,6 +52,8 @@ module Reporting end def tax_on_fees(line_item, included: false) + return 0.0 unless supplier(line_item).charges_sales_tax + total_amount = 0.0 suppliers_adjustments(line_item).each do |adjustment| adjustment.adjustments.tax.each do |fee_adjustment| From e8b185256ec6fd4c16756e5dc59812503e727e30 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 13 Dec 2024 00:55:27 +0500 Subject: [PATCH 3/6] 13013: add specs --- .../lib/reports/suppliers/pay_your_suppliers_report_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/lib/reports/suppliers/pay_your_suppliers_report_spec.rb b/spec/lib/reports/suppliers/pay_your_suppliers_report_spec.rb index 9494342ee0..945c47f541 100644 --- a/spec/lib/reports/suppliers/pay_your_suppliers_report_spec.rb +++ b/spec/lib/reports/suppliers/pay_your_suppliers_report_spec.rb @@ -24,6 +24,7 @@ RSpec.describe "Pay Your Suppliers Report" do expect(table_row.producer).to eq(supplier.name) expect(table_row.producer_address).to eq(supplier.address.full_address) expect(table_row.producer_abn_acn).to eq("none") + expect(table_row.producer_charges_gst).to eq("No") expect(table_row.email).to eq("none") expect(table_row.hub).to eq(hub.name) expect(table_row.hub_address).to eq(hub.address.full_address) @@ -42,6 +43,7 @@ RSpec.describe "Pay Your Suppliers Report" do expect(table_row.total_excl_vat.to_f).to eq(10.0) expect(table_row.total_fees_excl_tax.to_f).to eq(0.0) expect(table_row.total_tax_on_fees.to_f).to eq(0.0) + expect(table_row.total_tax_on_product.to_f).to eq(0.0) expect(table_row.total_tax.to_f).to eq(0.0) expect(table_row.total.to_f).to eq(10.0) end @@ -94,11 +96,13 @@ RSpec.describe "Pay Your Suppliers Report" do expect(report_table_rows.length).to eq(1) table_row = report_table_rows.first + expect(table_row.producer_charges_gst).to eq('Yes') expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0) expect(table_row.total_excl_vat.to_f).to eq(10.1) expect(table_row.total_fees_excl_tax.to_f).to eq(0.1) expect(table_row.total_tax_on_fees.to_f).to eq(0.01) - expect(table_row.total_tax.to_f).to eq(1.0) + expect(table_row.total_tax_on_product.to_f).to eq(1.0) + expect(table_row.total_tax.to_f).to eq(1.01) expect(table_row.total.to_f).to eq(11.11) end end From 393154bae3518d5a8a41a7ba788e8b24773deeee Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 13 Dec 2024 01:14:03 +0500 Subject: [PATCH 4/6] 13013: fix specs --- config/locales/en.yml | 2 +- spec/system/admin/reports/pay_your_suppliers_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 26d12688c5..946f9c24d7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3321,7 +3321,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_header_admin_handling_fees: "Admin & Handling (%{currency})" report_header_ship_price: "Ship (%{currency})" report_header_producer_charges_gst: Producer charges GST? - report_header_total_tax_on_product: Total tax on product + report_header_total_tax_on_product: "Total tax on product (%{currency})" report_header_pay_fee_price: "Pay fee (%{currency})" report_header_total_price: "Total (%{currency})" report_header_product_total_price: "Product Total (%{currency})" diff --git a/spec/system/admin/reports/pay_your_suppliers_spec.rb b/spec/system/admin/reports/pay_your_suppliers_spec.rb index b22a094c5d..d771712b07 100644 --- a/spec/system/admin/reports/pay_your_suppliers_spec.rb +++ b/spec/system/admin/reports/pay_your_suppliers_spec.rb @@ -48,6 +48,7 @@ RSpec.describe "Pay Your Suppliers Report" do "Producer", "Producer Address", "Producer ABN/ACN", + "Producer charges GST?", "Email", "Hub", "Hub Address", @@ -63,6 +64,7 @@ RSpec.describe "Pay Your Suppliers Report" do "Total excl. fees and tax ($)", "Total excl. tax ($)", "Total fees excl. tax ($)", + "Total tax on product ($)", "Total tax on fees ($)", "Total Tax ($)", "Total ($)" @@ -83,6 +85,7 @@ RSpec.describe "Pay Your Suppliers Report" do supplier.name, supplier.address.full_address, "none", + "No", "none", hub1.name, hub1.address.full_address, @@ -100,6 +103,7 @@ RSpec.describe "Pay Your Suppliers Report" do 0.0, 0.0, 0.0, + 0.0, 10.0, ].compact.join(" ")) end @@ -115,6 +119,7 @@ RSpec.describe "Pay Your Suppliers Report" do supplier.name, supplier.address.full_address, "none", + "No", "none", hub2.name, hub2.address.full_address, @@ -132,6 +137,7 @@ RSpec.describe "Pay Your Suppliers Report" do 0.0, 0.0, 0.0, + 0.0, 10.0, ].compact.join(" ")) end From d86965bc1423d482e3edea4de6490f85719ce282 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Tue, 28 Jan 2025 03:35:46 +0500 Subject: [PATCH 5/6] add total tax on product summary --- lib/reporting/reports/suppliers/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/reporting/reports/suppliers/base.rb b/lib/reporting/reports/suppliers/base.rb index e1e8cc0d0d..edfa1576fa 100644 --- a/lib/reporting/reports/suppliers/base.rb +++ b/lib/reporting/reports/suppliers/base.rb @@ -66,6 +66,7 @@ module Reporting 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) + summary_hash[:total_tax_on_product] += total_tax_on_product.call(line_item) end summary_hash From 5dddf8b69aa239584679a54a21907f6a06b3bd4d Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 31 Jan 2025 17:32:27 +0500 Subject: [PATCH 6/6] fix specs --- spec/system/admin/reports/pay_your_suppliers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/reports/pay_your_suppliers_spec.rb b/spec/system/admin/reports/pay_your_suppliers_spec.rb index d771712b07..12649e3ebf 100644 --- a/spec/system/admin/reports/pay_your_suppliers_spec.rb +++ b/spec/system/admin/reports/pay_your_suppliers_spec.rb @@ -143,7 +143,7 @@ RSpec.describe "Pay Your Suppliers Report" do end # summary row - expect(lines.last).to have_content("TOTAL 50.0 50.0 0.0 0.0 0.0 50.0") + expect(lines.last).to have_content("TOTAL 50.0 50.0 0.0 0.0 0.0 0.0 50.0") end end