dbh => $dbh);
# link previous items with orderitems
- foreach (qw(orderitems invoice)) {
- if (!$form->{saveasnew} && !$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
+ # assume we have a new workflow if we link from invoice or order to quotation
+ # unluckily orderitems are used for quotation and orders - therefore one more
+ # check to be sure NOT to link from order to quotation
+ foreach (qw(orderitems)) {
+ if (!$form->{saveasnew} && !$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}
+ && $form->{type} !~ 'quotation') {
RecordLinks->create_links('dbh' => $dbh,
'mode' => 'ids',
'from_table' => $_,
$form->save_status($dbh);
# Link this record to the records it was created from.
- # check every record type we may link. i am not happy with converting the string to array back
- # should be a array from the start (OE.pm -> retrieve).
- # and that i need the local array ref for close_quotation_rfqs. better ideas welcome
$form->{convert_from_oe_ids} =~ s/^\s+//;
$form->{convert_from_oe_ids} =~ s/\s+$//;
my @convert_from_oe_ids = split m/\s+/, $form->{convert_from_oe_ids};
delete $form->{convert_from_oe_ids};
- @{ $form->{convert_from_oe_ids} } = @convert_from_oe_ids;
- foreach (qw(ar oe)) {
- if (!$form->{useasnew} && $form->{"convert_from_${_}_ids"}) {
- RecordLinks->create_links('dbh' => $dbh,
- 'mode' => 'ids',
- 'from_table' => $_,
- 'from_ids' => $form->{"convert_from_${_}_ids"},
- 'to_table' => 'oe',
- 'to_id' => $form->{id},
- );
- delete $form->{"convert_from_${_}_ids"};
- }
+ if (!$form->{useasnew} && scalar @convert_from_oe_ids) {
+ RecordLinks->create_links('dbh' => $dbh,
+ 'mode' => 'ids',
+ 'from_table' => 'oe',
+ 'from_ids' => \@convert_from_oe_ids,
+ 'to_table' => 'oe',
+ 'to_id' => $form->{id},
+ );
$self->_close_quotations_rfqs('dbh' => $dbh,
'from_id' => \@convert_from_oe_ids,
- 'to_id' => $form->{id}) if $_ eq 'oe';
+ 'to_id' => $form->{id});
}
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
$form->{subtotal_nofmt} = $form->{ordtotal};
}
- $form->{ordtotal} = ($form->{taxincluded}) ? $form->{ordtotal} : $form->{ordtotal} + $tax;
+ my $grossamount = ($form->{taxincluded}) ? $form->{ordtotal} : $form->{ordtotal} + $tax;
+ $form->{ordtotal} = $form->round_amount( $grossamount, 2, 1);
+ $form->{rounding} = $form->round_amount(
+ $form->{ordtotal} - $form->round_amount($grossamount, 2),
+ 2
+ );
# format amounts
+ $form->{rounding} = $form->format_amount($myconfig, $form->{rounding}, 2);
$form->{quototal} = $form->{ordtotal} = $form->format_amount($myconfig, $form->{ordtotal}, 2);
- if ($form->{type} =~ /_quotation/) {
- $form->set_payment_options($myconfig, $form->{quodate});
- } else {
- $form->set_payment_options($myconfig, $form->{orddate});
- }
+ $form->set_payment_options($myconfig, $form->{$form->{type} =~ /_quotation/ ? 'quodate' : 'orddate'}, $form->{type});
$form->{username} = $myconfig->{name};