$form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
$form->{"qty_$i"} *= -1 if $form->{storno};
- $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"} if $main::eur;
+ $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"} if $::lx_office_conf{system}->{eur};
# get item baseunit
if (!$item_units{$form->{"id_$i"}}) {
$linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor, 2);
if ($form->{taxincluded}) {
+
$taxamount = $linetotal * ($taxrate / (1 + $taxrate));
$form->{"sellprice_$i"} = $form->{"sellprice_$i"} * (1 / (1 + $taxrate));
+
} else {
$taxamount = $linetotal * $taxrate;
}
$invoicediff += $paiddiff;
$expensediff += $paiddiff;
- ######## this only applies to tax included
+######## this only applies to tax included
+
+ # in the sales invoice case rounding errors only have to be corrected for
+ # income accounts, it is enough to add the total rounding error to one of
+ # the income accounts, with the one assigned to the last row being used
+ # (lastinventoryaccno)
+
+ # in the purchase invoice case rounding errors may be split between
+ # inventory accounts and expense accounts. After rounding, an error of 1
+ # cent is introduced if the total rounding error exceeds 0.005. The total
+ # error is made up of $invoicediff and $expensediff, however, so if both
+ # values are below 0.005, but add up to a total >= 0.005, correcting
+ # lastinventoryaccno and lastexpenseaccno separately has no effect after
+ # rounding. This caused bug 1579. Therefore when the combined total exceeds
+ # 0.005, but neither do individually, the account with the larger value
+ # shall receive the total rounding error, and the next time it is rounded
+ # the 1 cent correction will be introduced.
$form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff if $lastinventoryaccno;
$form->{amount}{ $form->{id} }{$lastexpenseaccno} -= $expensediff if $lastexpenseaccno;
+ if ( (abs($expensediff)+abs($invoicediff)) >= 0.005 and abs($expensediff) < 0.005 and abs($invoicediff) < 0.005 ) {
+
+ # in total the rounding error adds up to 1 cent effectively, correct the
+ # larger of the two numbers
+
+ if ( abs($form->{amount}{ $form->{id} }{$lastinventoryaccno}) > abs($form->{amount}{ $form->{id} }{$lastexpenseaccno}) ) {
+ # $invoicediff has already been deducted, now also deduct expensediff
+ $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $expensediff;
+ } else {
+ # expensediff has already been deducted, now also deduct invoicediff
+ $form->{amount}{ $form->{id} }{$lastexpenseaccno} -= $invoicediff;
+ };
+ };
+
} else {
$amount = $form->round_amount($netamount * $form->{exchangerate}, 2);
$paiddiff = $amount - $netamount * $form->{exchangerate};
$form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate} + $paiddiff, 2) if $form->{paid} != 0;
- # update exchangerate
+# update exchangerate
$form->update_exchangerate($dbh, $form->{currency}, $form->{invdate}, 0, $form->{exchangerate})
if ($form->{currency} ne $defaultcurrency) && !$exchangerate;
- # record acc_trans transactions
+# record acc_trans transactions
foreach my $trans_id (keys %{ $form->{amount} }) {
foreach my $accno (keys %{ $form->{amount}{$trans_id} }) {
$form->{amount}{$trans_id}{$accno} = $form->round_amount($form->{amount}{$trans_id}{$accno}, 2);
+
next if $payments_only || !$form->{amount}{$trans_id}{$accno};
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
+ (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
@values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno},
conv_date($form->{invdate}), $accno, $project_id);
do_query($form, $dbh, $query, @values);
# set values which could be empty
my $taxzone_id = $form->{taxzone_id} * 1;
- $form->{department_id} = (split /--/, $form->{department})[1];
+
+ # Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
+ # korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
+ # Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011
+ # copy & paste von IS.pm
+ if (!$form->{department_id}){
+ $form->{department_id} = (split /--/, $form->{department})[1];
+ }
$form->{invnumber} = $form->{id} unless $form->{invnumber};
$taxzone_id = 0 if (3 < $taxzone_id) || (0 > $taxzone_id);
# delete zero entries
do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE amount = 0|);
- Common::webdav_folder($form) if ($main::webdav);
+ Common::webdav_folder($form);
# Link this record to the records it was created from.
RecordLinks->create_links('dbh' => $dbh,
}
$sth->finish();
- Common::webdav_folder($form) if ($main::webdav);
+ Common::webdav_folder($form);
$dbh->disconnect();