Bei Kundenangeboten, Kundenaufträgen, Lieferantenbestellungen und Lieferantenanfragen...
[kivitendo-erp.git] / bin / mozilla / oe.pl
index bab0734..3c55ee5 100644 (file)
@@ -37,8 +37,8 @@ use SL::IR;
 use SL::IS;
 use SL::PE;
 
-require "$form->{path}/io.pl";
-require "$form->{path}/arap.pl";
+require "bin/mozilla/io.pl";
+require "bin/mozilla/arap.pl";
 
 1;
 
@@ -98,7 +98,7 @@ sub add {
   set_headings("add");
 
   $form->{callback} =
-    "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
+    "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &order_links;
@@ -254,14 +254,6 @@ sub order_links {
       (@{ $form->{"all_$form->{vc}"} });
   }
 
-  # currencies
-  @curr = split(/:/, $form->{currencies});
-  chomp $curr[0];
-  $form->{defaultcurrency} = $curr[0];
-  $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
-
-  map { $form->{selectcurrency} .= "<option>$_</option>\n" } @curr;
-
   $form->{taxincluded} = $taxincluded if ($form->{id});
 
   # departments
@@ -361,12 +353,12 @@ sub form_header {
 
     # with JavaScript Calendar
     $button1 = qq|
-       <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
+       <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
        <td><input type=button name=transdate id="trigger1" value=|
       . $locale->text('button') . qq|></td>
       |;
     $button2 = qq|
-       <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
+       <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\"></td>
        <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
       . $locale->text('button') . qq|></td>
      |;
@@ -380,28 +372,30 @@ sub form_header {
 
     # without JavaScript Calendar
     $button1 = qq|
-                              <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
+                              <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
     $button2 = qq|
-                              <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
+                              <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\"></td>|;
   }
 
-  if ($form->{id}) {
-    $openclosed = qq|
-      <tr>
-        <td colspan=2 align=center>
-          <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
-          <label for="closed">| . $locale->text('Closed') . qq|</label>
-|;
+  my @tmp;
 
-    if (($form->{"type"} eq "sales_order") ||
-        ($form->{"type"} eq "purchase_order")) {
-      $openclosed .= qq|
+  if (($form->{"type"} eq "sales_order") ||
+      ($form->{"type"} eq "purchase_order")) {
+    push(@tmp, qq|
           <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
-          <label for="delivered">| . $locale->text('Delivered') . qq|</label>
-|;
-    }
+          <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
+  }
+
+  if ($form->{id}) {
+    push(@tmp, qq|
+          <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
+          <label for="closed">| . $locale->text('Closed') . qq|</label>|);
+  }
 
+  if (@tmp) {
     $openclosed .= qq|
+      <tr>
+        <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
         </td>
       </tr>
 |;
@@ -429,7 +423,9 @@ sub form_header {
                    "projects" => { "key" => "ALL_PROJECTS",
                                    "all" => 0,
                                    "old_id" => \@old_project_ids },
-                   "employees" => "ALL_SALESMEN");
+                   "employees" => "ALL_SALESMEN",
+                   "taxzones" => "ALL_TAXZONES",
+                   "currencies" => "ALL_CURRENCIES");
 
   my %labels;
   my @values = (undef);
@@ -487,6 +483,42 @@ sub form_header {
          </tr>|;
   }
 
+
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
+    push(@values, $item->{"id"});
+    $labels{$item->{"id"}} = $item->{"description"};
+  }
+
+  $taxzone = qq|
+    <tr>
+      <th align="right">| . $locale->text('Steuersatz') . qq|</th>
+      <td>| .
+        NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
+                             '-values' => \@values, '-labels' => \%labels)) . qq|
+      </td>
+    </tr>|;
+
+  %labels = ();
+  @values = ();
+  my $i = 0;
+  foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
+    push(@values, $item);
+    $labels{$item} = $item;
+  }
+  
+  $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
+  my $currencies = qq|
+    <tr>
+      <th align="right">| . $locale->text('Currency') . qq|</th>
+      <td>| .
+        NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+                             '-values' => \@values, '-labels' => \%labels)) . qq|
+      </td>
+    </tr>|;
+
+
   $form->{exchangerate} =
     $form->format_amount(\%myconfig, $form->{exchangerate});
 
@@ -558,34 +590,6 @@ sub form_header {
 |;
   }
 
-  if (@{ $form->{TAXZONE} }) {
-    $form->{selecttaxzone} = "";
-    foreach $item (@{ $form->{TAXZONE} }) {
-      if ($item->{id} == $form->{taxzone_id}) {
-        $form->{selecttaxzone} .=
-          "<option value=$item->{id} selected>" . H($item->{description}) .
-          "</option>";
-      } else {
-        $form->{selecttaxzone} .=
-          "<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>/;
-    }
-  }
-
-  $taxzone = qq|
-             <tr>
-               <th align=right>| . $locale->text('Steuersatz') . qq|</th>
-               <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
-               <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
-             </tr>|;
-
-
   if ($form->{type} !~ /_quotation$/) {
     $ordnumber = qq|
              <tr>
@@ -675,7 +679,10 @@ sub form_header {
 
   $vc =
     ($form->{"select$form->{vc}"})
-    ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
+    ? qq|<select name="$form->{vc}"
+onchange="document.getElementById('update_button').click();">| .
+    qq|$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="| .
+    Q($form->{"select$form->{vc}"}) . qq|">|
     : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
 
   $department = qq|
@@ -720,14 +727,17 @@ sub form_header {
   } elsif ($form->{resubmit}) {
     $onload = qq|document.oe.submit()|;
   } else {
-    $onload = "fokus()";
+    $onload = "focus()";
   }
 
   $credittext = $locale->text('Credit Limit exceeded!!!');
   if ($creditwarning) {
     $onload = qq|alert('$credittext')|;
   }
-
+  
+  $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+  $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
+  
   $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
   # show history button js
   $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
@@ -794,10 +804,7 @@ sub form_header {
               $taxzone
              $department
              <tr>
-               <th align=right>| . $locale->text('Currency') . qq|</th>
-               <td><select name=currency>$form->{selectcurrency}</select></td>
-               <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
-               <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
+               $currencies
                $exchangerate
              </tr>
              <tr>
@@ -807,7 +814,11 @@ sub form_header {
              <tr>
                <th align=right>| . $locale->text('Ship via') . qq|</th>
                <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
-             </tr>|;
+             </tr>
+              <tr>
+                <th align="right">| . $locale->text('Transaction description') . qq|</th>
+                <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
+              </tr>|;
 #              <tr>
 #                 <td colspan=4>
 #                   <table>
@@ -1060,7 +1071,7 @@ sub form_footer {
   <tr>
     <td>
 |;
-  &print_options;
+  print_options();
 
   print qq|
     </td>
@@ -1155,7 +1166,6 @@ sub form_footer {
 
 <input name=callback type=hidden value="$form->{callback}">
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1395,12 +1405,12 @@ sub search {
 
     # with JavaScript Calendar
     $button1 = qq|
-       <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
+       <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
        <input type=button name=transdatefrom id="trigger3" value=|
       . $locale->text('button') . qq|></td>
       |;
     $button2 = qq|
-       <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
+       <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
        <input type=button name=transdateto name=transdateto id="trigger4" value=|
       . $locale->text('button') . qq|></td>
      |;
@@ -1413,9 +1423,9 @@ sub search {
 
     # without JavaScript Calendar
     $button1 = qq|
-                              <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
+                              <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
     $button2 = qq|
-                              <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
+                              <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\></td>|;
   }
 
   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
@@ -1455,6 +1465,10 @@ sub search {
           <th align=right>$ordlabel</th>
           <td colspan=3><input name="$ordnumber" size=20></td>
         </tr>
+        <tr>
+          <th align="right">| . $locale->text('Transaction description') . qq|</th>
+          <td colspan="3"><input name="transaction_description" size=20></td>
+        </tr>
         <tr>
           <th align="right">| . $locale->text("Project Number") . qq|</th>
           <td colspan="3">$projectnumber</td>
@@ -1500,8 +1514,12 @@ sub search {
     . $locale->text('Tax') . qq|</td>
                <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
     . $locale->text('Total') . qq|</td>
+             </tr>
+             <tr>
           <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
           . $locale->text('Project Number') . qq|</td>
+          <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
+          . $locale->text('Transaction description') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
@@ -1520,7 +1538,6 @@ $jsscript
 
 <br>
 <input type=hidden name=nextsub value=orders>
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 <input type=hidden name=vc value=$form->{vc}>
@@ -1548,27 +1565,26 @@ sub orders {
 
   $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
 
-  $number     = $form->escape($form->{$ordnumber});
-  $name       = $form->escape($form->{ $form->{vc} });
-  $department = $form->escape($form->{department});
-
   # construct href
-  $href =
-    "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&notdelivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
-
-  # construct callback
-  $number     = $form->escape($form->{$ordnumber},    1);
-  $name       = $form->escape($form->{ $form->{vc} }, 1);
-  $department = $form->escape($form->{department},    1);
-
-  $callback =
-    "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&notdelivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
-
-  @columns =
-    $form->sort_columns("transdate", "reqdate",   "id",      "$ordnumber",
-                        "name",      "netamount", "tax",     "amount",
-                        "curr",      "employee",  "shipvia", "globalprojectnumber",
-                        "open",      "closed",    "delivered");
+  my @fields =
+    qw(type vc login password transdatefrom transdateto
+       open closed notdelivered delivered department
+       transaction_description);
+  $href = "$form->{script}?action=orders&"
+    . join("&", map { "${_}=" . E($form->{$_}) } @fields)
+    . "&${ordnumber}=" . E($form->{$ordnumber});
+  $callback = $href;
+
+  @columns = (
+    "transdate",               "reqdate",
+    "id",                      "$ordnumber",
+    "name",                    "netamount",
+    "tax",                     "amount",
+    "curr",                    "employee",
+    "shipvia",                 "globalprojectnumber",
+    "transaction_description", "open",
+    "closed",                  "delivered"
+  );
 
   $form->{l_open} = $form->{l_closed} = "Y"
     if ($form->{open} && $form->{closed});
@@ -1662,6 +1678,9 @@ sub orders {
 
   $column_header{employee} =
     qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
+  $column_header{transaction_description} =
+    qq|<th><a class=listheading href="$href&sort=transaction_description">|
+    . $locale->text("Transaction description") . qq|</a></th>|;
 
   $column_header{ids} = qq|<th></th>|;
 
@@ -1764,7 +1783,7 @@ sub orders {
     $column_data{reqdate}   = "<td>$oe->{reqdate}&nbsp;</td>";
 
     $column_data{$ordnumber} =
-      "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
+      "<td><a href=oe.pl?action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
     $column_data{name} = "<td>$oe->{name}</td>";
 
     $column_data{employee} = "<td>$oe->{employee}&nbsp;</td>";
@@ -1781,6 +1800,7 @@ sub orders {
     $column_data{"delivered"} = "<td>" .
       ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
       "</td>";
+    $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
 
     $i++;
     $i %= 2;
@@ -1832,7 +1852,6 @@ sub orders {
 
   if ($form->{type} =~ /sales_order/) {
     print qq|
-  <input type="hidden" name="path" value="$form->{path}">
   <input class"submit" type="submit" name="action" value="|
       . $locale->text('Continue') . qq|">
   <input type="hidden" name="nextsub" value="edit">
@@ -1855,7 +1874,6 @@ sub orders {
 <input type=hidden name=type value=$form->{type}>
 <input type=hidden name=vc value=$form->{vc}>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1973,6 +1991,7 @@ sub save_and_close {
 
   # saving the history
   if(!exists $form->{addition}) {
+    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
        $form->{addition} = "SAVED";
        $form->save_history($form->dbconnect(\%myconfig));
   }
@@ -2054,6 +2073,7 @@ sub save {
 
   # saving the history
   if(!exists $form->{addition}) {
+    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
        $form->{addition} = "SAVED";
        $form->save_history($form->dbconnect(\%myconfig));
   }
@@ -2125,6 +2145,7 @@ sub yes {
     $form->redirect($msg);
     # saving the history
     if(!exists $form->{addition}) {
+      $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
          $form->{addition} = "DELETED";
          $form->save_history($form->dbconnect(\%myconfig));
     }
@@ -2238,7 +2259,7 @@ sub invoice {
   # locale messages
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
-  require "$form->{path}/$form->{script}";
+  require "bin/mozilla/$form->{script}";
 
   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
 
@@ -2319,7 +2340,6 @@ sub backorder_exchangerate {
 
   print qq|
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -2473,6 +2493,10 @@ sub purchase_order {
     OE->close_order(\%myconfig, \%$form);
   }
 
+  if ($form->{type} =~ /^sales_/) {
+    delete($form->{ordnumber});
+  }
+
   $form->{cp_id} *= 1;
 
   $form->{title} = $locale->text('Add Purchase Order');
@@ -2492,6 +2516,10 @@ sub sales_order {
     OE->close_order(\%myconfig, $form);
   }
 
+  if ($form->{type} eq "purchase_order") {
+    delete($form->{ordnumber});
+  }
+
   $form->{cp_id} *= 1;
 
   $form->{title} = $locale->text('Add Sales Order');