Verknüpfte Belege: Spalte "Verknüpfungsrichtung" anzeigen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 28 Feb 2013 10:03:32 +0000 (11:03 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 1 Mar 2013 09:41:27 +0000 (10:41 +0100)
SL/Controller/RecordLinks.pm
SL/DB/Helper/LinkedRecords.pm
SL/Presenter/Record.pm
locale/de/all

index fd424b9..8edd787 100644 (file)
@@ -23,7 +23,7 @@ sub action_ajax_list {
     my $model          = 'SL::DB::' . $::form->{object_model};
     my $object         = $model->new(id => $::form->{object_id})->load || die $::locale->text("Record not found");
     my $linked_records = $object->linked_records(direction => 'both');
-    my $output         = SL::Presenter->get->grouped_record_list($linked_records);
+    my $output         = SL::Presenter->get->grouped_record_list($linked_records, with_columns => [ qw(record_link_direction) ]);
     $self->render(\$output, { layout => 0, process => 0 });
 
     1;
index 3fb5948..dd22863 100644 (file)
@@ -64,10 +64,15 @@ sub _linked_records_implementation {
 
   my @get_objects_query = ref($params{query}) eq 'ARRAY' ? @{ $params{query} } : ();
   my $get_objects       = sub {
-    my $manager_class = SL::DB::Helper::Mappings::get_manager_package_for_table($_[0]->$sub_wanted_table);
-    my $object_class  = SL::DB::Helper::Mappings::get_package_for_table($_[0]->$sub_wanted_table);
+    my ($link)        = @_;
+    my $manager_class = SL::DB::Helper::Mappings::get_manager_package_for_table($link->$sub_wanted_table);
+    my $object_class  = SL::DB::Helper::Mappings::get_package_for_table($link->$sub_wanted_table);
     eval "require " . $object_class . "; 1;";
-    return @{ $manager_class->get_all(query => [ id => $_[0]->$sub_wanted_id, @get_objects_query ]) };
+    return map {
+      $_->{_record_link_direction} = $wanted;
+      $_->{_record_link}           = $link;
+      $_
+    } @{ $manager_class->get_all(query => [ id => $link->$sub_wanted_id, @get_objects_query ]) };
   };
 
   # If no 'via' is given then use a simple(r) method for querying the wanted objects.
@@ -295,7 +300,22 @@ the current employee.
 
 =back
 
-Returns an array reference.
+Returns an array reference. Each element returned is a Rose::DB
+instance. Additionally several elements in the element returned are
+set to special values:
+
+=over 2
+
+=item C<_record_link_direction>
+
+Either C<from> or C<to> indicating the direction. C<from> means that
+this object is the source in the link.
+
+=item C<_record_link>
+
+The actual database link object (an instance of L<SL::DB::RecordLink>).
+
+=back
 
 =item C<link_to_record $record, %params>
 
index 20d4d5f..64cb21b 100644 (file)
@@ -10,23 +10,32 @@ 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(selectable with_columns);
+
   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};
 
   return $output || $self->empty_record_list;
 }
@@ -54,6 +63,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 };
 
@@ -141,7 +158,7 @@ sub _group_records {
 }
 
 sub _sales_quotation_list {
-  my ($self, $list) = @_;
+  my ($self, $list, %params) = @_;
 
   return $self->record_list(
     $list,
@@ -155,11 +172,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,
@@ -173,11 +191,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,
@@ -192,11 +211,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,
@@ -211,11 +231,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,
@@ -230,11 +251,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,
@@ -249,11 +271,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,
@@ -268,11 +291,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,
@@ -287,11 +311,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,
@@ -304,11 +329,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,
@@ -321,6 +347,7 @@ sub _ap_transaction_list {
       [ $::locale->text('Paid'),                    'paid'                           ],
       [ $::locale->text('Transaction description'), 'transaction_description'        ],
     ],
+    %params,
   );
 }
 
index f91b702..80f80e9 100644 (file)
@@ -1125,6 +1125,7 @@ $self->{texts} = {
   'Line Total'                  => 'Zeilensumme',
   'Line and column'             => 'Zeile und Spalte',
   'Line endings'                => 'Zeilenumbr&uuml;che',
+  'Link direction'              => 'Verknüpfungsrichtung',
   'Linked Records'              => 'Verknüpfte Belege',
   'List Accounts'               => 'Konten anzeigen',
   'List Languages'              => 'Sprachen anzeigen',
@@ -1615,6 +1616,8 @@ $self->{texts} = {
   'Right'                       => 'Rechts',
   'Row #1: amount has to be different from zero.' => 'Zeile #1: Der Wert darf nicht 0 sein.',
   'Row number'                  => 'Zeilennummer',
+  'Row was created from current record' => 'Zeile wurde aus aktuellem Beleg erstellt',
+  'Row was source for current record' => 'Zeile war Quelle für aktuellen Beleg',
   'Run at'                      => 'Ausgeführt um',
   'SAVED'                       => 'Gespeichert',
   'SAVED FOR DUNNING'           => 'Gespeichert',