-        $row->{saldo}->{data} = $::form->format_amount(\%::myconfig,0, 2)."  ";
-      }
-      my $sum_cb = 0;
-      foreach my $acc ( @{ SL::DB::Manager::AccTransaction->get_all(where => [ chart_id => $chart->id, cb_transaction => 't',
-                                                                               transdate => { ge => $self->cb_startdate},
-                                                                               transdate => { le => $self->cb_date }]) }) {
-        $sum_cb += $acc->amount;
-      }
-      my $sum_ob = 0;
-      foreach my $acc ( @{ SL::DB::Manager::AccTransaction->get_all(where => [ chart_id => $chart->id, ob_transaction => 't',
-                                                                               transdate => { ge => $self->ob_date},
-                                                                               transdate => { le => $ob_next_date }]) }) {
-        $sum_ob += $acc->amount;
-      }
-      if ( $sum_cb > 0 ) {
-        $row->{sum_cb}->{data} = $::form->format_amount(\%::myconfig, $sum_cb, 2)." H";
-      } elsif ( $sum_cb < 0 )  {
-        $row->{sum_cb}->{data} = $::form->format_amount(\%::myconfig,-$sum_cb, 2)." S";
+        # $main::lxdebug->message(0, sprintf("adding accno %s with balance %s to credit", $asset_account->{accno}, $asset_account->{amount_with_cb}));
+        $credit_balance += $asset_account->{amount_with_cb};
+
+        $asset_cb_credit_entry->add_chart_booking(
+          chart  => $ass_acc,
+          debit  => $asset_account->{amount_with_cb},
+          tax_id => 0
+        );
+        $asset_ob_credit_entry->add_chart_booking(
+          chart  => $ass_acc,
+          credit  => $asset_account->{amount_with_cb},
+          tax_id => 0
+        );
+      };
+    };
+
+    if ( $debit_balance ) {
+      $asset_cb_debit_entry->add_chart_booking(
+        chart  => $carry_over_chart,
+        debit  => -1 * $debit_balance,
+        tax_id => 0,
+      );
+
+      $asset_ob_debit_entry->add_chart_booking(
+        chart  => $carry_over_chart,
+        credit => -1 * $debit_balance,
+        tax_id => 0,
+      );
+    };
+
+    if ( $credit_balance ) {
+      $asset_cb_credit_entry->add_chart_booking(
+        chart  => $carry_over_chart,
+        credit => $credit_balance,
+        tax_id => 0,
+      );
+      $asset_ob_credit_entry->add_chart_booking(
+        chart  => $carry_over_chart,
+        debit  => $credit_balance,
+        tax_id => 0,
+      );
+    };
+
+    $asset_cb_debit_entry->post  if scalar @{ $asset_cb_debit_entry->transactions  } > 1;
+    $asset_ob_debit_entry->post  if scalar @{ $asset_ob_debit_entry->transactions  } > 1;
+    $asset_cb_credit_entry->post if scalar @{ $asset_cb_credit_entry->transactions } > 1;
+    $asset_ob_credit_entry->post if scalar @{ $asset_ob_credit_entry->transactions } > 1;
+
+    #######  profit-loss accounts #######
+    # these only have a closing balance, the balance is transferred to the profit-loss account
+
+    # need to know if profit or loss first!
+    # use amount_with_cb, so it can be run several times. So sum may be 0 the second time.
+    my $profit_loss_sum = sum map { $_->{amount_with_cb} }
+                              grep { $_->{account_type} eq 'profit_loss_account' }
+                              @{$report_data};
+    $profit_loss_sum ||= 0;
+    my $pl_chart;
+    if ( $profit_loss_sum > 0 ) {
+      $pl_chart = $profit_chart;
+    } else {
+      $pl_chart = $loss_chart;
+    };
+
+    my $pl_debit_balance  = 0;
+    my $pl_credit_balance = 0;
+    # soll = debit, haben = credit
+    my $pl_cb_debit_entry = SL::DB::GLTransaction->new(
+      employee_id    => $employee_id,
+      transdate      => $cb_date,
+      reference      => 'SB ' . $cb_date->year,
+      description    => 'Automatische SB-Buchungen Erfolgskonten Soll für ' . $cb_date->year,
+      ob_transaction => 0,
+      cb_transaction => 1,
+      taxincluded    => 0,
+      transactions   => [],
+    );
+    my $pl_cb_credit_entry = SL::DB::GLTransaction->new(
+      employee_id    => $employee_id,
+      transdate      => $cb_date,
+      reference      => 'SB ' . $cb_date->year,
+      description    => 'Automatische SB-Buchungen Erfolgskonten Haben für ' . $cb_date->year,
+      ob_transaction => 0,
+      cb_transaction => 1,
+      taxincluded    => 0,
+      transactions   => [],
+    );
+
+    foreach my $profit_loss_account ( @profit_loss_accounts ) {
+      # $main::lxdebug->message(0, sprintf("found chart %s with balance %s", $profit_loss_account->{accno}, $profit_loss_account->{amount_with_cb}));
+      my $chart = $charts_by_id{ $profit_loss_account->{chart_id} };
+
+      next if $profit_loss_account->{amount_with_cb} == 0;
+
+      if ( $profit_loss_account->{amount_with_cb} < 0 ) {
+        $pl_debit_balance -= $profit_loss_account->{amount_with_cb};
+        $pl_cb_debit_entry->add_chart_booking(
+          chart  => $chart,
+          tax_id => 0,
+          credit => - $profit_loss_account->{amount_with_cb},
+        );