]> wagnertech.de Git - mfinanz.git/blobdiff - SL/OE.pm
mebil
[mfinanz.git] / SL / OE.pm
index 3666f7d908afcca0f47e949bf31a593d89261633..31b3067f55b7ffc17b2bbd2100ee6e8bc7e8babc 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -658,8 +658,12 @@ SQL
                                   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' => $_,
@@ -762,7 +766,7 @@ SQL
   $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};
-  if (scalar @convert_from_oe_ids) {
+  if (!$form->{useasnew} && scalar @convert_from_oe_ids) {
     RecordLinks->create_links('dbh'        => $dbh,
                               'mode'       => 'ids',
                               'from_table' => 'oe',
@@ -920,7 +924,7 @@ sub retrieve {
 
   # if called in multi id mode, and still only got one id, switch back to single id
   if ($form->{"rowcount"} and $#ids == 0) {
-   $form->{"id"} = $ids[0];
+    $form->{"id"} = $ids[0];
     undef @ids;
     delete $form->{convert_from_oe_ids};
   }
@@ -1572,9 +1576,15 @@ sub order_details {
     $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);
 
   $form->set_payment_options($myconfig, $form->{$form->{type} =~ /_quotation/ ? 'quodate' : 'orddate'}, $form->{type});