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