OE->save() parst verschiedene Zahlen. Das ist beim Umwandeln in anderen Formulartypen...
[kivitendo-erp.git] / bin / mozilla / oe.pl
index 20042ca..2537eaf 100644 (file)
@@ -111,6 +111,8 @@ sub add {
 sub edit {
   $lxdebug->enter_sub();
 
+  $form->{simple_save} = 0;
+
   set_headings("edit");
 
   # editing without stuff to edit? try adding it first
@@ -282,12 +284,9 @@ sub order_links {
 
 sub prepare_order {
   $lxdebug->enter_sub();
-  $form->{format}   = "pdf" unless ($form->{print_and_save} && $form->{format});
   $form->{media}    = "screen";
   $form->{formname} = $form->{type} unless $form->{formname};
 
-  map { $form->{$_} =~ s/\"/"/g }
-    qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact);
   my $i = 0;
   foreach $ref (@{ $form->{form_details} }) {
     $form->{rowcount} = ++$i;
@@ -332,6 +331,11 @@ sub form_header {
   $checkedopen   = ($form->{closed}) ? ""        : "checked";
   $checkedclosed = ($form->{closed}) ? "checked" : "";
 
+  map { $form->{$_} =~ s/\"/"/g }
+    qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
+       shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
+       shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
+
   # use JavaScript Calendar or not
   $form->{jsscript} = $form->{jscalendar};
   $jsscript = "";
@@ -534,26 +538,21 @@ sub form_header {
     foreach $item (@{ $form->{TAXZONE} }) {
       if ($item->{id} == $form->{taxzone_id}) {
         $form->{selecttaxzone} .=
-          "<option value=$item->{id} selected>$item->{description}</option>";
+          "<option value=$item->{id} selected>" . H($item->{description}) .
+          "</option>";
       } else {
         $form->{selecttaxzone} .=
-          "<option value=$item->{id}>$item->{description}</option>";
+          "<option value=$item->{id}>" . H($item->{description}) . "</option>";
       }
 
     }
   } else {
     $form->{selecttaxzone} =~ s/ selected//g;
     if ($form->{taxzone_id} ne "") {
-      $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
+      $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
     }
   }
 
-  if ($form->{rowcount} >0) {
-    $form->{selecttaxzone} =~ /<option value=\d+ selected>.*?<\/option>/;
-    $form->{selecttaxzone} = $&;
-  }
-  
-
   $taxzone = qq|
              <tr>
                <th align=right>| . $locale->text('Steuersatz') . qq|</th>
@@ -828,6 +827,8 @@ $jsscript
 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
 <input type=hidden name=shiptophone value="$form->{shiptophone}">
 <input type=hidden name=shiptofax value="$form->{shiptofax}">
+<input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
+<input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
 
 <!-- email variables -->
@@ -1086,7 +1087,7 @@ sub form_footer {
 <input class=submit type=submit name=action value="|
         . $locale->text('Sales Order') . qq|">
 <input class=submit type=submit name=action value="|
-        . $locale->text('Quotation') . qq|">
+        . $locale->text('Request for Quotation') . qq|">
 |;
 
     } else {
@@ -1166,8 +1167,6 @@ sub update {
 
   } else {
 
-    $form->{"selected_unit_$i"} = $form->{"unit_$i"};
-
     if (   $form->{type} eq 'purchase_order'
         || $form->{type} eq 'request_quotation') {
       IR->retrieve_item(\%myconfig, \%$form);
@@ -1962,10 +1961,12 @@ sub save_and_close {
   }
 
   # get new number in sequence if no number is given or if saveasnew was requested
-  if (!$form->{$ordumber} || $form->{saveasnew}) {
+  if (!$form->{$ordnumber} || $form->{saveasnew}) {
     $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
   }
 
+  relink_accounts();
+
   $form->redirect(
             $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
     if (OE->save(\%myconfig, \%$form));
@@ -2038,6 +2039,7 @@ sub save {
   $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
     unless $form->{$ordnumber};
 
+  relink_accounts();
 
   OE->save(\%myconfig, \%$form);
   $form->{simple_save} = 1;
@@ -2163,7 +2165,7 @@ sub invoice {
   # if not it's most likely a collective order, which can't be saved back
   # so they just have to be closed
   if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
-    OE->save(\%myconfig, \%$form);
+    OE->close_order(\%myconfig, \%$form);
   } else {
     OE->close_orders(\%myconfig, \%$form);
   }
@@ -2228,6 +2230,13 @@ sub invoice {
 
   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
+  for $i (1 .. $form->{rowcount}) {
+    map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
+                                                     $form->{"${_}_${i}"})
+            if ($form->{"${_}_${i}"}) }
+        qw(ship qty sellprice listprice basefactor));
+  }
+
   &prepare_invoice;
 
   # format amounts
@@ -2387,6 +2396,8 @@ sub create_backorder {
     } qw(sellprice discount);
   }
 
+  relink_accounts();
+
   OE->save(\%myconfig, \%$form);
 
   # rebuild rows for invoice
@@ -2428,6 +2439,7 @@ sub purchase_order {
   if (   $form->{type} eq 'sales_quotation'
       || $form->{type} eq 'request_quotation') {
     $form->{closed} = 1;
+    relink_accounts();
     OE->save(\%myconfig, \%$form);
   }
 
@@ -2447,8 +2459,7 @@ sub sales_order {
 
   if (   $form->{type} eq 'sales_quotation'
       || $form->{type} eq 'request_quotation') {
-    $form->{closed} = 1;
-    OE->save(\%myconfig, \%$form);
+    OE->close_order(\%myconfig, $form);
   }
 
   $form->{cp_id} *= 1;
@@ -2474,6 +2485,13 @@ sub poso {
   map { delete $form->{$_} }
     qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
 
+  for $i (1 .. $form->{rowcount}) {
+    map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
+                                                     $form->{"${_}_${i}"})
+            if ($form->{"${_}_${i}"}) }
+        qw(ship qty sellprice listprice basefactor));
+  }
+
   &order_links;
 
   &prepare_order;
@@ -2681,6 +2699,8 @@ sub display_ship_receive {
 <input type=hidden name=shiptophone value="$form->{shiptophone}">
 <input type=hidden name=shiptofax value="$form->{shiptofax}">
 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
+<input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
+<input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
 
 <!-- email variables -->
 <input type=hidden name=message value="$form->{message}">