From: Rolf Fluehmann Date: Thu, 30 Jun 2016 16:18:30 +0000 (+0200) Subject: added roundings for periodic invoices X-Git-Tag: release-3.4.1~11^2~1 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=abd56be11a58421b1d9401e812a83d28832b939a;p=kivitendo-erp.git added roundings for periodic invoices --- diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index 44c651196..6afb45a4f 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -57,7 +57,7 @@ sub calculate_prices_and_taxes { return $self unless wantarray; - return map { ($_ => $data{$_}) } qw(taxes amounts amounts_cogs allocated exchangerate assembly_items items); + return map { ($_ => $data{$_}) } qw(taxes amounts amounts_cogs allocated exchangerate assembly_items items rounding); } sub _get_exchangerate { @@ -185,10 +185,13 @@ sub _calculate_amounts { _dbg("Sna " . $self->netamount . " idiff " . $data->{invoicediff} . " tdiff ${tax_diff}"); my $tax = sum values %{ $data->{taxes} }; - $data->{arap_amount} = $netamount + $tax; + $amount = $netamount + $tax; + my $grossamount = _round($amount, 2, 1); + $data->{rounding} = _round($grossamount - $amount, 2); + $data->{arap_amount} = $grossamount; $self->netamount( $netamount); - $self->amount( $netamount + $tax); + $self->amount( $grossamount); $self->marge_percent($self->netamount ? ($self->netamount - $data->{lastcost_total}) * 100 / $self->netamount : 0); } diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 9aa17adec..99c2e11ad 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -260,6 +260,8 @@ sub post { $self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 }); $self->_post_update_allocated($data{allocated}); + + $self->_post_book_rounding($data{rounding}); }; if ($self->db->in_transaction) { @@ -296,6 +298,26 @@ sub _post_add_acctrans { } } +sub _post_book_rounding { + my ($self, $rounding) = @_; + + my $tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id; + my $rnd_accno = $rounding == 0 ? 0 + : $rounding > 0 ? SL::DB::Default->get->rndgain_accno_id + : SL::DB::Default->get->rndloss_accno_id + ; + if ($rnd_accno != 0) { + SL::DB::AccTransaction->new(trans_id => $self->id, + chart_id => $rnd_accno, + amount => $rounding, + tax_id => $tax_id, + taxkey => 0, + project_id => $self->globalproject_id, + transdate => $self->transdate, + chart_link => $rnd_accno)->save; + } +} + sub add_ar_amount_row { my ($self, %params ) = @_;