From 64b3d19a8012187c3c01717b91d59df2b2753ee3 Mon Sep 17 00:00:00 2001 From: Rolf Fluehmann Date: Thu, 30 Jun 2016 13:37:42 +0200 Subject: [PATCH] added roundings for periodic invoices --- SL/DB/Invoice.pm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 9aa17adec..0ef5b6602 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -249,6 +249,12 @@ sub post { my $worker = sub { my %data = $self->calculate_prices_and_taxes; + my $grossamount = $self->amount; + $self->amount($::form->round_amount($grossamount, 2, 1)); + my $rounding = $::form->round_amount( + $self->amount - $grossamount, + 2 + ); $self->_post_create_assemblyitem_entries($data{assembly_items}); $self->save; @@ -256,10 +262,11 @@ sub post { $self->_post_add_acctrans($data{amounts_cogs}); $self->_post_add_acctrans($data{amounts}); $self->_post_add_acctrans($data{taxes}); - $self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 }); $self->_post_update_allocated($data{allocated}); + + $self->_post_book_rounding($rounding); }; if ($self->db->in_transaction) { @@ -296,6 +303,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 ) = @_; -- 2.20.1