Keine direkt vom Browser stammenden Strings bei open() verwenden.
[kivitendo-erp.git] / bin / mozilla / is.pl
index 3d48572..81ba521 100644 (file)
@@ -35,8 +35,8 @@ use SL::IS;
 use SL::PE;
 use Data::Dumper;
 
-require "$form->{path}/io.pl";
-require "$form->{path}/arap.pl";
+require "bin/mozilla/io.pl";
+require "bin/mozilla/arap.pl";
 require "bin/mozilla/drafts.pl";
 
 1;
@@ -61,7 +61,7 @@ sub add {
 
 
   $form->{callback} =
-    "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
+    "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   $form{jsscript} = "date";
@@ -167,19 +167,11 @@ sub invoice_links {
     $form->{shipto_id} = $shipto_id;
   }
 
-  # currencies
-  @curr = split(/:/, $form->{currencies});
-  chomp $curr[0];
-  $form->{defaultcurrency} = $curr[0];
-
-  map { $form->{selectcurrency} .= "<option>$_</option>\n" } @curr;
-
   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
   if (@{ $form->{all_customer} }) {
-    $form->{customer} = "$form->{customer}--$form->{customer_id}";
-    map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}</option>\n" }
-      (@{ $form->{all_customer} });
+     $form->{customer} = "$form->{customer}--$form->{customer_id}";
+     $form->{selectcustomer} = "$form->{customer}--$form->{customer_id}";
   }
 
   # departments
@@ -195,13 +187,6 @@ sub invoice_links {
 
   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
-  # sales staff
-  if ($form->{all_employees}) {
-    $form->{selectemployee} = "";
-    map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}</option>\n" }
-      (@{ $form->{all_employees} });
-  }
-
   # forex
   $form->{forex} = $form->{exchangerate};
   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
@@ -329,7 +314,7 @@ sub form_header {
   }
 
   my $set_duedate_url =
-    "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
+    "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
 
   my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
   push(@ { $form->{AJAX} }, $pjx);
@@ -344,7 +329,9 @@ sub form_header {
                                    "all" => 0,
                                    "old_id" => \@old_project_ids },
                    "employees" => "ALL_SALESMEN",
-                   "taxzones" => "ALL_TAXZONES");
+                   "taxzones" => "ALL_TAXZONES",
+                   "currencies" => "ALL_CURRENCIES",
+                   "customers" => "ALL_CUSTOMERS");
 
   my %labels;
   my @values = (undef);
@@ -357,6 +344,40 @@ sub form_header {
     NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
                          '-labels' => \%labels, '-default' => $form->{"cp_id"}));
 
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
+    push(@values, $item->{"id"});
+    $labels{$item->{"id"}} = $item->{"name"};
+  }
+
+  my $employees = qq|
+    <tr>
+      <th align="right">| . $locale->text('Employee') . qq|</th>
+      <td>| .
+        NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee_id"},
+                             '-values' => \@values, '-labels' => \%labels)) . qq|
+      </td>
+    </tr>|;
+
+
+  %labels = ();
+  @values = ();
+  foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
+    push(@values, $item->{name}.qq|--|.$item->{"id"});
+    $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
+  }
+
+  my $customers = qq|
+      <th align="right">| . $locale->text('Customer') . qq|</th>
+      <td>| . 
+        (($myconfig{vclimit} <=  scalar(@values)) 
+              ? qq|<input type="text" value="| . H($form->{"oldcustomer"}) . qq|" name="customer">| 
+              : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer}, 
+                             '-onChange' => 'document.getElementById(\'update_button\').click();',
+                             '-values' => \@values, '-labels' => \%labels)))) . qq|
+      </td>|;
+    
   %labels = ();
   @values = ("");
   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
@@ -372,6 +393,23 @@ sub form_header {
                          '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
     . qq|</td>|;
 
+  %labels = ();
+  @values = ();
+  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>|;
+
   %labels = ();
   @values = ("");
   foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
@@ -472,14 +510,6 @@ sub form_header {
 <input type="hidden" name="forex" value="$form->{forex}">
 |;
 
-  $customer =
-    ($form->{selectcustomer})
-    ? qq|<select name="customer"
-onchange="document.getElementById('update_button').click();">| .
-    qq|$form->{selectcustomer}</select>\n<input type="hidden" name="selectcustomer" value="| .
-    Q($form->{selectcustomer}) . qq|">|
-    : qq|<input name="customer" value="$form->{customer}" size="35">|;
-
   $department = qq|
               <tr>
                <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
@@ -642,11 +672,11 @@ print qq|
          <td>
            <table>
              <tr>
-               <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
-               <td colspan="3">$customer</td>
+               $customers
     <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
                <input type="hidden" name="customer_id" value="$form->{customer_id}">
-               <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
+    <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
+        <input type="hidden" name="selectcustomer" value="1">
                 <th align="right" nowrap>|
     . $locale->text('Contact Person') . qq|</th>
                 <td colspan="3">$contact</td>
@@ -676,10 +706,7 @@ print qq|
               $taxzone
              $department
              <tr>
-               <th align="right" nowrap>| . $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
                <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
                <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
                $exchangerate
@@ -692,7 +719,11 @@ print qq|
              <tr>
                <th align="right" nowrap>| . $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">| . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq|</td>
+              </tr>|;
 #               <tr>
 #                 <td colspan=4>
 #                   <table>
@@ -717,12 +748,7 @@ print qq|      </table>
          </td>
          <td align="right">
            <table>
-             <tr>
-               <th align="right" nowrap>| . $locale->text('Employee') . qq|</th>
-               <td colspan="2"><select name="employee">$form->{selectemployee}</select></td>
-               <input type="hidden" name="selectemployee" value="$form->{selectemployee}">
-                <td></td>
-             </tr>
+             $employees
         $salesman
 |;
 if ($form->{type} eq "credit_note") {
@@ -823,13 +849,13 @@ sub form_footer {
     qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
   $intnotes =
     qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
-
-  $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+  $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
 
   $taxincluded = "";
   if ($form->{taxaccounts}) {
     $taxincluded = qq|
-               <input name="taxincluded" class="checkbox" type="checkbox" value=$form->{taxincluded}> <b>|
+               <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
       . $locale->text('Tax Included') . qq|</b><br><br>|;
   }
 
@@ -1165,7 +1191,7 @@ if ($form->{type} eq "credit_note") {
 $cgi->hidden("-name" => "callback", "-value" => $form->{callback}) 
 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
-map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(path login password));
+map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(login password));
 print qq|
 </form>
 
@@ -1186,10 +1212,19 @@ sub update {
     $form->{print_and_post} = 0;
   }
 
+  
+  if($form->{taxincluded}) {
+    $taxincluded = "checked";
+  }
   $form->{update} = 1;
 
   &check_name(customer);
 
+  if(!$form->{taxincluded}) {
+    $form->{taxincluded} = $taxincluded;
+  }
+
+
   $form->{exchangerate} = $exchangerate
     if (
         $form->{forex} = (
@@ -1377,6 +1412,9 @@ sub post {
   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
   $form->isblank("customer", $locale->text('Customer missing!'));
 
+  $form->{invnumber} =~ s/^\s*//g;
+  $form->{invnumber} =~ s/\s*$//g;
+
   # if oldcustomer ne customer redo form
   if (&check_name(customer)) {
     &update;
@@ -1487,21 +1525,25 @@ sub storno {
   }
 
   map({ my $key = $_; delete($form->{$key})
-          unless (grep({ $key eq $_ } qw(path login password id type))); }
+          unless (grep({ $key eq $_ } qw(login password id stylesheet type))); }
       keys(%{ $form }));
 
-  &invoice_links;
-  &prepare_invoice;
+  invoice_links();
+  prepare_invoice();
   relink_accounts();
 
+  # Payments must not be recorded for the new storno invoice.
+  $form->{paidaccounts} = 0;
+  map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
+
   $form->{storno_id} = $form->{id};
   $form->{storno} = 1;
   $form->{id} = "";
   $form->{invnumber} = "Storno zu " . $form->{invnumber};
+  $form->{rowcount}++;
 
-  &post();
+  post();
   $lxdebug->leave_sub();
-
 }
 
 sub preview {