Projekt

Allgemein

Profil

Herunterladen (5,47 KB) Statistiken
| Zweig: | Markierung: | Revision:
5b5dbec0 Moritz Bunkus
package SL::Presenter::Invoice;

use strict;

0e5e3501 Sven Schöling
use SL::Presenter::EscapedText qw(escape is_escaped);
ee51b82f Tamino Steinert
use SL::Presenter::Tag qw(link_tag);
5b5dbec0 Moritz Bunkus
use Exporter qw(import);
0e5e3501 Sven Schöling
our @EXPORT_OK = qw(invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
5b5dbec0 Moritz Bunkus
use Carp;

15f58ff3 Geoffrey Richardson
sub invoice {
0e5e3501 Sven Schöling
my ($invoice, %params) = @_;
15f58ff3 Geoffrey Richardson
if ( $invoice->is_sales ) {
if ( $invoice->invoice ) {
0e5e3501 Sven Schöling
return _is_ir_record($invoice, 'is', %params);
15f58ff3 Geoffrey Richardson
} else {
0e5e3501 Sven Schöling
return _is_ir_record($invoice, 'ar', %params);
15f58ff3 Geoffrey Richardson
}
} else {
if ( $invoice->invoice ) {
0e5e3501 Sven Schöling
return _is_ir_record($invoice, 'ir', %params);
15f58ff3 Geoffrey Richardson
} else {
0e5e3501 Sven Schöling
return _is_ir_record($invoice, 'ap', %params);
15f58ff3 Geoffrey Richardson
}
};
};

5b5dbec0 Moritz Bunkus
sub sales_invoice {
0e5e3501 Sven Schöling
my ($invoice, %params) = @_;
5b5dbec0 Moritz Bunkus
0e5e3501 Sven Schöling
_is_ir_record($invoice, 'is', %params);
5b5dbec0 Moritz Bunkus
}

sub ar_transaction {
0e5e3501 Sven Schöling
my ($invoice, %params) = @_;
5b5dbec0 Moritz Bunkus
0e5e3501 Sven Schöling
_is_ir_record($invoice, 'ar', %params);
5b5dbec0 Moritz Bunkus
}

sub purchase_invoice {
0e5e3501 Sven Schöling
my ($invoice, %params) = @_;
5b5dbec0 Moritz Bunkus
0e5e3501 Sven Schöling
_is_ir_record($invoice, 'ir', %params);
5b5dbec0 Moritz Bunkus
}

sub ap_transaction {
0e5e3501 Sven Schöling
my ($invoice, %params) = @_;
5b5dbec0 Moritz Bunkus
0e5e3501 Sven Schöling
_is_ir_record($invoice, 'ap', %params);
5b5dbec0 Moritz Bunkus
}

sub _is_ir_record {
0e5e3501 Sven Schöling
my ($invoice, $controller, %params) = @_;
5b5dbec0 Moritz Bunkus
$params{display} ||= 'inline';

croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;

ee51b82f Tamino Steinert
my $text = escape($invoice->invnumber);
if (! delete $params{no_link}) {
my $href = $controller . '.pl?action=edit&type=invoice'
. '&id=' . escape($invoice->id);
$text = link_tag($href, $text, %params);
}
0e5e3501 Sven Schöling
is_escaped($text);
5b5dbec0 Moritz Bunkus
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

SL::Presenter::Invoice - Presenter module for sales invoice, AR
transaction, purchase invoice and AP transaction Rose::DB objects

=head1 SYNOPSIS

# Sales invoices:
my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
0e5e3501 Sven Schöling
my $html = SL::Presenter::Invoice::sales_invoice($object, display => 'inline');
5b5dbec0 Moritz Bunkus
# AR transactions:
my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
0e5e3501 Sven Schöling
my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
5b5dbec0 Moritz Bunkus
# Purchase invoices:
my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
0e5e3501 Sven Schöling
my $html = SL::Presenter::Invoice::purchase_invoice($object, display => 'inline');
5b5dbec0 Moritz Bunkus
# AP transactions:
my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
0e5e3501 Sven Schöling
my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
5b5dbec0 Moritz Bunkus
15f58ff3 Geoffrey Richardson
# use with any of the above ar/ap/is/ir types:
0e5e3501 Sven Schöling
my $html = SL::Presenter::Invoice::invoice($object, display => 'inline');
15f58ff3 Geoffrey Richardson
5b5dbec0 Moritz Bunkus
=head1 FUNCTIONS

=over 4

15f58ff3 Geoffrey Richardson
=item C<invoice $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of an ar/ap/is/ir object C<$object> . Determines
which type (sales or purchase, invoice or not) the object is.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
15f58ff3 Geoffrey Richardson
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
15f58ff3 Geoffrey Richardson
=item * no_link

If falsish (the default) then the invoice number will be linked to the
"edit invoice" dialog from the sales menu.

=back

5b5dbec0 Moritz Bunkus
=item C<sales_invoice $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
5b5dbec0 Moritz Bunkus
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
5b5dbec0 Moritz Bunkus
=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<ar_transaction $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
5b5dbec0 Moritz Bunkus
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
5b5dbec0 Moritz Bunkus
=item * no_link

If falsish (the default) then the invoice number will be linked to the
"edit invoice" dialog from the general ledger menu.

=back

=item C<purchase_invoice $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of the purchase invoice object
C<$object>.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
5b5dbec0 Moritz Bunkus
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
5b5dbec0 Moritz Bunkus
=item * no_link

If falsish (the default) then the invoice number will be linked to
the "edit invoice" dialog from the purchase menu.

=back

=item C<ap_transaction $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
5b5dbec0 Moritz Bunkus
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
5b5dbec0 Moritz Bunkus
=item * no_link

If falsish (the default) then the invoice number will be linked to the
"edit invoice" dialog from the general ledger menu.

=back

=back

=head1 BUGS

Nothing here yet.

=head1 AUTHOR

Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>

=cut