-
-
-
-|;
+ my @columns =
+ qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
+ due duedate transaction_description notes employee globalprojectnumber);
+
+ my @hidden_variables = map { "l_${_}" } @columns;
+ push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto);
+
+ my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
+
+ my %column_defs = (
+ 'transdate' => { 'text' => $locale->text('Date'), },
+ 'id' => { 'text' => $locale->text('ID'), },
+ 'type' => { 'text' => $locale->text('Type'), },
+ 'invnumber' => { 'text' => $locale->text('Invoice'), },
+ 'ordnumber' => { 'text' => $locale->text('Order'), },
+ 'name' => { 'text' => $locale->text('Vendor'), },
+ 'netamount' => { 'text' => $locale->text('Amount'), },
+ 'tax' => { 'text' => $locale->text('Tax'), },
+ 'amount' => { 'text' => $locale->text('Total'), },
+ 'paid' => { 'text' => $locale->text('Paid'), },
+ 'datepaid' => { 'text' => $locale->text('Date Paid'), },
+ 'due' => { 'text' => $locale->text('Amount Due'), },
+ 'duedate' => { 'text' => $locale->text('Due Date'), },
+ 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
+ 'notes' => { 'text' => $locale->text('Notes'), },
+ 'employee' => { 'text' => $locale->text('Salesperson'), },
+ 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
+ );
+
+ foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
+ my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
+ }
- map { print "\n$column_header{$_}" } @column_index;
+ my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
- print qq|
-
-|;
+ $form->{"l_type"} = "Y";
+ map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
- # add sort and escape callback
- $form->{callback} = "$callback&sort=$form->{sort}";
- $callback = $form->escape($form->{callback});
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
- if (@{ $form->{AP} }) {
- $sameitem = $form->{AP}->[0]->{ $form->{sort} };
- }
+ $report->set_export_options('ap_transactions', @hidden_variables, qw(sort sortdir));
- # sums and tax on reports by Antonio Gallardo
- #
- foreach $ap (@{ $form->{AP} }) {
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ap->{ $form->{sort} }) {
- &ap_subtotal;
- $sameitem = $ap->{ $form->{sort} };
- }
- }
+ my @options;
+ push @options, $locale->text('Vendor') . " : $form->{vendor}" if ($form->{vendor});
+ push @options, $locale->text('Department') . " : " . (split /--/, $form->{department})[0] if ($form->{department});
+ push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if ($form->{invnumber});
+ push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if ($form->{ordnumber});
+ push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
+ push @options, $locale->text('Transaction description') . " : $form->{transaction_description}" if ($form->{transaction_description});
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1) if ($form->{transdatefrom});
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1) if ($form->{transdateto});
+ push @options, $locale->text('Open') if ($form->{open});
+ push @options, $locale->text('Closed') if ($form->{closed});
- $column_data{netamount} =
- ""
- . $form->format_amount(\%myconfig, $ap->{netamount}, 2, " ")
- . " | ";
- $column_data{tax} = ""
- . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{netamount},
- 2, " ")
- . " | ";
- $column_data{amount} =
- ""
- . $form->format_amount(\%myconfig, $ap->{amount}, 2, " ") . " | ";
- $column_data{paid} =
- ""
- . $form->format_amount(\%myconfig, $ap->{paid}, 2, " ") . " | ";
- $column_data{due} = ""
- . $form->format_amount(\%myconfig, $ap->{amount} - $ap->{paid},
- 2, " ")
- . " | ";
-
- $totalnetamount += $ap->{netamount};
- $totalamount += $ap->{amount};
- $totalpaid += $ap->{paid};
- $totaldue += ($ap->{amount} - $ap->{paid});
-
- $subtotalnetamount += $ap->{netamount};
- $subtotalamount += $ap->{amount};
- $subtotalpaid += $ap->{paid};
- $subtotaldue += ($ap->{amount} - $ap->{paid});
-
- $column_data{transdate} = "$ap->{transdate} | ";
- $column_data{type} = "" .
- ($ap->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
- $locale->text("AP Transaction (abbreviation)"))
- . " | ";
- $column_data{duedate} = "$ap->{duedate} | ";
- $column_data{datepaid} = "$ap->{datepaid} | ";
-
- $module = ($ap->{invoice}) ? "ir.pl" : $form->{script};
-
- $column_data{invnumber} =
- qq|$ap->{invnumber} | |;
- $column_data{id} = "$ap->{id} | ";
- $column_data{ordnumber} = "$ap->{ordnumber} | ";
- $column_data{name} = "$ap->{name} | ";
- $ap->{notes} =~ s/\r\n/ /g;
- $column_data{notes} = "$ap->{notes} | ";
- $column_data{employee} = "$ap->{employee} | ";
- $column_data{globalprojectnumber} =
- "" . H($ap->{globalprojectnumber}) . " | ";
-
- $i++;
- $i %= 2;
- print "
-
-";
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $locale->text('vendor_invoice_list') . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
- map { print "\n$column_data{$_}" } @column_index;
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $href .= "&sort=$form->{sort}";
- print qq|
-
-|;
+ # escape callback for href
+ $callback = $form->escape($href);
- }
+ my @subtotal_columns = qw(netamount amount paid due);
- if ($form->{l_subtotal} eq 'Y') {
- &ap_subtotal;
- }
+ my %totals = map { $_ => 0 } @subtotal_columns;
+ my %subtotals = map { $_ => 0 } @subtotal_columns;
- # print totals
- print qq|
-
-|;
+ my $idx = 0;
- map { $column_data{$_} = " | " } @column_index;
-
- $column_data{netamount} =
- ""
- . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . " | ";
- $column_data{tax} = ""
- . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
- 2, " ")
- . " | ";
- $column_data{amount} =
- ""
- . $form->format_amount(\%myconfig, $totalamount, 2, " ") . " | ";
- $column_data{paid} =
- ""
- . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . " | ";
- $column_data{due} =
- ""
- . $form->format_amount(\%myconfig, $totaldue, 2, " ") . " | ";
+ foreach $ap (@{ $form->{AP} }) {
+ $ap->{tax} = $ap->{amount} - $ap->{netamount};
+ $ap->{due} = $ap->{amount} - $ap->{paid};
- map { print "$column_data{$_}\n" } @column_index;
+ map { $subtotals{$_} += $ap->{$_};
+ $totals{$_} += $ap->{$_} } @subtotal_columns;
- print qq|
-
-
- |
-
-