Probleme mit mehreren Währungen und Wechselkursen behoben.
[kivitendo-erp.git] / bin / mozilla / is.pl
index 7d3be25..feb43ac 100644 (file)
@@ -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,6 +279,13 @@ 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") {
@@ -300,7 +302,7 @@ sub form_header {
       }
     }
   }
-
+  $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,17 +376,19 @@ 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">|
+              ? 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>|;
 
@@ -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>|;
   }
@@ -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>
@@ -662,7 +660,7 @@ sub form_header {
           <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
@@ -674,7 +672,7 @@ sub form_header {
         $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
@@ -1011,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}) {
@@ -1032,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"}) {
@@ -1062,6 +1064,23 @@ if ($form->{type} eq "credit_note") {
     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
   }
 
+  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>
@@ -1152,11 +1171,16 @@ 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|
 
@@ -1177,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();
 
@@ -1352,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);
@@ -1373,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!'));
 
@@ -1383,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!'));