Revision dfcefa49
Von Kivitendo Admin vor fast 11 Jahren hinzugefügt
SL/RP.pm | ||
---|---|---|
50 | 50 |
# - proper testing for heading charts |
51 | 51 |
# - transmission from $form to TMPL realm is not as clear as i'd like |
52 | 52 |
|
53 |
sub get_openbalance_date { |
|
54 |
my ($closedto, $target) = map { $::locale->parse_date_to_object(\%::myconfig, $_) } @_; |
|
53 |
sub get_balance_starting_date { |
|
55 | 54 |
|
56 |
return unless $closedto; |
|
55 |
# determine date from which the balance is calculated. The method is |
|
56 |
# configured in the client configuration. |
|
57 | 57 |
|
58 |
$closedto->subtract(years => 1) while ($target - $closedto)->is_negative; |
|
59 |
$closedto->add(days => 1); |
|
60 |
return $::locale->format_date(\%::myconfig, $closedto); |
|
61 |
} |
|
58 |
my $asofdate = shift; |
|
59 |
return unless $asofdate; |
|
60 |
|
|
61 |
$asofdate = $::locale->parse_date_to_object(\%::myconfig, $asofdate); |
|
62 |
|
|
63 |
my $form = $main::form; |
|
64 |
my $dbh = $::form->get_standard_dbh; |
|
65 |
|
|
66 |
my $startdate_method = $::instance_conf->get_balance_startdate_method; |
|
67 |
|
|
68 |
# We could use the following objects to determine the starting date for |
|
69 |
# calculating the balance from asofdate (the reference date for the balance): |
|
70 |
# * start_of_year - 1.1., no deviating fiscal year supported |
|
71 |
# * closed_to - all transactions since the books were last closed |
|
72 |
# * last_ob - all transactions since last opening balance transaction (usually 1.1.) |
|
73 |
# * mindate - all transactions in database |
|
74 |
|
|
75 |
my $start_of_year = $asofdate->clone(); |
|
76 |
$start_of_year->set_day(1); |
|
77 |
$start_of_year->set_month(1); |
|
78 |
|
|
79 |
# closedto assumes that we only close the books at the end of a fiscal year, |
|
80 |
# never during the fiscal year. If this assumption is valid closedto should |
|
81 |
# also work for deviating fiscal years. But as the trial balance (SuSa) |
|
82 |
# doesn't yet deal with deviating fiscal years, and is useful to also close |
|
83 |
# the books after a month has been exported via DATEV, so this method of |
|
84 |
# determining the starting date isn't recommended and has been removed as |
|
85 |
# default. |
|
86 |
my ($closedto) = selectfirst_array_query($form, $dbh, 'SELECT closedto FROM defaults'); |
|
87 |
if ($closedto) { |
|
88 |
$closedto = $::locale->parse_date_to_object(\%::myconfig, $closedto); |
|
89 |
$closedto->subtract(years => 1) while ($asofdate - $closedto)->is_negative; |
|
90 |
$closedto->add(days => 1); |
|
91 |
}; |
|
92 |
|
|
93 |
my ($query, $startdate, $last_ob, $mindate); |
|
94 |
$query = qq|select max(transdate) from acc_trans where ob_transaction is true and transdate <= ?|; |
|
95 |
($last_ob) = selectrow_query($::form, $dbh, $query, $::locale->format_date(\%::myconfig, $asofdate)); |
|
96 |
$last_ob = $::locale->parse_date_to_object(\%::myconfig, $last_ob) if $last_ob; |
|
97 |
|
|
98 |
$query = qq|select min(transdate) from acc_trans|; |
|
99 |
($mindate) = selectrow_query($::form, $dbh, $query); |
|
100 |
$mindate = $::locale->parse_date_to_object(\%::myconfig, $mindate); |
|
101 |
|
|
102 |
# the default method is to use all transactions ($mindate) |
|
103 |
|
|
104 |
if ( $startdate_method eq 'closed_to' and $closedto ) { |
|
105 |
# if no closedto is configured use default |
|
106 |
return $::locale->format_date(\%::myconfig, $closedto); |
|
107 |
|
|
108 |
} elsif ( $startdate_method eq 'start_of_year' ) { |
|
109 |
|
|
110 |
return $::locale->format_date(\%::myconfig, $start_of_year); |
|
111 |
|
|
112 |
} elsif ( $startdate_method eq 'all_transactions' ) { |
|
113 |
|
|
114 |
return $::locale->format_date(\%::myconfig, $mindate); |
|
115 |
|
|
116 |
} elsif ( $startdate_method eq 'last_ob_or_all_transactions' and $last_ob ) { |
|
117 |
# use default if there are no ob transactions |
|
118 |
|
|
119 |
return $::locale->format_date(\%::myconfig, $last_ob); |
|
120 |
|
|
121 |
} elsif ( $startdate_method eq 'last_ob_or_start_of_year' ) { |
|
122 |
|
|
123 |
if ( $last_ob ) { |
|
124 |
return $::locale->format_date(\%::myconfig, $last_ob); |
|
125 |
} else { |
|
126 |
return $::locale->format_date(\%::myconfig, $start_of_year); |
|
127 |
}; |
|
128 |
|
|
129 |
} else { |
|
130 |
# default action, also used for closedto and last_ob_or_all_transactions if |
|
131 |
# there are no valid dates |
|
132 |
|
|
133 |
return $::locale->format_date(\%::myconfig, $mindate); |
|
134 |
}; |
|
135 |
|
|
136 |
}; |
|
62 | 137 |
|
63 | 138 |
sub balance_sheet { |
64 | 139 |
$main::lxdebug->enter_sub(); |
... | ... | |
75 | 150 |
$form->{period} = $form->{this_period} = conv_dateq($form->{asofdate}); |
76 | 151 |
} |
77 | 152 |
|
78 |
# get end of financial year and convert to Date format |
|
79 |
my ($closedto) = selectfirst_array_query($form, $dbh, 'SELECT closedto FROM defaults'); |
|
80 |
|
|
81 |
# get date of last opening balance |
|
82 |
my $startdate = get_openbalance_date($closedto, $form->{asofdate}); |
|
153 |
# get starting date for calculating balance |
|
154 |
$form->{this_startdate} = get_balance_starting_date($form->{asofdate}); |
|
83 | 155 |
|
84 |
get_accounts($dbh, $last_period, $startdate, $form->{asofdate}, $form, \@categories);
|
|
156 |
get_accounts($dbh, $last_period, $form->{this_startdate}, $form->{asofdate}, $form, \@categories);
|
|
85 | 157 |
|
86 | 158 |
# if there are any compare dates |
87 | 159 |
if ($form->{compareasofdate}) { |
88 | 160 |
$last_period = 1; |
89 | 161 |
|
90 |
$startdate = get_openbalance_date($closedto, $form->{compareasofdate});
|
|
162 |
$form->{last_startdate} = get_balance_starting_date($form->{compareasofdate});
|
|
91 | 163 |
|
92 |
get_accounts($dbh, $last_period, $startdate, $form->{compareasofdate}, $form, \@categories);
|
|
164 |
get_accounts($dbh, $last_period, $form->{last_startdate} , $form->{compareasofdate}, $form, \@categories);
|
|
93 | 165 |
$form->{last_period} = conv_dateq($form->{compareasofdate}); |
94 | 166 |
} |
95 | 167 |
|
Auch abrufbar als: Unified diff
Startdatum in Bilanz in Mandantenkonfiguration konfigurierbar gemacht
Bisher wurde closed_to ("Bücher schließen zum") als Grundlage für das
Jetzt kann man Einstellen, ob manStartdatum benutzt. Schließt man die Bücher allerdings monatsweise führt dies
zu falschen Werten. Siehe auch Ticket #2444.
Das "Bücher schließen Datum" ist sinnvoll, wenn man nur komplette Jahre
schließt. Bei Wirtschaftsjahr = Kalendarjahr entspricht dies aber auch
Jahresanfang.
"Alle Buchungen" kann z.B. sinnvoll sein wenn man ohne Jahresabschluß
durchbucht.
Eröffnungsbuchung mit "alle Buchungen" als Fallback ist z.B. sinnvoll, wenn man
am sich Anfang des zweiten Buchungsjahres befindet, und noch keinen
Jahreswechsel und auch noch keine EB-Buchungen hat.
Bei den Optionen mit EB-Buchungen wird vorausgesetzt, daß diese immer am 1. Tag
des Wirtschaftsjahres gebucht werden.
Zur Sicherheit wird das Startdatum im Bilanzbericht jetzt zusätzlich zum
Stichtag mit angezeigt. Das hilft auch bei der Kontrolle für den
Abgleich mit der GuV.
Es ist geplant dies weiter zu überarbeiten, wenn ein abweichendes
Wirtschaftsjahr umgesetzt wird. Die SuSa kann z.B. derzeit nicht mit
abweichenden Wirtschaftsjahren umgehen.