-## LINET: Create a drop-down box with all prior titles and greetings.
- CT->query_titles_and_greetings(\%myconfig, \%$form);
-
- $select_title = qq| <select name=selected_cp_title><option></option>|;
- map({ $select_title .= qq|<option>$_</option>|; } @{ $form->{TITLES} });
- $select_title .= qq|</select>|;
-
- $select_greeting =
- qq| <select name=selected_cp_greeting><option></option>|;
- map(
- { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
- $select_greeting .= qq|</select>|;
-
- $select_company_greeting =
- qq| <select name=selected_company_greeting><option></option>|;
- map(
- { $select_company_greeting .= qq|<option>$_</option>|; } @{ $form->{COMPANY_GREETINGS} });
- $select_company_greeting .= qq|</select>|;
-
- $select_department =
- qq| <select name=selected_cp_abteilung><option></option>|;
- map(
- { $select_department .= qq|<option>$_</option>|; } @{ $form->{DEPARTMENT} });
- $select_department .= qq|</select>|;
-## /LINET
-
- if ($form->{db} eq 'customer') {
-
- #get pricegroup and form it
- $form->get_pricegroup(\%myconfig, { all => 1 });
-
- $form->{pricegroup} = "$form->{klass}";
- $form->{pricegroup_id} = "$form->{klass}";
-
- if (@{ $form->{all_pricegroup} }) {
-
- $form->{selectpricegroup} = qq|<option>\n|;
- map {
- $form->{selectpricegroup} .=
- qq|<option value="$_->{id}">$_->{pricegroup}\n|
- } @{ $form->{all_pricegroup} };
+ if ( $form->{insertdatefrom} or $form->{insertdateto} ) {
+ push @options, $locale->text('Insert Date');
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{insertdatefrom}, 1) if $form->{insertdatefrom};
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{insertdateto}, 1) if $form->{insertdateto};
+ };
+
+ my @columns = (
+ 'id', 'name', "$form->{db}number", 'contact', 'phone', 'discount',
+ 'fax', 'email', 'taxnumber', 'street', 'zipcode' , 'city',
+ 'business', 'payment', 'invnumber', 'ordnumber', 'quonumber', 'salesman',
+ 'country', 'gln', 'insertdate', 'pricegroup'
+ );
+
+ my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
+ my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs };
+ my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
+
+ push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
+
+ my %column_defs = (
+ 'id' => { 'text' => $locale->text('ID'), },
+ "$form->{db}number" => { 'text' => $locale->text('Number'), },
+ 'name' => { 'text' => $form->{IS_CUSTOMER} ? $::locale->text('Customer Name') : $::locale->text('Vendor Name'), },
+ 'contact' => { 'text' => $locale->text('Contact'), },
+ 'phone' => { 'text' => $locale->text('Phone'), },
+ 'fax' => { 'text' => $locale->text('Fax'), },
+ 'email' => { 'text' => $locale->text('E-mail'), },
+ 'cc' => { 'text' => $locale->text('Cc'), },
+ 'taxnumber' => { 'text' => $locale->text('Tax Number'), },
+ 'business' => { 'text' => $locale->text('Type of Business'), },
+ 'invnumber' => { 'text' => $locale->text('Invoice'), },
+ 'ordnumber' => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Sales Order') : $locale->text('Purchase Order'), },
+ 'quonumber' => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Quotation') : $locale->text('Request for Quotation'), },
+ 'street' => { 'text' => $locale->text('Street'), },
+ 'zipcode' => { 'text' => $locale->text('Zipcode'), },
+ 'city' => { 'text' => $locale->text('City'), },
+ 'country' => { 'text' => $locale->text('Country'), },
+ 'gln' => { 'text' => $locale->text('GLN'), },
+ 'salesman' => { 'text' => $locale->text('Salesman'), },
+ 'discount' => { 'text' => $locale->text('Discount'), },
+ 'payment' => { 'text' => $locale->text('Payment Terms'), },
+ 'insertdate' => { 'text' => $locale->text('Insert Date'), },
+ 'pricegroup' => { 'text' => $locale->text('Pricegroup'), },
+ %column_defs_cvars,
+ );
+
+ map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
+
+ my @hidden_variables = ( qw(
+ db status obsolete name contact email cp_name addr_street addr_zipcode
+ addr_city addr_country addr_gln business_id salesman_id insertdateto insertdatefrom all
+ ), "$form->{db}number",
+ map({ "cvar_$_->{name}" } @searchable_custom_variables),
+ map({'cvar_'. $_->{name} .'_qtyop'} grep({$_->{type} eq 'number'} @searchable_custom_variables)),
+ map({ "l_$_" } @columns),
+ );
+
+ my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
+ my $callback = build_std_url('action=list_names', grep { $form->{$_} } @hidden_nondefault);
+ $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
+
+ foreach (@columns) {
+ my $sortdir = $form->{sort} eq $_ ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=${sortdir}";
+ }
+
+ my ($ordertype, $quotationtype, $attachment_basename);
+ if ($form->{IS_CUSTOMER}) {
+ $form->{title} = $locale->text('Customers');
+ $ordertype = 'sales_order';
+ $quotationtype = 'sales_quotation';
+ $attachment_basename = $locale->text('customer_list');
+
+ } else {
+ $form->{title} = $locale->text('Vendors');
+ $ordertype = 'purchase_order';
+ $quotationtype = 'request_quotation';
+ $attachment_basename = $locale->text('vendor_list');
+ }
+
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
+
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'raw_bottom_info_text' => $form->parse_html_template('ct/list_names_bottom'),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basename . 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);
+
+ $report->set_export_options('list_names', @hidden_variables, qw(sort sortdir));
+
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
+
+ CVar->add_custom_variables_to_report('module' => 'CT',
+ 'trans_id_field' => 'id',
+ 'configs' => $cvar_configs,
+ 'column_defs' => \%column_defs,
+ 'data' => $form->{CT});
+
+ my $previous_id;
+
+ foreach my $ref (@{ $form->{CT} }) {
+ my $row = { map { $_ => { 'data' => '' } } @columns };
+
+ if ($ref->{id} ne $previous_id) {
+ $previous_id = $ref->{id};
+ $ref->{discount} = $form->format_amount(\%myconfig, $ref->{discount} * 100.0, 2);
+ map { $row->{$_}->{data} = $ref->{$_} } @columns;
+
+ $row->{name}->{link} = build_std_url('script=controller.pl', 'action=CustomerVendor/edit', 'id=' . E($ref->{id}), 'callback', @hidden_nondefault);
+ $row->{email}->{link} = 'mailto:' . E($ref->{email});