Verkaufsbericht: genauere Berechnung von sellprice_total (2. Mal)
[kivitendo-erp.git] / bin / mozilla / vk.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # Sales report
31 #
32 #======================================================================
33
34 use POSIX qw(strftime);
35 use List::Util qw(sum first);
36
37 use SL::VK;
38 use SL::IS;
39 use SL::ReportGenerator;
40 use Data::Dumper;
41
42 require "bin/mozilla/arap.pl";
43 require "bin/mozilla/common.pl";
44 require "bin/mozilla/drafts.pl";
45 require "bin/mozilla/reportgenerator.pl";
46
47 use strict;
48
49 sub search_invoice {
50   $main::lxdebug->enter_sub();
51   $main::auth->assert('general_ledger | invoice_edit');
52
53   my $form     = $main::form;
54   my %myconfig = %main::myconfig;
55   my $locale   = $main::locale;
56
57   my ($customer, $department);
58
59   # setup customer selection
60   $form->all_vc(\%myconfig, "customer", "AR");
61
62   $form->{title}    = $locale->text('Sales Report');
63   $form->{jsscript} = 1;
64
65   $form->get_lists("projects"        => { "key" => "ALL_PROJECTS", "all" => 1 },
66                    "departments"     => "ALL_DEPARTMENTS",
67                    "business_types"  => "ALL_BUSINESS_TYPES",
68                    "salesmen"        => "ALL_SALESMEN",
69                    'employees'       => 'ALL_EMPLOYEES',
70                    'partsgroup'      => 'ALL_PARTSGROUPS',
71                    "customers"       => "ALL_VC");
72   $form->{CUSTOM_VARIABLES_IC}                  = CVar->get_configs('module' => 'IC');
73   ($form->{CUSTOM_VARIABLES_FILTER_CODE_IC},
74    $form->{CUSTOM_VARIABLES_INCLUSION_CODE_IC}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES_IC},
75                                                                            'include_prefix' => 'l_',
76                                                                            'include_value'  => 'Y');
77
78   $form->{CUSTOM_VARIABLES_CT}                  = CVar->get_configs('module' => 'CT');
79   ($form->{CUSTOM_VARIABLES_FILTER_CODE_CT},
80    $form->{CUSTOM_VARIABLES_INCLUSION_CODE_CT}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES_CT},
81                                                                            'include_prefix' => 'l_',
82                                                                            'include_value'  => 'Y');
83   $form->{vc_keys}   = sub { "$_[0]->{name}--$_[0]->{id}" };
84   $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} };
85   $form->{salesman_labels} = $form->{employee_labels};
86
87   $form->header;
88   print $form->parse_html_template('vk/search_invoice', { %myconfig });
89
90   $main::lxdebug->leave_sub();
91 }
92
93 sub invoice_transactions {
94   $main::lxdebug->enter_sub();
95
96   $main::auth->assert('general_ledger | invoice_edit');
97
98   my $form     = $main::form;
99   my %myconfig = %main::myconfig;
100   my $locale   = $main::locale;
101
102   my ($callback, $href, @columns);
103
104   # can't currently be configured from report, empty line between main sortings
105   my $addemptylines = '1';
106
107   if ( $form->{customer} =~ /--/ ) {
108     # Felddaten kommen aus Dropdownbox
109     ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer});
110   } elsif ($form->{customer}) {
111     # es wurde ein Wert im Freitextfeld übergeben, auf Eindeutigkeit überprüfen
112
113     # check_name wird mit no_select => 1 ausgeführt, ist die Abfrage nicht eindeutig kommt ein Fehler
114     # und die Abfrage muß erneut ausgeführt werden
115
116     # Ohne no_select kommt bei Auswahl des Kunden ein Aufruf von update der ins
117     # Nichts führt, daher diese Zwischenlösung
118
119     &check_name('customer', no_select => 1);
120
121     # $form->{customer_id} wurde schon von check_name gesetzt
122     $form->{customername} = $form->{customer};
123   };
124   # ist $form->{customer} leer passiert hier nichts weiter
125
126   # decimalplaces überprüfen oder auf Default 2 setzen
127   $form->{decimalplaces} = 2 unless $form->{decimalplaces} > 0 && $form->{decimalplaces} < 6;
128
129   my $cvar_configs_ct = CVar->get_configs('module' => 'CT');
130   my $cvar_configs_ic = CVar->get_configs('module' => 'IC');
131
132 #  report_generator_set_default_sort('transdate', 1);
133
134   VK->invoice_transactions(\%myconfig, \%$form);
135
136   
137   if ( $form->{mainsort} eq 'month' or $form->{subsort} eq 'month' ) {
138
139     # Data already comes out of SELECT statement in correct month order, but
140     # remove whitespaces (month names are padded) and translate them as early
141     # as possible
142
143     foreach (@{ $form->{AR} }) {
144       $_->{month} =~ s/\s//g;
145       $_->{month} = $locale->text($_->{month});
146     };
147   };
148
149   $form->{title} = $locale->text('Sales Report');
150
151   @columns =
152     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);
153
154   my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs_ic }, @{ $cvar_configs_ct };
155   my @searchable_custom_variables  = grep { $_->{searchable} }  @{ $cvar_configs_ic }, @{ $cvar_configs_ct };
156   my %column_defs_cvars            = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
157
158   push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
159
160
161   # hidden variables für pdf/csv export übergeben
162   # einmal mit l_ um zu bestimmen welche Spalten ausgegeben werden sollen
163   # einmal optionen für die Überschrift (z.B. transdatefrom, partnumber, ...)
164   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), 
165       "$form->{db}number", 
166       map({ "cvar_$_->{name}" } @searchable_custom_variables),
167       map { "l_$_" } @columns
168       );
169   my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
170   # Variablen werden dann als Hidden Variable mitgegeben, z.B.
171   # <input type="hidden" name="report_generator_hidden_transdateto" value="21.05.2010">
172
173   $href = build_std_url('action=invoice_transactions', grep { $form->{$_} } @hidden_variables);
174   # href = vk.pl?action=invoice_transactions&l_headers=Y&l_subtotal=Y&l_total=Y&transdatefrom=04.03.2010 ...
175
176   my %column_defs = (
177     'description'             => { 'text' => $locale->text('Description'), },
178     'partnumber'              => { 'text' => $locale->text('Part Number'), },
179     'partsgroup'              => { 'text' => $locale->text('Group'), },
180     'country'                 => { 'text' => $locale->text('Country'), },
181     'business'                => { 'text' => $locale->text('Customer type'), },
182     'employee'                => { 'text' => $locale->text('Employee'), },
183     'salesman'                => { 'text' => $locale->text('Salesperson'), },
184     'invnumber'               => { 'text' => $locale->text('Invoice Number'), },
185     'transdate'               => { 'text' => $locale->text('Invoice Date'), },
186     'qty'                     => { 'text' => $locale->text('Quantity'), },
187     'unit'                    => { 'text' => $locale->text('Unit'), },
188     'sellprice'               => { 'text' => $locale->text('Sales price'), },
189     'sellprice_total'         => { 'text' => $locale->text('Sales net amount'), },
190     'lastcost_total'          => { 'text' => $locale->text('Purchase net amount'), },
191     'discount'                => { 'text' => $locale->text('Discount'), },
192     'lastcost'                => { 'text' => $locale->text('Purchase price'), },
193     'marge_total'             => { 'text' => $locale->text('Sales margin'), },
194     'marge_percent'           => { 'text' => $locale->text('Sales margin %'), },
195     'customernumber'          => { 'text' => $locale->text('Customer Number'), },
196     'customername'            => { 'text' => $locale->text('Customer Name'), },
197 # add 3 more column_defs so we have a translation for top_info_text
198     'customer'                => { 'text' => $locale->text('Customer'), },
199     'part'                    => { 'text' => $locale->text('Part'), },
200     'month'                   => { 'text' => $locale->text('Month'), },
201     %column_defs_cvars,
202   );
203
204   map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
205
206   my %column_alignment = map { $_ => 'right' } qw(lastcost sellprice sellprice_total lastcost_total unit discount marge_total marge_percent qty);
207
208   
209   # so now the check-box "Description" is only used as switch for part description in invoice-mode
210   # always fill the column "Description" if we are in Zwischensummenmode
211   if (not defined $form->{"l_parts"}) {
212     $form->{"l_description"} = "Y";
213   };
214   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
215
216   my @options;
217
218   if ($form->{description}) {
219     push @options, $locale->text('Description') . " : $form->{description}";
220   }
221   if ($form->{customer}) {
222     push @options, $locale->text('Customer') . " : $form->{customername}";
223   }
224   if ($form->{customernumber}) {
225     push @options, $locale->text('Customer Number') . " : $form->{customernumber}";
226   }
227 # TODO: es wird nur id übergeben
228   if ($form->{department}) {
229     my ($department) = split /--/, $form->{department};
230     push @options, $locale->text('Department') . " : $department";
231   }
232   if ($form->{invnumber}) {
233     push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
234   }
235   if ($form->{invdate}) {
236     push @options, $locale->text('Invoice Date') . " : $form->{invdate}";
237   }
238   if ($form->{partnumber}) {
239     push @options, $locale->text('Part Number') . " : $form->{partnumber}";
240   }
241   if ($form->{partsgroup_id}) {
242     my $partsgroup = SL::DB::PartsGroup->new(id => $form->{partsgroup_id})->load;
243     push @options, $locale->text('Group') . " : $partsgroup->{partsgroup}";
244   }
245   if ($form->{country}) {
246     push @options, $locale->text('Country') . " : $form->{country}";
247   }
248   if ($form->{employee_id}) {
249     my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load;
250     push @options, $locale->text('Employee') . ' : ' . $employee->name;
251   }
252   if ($form->{salesman_id}) {
253     my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load;
254     push @options, $locale->text('Salesman') . ' : ' . $salesman->name;
255   }
256   if ($form->{business_id}) {
257     my $business = SL::DB::Business->new(id => $form->{business_id})->load;
258     push @options, $locale->text('Customer type') . ' : ' . $business->description;
259   }
260   if ($form->{ordnumber}) {
261     push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
262   }
263   if ($form->{notes}) {
264     push @options, $locale->text('Notes') . " : $form->{notes}";
265   }
266   if ($form->{transaction_description}) {
267     push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
268   }
269   if ($form->{transdatefrom}) {
270     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
271   }
272   if ($form->{transdateto}) {
273     push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
274   }
275
276   my $report = SL::ReportGenerator->new(\%myconfig, $form);
277
278   $report->set_options('top_info_text'        => join("\n", $locale->text('Main sorting') . ' : ' . $column_defs{$form->{mainsort}}->{text} , $locale->text('Secondary sorting') . ' : ' . $column_defs{$form->{'subsort'}}->{text}, @options),
279                        'output_format'        => 'HTML',
280                        'title'                => $form->{title},
281                        'attachment_basename'  => $locale->text('Sales Report') . strftime('_%Y%m%d', localtime time),
282     );
283   $report->set_options_from_form();
284   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
285
286   $report->set_columns(%column_defs);
287   $report->set_column_order(@columns);
288
289   $report->set_export_options('invoice_transactions', @hidden_variables, qw(mainsort sortdir));
290
291   $report->set_sort_indicator($form->{mainsort}, $form->{sortdir});
292
293   CVar->add_custom_variables_to_report('module'         => 'CT',
294       'trans_id_field' => 'customerid',
295       'configs'        => $cvar_configs_ct,
296       'column_defs'    => \%column_defs,
297       'data'           => $form->{AR}
298   );
299
300   CVar->add_custom_variables_to_report('module'         => 'IC',
301       'trans_id_field' => 'parts_id',
302       'configs'        => $cvar_configs_ic,
303       'column_defs'    => \%column_defs,
304       'data'           => $form->{AR}
305   );
306
307   # add sort and escape callback, this one we use for the add sub
308   $form->{callback} = $href .= "&sort=$form->{mainsort}";
309
310   # escape callback for href
311   $callback = $form->escape($href);
312
313   my @subtotal_columns = qw(qty sellprice sellprice_total lastcost lastcost_total marge_total marge_percent discount);
314   # Gesamtsumme:
315   # Summe von sellprice_total, lastcost_total und marge_total
316   # Durchschnitt von marge_percent
317   my @total_columns = qw(sellprice_total lastcost_total marge_total marge_percent );
318
319   my %totals    = map { $_ => 0 } @total_columns;
320   my %subtotals1 = map { $_ => 0 } @subtotal_columns;
321   my %subtotals2 = map { $_ => 0 } @subtotal_columns;
322
323   my $idx = 0;
324
325   foreach my $ar (@{ $form->{AR} }) {
326
327     $ar->{price_factor} = 1 unless $ar->{price_factor};
328     # calculate individual sellprice
329     # discount was already accounted for in db sellprice
330     $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor};
331     $ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor};
332     $ar->{sellprice_total} = $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) ;
333     $ar->{lastcost_total}  = $ar->{qty} * $ar->{lastcost};
334     # marge_percent wird neu berechnet, da Wert in invoice leer ist (Bug)
335     $ar->{marge_percent} = $ar->{sellprice_total} ? (($ar->{sellprice_total}-$ar->{lastcost_total}) / $ar->{sellprice_total} * 100) : 0;
336     # marge_total neu berechnen
337     $ar->{marge_total} = $ar->{sellprice_total} ? $ar->{sellprice_total}-$ar->{lastcost_total}  : 0;
338     $ar->{discount} *= 100;  # für Ausgabe formatieren, 10% stored as 0.1 in db
339
340     # Anfangshauptüberschrift
341     if ( $form->{l_headers_mainsort} eq "Y" && ( $idx == 0 or $ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'mainsort'} } )) {
342       my $headerrow;
343
344       # use $emptyname for mainsort header if mainsort is empty
345       if ( $ar->{$form->{'mainsort'}} ) {
346         $headerrow->{description}->{data} = $ar->{$form->{'mainsort'}};
347       } else {
348         $headerrow->{description}->{data} = $locale->text('empty');
349       };
350
351       $headerrow->{description}->{class} = "listmainsortheader";
352       my $headerrow_set = [ $headerrow ];
353       $report->add_data($headerrow_set);
354
355       # add empty row after main header
356 #      my $emptyheaderrow->{description}->{data} = "";
357 #      $emptyheaderrow->{description}->{class} = "listmainsortheader";
358 #      my $emptyheaderrow_set = [ $emptyheaderrow ];
359 #      $report->add_data($emptyheaderrow_set) if $form->{l_headers} eq "Y";
360     };
361
362     # subsort überschriften
363     if ( $idx == 0
364       or $ar->{ $form->{'subsort'} }  ne $form->{AR}->[$idx - 1]->{ $form->{'subsort'} }
365       or $ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'mainsort'} }
366     ) {
367       my $headerrow;
368
369       # if subsort name is defined, use that name in header, otherwise use $emptyname
370       if ( $ar->{$form->{'subsort'}} ) {
371         $headerrow->{description}->{data} = $ar->{$form->{'subsort'}};
372       } else {
373         $headerrow->{description}->{data} = $locale->text('empty');
374       };
375       $headerrow->{description}->{class} = "listsubsortheader";
376       my $headerrow_set = [ $headerrow ];
377       # special case: subsort headers only makes (aesthetical) sense if we show individual parts
378       $report->add_data($headerrow_set) if $form->{l_headers_subsort} eq "Y" and $form->{l_parts};
379     };
380
381     map { $subtotals1{$_} += $ar->{$_};
382           $subtotals2{$_} += $ar->{$_};
383         } @subtotal_columns;
384
385     map { $totals{$_}    += $ar->{$_} } @total_columns;
386
387     if ( $subtotals1{qty} != 0 ) {
388       # calculate averages for subtotals1 and subtotals2
389       # credited positions reduce both total and qty and thus don't influence average prices
390       $subtotals1{sellprice} = $subtotals1{sellprice_total} / $subtotals1{qty};
391       $subtotals1{lastcost} = $subtotals1{lastcost_total} / $subtotals1{qty};
392     } else {
393       # qty is zero, so we have a special case where each position in subtotal
394       # group has a corresponding credit note so that the total qty is zero in
395       # this case we also want the total amounts to be zero, so overwrite them,
396       # rather than leaving the last value in sellprice/lastcost
397
398       $subtotals1{sellprice} = 0;
399       $subtotals1{lastcost} = 0;
400     };
401
402     if ( $subtotals2{qty} != 0 ) {
403       $subtotals2{sellprice} = $subtotals2{sellprice_total} / $subtotals2{qty};
404       $subtotals2{lastcost} = $subtotals2{lastcost_total} / $subtotals2{qty};
405     } else {
406       $subtotals2{sellprice} = 0;
407       $subtotals2{lastcost} = 0;
408     };
409
410     # Ertrag prozentual in den Summen: (summe VK - summe Ertrag) / summe VK
411     $subtotals1{marge_percent} = $subtotals1{sellprice_total} ? (($subtotals1{sellprice_total} - $subtotals1{lastcost_total}) / $subtotals1{sellprice_total}) * 100 : 0;
412     $subtotals2{marge_percent} = $subtotals2{sellprice_total} ? (($subtotals2{sellprice_total} - $subtotals2{lastcost_total}) / $subtotals2{sellprice_total}) *100 : 0;
413
414     # Ertrag prozentual:  (Summe VK betrag - Summe EK betrag) / Summe VK betrag
415     # wird laufend bei jeder Position neu berechnet
416     $totals{marge_percent}    = $totals{sellprice_total}    ? ( ($totals{sellprice_total} - $totals{lastcost_total}) / $totals{sellprice_total}   ) * 100 : 0;
417
418     map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(marge_total marge_percent);
419     map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, $form->{"decimalplaces"} )} qw(lastcost sellprice sellprice_total lastcost_total);
420
421     my $row = { };
422
423     foreach my $column (@columns) {
424       $row->{$column} = {
425         'data'  => $ar->{$column},
426         'align' => $column_alignment{$column},
427       };
428     }
429
430    $row->{description}->{class} = 'listsortdescription';
431
432     $row->{invnumber}->{link} = build_std_url("script=is.pl", 'action=edit')
433       . "&id=" . E($ar->{id}) . "&callback=${callback}";
434
435     # Einzelzeilen nur zeigen wenn l_parts gesetzt ist, nützlich, wenn man nur
436     # Subtotals und Totals sehen möchte
437     my $row_set = $form->{l_parts} ? [ $row ] : [ ];
438
439     # hier wird bei l_subtotal nicht differenziert zwischen mainsort und subsort
440     # macht man l_subtotal_mainsort aus wird l_subtotal_subsort auch nicht ausgeführt
441     if (($form->{l_subtotal_mainsort} eq 'Y')
442         && (($idx == (scalar @{ $form->{AR} } - 1))   # last element always has a subtotal
443           || ($ar->{ $form->{'subsort'} } ne $form->{AR}->[$idx + 1]->{ $form->{'subsort'}   })
444           || ($ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx + 1]->{ $form->{'mainsort'} })
445           )) {   # if value that is sorted by changes, print subtotal
446
447       if ($form->{l_subtotal_subsort} eq 'Y') {
448         push @{ $row_set }, create_subtotal_row_invoice(\%subtotals2, \@columns, \%column_alignment, \@subtotal_columns, 'listsubsortsubtotal', $ar->{ $form->{'subsort'} }) ;
449         push @{ $row_set }, insert_empty_row() if $form->{l_parts} and $addemptylines;
450       };
451     }
452
453     # if last mainsort is reached or mainsort has changed, add mainsort subtotal and empty row
454     if (($form->{l_subtotal_mainsort} eq 'Y')
455         && (($idx == (scalar @{ $form->{AR} } - 1))   # last element always has a subtotal
456             || ($ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx + 1]->{ $form->{'mainsort'} })
457             )) {   # if value that is sorted by changes, print subtotal
458       if ($form->{l_subtotal_mainsort} eq 'Y' and $form->{mainsort} ne $form->{subsort} ) {
459         # subtotal is overriden if mainsort and subsort are equal, don't print
460         # subtotal line even if it is selected
461         push @{ $row_set }, create_subtotal_row_invoice(\%subtotals1, \@columns, \%column_alignment, \@subtotal_columns, 'listmainsortsubtotal', $ar->{$form->{mainsort}});
462         push @{ $row_set }, insert_empty_row() if $addemptylines; # insert empty row after mainsort
463       };
464     }
465
466     $report->add_data($row_set);
467
468     $idx++;
469   }
470   if ( $form->{l_total} eq "Y" ) {
471     $report->add_separator();
472     $report->add_data(create_subtotal_row_invoice(\%totals, \@columns, \%column_alignment, \@total_columns, 'listtotal', 'l_total'))
473   };
474
475   $report->generate_with_headers();
476   $main::lxdebug->leave_sub();
477 }
478
479
480 sub insert_empty_row {
481     my $dummyrow;
482     $dummyrow->{description}->{data} = "";
483     my $dummyrowset = [ $dummyrow ];
484     return $dummyrow;
485 };
486
487
488
489 sub create_subtotal_row_invoice {
490   $main::lxdebug->enter_sub();
491
492   my ($totals, $columns, $column_alignment, $subtotal_columns, $class, $name) = @_;
493
494   my $form     = $main::form;
495   my %myconfig = %main::myconfig;
496   my $locale   = $main::locale;
497
498   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
499
500   # set name as "empty" if no value is given, except if we are dealing with the
501   # absolute total, then just write "Total sum"
502   # here we assume that no name will be called 'l_total'
503   $name = $locale->text('empty') unless $name;
504   if ( $name eq 'l_total' ) {
505     $row->{description}->{data} = $locale->text('Total sum');
506   } else {
507     $row->{description}->{data} = $locale->text('Total') . ' ' . $name;
508   };
509
510   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(marge_total marge_percent);
511   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 0) } qw(qty);
512   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, $form->{decimalplaces}) } qw(lastcost sellprice sellprice_total lastcost_total);
513
514
515   map { $totals->{$_} = 0 } @{ $subtotal_columns };
516
517   $main::lxdebug->leave_sub();
518
519   return $row;
520 }
521
522 1;
523