Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b73ca44e

Von Bernd Bleßmann vor fast 3 Jahren hinzugefügt

  • ID b73ca44eeb471385d0f0d2e8ab4cf38961403580
  • Vorgänger 9c668ab9
  • Nachfolger 93de7a97

Anzahlungs-Rg.: Buchung: Sanity-Checks an einer Stelle zusammengefasst

Unterschiede anzeigen:

SL/IS.pm
36 36
package IS;
37 37

  
38 38
use List::Util qw(max sum0);
39
use List::MoreUtils qw(any);
39 40

  
40 41
use Carp;
41 42
use SL::AM;
......
1065 1066
  # entsprechend auch beim Bestimmen des Steuerschlüssels in Taxkey.pm berücksichtigen
1066 1067
  my $taxdate = $form->{tax_point} ||$form->{deliverydate} || $form->{invdate};
1067 1068

  
1069
  # Sanity checks for invoices for advance payment and final invoices
1070
  my $advance_payment_clearing_chart;
1071
  if (any { $_ eq $form->{type} } qw(invoice_for_advance_payment final_invoice)) {
1072
    $advance_payment_clearing_chart = SL::DB::Chart->new(id => $::instance_conf->get_advance_payment_clearing_chart_id)->load;
1073
    die "No Clearing Chart for Advance Payment" unless ref $advance_payment_clearing_chart eq 'SL::DB::Chart';
1074

  
1075
    my @current_taxaccounts = (split(/ /, $form->{taxaccounts}));
1076
    die 'Wrong call: Cannot post invoice for advance payment or final invoice with more than one tax' if (scalar @current_taxaccounts > 1);
1077

  
1078
    my @trans_ids = keys %{ $form->{amount} };
1079
    if (scalar @trans_ids > 1) {
1080
      require Data::Dumper;
1081
      die "Invalid state for advance payment more than one trans_id " . Dumper($form->{amount});
1082
    }
1083
  }
1084

  
1068 1085
  if (!$already_booked && $form->{type} eq 'final_invoice') {
1069 1086
    my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id});
1070 1087
    if (scalar @$invoices_for_advance_payment > 0) {
1071 1088
      # reverse booking for invoices for advance payment
1072
      my $clearing_chart = SL::DB::Chart->new(id => $::instance_conf->get_advance_payment_clearing_chart_id)->load;
1073
      die "No Clearing Chart for Advance Payment" unless ref $clearing_chart eq 'SL::DB::Chart';
1074 1089
      foreach my $invoice_for_advance_payment (@$invoices_for_advance_payment) {
1075 1090
        # delete ?
1076 1091
        # --> is implemented below (bookings are marked in memo field)
......
1086 1101
        #     if deletion of final invoice is allowed, reverting bookings in invoices
1087 1102
        #     for advance payment are allowed, too.
1088 1103
        # $booking->id, $self->id in helper table
1089
        $form->{amount}->{$invoice_for_advance_payment->id}->{$clearing_chart->accno} = -1 * $invoice_for_advance_payment->netamount;
1090
        $form->{memo}  ->{$invoice_for_advance_payment->id}->{$clearing_chart->accno} = 'reverse booking by final invoice';
1104
        $form->{amount}->{$invoice_for_advance_payment->id}->{$advance_payment_clearing_chart->accno} = -1 * $invoice_for_advance_payment->netamount;
1105
        $form->{memo}  ->{$invoice_for_advance_payment->id}->{$advance_payment_clearing_chart->accno} = 'reverse booking by final invoice';
1091 1106
        # AR
1092 1107
        $form->{amount}->{$invoice_for_advance_payment->id}->{$form->{AR}} = $invoice_for_advance_payment->netamount;
1093 1108
        $form->{memo}  ->{$invoice_for_advance_payment->id}->{$form->{AR}} = 'reverse booking by final invoice';
1094 1109
      }
1095 1110
    }
1096 1111
  }
1097
  if ($form->{type} eq 'invoice_for_advance_payment') {
1098
    # sanity and decomplex, allow only one tax rate
1099
    my $clearing_chart = SL::DB::Chart->new(id => $::instance_conf->get_advance_payment_clearing_chart_id)->load;
1100
    die "No Clearing Chart for Advance Payment" unless ref $clearing_chart eq 'SL::DB::Chart';
1101

  
1102
    my @current_taxaccounts = (split(/ /, $form->{taxaccounts}));
1103
    die 'Wrong Call, cannot post invoice for advance payment with more than one tax' if (scalar @current_taxaccounts > 1);
1104

  
1105
    my @trans_ids = keys %{ $form->{amount} };
1106
    if (scalar @trans_ids > 1) {
1107
      require Data::Dumper;
1108
      die "Invalid state for advance payment more than one trans_id " . Dumper($form->{amount});
1109
    }
1110 1112

  
1113
  if ($form->{type} eq 'invoice_for_advance_payment') {
1111 1114
    # get gross and move to clearing chart - delete everything else
1112 1115
    # 1. gross
1113
    my $gross = $form->{amount}{$trans_ids[0]}{$form->{AR}};
1116
    my $gross = $form->{amount}{ $form->{id} }{$form->{AR}};
1114 1117
    # 2. destroy
1115
    undef $form->{amount}{$trans_ids[0]};
1118
    undef $form->{amount}{ $form->{id} };
1116 1119
    # 3. rebuild
1117
    $form->{amount}{$trans_ids[0]}{$form->{AR}}            = $gross;
1118
    $form->{amount}{$trans_ids[0]}{$clearing_chart->accno} = $gross * -1;
1120
    $form->{amount}{ $form->{id} }{$form->{AR}}            = $gross;
1121
    $form->{amount}{ $form->{id} }{$advance_payment_clearing_chart->accno} = $gross * -1;
1119 1122
    # 4. no cogs, hopefully not commonly used at all
1120 1123
    undef $form->{amount_cogs};
1121 1124
  }

Auch abrufbar als: Unified diff