Probleme mit mehreren Währungen und Wechselkursen behoben.
[kivitendo-erp.git] / bin / mozilla / is.pl
index f02e066..feb43ac 100644 (file)
@@ -83,7 +83,7 @@ sub edit {
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
   #/show hhistory button
-  
+
   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
   {
     $form->error("Access Denied");
@@ -169,11 +169,6 @@ sub invoice_links {
 
   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
 
-  if (@{ $form->{all_customer} }) {
-     $form->{customer} = "$form->{customer}--$form->{customer_id}";
-     $form->{selectcustomer} = "$form->{customer}--$form->{customer_id}";
-  }
-
   # departments
   if ($form->{all_departments}) {
     $form->{selectdepartment} = "<option>\n";
@@ -284,23 +279,30 @@ sub prepare_invoice {
 sub form_header {
   $lxdebug->enter_sub();
 
+  if ($form->{old_employee_id}) {
+    $form->{employee_id} = $form->{old_employee_id};
+  }
+  if ($form->{old_salesman_id}) {
+    $form->{salesman_id} = $form->{old_salesman_id};
+  }
+
   if ($edit) {
 
     if ($form->{type} eq "credit_note") {
       $form->{title} = $locale->text('Edit Credit Note');
-    
+
       if ($form->{storno}) {
         $form->{title} = $locale->text('Edit Storno Credit Note');
       }
     } else {
       $form->{title} = $locale->text('Edit Sales Invoice');
-    
+
       if ($form->{storno}) {
         $form->{title} = $locale->text('Edit Storno Invoice');
       }
     }
   }
-
+  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
   $form->{radier} =
     ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
@@ -346,7 +348,7 @@ sub form_header {
     <tr>
       <th align="right">| . $locale->text('Contact Person') . qq|</th>
       <td>| .
-      NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
+      NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
                            '-labels' => \%labels, '-default' => $form->{"cp_id"}))
       . qq|
       </td>
@@ -357,14 +359,14 @@ sub form_header {
   @values = ();
   foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
     push(@values, $item->{"id"});
-    $labels{$item->{"id"}} = $item->{"name"};
+    $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
   }
 
   my $employees = qq|
     <tr>
       <th align="right">| . $locale->text('Employee') . qq|</th>
       <td>| .
-        NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee_id"},
+        NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
                              '-values' => \@values, '-labels' => \%labels)) . qq|
       </td>
     </tr>|;
@@ -374,25 +376,27 @@ sub form_header {
   @values = ();
   foreach my $item (@{ $form->{"ALL_CUSTOMERS"} }) {
     push(@values, $item->{name}.qq|--|.$item->{"id"});
-    $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
+    $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
   }
 
+  $form->{selectcustomer} = ($myconfig{vclimit} > scalar(@values));
+
   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}, 
+      <td>| .
+        (($myconfig{vclimit} <=  scalar(@values))
+              ? qq|<input type="text" value="| . H($form->{customer}) . qq|" name="customer">|
+              : (NTI($cgi->popup_menu('-name' => 'customer', '-default' => $form->{oldcustomer},
                              '-onChange' => 'document.getElementById(\'update_button\').click();',
-                             '-values' => \@values, '-labels' => \%labels)))) . qq|
+                             '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
+        <input type="button" value="?" onclick="show_vc_details('customer')">
       </td>|;
-    
+
   %labels = ();
   @values = ("");
   foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
     push(@values, $item->{"shipto_id"});
-    $labels{$item->{"shipto_id"}} =
-      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
+    $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
   }
 
   my $shipto;
@@ -401,7 +405,7 @@ sub form_header {
     <tr>
       <th align="right">| . $locale->text('Shipping Address') . qq|</th>
       <td>| .
-      NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
+      NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
                            '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
     . qq|</td>|;
   }
@@ -412,7 +416,7 @@ sub form_header {
     push(@values, $item);
     $labels{$item} = $item;
   }
-  
+
   $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
   my $currencies;
   if (scalar @values) {
@@ -438,7 +442,7 @@ sub form_header {
                          '-default' => $form->{"globalproject_id"}));
 
   %labels = ();
-  @values = ("");
+  @values = ();
   foreach my $item (@{ $form->{ALL_SALESMEN} }) {
     push(@values, $item->{id});
     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
@@ -448,8 +452,8 @@ sub form_header {
     qq|<tr>
           <th align="right">| . $locale->text('Salesman') . qq|</th>
           <td>| .
-     NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
-                               '-values' => \@values, '-labels' => \%labels))
+     NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id},
+                          '-values' => \@values, '-labels' => \%labels))
      . qq|</td>
          </tr>|;
 
@@ -466,7 +470,7 @@ sub form_header {
       <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|
+                             '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
       </td>
     </tr>|;
 
@@ -488,12 +492,6 @@ sub form_header {
       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
 
-  #quote customer Bug 133
-  $form->{selectcustomer} = $form->quote($form->{selectcustomer});
-
-  #substitute \n and \r to \s (bug 543)
-  $form->{selectcustomer} =~ s/[\n\r]/&nbsp;/g;
-  
   if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
     $creditwarning = 1;
   } else {
@@ -529,7 +527,7 @@ sub form_header {
   $department = qq|
               <tr>
                <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
-               <td colspan="3"><select name="department">$form->{selectdepartment}</select>
+               <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
                <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
                </td>
              </tr>
@@ -540,13 +538,11 @@ sub form_header {
   if ($form->{business}) {
     $business = qq|
              <tr>
-               <th align="right">| . $locale->text('Business') . qq|</th>
-               <td>$form->{business}</td>
-               <th align="right">| . $locale->text('Trade Discount') . qq|</th>
-               <td>|
+          <th align="right">| . $locale->text('Customer type') . qq|</th>
+          <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
       . qq| %</td>
-             </tr>
+        </tr>
 |;
   }
 
@@ -567,67 +563,46 @@ sub form_header {
   $form->{fokus} = "invoice.customer";
 
   # use JavaScript Calendar or not
-  $form->{jsscript} = $jscalendar;
+  $form->{jsscript} = 1;
   $jsscript = "";
   if ($form->{type} eq "credit_note") {
-    if ($form->{jsscript}) {
-  
-      # with JavaScript Calendar
-      $button1 = qq|
-        <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
-         <input type="button" name="invdate" id="trigger1" value="|
-        . $locale->text('button') . qq|"></td>|;
-       
-      #write Trigger
-      $jsscript =
-        Form->write_trigger(\%myconfig,     "1",
-                            "invdate",      "BL",
-                            "trigger1");
-    } else {
-  
-      # without JavaScript Calendar
-      $button1 =
-        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>|;
-    }
+    $button1 = qq|
+      <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
+       <input type="button" name="invdate" id="trigger1" value="|
+      . $locale->text('button') . qq|"></td>|;
+
+    #write Trigger
+    $jsscript =
+      Form->write_trigger(\%myconfig,     "1",
+                          "invdate",      "BL",
+                          "trigger1");
   } else {
-    if ($form->{jsscript}) {
-  
-      # with JavaScript Calendar
-      $button1 = qq|
-        <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
-         <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}" onBlur=\"check_right_date_format(this)\">
-         <input type="button" name="duedate" id="trigger2" value="|
-        . $locale->text('button') . qq|"></td></td>
+    $button1 = qq|
+      <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
+       <input type="button" name="invdate" id="trigger1" value="|
+      . $locale->text('button') . qq|"></td>
       |;
-      $button3 = qq|
-        <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
-         <input type="button" name="deliverydate" id="trigger3" value="|
-        . $locale->text('button') . qq|"></td></td>
-      |;
-  
-      #write Trigger
-      $jsscript =
-        Form->write_trigger(\%myconfig,     "3",
-                            "invdate",      "BL",
-                            "trigger1",     "duedate",
-                            "BL",           "trigger2",
-                            "deliverydate", "BL",
-                            "trigger3");
-    } else {
-  
-      # without JavaScript Calendar
-      $button1 =
-        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} onBlur=\"check_right_date_format(this)\"></td>|;
-    }
+    $button2 = qq|
+      <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
+       <input type="button" name="duedate" id="trigger2" value="|
+      . $locale->text('button') . qq|"></td></td>
+    |;
+    $button3 = qq|
+      <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}" onBlur=\"check_right_date_format(this)\">
+       <input type="button" name="deliverydate" id="trigger3" value="|
+      . $locale->text('button') . qq|"></td></td>
+    |;
+
+    #write Trigger
+    $jsscript =
+      Form->write_trigger(\%myconfig,     "3",
+                          "invdate",      "BL",
+                          "trigger1",     "duedate",
+                          "BL",           "trigger2",
+                          "deliverydate", "BL",
+                          "trigger3");
   }
+
   if ($form->{resubmit} && ($form->{format} eq "html")) {
     $onload =
       qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
@@ -644,6 +619,7 @@ sub form_header {
   }
 
   $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
+  $form->{javascript}   .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
 
   $jsscript .=
     $form->write_trigger(\%myconfig, 2,
@@ -663,11 +639,13 @@ sub form_header {
 
 <form method="post" name="invoice" action="$form->{script}">
 | ;
-map({print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} 
-     qw(id action type media format queued printed emailed title vc discount 
-        creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id)) ;
-print ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") ;
-print qq|
+
+  $form->hide_form(qw(id action type media format queued printed emailed title vc discount
+                      creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
+                      max_dunning_level dunning_amount));
+  print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
+
+  print qq|
 
 <input type="hidden" name="lizenzen" value="$lizenzen">
 
@@ -682,7 +660,7 @@ print qq|
           <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="selectcustomer" value="1">
+          <input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">
         </tr>
         $contact
         $shipto
@@ -694,7 +672,7 @@ print qq|
         $business
              <tr>
                <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
-               <td colspan="3"><select name="AR" style="width:280px;">$form->{selectAR}</select></td>
+               <td colspan="3"><select name="AR" style="width:250px;">$form->{selectAR}</select></td>
                <input type="hidden" name="selectAR" value="$form->{selectAR}">
              </tr>
               $taxzone
@@ -808,20 +786,20 @@ print qq|     <tr>
     <td>
     </td>
   </tr>
-| . 
+| .
 $jsscript
 . qq|
 <!-- shipto are in hidden variables -->
 | ;
-map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } 
+map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
        qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2));
 print qq|<!-- email variables --> |;
-map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } 
+map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
     qw(message email subject cc bcc taxaccounts));
 print qq|<input type="hidden" name="webdav" value="| . $webdav . qq|">|;
 
   foreach $item (split(/ /, $form->{taxaccounts})) {
-    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } 
+    map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
     ("${item}_rate", "${item}_description", "${item}_taxnumber"));
   }
   $lxdebug->leave_sub();
@@ -843,7 +821,7 @@ 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" : "");
 
   $taxincluded = "";
@@ -1031,7 +1009,8 @@ if ($form->{type} eq "credit_note") {
         </tr>
 ";
 
-  my @triggers = ();
+  my @triggers  = ();
+  my $totalpaid = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   for $i (1 .. $form->{paidaccounts}) {
@@ -1052,6 +1031,9 @@ if ($form->{type} eq "credit_note") {
     $form->{"exchangerate_$i"} =
       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
+    if ($form->{"exchangerate_$i"} == 0) {
+      $form->{"exchangerate_$i"} = "";
+    }
     $exchangerate = qq|&nbsp;|;
     if ($form->{currency} ne $form->{defaultcurrency}) {
       if ($form->{"forex_$i"}) {
@@ -1082,7 +1064,24 @@ if ($form->{type} eq "credit_note") {
     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
   }
 
-  map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal)); 
+  my $paid_missing = $form->{oldinvtotal} - $totalpaid;
+
+  print qq|
+    <tr>
+      <td></td>
+      <td></td>
+      <td align="center">| . $locale->text('Total') . qq|</td>
+      <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
+    </tr>
+    <tr>
+      <td></td>
+      <td></td>
+      <td align="center">| . $locale->text('Missing amount') . qq|</td>
+      <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
+    </tr>
+|;
+
+  map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
   print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
     </table>
     </td>
@@ -1172,17 +1171,22 @@ if ($form->{type} eq "credit_note") {
          . Q($form->{id})
          . qq|);" name="history" id="history" value="|
          . $locale->text('history')
-         . qq|">|;
+         . qq|"> |;
   }
   # /button for saving history
-
-
+  
+  # mark_as_paid button 
+  if($form->{id} ne "") {  
+    print qq|<input type="submit" class="submit" name="action" value="| 
+          . $locale->text('mark as paid') . qq|">|;
+  }
+  # /mark_as_paid button
   print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
     qq|
 
 <input type="hidden" name="rowcount" value="$form->{rowcount}">
 | .
-$cgi->hidden("-name" => "callback", "-value" => $form->{callback}) 
+$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(login password));
@@ -1197,6 +1201,12 @@ print qq|
   $lxdebug->leave_sub();
 }
 
+sub mark_as_paid {
+  $lxdebug->enter_sub();
+  &mark_as_paid_common(\%myconfig,"ar");  
+  $lxdebug->leave_sub();
+}
+
 sub update {
   $lxdebug->enter_sub();
 
@@ -1206,7 +1216,7 @@ sub update {
     $form->{print_and_post} = 0;
   }
 
-  
+
   if($form->{taxincluded}) {
     $taxincluded = "checked";
   }
@@ -1372,6 +1382,8 @@ sub update {
 
 sub post_payment {
   $lxdebug->enter_sub();
+
+  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
   for $i (1 .. $form->{paidaccounts}) {
     if ($form->{"paid_$i"}) {
       $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
@@ -1393,7 +1405,7 @@ sub post_payment {
   ($form->{AR})      = split /--/, $form->{AR};
   ($form->{AR_paid}) = split /--/, $form->{AR_paid};
   relink_accounts();
-  $form->redirect($locale->text(' Payment posted!'))
+  $form->redirect($locale->text('Payment posted!'))
       if (IS->post_payment(\%myconfig, \%$form));
     $form->error($locale->text('Cannot post payment!'));
 
@@ -1403,6 +1415,8 @@ sub post_payment {
 
 sub post {
   $lxdebug->enter_sub();
+
+  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
   $form->isblank("customer", $locale->text('Customer missing!'));
 
@@ -1475,7 +1489,7 @@ sub post {
                                           "POSTED";
     $form->save_history($form->dbconnect(\%myconfig));
   }
-  
+
   $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
     unless $print_post;
 
@@ -1607,7 +1621,7 @@ sub credit_note {
   $form->{script} = 'is.pl';
   $script         = "is";
   $buysell        = 'buy';
-  
+
 
   # bo creates the id, reset it
   map { delete $form->{$_} }
@@ -1650,12 +1664,12 @@ sub yes {
   if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
     # saving the history
        if(!exists $form->{addition}) {
-    $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; 
+    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
          $form->{addition} = "DELETED";
          $form->save_history($form->dbconnect(\%myconfig));
     }
-    # /saving the history 
-    $form->redirect($locale->text('Invoice deleted!')); 
+    # /saving the history
+    $form->redirect($locale->text('Invoice deleted!'));
   }
   $form->error($locale->text('Cannot delete invoice!'));