Fehler bei Lieferadressen die Anfuehrungszeichen im Namen enthalten
[kivitendo-erp.git] / bin / mozilla / oe.pl
index 67c99bd..6941424 100644 (file)
@@ -44,26 +44,59 @@ require "$form->{path}/arap.pl";
 
 # end of main
 
-sub add {
+# For locales.pl:
+# $locale->text('Edit the purchase_order');
+# $locale->text('Edit the sales_order');
+# $locale->text('Edit the request_quotation');
+# $locale->text('Edit the sales_quotation');
+
+# $locale->text('Workflow purchase_order');
+# $locale->text('Workflow sales_order');
+# $locale->text('Workflow request_quotation');
+# $locale->text('Workflow sales_quotation');
+
+sub set_headings {
   $lxdebug->enter_sub();
 
+  my ($action) = @_;
+
   if ($form->{type} eq 'purchase_order') {
-    $form->{title} = $locale->text('Add Purchase Order');
-    $form->{vc}    = 'vendor';
+    $form->{title}   = $action eq "edit" ?
+      $locale->text('Edit Purchase Order') :
+      $locale->text('Add Purchase Order');
+    $form->{heading} = $locale->text('Purchase Order');
+    $form->{vc}      = 'vendor';
   }
   if ($form->{type} eq 'sales_order') {
-    $form->{title} = $locale->text('Add Sales Order');
-    $form->{vc}    = 'customer';
+    $form->{title}   = $action eq "edit" ?
+      $locale->text('Edit Sales Order') :
+      $locale->text('Add Sales Order');
+    $form->{heading} = $locale->text('Sales Order');
+    $form->{vc}      = 'customer';
   }
   if ($form->{type} eq 'request_quotation') {
-    $form->{title} = $locale->text('Add Request for Quotation');
-    $form->{vc}    = 'vendor';
+    $form->{title}   = $action eq "edit" ?
+      $locale->text('Edit Request for Quotation') :
+      $locale->text('Add Request for Quotation');
+    $form->{heading} = $locale->text('Request for Quotation');
+    $form->{vc}      = 'vendor';
   }
   if ($form->{type} eq 'sales_quotation') {
-    $form->{title} = $locale->text('Add Quotation');
-    $form->{vc}    = 'customer';
+    $form->{title}   = $action eq "edit" ?
+      $locale->text('Edit Quotation') :
+      $locale->text('Add Quotation');
+    $form->{heading} = $locale->text('Quotation');
+    $form->{vc}      = 'customer';
   }
 
+  $lxdebug->leave_sub();
+}
+
+sub add {
+  $lxdebug->enter_sub();
+
+  set_headings("add");
+
   $form->{callback} =
     "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
     unless $form->{callback};
@@ -78,6 +111,10 @@ sub add {
 sub edit {
   $lxdebug->enter_sub();
 
+  $form->{simple_save} = 0;
+
+  set_headings("edit");
+
   # editing without stuff to edit? try adding it first
   if ($form->{rowcount}) {
     map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount});
@@ -102,26 +139,7 @@ sub edit {
     $printer_id = $form->{printer_id};
   }
 
-  if ($form->{type} eq 'purchase_order') {
-    $form->{title}   = $locale->text('Edit Purchase Order');
-    $form->{heading} = $locale->text('Purchase Order');
-    $form->{vc}      = 'vendor';
-  }
-  if ($form->{type} eq 'sales_order') {
-    $form->{title}   = $locale->text('Edit Sales Order');
-    $form->{heading} = $locale->text('Sales Order');
-    $form->{vc}      = 'customer';
-  }
-  if ($form->{type} eq 'request_quotation') {
-    $form->{title}   = $locale->text('Edit Request for Quotation');
-    $form->{heading} = $locale->text('Request for Quotation');
-    $form->{vc}      = 'vendor';
-  }
-  if ($form->{type} eq 'sales_quotation') {
-    $form->{title}   = $locale->text('Edit Quotation');
-    $form->{heading} = $locale->text('Quotation');
-    $form->{vc}      = 'customer';
-  }
+  set_headings("edit");
 
   &order_links;
   &prepare_order;
@@ -229,7 +247,7 @@ sub order_links {
   }
 
   # currencies
-  @curr = split /:/, $form->{currencies};
+  @curr = split(/:/, $form->{currencies});
   chomp $curr[0];
   $form->{defaultcurrency} = $curr[0];
   $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
@@ -266,12 +284,9 @@ sub order_links {
 
 sub prepare_order {
   $lxdebug->enter_sub();
-  $form->{format}   = "pdf";
   $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;
@@ -316,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 = "";
@@ -407,16 +427,17 @@ sub form_header {
   if (@{ $form->{SHIPTO} }) {
     $form->{selectshipto} = "<option value=0></option>";
     foreach $item (@{ $form->{SHIPTO} }) {
-      if ($item->{id} == $form->{shipto_id}) {
+      if ($item->{shipto_id} == $form->{shipto_id}) {
         $form->{selectshipto} .=
-          "<option value=$item->{id} selected>$item->{shiptoname}</option>";
+          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
       } else {
         $form->{selectshipto} .=
-          "<option value=$item->{id}>$item->{shiptoname}</option>";
+          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
       }
 
     }
   } else {
+    $form->{selectshipto} = $form->unquote($form->{selectshipto});
     $form->{selectshipto} =~ s/ selected//g;
     if ($form->{shipto_id} ne "") {
       $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
@@ -425,9 +446,9 @@ sub form_header {
 
   $shipto = qq|
                <th align=right>| . $locale->text('Shipping Address') . qq|</th>
-               <td><select name=shipto_id>$form->{selectshipto}</select></td>
-               <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
-
+               <td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>|;
+  $form->{selectshipto} = $form->quote($form->{selectshipto});
+  $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
 
 
 
@@ -473,13 +494,8 @@ sub form_header {
   $vclabel = ucfirst $form->{vc};
   $vclabel = $locale->text($vclabel);
 
-  $terms = qq|
-                    <tr>
-                     <th align=right nowrap>| . $locale->text('Terms: Net') . qq|</th>
-                     <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |
-    . $locale->text('days') . qq|</td>
-                    </tr>
-|;
+  $terms = qq|<input name=terms size="3" maxlength="3" value="| .
+    $form->quote($form->{terms}) . qq|">|;
 
   if ($form->{business}) {
     $business = qq|
@@ -518,26 +534,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>
@@ -585,7 +596,7 @@ sub form_header {
                      <td>$form->{creditlimit}</td>
                      <td width=20%></td>
                      <th nowrap>| . $locale->text('Remaining') . qq|</th>
-                     <td class="plus$n">$form->{creditremaining}</td>
+                     <td class="plus$n" nowrap>$form->{creditremaining}</td>
                    </tr>
                  </table>
                </td>
@@ -812,6 +823,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 -->
@@ -1016,7 +1029,7 @@ sub form_footer {
   </tr>
 </table>
 
-Bearbeiten des $form->{heading}<br>
+| . $locale->text("Edit the $form->{type}") . qq|<br>
 <input class=submit type=submit name=action value="|
     . $locale->text('Update') . qq|">
 <input class=submit type=submit name=action value="|
@@ -1033,7 +1046,7 @@ Bearbeiten des $form->{heading}<br>
 
   if (($form->{id})) {
     print qq|
-<br>Workflow  $form->{heading}<br>
+<br>| . $locale->text("Workflow $form->{type}") . qq|<br>
 <input class=submit type=submit name=action value="|
       . $locale->text('Save as new') . qq|">
 <input class=submit type=submit name=action value="|
@@ -1070,7 +1083,7 @@ Bearbeiten des $form->{heading}<br>
 <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 {
@@ -1116,6 +1129,8 @@ Bearbeiten des $form->{heading}<br>
 sub update {
   $lxdebug->enter_sub();
 
+  set_headings($form->{"id"} ? "edit" : "add");
+
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(exchangerate creditlimit creditremaining);
   $form->{update} = 1;
@@ -1148,8 +1163,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);
@@ -1601,7 +1614,9 @@ sub orders {
     . qq|</a></th>|;
   $column_header{quonumber} =
       qq|<th><a class=listheading href=$href&sort=quonumber>|
-    . $locale->text('Quotation')
+    . ($form->{"type"} eq "request_quotation" ?
+       $locale->text('RFQ') :
+       $locale->text('Quotation'))
     . qq|</a></th>|;
   $column_header{name} =
     qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
@@ -1943,8 +1958,12 @@ sub save_and_close {
 
   }
 
-  $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
-    unless $form->{$ordnumber};
+  # get new number in sequence if no number is given or if saveasnew was requested
+  if (!$form->{$ordnumber} || $form->{saveasnew}) {
+    $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
+  }
+
+  relink_accounts();
 
   $form->redirect(
             $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
@@ -2018,10 +2037,12 @@ sub save {
   $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
     unless $form->{$ordnumber};
 
+  relink_accounts();
 
   OE->save(\%myconfig, \%$form);
   $form->{simple_save} = 1;
   if(!$form->{print_and_save}) {
+    set_headings("edit");
     &update;
     exit;
   }
@@ -2118,6 +2139,13 @@ sub invoice {
 
   $form->{cp_id} *= 1;
 
+  for $i (1 .. $form->{rowcount}) {
+    map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
+                                                     $form->{"${_}_${i}"})
+            if ($form->{"${_}_${i}"}) }
+        qw(ship qty sellprice listprice basefactor));
+  }
+
   if (   $form->{type} =~ /_order/
       && $form->{currency} ne $form->{defaultcurrency}) {
 
@@ -2142,7 +2170,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);
   }
@@ -2366,6 +2394,8 @@ sub create_backorder {
     } qw(sellprice discount);
   }
 
+  relink_accounts();
+
   OE->save(\%myconfig, \%$form);
 
   # rebuild rows for invoice
@@ -2406,8 +2436,7 @@ sub purchase_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;
@@ -2426,8 +2455,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;
@@ -2453,6 +2481,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;
@@ -2660,6 +2695,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}">