use Exporter qw(import);
our @EXPORT = qw(grouped_record_list empty_record_list record_list);
+use SL::Util;
+
use Carp;
use List::Util qw(first);
$output .= _purchase_invoice_list( $self, $groups{purchase_invoices}, %params) if $groups{purchase_invoices};
$output .= _ar_transaction_list( $self, $groups{ar_transactions}, %params) if $groups{ar_transactions};
+ $output .= _sepa_collection_list( $self, $groups{sepa_collections}, %params) if $groups{sepa_collections};
+ $output .= _sepa_transfer_list( $self, $groups{sepa_transfers}, %params) if $groups{sepa_transfers};
+
$output = $self->render('presenter/record/grouped_record_list', %params, output => $output);
return $output;
my $meta = $column_meta{ $spec->{data} };
my $type = ref $meta;
my $relationship = $relationships{ $spec->{data} };
- my $rel_type = !$relationship ? '' : lc $relationship->class;
- $rel_type =~ s/^sl::db:://;
+ my $rel_type = !$relationship ? '' : $relationship->class;
+ $rel_type =~ s/^SL::DB:://;
+ $rel_type = SL::Util::snakify($rel_type);
if (ref($spec->{data}) eq 'CODE') {
$cell{value} = $spec->{data}->($obj);
purchase_delivery_orders => sub { (ref($_[0]) eq 'SL::DB::DeliveryOrder') && !$_[0]->is_sales },
purchase_invoices => sub { (ref($_[0]) eq 'SL::DB::PurchaseInvoice') && $_[0]->invoice },
ap_transactions => sub { (ref($_[0]) eq 'SL::DB::PurchaseInvoice') && !$_[0]->invoice },
+ sepa_collections => sub { (ref($_[0]) eq 'SL::DB::SepaExportItem') && $_[0]->ar_id },
+ sepa_transfers => sub { (ref($_[0]) eq 'SL::DB::SepaExportItem') && $_[0]->ap_id },
);
my %groups;
sub _sort_grouped_lists {
my (%groups) = @_;
- $groups{$_} = [ sort { $a->date <=> $b->date } @{ $groups{$_} } ] for keys %groups;
+ foreach my $group (keys %groups) {
+ next unless @{ $groups{$group} };
+ if ($groups{$group}->[0]->can('compare_to')) {
+ $groups{$group} = [ sort { $a->compare_to($b) } @{ $groups{$group} } ];
+ } else {
+ $groups{$group} = [ sort { $a->date <=> $b->date } @{ $groups{$group} } ];
+ }
+ }
return %groups;
}
);
}
+sub _sepa_export_list {
+ my ($self, $list, %params) = @_;
+
+ my ($source, $destination) = $params{type} eq 'sepa_transfer' ? qw(our vc) : qw(vc our);
+ $params{title} = $params{type} eq 'sepa_transfer' ? $::locale->text('Bank transfers via SEPA') : $::locale->text('Bank collections via SEPA');
+ $params{with_columns} = [ grep { $_ ne 'record_link_direction' } @{ $params{with_columns} || [] } ];
+
+ delete $params{edit_record_links};
+
+ return $self->record_list(
+ $list,
+ columns => [
+ [ $::locale->text('Export Number'), 'sepa_export', ],
+ [ $::locale->text('Execution date'), 'execution_date' ],
+ [ $::locale->text('Export date'), sub { $_[0]->sepa_export->itime->to_kivitendo } ],
+ [ $::locale->text('Source BIC'), "${source}_bic" ],
+ [ $::locale->text('Source IBAN'), "${source}_iban" ],
+ [ $::locale->text('Destination BIC'), "${destination}_bic" ],
+ [ $::locale->text('Destination IBAN'), "${destination}_iban" ],
+ [ $::locale->text('Amount'), 'amount' ],
+ ],
+ %params,
+ );
+}
+
+sub _sepa_transfer_list {
+ my ($self, $list, %params) = @_;
+ _sepa_export_list($self, $list, %params, type => 'sepa_transfer');
+}
+
+sub _sepa_collection_list {
+ my ($self, $list, %params) = @_;
+ _sepa_export_list($self, $list, %params, type => 'sepa_collection');
+}
+
1;
__END__
=item * AP transactions
+=item * SEPA collections
+
+=item * SEPA transfers
+
=back
Objects of unknown types are skipped.
--- /dev/null
+package SL::Presenter::SepaExport;
+
+use strict;
+
+use parent qw(Exporter);
+
+use Exporter qw(import);
+our @EXPORT = qw(sepa_export);
+
+use Carp;
+
+sub sepa_export {
+ my ($self, $sepa_export, %params) = @_;
+
+ $params{display} ||= 'inline';
+
+ croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
+
+ my $text = join '', (
+ $params{no_link} ? '' : '<a href="sepa.pl?action=bank_transfer_edit&vc=' . $self->escape($sepa_export->vc) . '&id=' . $self->escape($sepa_export->id) . '">',
+ $self->escape($sepa_export->id),
+ $params{no_link} ? '' : '</a>',
+ );
+ return $self->escaped_text($text);
+}
+
+1;
+
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+SL::Presenter::SepaExport - Presenter module for Rose::DB objects
+for SEPA transfers and collections
+
+=head1 SYNOPSIS
+
+ # Collections from an invoice:
+ my $invoice = SL::DB::Invoice->new(id => 123)->load;
+ my $object = $invoice->sepa_export_items->[0]->sepa_export;
+ my $html = SL::Presenter->get->sepa_export($object, display => 'inline');
+
+ # Transfers from a purchase invoice:
+ my $invoice = SL::DB::PurchaseInvoice->new(id => 123)->load;
+ my $object = $invoice->sepa_export_items->[0]->sepa_export;
+ my $html = SL::Presenter->get->sepa_export($object, display => 'inline');
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<sepa_export $object, %params>
+
+Returns a rendered version (actually an instance of
+L<SL::Presenter::EscapedText>) of the SEPA collection/transfer object
+C<$object>.
+
+C<%params> can include:
+
+=over 2
+
+=item * display
+
+Either C<inline> (the default) or C<table-cell>. At the moment both
+representations are identical and produce the objects's delivery
+order number linked to the corresponding 'edit' action.
+
+=item * no_link
+
+If falsish (the default) then the delivery order number will be linked
+to the "edit SEPA transfer" dialog from the 'cash' menu.
+
+=back
+
+=back
+
+=head1 BUGS
+
+Nothing here yet.
+
+=head1 AUTHOR
+
+Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
+
+=cut