From 7d26ae8a9121401789d9cc97f522a8ad542319a6 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 9 Nov 2010 09:02:41 +0100 Subject: [PATCH] =?utf8?q?Ermitteln=20des=20g=C3=BCltigen=20Steuerschl?= =?utf8?q?=C3=BCssels=20zu=20einem=20Artikel=20an=20einem=20bestimmten=20D?= =?utf8?q?atum?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/Part.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index c4597a101..a553f48a4 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -6,6 +6,7 @@ use Carp; use SL::DBUtils; use SL::DB::MetaSetup::Part; use SL::DB::Manager::Part; +use SL::DB::Chart; __PACKAGE__->meta->add_relationships( unit_obj => { @@ -118,6 +119,36 @@ sub buchungsgruppe { shift->buchungsgruppen(@_); } +sub get_taxkey { + my ($self, %params) = @_; + + my $date = $params{date} || DateTime->today_local; + my $is_sales = !!$params{is_sales}; + my $taxzone = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1; + + $self->{__partpriv_taxkey_information} ||= { }; + my $tk_info = $self->{__partpriv_taxkey_information}; + + $tk_info->{$taxzone} ||= { }; + $tk_info->{$taxzone}->{$is_sales} ||= { }; + + return $tk_info->{$taxzone}->{$is_sales}->{$date} if exists $tk_info->{$taxzone}->{$is_sales}->{$date}; + + my $bugru = $self->buchungsgruppe; + my %charts = ( inventory => { id => $self->inventory_accno_id ? $bugru->inventory_accno_id : undef }, + income => { id => $bugru->call_sub("income_accno_id_${taxzone}") }, + expense => { id => $bugru->call_sub("expense_accno_id_${taxzone}") }, + ); + + foreach my $type(qw(inventory income expense)) { + $charts{$type}->{chart} ||= $charts{$type}->{id} ? SL::DB::Manager::Chart->find_by(id => $charts{$type}->{id}) : undef if $charts{$type}->{id}; + } + + my $chart = $charts{ $is_sales ? 'income' : 'expense' }->{chart}; + + return $tk_info->{$taxzone}->{$is_sales}->{$date} = $chart->get_active_taxkey($date); +} + 1; __END__ @@ -216,6 +247,21 @@ C<$self> is used. Retrieves the quantity that has been ordered from a vendor but that has not been delivered yet. Only open purchase orders are considered. +=item C + +Retrieves and returns a taxkey object valid for the given date +C<$params{date}> and tax zone C<$params{taxzone}> +(C<$params{taxzone_id}> is also recognized). The date defaults to the +current date if undefined. + +This function looks up the income (for trueish values of +C<$params{is_sales}>) or expense (for falsish values of +C<$params{is_sales}>) account for the current part. It uses the part's +associated buchungsgruppe and uses the fields belonging to the tax +zone given by C<$params{taxzone}> (range 0..3). + +The information retrieved by the function is cached. + =item C Checks if this articke is used in orders, invoices, delivery orders or -- 2.20.1