From c8e0c77f4da1fe14f1294a3be2e437c24f40eaea Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 30 Apr 2013 16:58:49 +0200 Subject: [PATCH] =?utf8?q?Verkn=C3=BCpfte=20Dokumente:=20Auch=20SEPA-?= =?utf8?q?=C3=9Cberweisungen/-Einz=C3=BCge=20anzeigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bisher noch nicht bei Debitoren- und Kreditorenbuchungen. Conflicts: SL/Presenter.pm --- SL/Controller/RecordLinks.pm | 1 + SL/DB/SepaExportItem.pm | 14 ++++-- SL/Presenter.pm | 1 + SL/Presenter/Record.pm | 60 ++++++++++++++++++++++-- SL/Presenter/SepaExport.pm | 89 ++++++++++++++++++++++++++++++++++++ locale/de/all | 1 + 6 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 SL/Presenter/SepaExport.pm diff --git a/SL/Controller/RecordLinks.pm b/SL/Controller/RecordLinks.pm index de0377577..8d6adc735 100644 --- a/SL/Controller/RecordLinks.pm +++ b/SL/Controller/RecordLinks.pm @@ -44,6 +44,7 @@ sub action_ajax_list { eval { my $linked_records = $self->object->linked_records(direction => 'both'); + push @{ $linked_records }, $self->object->sepa_export_items if $self->object->can('sepa_export_items'); my $output = SL::Presenter->get->grouped_record_list( $linked_records, with_columns => [ qw(record_link_direction) ], diff --git a/SL/DB/SepaExportItem.pm b/SL/DB/SepaExportItem.pm index 3c46ee39b..757011660 100644 --- a/SL/DB/SepaExportItem.pm +++ b/SL/DB/SepaExportItem.pm @@ -1,6 +1,3 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::SepaExportItem; use strict; @@ -10,4 +7,15 @@ use SL::DB::MetaSetup::SepaExportItem; # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; +sub compare_to { + my ($self, $other) = @_; + + return 1 if $self->execution_date && !$other->execution_date; + return -1 if !$self->execution_date && $other->execution_date; + + my $result = 0; + $result = $self->execution_date <=> $other->execution_date if $self->execution_date; + return $result || ($self->sepa_export_id <=> $other->sepa_export_id) || ($self->id <=> $other->id); +} + 1; diff --git a/SL/Presenter.pm b/SL/Presenter.pm index d8add6378..67e1948e4 100644 --- a/SL/Presenter.pm +++ b/SL/Presenter.pm @@ -14,6 +14,7 @@ use SL::Presenter::Invoice; use SL::Presenter::Order; use SL::Presenter::Project; use SL::Presenter::Record; +use SL::Presenter::SepaExport; use SL::Presenter::Text; use SL::Presenter::Tag; diff --git a/SL/Presenter/Record.pm b/SL/Presenter/Record.pm index 082fbd019..a00f40055 100644 --- a/SL/Presenter/Record.pm +++ b/SL/Presenter/Record.pm @@ -7,6 +7,8 @@ use parent qw(Exporter); 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); @@ -37,6 +39,9 @@ sub grouped_record_list { $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; @@ -92,8 +97,9 @@ sub record_list { 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); @@ -146,6 +152,8 @@ sub _group_records { 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; @@ -162,7 +170,14 @@ sub _group_records { 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; } @@ -371,6 +386,41 @@ sub _ap_transaction_list { ); } +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__ @@ -441,6 +491,10 @@ The order in which the records are grouped is: =item * AP transactions +=item * SEPA collections + +=item * SEPA transfers + =back Objects of unknown types are skipped. diff --git a/SL/Presenter/SepaExport.pm b/SL/Presenter/SepaExport.pm new file mode 100644 index 000000000..ceb483f2f --- /dev/null +++ b/SL/Presenter/SepaExport.pm @@ -0,0 +1,89 @@ +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} ? '' : '', + $self->escape($sepa_export->id), + $params{no_link} ? '' : '', + ); + 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 + +Returns a rendered version (actually an instance of +L) of the SEPA collection/transfer object +C<$object>. + +C<%params> can include: + +=over 2 + +=item * display + +Either C (the default) or C. 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 Em.bunkus@linet-services.deE + +=cut diff --git a/locale/de/all b/locale/de/all index a2463c6e3..823045a14 100755 --- a/locale/de/all +++ b/locale/de/all @@ -871,6 +871,7 @@ $self->{texts} = { 'Expenses EU with UStId' => 'Aufwand EU m. UStId', 'Expenses EU without UStId' => 'Aufwand EU o. UStId', 'Export Buchungsdaten' => 'Export Buchungsdaten', + 'Export Number' => 'Exportnummer', 'Export Stammdaten' => 'Export Stammdaten', 'Export as CSV' => 'Als CSV exportieren', 'Export as PDF' => 'Als PDF exportieren', -- 2.20.1