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 {
_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);
}
$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) {
}
}
+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 ) = @_;