Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 915cb1a4

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

  • ID 915cb1a4ccd73c8795b5b5eb69d0719dfc331e59
  • Vorgänger 9271a8c6
  • Nachfolger 0f55816d

Mahnungen: Offene Gutschriften anzeigen und bei Auswahl gegen Offene Posten rechnen

Falls der Haken in der Übersicht gemacht wird, werden alle offenen
Gutschriften für den jeweiligen Kunden angezeigt. Wenn diese aktiviert
werden, werden diese Gutschriften für die jeweilige Mahnstufe ausgegeben.
Entsprechend wird die Summe der offenen Zahlung reduziert.
Offen: Im Mahnungsbericht werden die Mahnungen dann allerdings ohne
die Gutschriften angezeigt

Unterschiede anzeigen:

SL/DN.pm
346 346
  my ($send_email, $print_invoice) = (0, 0);
347 347

  
348 348
  foreach my $row (@{ $rows }) {
349
    if ($row->{credit_note}) {
350
      my $i = $row->{row};
351
      %{ $form->{LIST_CREDIT_NOTES}{$row->{customer_id}}{$row->{invoice_id}} } = (
352
        open_amount => $form->{"open_amount_$i"},
353
        amount      => $form->{"amount_$i"},
354
        invnumber   => $form->{"invnumber_$i"},
355
        invdate     => $form->{"invdate_$i"},
356
      );
357
      next;
358
    }
349 359
    push @invoice_ids, $row->{invoice_id};
350 360
    $next_dunning_config_id = $row->{next_dunning_config_id};
351 361
    $customer_id            = $row->{customer_id};
......
364 374
               $next_config_id, $next_config_id);
365 375
    do_statement($form, $h_insert_dunning, $q_insert_dunning, @values);
366 376
  }
377
  # die this transaction, because for this customer only credit notes are
378
  # selected ...
379
  return unless $customer_id;
367 380

  
368 381
  $h_update_ar->finish();
369 382
  $h_insert_dunning->finish();
......
580 593
  if (!$form->{l_include_direct_debit}) {
581 594
    $where .= qq| AND NOT COALESCE(a.direct_debit, FALSE) |;
582 595
  }
596
  my $paid = ($form->{l_include_credit_notes}) ? "WHERE (a.paid <> a.amount)" : "WHERE (a.paid < a.amount)";
583 597

  
584 598
  $query =
585 599
    qq|SELECT
......
628 642
         WHERE (d2.trans_id      = a.id)
629 643
           AND (d2.dunning_level = cfg.dunning_level)
630 644
       ))
631

  
632
       WHERE (a.paid < a.amount)
633
         AND (a.duedate < current_date)
645
        $paid
646
        AND (a.duedate < current_date)
634 647

  
635 648
       $where
636 649

  
......
641 654

  
642 655
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
643 656
    next if ($ref->{pastdue} < $ref->{terms});
644

  
657
    $ref->{credit_note} = 1 if ($ref->{amount} < 0 && $form->{l_include_credit_notes});
645 658
    $ref->{interest} = $form->round_amount($ref->{interest}, 2);
646 659
    push(@{ $form->{DUNNINGS} }, $ref);
647 660
  }
......
869 882
  }
870 883
  $sth->finish();
871 884

  
885
  # if we have some credit notes to add, do a safety check on the first customer id
886
  # and add one entry for each credit note
887
  if ($form->{LIST_CREDIT_NOTES} && $form->{LIST_CREDIT_NOTES}->{$form->{TEMPLATE_ARRAYS}->{"dn_customer_id"}[0]}) {
888
    my $first_customer_id = $form->{TEMPLATE_ARRAYS}->{"dn_customer_id"}[0];
889
    while ( my ($cred_id, $value) = each(%{ $form->{LIST_CREDIT_NOTES}->{$first_customer_id} } ) ) {
890
      map { push @{ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} }, $value->{$_} } keys %{ $value };
891
    }
892
  }
872 893
  $query =
873 894
    qq|SELECT
874 895
         c.id AS customer_id, c.name,         c.street,       c.zipcode,   c.city,
......
918 939
  $form->{interest_rate}     = $form->format_amount($myconfig, $ref->{interest_rate} * 100);
919 940
  $form->{fee}               = $form->format_amount($myconfig, $ref->{fee}, 2);
920 941
  $form->{total_interest}    = $form->format_amount($myconfig, $form->round_amount($ref->{total_interest}, 2), 2);
921
  $form->{total_open_amount} = $form->format_amount($myconfig, $form->round_amount($ref->{total_open_amount}, 2), 2);
922
  $form->{total_amount}      = $form->format_amount($myconfig, $form->round_amount($ref->{fee} + $ref->{total_interest} + $ref->{total_open_amount}, 2), 2);
942
  my $total_open_amount      = $ref->{total_open_amount};
943
  if ($form->{l_include_credit_notes}) {
944
    # a bit stupid, but redo calc because of credit notes
945
    $total_open_amount      = 0;
946
    foreach my $amount (@{ $form->{TEMPLATE_ARRAYS}->{dn_open_amount} }) {
947
      $total_open_amount += $form->parse_amount($myconfig, $amount, 2);
948
    }
949
  }
950
  $form->{total_open_amount} = $form->format_amount($myconfig, $form->round_amount($total_open_amount, 2), 2);
951
  $form->{total_amount}      = $form->format_amount($myconfig, $form->round_amount($ref->{fee} + $ref->{total_interest} + $total_open_amount, 2), 2);
923 952

  
924 953
  $::form->format_dates($output_dateformat, $output_longdates,
925 954
    qw(dn_dunning_date dn_dunning_duedate dn_transdate dn_duedate

Auch abrufbar als: Unified diff