X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/60e14abfddb3e3bf68e19e586a0ad9cff615fcd6..d8be5cc409de5b3bc34439599b1481201a5a1c2e:/SL/IO.pm diff --git a/SL/IO.pm b/SL/IO.pm index 32537e547..e1374feb3 100644 --- a/SL/IO.pm +++ b/SL/IO.pm @@ -1,8 +1,12 @@ package IO; -use strict; +use List::Util qw(first); +use List::MoreUtils qw(any); use SL::DBUtils; +use SL::DB; + +use strict; sub retrieve_partunits { $main::lxdebug->enter_sub(); @@ -26,4 +30,77 @@ sub retrieve_partunits { } +sub set_datepaid { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, qw(id table)); + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; + my $id = conv_i($params{id}); + my $table = (any { $_ eq $params{table} } qw(ar ap gl)) ? $params{table} : 'ar'; + + my ($curr_datepaid, $curr_paid) = selectfirst_array_query($form, $dbh, qq|SELECT datepaid, paid FROM $table WHERE id = ?|, $id); + + my $query = <client->error }; + + $main::lxdebug->leave_sub(); +} + +sub get_active_taxes_for_chart { + my ($self, $chart_id, $transdate, $tax_id) = @_; + + my $chart = SL::DB::Chart->new(id => $chart_id)->load; + my $active_taxkey = $chart->get_active_taxkey($transdate); + + my $where = [ chart_categories => { like => '%' . $chart->category . '%' } ]; + + if ( defined $tax_id && $tax_id >= 0 ) { + $where = [ or => [ chart_categories => { like => '%' . $chart->category . '%' }, + id => $tax_id + ] + ]; + } + + my $taxes = SL::DB::Manager::Tax->get_all( + where => $where, + sort_by => 'taxkey, rate', + ); + + my $default_tax = first { $active_taxkey->tax_id == $_->id } @{ $taxes }; + $default_tax->{is_default} = 1 if $default_tax; + + return @{ $taxes }; +} + 1;