X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FPresenter%2FInvoice.pm;h=ba662edc27663ec803a9bebb517d4190ff1c4700;hb=5474d397bbc42ffaea0b51ebb4bb9a4c7afaa881;hp=b18c064b761071547074520ba4428637768f2671;hpb=6a12a968761127af91e9da8db7579be2836bcaaa;p=kivitendo-erp.git diff --git a/SL/Presenter/Invoice.pm b/SL/Presenter/Invoice.pm index b18c064b7..ba662edc2 100644 --- a/SL/Presenter/Invoice.pm +++ b/SL/Presenter/Invoice.pm @@ -2,56 +2,69 @@ package SL::Presenter::Invoice; use strict; -use parent qw(Exporter); +use SL::Presenter::EscapedText qw(escape is_escaped); use Exporter qw(import); -our @EXPORT = qw(sales_invoice ar_transaction purchase_invoice ap_transaction gl_transaction); +our @EXPORT_OK = qw(invoice sales_invoice ar_transaction purchase_invoice ap_transaction); use Carp; +sub invoice { + my ($invoice, %params) = @_; + + if ( $invoice->is_sales ) { + if ( $invoice->invoice ) { + return _is_ir_record($invoice, 'is', %params); + } else { + return _is_ir_record($invoice, 'ar', %params); + } + } else { + if ( $invoice->invoice ) { + return _is_ir_record($invoice, 'ir', %params); + } else { + return _is_ir_record($invoice, 'ap', %params); + } + }; +}; + sub sales_invoice { - my ($self, $invoice, %params) = @_; + my ($invoice, %params) = @_; - return _is_ir_record($self, $invoice, 'is', %params); + _is_ir_record($invoice, 'is', %params); } sub ar_transaction { - my ($self, $invoice, %params) = @_; + my ($invoice, %params) = @_; - return _is_ir_record($self, $invoice, 'ar', %params); + _is_ir_record($invoice, 'ar', %params); } sub purchase_invoice { - my ($self, $invoice, %params) = @_; + my ($invoice, %params) = @_; - return _is_ir_record($self, $invoice, 'ir', %params); + _is_ir_record($invoice, 'ir', %params); } sub ap_transaction { - my ($self, $invoice, %params) = @_; - - return _is_ir_record($self, $invoice, 'ap', %params); -} - -sub gl_transaction { - my ($self, $invoice, %params) = @_; + my ($invoice, %params) = @_; - return _is_ir_record($self, $invoice, 'gl', %params); + _is_ir_record($invoice, 'ap', %params); } sub _is_ir_record { - my ($self, $invoice, $controller, %params) = @_; + my ($invoice, $controller, %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($invoice->invnumber), + $params{no_link} ? '' : '', + escape($invoice->invnumber), $params{no_link} ? '' : '', ); - return $self->escaped_text($text); + + is_escaped($text); } 1; @@ -71,24 +84,50 @@ transaction, purchase invoice and AP transaction Rose::DB objects # Sales invoices: my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]); - my $html = SL::Presenter->get->sales_invoice($object, display => 'inline'); + my $html = SL::Presenter::Invoice::sales_invoice($object, display => 'inline'); # AR transactions: my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]); - my $html = SL::Presenter->get->ar_transaction($object, display => 'inline'); + my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline'); # Purchase invoices: my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]); - my $html = SL::Presenter->get->purchase_invoice($object, display => 'inline'); + my $html = SL::Presenter::Invoice::purchase_invoice($object, display => 'inline'); # AP transactions: my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]); - my $html = SL::Presenter->get->ar_transaction($object, display => 'inline'); + my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline'); + + # use with any of the above ar/ap/is/ir types: + my $html = SL::Presenter::Invoice::invoice($object, display => 'inline'); =head1 FUNCTIONS =over 4 +=item C + +Returns a rendered version (actually an instance of +L) of an ar/ap/is/ir object C<$object> . Determines +which type (sales or purchase, invoice or not) the object is. + +C<%params> can include: + +=over 2 + +=item * display + +Either C (the default) or C. At the moment both +representations are identical and produce the invoice number linked +to the corresponding 'edit' action. + +=item * no_link + +If falsish (the default) then the invoice number will be linked to the +"edit invoice" dialog from the sales menu. + +=back + =item C Returns a rendered version (actually an instance of