X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fvk.pl;h=a6476d9f1ec8d6270c0a6ab37c7c49156f06a830;hb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44;hp=148fec02d023872d1ba5065073fdf8117f7c9f5c;hpb=4486e3bc8eb00c37cf8029e663eb94b4b9c5346a;p=kivitendo-erp.git diff --git a/bin/mozilla/vk.pl b/bin/mozilla/vk.pl index 148fec02d..a6476d9f1 100644 --- a/bin/mozilla/vk.pl +++ b/bin/mozilla/vk.pl @@ -61,7 +61,6 @@ sub search_invoice { $form->all_vc(\%myconfig, "customer", "AR"); $form->{title} = $locale->text('Sales Report'); - $form->{jsscript} = 1; $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, "departments" => "ALL_DEPARTMENTS", @@ -105,26 +104,19 @@ sub invoice_transactions { # can't currently be configured from report, empty line between main sortings my $addemptylines = 1; + # don't add empty lines between mainsort subtotals when only subtotal_mainsort is selected + if ($form->{l_subtotal_mainsort} eq "Y" and not defined $form->{l_headers_mainsort} and not defined $form->{l_headers_subsort} and not defined $form->{l_subtotal_subsort} ) { + $addemptylines = 0 + }; + if ( $form->{customer} =~ /--/ ) { # Felddaten kommen aus Dropdownbox - ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer}); - } elsif ($form->{customer}) { - # es wurde ein Wert im Freitextfeld übergeben, auf Eindeutigkeit überprüfen - - # check_name wird mit no_select => 1 ausgeführt, ist die Abfrage nicht eindeutig kommt ein Fehler - # und die Abfrage muß erneut ausgeführt werden - - # Ohne no_select kommt bei Auswahl des Kunden ein Aufruf von update der ins - # Nichts führt, daher diese Zwischenlösung - - &check_name('customer', no_select => 1); - - # $form->{customer_id} wurde schon von check_name gesetzt - $form->{customername} = $form->{customer}; - }; - # ist $form->{customer} leer passiert hier nichts weiter + my $dummy; + ($dummy, $form->{customer_id}) = split(/--/, $form->{customer}); + } + # if $form->{customer} is empty nothing further happens here - # decimalplaces überprüfen oder auf Default 2 setzen + # test for decimalplaces or set to default of 2 $form->{decimalplaces} = 2 unless $form->{decimalplaces} > 0 && $form->{decimalplaces} < 6; my $cvar_configs_ct = CVar->get_configs('module' => 'CT'); @@ -159,16 +151,16 @@ sub invoice_transactions { push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables; - # hidden variables für pdf/csv export übergeben - # einmal mit l_ um zu bestimmen welche Spalten ausgegeben werden sollen - # einmal optionen für die Überschrift (z.B. transdatefrom, partnumber, ...) - my @hidden_variables = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customername customer_id department partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort), + # pass hidden variables for pdf/csv export + # first with l_ to determine which columns to show + # then with the options for headings (such as transdatefrom, partnumber, ...) + my @hidden_variables = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customer_id department partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort), "$form->{db}number", map({ "cvar_$_->{name}" } @searchable_custom_variables), map { "l_$_" } @columns ); my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables); - # Variablen werden dann als Hidden Variable mitgegeben, z.B. + # variables are passed as hiddens, e.g. # $href = build_std_url('action=invoice_transactions', grep { $form->{$_} } @hidden_variables); @@ -216,9 +208,9 @@ sub invoice_transactions { my @options; push @options, $locale->text('Description') . " : $form->{description}" if $form->{description}; - push @options, $locale->text('Customer') . " : $form->{customername}" if $form->{customer}; + push @options, $locale->text('Customer') . " : $form->{customer}" if $form->{customer}; push @options, $locale->text('Customer Number') . " : $form->{customernumber}" if $form->{customernumber}; - # TODO: es wird nur id übergeben + # TODO: only customer id is passed push @options, $locale->text('Department') . " : " . (split /--/, $form->{department})[0] if $form->{department}; push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if $form->{invnumber}; push @options, $locale->text('Invoice Date') . " : $form->{invdate}" if $form->{invdate}; @@ -281,9 +273,9 @@ sub invoice_transactions { $callback = $form->escape($href); my @subtotal_columns = qw(qty weight sellprice sellprice_total lastcost lastcost_total marge_total marge_percent discount); - # Gesamtsumme: - # Summe von sellprice_total, lastcost_total und marge_total - # Durchschnitt von marge_percent + # Total sum: + # sum of sellprice_total, lastcost_total and marge_total + # average of marge_percent my @total_columns = qw(sellprice_total lastcost_total marge_total marge_percent ); my %totals = map { $_ => 0 } @total_columns; @@ -300,26 +292,56 @@ sub invoice_transactions { $basefactor = 1 unless $basefactor; $ar->{price_factor} = 1 unless $ar->{price_factor}; - # calculate individual sellprice - # discount was already accounted for in db sellprice + + # calculate individual sellprice, discount is already accounted for in column sellprice in db + + # The sellprice total can be calculated from sellprice or fxsellprice (the + # value that was actually entered in the sellprice field and is always + # stored seperately). However, for fxsellprice this method only works when + # the tax is not included, because otherwise fxsellprice includes the tax + # and there is no simple way to extract the tax rate of the article from + # the big query. + # + # Using fxsellprice is potentially more accurate (certainly for tax + # included), because we can use the same method as is used while the + # invoice is generated. + # + # sellprice however has already been converted to the net value (but + # rounded in the process, which leads to rounding errors when calculating + # the linetotal from the rounded sellprice in the report. These rounding + # errors can quickly amount to several cents when qty is large) + # + # For calculating sellprice_total from fxsellprice, you would use: + # sellprice_total_including_tax = qty * fxsellprice * (1-discount) / price_factor * exchangerate + # $ar->{sellprice_total_including_tax} = $form->round_amount( $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}, $form->{"decimalplaces"}); + + my $sellprice_orig = $ar->{sellprice}; + my $qty_orig = $ar->{qty}; + # adjust sellprice so it reflects the unit sellprice according to price_factor and basefactor $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor; + # for sellprice_total use the original amounts + $ar->{sellprice_total} = $form->round_amount( $qty_orig * $sellprice_orig / $ar->{price_factor}, $form->{"decimalplaces"}); + + my $lastcost_orig = $ar->{lastcost}; $ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor} / $basefactor; - $ar->{sellprice_total} = $form->round_amount( $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}, 2); - $ar->{lastcost_total} = $form->round_amount( $ar->{qty} * $ar->{lastcost} * $basefactor, 2); - # marge_percent wird neu berechnet, da Wert in invoice leer ist (Bug) + $ar->{lastcost_total} = $form->round_amount( $qty_orig * $lastcost_orig / $ar->{price_factor}, $form->{"decimalplaces"}); + + # marge_percent is recalculated, because the value in invoice used to be empty $ar->{marge_percent} = $ar->{sellprice_total} ? (($ar->{sellprice_total}-$ar->{lastcost_total}) / $ar->{sellprice_total} * 100) : 0; - # marge_total neu berechnen + # also recalculate marge_total $ar->{marge_total} = $ar->{sellprice_total} ? $ar->{sellprice_total}-$ar->{lastcost_total} : 0; - $ar->{discount} *= 100; # für Ausgabe formatieren, 10% stored as 0.1 in db + $ar->{discount} *= 100; # format discount value for output, 10% is stored as 0.1 in db - #adapt qty to the chosen unit + # adjust qty to reflect the qty of the base unit $ar->{qty} *= $basefactor; - #weight is the still the weight per part, but here we want the total weight + # now $ar->{sellprice} * $ar->{qty} should be the same as $qty_orig * $ar->{qty} + + # weight is the still the weight per part, but here we want the total weight $ar->{weight} *= $ar->{qty}; - # Anfangshauptüberschrift - if ( $form->{l_headers_mainsort} eq "Y" && ( $idx == 0 or $ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'mainsort'} } )) { + # Main header + if ( $form->{l_headers_mainsort} eq "Y" && ( $idx == 1 or $ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'mainsort'} } )) { my $headerrow = { # use $emptyname for mainsort header if mainsort is empty data => $ar->{$form->{'mainsort'}} || $locale->text('empty'), @@ -335,7 +357,7 @@ sub invoice_transactions { # $report->add_data($emptyheaderrow_set) if $form->{l_headers} eq "Y"; }; - # subsort überschriften + # subsort headers # special case: subsort headers only makes (aesthetical) sense if we show individual parts if (( $idx == 0 or $ar->{ $form->{'subsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'subsort'} } @@ -381,20 +403,21 @@ sub invoice_transactions { $subtotals2{lastcost} = 0; }; - # Ertrag prozentual in den Summen: (summe VK - summe Ertrag) / summe VK + # marge percent as sums: (sum VK - sum Ertrag) / sum VK $subtotals1{marge_percent} = $subtotals1{sellprice_total} ? (($subtotals1{sellprice_total} - $subtotals1{lastcost_total}) / $subtotals1{sellprice_total}) * 100 : 0; $subtotals2{marge_percent} = $subtotals2{sellprice_total} ? (($subtotals2{sellprice_total} - $subtotals2{lastcost_total}) / $subtotals2{sellprice_total}) *100 : 0; - # Ertrag prozentual: (Summe VK betrag - Summe EK betrag) / Summe VK betrag - # wird laufend bei jeder Position neu berechnet + # total marge percent: (sum VK betrag - sum EK betrag) / sum VK betrag + # is recalculated after each position $totals{marge_percent} = $totals{sellprice_total} ? ( ($totals{sellprice_total} - $totals{lastcost_total}) / $totals{sellprice_total} ) * 100 : 0; - map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(marge_total marge_percent qty sellprice_total lastcost_total); + map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(marge_percent qty); map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 3) } qw(weight); - map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, $form->{"decimalplaces"} )} qw(lastcost sellprice); + map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, $form->{"decimalplaces"} )} qw(lastcost sellprice sellprice_total lastcost_total marge_total); + + # only show individual lines when l_parts is set, this is useful, if you + # only want to see subtotals and totals - # Einzelzeilen nur zeigen wenn l_parts gesetzt ist, nützlich, wenn man nur - # Subtotals und Totals sehen möchte if ($form->{l_parts}) { my %row = ( map { ($_ => { data => $ar->{$_}, align => $column_alignment{$_} }) } @columns @@ -402,11 +425,14 @@ sub invoice_transactions { $row{invnumber}->{link} = build_std_url("script=is.pl", 'action=edit') . "&id=" . E($ar->{id}) . "&callback=${callback}"; + # use partdescription according to invoice in article mode + $row{description}->{data} = $ar->{invoice_description}; + $report->add_data(\%row); } - # hier wird bei l_subtotal nicht differenziert zwischen mainsort und subsort - # macht man l_subtotal_mainsort aus wird l_subtotal_subsort auch nicht ausgeführt + # choosing l_subtotal doesn't make a distinction between mainsort and subsort + # if l_subtotal_mainsort is not selected l_subtotal_subsort isn't run either if ( ($form->{l_subtotal_mainsort} eq 'Y') && ($form->{l_subtotal_subsort} eq 'Y') && (($idx == (scalar @{ $form->{AR} } - 1)) # last element always has a subtotal @@ -425,7 +451,7 @@ sub invoice_transactions { && (($idx == (scalar @{ $form->{AR} } - 1)) # last element always has a subtotal || ($ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx + 1]->{ $form->{'mainsort'} }) )) { # if value that is sorted by changes, print subtotal - # subtotal is overriden if mainsort and subsort are equal, don't print + # subtotal is overridden if mainsort and subsort are equal, don't print # subtotal line even if it is selected $report->add_data(create_subtotal_row_invoice(\%subtotals1, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal', $ar->{$form->{mainsort}})); $report->add_data({ %empty_row }) if $addemptylines; # insert empty row after mainsort