- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
-
- $column_header{id} = qq|<th class=listheading>|.$locale->text('ID').qq|</th>|;
- $column_header{"$form->{db}number"} = qq|<th><a class=listheading href=$href&sort=$form->{db}number>$number</a></th>|;
- $column_header{name} = qq|<th><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
- $column_header{address} = qq|<th><a class=listheading href=$href&sort=address>|.$locale->text('Address').qq|</a></th>|;
- $column_header{contact} = qq|<th><a class=listheading href=$href&sort=contact>|.$locale->text('Contact').qq|</a></th>|;
- $column_header{phone} = qq|<th><a class=listheading href=$href&sort=phone>|.$locale->text('Phone').qq|</a></th>|;
- $column_header{fax} = qq|<th><a class=listheading href=$href&sort=fax>|.$locale->text('Fax').qq|</a></th>|;
- $column_header{email} = qq|<th><a class=listheading href=$href&sort=email>|.$locale->text('E-mail').qq|</a></th>|;
- $column_header{cc} = qq|<th><a class=listheading href=$href&sort=cc>|.$locale->text('Cc').qq|</a></th>|;
-
- $column_header{taxnumber} = qq|<th><a class=listheading href=$href&sort=taxnumber>|.$locale->text('Tax Number').qq|</a></th>|;
- $column_header{gifi_accno} = qq|<th><a class=listheading href=$href&sort=gifi_accno>|.$locale->text('GIFI').qq|</a></th>|;
- $column_header{sic_code} = qq|<th><a class=listheading href=$href&sort=sic_code>|.$locale->text('SIC').qq|</a></th>|;
- $column_header{business} = qq|<th><a class=listheading href=$href&sort=business>|.$locale->text('Type of Business').qq|</a></th>|;
-
- $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice').qq|</a></th>|;
- $column_header{ordnumber} = qq|<th><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order').qq|</a></th>|;
- $column_header{quonumber} = qq|<th><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
-
-
- $label = ucfirst $form->{db}."s";
- $form->{title} = $locale->text($label);
-
- $form->header;
-
- print qq|
-<body>
-
-<table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>$option</td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>
-|;
-
- map { print "$column_header{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
-
- $ordertype = ($form->{db} eq 'customer') ? 'sales_order' : 'purchase_order';
- $quotationtype = ($form->{db} eq 'customer') ? 'sales_quotation' : 'request_quotation';
-
- foreach $ref (@{ $form->{CT} }) {
+ my @columns = (
+ 'id', 'name', "$form->{db}number", 'address', 'contact', 'phone',
+ 'fax', 'email', 'taxnumber', 'sic_code', 'business', 'invnumber',
+ 'ordnumber', 'quonumber'
+ );
+
+ my %column_defs = (
+ 'id' => { 'text' => $locale->text('ID'), },
+ "$form->{db}number" => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Customer Number') : $locale->text('Vendor Number'), },
+ 'name' => { 'text' => $locale->text('Name'), },
+ 'address' => { 'text' => $locale->text('Address'), },
+ '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'), },
+ 'sic_code' => { 'text' => $locale->text('SIC'), },
+ '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'), },
+ );
+
+ map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
+
+ my @hidden_variables = (qw(db status obsolete), map { "l_$_" } @columns);
+ my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
+ my $callback = build_std_url('action=list_names', grep { $form->{$_} } @hidden_variables);
+ $form->{callback} = "$callback&sort=" . E($form->{sort});
+
+ map { $column_defs{$_}->{link} = "${callback}&sort=${_}" } @columns;
+
+ 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');