Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 57342517

Von Jan Büren vor mehr als 2 Jahren hinzugefügt

  • ID 5734251762d9fc172a5110472d029bb6a36578a0
  • Vorgänger 053d0c37
  • Nachfolger bb84bc55

Kreditorenbuchung um Steuerschlüssel 94 (reverse charge) erweitert

Bucht die gegensätzliche Steuer auf eine verknüpfte Dialogbuchung
und setzt den Steuerschlüssel beim DATEV-Export auf 0. Ferner sind
Steuer inklusive Buchungen unterbunden und die Dialogbuchung ist
nicht veränderbar, wird aber entsprechend modifiziert wenn die
Quell-Buchung geändert (gelöscht) wird.

Unterschiede anzeigen:

SL/AP.pm
39 39
use SL::DBUtils;
40 40
use SL::IO;
41 41
use SL::MoreCommon;
42
use SL::DB::ApGl;
42 43
use SL::DB::Default;
43 44
use SL::DB::Draft;
44 45
use SL::DB::Order;
......
406 407
    SL::DB::Manager::Draft->delete_all(where => [ id => delete($form->{draft_id}) ]);
407 408
  }
408 409

  
410
  # hook for taxkey 94
411
  $self->_reverse_charge($myconfig, $form);
409 412
  # safety check datev export
410 413
  if ($::instance_conf->get_datev_check_on_ap_transaction) {
411 414
    my $datev = SL::DATEV->new(
......
422 425
  return 1;
423 426
}
424 427

  
428
sub _reverse_charge {
429
  my ($self, $myconfig, $form) = @_;
430

  
431
  # check taxkey settings or return
432
  my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => 94 ]);
433
  return unless ref $tax eq 'SL::DB::Tax';
434

  
435
  # delete previous bookings, if they exists (repost)
436
  my $ap_gl = SL::DB::Manager::ApGl->get_first(where => [ ap_id => $form->{id} ]);
437
  my $gl_id = ref $ap_gl eq 'SL::DB::ApGl' ? $ap_gl->gl_id : undef;
438

  
439
  SL::DB::Manager::GLTransaction->delete_all(where => [ id    => $gl_id ])       if $gl_id;
440
  SL::DB::Manager::ApGl->         delete_all(where => [ ap_id => $form->{id} ])  if $gl_id;
441
  SL::DB::Manager::RecordLink->   delete_all(where => [ from_table => 'ap', to_table => 'gl', from_id => $form->{id} ]);
442

  
443
  # gl booking
444
  my ($credit, $debit);
445
  $credit   = SL::DB::Manager::Chart->find_by(id => $tax->chart_id);
446
  $debit    = SL::DB::Manager::Chart->find_by(id => $tax->reverse_charge_chart_id);
447

  
448
  croak("No such Chart ID" . $tax->chart_id)          unless ref $credit eq 'SL::DB::Chart';
449
  croak("No such Chart ID" . $tax->reverse_chart_id)  unless ref $debit  eq 'SL::DB::Chart';
450

  
451
  my ($i, $current_transaction);
452

  
453
  for $i (1 .. $form->{rowcount}) {
454
    next unless $form->{"taxkey_$i"} == 94;
455

  
456
    my ($tmpnetamount, $tmptaxamount) = $form->calculate_tax($form->{"amount_$i"}, 0.19, $form->{taxincluded}, 2);
457
    $current_transaction = SL::DB::GLTransaction->new(
458
          employee_id    => $form->{employee_id},
459
          transdate      => $form->{transdate},
460
          description    => $form->{notes} || $form->{invnumber},
461
          reference      => $form->{invnumber},
462
          department_id  => $form->{department_id} ? $form->{department_id} : undef,
463
          imported       => 0, # not imported
464
          taxincluded    => 0,
465
        )->add_chart_booking(
466
          chart  => $tmptaxamount < 0 ? $credit : $debit,
467
          credit => abs($tmptaxamount),
468
          source => "Reverse Charge for " . $form->{invnumber},
469
        )->add_chart_booking(
470
          chart  => $tmptaxamount < 0 ? $debit : $credit,
471
          debit  => abs($tmptaxamount),
472
          source => "Reverse Charge for " . $form->{invnumber},
473
      )->post;
474
    # add a stable link from ap to gl
475
    my %props_gl = (
476
        ap_id => $form->{id},
477
        gl_id => $current_transaction->id,
478
      );
479
    SL::DB::ApGl->new(%props_gl)->save;
480
    # Record a record link from ap to gl
481
    my %props_rl = (
482
        from_table => 'ap',
483
        from_id    => $form->{id},
484
        to_table   => 'gl',
485
        to_id      => $current_transaction->id,
486
      );
487
    SL::DB::RecordLink->new(%props_rl)->save;
488
  }
489
}
490

  
425 491
sub delete_transaction {
426 492
  $main::lxdebug->enter_sub();
427 493

  
428 494
  my ($self, $myconfig, $form) = @_;
429 495

  
430 496
  SL::DB->client->with_transaction(sub {
497

  
498
    # if tax 94 reverse charge, clear all GL bookings and links
499
    my $ap_gl = SL::DB::Manager::ApGl->get_first(where => [ ap_id => $form->{id} ]);
500
    my $gl_id = ref $ap_gl eq 'SL::DB::ApGl' ? $ap_gl->gl_id : undef;
501

  
502
    SL::DB::Manager::GLTransaction->delete_all(where => [ id    => $gl_id ])       if $gl_id;
503
    SL::DB::Manager::ApGl->         delete_all(where => [ ap_id => $form->{id} ])  if $gl_id;
504
    SL::DB::Manager::RecordLink->   delete_all(where => [ from_table => 'ap', to_table => 'gl', from_id => $form->{id} ]);
505
    # done gl delete for tax 94 case
506

  
507
    # begin ap delete
431 508
    my $query = qq|DELETE FROM ap WHERE id = ?|;
432 509
    do_query($form, SL::DB->client->dbh, $query, $form->{id});
433 510
    1;

Auch abrufbar als: Unified diff