Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5b5dbec0

Von Moritz Bunkus vor fast 12 Jahren hinzugefügt

  • ID 5b5dbec0272c91697acf33c4842ee9d63f041f22
  • Vorgänger d4458803
  • Nachfolger 804e16d1

Presenter-Module für Listen von Verkaufs-/Einkaufsobjekte

Unterschiede anzeigen:

SL/Presenter/CustomerVendor.pm
1
package SL::Presenter::CustomerVendor;
2

  
3
use strict;
4

  
5
use parent qw(Exporter);
6

  
7
use Exporter qw(import);
8
our @EXPORT = qw(customer vendor);
9

  
10
use Carp;
11

  
12
sub customer {
13
  my ($self, $customer, $type, %params) = @_;
14
  return _customer_vendor($self, $customer, 'customer', %params);
15
}
16

  
17
sub vendor {
18
  my ($self, $vendor, $type, %params) = @_;
19
  return _customer_vendor($self, $vendor, 'vendor', %params);
20
}
21

  
22
sub _customer_vendor {
23
  my ($self, $cv, $type, %params) = @_;
24

  
25
  $params{display} ||= 'inline';
26

  
27
  croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
28

  
29
  my $text = join '', (
30
    $params{no_link} ? '' : '<a href="ct.pl?action=edit&amp;db=' . $type . '&amp;id=' . $self->escape($cv->id) . '">',
31
    $self->escape($cv->name),
32
    $params{no_link} ? '' : '</a>',
33
  );
34
  return $self->escaped_text($text);
35
}
36

  
37
1;
38

  
39
__END__
40

  
41
=pod
42

  
43
=encoding utf8
44

  
45
=head1 NAME
46

  
47
SL::Presenter::CustomerVendor - Presenter module for customer and
48
vendor Rose::DB objects
49

  
50
=head1 SYNOPSIS
51

  
52
  # Customers:
53
  my $customer = SL::DB::Manager::Customer->get_first;
54
  my $html     = SL::Presenter->get->customer($customer, display => 'inline');
55

  
56
  # Vendors:
57
  my $vendor = SL::DB::Manager::Vendor->get_first;
58
  my $html   = SL::Presenter->get->vendor($customer, display => 'inline');
59

  
60
=head1 FUNCTIONS
61

  
62
=over 4
63

  
64
=item C<customer $object, %params>
65

  
66
Returns a rendered version (actually an instance of
67
L<SL::Presenter::EscapedText>) of the customer object C<$object>.
68

  
69
C<%params> can include:
70

  
71
=over 2
72

  
73
=item * display
74

  
75
Either C<inline> (the default) or C<table-cell>. At the moment both
76
representations are identical and produce the customer's name linked
77
to the corresponding 'edit' action.
78

  
79
=item * no_link
80

  
81
If falsish (the default) then the customer's name will be linked to
82
the "edit customer" dialog from the master data menu.
83

  
84
=back
85

  
86
=item C<vendor $object, %params>
87

  
88
Returns a rendered version (actually an instance of
89
L<SL::Presenter::EscapedText>) of the vendor object C<$object>.
90

  
91
C<%params> can include:
92

  
93
=over 2
94

  
95
=item * display
96

  
97
Either C<inline> (the default) or C<table-cell>. At the moment both
98
representations are identical and produce the vendor's name linked
99
to the corresponding 'edit' action.
100

  
101
=item * no_link
102

  
103
If falsish (the default) then the vendor's name will be linked to
104
the "edit vendor" dialog from the master data menu.
105

  
106
=back
107

  
108
=back
109

  
110
=head1 BUGS
111

  
112
Nothing here yet.
113

  
114
=head1 AUTHOR
115

  
116
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
117

  
118
=cut
SL/Presenter/DeliveryOrder.pm
1
package SL::Presenter::DeliveryOrder;
2

  
3
use strict;
4

  
5
use parent qw(Exporter);
6

  
7
use Exporter qw(import);
8
our @EXPORT = qw(sales_delivery_order purchase_delivery_order);
9

  
10
use Carp;
11

  
12
sub sales_delivery_order {
13
  my ($self, $delivery_order, %params) = @_;
14

  
15
  return _do_record($self, $delivery_order, 'sales_delivery_order', %params);
16
}
17

  
18
sub purchase_delivery_order {
19
  my ($self, $delivery_order, %params) = @_;
20

  
21
  return _do_record($self, $delivery_order, 'purchase_delivery_order', %params);
22
}
23

  
24
sub _do_record {
25
  my ($self, $delivery_order, $type, %params) = @_;
26

  
27
  $params{display} ||= 'inline';
28

  
29
  croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
30

  
31
  my $text = join '', (
32
    $params{no_link} ? '' : '<a href="do.pl?action=edit&amp;type=' . $type . '&amp;id=' . $self->escape($delivery_order->id) . '">',
33
    $self->escape($delivery_order->donumber),
34
    $params{no_link} ? '' : '</a>',
35
  );
36
  return $self->escaped_text($text);
37
}
38

  
39
1;
40

  
41
__END__
42

  
43
=pod
44

  
45
=encoding utf8
46

  
47
=head1 NAME
48

  
49
SL::Presenter::DeliveryOrder - Presenter module for Rose::DB objects
50
for sales and purchase delivery orders
51

  
52
=head1 SYNOPSIS
53

  
54
  # Sales delivery orders:
55
  my $object = SL::DB::Manager::DeliveryOrder->get_first(where => [ is_sales => 1 ]);
56
  my $html   = SL::Presenter->get->sales_delivery_order($object, display => 'inline');
57

  
58
  # Purchase delivery orders:
59
  my $object = SL::DB::Manager::DeliveryOrder->get_first(where => [ or => [ is_sales => undef, is_sales => 0 ]]);
60
  my $html   = SL::Presenter->get->purchase_delivery_order($object, display => 'inline');
61

  
62
=head1 FUNCTIONS
63

  
64
=over 4
65

  
66
=item C<sales_delivery_order $object, %params>
67

  
68
Returns a rendered version (actually an instance of
69
L<SL::Presenter::EscapedText>) of the sales delivery order object
70
C<$object>.
71

  
72
C<%params> can include:
73

  
74
=over 2
75

  
76
=item * display
77

  
78
Either C<inline> (the default) or C<table-cell>. At the moment both
79
representations are identical and produce the objects's delivery
80
order number linked to the corresponding 'edit' action.
81

  
82
=item * no_link
83

  
84
If falsish (the default) then the delivery order number will be linked
85
to the "edit delivery order" dialog from the sales menu.
86

  
87
=back
88

  
89
=item C<purchase_delivery_order $object, %params>
90

  
91
Returns a rendered version (actually an instance of
92
L<SL::Presenter::EscapedText>) of the purchase delivery order object
93
C<$object>.
94

  
95
C<%params> can include:
96

  
97
=over 2
98

  
99
=item * display
100

  
101
Either C<inline> (the default) or C<table-cell>. At the moment both
102
representations are identical and produce the objects's delivery
103
order number linked to the corresponding 'edit' action.
104

  
105
=item * no_link
106

  
107
If falsish (the default) then the delivery order number will be linked
108
to the "edit delivery order" dialog from the purchase menu.
109

  
110
=back
111

  
112
=back
113

  
114
=head1 BUGS
115

  
116
Nothing here yet.
117

  
118
=head1 AUTHOR
119

  
120
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
121

  
122
=cut
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, 'is', %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
SL/Presenter/Order.pm
1
package SL::Presenter::Order;
2

  
3
use strict;
4

  
5
use parent qw(Exporter);
6

  
7
use Exporter qw(import);
8
our @EXPORT = qw(sales_quotation sales_order request_quotation purchase_order);
9

  
10
use Carp;
11

  
12
sub sales_quotation {
13
  my ($self, $order, %params) = @_;
14

  
15
  return _oe_record($self, $order, 'sales_quotation', %params);
16
}
17

  
18
sub sales_order {
19
  my ($self, $order, %params) = @_;
20

  
21
  return _oe_record($self, $order, 'sales_order', %params);
22
}
23

  
24
sub request_quotation {
25
  my ($self, $order, %params) = @_;
26

  
27
  return _oe_record($self, $order, 'request_quotation', %params);
28
}
29

  
30
sub purchase_order {
31
  my ($self, $order, %params) = @_;
32

  
33
  return _oe_record($self, $order, 'purchase_order', %params);
34
}
35

  
36
sub _oe_record {
37
  my ($self, $order, $type, %params) = @_;
38

  
39
  $params{display} ||= 'inline';
40

  
41
  croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
42

  
43
  my $number_method = $order->quotation ? 'quonumber' : 'ordnumber';
44

  
45
  my $text = join '', (
46
    $params{no_link} ? '' : '<a href="oe.pl?action=edit&amp;type=' . $type . '&amp;id=' . $self->escape($order->id) . '">',
47
    $self->escape($order->$number_method),
48
    $params{no_link} ? '' : '</a>',
49
  );
50
  return $self->escaped_text($text);
51
}
52

  
53
1;
54

  
55

  
56
__END__
57

  
58
=pod
59

  
60
=encoding utf8
61

  
62
=head1 NAME
63

  
64
SL::Presenter::Order - Presenter module for Rose::DB objects for sales
65
quotations, sales orders, requests for quotations and purchase orders
66

  
67
=head1 SYNOPSIS
68

  
69
  # Sales quotations:
70
  my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_quotation') ]);
71
  my $html   = SL::Presenter->get->sales_quotation($object, display => 'inline');
72

  
73
  # Sales orders:
74
  my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_order') ]);
75
  my $html   = SL::Presenter->get->sales_order($object, display => 'inline');
76

  
77
  # Requests for quotations:
78
  my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('request_quotation') ]);
79
  my $html   = SL::Presenter->get->request_quotation($object, display => 'inline');
80

  
81
  # Purchase orders:
82
  my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('purchase_order') ]);
83
  my $html   = SL::Presenter->get->purchase_order($object, display => 'inline');
84

  
85
=head1 FUNCTIONS
86

  
87
=over 4
88

  
89
=item C<sales_quotation $object, %params>
90

  
91
Returns a rendered version (actually an instance of
92
L<SL::Presenter::EscapedText>) of the sales quotation object
93
C<$object>.
94

  
95
C<%params> can include:
96

  
97
=over 2
98

  
99
=item * display
100

  
101
Either C<inline> (the default) or C<table-cell>. At the moment both
102
representations are identical and produce the objects's
103
quotation number linked to the corresponding 'edit' action.
104

  
105
=item * no_link
106

  
107
If falsish (the default) then the order number will be linked to the
108
"edit quotation" dialog from the sales menu.
109

  
110
=back
111

  
112
=item C<sales_order $object, %params>
113

  
114
Returns a rendered version (actually an instance of
115
L<SL::Presenter::EscapedText>) of the sales order object C<$object>.
116

  
117
C<%params> can include:
118

  
119
=over 2
120

  
121
=item * display
122

  
123
Either C<inline> (the default) or C<table-cell>. At the moment both
124
representations are identical and produce the objects's
125
order number linked to the corresponding 'edit' action.
126

  
127
=item * no_link
128

  
129
If falsish (the default) then the  order number will be linked
130
to the "edit order" dialog from the sales menu.
131

  
132
=back
133

  
134
=item C<request_quotation $object, %params>
135

  
136
Returns a rendered version (actually an instance of
137
L<SL::Presenter::EscapedText>) of the request for quotation object
138
C<$object>.
139

  
140
C<%params> can include:
141

  
142
=over 2
143

  
144
=item * display
145

  
146
Either C<inline> (the default) or C<table-cell>. At the moment both
147
representations are identical and produce the objects's
148
quotation number linked to the corresponding 'edit' action.
149

  
150
=item * no_link
151

  
152
If falsish (the default) then the order number will be linked to the
153
"edit request for quotation" dialog from the purchase menu.
154

  
155
=back
156

  
157
=item C<purchase_order $object, %params>
158

  
159
Returns a rendered version (actually an instance of
160
L<SL::Presenter::EscapedText>) of the purchase order object
161
C<$object>.
162

  
163
C<%params> can include:
164

  
165
=over 2
166

  
167
=item * display
168

  
169
Either C<inline> (the default) or C<table-cell>. At the moment both
170
representations are identical and produce the objects's
171
order number linked to the corresponding 'edit' action.
172

  
173
=item * no_link
174

  
175
If falsish (the default) then the  order number will be linked
176
to the "edit order" dialog from the purchase menu.
177

  
178
=back
179

  
180
=back
181

  
182
=head1 BUGS
183

  
184
Nothing here yet.
185

  
186
=head1 AUTHOR
187

  
188
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
189

  
190
=cut
SL/Presenter/Project.pm
1
package SL::Presenter::Project;
2

  
3
use strict;
4

  
5
use parent qw(Exporter);
6

  
7
use Exporter qw(import);
8
our @EXPORT = qw(project);
9

  
10
use Carp;
11

  
12
sub project {
13
  my ($self, $project, %params) = @_;
14

  
15
  return '' unless $project;
16

  
17
  $params{display} ||= 'inline';
18

  
19
  croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
20

  
21
  $params{style} ||= 'both';
22
  my $description;
23

  
24
  if ($params{style} =~ m/number/) {
25
    $description = $project->projectnumber;
26

  
27
  } elsif ($params{style} =~ m/description/) {
28
    $description = $project->description;
29

  
30
  } else {
31
    $description = $project->projectnumber;
32
    if ($project->description && do { my $desc = quotemeta $project->description; $project->projectnumber !~ m/$desc/ }) {
33
      $description .= ' (' . $project->description . ')';
34
    }
35
  }
36

  
37
  my $text = join '', (
38
    $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . $self->escape($project->id) . '">',
39
    $self->escape($description),
40
    $params{no_link} ? '' : '</a>',
41
  );
42
  return $self->escaped_text($text);
43
}
44

  
45
1;
46

  
47
__END__
48

  
49
=pod
50

  
51
=encoding utf8
52

  
53
=head1 NAME
54

  
55
SL::Presenter::Project - Presenter module for project Rose::DB objects
56

  
57
=head1 SYNOPSIS
58

  
59
  my $project = SL::DB::Manager::Project->get_first;
60
  my $html    = SL::Presenter->get->project($project, display => 'inline');
61

  
62
=head1 FUNCTIONS
63

  
64
=over 4
65

  
66
=item C<project $object, %params>
67

  
68
Returns a rendered version (actually an instance of
69
L<SL::Presenter::EscapedText>) of the project object C<$customer>.
70

  
71
C<%params> can include:
72

  
73
=over 2
74

  
75
=item * display
76

  
77
Either C<inline> (the default) or C<table-cell>. At the moment both
78
representations are identical and produce the project's description
79
(controlled by the C<style> parameter) linked to the corresponding
80
'edit' action.
81

  
82
=item * style
83

  
84
Determines what exactly will be output. Can be one of the values with
85
C<both> being the default if it is missing:
86

  
87
=over 2
88

  
89
=item C<projectnumber> (or simply C<number>)
90

  
91
Outputs only the project's number.
92

  
93
=item C<projectdescription> (or simply C<description>)
94

  
95
Outputs only the project's description.
96

  
97
=item C<both>
98

  
99
Outputs the project's number followed by its description in
100
parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
101
description is already part of the project's number then it will not
102
be appended.
103

  
104
=back
105

  
106
=item * no_link
107

  
108
If falsish (the default) then the project's description will be linked to
109
the "edit project" dialog from the master data menu.
110

  
111
=back
112

  
113
=back
114

  
115
=head1 BUGS
116

  
117
Nothing here yet.
118

  
119
=head1 AUTHOR
120

  
121
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
122

  
123
=cut
SL/Presenter/Record.pm
1
package SL::Presenter::Record;
2

  
3
use strict;
4

  
5
use parent qw(Exporter);
6

  
7
use Exporter qw(import);
8
our @EXPORT = qw(grouped_record_list empty_record_list record_list);
9

  
10
use Carp;
11
use List::Util qw(first);
12

  
13
sub grouped_record_list {
14
  my ($self, $list, %params) = @_;
15

  
16
  my %groups = _group_records($list);
17
  my $output = '';
18

  
19
  $output .= _sales_quotation_list(        $self, $groups{sales_quotations})         if $groups{sales_quotations};
20
  $output .= _sales_order_list(            $self, $groups{sales_orders})             if $groups{sales_orders};
21
  $output .= _sales_delivery_order_list(   $self, $groups{sales_delivery_orders})    if $groups{sales_delivery_orders};
22
  $output .= _sales_invoice_list(          $self, $groups{sales_invoices})           if $groups{sales_invoices};
23
  $output .= _ar_transaction_list(         $self, $groups{ar_transactions})          if $groups{ar_transactions};
24

  
25
  $output .= _request_quotation_list(      $self, $groups{purchase_quotations})      if $groups{purchase_quotations};
26
  $output .= _purchase_order_list(         $self, $groups{purchase_orders})          if $groups{purchase_orders};
27
  $output .= _purchase_delivery_order_list($self, $groups{purchase_delivery_orders}) if $groups{purchase_delivery_orders};
28
  $output .= _purchase_invoice_list(       $self, $groups{purchase_invoices})        if $groups{purchase_invoices};
29
  $output .= _ar_transaction_list(         $self, $groups{ar_transactions})          if $groups{ar_transactions};
30

  
31
  return $output || $self->empty_record_list;
32
}
33

  
34
sub empty_record_list {
35
  my ($self) = @_;
36
  return $self->render('presenter/record/empty_record_list');
37
}
38

  
39
sub record_list {
40
  my ($self, $list, %params) = @_;
41

  
42
  my @columns;
43

  
44
  if (ref($params{columns}) eq 'ARRAY') {
45
    @columns = map {
46
      if (ref($_) eq 'ARRAY') {
47
        { title => $_->[0], data => $_->[1], link => $_->[2] }
48
      } else {
49
        $_;
50
      }
51
    } @{ delete $params{columns} };
52

  
53
  } else {
54
    croak "Wrong type for 'columns' argument: not an array reference";
55
  }
56

  
57
  my %column_meta   = map { $_->name => $_ } @{ $list->[0]->meta->columns       };
58
  my %relationships = map { $_->name => $_ } @{ $list->[0]->meta->relationships };
59

  
60
  my $call = sub {
61
    my ($obj, $method, @args) = @_;
62
    $obj->$method(@args);
63
  };
64

  
65
  my @data;
66
  foreach my $obj (@{ $list }) {
67
    my @row;
68

  
69
    foreach my $spec (@columns) {
70
      my %cell;
71

  
72
      my $method       =  $spec->{column} || $spec->{data};
73
      my $meta         =  $column_meta{ $spec->{data} };
74
      my $type         =  lc ref $meta;
75
      $type            =~ s/.*:://;
76
      my $relationship =  $relationships{ $spec->{data} };
77
      my $rel_type     =  !$relationship ? '' : lc $relationship->class;
78
      $rel_type        =~ s/.*:://;
79

  
80
      if (ref($spec->{data}) eq 'CODE') {
81
        $cell{value} = $spec->{data}->($obj);
82

  
83
      } else {
84
        $cell{value} = $rel_type eq 'customer'        ? $self->customer($obj->$method, display => 'table-cell')
85
                     : $rel_type eq 'vendor'          ? $self->vendor(  $obj->$method, display => 'table-cell')
86
                     : $rel_type eq 'project'         ? $self->project( $obj->$method, display => 'table-cell')
87
                     : $type eq 'date'                ? $call->($obj, $method . '_as_date')
88
                     : $type =~ m/float|numeric|real/ ? $::form->format_amount(\%::myconfig, $call->($obj, $method), 2)
89
                     : $type eq 'boolean'             ? $call->($obj, $method . '_as_bool_yn')
90
                     : $type =~ m/int|serial/         ? $spec->{data} * 1
91
                     :                                  $call->($obj, $method);
92
      }
93

  
94
      $cell{alignment} = 'right' if $type =~ m/int|serial|float|real|numeric/;
95

  
96
      push @row, \%cell;
97
    }
98

  
99
    push @data, \@row;
100
  }
101

  
102
  my @header =
103
    map +{ value     => $columns[$_]->{title},
104
           alignment => $data[0]->[$_]->{alignment},
105
         }, (0..scalar(@columns) - 1);
106

  
107
  return $self->render(
108
    'presenter/record/record_list',
109
    %params,
110
    TABLE_HEADER => \@header,
111
    TABLE_ROWS   => \@data,
112
  );
113
}
114

  
115
#
116
# private methods
117
#
118

  
119
sub _group_records {
120
  my ($list) = @_;
121

  
122
  my %matchers = (
123
    sales_quotations         => sub { (ref($_[0]) eq 'SL::DB::Order')           &&  $_[0]->is_type('sales_quotation')   },
124
    sales_orders             => sub { (ref($_[0]) eq 'SL::DB::Order')           &&  $_[0]->is_type('sales_order')       },
125
    sales_delivery_orders    => sub { (ref($_[0]) eq 'SL::DB::DeliveryOrder')   &&  $_[0]->is_sales                     },
126
    sales_invoices           => sub { (ref($_[0]) eq 'SL::DB::Invoice')         &&  $_[0]->invoice                      },
127
    ar_transactions          => sub { (ref($_[0]) eq 'SL::DB::Invoice')         && !$_[0]->invoice                      },
128
    purchase_quotations      => sub { (ref($_[0]) eq 'SL::DB::Order')           &&  $_[0]->is_type('request_quotation') },
129
    purchase_orders          => sub { (ref($_[0]) eq 'SL::DB::Order')           &&  $_[0]->is_type('purchase_order')    },
130
    purchase_delivery_orders => sub { (ref($_[0]) eq 'SL::DB::DeliveryOrder')   && !$_[0]->is_sales                     },
131
    purchase_invoices        => sub { (ref($_[0]) eq 'SL::DB::PurchaseInvoice') &&  $_[0]->invoice                      },
132
    ap_transactions          => sub { (ref($_[0]) eq 'SL::DB::PurchaseInvoice') && !$_[0]->invoice                      },
133
  );
134

  
135
  my %groups;
136

  
137
  foreach my $record (@{ $list || [] }) {
138
    my $type         = (first { $matchers{$_}->($record) } keys %matchers) || 'other';
139
    $groups{$type} ||= [];
140
    push @{ $groups{$type} }, $record;
141
  }
142

  
143
  return %groups;
144
}
145

  
146
sub _sales_quotation_list {
147
  my ($self, $list) = @_;
148

  
149
  return $self->record_list(
150
    $list,
151
    title   => $::locale->text('Sales Quotations'),
152
    columns => [
153
      [ $::locale->text('Quotation Date'),          'transdate'                                                                ],
154
      [ $::locale->text('Quotation Number'),        sub { $self->sales_quotation($_[0], display => 'table-cell') }   ],
155
      [ $::locale->text('Customer'),                'customer'                                                                 ],
156
      [ $::locale->text('Net amount'),              'netamount'                                                                ],
157
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
158
      [ $::locale->text('Project'),                 'globalproject', ],
159
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
160
    ],
161
  );
162
}
163

  
164
sub _request_quotation_list {
165
  my ($self, $list) = @_;
166

  
167
  return $self->record_list(
168
    $list,
169
    title   => $::locale->text('Request Quotations'),
170
    columns => [
171
      [ $::locale->text('Quotation Date'),          'transdate'                                                                ],
172
      [ $::locale->text('Quotation Number'),        sub { $self->sales_quotation($_[0], display => 'table-cell') }   ],
173
      [ $::locale->text('Vendor'),                  'vendor'                                                                   ],
174
      [ $::locale->text('Net amount'),              'netamount'                                                                ],
175
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
176
      [ $::locale->text('Project'),                 'globalproject', ],
177
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
178
    ],
179
  );
180
}
181

  
182
sub _sales_order_list {
183
  my ($self, $list) = @_;
184

  
185
  return $self->record_list(
186
    $list,
187
    title   => $::locale->text('Sales Orders'),
188
    columns => [
189
      [ $::locale->text('Order Date'),              'transdate'                                                                ],
190
      [ $::locale->text('Order Number'),            sub { $self->sales_order($_[0], display => 'table-cell') }   ],
191
      [ $::locale->text('Quotation'),               'quonumber' ],
192
      [ $::locale->text('Customer'),                'customer'                                                                 ],
193
      [ $::locale->text('Net amount'),              'netamount'                                                                ],
194
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
195
      [ $::locale->text('Project'),                 'globalproject', ],
196
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
197
    ],
198
  );
199
}
200

  
201
sub _purchase_order_list {
202
  my ($self, $list) = @_;
203

  
204
  return $self->record_list(
205
    $list,
206
    title   => $::locale->text('Purchase Orders'),
207
    columns => [
208
      [ $::locale->text('Order Date'),              'transdate'                                                                ],
209
      [ $::locale->text('Order Number'),            sub { $self->sales_order($_[0], display => 'table-cell') }   ],
210
      [ $::locale->text('Request for Quotation'),   'quonumber' ],
211
      [ $::locale->text('Vendor'),                  'vendor'                                                                 ],
212
      [ $::locale->text('Net amount'),              'netamount'                                                                ],
213
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
214
      [ $::locale->text('Project'),                 'globalproject', ],
215
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
216
    ],
217
  );
218
}
219

  
220
sub _sales_delivery_order_list {
221
  my ($self, $list) = @_;
222

  
223
  return $self->record_list(
224
    $list,
225
    title   => $::locale->text('Sales Delivery Orders'),
226
    columns => [
227
      [ $::locale->text('Delivery Order Date'),     'transdate'                                                                ],
228
      [ $::locale->text('Delivery Order Number'),   sub { $self->sales_delivery_order($_[0], display => 'table-cell') } ],
229
      [ $::locale->text('Order Number'),            'ordnumber' ],
230
      [ $::locale->text('Customer'),                'customer'                                                                 ],
231
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
232
      [ $::locale->text('Project'),                 'globalproject', ],
233
      [ $::locale->text('Delivered'),               'delivered'                                                                ],
234
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
235
    ],
236
  );
237
}
238

  
239
sub _purchase_delivery_order_list {
240
  my ($self, $list) = @_;
241

  
242
  return $self->record_list(
243
    $list,
244
    title   => $::locale->text('Purchase Delivery Orders'),
245
    columns => [
246
      [ $::locale->text('Delivery Order Date'),     'transdate'                                                                ],
247
      [ $::locale->text('Delivery Order Number'),   sub { $self->sales_delivery_order($_[0], display => 'table-cell') } ],
248
      [ $::locale->text('Order Number'),            'ordnumber' ],
249
      [ $::locale->text('Vendor'),                  'vendor'                                                                 ],
250
      [ $::locale->text('Transaction description'), 'transaction_description'                                                  ],
251
      [ $::locale->text('Project'),                 'globalproject', ],
252
      [ $::locale->text('Delivered'),               'delivered'                                                                ],
253
      [ $::locale->text('Closed'),                  'closed'                                                                   ],
254
    ],
255
  );
256
}
257

  
258
sub _sales_invoice_list {
259
  my ($self, $list) = @_;
260

  
261
  return $self->record_list(
262
    $list,
263
    title   => $::locale->text('Sales Invoices'),
264
    columns => [
265
      [ $::locale->text('Invoice Date'),            'transdate'               ],
266
      [ $::locale->text('Invoice Number'),          sub { $self->sales_invoice($_[0], display => 'table-cell') } ],
267
      [ $::locale->text('Quotation Number'),        'quonumber' ],
268
      [ $::locale->text('Order Number'),            'ordnumber' ],
269
      [ $::locale->text('Customer'),                'customer'                ],
270
      [ $::locale->text('Net amount'),              'netamount'               ],
271
      [ $::locale->text('Paid'),                    'paid'                    ],
272
      [ $::locale->text('Transaction description'), 'transaction_description' ],
273
    ],
274
  );
275
}
276

  
277
sub _purchase_invoice_list {
278
  my ($self, $list) = @_;
279

  
280
  return $self->record_list(
281
    $list,
282
    title   => $::locale->text('Purchase Invoices'),
283
    columns => [
284
      [ $::locale->text('Invoice Date'),                 'transdate'               ],
285
      [ $::locale->text('Invoice Number'),               sub { $self->sales_invoice($_[0], display => 'table-cell') } ],
286
      [ $::locale->text('Request for Quotation Number'), 'quonumber' ],
287
      [ $::locale->text('Order Number'),                 'ordnumber' ],
288
      [ $::locale->text('Vendor'),                       'vendor'                 ],
289
      [ $::locale->text('Net amount'),                   'netamount'               ],
290
      [ $::locale->text('Paid'),                         'paid'                    ],
291
      [ $::locale->text('Transaction description'),      'transaction_description' ],
292
    ],
293
  );
294
}
295

  
296
sub _ar_transaction_list {
297
  my ($self, $list) = @_;
298

  
299
  return $self->record_list(
300
    $list,
301
    title   => $::locale->text('AR Transactions'),
302
    columns => [
303
      [ $::locale->text('Invoice Date'),            'transdate'               ],
304
      [ $::locale->text('Invoice Number'),          sub { $self->ar_transaction($_[0], display => 'table-cell') } ],
305
      [ $::locale->text('Customer'),                'customer'                ],
306
      [ $::locale->text('Net amount'),              'netamount'               ],
307
      [ $::locale->text('Paid'),                    'paid'                    ],
308
      [ $::locale->text('Transaction description'), 'transaction_description' ],
309
    ],
310
  );
311
}
312

  
313
sub _ap_transaction_list {
314
  my ($self, $list) = @_;
315

  
316
  return $self->record_list(
317
    $list,
318
    title   => $::locale->text('AP Transactions'),
319
    columns => [
320
      [ $::locale->text('Invoice Date'),            'transdate'                      ],
321
      [ $::locale->text('Invoice Number'),          sub { $self->ar_transaction($_[0 ], display => 'table-cell') } ],
322
      [ $::locale->text('Vendor'),                  'vendor'                         ],
323
      [ $::locale->text('Net amount'),              'netamount'                      ],
324
      [ $::locale->text('Paid'),                    'paid'                           ],
325
      [ $::locale->text('Transaction description'), 'transaction_description'        ],
326
    ],
327
  );
328
}
329

  
330
1;
331

  
332
__END__
333

  
334
=pod
335

  
336
=encoding utf8
337

  
338
=head1 NAME
339

  
340
SL::Presenter::Record - Presenter module for lists of
341
sales/purchase/general ledger record Rose::DB objects
342

  
343
=head1 SYNOPSIS
344

  
345
  # Retrieve a number of documents from somewhere, e.g.
346
  my $order   = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_order') ]);
347
  my $records = $order->linked_records(destination => 'to');
348

  
349
  # Give HTML representation:
350
  my $html = SL::Presenter->get->grouped_record_list($records);
351

  
352
=head1 OVERVIEW
353

  
354
TODO
355

  
356
=head1 FUNCTIONS
357

  
358
=over 4
359

  
360
=item C<empty_record_list>
361

  
362
Returns a rendered version (actually an instance of
363
L<SL::Presenter::EscapedText>) of an empty list of records. Is usually
364
only called by L<grouped_record_list> if its list is empty.
365

  
366
=item C<grouped_record_list $list, %params>
367

  
368
Given a number of Rose::DB objects in the array reference C<$list>
369
this function first groups them by type. Then it calls L<record_list>
370
with each non-empty type-specific sub-list and the appropriate
371
parameters for outputting a list of those records.
372

  
373
Returns a rendered version (actually an instance of
374
L<SL::Presenter::EscapedText>) of all the lists.
375

  
376
The order in which the records are grouped is:
377

  
378
=over 2
379

  
380
=item * sales quotations
381

  
382
=item * sales orders
383

  
384
=item * sales delivery orders
385

  
386
=item * sales invoices
387

  
388
=item * AR transactions
389

  
390
=item * requests for quotations
391

  
392
=item * purchase orders
393

  
394
=item * purchase delivery orders
395

  
396
=item * purchase invoices
397

  
398
=item * AP transactions
399

  
400
=back
401

  
402
Objects of unknown types are skipped.
403

  
404
=item C<record_list $list, %params>
405

  
406
Returns a rendered version (actually an instance of
407
L<SL::Presenter::EscapedText>) of a list of records. This list
408
consists of a heading and a tabular representation of the list.
409

  
410
The parameters include:
411

  
412
=over 2
413

  
414
=item C<title>
415

  
416
Mandatory. The title to use in the heading. Must already be
417
translated.
418

  
419
=item C<columns>
420

  
421
Mandatory. An array reference of column specs to output. Each column
422
spec can be either an array reference or a hash reference.
423

  
424
If a column spec is an array reference then the first element is the
425
column's name shown in the table header. It must already be translated.
426

  
427
The second element can be either a string or a code reference. A
428
string is taken as the name of a function to call on the Rose::DB
429
object for the current row. Its return value is formatted depending on
430
the column's type (e.g. dates are output as the user expects them,
431
floating point numbers are rounded to two decimal places and
432
right-aligned etc). If it is a code reference then that code is called
433
with the object as the first argument. Its return value should be an
434
instance of L<SL::Presenter::EscapedText> and contain the rendered
435
representation of the content to output.
436

  
437
The third element, if present, can be a link to which the column will
438
be linked.
439

  
440
If the column spec is a hash reference then the same arguments are
441
expected. The corresponding hash keys are C<title>, C<data> and
442
C<link>.
443

  
444
=back
445

  
446
=back
447

  
448
=head1 BUGS
449

  
450
Nothing here yet.
451

  
452
=head1 AUTHOR
453

  
454
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
455

  
456
=cut
locale/de/all
1115 1115
  'Line Total'                  => 'Zeilensumme',
1116 1116
  'Line and column'             => 'Zeile und Spalte',
1117 1117
  'Line endings'                => 'Zeilenumbr&uuml;che',
1118
  'Linked Records'              => 'Verknüpfte Belege',
1118 1119
  'List Accounts'               => 'Konten anzeigen',
1119 1120
  'List Languages'              => 'Sprachen anzeigen',
1120 1121
  'List Price'                  => 'Listenpreis',
......
1497 1498
  'Projects'                    => 'Projekte',
1498 1499
  'Projecttransactions'         => 'Projektbuchungen',
1499 1500
  'Prozentual/Absolut'          => 'Prozentual/Absolut',
1501
  'Purchase Delivery Orders'    => 'Einkaufslieferscheine',
1500 1502
  'Purchase Delivery Orders deleteable' => 'Einkaufslieferscheine löschbar',
1501 1503
  'Purchase Invoice'            => 'Einkaufsrechnung',
1504
  'Purchase Invoices'           => 'Einkaufsrechnungen',
1502 1505
  'Purchase Order'              => 'Lieferantenauftrag',
1503 1506
  'Purchase Orders'             => 'Lieferantenaufträge',
1504 1507
  'Purchase Orders deleteable'  => 'Lieferantenaufträge löschbar',
......
1576 1579
  'Reports'                     => 'Berichte',
1577 1580
  'Representative'              => 'Vertreter',
1578 1581
  'Reqdate'                     => 'Liefertermin',
1582
  'Request Quotations'          => 'Preisanfragen',
1579 1583
  'Request for Quotation'       => 'Anfrage',
1584
  'Request for Quotation Number' => 'Anfragenummer',
1580 1585
  'Request for Quotations'      => 'Anfragen',
1581 1586
  'Request quotation'           => 'Preisanfrage',
1582 1587
  'Requested execution date'    => 'Gewünschtes Ausführungsdatum',
......
1607 1612
  'Saldo neu'                   => 'Saldo neu',
1608 1613
  'Saldo per'                   => 'Saldo per',
1609 1614
  'Sale Prices'                 => 'Verkaufspreise',
1615
  'Sales Delivery Orders'       => 'Verkaufslieferscheine',
1610 1616
  'Sales Delivery Orders deleteable' => 'Verkaufslieferscheine löschbar',
1611 1617
  'Sales Invoice'               => 'Rechnung',
1612
  'Sales Invoices'              => 'Kundenrechnung',
1618
  'Sales Invoices'              => 'Kundenrechnungen',
1613 1619
  'Sales Order'                 => 'Kundenauftrag',
1614 1620
  'Sales Orders'                => 'Aufträge',
1615 1621
  'Sales Orders deleteable'     => 'Kundenaufträge löschbar',
1616 1622
  'Sales Price information'     => 'Verkaufspreisinformation',
1623
  'Sales Quotations'            => 'Angebote',
1617 1624
  'Sales Report'                => 'Verkaufsbericht',
1618 1625
  'Sales and purchase invoices with inventory transactions with taxkeys' => 'Einkaufs- und Verkaufsrechnungen mit Warenbestandsbuchungen mit Steuerschlüsseln',
1619 1626
  'Sales delivery order'        => 'Lieferschein (Verkauf)',
templates/webpages/presenter/record/empty_record_list.html
1
[% USE LxERP %]
2
<p class="message_hint">[% LxERP.t8('No data was found.') %]</p>
templates/webpages/presenter/record/record_list.html
1
[% USE L %][% USE LxERP %]
2
<div class="listtop">[%- P.escape(title) %]</div>
3

  
4
<div style="padding-bottom: 15px">
5
 <table style="width: 100%">
6
  <thead>
7
   <tr>
8
    [%- FOREACH column = TABLE_HEADER %]
9
    <th class="listheading"[% IF column.alignment %] align="[% column.alignment %]"[% END %]>[%- P.escape(column.value) %]</th>
10
    [%- END %]
11
   </tr>
12
  </thead>
13

  
14
  <tbody>
15
   [%- FOREACH row = TABLE_ROWS %]
16
   <tr class="listrow[% loop.count % 2 %]">
17
    [%- FOREACH column = row %]
18
    <td[% IF column.alignment %] align="[% column.alignment %]"[% END %]>
19
     [%- IF column.link %]<a href="[% column.link %]">[%- END %]
20
      [%- P.escape(column.value) %]
21
      [%- IF column.link %]</a>[%- END %]
22
    </td>
23
    [%- END %]
24
   </tr>
25
   [%- END %]
26
  </tbody>
27
 </table>
28
</div>

Auch abrufbar als: Unified diff