]> wagnertech.de Git - mfinanz.git/blob - SL/Presenter/Invoice.pm
restart apache2 in postinst
[mfinanz.git] / SL / Presenter / Invoice.pm
1 package SL::Presenter::Invoice;
2
3 use strict;
4
5 use SL::Presenter::EscapedText qw(escape is_escaped);
6 use SL::Presenter::Tag         qw(link_tag);
7
8 use Exporter qw(import);
9 our @EXPORT_OK = qw(show invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
10
11 use Carp;
12
13 sub show {goto &invoice};
14
15 sub invoice {
16   my ($invoice, %params) = @_;
17
18   if ( $invoice->is_sales ) {
19     if ( $invoice->invoice ) {
20       return _is_ir_record($invoice, 'is', %params);
21     } else {
22       return _is_ir_record($invoice, 'ar', %params);
23     }
24   } else {
25     if ( $invoice->invoice ) {
26       return _is_ir_record($invoice, 'ir', %params);
27     } else {
28       return _is_ir_record($invoice, 'ap', %params);
29     }
30   };
31 };
32
33 sub sales_invoice {
34   my ($invoice, %params) = @_;
35
36   _is_ir_record($invoice, 'is', %params);
37 }
38
39 sub ar_transaction {
40   my ($invoice, %params) = @_;
41
42   _is_ir_record($invoice, 'ar', %params);
43 }
44
45 sub purchase_invoice {
46   my ($invoice, %params) = @_;
47
48   _is_ir_record($invoice, 'ir', %params);
49 }
50
51 sub ap_transaction {
52   my ($invoice, %params) = @_;
53
54   _is_ir_record($invoice, 'ap', %params);
55 }
56
57 sub _is_ir_record {
58   my ($invoice, $controller, %params) = @_;
59
60   $params{display} ||= 'inline';
61
62   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
63
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);
69   }
70
71   is_escaped($text);
72 }
73
74 1;
75
76 __END__
77
78 =pod
79
80 =encoding utf8
81
82 =head1 NAME
83
84 SL::Presenter::Invoice - Presenter module for sales invoice, AR
85 transaction, purchase invoice and AP transaction Rose::DB objects
86
87 =head1 SYNOPSIS
88
89   # Sales invoices:
90   my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
91   my $html   = SL::Presenter::Invoice::sales_invoice($object, display => 'inline');
92
93   # AR transactions:
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');
96
97   # Purchase invoices:
98   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
99   my $html   = SL::Presenter::Invoice::purchase_invoice($object, display => 'inline');
100
101   # AP transactions:
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');
104
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();
108
109 =head1 FUNCTIONS
110
111 =over 4
112
113 =item C<show $object>
114
115 Alias for C<invoice $object %params>.
116
117 =item C<invoice $object, %params>
118
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.
122
123 Remaining C<%params> are passed to the function
124 C<SL::Presenter::Tag::link_tag>. It can include:
125
126 =over 2
127
128 =item * display
129
130 Either C<inline> (the default) or C<table-cell>. Is passed to the function
131 C<SL::Presenter::Tag::link_tag>.
132
133 =item * no_link
134
135 If falsish (the default) then the invoice number will be linked to the
136 "edit invoice" dialog from the sales menu.
137
138 =back
139
140 =item C<sales_invoice $object, %params>
141
142 Returns a rendered version (actually an instance of
143 L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
144 .
145
146 Remaining C<%params> are passed to the function
147 C<SL::Presenter::Tag::link_tag>. It can include:
148
149 =over 2
150
151 =item * display
152
153 Either C<inline> (the default) or C<table-cell>. Is passed to the function
154 C<SL::Presenter::Tag::link_tag>.
155
156 =item * no_link
157
158 If falsish (the default) then the invoice number will be linked to the
159 "edit invoice" dialog from the sales menu.
160
161 =back
162
163 =item C<ar_transaction $object, %params>
164
165 Returns a rendered version (actually an instance of
166 L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
167 .
168
169 Remaining C<%params> are passed to the function
170 C<SL::Presenter::Tag::link_tag>. It can include:
171
172 =over 2
173
174 =item * display
175
176 Either C<inline> (the default) or C<table-cell>. Is passed to the function
177 C<SL::Presenter::Tag::link_tag>.
178
179 =item * no_link
180
181 If falsish (the default) then the invoice number will be linked to the
182 "edit invoice" dialog from the general ledger menu.
183
184 =back
185
186 =item C<purchase_invoice $object, %params>
187
188 Returns a rendered version (actually an instance of
189 L<SL::Presenter::EscapedText>) of the purchase invoice object
190 C<$object>.
191
192 Remaining C<%params> are passed to the function
193 C<SL::Presenter::Tag::link_tag>. It can include:
194
195 =over 2
196
197 =item * display
198
199 Either C<inline> (the default) or C<table-cell>. Is passed to the function
200 C<SL::Presenter::Tag::link_tag>.
201
202 =item * no_link
203
204 If falsish (the default) then the invoice number will be linked to
205 the "edit invoice" dialog from the purchase menu.
206
207 =back
208
209 =item C<ap_transaction $object, %params>
210
211 Returns a rendered version (actually an instance of
212 L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
213 .
214
215 Remaining C<%params> are passed to the function
216 C<SL::Presenter::Tag::link_tag>. It can include:
217
218 =over 2
219
220 =item * display
221
222 Either C<inline> (the default) or C<table-cell>. Is passed to the function
223 C<SL::Presenter::Tag::link_tag>.
224
225 =item * no_link
226
227 If falsish (the default) then the invoice number will be linked to the
228 "edit invoice" dialog from the general ledger menu.
229
230 =back
231
232 =back
233
234 =head1 BUGS
235
236 Nothing here yet.
237
238 =head1 AUTHOR
239
240 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
241
242 =cut