Allgemeine Presenter-Methode für records (ar/ap/gl)
authorG. Richardson <information@kivitendo-premium.de>
Tue, 27 Jan 2015 13:32:07 +0000 (14:32 +0100)
committerG. Richardson <information@kivitendo-premium.de>
Tue, 27 Jan 2015 13:42:55 +0000 (14:42 +0100)
Damit kann man einen HTML-Link für ein einzelnes Record Objekt
erstellen, ohne zu wissen ob es ar, ap oder gl ist.

SL::Presenter->get->record($record, display => 'inline');

SL/Presenter/Record.pm

index 23c5d46..b46896d 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use parent qw(Exporter);
 
 use Exporter qw(import);
-our @EXPORT = qw(grouped_record_list empty_record_list record_list);
+our @EXPORT = qw(grouped_record_list empty_record_list record_list record);
 
 use SL::Util;
 
@@ -19,6 +19,21 @@ sub _arrayify {
   return [ $array ];
 }
 
+sub record {
+  my ($self, $record, %params) = @_;
+
+  my %grouped = _group_records( [ $record ] ); # pass $record as arrayref
+  my $type    = (keys %grouped)[0];
+
+  return $self->sales_invoice(   $record, %params) if $type eq 'sales_invoices';
+  return $self->purchase_invoice($record, %params) if $type eq 'purchase_invoices';
+  return $self->ar_transaction(  $record, %params) if $type eq 'ar_transactions';
+  return $self->ap_transaction(  $record, %params) if $type eq 'ap_transactions';
+  return $self->gl_transaction(  $record, %params) if $type eq 'gl_transactions';
+
+  return '';
+}
+
 sub grouped_record_list {
   my ($self, $list, %params) = @_;
 
@@ -161,6 +176,7 @@ sub _group_records {
     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                        },
+    gl_transactions          => sub { (ref($_[0]) eq 'SL::DB::GLTransaction')                                           },
   );
 
   my %groups;
@@ -478,6 +494,18 @@ TODO
 
 =over 4
 
+=item C<record>
+
+Returns a rendered version (actually an instance of
+L<SL::Presenter::EscapedText>) of a single ar, ap or gl object.
+
+Example:
+  # fetch the record from a random acc_trans object and print its link (could be ar, ap or gl)
+  my $record = SL::DB::Manager::AccTransaction->get_first()->record;
+  my $html   = SL::Presenter->get->record($record, display => 'inline');
+
+=item C<grouped_record_list $list, %params>
+
 =item C<empty_record_list>
 
 Returns a rendered version (actually an instance of