1 package SL::Presenter::Invoice;
5 use SL::Presenter::EscapedText qw(escape is_escaped);
6 use SL::Presenter::Tag qw(link_tag);
8 use Exporter qw(import);
9 our @EXPORT_OK = qw(show invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
13 sub show {goto &invoice};
16 my ($invoice, %params) = @_;
18 if ( $invoice->is_sales ) {
19 if ( $invoice->invoice ) {
20 return _is_ir_record($invoice, 'is', %params);
22 return _is_ir_record($invoice, 'ar', %params);
25 if ( $invoice->invoice ) {
26 return _is_ir_record($invoice, 'ir', %params);
28 return _is_ir_record($invoice, 'ap', %params);
34 my ($invoice, %params) = @_;
36 _is_ir_record($invoice, 'is', %params);
40 my ($invoice, %params) = @_;
42 _is_ir_record($invoice, 'ar', %params);
45 sub purchase_invoice {
46 my ($invoice, %params) = @_;
48 _is_ir_record($invoice, 'ir', %params);
52 my ($invoice, %params) = @_;
54 _is_ir_record($invoice, 'ap', %params);
58 my ($invoice, $controller, %params) = @_;
60 $params{display} ||= 'inline';
62 croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
64 my $text = escape($invoice->invnumber);
65 if (! delete $params{no_link}) {
66 my $href = $controller . '.pl?action=edit&type=invoice'
67 . '&id=' . escape($invoice->id);
68 $text = link_tag($href, $text, %params);
84 SL::Presenter::Invoice - Presenter module for sales invoice, AR
85 transaction, purchase invoice and AP transaction Rose::DB objects
90 my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
91 my $html = SL::Presenter::Invoice::sales_invoice($object, display => 'inline');
94 my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
95 my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
98 my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
99 my $html = SL::Presenter::Invoice::purchase_invoice($object, display => 'inline');
102 my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
103 my $html = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
105 # use with any of the above ar/ap/is/ir types:
106 my $html = SL::Presenter::Invoice::invoice($object, display => 'inline');
107 my $html = $object->presenter->show();
113 =item C<show $object>
115 Alias for C<invoice $object %params>.
117 =item C<invoice $object, %params>
119 Returns a rendered version (actually an instance of
120 L<SL::Presenter::EscapedText>) of an ar/ap/is/ir object C<$object> . Determines
121 which type (sales or purchase, invoice or not) the object is.
123 Remaining C<%params> are passed to the function
124 C<SL::Presenter::Tag::link_tag>. It can include:
130 Either C<inline> (the default) or C<table-cell>. Is passed to the function
131 C<SL::Presenter::Tag::link_tag>.
135 If falsish (the default) then the invoice number will be linked to the
136 "edit invoice" dialog from the sales menu.
140 =item C<sales_invoice $object, %params>
142 Returns a rendered version (actually an instance of
143 L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
146 Remaining C<%params> are passed to the function
147 C<SL::Presenter::Tag::link_tag>. It can include:
153 Either C<inline> (the default) or C<table-cell>. Is passed to the function
154 C<SL::Presenter::Tag::link_tag>.
158 If falsish (the default) then the invoice number will be linked to the
159 "edit invoice" dialog from the sales menu.
163 =item C<ar_transaction $object, %params>
165 Returns a rendered version (actually an instance of
166 L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
169 Remaining C<%params> are passed to the function
170 C<SL::Presenter::Tag::link_tag>. It can include:
176 Either C<inline> (the default) or C<table-cell>. Is passed to the function
177 C<SL::Presenter::Tag::link_tag>.
181 If falsish (the default) then the invoice number will be linked to the
182 "edit invoice" dialog from the general ledger menu.
186 =item C<purchase_invoice $object, %params>
188 Returns a rendered version (actually an instance of
189 L<SL::Presenter::EscapedText>) of the purchase invoice object
192 Remaining C<%params> are passed to the function
193 C<SL::Presenter::Tag::link_tag>. It can include:
199 Either C<inline> (the default) or C<table-cell>. Is passed to the function
200 C<SL::Presenter::Tag::link_tag>.
204 If falsish (the default) then the invoice number will be linked to
205 the "edit invoice" dialog from the purchase menu.
209 =item C<ap_transaction $object, %params>
211 Returns a rendered version (actually an instance of
212 L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
215 Remaining C<%params> are passed to the function
216 C<SL::Presenter::Tag::link_tag>. It can include:
222 Either C<inline> (the default) or C<table-cell>. Is passed to the function
223 C<SL::Presenter::Tag::link_tag>.
227 If falsish (the default) then the invoice number will be linked to the
228 "edit invoice" dialog from the general ledger menu.
240 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>