Revision c648487a
Von Andreas Rudin vor etwa 1 Jahr hinzugefügt
- ID c648487ad906252da91494510e501c002e429322
- Vorgänger 64ed077b
| SL/Controller/YearEndTransactions.pm | ||
|---|---|---|
| use Data::Dumper;
 | ||
| use List::Util qw(sum);
 | ||
| use SL::ClientJS;
 | ||
| use SL::DB::Default;
 | ||
|  | ||
| use SL::DB::Chart;
 | ||
| use SL::DB::GLTransaction;
 | ||
| ... | ... | |
| use SL::DB::Helper::AccountingPeriod qw(get_balance_starting_date get_balance_startdate_method_options);
 | ||
|  | ||
| use Rose::Object::MakeMethods::Generic (
 | ||
|   'scalar --get_set_init' => [ qw(cb_date cb_startdate ob_date) ],
 | ||
|   'scalar --get_set_init' => [ qw(cb_date cb_startdate ob_date defaults) ],
 | ||
| );
 | ||
|  | ||
| __PACKAGE__->run_before('check_auth');
 | ||
| ... | ... | |
|   my $defaults         = SL::DB::Default->get;
 | ||
|   my $carry_over_chart = SL::DB::Manager::Chart->find_by( id => $defaults->carry_over_account_chart_id     ) // die t8('No carry-over chart configured!');
 | ||
|   my $profit_chart     = SL::DB::Manager::Chart->find_by( id => $defaults->profit_carried_forward_chart_id ) // die t8('No profit carried forward chart configured!');
 | ||
|   my $loss_chart       = SL::DB::Manager::Chart->find_by( id => $defaults->loss_carried_forward_chart_id   ) // die t8('No profit and loss carried forward chart configured!');
 | ||
|   my $loss_chart;
 | ||
|   if ( $defaults->yearend_method eq 'simple') {
 | ||
|     $loss_chart       = $profit_chart;
 | ||
|   } else {
 | ||
|     $loss_chart     = SL::DB::Manager::Chart->find_by( id => $defaults->loss_carried_forward_chart_id   ) // die t8('No profit and loss carried forward chart configured!');
 | ||
|   }
 | ||
|  | ||
|   my ($report_data, $profit_loss_sum) = _report(
 | ||
|                                                 start_date => $start_date,
 | ||
| ... | ... | |
|                               @{$report_data};
 | ||
|     $profit_loss_sum ||= 0;
 | ||
|     my $pl_chart;
 | ||
|     if ( $profit_loss_sum > 0 ) {
 | ||
|     if ( $profit_loss_sum > 0 || $defaults->yearend_method eq 'simple') {
 | ||
|       $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 ($defaults->yearend_method ne 'simple') {
 | ||
|       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   => [],
 | ||
|       );
 | ||
|  | ||
|       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},
 | ||
|         );
 | ||
|       } else {
 | ||
|         $pl_credit_balance += $profit_loss_account->{amount_with_cb};
 | ||
|         $pl_cb_credit_entry->add_chart_booking(
 | ||
|           chart  => $chart,
 | ||
|           tax_id => 0,
 | ||
|           debit  => $profit_loss_account->{amount_with_cb},
 | ||
|         );
 | ||
|       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},
 | ||
|           );
 | ||
|         } else {
 | ||
|           $pl_credit_balance += $profit_loss_account->{amount_with_cb};
 | ||
|           $pl_cb_credit_entry->add_chart_booking(
 | ||
|             chart  => $chart,
 | ||
|             tax_id => 0,
 | ||
|             debit  => $profit_loss_account->{amount_with_cb},
 | ||
|           );
 | ||
|         };
 | ||
|       };
 | ||
|     };
 | ||
|  | ||
|     # $main::lxdebug->message(0, "pl_debit_balance  = $pl_debit_balance");
 | ||
|     # $main::lxdebug->message(0, "pl_credit_balance = $pl_credit_balance");
 | ||
|  | ||
|     $pl_cb_debit_entry->add_chart_booking(
 | ||
|       chart  => $pl_chart,
 | ||
|       tax_id => 0,
 | ||
|       debit  => $pl_debit_balance,
 | ||
|     ) if $pl_debit_balance;
 | ||
|       # $main::lxdebug->message(0, "pl_debit_balance  = $pl_debit_balance");
 | ||
|       # $main::lxdebug->message(0, "pl_credit_balance = $pl_credit_balance");
 | ||
|  | ||
|     $pl_cb_credit_entry->add_chart_booking(
 | ||
|       chart  => $pl_chart,
 | ||
|       tax_id => 0,
 | ||
|       credit => $pl_credit_balance,
 | ||
|     ) if $pl_credit_balance;
 | ||
|       $pl_cb_debit_entry->add_chart_booking(
 | ||
|         chart  => $pl_chart,
 | ||
|         tax_id => 0,
 | ||
|         debit  => $pl_debit_balance,
 | ||
|       ) if $pl_debit_balance;
 | ||
|  | ||
|     # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_debit_entry->transactions };
 | ||
|     # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_credit_entry->transactions };
 | ||
|       $pl_cb_credit_entry->add_chart_booking(
 | ||
|         chart  => $pl_chart,
 | ||
|         tax_id => 0,
 | ||
|         credit => $pl_credit_balance,
 | ||
|       ) if $pl_credit_balance;
 | ||
|  | ||
|     $pl_cb_debit_entry->post  if scalar @{ $pl_cb_debit_entry->transactions }  > 1;
 | ||
|     $pl_cb_credit_entry->post if scalar @{ $pl_cb_credit_entry->transactions } > 1;
 | ||
|       # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_debit_entry->transactions };
 | ||
|       # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_credit_entry->transactions };
 | ||
|  | ||
|       $pl_cb_debit_entry->post  if scalar @{ $pl_cb_debit_entry->transactions }  > 1;
 | ||
|       $pl_cb_credit_entry->post if scalar @{ $pl_cb_credit_entry->transactions } > 1;
 | ||
|     };
 | ||
|     ######### profit-loss transfer #########
 | ||
|     # and finally transfer the new balance of the profit-loss account via the carry-over account
 | ||
|     # we want to use profit_loss_sum with cb!
 | ||
|  | ||
|     if ( $profit_loss_sum != 0 ) {
 | ||
|  | ||
|       my $carry_over_cb_entry = SL::DB::GLTransaction->new(
 | ||
|         employee_id    => $employee_id,
 | ||
|         transdate      => $cb_date,
 | ||
|         reference      => 'SB ' . $cb_date->year,
 | ||
|         description    => sprintf('Automatische SB-Buchung für %s %s',
 | ||
|                                   $profit_loss_sum >= 0 ? 'Gewinnvortrag' : 'Verlustvortrag',
 | ||
|                                   $cb_date->year,
 | ||
|                                  ),
 | ||
|         ob_transaction => 0,
 | ||
|         cb_transaction => 1,
 | ||
|         taxincluded    => 0,
 | ||
|         transactions   => [],
 | ||
|       );
 | ||
|       my $carry_over_cb_entry;
 | ||
|       if ($defaults->yearend_method ne 'simple') {
 | ||
|         $carry_over_cb_entry = SL::DB::GLTransaction->new(
 | ||
|           employee_id    => $employee_id,
 | ||
|           transdate      => $cb_date,
 | ||
|           reference      => 'SB ' . $cb_date->year,
 | ||
|           description    => sprintf('Automatische SB-Buchung für %s %s',
 | ||
|                                     $profit_loss_sum >= 0 ? 'Gewinnvortrag' : 'Verlustvortrag',
 | ||
|                                     $cb_date->year,
 | ||
|                                    ),
 | ||
|           ob_transaction => 0,
 | ||
|           cb_transaction => 1,
 | ||
|           taxincluded    => 0,
 | ||
|           transactions   => [],
 | ||
|         );
 | ||
|       };
 | ||
|       my $carry_over_ob_entry = SL::DB::GLTransaction->new(
 | ||
|         employee_id    => $employee_id,
 | ||
|         transdate      => $ob_date,
 | ||
| ... | ... | |
|         $amount2 = 'debit';
 | ||
|       };
 | ||
|  | ||
|       $carry_over_cb_entry->add_chart_booking(
 | ||
|         chart    => $carry_over_chart,
 | ||
|         tax_id   => 0,
 | ||
|         $amount1 => abs($profit_loss_sum),
 | ||
|       );
 | ||
|       $carry_over_cb_entry->add_chart_booking(
 | ||
|         chart    => $pl_chart,
 | ||
|         tax_id   => 0,
 | ||
|         $amount2 => abs($profit_loss_sum),
 | ||
|       );
 | ||
|       if ($defaults->yearend_method ne 'simple') {
 | ||
|         $carry_over_cb_entry->add_chart_booking(
 | ||
|           chart    => $carry_over_chart,
 | ||
|           tax_id   => 0,
 | ||
|           $amount1 => abs($profit_loss_sum),
 | ||
|         );
 | ||
|         $carry_over_cb_entry->add_chart_booking(
 | ||
|           chart    => $pl_chart,
 | ||
|           tax_id   => 0,
 | ||
|           $amount2 => abs($profit_loss_sum),
 | ||
|         );
 | ||
|       };
 | ||
|       $carry_over_ob_entry->add_chart_booking(
 | ||
|         chart    => $carry_over_chart,
 | ||
|         tax_id   => 0,
 | ||
| ... | ... | |
|       # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $carry_over_ob_entry->transactions };
 | ||
|       # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $carry_over_ob_entry->transactions };
 | ||
|  | ||
|       $carry_over_cb_entry->post if scalar @{ $carry_over_cb_entry->transactions } > 1;
 | ||
|       if ($defaults->yearend_method ne 'simple') {
 | ||
|         $carry_over_cb_entry->post if scalar @{ $carry_over_cb_entry->transactions } > 1;
 | ||
|       };
 | ||
|       $carry_over_ob_entry->post if scalar @{ $carry_over_ob_entry->transactions } > 1;
 | ||
|     };
 | ||
|  | ||
| ... | ... | |
| sub init_ob_date        { $::locale->parse_date_to_object($::form->{ob_date})      }
 | ||
| sub init_cb_startdate   { $::locale->parse_date_to_object($::form->{cb_startdate}) }
 | ||
| sub init_cb_date        { $::locale->parse_date_to_object($::form->{cb_date})      }
 | ||
|  | ||
| sub init_defaults       { SL::DB::Default->get }
 | ||
| 1;
 | ||
Auch abrufbar als: Unified diff
Vereinfachte Methode beim Jahresabschluss
- Nur 2 statt 3 Konten bei den Jahresabschluss-Standardkonten:
Jahresabschluss-Konto und
Konto zum Verbuchen des Jahresgewinns oder
verlusts
Keine Abschlussbuchungen bei den Erfolgskonten- Auswahl der Methode in der Mandantenkonfiguration unter Buchungskonfiguration