Revision a6bf2bd6
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
|
5 | 5 |
use Carp; |
6 |
use List::MoreUtils qw(any); |
|
7 |
|
|
6 | 8 |
use SL::DBUtils; |
7 | 9 |
use SL::DB::MetaSetup::Part; |
8 | 10 |
use SL::DB::Manager::Part; |
... | ... | |
132 | 134 |
$tk_info->{$taxzone} ||= { }; |
133 | 135 |
$tk_info->{$taxzone}->{$is_sales} ||= { }; |
134 | 136 |
|
135 |
return $tk_info->{$taxzone}->{$is_sales}->{$date} if exists $tk_info->{$taxzone}->{$is_sales}->{$date}; |
|
137 |
if (!exists $tk_info->{$taxzone}->{$is_sales}->{$date}) { |
|
138 |
$tk_info->{$taxzone}->{$is_sales}->{$date} = |
|
139 |
$self->get_chart(type => $is_sales ? 'income' : 'expense', taxzone => $taxzone) |
|
140 |
->load |
|
141 |
->get_active_taxkey($date); |
|
142 |
} |
|
136 | 143 |
|
137 |
my $bugru = $self->buchungsgruppe; |
|
138 |
my %charts = ( inventory => { id => $self->inventory_accno_id ? $bugru->inventory_accno_id : undef }, |
|
139 |
income => { id => $bugru->call_sub("income_accno_id_${taxzone}") }, |
|
140 |
expense => { id => $bugru->call_sub("expense_accno_id_${taxzone}") }, |
|
141 |
); |
|
144 |
return $tk_info->{$taxzone}->{$is_sales}->{$date}; |
|
145 |
} |
|
142 | 146 |
|
143 |
foreach my $type(qw(inventory income expense)) { |
|
144 |
$charts{$type}->{chart} ||= $charts{$type}->{id} ? SL::DB::Manager::Chart->find_by(id => $charts{$type}->{id}) : undef if $charts{$type}->{id}; |
|
145 |
} |
|
147 |
sub get_chart { |
|
148 |
my ($self, %params) = @_; |
|
149 |
|
|
150 |
my $type = (any { $_ eq $params{type} } qw(income expense inventory)) ? $params{type} : croak("Invalid 'type' parameter '$params{type}'"); |
|
151 |
my $taxzone = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1; |
|
152 |
|
|
153 |
$self->{__partpriv_get_chart_id} ||= { }; |
|
154 |
my $charts = $self->{__partpriv_get_chart_id}; |
|
155 |
|
|
156 |
$charts->{$taxzone} ||= { }; |
|
146 | 157 |
|
147 |
my $chart = $charts{ $is_sales ? 'income' : 'expense' }->{chart}; |
|
158 |
if (!exists $charts->{$taxzone}->{$type}) { |
|
159 |
my $bugru = $self->buchungsgruppe; |
|
160 |
my $chart_id = ($type eq 'inventory') ? ($self->inventory_accno_id ? $bugru->inventory_accno_id : undef) |
|
161 |
: $bugru->call_sub("${type}_accno_id_${taxzone}"); |
|
148 | 162 |
|
149 |
return $tk_info->{$taxzone}->{$is_sales}->{$date} = $chart->get_active_taxkey($date); |
|
163 |
$charts->{$taxzone}->{$type} = $chart_id ? SL::DB::Chart->new(id => $chart_id)->load : undef; |
|
164 |
} |
|
165 |
|
|
166 |
return $charts->{$taxzone}->{$type}; |
|
150 | 167 |
} |
151 | 168 |
|
152 | 169 |
1; |
... | ... | |
262 | 279 |
|
263 | 280 |
The information retrieved by the function is cached. |
264 | 281 |
|
282 |
=item C<get_chart %params> |
|
283 |
|
|
284 |
Retrieves and returns a chart object valid for the given type |
|
285 |
C<$params{type}> and tax zone C<$params{taxzone}> |
|
286 |
(C<$params{taxzone_id}> is also recognized). The type must be one of |
|
287 |
the three key words C<income>, C<expense> and C<inventory>. |
|
288 |
|
|
289 |
This function uses the part's associated buchungsgruppe and uses the |
|
290 |
fields belonging to the tax zone given by C<$params{taxzone}> (range |
|
291 |
0..3). |
|
292 |
|
|
293 |
The information retrieved by the function is cached. |
|
294 |
|
|
265 | 295 |
=item C<orphaned> |
266 | 296 |
|
267 | 297 |
Checks if this articke is used in orders, invoices, delivery orders or |
Auch abrufbar als: Unified diff
Part::get_chart - Laden eines dazugehörigen Chart-Objektes über Buchungsgruppe