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