Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f581a41b

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID f581a41b28e09f2774b96882cdd18ed21dbe4702
  • Vorgänger 3e44c8fe
  • Nachfolger b7af55b2

EmailJournal: nutze Presenter::Record um Belege anzuzeigen

Unterschiede anzeigen:

SL/Controller/EmailJournal.pm
9 9
use SL::DB::EmailJournal;
10 10
use SL::DB::EmailJournalAttachment;
11 11
use SL::Presenter::EmailJournal;
12
use SL::Presenter::Record qw(grouped_record_list);
12 13
use SL::Presenter::Tag qw(html_tag div_tag button_tag);
13 14
use SL::Helper::Flash;
14 15
use SL::Locale::String qw(t8);
......
241 242
  my $cv_type = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
242 243

  
243 244
  my $record_types = $self->record_types_for_customer_vendor_type_and_action($cv_type, 'workflow_record');
244
  my @records = $self->get_records_for_types(
245
    $record_types,
246
    customer_vendor_type => $cv_type,
247
    customer_vendor_id   => $customer_vendor && $customer_vendor->id,
248
    record_number        => '',
249
    with_closed          => 0,
250
  );
251 245

  
252 246
  $self->setup_show_action_bar;
253 247
  my $cv_type_found = $customer_vendor && $customer_vendor->is_vendor ? 'vendor' : 'customer';
......
259 253
    CUSTOMER_VENDOR => , $customer_vendor,
260 254
    CV_TYPE_FOUND => $cv_type_found,
261 255
    RECORD_TYPES_WITH_INFO => \@record_types_with_info,
262
    RECORDS => \@records,
263 256
    back_to  => $back_to
264 257
  );
265 258
}
266 259

  
267
sub get_records_for_types {
268
  my ($self, $record_types, %params) = @_;
269
  $record_types = [ $record_types ] unless ref $record_types eq 'ARRAY';
270

  
271
  my $cv_type       = $params{customer_vendor_type};
272
  my $cv_id         = $params{customer_vendor_id};
273
  my $record_number = $params{record_number};
274
  my $with_closed   = $params{with_closed};
275

  
276
  my @records = ();
277
  foreach my $record_type (@$record_types) {
278
    my $manager = $RECORD_TYPE_TO_MANAGER{$record_type};
279
    my $model = $RECORD_TYPE_TO_MODEL{$record_type};
280
    my %additional_where = ();
281
    if ($cv_type && $cv_id && $record_type !~ /^gl_transaction/) {
282
      $additional_where{"${cv_type}_id"} = $cv_id;
283
    }
284
    if ($record_number) {
285
      my $nr_key = $RECORD_TYPE_TO_NR_KEY{$record_type};
286
      $additional_where{$nr_key} = { ilike => "%$record_number%" };
287
    }
288
    unless ($with_closed) {
289
      if (any {$_ eq 'closed'} $model->meta->columns) {
290
        $additional_where{closed} = 0;
291
      } elsif (any {$_ eq 'paid'} $model->meta->columns) {
292
        $additional_where{amount} = { gt => \'paid' };
293
      }
294
    }
295
    my $records_of_type = $manager->get_all(
296
      where => [
297
        $manager->type_filter($record_type),
298
        %additional_where,
299
      ],
300
    );
301
    push @records, @$records_of_type;
302
  }
303

  
304
  return @records;
305
}
306

  
307 260
sub action_attachment_preview {
308 261
  my ($self) = @_;
309 262

  
......
467 420
    with_closed          => $with_closed,
468 421
  );
469 422

  
470
  my $new_list;
471
  if (@records) {
472
    $new_list = join('', map {
473
        button_tag(
474
          "kivi.EmailJournal.apply_action_with_attachment('${\$_->id}', '${\$_->record_type}');",
475
          $_->displayable_name,
476
          class => "record_button",
477
        );
478
      } @records);
479
  } else {
480
    $new_list = html_tag('h3', t8('No records found.'));
481
  }
482
  my $new_div = div_tag(
483
    $new_list,
484
    id => 'record_list',
485
  );
423
  my $new_div = $self->get_records_div(\@records);
486 424

  
487 425
  $self->js->replaceWith('#record_list', $new_div);
488 426
  $self->js->hide('#record_toggle_closed') if scalar @records < 20;
......
527 465
# helpers
528 466
#
529 467

  
468
sub get_records_for_types {
469
  my ($self, $record_types, %params) = @_;
470
  $record_types = [ $record_types ] unless ref $record_types eq 'ARRAY';
471

  
472
  my $cv_type       = $params{customer_vendor_type};
473
  my $cv_id         = $params{customer_vendor_id};
474
  my $record_number = $params{record_number};
475
  my $with_closed   = $params{with_closed};
476

  
477
  my @records = ();
478
  foreach my $record_type (@$record_types) {
479
    my $manager = $RECORD_TYPE_TO_MANAGER{$record_type};
480
    my $model = $RECORD_TYPE_TO_MODEL{$record_type};
481
    my %additional_where = ();
482
    if ($cv_type && $cv_id && $record_type !~ /^gl_transaction/) {
483
      $additional_where{"${cv_type}_id"} = $cv_id;
484
    }
485
    if ($record_number) {
486
      my $nr_key = $RECORD_TYPE_TO_NR_KEY{$record_type};
487
      $additional_where{$nr_key} = { ilike => "%$record_number%" };
488
    }
489
    unless ($with_closed) {
490
      if (any {$_ eq 'closed'} $model->meta->columns) {
491
        $additional_where{closed} = 0;
492
      } elsif (any {$_ eq 'paid'} $model->meta->columns) {
493
        $additional_where{amount} = { gt => \'paid' };
494
      }
495
    }
496
    my $records_of_type = $manager->get_all(
497
      where => [
498
        $manager->type_filter($record_type),
499
        %additional_where,
500
      ],
501
    );
502
    push @records, @$records_of_type;
503
  }
504

  
505
  return @records;
506
}
507

  
508
sub get_records_div {
509
  my ($self, $records) = @_;
510
  my $div = div_tag(
511
    grouped_record_list(
512
      $records,
513
      with_columns => [ qw(email_journal_action) ],
514
    ),
515
    id => 'record_list',
516
  );
517
  return $div;
518
}
519

  
530 520
sub link_and_add_attachment_to_record {
531 521
 my ($self, $params) = @_;
532 522

  

Auch abrufbar als: Unified diff