Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 32dc7476

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 32dc7476d46dc7b6991e8d0c203deaea727c7413
  • Vorgänger 24097357
  • Nachfolger 9468ce7d

Bankauszug verbuchen: Umstellung auf Belegvorlagen & Filter-Fixes

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
21 21
use SL::DB::Chart;
22 22
use SL::DB::AccTransaction;
23 23
use SL::DB::Tax;
24
use SL::DB::Draft;
25 24
use SL::DB::BankAccount;
25
use SL::DB::RecordTemplate;
26 26
use SL::DB::SepaExportItem;
27 27
use SL::DBUtils qw(like);
28 28
use SL::Presenter;
......
32 32

  
33 33
use Rose::Object::MakeMethods::Generic
34 34
(
35
  scalar                  => [ qw(callback transaction) ],
35 36
  'scalar --get_set_init' => [ qw(models problems) ],
36 37
);
37 38

  
......
284 285
  my ($self) = @_;
285 286
  my %myconfig = %main::myconfig;
286 287

  
287
  $self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
288
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number});
289

  
290
  my $use_vendor_filter = $self->{transaction}->{remote_account_number} && $vendor_of_transaction;
288
  $self->transaction(SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}));
291 289

  
292
  my $drafts = SL::DB::Manager::Draft->get_all(where => [ module => 'ap'] , with_objects => 'employee');
290
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->transaction->{remote_account_number});
291
  my $use_vendor_filter     = $self->transaction->{remote_account_number} && $vendor_of_transaction;
293 292

  
294
  my @filtered_drafts;
295

  
296
  foreach my $draft ( @{ $drafts } ) {
297
    my $draft_as_object = YAML::Load($draft->form);
298
    my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id});
299
    $draft->{vendor} = $vendor->name;
300
    $draft->{vendor_id} = $vendor->id;
301
    push @filtered_drafts, $draft;
302
  }
293
  my $templates             = SL::DB::Manager::RecordTemplate->get_all(
294
    where        => [ template_type => 'ap_transaction' ],
295
    with_objects => [ qw(employee vendor) ],
296
  );
303 297

  
304
  #Filter drafts
305
  @filtered_drafts = grep { $_->{vendor_id} == $vendor_of_transaction->id } @filtered_drafts if $use_vendor_filter;
298
  #Filter templates
299
  $templates = [ grep { $_->vendor_id == $vendor_of_transaction->id } @{ $templates } ] if $use_vendor_filter;
306 300

  
307
  my $all_vendors = SL::DB::Manager::Vendor->get_all();
308
  my $callback    = $self->url_for(action                => 'list',
309
                                   'filter.bank_account' => $::form->{filter}->{bank_account},
310
                                   'filter.todate'       => $::form->{filter}->{todate},
311
                                   'filter.fromdate'     => $::form->{filter}->{fromdate});
301
  $self->callback($self->url_for(
302
    action                => 'list',
303
    'filter.bank_account' => $::form->{filter}->{bank_account},
304
    'filter.todate'       => $::form->{filter}->{todate},
305
    'filter.fromdate'     => $::form->{filter}->{fromdate},
306
  ));
312 307

  
313 308
  $self->render(
314 309
    'bank_transactions/create_invoice',
315 310
    { layout => 0 },
316 311
    title       => t8('Create invoice'),
317
    DRAFTS      => \@filtered_drafts,
312
    TEMPLATES   => $templates,
318 313
    vendor_id   => $use_vendor_filter ? $vendor_of_transaction->id   : undef,
319 314
    vendor_name => $use_vendor_filter ? $vendor_of_transaction->name : undef,
320
    ALL_VENDORS => $all_vendors,
321
    callback    => $callback,
322 315
  );
323 316
}
324 317

  
......
348 341
  $self->render(\ SL::JSON::to_json( { 'html' => "$html" } ), { layout => 0, type => 'json', process => 0 });
349 342
};
350 343

  
351
sub action_filter_drafts {
344
sub action_filter_templates {
352 345
  my ($self) = @_;
353 346

  
354 347
  $self->{transaction}      = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
355 348
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number});
356 349

  
357
  my $drafts                = SL::DB::Manager::Draft->get_all(with_objects => 'employee');
358

  
359
  my @filtered_drafts;
360

  
361
  foreach my $draft ( @{ $drafts } ) {
362
    my $draft_as_object = YAML::Load($draft->form);
363
    next unless $draft_as_object->{vendor_id};  # we cannot filter for vendor name, if this is a gl draft
364

  
365
    my $vendor          = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id});
366
    $draft->{vendor}    = $vendor->name;
367
    $draft->{vendor_id} = $vendor->id;
350
  my @filter;
351
  push @filter, ('vendor.id'   => $::form->{vendor_id})                       if $::form->{vendor_id};
352
  push @filter, ('vendor.name' => { ilike => '%' . $::form->{vendor} . '%' }) if $::form->{vendor};
368 353

  
369
    push @filtered_drafts, $draft;
370
  }
354
  my $templates = SL::DB::Manager::RecordTemplate->get_all(
355
    where        => [ template_type => 'ap_transaction', (or => \@filter) x !!@filter ],
356
    with_objects => [ qw(employee vendor) ],
357
  );
371 358

  
372
  my $vendor_name = $::form->{vendor};
373
  my $vendor_id   = $::form->{vendor_id};
359
  $::form->{filter} //= {};
374 360

  
375
  #Filter drafts
376
  @filtered_drafts = grep { $_->{vendor_id} == $vendor_id      } @filtered_drafts if $vendor_id;
377
  @filtered_drafts = grep { $_->{vendor}    =~ /$vendor_name/i } @filtered_drafts if $vendor_name;
361
  $self->callback($self->url_for(
362
    action                => 'list',
363
    'filter.bank_account' => $::form->{filter}->{bank_account},
364
    'filter.todate'       => $::form->{filter}->{todate},
365
    'filter.fromdate'     => $::form->{filter}->{fromdate},
366
  ));
378 367

  
379 368
  my $output  = $self->render(
380
    'bank_transactions/filter_drafts',
369
    'bank_transactions/_template_list',
381 370
    { output => 0 },
382
    DRAFTS => \@filtered_drafts,
371
    TEMPLATES => $templates,
383 372
  );
384 373

  
385
  my %result = ( count => 0, html => $output );
386

  
387
  $self->render(\to_json(\%result), { type => 'json', process => 0 });
374
  $self->render(\to_json({ html => $output }), { type => 'json', process => 0 });
388 375
}
389 376

  
390 377
sub action_ajax_add_list {
......
883 870
  );
884 871
}
885 872

  
873
sub load_ap_record_template_url {
874
  my ($self, $template) = @_;
875

  
876
  return $self->url_for(
877
    controller                 => 'ap.pl',
878
    action                     => 'load_record_template',
879
    id                         => $template->id,
880
    'form_defaults.amount_1'   => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2),
881
    'form_defaults.transdate'  => $self->transaction->transdate_as_date,
882
    'form_defaults.duedate'    => $self->transaction->transdate_as_date,
883
    'form_defaults.datepaid_1' => $self->transaction->transdate_as_date,
884
    'form_defaults.paid_1'     => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2),
885
    'form_defaults.currency'   => $self->transaction->currency->name,
886
    'form_defaults.AP_paid_1'  => $self->transaction->local_bank_account->chart->accno,
887
    'form_defaults.callback'   => $self->callback,
888
  );
889
}
890

  
886 891
1;
887 892
__END__
888 893

  

Auch abrufbar als: Unified diff