Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 86bb04e4

Von Andreas Rudin vor 9 Monaten hinzugefügt

  • ID 86bb04e41f0df71515b17ff5221d317861c967b6
  • Vorgänger b0c61725
  • Nachfolger d2ec2817

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
- Alle Konten als Abschlusskonten auswählbar
- Verbuchen des Jahresgewinns oder -verlusts nur bei den Eröffnungsbuchungen

Unterschiede anzeigen:

SL/Controller/YearEndTransactions.pm
12 12
use Data::Dumper;
13 13
use List::Util qw(sum);
14 14
use SL::ClientJS;
15
use SL::DB::Default;
15 16

  
16 17
use SL::DB::Chart;
17 18
use SL::DB::GLTransaction;
......
20 21
use SL::DB::Helper::AccountingPeriod qw(get_balance_starting_date get_balance_startdate_method_options);
21 22

  
22 23
use Rose::Object::MakeMethods::Generic (
23
  'scalar --get_set_init' => [ qw(cb_date cb_startdate ob_date) ],
24
  'scalar --get_set_init' => [ qw(cb_date cb_startdate ob_date defaults) ],
24 25
);
25 26

  
26 27
__PACKAGE__->run_before('check_auth');
......
30 31

  
31 32
  $self->cb_startdate($::locale->parse_date_to_object($self->get_balance_starting_date($self->cb_date)));
32 33

  
33
  my $defaults         = SL::DB::Default->get;
34
  my $carry_over_chart = SL::DB::Manager::Chart->find_by( id => $defaults->carry_over_account_chart_id     );
35
  my $profit_chart     = SL::DB::Manager::Chart->find_by( id => $defaults->profit_carried_forward_chart_id );
36
  my $loss_chart       = SL::DB::Manager::Chart->find_by( id => $defaults->loss_carried_forward_chart_id   );
34
  my $carry_over_chart = SL::DB::Manager::Chart->find_by( id => $self->defaults->carry_over_account_chart_id     );
35
  my $profit_chart     = SL::DB::Manager::Chart->find_by( id => $self->defaults->profit_carried_forward_chart_id );
36
  my $loss_chart       = SL::DB::Manager::Chart->find_by( id => $self->defaults->loss_carried_forward_chart_id   );
37 37

  
38 38
  $self->render('yearend/form',
39 39
                title                            => t8('Year-end closing'),
......
50 50
  $self->_parse_form;
51 51

  
52 52
  eval {
53
    _year_end_bookings( start_date => $self->cb_startdate,
53
    $self->_year_end_bookings( start_date => $self->cb_startdate,
54 54
                        cb_date    => $self->cb_date,
55 55
                      );
56 56
    1;
......
59 59
    return $self->js->render;
60 60
  };
61 61

  
62
  my ($report_data, $profit_loss_sum) = _report(
62
  my ($report_data, $profit_loss_sum) = $self->_report(
63 63
                                                cb_date    => $self->cb_date,
64 64
                                                start_date => $self->cb_startdate,
65 65
                                               );
......
98 98

  
99 99
  $self->_parse_form;
100 100

  
101
  my ($report_data, $profit_loss_sum) = _report(
101
  my ($report_data, $profit_loss_sum) = $self->_report(
102 102
                                                cb_date   => $self->cb_date,
103 103
                                                start_date => $self->cb_startdate,
104 104
                                               );
......
123 123
}
124 124

  
125 125
sub _year_end_bookings {
126
  my (%params) = @_;
126
  my ($self, %params) = @_;
127 127

  
128 128
  my $start_date = delete $params{start_date};
129 129
  my $cb_date    = delete $params{cb_date};
130 130

  
131
  my $defaults         = SL::DB::Default->get;
132
  my $carry_over_chart = SL::DB::Manager::Chart->find_by( id => $defaults->carry_over_account_chart_id     ) // die t8('No carry-over chart configured!');
133
  my $profit_chart     = SL::DB::Manager::Chart->find_by( id => $defaults->profit_carried_forward_chart_id ) // die t8('No profit carried forward chart configured!');
134
  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!');
131
  my $carry_over_chart = SL::DB::Manager::Chart->find_by( id => $self->defaults->carry_over_account_chart_id     ) // die t8('No carry-over chart configured!');
132
  my $profit_chart     = SL::DB::Manager::Chart->find_by( id => $self->defaults->profit_carried_forward_chart_id ) // die t8('No profit carried forward chart configured!');
133
  my $loss_chart;
134
  if ( $self->defaults->yearend_method eq 'simple' ) {
135
    $loss_chart       = $profit_chart;
136
  } else {
137
    $loss_chart     = SL::DB::Manager::Chart->find_by( id => $self->defaults->loss_carried_forward_chart_id   ) // die t8('No profit and loss carried forward chart configured!');
138
  }
135 139

  
136
  my ($report_data, $profit_loss_sum) = _report(
140
  my ($report_data, $profit_loss_sum) = $self->_report(
137 141
                                                start_date => $start_date,
138 142
                                                cb_date    => $cb_date,
139 143
                                               );
......
288 292
                              @{$report_data};
289 293
    $profit_loss_sum ||= 0;
290 294
    my $pl_chart;
291
    if ( $profit_loss_sum > 0 ) {
295
    if ( $profit_loss_sum > 0 || $self->defaults->yearend_method eq 'simple' ) {
292 296
      $pl_chart = $profit_chart;
293 297
    } else {
294 298
      $pl_chart = $loss_chart;
......
297 301
    my $pl_debit_balance  = 0;
298 302
    my $pl_credit_balance = 0;
299 303
    # soll = debit, haben = credit
300
    my $pl_cb_debit_entry = SL::DB::GLTransaction->new(
301
      employee_id    => $employee_id,
302
      transdate      => $cb_date,
303
      reference      => 'SB ' . $cb_date->year,
304
      description    => 'Automatische SB-Buchungen Erfolgskonten Soll für ' . $cb_date->year,
305
      ob_transaction => 0,
306
      cb_transaction => 1,
307
      taxincluded    => 0,
308
      transactions   => [],
309
    );
310
    my $pl_cb_credit_entry = SL::DB::GLTransaction->new(
311
      employee_id    => $employee_id,
312
      transdate      => $cb_date,
313
      reference      => 'SB ' . $cb_date->year,
314
      description    => 'Automatische SB-Buchungen Erfolgskonten Haben für ' . $cb_date->year,
315
      ob_transaction => 0,
316
      cb_transaction => 1,
317
      taxincluded    => 0,
318
      transactions   => [],
319
    );
320

  
321
    foreach my $profit_loss_account ( @profit_loss_accounts ) {
322
      # $main::lxdebug->message(0, sprintf("found chart %s with balance %s", $profit_loss_account->{accno}, $profit_loss_account->{amount_with_cb}));
323
      my $chart = $charts_by_id{ $profit_loss_account->{chart_id} };
324

  
325
      next if $profit_loss_account->{amount_with_cb} == 0;
304
    if ( $self->defaults->yearend_method ne 'simple' ) {
305
      my $pl_cb_debit_entry = SL::DB::GLTransaction->new(
306
        employee_id    => $employee_id,
307
        transdate      => $cb_date,
308
        reference      => 'SB ' . $cb_date->year,
309
        description    => 'Automatische SB-Buchungen Erfolgskonten Soll für ' . $cb_date->year,
310
        ob_transaction => 0,
311
        cb_transaction => 1,
312
        taxincluded    => 0,
313
        transactions   => [],
314
      );
315
      my $pl_cb_credit_entry = SL::DB::GLTransaction->new(
316
        employee_id    => $employee_id,
317
        transdate      => $cb_date,
318
        reference      => 'SB ' . $cb_date->year,
319
        description    => 'Automatische SB-Buchungen Erfolgskonten Haben für ' . $cb_date->year,
320
        ob_transaction => 0,
321
        cb_transaction => 1,
322
        taxincluded    => 0,
323
        transactions   => [],
324
      );
326 325

  
327
      if ( $profit_loss_account->{amount_with_cb} < 0 ) {
328
        $pl_debit_balance -= $profit_loss_account->{amount_with_cb};
329
        $pl_cb_debit_entry->add_chart_booking(
330
          chart  => $chart,
331
          tax_id => 0,
332
          credit => - $profit_loss_account->{amount_with_cb},
333
        );
334
      } else {
335
        $pl_credit_balance += $profit_loss_account->{amount_with_cb};
336
        $pl_cb_credit_entry->add_chart_booking(
337
          chart  => $chart,
338
          tax_id => 0,
339
          debit  => $profit_loss_account->{amount_with_cb},
340
        );
326
      foreach my $profit_loss_account ( @profit_loss_accounts ) {
327
        # $main::lxdebug->message(0, sprintf("found chart %s with balance %s", $profit_loss_account->{accno}, $profit_loss_account->{amount_with_cb}));
328
        my $chart = $charts_by_id{ $profit_loss_account->{chart_id} };
329

  
330
        next if $profit_loss_account->{amount_with_cb} == 0;
331

  
332
        if ( $profit_loss_account->{amount_with_cb} < 0 ) {
333
          $pl_debit_balance -= $profit_loss_account->{amount_with_cb};
334
          $pl_cb_debit_entry->add_chart_booking(
335
            chart  => $chart,
336
            tax_id => 0,
337
            credit => - $profit_loss_account->{amount_with_cb},
338
          );
339
        } else {
340
          $pl_credit_balance += $profit_loss_account->{amount_with_cb};
341
          $pl_cb_credit_entry->add_chart_booking(
342
            chart  => $chart,
343
            tax_id => 0,
344
            debit  => $profit_loss_account->{amount_with_cb},
345
          );
346
        };
341 347
      };
342
    };
343

  
344
    # $main::lxdebug->message(0, "pl_debit_balance  = $pl_debit_balance");
345
    # $main::lxdebug->message(0, "pl_credit_balance = $pl_credit_balance");
346 348

  
347
    $pl_cb_debit_entry->add_chart_booking(
348
      chart  => $pl_chart,
349
      tax_id => 0,
350
      debit  => $pl_debit_balance,
351
    ) if $pl_debit_balance;
349
      # $main::lxdebug->message(0, "pl_debit_balance  = $pl_debit_balance");
350
      # $main::lxdebug->message(0, "pl_credit_balance = $pl_credit_balance");
352 351

  
353
    $pl_cb_credit_entry->add_chart_booking(
354
      chart  => $pl_chart,
355
      tax_id => 0,
356
      credit => $pl_credit_balance,
357
    ) if $pl_credit_balance;
352
      $pl_cb_debit_entry->add_chart_booking(
353
        chart  => $pl_chart,
354
        tax_id => 0,
355
        debit  => $pl_debit_balance,
356
      ) if $pl_debit_balance;
358 357

  
359
    # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_debit_entry->transactions };
360
    # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_credit_entry->transactions };
358
      $pl_cb_credit_entry->add_chart_booking(
359
        chart  => $pl_chart,
360
        tax_id => 0,
361
        credit => $pl_credit_balance,
362
      ) if $pl_credit_balance;
361 363

  
362
    $pl_cb_debit_entry->post  if scalar @{ $pl_cb_debit_entry->transactions }  > 1;
363
    $pl_cb_credit_entry->post if scalar @{ $pl_cb_credit_entry->transactions } > 1;
364
      # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_debit_entry->transactions };
365
      # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $pl_cb_credit_entry->transactions };
364 366

  
367
      $pl_cb_debit_entry->post  if scalar @{ $pl_cb_debit_entry->transactions }  > 1;
368
      $pl_cb_credit_entry->post if scalar @{ $pl_cb_credit_entry->transactions } > 1;
369
    };
365 370
    ######### profit-loss transfer #########
366 371
    # and finally transfer the new balance of the profit-loss account via the carry-over account
367 372
    # we want to use profit_loss_sum with cb!
368 373

  
369 374
    if ( $profit_loss_sum != 0 ) {
370

  
371
      my $carry_over_cb_entry = SL::DB::GLTransaction->new(
372
        employee_id    => $employee_id,
373
        transdate      => $cb_date,
374
        reference      => 'SB ' . $cb_date->year,
375
        description    => sprintf('Automatische SB-Buchung für %s %s',
376
                                  $profit_loss_sum >= 0 ? 'Gewinnvortrag' : 'Verlustvortrag',
377
                                  $cb_date->year,
378
                                 ),
379
        ob_transaction => 0,
380
        cb_transaction => 1,
381
        taxincluded    => 0,
382
        transactions   => [],
383
      );
375
      my $carry_over_cb_entry;
376
      if ($self->defaults->yearend_method ne 'simple') {
377
        $carry_over_cb_entry = SL::DB::GLTransaction->new(
378
          employee_id    => $employee_id,
379
          transdate      => $cb_date,
380
          reference      => 'SB ' . $cb_date->year,
381
          description    => sprintf('Automatische SB-Buchung für %s %s',
382
                                    $profit_loss_sum >= 0 ? 'Gewinnvortrag' : 'Verlustvortrag',
383
                                    $cb_date->year,
384
                                   ),
385
          ob_transaction => 0,
386
          cb_transaction => 1,
387
          taxincluded    => 0,
388
          transactions   => [],
389
        );
390
      };
384 391
      my $carry_over_ob_entry = SL::DB::GLTransaction->new(
385 392
        employee_id    => $employee_id,
386 393
        transdate      => $ob_date,
......
404 411
        $amount2 = 'debit';
405 412
      };
406 413

  
407
      $carry_over_cb_entry->add_chart_booking(
408
        chart    => $carry_over_chart,
409
        tax_id   => 0,
410
        $amount1 => abs($profit_loss_sum),
411
      );
412
      $carry_over_cb_entry->add_chart_booking(
413
        chart    => $pl_chart,
414
        tax_id   => 0,
415
        $amount2 => abs($profit_loss_sum),
416
      );
414
      if ($self->defaults->yearend_method ne 'simple') {
415
        $carry_over_cb_entry->add_chart_booking(
416
          chart    => $carry_over_chart,
417
          tax_id   => 0,
418
          $amount1 => abs($profit_loss_sum),
419
        );
420
        $carry_over_cb_entry->add_chart_booking(
421
          chart    => $pl_chart,
422
          tax_id   => 0,
423
          $amount2 => abs($profit_loss_sum),
424
        );
425
      };
417 426
      $carry_over_ob_entry->add_chart_booking(
418 427
        chart    => $carry_over_chart,
419 428
        tax_id   => 0,
......
428 437
      # printf("debit : %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $carry_over_ob_entry->transactions };
429 438
      # printf("credit: %s -> %s\n", $_->chart->displayable_name, $_->amount) foreach @{ $carry_over_ob_entry->transactions };
430 439

  
431
      $carry_over_cb_entry->post if scalar @{ $carry_over_cb_entry->transactions } > 1;
440
      if ($self->defaults->yearend_method ne 'simple') {
441
        $carry_over_cb_entry->post if scalar @{ $carry_over_cb_entry->transactions } > 1;
442
      };
432 443
      $carry_over_ob_entry->post if scalar @{ $carry_over_ob_entry->transactions } > 1;
433 444
    };
434 445

  
......
449 460
}
450 461

  
451 462
sub _report {
452
  my (%params) = @_;
463
  my ($self, %params) = @_;
453 464

  
454 465
  my $start_date = delete $params{start_date};
455 466
  my $cb_date    = delete $params{cb_date};
456 467

  
457
  my $defaults = SL::DB::Default->get;
458 468
  die "no carry over account defined"
459
    unless defined $defaults->carry_over_account_chart_id
460
           and $defaults->carry_over_account_chart_id > 0;
469
    unless defined $self->defaults->carry_over_account_chart_id
470
           and $self->defaults->carry_over_account_chart_id > 0;
461 471

  
462 472
  my $salden_query = <<SQL;
463 473
select c.id as chart_id,
......
486 496
  my $report = selectall_hashref_query($::form, $dbh, $salden_query,
487 497
                                       $start_date,
488 498
                                       $cb_date,
489
                                       $defaults->carry_over_account_chart_id,
499
                                       $self->defaults->carry_over_account_chart_id,
490 500
                                      );
491 501
  # profit_loss_sum is the actual profit/loss for the year, without cb, use "amount_without_cb")
492 502
  my $profit_loss_sum = sum map { $_->{amount_without_cb} }
......
512 522
sub init_ob_date        { $::locale->parse_date_to_object($::form->{ob_date})      }
513 523
sub init_cb_startdate   { $::locale->parse_date_to_object($::form->{cb_startdate}) }
514 524
sub init_cb_date        { $::locale->parse_date_to_object($::form->{cb_date})      }
515

  
525
sub init_defaults       { SL::DB::Default->get }
516 526
1;

Auch abrufbar als: Unified diff