From 3bd0186152b02a358563ff441172c23f1fc8fadc Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 27 Jan 2015 14:32:07 +0100 Subject: [PATCH] =?utf8?q?Allgemeine=20Presenter-Methode=20f=C3=BCr=20reco?= =?utf8?q?rds=20(ar/ap/gl)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/SL/Presenter/Record.pm b/SL/Presenter/Record.pm index 23c5d46ea..b46896d47 100644 --- a/SL/Presenter/Record.pm +++ b/SL/Presenter/Record.pm @@ -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 + +Returns a rendered version (actually an instance of +L) 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 + =item C Returns a rendered version (actually an instance of -- 2.20.1