diff --git a/lib/reporting/report_template.rb b/lib/reporting/report_template.rb index bfbb019b12..2e2ad8a614 100644 --- a/lib/reporting/report_template.rb +++ b/lib/reporting/report_template.rb @@ -88,7 +88,7 @@ module Reporting # summary_row: proc do |group_key, items, rows| # { # quantity: rows.map(&:quantity).sum(&:to_i), - # price: "#{rows.map(&:price).sum(&:to_f)} #{currency_symbol}" + # price: "#{rows.map(&:price).sum(&:to_f).round(2)} #{currency_symbol}" # } # end, # summary_row_class: "", # by default 'text-bold' diff --git a/lib/reporting/reports/bulk_coop/allocation.rb b/lib/reporting/reports/bulk_coop/allocation.rb index 051a1332df..ca951454d2 100644 --- a/lib/reporting/reports/bulk_coop/allocation.rb +++ b/lib/reporting/reports/bulk_coop/allocation.rb @@ -32,7 +32,7 @@ module Reporting summary_row: proc do |_key, items, rows| line_items = items.flatten { - sum_total: rows.map(&:sum_total).sum(&:to_f), + sum_total: rows.map(&:sum_total).sum(&:to_f).round(2), total_available: total_available(line_items), unallocated: remainder(line_items), max_quantity_excess: max_quantity_excess(line_items) diff --git a/lib/reporting/reports/bulk_coop/base.rb b/lib/reporting/reports/bulk_coop/base.rb index 371713d676..0d9e745252 100644 --- a/lib/reporting/reports/bulk_coop/base.rb +++ b/lib/reporting/reports/bulk_coop/base.rb @@ -94,7 +94,9 @@ module Reporting end def total_amount(line_items) - line_items.map { |li| scaled_final_weight_volume(li) }.sum(&:to_f) + line_items.map { |li| + scaled_final_weight_volume(li) + }.sum(&:to_f).round(2) end def scaled_final_weight_volume(line_item) diff --git a/lib/reporting/reports/bulk_coop/customer_payments.rb b/lib/reporting/reports/bulk_coop/customer_payments.rb index 4e4da4ce12..6746bfcaff 100644 --- a/lib/reporting/reports/bulk_coop/customer_payments.rb +++ b/lib/reporting/reports/bulk_coop/customer_payments.rb @@ -21,15 +21,15 @@ module Reporting private def customer_payments_total_cost(line_items) - unique_orders(line_items).map(&:total).sum(&:to_f) + unique_orders(line_items).map(&:total).sum(&:to_f).round(2) end def customer_payments_amount_owed(line_items) - unique_orders(line_items).map(&:new_outstanding_balance).sum(&:to_f) + unique_orders(line_items).map(&:new_outstanding_balance).sum(&:to_f).round(2) end def customer_payments_amount_paid(line_items) - unique_orders(line_items).map(&:payment_total).sum(&:to_f) + unique_orders(line_items).map(&:payment_total).sum(&:to_f).round(2) end def unique_orders(line_items) diff --git a/lib/reporting/reports/bulk_coop/supplier_report.rb b/lib/reporting/reports/bulk_coop/supplier_report.rb index d7e66c6353..2195ec8890 100644 --- a/lib/reporting/reports/bulk_coop/supplier_report.rb +++ b/lib/reporting/reports/bulk_coop/supplier_report.rb @@ -32,7 +32,7 @@ module Reporting summary_row: proc do |_key, items, rows| line_items = items.flatten { - sum_total: rows.map(&:sum_total).sum(&:to_f), + sum_total: rows.map(&:sum_total).sum(&:to_f).round(2), units_required: units_required(line_items), unallocated: remainder(line_items), max_quantity_excess: max_quantity_excess(line_items) diff --git a/lib/reporting/reports/customers/base.rb b/lib/reporting/reports/customers/base.rb index b53fb7b44c..19f1d7e271 100644 --- a/lib/reporting/reports/customers/base.rb +++ b/lib/reporting/reports/customers/base.rb @@ -33,7 +33,7 @@ module Reporting }, shipping_method: proc { |orders| last_completed_order(orders).shipping_method&.name }, total_orders: proc { |orders| orders.count }, - total_incl_tax: proc { |orders| orders.map(&:total).sum(&:to_f) }, + total_incl_tax: proc { |orders| orders.map(&:total).sum(&:to_f).round(2) }, last_completed_order_date: proc { |orders| last_completed_order_date(orders) }, } end diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb index abc27aa844..58a8cd6514 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb @@ -158,7 +158,7 @@ module Reporting end def enterprise_fees_sum(order) - amount = enterprise_fees(order).map(&:amount).sum(&:to_f) + amount = enterprise_fees(order).map(&:amount).sum(&:to_f).round(2) apply_voucher_on_amount(order, amount) end @@ -182,7 +182,8 @@ module Reporting query = order.all_adjustments.tax query = query.inclusive if included == true query = query.additional if added == true - amount = query.where(adjustable: enterprise_fees(order)).map(&:amount).sum(&:to_f) + amount = + query.where(adjustable: enterprise_fees(order)).map(&:amount).sum(&:to_f).round(2) apply_voucher_on_amount(order, amount) end diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index a005018b2e..002ec5916b 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -232,7 +232,7 @@ module Reporting line_item.supplier_id == supplier_id end - tax_for_enterprise_fees = rows.map(&:tax).sum(&:to_f) + tax_for_enterprise_fees = rows.map(&:tax).sum(&:to_f).round(2) total_excl_tax = total_fees_excl_tax(items) + line_items_excl_tax(line_items) tax = tax_for_enterprise_fees + tax_for_line_items(line_items) { @@ -280,18 +280,18 @@ module Reporting end def line_items_excl_tax(line_items) - cost_of_line_items(line_items) - line_items.map(&:included_tax).sum(&:to_f) + cost_of_line_items(line_items) - line_items.map(&:included_tax).sum(&:to_f).round(2) end def cost_of_line_items(line_items) - line_items.map(&:amount).sum(&:to_f) + line_items.map(&:amount).sum(&:to_f).round(2) end # This query gets called twice for each set of line_items, ideally it would be cached. def tax_for_line_items(line_items) line_items.map do |line_item| line_item.adjustments.eligible.tax.map(&:amount).sum(&:to_f) - end.sum(&:to_f) + end.sum(&:to_f).round(2) end def included_tax_for_order_ids(order_ids, enterprise_fee_ids) diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb index c1231bc2c8..3c93beb056 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb @@ -23,9 +23,9 @@ module Reporting variant: variant_name, quantity: proc { |line_items| line_items.map(&:quantity).sum(&:to_i) }, - item_price: proc { |line_items| line_items.map(&:amount).sum(&:to_f) }, + item_price: proc { |line_items| line_items.map(&:amount).sum(&:to_f).round(2) }, item_fees_price: proc { |line_items| - line_items.map(&:amount_with_adjustments).sum(&:to_f) + line_items.map(&:amount_with_adjustments).sum(&:to_f).round(2) }, admin_handling_fees: proc { |_line_items| "" }, ship_price: proc { |_line_items| "" }, @@ -68,7 +68,7 @@ module Reporting order_number: proc { |line_items| line_items.first.order.number }, date: proc { |line_items| line_items.first.order.completed_at.strftime("%F %T") }, final_weight_volume: proc { |line_items| - line_items.map(&:final_weight_volume).sum(&:to_f) + line_items.map(&:final_weight_volume).sum(&:to_f).round(2) }, shipment_state: proc { |line_items| line_items.first.order.shipment_state }, } @@ -129,8 +129,8 @@ module Reporting { hub: rows.last.hub, customer: rows.last.customer, - item_price: rows.map(&:item_price).sum(&:to_f), - item_fees_price: rows.map(&:item_fees_price).sum(&:to_f), + item_price: rows.map(&:item_price).sum(&:to_f).round(2), + item_fees_price: rows.map(&:item_fees_price).sum(&:to_f).round(2), admin_handling_fees: order.admin_and_handling_total, ship_price: order.ship_total, pay_fee_price: order.payment_fee, diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb index d9bca1f3f3..45d3133b2c 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_distributor_totals_by_supplier.rb @@ -12,7 +12,7 @@ module Reporting variant: variant_name, quantity: proc { |line_items| line_items.to_a.map(&:quantity).sum(&:to_i) }, curr_cost_per_unit: proc { |line_items| line_items.first.price }, - total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f) }, + total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f).round(2) }, total_shipping_cost: proc { |_line_items| "" }, shipping_method: proc { |line_items| line_items.first.order.shipping_method&.name } } @@ -25,9 +25,9 @@ module Reporting header: proc { |key, _items, _rows| "#{I18n.t(:report_header_hub)} #{key}" }, summary_row: proc do |_key, line_items, rows| { - total_cost: rows.map(&:total_cost).sum(&:to_f), + total_cost: rows.map(&:total_cost).sum(&:to_f).round(2), total_shipping_cost: - line_items.map(&:first).map(&:order).uniq.map(&:ship_total).sum(&:to_f) + line_items.map(&:first).map(&:order).uniq.map(&:ship_total).sum(&:to_f).round(2) } end } diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb index 1aeaa71986..1dfa1c2adf 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb @@ -12,7 +12,7 @@ module Reporting quantity: proc { |line_items| line_items.map(&:quantity).sum(&:to_i) }, total_units: proc { |line_items| total_units(line_items) }, curr_cost_per_unit: proc { |line_items| line_items.first.price }, - total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f) }, + total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f).round(2) }, sku: variant_sku, producer_charges_sales_tax?: supplier_charges_sales_tax?, product_tax_category: @@ -34,7 +34,7 @@ module Reporting { quantity: rows.map(&:quantity).sum(&:to_i), total_units: summary_total_units, - total_cost: rows.map(&:total_cost).sum(&:to_f) + total_cost: rows.map(&:total_cost).sum(&:to_f).round(2) } end } diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb index 039ed25e6d..68dcd7a8b6 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb @@ -12,7 +12,7 @@ module Reporting hub: hub_name, quantity: proc { |line_items| line_items.to_a.map(&:quantity).sum(&:to_i) }, curr_cost_per_unit: proc { |line_items| line_items.first.price }, - total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f) }, + total_cost: proc { |line_items| line_items.map(&:amount).sum(&:to_f).round(2) }, shipping_method: proc { |line_items| line_items.first.order.shipping_method&.name } } end @@ -32,7 +32,7 @@ module Reporting summary_row: proc do |_key, _items, rows| { quantity: rows.map(&:quantity).sum(&:to_i), - total_cost: rows.map(&:total_cost).sum(&:to_f) + total_cost: rows.map(&:total_cost).sum(&:to_f).round(2) } end, } diff --git a/lib/reporting/reports/packing/base.rb b/lib/reporting/reports/packing/base.rb index 8ad19d2fc5..4f2c7d2cf1 100644 --- a/lib/reporting/reports/packing/base.rb +++ b/lib/reporting/reports/packing/base.rb @@ -73,7 +73,7 @@ module Reporting proc do |_key, _items, rows| { quantity: rows.map(&:quantity).sum(&:to_i), - price: rows.map(&:price).sum(&:to_f) + price: rows.map(&:price).sum(&:to_f).round(2) } end end diff --git a/lib/reporting/reports/payments/itemised_payment_totals.rb b/lib/reporting/reports/payments/itemised_payment_totals.rb index fae956543d..48a4f7f6b3 100644 --- a/lib/reporting/reports/payments/itemised_payment_totals.rb +++ b/lib/reporting/reports/payments/itemised_payment_totals.rb @@ -8,12 +8,12 @@ module Reporting { payment_state: proc { |orders| payment_state(orders.first) }, distributor: proc { |orders| orders.first.distributor.name }, - product_total_price: proc { |orders| orders.map(&:item_total).sum(&:to_f) }, - shipping_total_price: proc { |orders| orders.map(&:ship_total).sum(&:to_f) }, + product_total_price: proc { |orders| orders.map(&:item_total).sum(&:to_f).round(2) }, + shipping_total_price: proc { |orders| orders.map(&:ship_total).sum(&:to_f).round(2) }, outstanding_balance_price: proc do |orders| - orders.map(&:outstanding_balance).sum(&:to_f) + orders.map(&:outstanding_balance).sum(&:to_f).round(2) end, - total_price: proc { |orders| orders.map(&:total).sum(&:to_f) } + total_price: proc { |orders| orders.map(&:total).sum(&:to_f).round(2) } } end end diff --git a/lib/reporting/reports/payments/payment_totals.rb b/lib/reporting/reports/payments/payment_totals.rb index 28ccde0cef..1dc89fd101 100644 --- a/lib/reporting/reports/payments/payment_totals.rb +++ b/lib/reporting/reports/payments/payment_totals.rb @@ -8,13 +8,13 @@ module Reporting { payment_state: proc { |orders| payment_state(orders.first) }, distributor: proc { |orders| orders.first.distributor.name }, - product_total_price: proc { |orders| orders.map(&:item_total).sum(&:to_f) }, - shipping_total_price: proc { |orders| orders.map(&:ship_total).sum(&:to_f) }, - total_price: proc { |orders| orders.map(&:total).sum(&:to_f) }, + product_total_price: proc { |orders| orders.map(&:item_total).sum(&:to_f).round(2) }, + shipping_total_price: proc { |orders| orders.map(&:ship_total).sum(&:to_f).round(2) }, + total_price: proc { |orders| orders.map(&:total).sum(&:to_f).round(2) }, eft_price: proc { |orders| total_by_payment_method(orders, "EFT") }, paypal_price: proc { |orders| total_by_payment_method(orders, "PayPal") }, outstanding_balance_price: proc { |orders| - orders.map(&:outstanding_balance).sum(&:to_f) + orders.map(&:outstanding_balance).sum(&:to_f).round(2) } } end @@ -24,7 +24,7 @@ module Reporting def total_by_payment_method(orders, pay_method) orders.map(&:payments).flatten.select { |payment| payment.completed? && payment.payment_method&.name.to_s.include?(pay_method) - }.map(&:amount).sum(&:to_f) + }.map(&:amount).sum(&:to_f).round(2) end end end diff --git a/lib/reporting/reports/payments/payments_by_payment_type.rb b/lib/reporting/reports/payments/payments_by_payment_type.rb index 1ea7696af7..a0c66977af 100644 --- a/lib/reporting/reports/payments/payments_by_payment_type.rb +++ b/lib/reporting/reports/payments/payments_by_payment_type.rb @@ -18,7 +18,7 @@ module Reporting payment_state: proc { |payments| payment_state(payments.first.order) }, distributor: proc { |payments| payments.first.order.distributor.name }, payment_type: proc { |payments| payments.first.payment_method&.name }, - total_price: proc { |payments| payments.map(&:amount).sum(&:to_f) } + total_price: proc { |payments| payments.map(&:amount).sum(&:to_f).round(2) } } end end diff --git a/lib/reporting/reports/revenues_by_hub/base.rb b/lib/reporting/reports/revenues_by_hub/base.rb index 243a0dd518..71eb6f0d88 100644 --- a/lib/reporting/reports/revenues_by_hub/base.rb +++ b/lib/reporting/reports/revenues_by_hub/base.rb @@ -60,8 +60,8 @@ module Reporting grouped_orders.each do |orders| voucher_adjustments = calculate_voucher_adjustments(orders) - total_incl_tax = orders.map(&:total).sum(&:to_f) - total_tax = orders.map(&:total_tax).sum(&:to_f) + voucher_adjustments + total_incl_tax = orders.map(&:total).sum(&:to_f).round(2) + total_tax = orders.map(&:total_tax).sum(&:to_f).round(2) + voucher_adjustments total_excl_tax = total_incl_tax - total_tax @tax_data[distributor(orders).id] = { diff --git a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb index 58b8c2706f..8d6fd2066f 100644 --- a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb +++ b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb @@ -77,10 +77,11 @@ module Reporting summary_row: proc do |_key, items, _rows| line_items = items.flat_map(&:second).flatten.uniq total_excl_tax = - line_items.map(&:amount).sum(&:to_f) - line_items.map(&:included_tax).sum(&:to_f) + line_items.map(&:amount).sum(&:to_f).round(2) - + line_items.map(&:included_tax).sum(&:to_f).round(2) tax = line_items.map do |line_item| line_item.adjustments.eligible.tax.map(&:amount).sum(&:to_f) - end.sum(&:to_f) + end.sum(&:to_f).round(2) { total_excl_tax:, tax:, @@ -126,8 +127,8 @@ module Reporting end def total_excl_tax(query_result_row) - line_items(query_result_row).map(&:amount).sum(&:to_f) - - line_items(query_result_row).map(&:included_tax).sum(&:to_f) + line_items(query_result_row).map(&:amount).sum(&:to_f).round(2) - + line_items(query_result_row).map(&:included_tax).sum(&:to_f).round(2) end def tax(query_result_row) @@ -136,7 +137,7 @@ module Reporting .where(originator_id: tax_rate_id(query_result_row)) .map(&:amount) .sum(&:to_f) - end&.sum(&:to_f) + end&.sum(&:to_f)&.round(2) end def total_incl_tax(query_result_row) diff --git a/lib/reporting/reports/sales_tax/tax_types.rb b/lib/reporting/reports/sales_tax/tax_types.rb index d9c0fa6203..acd141af0c 100644 --- a/lib/reporting/reports/sales_tax/tax_types.rb +++ b/lib/reporting/reports/sales_tax/tax_types.rb @@ -53,7 +53,7 @@ module Reporting end def tax_included_in(line_item) - line_item.adjustments.tax.inclusive.map(&:amount).sum(&:to_f) + line_item.adjustments.tax.inclusive.map(&:amount).sum(&:to_f).round(2) end end end diff --git a/lib/reporting/reports/xero_invoices/base.rb b/lib/reporting/reports/xero_invoices/base.rb index 8cc666b767..0e1ab55a51 100644 --- a/lib/reporting/reports/xero_invoices/base.rb +++ b/lib/reporting/reports/xero_invoices/base.rb @@ -207,34 +207,36 @@ module Reporting end def total_untaxable_products(order) - order.line_items.without_tax.map(&:amount).sum(&:to_f) + order.line_items.without_tax.map(&:amount).sum(&:to_f).round(2) end def total_taxable_products(order) - order.line_items.with_tax.map(&:amount).sum(&:to_f) + order.line_items.with_tax.map(&:amount).sum(&:to_f).round(2) end def total_untaxable_fees(order) - order.all_adjustments.enterprise_fee.where(tax_category: nil).map(&:amount).sum(&:to_f) + order.all_adjustments.enterprise_fee.where(tax_category: nil) + .map(&:amount).sum(&:to_f).round(2) end def total_taxable_fees(order) order.all_adjustments.enterprise_fee.where.not(tax_category: nil) - .map(&:amount).sum(&:to_f) + .map(&:amount).sum(&:to_f).round(2) end def total_shipping(order) - order.all_adjustments.shipping.map(&:amount).sum(&:to_f) + order.all_adjustments.shipping.map(&:amount).sum(&:to_f).round(2) end def total_transaction(order) - order.all_adjustments.payment_fee.map(&:amount).sum(&:to_f) + order.all_adjustments.payment_fee.map(&:amount).sum(&:to_f).round(2) end def tax_on_shipping_s(order) tax_on_shipping = order.shipments .map{ |shipment| shipment.additional_tax_total + shipment.included_tax_total } .sum(&:to_f) + .round(2) .positive? if tax_on_shipping I18n.t(:report_header_gst_on_income) @@ -244,11 +246,11 @@ module Reporting end def total_untaxable_admin_adjustments(order) - order.adjustments.admin.where(tax_category: nil).map(&:amount).sum(&:to_f) + order.adjustments.admin.where(tax_category: nil).map(&:amount).sum(&:to_f).round(2) end def total_taxable_admin_adjustments(order) - order.adjustments.admin.where.not(tax_category: nil).map(&:amount).sum(&:to_f) + order.adjustments.admin.where.not(tax_category: nil).map(&:amount).sum(&:to_f).round(2) end def detail?