+ my @columns = (
+ 'id', 'name', "$form->{db}number", 'contact', 'phone',
+ 'fax', 'email', 'taxnumber', 'street', 'zipcode' , 'city',
+ 'business', 'invnumber', 'ordnumber', 'quonumber'
+ );
+
+ 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'), },
+ %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 business_id
+ ), "$form->{db}number",
+ map({ "cvar_$_->{name}" } @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};
+ map { $row->{$_}->{data} = $ref->{$_} } @columns;
+
+ $row->{name}->{link} = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback', @hidden_nondefault);
+ $row->{email}->{link} = 'mailto:' . E($ref->{email});