CGI::Carp qw(fatalsToBrowser); wieder rausgenommen
[kivitendo-erp.git] / bin / mozilla / ir.pl
index e088def..87ac207 100644 (file)
 #======================================================================
 
 use SL::IR;
+use SL::IS;
 use SL::PE;
 
-require "$form->{path}/io.pl";
-require "$form->{path}/arap.pl";
-require "$form->{path}/common.pl";
+require "bin/mozilla/io.pl";
+require "bin/mozilla/arap.pl";
+require "bin/mozilla/common.pl";
 require "bin/mozilla/drafts.pl";
 
 1;
@@ -239,6 +240,9 @@ sub form_header {
   #quote selectvendor Bug 133
   $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
 
+  #substitute \n and \r to \s (bug 543)
+  $form->{"selectvendor"} =~ s/[\n\r]/ /g;
+  
   $form->{exchangerate} =
     $form->format_amount(\%myconfig, $form->{exchangerate});
 
@@ -274,9 +278,11 @@ sub form_header {
   $form->get_lists("contacts" => "ALL_CONTACTS",
                    "projects" => { "key" => "ALL_PROJECTS",
                                    "all" => 0,
-                                   "old_id" => \@old_project_ids });
+                                   "old_id" => \@old_project_ids },
+                   "taxzones" => "ALL_TAXZONES");
 
-  my (%labels, @values);
+  my %labels;
+  my @values = (undef);
   foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
     push(@values, $item->{"cp_id"});
     $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
@@ -297,38 +303,40 @@ sub form_header {
                          '-labels' => \%labels,
                          '-default' => $form->{"globalproject_id"}));
 
-  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/;
-    }
+  %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><select name=taxzone_id>$form->{selecttaxzone}</select></td>
-               <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
-             </tr>|;
-
+  if (!$form->{"id"}) {
+    $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>|;
 
+  } else {
+    $taxzone = qq|
+    <tr>
+      <th align="right">| . $locale->text('Steuersatz') . qq|</th>
+      <td>
+        <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
+        | . H($labels{$form->{"taxzone_id"}}) . qq|
+      </td>
+    </tr>|;
+  }
 
   $vendor =
     ($form->{selectvendor})
-    ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
+    ? qq|<select name="vendor"
+onchange="document.getElementById('update_button').click();">| .
+    qq|$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="| .
+    Q($form->{selectvendor}) . qq|">|
     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
   $department = qq|
@@ -349,12 +357,12 @@ sub form_header {
 
     # with JavaScript Calendar
     $button1 = qq|
-       <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
+       <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"></td>
        <td><input type=button name=invdate id="trigger1" value=|
       . $locale->text('button') . qq|></td>
        |;
     $button2 = qq|
-       <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
+       <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}"  onBlur=\"check_right_date_format(this)\"></td>
        <td width="4"><input type=button name=duedate id="trigger2" value=|
       . $locale->text('button') . qq|></td></td>
      |;
@@ -367,12 +375,13 @@ sub form_header {
 
     # without JavaScript Calendar
     $button1 =
-      qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
+      qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}"  onBlur=\"check_right_date_format(this)\"></td>|;
     $button2 =
-      qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
+      qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
   }
 
   $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
+  $form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
   $jsscript .=
     $form->write_trigger(\%myconfig, 2,
@@ -380,9 +389,11 @@ sub form_header {
                          "quodate", "BL", "trigger_quodate");
 
   $form->header;
-
+  $onload = qq|focus()|;
+  $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+  $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   print qq|
-<body>
+<body onLoad="$onload">
 
 <form method=post action=$form->{script}>
 
@@ -475,12 +486,12 @@ sub form_header {
              </tr>
         <tr>
           <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
-          <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
+          <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\"></td>
           <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
         </tr>
         <tr>
           <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
-          <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
+          <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\"></td>
           <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
         </tr>
              <tr>
@@ -747,12 +758,12 @@ sub form_footer {
 |;
 
     $column_data{"paid_$i"} =
-      qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
+      qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
     $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
     $column_data{"AP_paid_$i"}      =
       qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
     $column_data{"datepaid_$i"} =
-      qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
+      qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
     $column_data{"source_$i"} =
       qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
@@ -785,12 +796,14 @@ sub form_footer {
   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
   if ($form->{id}) {
+    my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
+
     print qq|<input class=submit type=submit name=action value="|
       . $locale->text('Post Payment') . qq|">
 |;
     print qq|<input class=submit type=submit name=action value="|
       . $locale->text('Storno') . qq|">
-| unless ($form->{storno});
+| if ($show_storno);
     if ($form->{radier}) {
     print qq|
     <input class=submit type=submit name=action value="|
@@ -813,19 +826,8 @@ sub form_footer {
                        '-class' => 'submit'));
   }
 
-  print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
-    qq|
-
-<input type=hidden name=rowcount value=$form->{rowcount}>
-
-<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}>
-|
-  . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
-  . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
+  print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
+  $form->hide_form(qw(rowcount callback draft_id draft_description login password));
 
   # button for saving history
   if($form->{id} ne "") {
@@ -972,15 +974,27 @@ sub storno {
     $form->error($locale->text('Cannot storno storno invoice!'));
   }
 
-  if (IR->has_storno(\%myconfig, $form)) {
+  if (IS->has_storno(\%myconfig, $form, "ap")) {
     $form->error($locale->text("Invoice has already been storno'd!"));
   }
 
+  invoice_links();
+  prepare_invoice();
+  relink_accounts();
+  
+  # saving the history
+  if(!exists $form->{addition} && $form->{id} ne "") {
+    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};  
+    $form->{addition} = "CANCELED";
+    $form->save_history($form->dbconnect(\%myconfig));
+  }
+  # /saving the history
+  
   $form->{storno_id} = $form->{id};
   $form->{storno} = 1;
   $form->{id} = "";
   $form->{invnumber} = "Storno zu " . $form->{invnumber};
-
+  $form->{rowcount}++;
   &post();
   $lxdebug->leave_sub();
 
@@ -1024,6 +1038,7 @@ sub post_payment {
        
        if(!exists $form->{addition} && $form->{id} ne "") {
                # saving the history
+      $form->{snumbers} = qq|invnumber_| . $form->{invnumber};  
                $form->{addition} = "PAYMENT POSTED";
                $form->save_history($form->dbconnect(\%myconfig));
                # /saving the history 
@@ -1087,7 +1102,8 @@ sub post {
   if (IR->post_invoice(\%myconfig, \%$form)){
        # saving the history
        if(!exists $form->{addition} && $form->{id} ne "") {
-               $form->{addition} = "POSTED";
+      $form->{snumbers} = qq|invnumber_| . $form->{invnumber};  
+      $form->{addition} = "POSTED";
                #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
                $form->save_history($form->dbconnect(\%myconfig));
        }
@@ -1140,6 +1156,7 @@ sub yes {
   if (IR->delete_invoice(\%myconfig, \%$form)) {
     # saving the history
     if(!exists $form->{addition}) {
+      $form->{snumbers} = qq|invnumber_| . $form->{invnumber};  
          $form->{addition} = "DELETED";
          $form->save_history($form->dbconnect(\%myconfig));
     }