From b09bc3dee65b562db29f7884024af9720eb527e0 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Fri, 1 May 2015 13:48:32 +0200 Subject: [PATCH] AccTransaction: get_type und transaction_name umgeschrieben Nutzen jetzt record um Typ zu bestimmen. --- SL/DB/AccTransaction.pm | 62 +++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/SL/DB/AccTransaction.pm b/SL/DB/AccTransaction.pm index f25db8ee5..dc3628113 100644 --- a/SL/DB/AccTransaction.pm +++ b/SL/DB/AccTransaction.pm @@ -6,8 +6,10 @@ package SL::DB::AccTransaction; use strict; use SL::DB::MetaSetup::AccTransaction; +use SL::DB::Manager::AccTransaction; +use SL::Locale::String qw(t8); -use SL::DB::GLTransaction; +require SL::DB::GLTransaction; require SL::DB::Invoice; require SL::DB::PurchaseInvoice; @@ -31,9 +33,6 @@ __PACKAGE__->meta->add_relationship( __PACKAGE__->meta->initialize; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; - sub record { my ($self) = @_; @@ -47,17 +46,42 @@ sub record { }; -sub get_transaction { - my ($self) = @_; +sub get_type { + my $self = shift; + + my $ref = ref $self->record; + + return "ar" if $ref->isa('SL::DB::Invoice'); + return "ap" if $ref->isa('SL::DB::PurchaseInvoice'); + return "gl" if $ref->isa('SL::DB::GLTransaction'); + + die "Can't find trans_id " . $self->trans_id . " in ar, ap or gl" unless $ref; + +}; + +sub transaction_name { + my $self = shift; + + my $ref = ref $self->record; + my $name = "trans_id: " . $self->trans_id; + if ( $self->get_type eq 'ar' ) { + $name .= " (" . $self->record->abbreviation . " " . t8("AR") . ") " . t8("Invoice Number") . ": " . $self->record->invnumber; + } elsif ( $self->get_type eq 'ap' ) { + $name .= " (" . $self->record->abbreviation . " " . t8("AP") . ") " . t8("Invoice Number") . ": " . $self->record->invnumber; + } elsif ( $self->get_type eq 'gl' ) { + $name = "trans_id: " . $self->trans_id . " (" . $self->record->abbreviation . ") " . $self->record->reference . " - " . $self->record->description; + } else { + die "can't determine type of acc_trans line with trans_id " . $self->trans_id; + }; - my $transaction = SL::DB::Manager::GLTransaction->find_by(id => $self->trans_id); - $transaction = SL::DB::Manager::Invoice->find_by(id => $self->trans_id) if not defined $transaction; - $transaction = SL::DB::Manager::PurchaseInvoice->find_by(id => $self->trans_id) if not defined $transaction; + $name .= " " . t8("Date") . ": " . $self->transdate->to_kivitendo; - return $transaction; -} + return $name; + +}; 1; + __END__ =pod @@ -90,6 +114,22 @@ We use the Rose::DB::Object load function with the C parameter for each record type, which returns true if the load was successful, so we don't bother to check the ref of the object. +=item C + +Returns the type of transaction the acc_trans entry belongs to: ar, ap or gl. + +Example: + my $acc = SL::DB::Manager::AccTransaction->get_first(); + my $type = $acc->get_type; + +=item C + +Generate a meaningful transaction name for an acc_trans line from the +corresponding ar/ap/gl object, a combination of trans_id, +invnumber/description, abbreviation. Can be used for better error output of the +DATEV export and contains some database information, e.g. the trans_id, and is +a kind of displayable_name for debugging or in the console. + =back =head1 BUGS -- 2.20.1