Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5436e964

Von Jan Büren vor etwa 3 Jahren hinzugefügt

  • ID 5436e96463cebab1e0a24bcb92b66deda649d471
  • Vorgänger 929c74e8
  • Nachfolger 87b04b66

Kontoauszug verbuchen, Mehrwertsteuerkorrektur für Anzahlungsrechnungen

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
77 77
  };
78 78

  
79 79
  # currency is either passed or use the invoice currency if it differs from the default currency
80
  # TODO remove
80 81
  my ($exchangerate,$currency);
81 82
  if ($params{currency} || $params{currency_id} || $self->currency_id != $::instance_conf->get_currency_id) {
82 83
    if ($params{currency} || $params{currency_id} ) { # currency was specified
......
290 291
    $arap_booking->save;
291 292
    push @new_acc_ids, $arap_booking->acc_trans_id;
292 293

  
294
    # hook for invoice_for_advance_payment DATEV always pairs, acc_trans_id has to be higher than arap_booking ;-)
295
    if ($self->type eq 'invoice_for_advance_payment') {
296
      my $clearing_chart = SL::DB::Chart->new(id => $::instance_conf->get_advance_payment_clearing_chart_id)->load;
297
      die "No Clearing Chart for Advance Payment" unless ref $clearing_chart eq 'SL::DB::Chart';
298

  
299
      # what does ptc say
300
      my %inv_calc = $self->calculate_prices_and_taxes();
301
      my @trans_ids = keys %{ $inv_calc{amounts} };
302
      die "Invalid state for advance payment more than one trans_id" if (scalar @trans_ids > 1);
303
      my $entry = delete $inv_calc{amounts}{$trans_ids[0]};
304
      my $tax;
305
      if ($entry->{tax_id}) {
306
        $tax = SL::DB::Manager::Tax->find_by(id => $entry->{tax_id}); # || die "Can't find tax with id " . $entry->{tax_id};
307
      }
308
      if ($tax and $tax->rate != 0) {
309
        my ($netamount, $taxamount);
310
        my $roundplaces = 2;
311
        # we dont have a clue about skonto, that's why we use $arap_amount as taxincluded
312
        ($netamount, $taxamount) = Form->calculate_tax($arap_amount, $tax->rate, 1, $roundplaces);
313
        # for debugging database set
314
        my $fullmatch = $netamount == $entry->{amount} ? '::netamount total true' : '';
315
        my $tax_booking= SL::DB::AccTransaction->new(trans_id   => $self->id,
316
                                                     chart_id   => $tax->chart_id,
317
                                                     chart_link => $tax->chart->link,
318
                                                     amount     => _round($taxamount),
319
                                                     transdate  => $transdate_obj,
320
                                                     source     => 'Automatic Tax Booking for Payment in Advance' . $fullmatch,
321
                                                     taxkey     => $tax->taxkey,
322
                                                     tax_id     => $tax->id);
323
        $tax_booking->save;
324
        push @new_acc_ids, $tax_booking->acc_trans_id;
325
        my $arap_tax_booking= SL::DB::AccTransaction->new(trans_id   => $self->id,
326
                                                     chart_id   => $clearing_chart->id,
327
                                                     chart_link => $clearing_chart->link,
328
                                                     amount     => _round($taxamount * -1),
329
                                                     transdate  => $transdate_obj,
330
                                                     source     => 'Automatic Tax Booking for Payment in Advance' . $fullmatch,
331
                                                     taxkey     => 0,
332
                                                     tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
333
        $arap_tax_booking->save;
334
        push @new_acc_ids, $arap_tax_booking->acc_trans_id;
335
      }
336
    }
293 337
    $fx_gain_loss_amount *= -1 if $self->is_sales;
294 338
    $self->paid($self->paid + _round($paid_amount) + $fx_gain_loss_amount) if $paid_amount;
295 339
    $self->datepaid($transdate_obj);

Auch abrufbar als: Unified diff