c078450160c755440ac7185f362f977c396fa23c
[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(sales_invoice ar_transaction purchase_invoice ap_transaction);
9
10 use Carp;
11
12 sub sales_invoice {
13   my ($self, $invoice, %params) = @_;
14
15   return _is_ir_record($self, $invoice, 'is', %params);
16 }
17
18 sub ar_transaction {
19   my ($self, $invoice, %params) = @_;
20
21   return _is_ir_record($self, $invoice, 'ar', %params);
22 }
23
24 sub purchase_invoice {
25   my ($self, $invoice, %params) = @_;
26
27   return _is_ir_record($self, $invoice, 'ir', %params);
28 }
29
30 sub ap_transaction {
31   my ($self, $invoice, %params) = @_;
32
33   return _is_ir_record($self, $invoice, 'ap', %params);
34 }
35
36 sub _is_ir_record {
37   my ($self, $invoice, $controller, %params) = @_;
38
39   $params{display} ||= 'inline';
40
41   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
42
43   my $text = join '', (
44     $params{no_link} ? '' : '<a href="' . $controller . '.pl?action=edit&amp;type=invoice&amp;id=' . $self->escape($invoice->id) . '">',
45     $self->escape($invoice->invnumber),
46     $params{no_link} ? '' : '</a>',
47   );
48   return $self->escaped_text($text);
49 }
50
51 1;
52
53 __END__
54
55 =pod
56
57 =encoding utf8
58
59 =head1 NAME
60
61 SL::Presenter::Invoice - Presenter module for sales invoice, AR
62 transaction, purchase invoice and AP transaction Rose::DB objects
63
64 =head1 SYNOPSIS
65
66   # Sales invoices:
67   my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
68   my $html   = SL::Presenter->get->sales_invoice($object, display => 'inline');
69
70   # AR transactions:
71   my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
72   my $html   = SL::Presenter->get->ar_transaction($object, display => 'inline');
73
74   # Purchase invoices:
75   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
76   my $html   = SL::Presenter->get->purchase_invoice($object, display => 'inline');
77
78   # AP transactions:
79   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
80   my $html   = SL::Presenter->get->ar_transaction($object, display => 'inline');
81
82 =head1 FUNCTIONS
83
84 =over 4
85
86 =item C<sales_invoice $object, %params>
87
88 Returns a rendered version (actually an instance of
89 L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
90 .
91
92 C<%params> can include:
93
94 =over 2
95
96 =item * display
97
98 Either C<inline> (the default) or C<table-cell>. At the moment both
99 representations are identical and produce the invoice number linked
100 to the corresponding 'edit' action.
101
102 =item * no_link
103
104 If falsish (the default) then the invoice number will be linked to the
105 "edit invoice" dialog from the sales menu.
106
107 =back
108
109 =item C<ar_transaction $object, %params>
110
111 Returns a rendered version (actually an instance of
112 L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
113 .
114
115 C<%params> can include:
116
117 =over 2
118
119 =item * display
120
121 Either C<inline> (the default) or C<table-cell>. At the moment both
122 representations are identical and produce the invoice number linked
123 to the corresponding 'edit' action.
124
125 =item * no_link
126
127 If falsish (the default) then the invoice number will be linked to the
128 "edit invoice" dialog from the general ledger menu.
129
130 =back
131
132 =item C<purchase_invoice $object, %params>
133
134 Returns a rendered version (actually an instance of
135 L<SL::Presenter::EscapedText>) of the purchase invoice object
136 C<$object>.
137
138 C<%params> can include:
139
140 =over 2
141
142 =item * display
143
144 Either C<inline> (the default) or C<table-cell>. At the moment both
145 representations are identical and produce the invoice number name
146 linked to the corresponding 'edit' action.
147
148 =item * no_link
149
150 If falsish (the default) then the invoice number will be linked to
151 the "edit invoice" dialog from the purchase menu.
152
153 =back
154
155 =item C<ap_transaction $object, %params>
156
157 Returns a rendered version (actually an instance of
158 L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
159 .
160
161 C<%params> can include:
162
163 =over 2
164
165 =item * display
166
167 Either C<inline> (the default) or C<table-cell>. At the moment both
168 representations are identical and produce the invoice number linked
169 to the corresponding 'edit' action.
170
171 =item * no_link
172
173 If falsish (the default) then the invoice number will be linked to the
174 "edit invoice" dialog from the general ledger menu.
175
176 =back
177
178 =back
179
180 =head1 BUGS
181
182 Nothing here yet.
183
184 =head1 AUTHOR
185
186 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
187
188 =cut