From 42b90912b1af5db275eb6e06ab5d89c3220153ac Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:07:28 +0100 Subject: [PATCH 01/44] Update invoice.rb exclude stock_orders in orders_sum, consider deliveries_sum --- app/models/invoice.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 781b1f1f4..a853b420a 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -31,21 +31,29 @@ def net_amount end def orders_sum - orders - .joins(order_articles: [:article_price]) - .sum('COALESCE(order_articles.units_received, order_articles.units_billed, order_articles.units_to_order)' \ - + '* article_prices.unit_quantity' \ - + '* ROUND((article_prices.price + article_prices.deposit) * (100 + article_prices.tax) / 100, 2)') + sum = 0 + for order in orders + sum += order.sum(:groups) + end + sum end def orders_transport_sum orders.sum(:transport) end - + + def deliveries_sum + sum = 0 + for delivery in deliveries + sum += delivery.sum + end + sum + end + def expected_amount return net_amount unless orders.any? - orders_sum + orders_transport_sum + orders_sum + orders_transport_sum + deliveries_sum end protected From e2285708caa036775048a776d0e830d8a395740a Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:15:28 +0100 Subject: [PATCH 02/44] Update order.rb exclude stock-orders from sum(:groups) --- app/models/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order.rb b/app/models/order.rb index 23c19baab..d98423f9f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -220,7 +220,7 @@ def sum(type = :gross) end end elsif %i[groups groups_without_markup].include?(type) - for go in group_orders.includes(group_order_articles: { order_article: %i[article article_price] }) + for go in group_orders.includes(group_order_articles: { order_article: %i[article article_price] }).where.not(ordergroup: nil) for goa in go.group_order_articles case type when :groups From c0654c28341a74d6aaa552a9afa2887dbd92bf4f Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:20:55 +0100 Subject: [PATCH 03/44] Update show.html.haml show order sums without and with stock order, consider only sums without stock order for total --- app/views/finance/invoices/show.html.haml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 3cd96b5f2..424f346ca 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -28,12 +28,15 @@ %dt= heading_helper(Invoice, :orders) + ':' %dd>< - @invoice.orders.order(:ends).each_with_index do |order, index| + - sum_og = order.sum(:groups) - sum = order.sum - transport = order.transport || 0 - - total += sum + transport + - total += sum_og + transport = ', ' if index > 0 = link_to format_date(order.ends), new_finance_order_path(order_id: order) - = ' (' + number_to_currency(sum) + = ' (' + number_to_currency(sum_og) + - if sum_og < sum + = ' / ' + number_to_currency(sum) - if transport != 0 = ' + ' + number_to_currency(transport) = ')' From ab4ff5b7cd79b96c5a475b678243bce6ace50a03 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:52:41 +0100 Subject: [PATCH 04/44] Update invoice.rb replaced for loop for summation by .sum() --- app/models/invoice.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a853b420a..138bde4fb 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -31,11 +31,7 @@ def net_amount end def orders_sum - sum = 0 - for order in orders - sum += order.sum(:groups) - end - sum + orders.sum { |order| order.sum(:groups) } end def orders_transport_sum @@ -43,11 +39,7 @@ def orders_transport_sum end def deliveries_sum - sum = 0 - for delivery in deliveries - sum += delivery.sum - end - sum + deliveries.sum(&:sum) end def expected_amount From c5761bb0aedd1de09bce93f8481249c326fc2d61 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:47:44 +0100 Subject: [PATCH 05/44] Update invoice.rb order sum without markup like in the current implementation --- app/models/invoice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 138bde4fb..e85c6102c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -31,7 +31,7 @@ def net_amount end def orders_sum - orders.sum { |order| order.sum(:groups) } + orders.sum { |order| order.sum(:groups_without_markup) } end def orders_transport_sum From 34e1c35e7ce3b794ca163ffa8e68f3de02e24c9c Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:50:04 +0100 Subject: [PATCH 06/44] Update show.html.haml sum_og without markup, like order.sum --- app/views/finance/invoices/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 424f346ca..6d2d8cc13 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -28,7 +28,7 @@ %dt= heading_helper(Invoice, :orders) + ':' %dd>< - @invoice.orders.order(:ends).each_with_index do |order, index| - - sum_og = order.sum(:groups) + - sum_og = order.sum(:groups_without_markup) - sum = order.sum - transport = order.transport || 0 - total += sum_og + transport From 46e54caa8380953003ace4d63d208cee771fe166 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:45:11 +0100 Subject: [PATCH 07/44] Update invoice.rb added type argument for order and delivery sum and for expected_amount for calculation without and with markup --- app/models/invoice.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index e85c6102c..ccdf53f1e 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -30,22 +30,30 @@ def net_amount amount - deposit + deposit_credit end - def orders_sum - orders.sum { |order| order.sum(:groups_without_markup) } + def orders_sum(type = :without_markup) + if type == :without_markup + orders.sum { |order| order.sum(:groups_without_markup) } + elsif type == :with_markup + orders.sum { |order| order.sum(:groups) } + end end def orders_transport_sum orders.sum(:transport) end - - def deliveries_sum - deliveries.sum(&:sum) + + def deliveries_sum(type = :without_markup) + if type == :without_markup + deliveries.sum(&:sum) + elsif type == :with_markup + deliveries.sum { |delivery| delivery.sum(:fc)} + end end - - def expected_amount + + def expected_amount(type = :without_markup) return net_amount unless orders.any? - orders_sum + orders_transport_sum + deliveries_sum + orders_sum(type) + orders_transport_sum + deliveries_sum(type) end protected From 895eb6b69677207996a4fd4aa86d8f7da423af38 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:49:05 +0100 Subject: [PATCH 08/44] Update show.html.haml added additional total with markup added foodcoop profit without/with markup --- app/views/finance/invoices/show.html.haml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 6d2d8cc13..029ecd140 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -63,8 +63,23 @@ %dd= number_to_currency @invoice.net_amount - if @invoice.deliveries.any? || @invoice.orders.any? - %dt= heading_helper(Invoice, :total) + ':' - %dd= number_to_currency total + %dt= heading_helper(Invoice, :total) + (total_fc > total ? t('.without_extra_charge') : '') + ':' # + %dd= number_to_currency(total) + - if total_fc > total + %dt= heading_helper(Invoice, :total) + t('.with_extra_charge') + ':' + %dd= number_to_currency(total_fc) + + %dt= t('.fc_profit') + (total_fc > total ? t('.without_extra_charge') : '') + ':' + - profit = total - @invoice.net_amount + %dd + %span{style: "color:#{profit < 0 ? 'red' : 'green'}"} + = number_to_currency(profit) + - if total_fc > total + %dt= t('.fc_profit') + ' ' + t('.with_extra_charge') + ':' + - profit = total_fc - @invoice.net_amount + %dd + %span{style: "color:#{profit < 0 ? 'red' : 'green'}"} + = number_to_currency(profit) - if @invoice.attachments.attached? %dt= heading_helper(Invoice, :attachment) + ':' From e0dfb47bad6e4686b1045ba0494235b1119036a6 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:01:24 +0100 Subject: [PATCH 09/44] Update de.yml show invoice labels for profit and markup --- config/locales/de.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index 68e01b143..51a1f2bee 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -990,6 +990,9 @@ de: title: Neue Rechnung anlegen show: title: Rechnung %{number} + fc_profit: FC Gewinn + with_extra_charge: ' mit Aufschlag' + without_extra_charge: ' ohne Aufschlag' unpaid: invoices_sum: Gesamtsumme invoices_text: Verwendungszweck From 876789c6db49b4bf3dd12d464daa6c7555dc3fb7 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:07:14 +0100 Subject: [PATCH 10/44] Update en.yml added show invoice labels for fc profit and markup (margin) --- config/locales/en.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index a863a670b..300e6c0e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -990,6 +990,9 @@ en: title: Create new invoice show: title: Invoice %{number} + fc_profit: FC Profit + with_extra_charge: ' with margin' + without_extra_charge: ' without margin' unpaid: invoices_sum: Total sum invoices_text: Reference From 728de447a00f0c732e3f4be005110942cc8c62ae Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:10:43 +0100 Subject: [PATCH 11/44] Update invoice.rb --- app/models/invoice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index ccdf53f1e..a3a00bcef 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -46,7 +46,7 @@ def deliveries_sum(type = :without_markup) if type == :without_markup deliveries.sum(&:sum) elsif type == :with_markup - deliveries.sum { |delivery| delivery.sum(:fc)} + deliveries.sum { |delivery| delivery.sum(:fc) } end end From 02290c845be08ff25a1c118399744c2610a5ef9c Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:36:14 +0100 Subject: [PATCH 12/44] Update invoice.rb - unnecessary whitspaces deleted --- app/models/invoice.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a3a00bcef..a36721d4c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -34,7 +34,7 @@ def orders_sum(type = :without_markup) if type == :without_markup orders.sum { |order| order.sum(:groups_without_markup) } elsif type == :with_markup - orders.sum { |order| order.sum(:groups) } + orders.sum { |order| order.sum(:groups) } end end @@ -44,16 +44,16 @@ def orders_transport_sum def deliveries_sum(type = :without_markup) if type == :without_markup - deliveries.sum(&:sum) - elsif type == :with_markup - deliveries.sum { |delivery| delivery.sum(:fc) } + deliveries.sum(&:sum) + elsif type == :with_markup + deliveries.sum { |delivery| delivery.sum(:fc) } end end def expected_amount(type = :without_markup) return net_amount unless orders.any? - orders_sum(type) + orders_transport_sum + deliveries_sum(type) + orders_sum(type) + orders_transport_sum + deliveries_sum(type) end protected From b932440bec0146c582d0bc0699403a50a51abd82 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:59:38 +0100 Subject: [PATCH 13/44] Update show.html.haml missing lines added for total_fc calculation --- app/views/finance/invoices/show.html.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 029ecd140..ec5e7274c 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -1,6 +1,7 @@ - title t('.title', number: @invoice.number) - total = 0 +- total_fc = 0 .row-fluid .span6 @@ -20,6 +21,7 @@ - @invoice.deliveries.order(:date).each_with_index do |delivery, index| - sum = delivery.sum - total += sum + - total_fc += delivery.sum(:fc) = ', ' if index > 0 = link_to format_date(delivery.date), [delivery.supplier, delivery] = ' (' + number_to_currency(sum) + ')' @@ -32,6 +34,7 @@ - sum = order.sum - transport = order.transport || 0 - total += sum_og + transport + - total_fc += order.sum(:groups) + transport = ', ' if index > 0 = link_to format_date(order.ends), new_finance_order_path(order_id: order) = ' (' + number_to_currency(sum_og) From 25b43b4acf3397717df3eab0aad0fb4277846b1b Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:09:18 +0100 Subject: [PATCH 14/44] Update invoice.rb calculate transport sum only from ordegroup transport charges --- app/models/invoice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index a36721d4c..dab32d1fb 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -39,7 +39,7 @@ def orders_sum(type = :without_markup) end def orders_transport_sum - orders.sum(:transport) + orders.sum { |order| order.sum(:transport) } end def deliveries_sum(type = :without_markup) From a66c4b48eb09fd763155bb0d13b4fc53aec43499 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:22:08 +0100 Subject: [PATCH 15/44] Update order.rb added order sum over group order transport charges. this can be different form the order's transport amount if groups are not charged with transport costs or if stock orders exist. --- app/models/order.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index d98423f9f..73df022a1 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -230,6 +230,8 @@ def sum(type = :gross) end end end + elsif type == :transport + total = group_orders.where.not(ordergroup: nil).sum(:transport) end total end From aa89f20f95ade3d42c0292974d6c439475e85c64 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:29:51 +0100 Subject: [PATCH 16/44] Update show.html.haml show total transport costs and sum of ordergroup charges for transport if they differ. for total, consider only the ordergroup transport charges. --- app/views/finance/invoices/show.html.haml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index ec5e7274c..e75d324a9 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -30,18 +30,21 @@ %dt= heading_helper(Invoice, :orders) + ':' %dd>< - @invoice.orders.order(:ends).each_with_index do |order, index| - - sum_og = order.sum(:groups_without_markup) - - sum = order.sum + - sum_og = order.sum(:groups_without_markup) # without markup + - sum = order.sum # without markup + - transport_og = order.sum(:transport) - transport = order.transport || 0 - - total += sum_og + transport - - total_fc += order.sum(:groups) + transport + - total += sum_og + transport_og # without markup + - total_fc += order.sum(:groups) + transport_og # with_markup = ', ' if index > 0 = link_to format_date(order.ends), new_finance_order_path(order_id: order) = ' (' + number_to_currency(sum_og) - if sum_og < sum = ' / ' + number_to_currency(sum) - if transport != 0 - = ' + ' + number_to_currency(transport) + = ' + ' + number_to_currency(transport_og) + - if transport_og < transport + = ' / ' + number_to_currency(transport) = ')' %dt= heading_helper(Invoice, :number) + ':' From cc21da8c4220ee410337a6444359ed2549e4b81b Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:28:16 +0100 Subject: [PATCH 17/44] Update unpaid.html.haml if markup is used, show both differences without and with markup --- app/views/finance/invoices/unpaid.html.haml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/finance/invoices/unpaid.html.haml b/app/views/finance/invoices/unpaid.html.haml index f93932c6c..d9b9e9c6e 100644 --- a/app/views/finance/invoices/unpaid.html.haml +++ b/app/views/finance/invoices/unpaid.html.haml @@ -9,16 +9,20 @@ %p - for invoice in invoices - invoice_amount_diff = invoice.expected_amount - invoice.net_amount + - invoice_profit = invoice.expected_amount(:with_markup) - invoice.net_amount - invoices_sum += invoice.amount - invoices_text << invoice.number = link_to finance_invoice_path(invoice) do = format_date invoice.date = ' ' + invoice.number = ' ' + number_to_currency(invoice.amount) - - if invoice_amount_diff != 0 - %span{style: "color:#{invoice_amount_diff < 0 ? 'red' : 'green'}"} - = invoice_amount_diff > 0 ? '+' : '-' - = number_to_currency(invoice_amount_diff.abs) + %span{style: "color:#{invoice_amount_diff < 0 ? 'red' : 'green'}"} + - # = invoice_amount_diff > 0 ? '+' : '-' + = number_to_currency(invoice_amount_diff) #.abs) + - if invoice_profit > invoice_amount_diff + = ' / ' + %span{style: "color:#{invoice_profit < 0 ? 'red' : 'green'}"} + = number_to_currency(invoice_profit) - if invoice.attachments.attached? - for attachment in invoice.attachments = link_to attachment.filename, url_for(attachment) From d2198f6f6f6bc4a817bb33e0f9e89b2c38709958 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:38:47 +0100 Subject: [PATCH 18/44] Update invoice.rb: calculate expected_amount also if invoice has no orders if an invoice has only deliveries but nor orders, expected amount returned the invoice net-amount but not the deliveries. if an invoice has no orders and deliveries, expected_amount is now 0. --- app/models/invoice.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index dab32d1fb..8418ec576 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -51,8 +51,6 @@ def deliveries_sum(type = :without_markup) end def expected_amount(type = :without_markup) - return net_amount unless orders.any? - orders_sum(type) + orders_transport_sum + deliveries_sum(type) end From ab424ac534c53ad7a5f91282ef5f2e88184e0c71 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:37:37 +0100 Subject: [PATCH 19/44] =?UTF-8?q?Update=20de.yml:=20Gewinn=20>=20=C3=9Cber?= =?UTF-8?q?schuss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Überschuss" drückt aus, dass die Einnahmen die Kosten übersteigen, ohne den kommerziellen oder profitorientierten Charakter anzudeuten, der mit "Gewinn" assoziiert wird. --- config/locales/de.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 51a1f2bee..6a74340cd 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -859,7 +859,7 @@ de: changed: Daten wurden verändert! duration: von %{starts} bis %{ends} fc_amount: 'FC-Betrag:' - fc_profit: FC Gewinn + fc_profit: FC Überschuss gross_amount: 'Bruttobetrag:' groups_amount: 'Gruppenbeträge:' net_amount: 'Nettobetrag:' @@ -990,7 +990,7 @@ de: title: Neue Rechnung anlegen show: title: Rechnung %{number} - fc_profit: FC Gewinn + fc_profit: FC Überschuss with_extra_charge: ' mit Aufschlag' without_extra_charge: ' ohne Aufschlag' unpaid: From be6b11d0e53d58aed40736998a96e0ae229beb8d Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:40:50 +0100 Subject: [PATCH 20/44] Update en.yml: profit > surplus "surplus" expresses that revenues exceed costs without implying the commercial or profit-oriented nature associated with the term "profit." --- config/locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 300e6c0e7..e8d2f5df4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -859,7 +859,7 @@ en: changed: Data was changed! duration: From %{starts} till %{ends} fc_amount: 'Sales value:' - fc_profit: FC surplus + fc_profit: FC Surplus gross_amount: 'Gross value:' groups_amount: 'Ordergroups sum:' net_amount: 'Net value:' @@ -990,7 +990,7 @@ en: title: Create new invoice show: title: Invoice %{number} - fc_profit: FC Profit + fc_profit: FC Surplus with_extra_charge: ' with margin' without_extra_charge: ' without margin' unpaid: From b49d21f0a1e2390b6f7e5f63c46a7993c710fbcd Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:42:40 +0100 Subject: [PATCH 21/44] Update en.yml: surplus lower case after FC --- config/locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index e8d2f5df4..f7cfdecaa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -859,7 +859,7 @@ en: changed: Data was changed! duration: From %{starts} till %{ends} fc_amount: 'Sales value:' - fc_profit: FC Surplus + fc_profit: FC surplus gross_amount: 'Gross value:' groups_amount: 'Ordergroups sum:' net_amount: 'Net value:' @@ -990,7 +990,7 @@ en: title: Create new invoice show: title: Invoice %{number} - fc_profit: FC Surplus + fc_profit: FC surplus with_extra_charge: ' with margin' without_extra_charge: ' without margin' unpaid: From f2cc26218c9f065c110d6d6ebc66a3a02c935c12 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:16:27 +0100 Subject: [PATCH 22/44] Update order.rb: sum for stock-order, transport-costs-skip set groups costs to 0 --- app/models/order.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index 73df022a1..5d1cc311b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -230,6 +230,12 @@ def sum(type = :gross) end end end + elsif type == :stock_order + for go in group_orders.includes(group_order_articles: { order_article: [:article, :article_price] }).where(ordergroup: nil) + for goa in go.group_order_articles + total += goa.result * goa.order_article.price.gross_price + end + end elsif type == :transport total = group_orders.where.not(ordergroup: nil).sum(:transport) end @@ -399,6 +405,8 @@ def distribute_transport group_orders.each do |go| go.transport = (amount * go.group_order_articles.sum(:result)).ceil(2) end + when Order.transport_distributions[:skip] + group_orders.each { |go| go.transport = 0 } end end From d5c6ac79fa1d1eff86b5923af6171f646eb17717 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:20:19 +0100 Subject: [PATCH 23/44] Update bootstrap_and_overrides.css.less: added span.positive_green --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 364dd8e25..6b64db724 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -537,6 +537,10 @@ span.positive_amount { color: black; } +span.positive_green { + color: green; +} + span.negative_amout { color: red; } @@ -547,4 +551,4 @@ span.negative_amout { details { cursor: pointer; -} \ No newline at end of file +} From e817345d69791b79a5d1784900931b21ef81661a Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:23:51 +0100 Subject: [PATCH 24/44] Update application_helper.rb: added format_currency_difference() positive values are displayed green with extra +, negative in red --- app/helpers/application_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4cd91e200..2a1845513 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -26,6 +26,11 @@ def format_currency(amount) content_tag :span, number_to_currency(amount), class: class_name end + def format_currency_difference(amount) + class_name = amount < 0 ? 'negative_amout' : 'positive_green' + content_tag :span, (amount > 0 ? '+' : '') + number_to_currency(amount), class: class_name + end + # Splits an IBAN into groups of 4 digits displayed with margins in between def format_iban(iban) iban && iban.scan(/..?.?.?/).map { |item| content_tag(:span, item, style: 'margin-right: 0.5em;') }.join.html_safe From 9040f72fd1629fee312bfc7a3501ed96f09137d0 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:26:14 +0100 Subject: [PATCH 25/44] Update bootstrap_and_overrides.css.less: typo amout > amount --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 6b64db724..0f7e5d989 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -541,7 +541,7 @@ span.positive_green { color: green; } -span.negative_amout { +span.negative_amount { color: red; } From 165dab6e8d4e75977eef788695032228d63fc346 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:27:31 +0100 Subject: [PATCH 26/44] Update application_helper.rb: typo amout > amount --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2a1845513..5937d59de 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,12 +22,12 @@ def format_datetime_timespec(time, format) def format_currency(amount) return nil if amount.nil? - class_name = amount < 0 ? 'negative_amout' : 'positive_amount' + class_name = amount < 0 ? 'negative_amount' : 'positive_amount' content_tag :span, number_to_currency(amount), class: class_name end def format_currency_difference(amount) - class_name = amount < 0 ? 'negative_amout' : 'positive_green' + class_name = amount < 0 ? 'negative_amount' : 'positive_green' content_tag :span, (amount > 0 ? '+' : '') + number_to_currency(amount), class: class_name end From 44d6b2470edf216be37836ecb73fa94d87ae8549 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:34:49 +0100 Subject: [PATCH 27/44] Update show.html.haml: use format_currency_difference() --- app/views/finance/invoices/show.html.haml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index e75d324a9..06352a1aa 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -76,16 +76,12 @@ %dd= number_to_currency(total_fc) %dt= t('.fc_profit') + (total_fc > total ? t('.without_extra_charge') : '') + ':' - - profit = total - @invoice.net_amount %dd - %span{style: "color:#{profit < 0 ? 'red' : 'green'}"} - = number_to_currency(profit) + = format_currency_difference(total - @invoice.net_amount) - if total_fc > total %dt= t('.fc_profit') + ' ' + t('.with_extra_charge') + ':' - - profit = total_fc - @invoice.net_amount %dd - %span{style: "color:#{profit < 0 ? 'red' : 'green'}"} - = number_to_currency(profit) + = format_currency_difference(total_fc - @invoice.net_amount) - if @invoice.attachments.attached? %dt= heading_helper(Invoice, :attachment) + ':' From 268d1bb82e9557895754acc8a449b6904a50d014 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:38:53 +0100 Subject: [PATCH 28/44] Update unpaid.html.haml: use format_currency_difference() --- app/views/finance/invoices/unpaid.html.haml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/views/finance/invoices/unpaid.html.haml b/app/views/finance/invoices/unpaid.html.haml index d9b9e9c6e..ecb1ace38 100644 --- a/app/views/finance/invoices/unpaid.html.haml +++ b/app/views/finance/invoices/unpaid.html.haml @@ -16,13 +16,9 @@ = format_date invoice.date = ' ' + invoice.number = ' ' + number_to_currency(invoice.amount) - %span{style: "color:#{invoice_amount_diff < 0 ? 'red' : 'green'}"} - - # = invoice_amount_diff > 0 ? '+' : '-' - = number_to_currency(invoice_amount_diff) #.abs) + = format_currency_difference(invoice_amount_diff) - if invoice_profit > invoice_amount_diff - = ' / ' - %span{style: "color:#{invoice_profit < 0 ? 'red' : 'green'}"} - = number_to_currency(invoice_profit) + = ' / ' + format_currency_difference(invoice_profit) - if invoice.attachments.attached? - for attachment in invoice.attachments = link_to attachment.filename, url_for(attachment) From ae55dc0ae91c7fa3545366a83f53046e0064baeb Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:52:20 +0100 Subject: [PATCH 29/44] Update _summary.haml: added stock order sum and transport costs, moved invoice balance to invoice summary, show markup relevant amounts only if markup>0 --- app/views/finance/balancing/_summary.haml | 42 +++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index e466727fb..dc94deff3 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -3,28 +3,42 @@ = t('.duration', {starts: format_date(order.starts), ends: format_date(order.ends)}) %p %table + - gross_sum = order.sum(:gross) + - fc_sum = order.sum(:fc) + - stock_order_amount = order.sum(:stock_order) %tr %td= t('.net_amount') %td.numeric= number_to_currency(order.sum(:net)) %tr %td= t('.gross_amount') - %td.numeric= number_to_currency(order.sum(:gross)) - %tr - %td= t('.fc_amount') - %td.numeric= number_to_currency(order.sum(:fc)) + %td.numeric= number_to_currency(gross_sum) + - if fc_sum > gross_sum + %tr + %td= t('.fc_amount') + %td.numeric= number_to_currency(fc_sum) %tr %td= t('.groups_amount') %td.numeric= number_to_currency(order.sum(:groups)) - %tr - %td - = t('.fc_profit') - %small= t('.without_extra_charge') - %td.numeric= number_to_currency(order.profit(:without_markup => true)) - %tr - %td - = t('.fc_profit') - %small= t('.with_extra_charge') - %td#order_profit.numeric= number_to_currency(order.profit) + + - if stock_order_amount > 0 + %tr + %td= t('.stock_order_amount') + %td.numeric= number_to_currency(stock_order_amount) + + - total_transport_costs = order.transport || 0 + - if total_transport_costs > 0 + %tr + %td= t('.total_transport_costs') + %td.numeric= number_to_currency(total_transport_costs) + - group_transport_costs = order.sum(:transport) + - fc_transport_costs = total_transport_costs - group_transport_costs + %tr + %td= t('.group_transport_costs') + %td.numeric= number_to_currency(group_transport_costs) + %tr + %td= t('.fc_transport_costs') + %td.numeric= number_to_currency(fc_transport_costs) + #summaryChangedWarning.alert(style="display:none;") %strong= t '.changed' %br/ From 3adab901cae510896ed9380f2adbca2e92c54a64 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:55:43 +0100 Subject: [PATCH 30/44] Update _invoice.html.haml: buttons for invoice view and edit --- app/views/finance/balancing/_invoice.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/finance/balancing/_invoice.html.haml b/app/views/finance/balancing/_invoice.html.haml index bae9a3478..7edaf3d60 100644 --- a/app/views/finance/balancing/_invoice.html.haml +++ b/app/views/finance/balancing/_invoice.html.haml @@ -19,7 +19,8 @@ %td= t('.refund_adjusted_amount') %td.curreny= number_to_currency invoice.net_amount %br/ - = link_to t('.edit'), edit_finance_invoice_path(invoice) + = link_to t('.view'), finance_invoice_path(invoice), class: 'btn' + = link_to t('.edit'), edit_finance_invoice_path(invoice), class: 'btn' - else = t '.new_body' From dbb14f2eee06b714dbb6fc58440428762d7cc2f2 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:00:43 +0100 Subject: [PATCH 31/44] Update _invoice.html.haml: show numbers of invoices and deliveries, show profit --- .../finance/balancing/_invoice.html.haml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/views/finance/balancing/_invoice.html.haml b/app/views/finance/balancing/_invoice.html.haml index 7edaf3d60..c0e990505 100644 --- a/app/views/finance/balancing/_invoice.html.haml +++ b/app/views/finance/balancing/_invoice.html.haml @@ -18,6 +18,35 @@ %tr %td= t('.refund_adjusted_amount') %td.curreny= number_to_currency invoice.net_amount + + - n_orders = invoice.orders.count + - n_deliveries = invoice.deliveries.count + - if n_orders > 1 + %tr + %td= t('.orders') + %td.numeric= n_orders.to_s + - if n_deliveries > 0 + %tr + %td= t('.deliveries') + %td.numeric= n_deliveries.to_s + + - profit_without_markup = invoice.profit(:without_markup) + - profit_with_markup = invoice.profit(:with_markup) + %tr + %td + = t('.fc_profit') + - if profit_with_markup > profit_without_markup + %small= t('.without_extra_charge') + - else + = ':' + %td.numeric= format_currency_difference(profit_without_markup) + - if profit_with_markup > profit_without_markup + %tr + %td + = t('.fc_profit') + %small= t('.with_extra_charge') + %td#order_profit.numeric= format_currency_difference(profit_with_markup) + %br/ = link_to t('.view'), finance_invoice_path(invoice), class: 'btn' = link_to t('.edit'), edit_finance_invoice_path(invoice), class: 'btn' From 00f331791a837543fb96d6760e971ab7f9c79b60 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:06:59 +0100 Subject: [PATCH 32/44] Update de.yml: finance balancing summary, invoice --- config/locales/de.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 6a74340cd..627a6db4a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -820,6 +820,7 @@ de: title: Beendete Bestellungen invoice: edit: Rechnung bearbeiten + view: Rechnung ansehen invoice_amount: 'Rechnungsbetrag:' invoice_date: 'Rechnungsdatum:' invoice_number: 'Rechnungsnummer:' @@ -828,6 +829,11 @@ de: new_body: 'Eine Rechnung für diese Bestellung anlegen:' plus_refund_credited: "+ Pfand gutgeschrieben:" refund_adjusted_amount: 'pfandbereinigter Betrag:' + fc_profit: 'FC Überschuss' + with_extra_charge: 'mit Aufschlag:' + without_extra_charge: 'ohne Aufschlag:' + orders: 'Anzahl Bestellungen:' + deliveries: 'Anzahl Lager-Lieferungen:' new: alert: Achtung, Bestellung wurde schon abgerechnet articles_overview: Artikelübersicht @@ -859,13 +865,16 @@ de: changed: Daten wurden verändert! duration: von %{starts} bis %{ends} fc_amount: 'FC-Betrag:' - fc_profit: FC Überschuss gross_amount: 'Bruttobetrag:' groups_amount: 'Gruppenbeträge:' + stock_order_amount: 'Lager-Bestellung:' net_amount: 'Nettobetrag:' reload: Zusammenfassung neu laden with_extra_charge: 'mit Aufschlag:' without_extra_charge: 'ohne Aufschlag:' + total_transport_costs: 'Transportkosten gesamt:' + group_transport_costs: 'Transportkosten Gruppen:' + fc_transport_costs: 'Transportkosten FC:' bank_accounts: assign_unlinked_transactions: notice: 'Es wurden %{count} Transaktionen zugeordnet.' From 13c06e19aa8e7343d2298c2248b10389ddcb2433 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:17:43 +0100 Subject: [PATCH 33/44] Update en.yml: finance balancing summary, invoice --- config/locales/en.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index f7cfdecaa..19f5f7c28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -820,6 +820,7 @@ en: title: Closed orders invoice: edit: Edit invoice + view: View invoice invoice_amount: 'Invoice amount:' invoice_date: 'Invoice date:' invoice_number: 'Invoice number:' @@ -828,6 +829,11 @@ en: new_body: 'Create an invoice for this order:' plus_refund_credited: "+ deposit returned:" refund_adjusted_amount: 'amount adjusted for refund:' + fc_profit: 'FC surplus' + with_extra_charge: 'with extra charge:' + without_extra_charge: 'without extra charge:' + orders: 'Number of orders:' + deliveries: 'Number of stock delivieries:' new: alert: Attention, order was already accounted articles_overview: Overview of articles @@ -859,13 +865,16 @@ en: changed: Data was changed! duration: From %{starts} till %{ends} fc_amount: 'Sales value:' - fc_profit: FC surplus gross_amount: 'Gross value:' groups_amount: 'Ordergroups sum:' + stock_order_amount: 'Stock order:' net_amount: 'Net value:' reload: Reload summary with_extra_charge: 'with extra charge:' without_extra_charge: 'without extra charge:' + total_transport_costs: 'Transport costs total:' + group_transport_costs: 'Transport costs groups:' + fc_transport_costs: 'Transport costs FC:' bank_accounts: assign_unlinked_transactions: notice: '%{count} transactions have been assigned' From 41c68666eb726203089c4c7aa56314ae3c0a9b14 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:41:07 +0100 Subject: [PATCH 34/44] Update application_helper.rb whitespace removed --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5937d59de..6f21fbbdb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,7 +27,7 @@ def format_currency(amount) end def format_currency_difference(amount) - class_name = amount < 0 ? 'negative_amount' : 'positive_green' + class_name = amount < 0 ? 'negative_amount' : 'positive_green' content_tag :span, (amount > 0 ? '+' : '') + number_to_currency(amount), class: class_name end From 67068134b15539a127b6505d5350a1204afde54e Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:57:05 +0100 Subject: [PATCH 35/44] Update .rubocop_todo.yml: increased Metrics/ModuleLength to 200 --- .rubocop_todo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 894d0e0b5..9a756c0c4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -223,7 +223,7 @@ Metrics/MethodLength: # Offense count: 4 # Configuration parameters: CountComments, CountAsOne. Metrics/ModuleLength: - Max: 192 + Max: 200 # Offense count: 1 # Configuration parameters: CountKeywordArgs, MaxOptionalParameters. From cb00c9e31dcdbeb0a739e058b864e6b921cea074 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:10:07 +0100 Subject: [PATCH 36/44] Update order.rb: whitespace removed, %i for string array --- app/models/order.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 5d1cc311b..dbfeca7d8 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -231,11 +231,11 @@ def sum(type = :gross) end end elsif type == :stock_order - for go in group_orders.includes(group_order_articles: { order_article: [:article, :article_price] }).where(ordergroup: nil) + for go in group_orders.includes(group_order_articles: { order_article: %i[article article_price] }).where(ordergroup: nil) for goa in go.group_order_articles total += goa.result * goa.order_article.price.gross_price end - end + end elsif type == :transport total = group_orders.where.not(ordergroup: nil).sum(:transport) end From ae7c4970c3735bf2adf18d22d04af5334acc12f2 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:24:44 +0100 Subject: [PATCH 37/44] Update unpaid.html.haml: invoice_profit formatting corrected --- app/views/finance/invoices/unpaid.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/finance/invoices/unpaid.html.haml b/app/views/finance/invoices/unpaid.html.haml index ecb1ace38..502b868fd 100644 --- a/app/views/finance/invoices/unpaid.html.haml +++ b/app/views/finance/invoices/unpaid.html.haml @@ -18,7 +18,8 @@ = ' ' + number_to_currency(invoice.amount) = format_currency_difference(invoice_amount_diff) - if invoice_profit > invoice_amount_diff - = ' / ' + format_currency_difference(invoice_profit) + = ' / ' + = format_currency_difference(invoice_profit) - if invoice.attachments.attached? - for attachment in invoice.attachments = link_to attachment.filename, url_for(attachment) From 2d711f4898951e9456f05c7971624e96204439bd Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:43:23 +0100 Subject: [PATCH 38/44] Update .rubocop_todo.yml: Metrics/ClassLength increased --- .rubocop_todo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a756c0c4..468e7de2f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -208,7 +208,7 @@ Metrics/BlockNesting: # Offense count: 18 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 304 + Max: 350 # Offense count: 51 # Configuration parameters: AllowedMethods, AllowedPatterns. From 45d22156a6d4bd60b6ec28aab0b16aae1f9ce150 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:11:17 +0100 Subject: [PATCH 39/44] Update invoice.rb: missing profit() method added --- app/models/invoice.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 8418ec576..e1c929b0d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -54,6 +54,10 @@ def expected_amount(type = :without_markup) orders_sum(type) + orders_transport_sum + deliveries_sum(type) end + def profit(type = :without_markup) + expected_amount(type) - net_amount + end + protected # validates that the attachments are jpeg, png or pdf From 4d5bc5650d89ce203138d3bcaa47d4d6b0377dab Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:24:17 +0100 Subject: [PATCH 40/44] Update order.rb: profit per order --- app/models/order.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index dbfeca7d8..c5690d529 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -189,15 +189,19 @@ def articles_sort_by_category end end - # Returns the defecit/benefit for the foodcoop + # Returns the defecit/benefit for the foodcoop per order # Requires a valid invoice, belonging to this order # FIXME: Consider order.foodcoop_result - def profit(options = {}) - markup = options[:without_markup] || false - return unless invoice - - groups_sum = markup ? sum(:groups_without_markup) : sum(:groups) - groups_sum - invoice.net_amount + def profit(type = :with_markup) + if invoice + invoice.profit(type) / invoice.orders.count + else + if type == :without_markup + sum(:groups_without_markup) + else + sum(:groups) + end + end end # Returns the all round price of a finished order From 6ec8fee55c10b3aec5e2893812783b05301223b3 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:40:49 +0100 Subject: [PATCH 41/44] Update order.rb: else/if resolved --- app/models/order.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index c5690d529..3b09e5a9a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -196,11 +196,7 @@ def profit(type = :with_markup) if invoice invoice.profit(type) / invoice.orders.count else - if type == :without_markup - sum(:groups_without_markup) - else - sum(:groups) - end + type == :without_markup ? sum(:groups_without_markup) : sum(:groups) end end From ef8dce09c50f1579ba3009aa89cafe32d248d116 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:55:44 +0100 Subject: [PATCH 42/44] Update _summary.haml: display order_surplus --- app/views/finance/balancing/_summary.haml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index dc94deff3..c2dd104d6 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -39,6 +39,10 @@ %td= t('.fc_transport_costs') %td.numeric= number_to_currency(fc_transport_costs) + %tr + %td= t('.order_surplus') + %td.numeric= format_currency_difference(order.profit(:without_markup)) + #summaryChangedWarning.alert(style="display:none;") %strong= t '.changed' %br/ From 655a6f80bcae4c2ec300d995962d63e0db89c37c Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:01:57 +0100 Subject: [PATCH 43/44] Update de.yml: added order_surplus --- config/locales/de.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index 627a6db4a..ecc07d048 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -875,6 +875,7 @@ de: total_transport_costs: 'Transportkosten gesamt:' group_transport_costs: 'Transportkosten Gruppen:' fc_transport_costs: 'Transportkosten FC:' + order_surplus: 'FC Überschuss Bestellung:' bank_accounts: assign_unlinked_transactions: notice: 'Es wurden %{count} Transaktionen zugeordnet.' From 0121d800b51f4dba2b163c8e8e28dc90f66c976c Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:03:43 +0100 Subject: [PATCH 44/44] Update en.yml: added order_surplus --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 19f5f7c28..ea29bf40a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -875,6 +875,7 @@ en: total_transport_costs: 'Transport costs total:' group_transport_costs: 'Transport costs groups:' fc_transport_costs: 'Transport costs FC:' + order_surplus: 'FC order surplus:' bank_accounts: assign_unlinked_transactions: notice: '%{count} transactions have been assigned'