use List::Util qw(sum first);
use SL::VK;
+use SL::IS;
use SL::ReportGenerator;
use Data::Dumper;
my ($callback, $href, @columns);
$form->{customer} = $form->unescape($form->{customer});
-
- ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer});
+
+ if ( $form->{customer} =~ /--/ ) {
+ # Felddaten kommen aus Dropdownbox
+ ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer});
+ } else {
+ # Felddaten kommen aus Freitextfeld
+
+ # 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};
+ };
# decimalplaces überprüfen oder auf Default 2 setzen
$form->{decimalplaces} = 2 unless $form->{decimalplaces} > 0 && $form->{decimalplaces} < 6;
'marge_total' => { 'text' => $locale->text('Sales margin'), },
'marge_percent' => { 'text' => $locale->text('Sales margin %'), },
);
-
+
my %column_alignment = map { $_ => 'right' } qw(lastcost sellprice sellprice_total lastcost_total unit discount marge_total marge_percent qty);
$form->{"l_type"} = "Y";
'attachment_basename' => $locale->text('Sales Report') . strftime('_%Y%m%d', localtime time),
);
$report->set_options_from_form();
+ $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
$ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor};
$ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor};
$ar->{sellprice_total} = $ar->{qty} * $ar->{sellprice};
- $ar->{lastcost_total} = $ar->{qty} * $ar->{lastcost};
+ $ar->{lastcost_total} = $ar->{qty} * $ar->{lastcost};
# 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}) : 0;
# marge_total neu berechnen
my $name;
my $headerrow;
if ( $form->{mainsort} eq 'parts_id' ) {
- $headerrow->{description}->{data} = "$ar->{description}";
+ $headerrow->{description}->{data} = "$ar->{description}";
} else {
- $headerrow->{description}->{data} = "$ar->{name}";
+ $headerrow->{description}->{data} = "$ar->{name}";
};
$headerrow->{description}->{class} = "listmainsortheader";
my $headerrow_set = [ $headerrow ];
$report->add_data($headerrow_set);
# add empty row after main header
-# my $emptyheaderrow->{description}->{data} = "";
+# my $emptyheaderrow->{description}->{data} = "";
# $emptyheaderrow->{description}->{class} = "listmainsortheader";
# my $emptyheaderrow_set = [ $emptyheaderrow ];
-# $report->add_data($emptyheaderrow_set) if $form->{l_headers} eq "Y";
+# $report->add_data($emptyheaderrow_set) if $form->{l_headers} eq "Y";
};
# subsort überschriften
- if ( $idx == 0
+ if ( $idx == 0
or $ar->{ $form->{'subsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'subsort'} }
or $ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx - 1]->{ $form->{'mainsort'} }
) {
map { $subtotals1{$_} += $ar->{$_};
$subtotals2{$_} += $ar->{$_};
} @subtotal_columns;
-
- map { $totals{$_} += $ar->{$_} } @total_columns;
+
+ map { $totals{$_} += $ar->{$_} } @total_columns;
$subtotals2{sellprice} = $subtotals2{sellprice_total} / $subtotals2{qty} if $subtotals2{qty} != 0;
$subtotals1{sellprice} = $subtotals1{sellprice_total} / $subtotals1{qty} if $subtotals1{qty} != 0;
'align' => $column_alignment{$column},
};
}
-
+
$row->{description}->{class} = 'listsortdescription';
$row->{invnumber}->{link} = build_std_url("script=is.pl", 'action=edit')
} else {
$name = 'name';
};
-
+
if ($form->{l_subtotal} eq 'Y' ) {
push @{ $row_set }, create_subtotal_row_invoice(\%subtotals2, \@columns, \%column_alignment, \@subtotal_columns, 'listsubsortsubtotal', $ar->{$name}) ;
push @{ $row_set }, insert_empty_row();
};
}
- # if mainsort has changed, add mainsort subtotal and empty row
+ # if mainsort has changed, add mainsort subtotal and empty row
if (($form->{l_subtotal} eq 'Y')
&& (($idx == (scalar @{ $form->{AR} } - 1)) # last element always has a subtotal
|| ($ar->{ $form->{'mainsort'} } ne $form->{AR}->[$idx + 1]->{ $form->{'mainsort'} })
push @{ $row_set }, insert_empty_row();
};
}
-
+
$report->add_data($row_set);
$idx++;
my %myconfig = %main::myconfig;
my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
-
+
$row->{description}->{data} = "Summe " . $name;
map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } qw(marge_total marge_percent);