$form->{nodiscount} = $form->format_amount($myconfig, $nodiscount, 2);
$form->{yesdiscount} = $form->format_amount($myconfig, $form->{nodiscount_total} - $nodiscount, 2);
- $form->{invtotal} = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
- $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
+ my $grossamount = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax;
+ $form->{invtotal} = $form->round_amount($grossamount, 2, 1);
+ $form->{rounding} = $form->round_amount(
+ $form->{invtotal} - $form->round_amount($grossamount, 2),
+ 2
+ );
+ $form->{rounding} = $form->format_amount($myconfig, $form->{rounding}, 2);
+ $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2);
$form->{invtotal} = $form->format_amount($myconfig, $form->{invtotal}, 2);
$form->{paid} = $form->format_amount($myconfig, $form->{paid}, 2);
- $form->set_payment_options($myconfig, $form->{invdate});
+ $form->set_payment_options($myconfig, $form->{invdate}, 'sales_invoice');
+ $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
$form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef);
$form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id};
- $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id};
$form->{username} = $myconfig->{name};
$ref->{cp_gender} = $contact->cp_gender;
}
}
- # remove id and taxincluded before copy back
- delete @$ref{qw(id taxincluded)};
+ # remove id,notes (double of customernotes) and taxincluded before copy back
+ delete @$ref{qw(id taxincluded notes)};
@wanted_vars = grep({ $_ } @wanted_vars);
if (scalar(@wanted_vars) > 0) {
do_query($form, $dbh, qq|UPDATE ar SET paid = amount WHERE id = ?|, conv_i($form->{"id"}));
}
- $form->new_lastmtime('ar');
+ # maybe we are in a larger transaction and the current
+ # object is not yet persistent in the db, therefore we
+ # need the current dbh to get the not yet committed mtime
+ $form->new_lastmtime('ar', $provided_dbh);
$form->{name} = $form->{customer};
$form->{name} =~ s/--\Q$form->{customer_id}\E//;
c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit,
c.email, c.cc, c.bcc, c.language_id, c.payment_id, c.delivery_term_id,
c.street, c.zipcode, c.city, c.country,
- c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, cu.name AS curr,
+ c.notes AS intnotes, c.pricegroup_id as customer_pricegroup_id, c.taxzone_id, c.salesman_id, cu.name AS curr,
c.taxincluded_checked, c.direct_debit,
b.discount AS tradediscount, b.description AS business
FROM customer c