From add49a32e648b08f1ff93096c9750a1d8c6f9657 Mon Sep 17 00:00:00 2001 From: Niclas Zimmermann Date: Tue, 14 Aug 2012 16:53:20 +0200 Subject: [PATCH] =?utf8?q?Verkaufsbericht=20Einheiten=20und=20Preisfaktore?= =?utf8?q?n=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Im Verkaufsbericht werden jetzt auch Einheiten und Preisfaktoren berücksichtigt. Vorher kam es zu Fehlern, wenn man Rechnungen mit von den Basisangaben abweichenden Einheiten oder Preisfaktoren erstellt hat. Weiterhin werden in dem Bericht nur noch absolute Mengen in Verbindung mit der Basiseinheit angezeigt (nicht mehr die Einheit aus dem Beleg; zur Berechnung von Durchschnitten). --- SL/VK.pm | 2 +- bin/mozilla/vk.pl | 22 ++++++++++++++++------ templates/webpages/vk/search_invoice.html | 16 ++++++++-------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/SL/VK.pm b/SL/VK.pm index 55c46f234..f2df17b33 100644 --- a/SL/VK.pm +++ b/SL/VK.pm @@ -51,7 +51,7 @@ sub invoice_transactions { my @values; my $query = - qq|SELECT ct.id as customerid, ct.name as customername,ct.customernumber,ct.country,ar.invnumber,ar.id,ar.transdate,p.partnumber,pg.partsgroup,i.parts_id,i.qty,i.price_factor,i.discount,i.description as description,i.lastcost,i.sellprice,i.fxsellprice,i.marge_total,i.marge_percent,i.unit,b.description as business,e.name as employee,e2.name as salesman, to_char(ar.transdate,'Month') as month, to_char(ar.transdate, 'YYYYMM') as nummonth | . + qq|SELECT ct.id as customerid, ct.name as customername,ct.customernumber,ct.country,ar.invnumber,ar.id,ar.transdate,p.partnumber,pg.partsgroup,i.parts_id,i.qty,i.price_factor,i.discount,i.description as description,i.lastcost,i.sellprice,i.fxsellprice,i.marge_total,i.marge_percent,i.unit,b.description as business,e.name as employee,e2.name as salesman, to_char(ar.transdate,'Month') as month, to_char(ar.transdate, 'YYYYMM') as nummonth, p.unit as parts_unit | . qq|FROM invoice i | . qq|JOIN ar on (i.trans_id = ar.id) | . qq|JOIN parts p on (i.parts_id = p.id) | . diff --git a/bin/mozilla/vk.pl b/bin/mozilla/vk.pl index 9e9116e42..097b637e7 100644 --- a/bin/mozilla/vk.pl +++ b/bin/mozilla/vk.pl @@ -34,6 +34,7 @@ use POSIX qw(strftime); use List::Util qw(sum first); +use SL::AM; use SL::VK; use SL::IS; use SL::ReportGenerator; @@ -149,7 +150,7 @@ sub invoice_transactions { $form->{title} = $locale->text('Sales Report'); @columns = - qw(description invnumber transdate customernumber customername partnumber partsgroup country business transdate qty unit sellprice sellprice_total discount lastcost lastcost_total marge_total marge_percent employee salesman); + qw(description invnumber transdate customernumber customername partnumber partsgroup country business transdate qty parts_unit sellprice sellprice_total discount lastcost lastcost_total marge_total marge_percent employee salesman); my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs_ic }, @{ $cvar_configs_ct }; my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs_ic }, @{ $cvar_configs_ct }; @@ -184,7 +185,7 @@ sub invoice_transactions { 'invnumber' => { 'text' => $locale->text('Invoice Number'), }, 'transdate' => { 'text' => $locale->text('Invoice Date'), }, 'qty' => { 'text' => $locale->text('Quantity'), }, - 'unit' => { 'text' => $locale->text('Unit'), }, + 'parts_unit' => { 'text' => $locale->text('Base unit'), }, 'sellprice' => { 'text' => $locale->text('Sales price'), }, 'sellprice_total' => { 'text' => $locale->text('Sales net amount'), }, 'lastcost_total' => { 'text' => $locale->text('Purchase net amount'), }, @@ -203,7 +204,7 @@ sub invoice_transactions { map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns; - my %column_alignment = map { $_ => 'right' } qw(lastcost sellprice sellprice_total lastcost_total unit discount marge_total marge_percent qty); + my %column_alignment = map { $_ => 'right' } qw(lastcost sellprice sellprice_total lastcost_total parts_unit discount marge_total marge_percent qty); # so now the check-box "Description" is only used as switch for part description in invoice-mode @@ -322,15 +323,20 @@ sub invoice_transactions { my $idx = 0; + my $basefactor; + my $all_units = AM->retrieve_all_units(); + foreach my $ar (@{ $form->{AR} }) { + $basefactor = $all_units->{$ar->{unit}}->{factor} / $all_units->{$ar->{parts_unit}}->{factor}; + $basefactor = 1 unless $basefactor; $ar->{price_factor} = 1 unless $ar->{price_factor}; # calculate individual sellprice # discount was already accounted for in db sellprice - $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor}; + $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor; $ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor}; - $ar->{sellprice_total} = $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) ; - $ar->{lastcost_total} = $ar->{qty} * $ar->{lastcost}; + $ar->{sellprice_total} = $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}; + $ar->{lastcost_total} = $ar->{qty} * $ar->{lastcost} * $basefactor; # marge_percent wird neu berechnet, da Wert in invoice leer ist (Bug) $ar->{marge_percent} = $ar->{sellprice_total} ? (($ar->{sellprice_total}-$ar->{lastcost_total}) / $ar->{sellprice_total} * 100) : 0; # marge_total neu berechnen @@ -415,6 +421,10 @@ sub invoice_transactions { # wird laufend bei jeder Position neu berechnet $totals{marge_percent} = $totals{sellprice_total} ? ( ($totals{sellprice_total} - $totals{lastcost_total}) / $totals{sellprice_total} ) * 100 : 0; + #passt die qty an die gewählte Einheit an + #qty wurde bisher noch für andere Berechnungen benötigt und daher erst am Schluss überschrieben + $ar->{qty} *= $basefactor; + map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(marge_total marge_percent); map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, $form->{"decimalplaces"} )} qw(lastcost sellprice sellprice_total lastcost_total); diff --git a/templates/webpages/vk/search_invoice.html b/templates/webpages/vk/search_invoice.html index 77f1d38b6..25ec860ce 100644 --- a/templates/webpages/vk/search_invoice.html +++ b/templates/webpages/vk/search_invoice.html @@ -29,8 +29,8 @@ - [% 'Heading' | $T8 %] - [% 'Subtotal' | $T8 %] + [% 'Heading' | $T8 %] + [% 'Subtotal' | $T8 %] [% 'Secondary sorting' | $T8 %] @@ -50,13 +50,13 @@ [% 'Item mode' | $T8 %] - ([%'Show items from invoices individually' | $T8 %]) + ([%'Show items from invoices individually' | $T8 %]) [% 'Total sum' | $T8 %] - + [% 'Decimalplaces' | $T8 %]: @@ -237,8 +237,8 @@ ([% 'averaged values, in invoice mode only useful when filtered by a part' | $T8 %]) - [% 'Quantity' | $T8 %] - [% 'Discount' | $T8 %] + [% 'Quantity' | $T8 %] + [% 'Discount' | $T8 %] ([% 'averaged values, in invoice mode only useful when filtered by a part' | $T8 %]) @@ -250,10 +250,10 @@ [% 'Description' | $T8 %] [% 'Part Number' | $T8 %] [% 'Invnumber' | $T8 %] - [% 'Invdate' | $T8 %] + [% 'Invdate' | $T8 %] - [% 'Unit' | $T8 %] + [% 'Base unit' | $T8 %] [% 'Group' | $T8 %] [% 'Salesperson' | $T8 %] [% 'Employee' | $T8 %] -- 2.20.1