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