X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/5b5dbec0272c91697acf33c4842ee9d63f041f22..b8fee3fc:/SL/Presenter/Record.pm diff --git a/SL/Presenter/Record.pm b/SL/Presenter/Record.pm index a9c6dcd8e..db0caa542 100644 --- a/SL/Presenter/Record.pm +++ b/SL/Presenter/Record.pm @@ -10,23 +10,35 @@ our @EXPORT = qw(grouped_record_list empty_record_list record_list); use Carp; use List::Util qw(first); +sub _arrayify { + my ($array) = @_; + return [] if !defined $array; + return $array if ref $array; + return [ $array ]; +} + sub grouped_record_list { my ($self, $list, %params) = @_; + %params = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(edit_record_links form_prefix with_columns object_id object_model); + $params{form_prefix} ||= 'record_links'; + my %groups = _group_records($list); my $output = ''; - $output .= _sales_quotation_list( $self, $groups{sales_quotations}) if $groups{sales_quotations}; - $output .= _sales_order_list( $self, $groups{sales_orders}) if $groups{sales_orders}; - $output .= _sales_delivery_order_list( $self, $groups{sales_delivery_orders}) if $groups{sales_delivery_orders}; - $output .= _sales_invoice_list( $self, $groups{sales_invoices}) if $groups{sales_invoices}; - $output .= _ar_transaction_list( $self, $groups{ar_transactions}) if $groups{ar_transactions}; + $output .= _sales_quotation_list( $self, $groups{sales_quotations}, %params) if $groups{sales_quotations}; + $output .= _sales_order_list( $self, $groups{sales_orders}, %params) if $groups{sales_orders}; + $output .= _sales_delivery_order_list( $self, $groups{sales_delivery_orders}, %params) if $groups{sales_delivery_orders}; + $output .= _sales_invoice_list( $self, $groups{sales_invoices}, %params) if $groups{sales_invoices}; + $output .= _ar_transaction_list( $self, $groups{ar_transactions}, %params) if $groups{ar_transactions}; - $output .= _request_quotation_list( $self, $groups{purchase_quotations}) if $groups{purchase_quotations}; - $output .= _purchase_order_list( $self, $groups{purchase_orders}) if $groups{purchase_orders}; - $output .= _purchase_delivery_order_list($self, $groups{purchase_delivery_orders}) if $groups{purchase_delivery_orders}; - $output .= _purchase_invoice_list( $self, $groups{purchase_invoices}) if $groups{purchase_invoices}; - $output .= _ar_transaction_list( $self, $groups{ar_transactions}) if $groups{ar_transactions}; + $output .= _request_quotation_list( $self, $groups{purchase_quotations}, %params) if $groups{purchase_quotations}; + $output .= _purchase_order_list( $self, $groups{purchase_orders}, %params) if $groups{purchase_orders}; + $output .= _purchase_delivery_order_list($self, $groups{purchase_delivery_orders}, %params) if $groups{purchase_delivery_orders}; + $output .= _purchase_invoice_list( $self, $groups{purchase_invoices}, %params) if $groups{purchase_invoices}; + $output .= _ar_transaction_list( $self, $groups{ar_transactions}, %params) if $groups{ar_transactions}; + + $output = $self->render('presenter/record/grouped_record_list', %params, output => $output, nownow => DateTime->now) if $output; return $output || $self->empty_record_list; } @@ -54,6 +66,14 @@ sub record_list { croak "Wrong type for 'columns' argument: not an array reference"; } + my %with_columns = map { ($_ => 1) } @{ _arrayify($params{with_columns}) }; + if ($with_columns{record_link_direction}) { + push @columns, { + title => $::locale->text('Link direction'), + data => sub { $_[0]->{_record_link_direction} eq 'from' ? $::locale->text('Row was source for current record') : $::locale->text('Row was created from current record') }, + }; + } + my %column_meta = map { $_->name => $_ } @{ $list->[0]->meta->columns }; my %relationships = map { $_->name => $_ } @{ $list->[0]->meta->relationships }; @@ -71,24 +91,21 @@ sub record_list { my $method = $spec->{column} || $spec->{data}; my $meta = $column_meta{ $spec->{data} }; - my $type = lc ref $meta; - $type =~ s/.*:://; + my $type = ref $meta; my $relationship = $relationships{ $spec->{data} }; my $rel_type = !$relationship ? '' : lc $relationship->class; - $rel_type =~ s/.*:://; + $rel_type =~ s/^sl::db:://; if (ref($spec->{data}) eq 'CODE') { $cell{value} = $spec->{data}->($obj); } else { - $cell{value} = $rel_type eq 'customer' ? $self->customer($obj->$method, display => 'table-cell') - : $rel_type eq 'vendor' ? $self->vendor( $obj->$method, display => 'table-cell') - : $rel_type eq 'project' ? $self->project( $obj->$method, display => 'table-cell') - : $type eq 'date' ? $call->($obj, $method . '_as_date') - : $type =~ m/float|numeric|real/ ? $::form->format_amount(\%::myconfig, $call->($obj, $method), 2) - : $type eq 'boolean' ? $call->($obj, $method . '_as_bool_yn') - : $type =~ m/int|serial/ ? $spec->{data} * 1 - : $call->($obj, $method); + $cell{value} = $rel_type && $self->can($rel_type) ? $self->$rel_type($obj->$method, display => 'table-cell') + : $type eq 'Rose::DB::Object::Metadata::Column::Date' ? $call->($obj, $method . '_as_date') + : $type =~ m/^Rose::DB::Object::Metadata::Column::(?:Float|Numeric|Real)$/ ? $::form->format_amount(\%::myconfig, $call->($obj, $method), 2) + : $type eq 'Rose::DB::Object::Metadata::Column::Boolean' ? $call->($obj, $method . '_as_bool_yn') + : $type =~ m/^Rose::DB::Object::Metadata::Column::(?:Integer|Serial)$/ ? $spec->{data} * 1 + : $call->($obj, $method); } $cell{alignment} = 'right' if $type =~ m/int|serial|float|real|numeric/; @@ -96,14 +113,16 @@ sub record_list { push @row, \%cell; } - push @data, \@row; + push @data, { columns => \@row, record_link => $obj->{_record_link} }; } my @header = map +{ value => $columns[$_]->{title}, - alignment => $data[0]->[$_]->{alignment}, + alignment => $data[0]->{columns}->[$_]->{alignment}, }, (0..scalar(@columns) - 1); + $params{form_prefix} ||= 'record_links'; + return $self->render( 'presenter/record/record_list', %params, @@ -144,7 +163,7 @@ sub _group_records { } sub _sales_quotation_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -158,11 +177,12 @@ sub _sales_quotation_list { [ $::locale->text('Project'), 'globalproject', ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _request_quotation_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -176,11 +196,12 @@ sub _request_quotation_list { [ $::locale->text('Project'), 'globalproject', ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _sales_order_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -195,11 +216,12 @@ sub _sales_order_list { [ $::locale->text('Project'), 'globalproject', ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _purchase_order_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -214,11 +236,12 @@ sub _purchase_order_list { [ $::locale->text('Project'), 'globalproject', ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _sales_delivery_order_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -233,11 +256,12 @@ sub _sales_delivery_order_list { [ $::locale->text('Delivered'), 'delivered' ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _purchase_delivery_order_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -252,11 +276,12 @@ sub _purchase_delivery_order_list { [ $::locale->text('Delivered'), 'delivered' ], [ $::locale->text('Closed'), 'closed' ], ], + %params, ); } sub _sales_invoice_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -271,11 +296,12 @@ sub _sales_invoice_list { [ $::locale->text('Paid'), 'paid' ], [ $::locale->text('Transaction description'), 'transaction_description' ], ], + %params, ); } sub _purchase_invoice_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -290,11 +316,12 @@ sub _purchase_invoice_list { [ $::locale->text('Paid'), 'paid' ], [ $::locale->text('Transaction description'), 'transaction_description' ], ], + %params, ); } sub _ar_transaction_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -307,11 +334,12 @@ sub _ar_transaction_list { [ $::locale->text('Paid'), 'paid' ], [ $::locale->text('Transaction description'), 'transaction_description' ], ], + %params, ); } sub _ap_transaction_list { - my ($self, $list) = @_; + my ($self, $list, %params) = @_; return $self->record_list( $list, @@ -324,6 +352,7 @@ sub _ap_transaction_list { [ $::locale->text('Paid'), 'paid' ], [ $::locale->text('Transaction description'), 'transaction_description' ], ], + %params, ); } @@ -401,6 +430,9 @@ The order in which the records are grouped is: Objects of unknown types are skipped. +Parameters are passed to C include C and +C. + =item C Returns a rendered version (actually an instance of @@ -441,6 +473,26 @@ If the column spec is a hash reference then the same arguments are expected. The corresponding hash keys are C, C<data> and C<link>. +=item C<with_columns> + +Can be set by the caller to indicate additional columns to +list. Currently supported: + +=over 2 + +=item C<record_link_destination> + +The record link destination. Requires that the records to list have +been retrieved via the L<SL::DB::Helper::LinkedRecords> helper. + +=back + +=item C<edit_record_links> + +If trueish additional controls will be rendered that allow the user to +remove and add record links. Requires that the records to list have +been retrieved via the L<SL::DB::Helper::LinkedRecords> helper. + =back =back