Beim Wechsel des Kunden das Konto und den Steuerschlüssel richtig vorbelegen.
[kivitendo-erp.git] / bin / mozilla / ar.pl
index b8aa128..c410680 100644 (file)
@@ -32,7 +32,7 @@
 #======================================================================
 
 use POSIX qw(strftime);
-use List::Util qw(sum);
+use List::Util qw(sum first);
 
 use SL::AR;
 use SL::FU;
@@ -577,7 +577,13 @@ $jsscript
       $selected_taxchart = "$item->{id}--$item->{rate}";
     }
 
-    $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
+    if (!$form->{"taxchart_$i"}) {
+      if ($form->{"AR_amount_$i"} =~ m/.--./) {
+        $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
+      } else {
+        $selected_taxchart = $taxchart_init;
+      }
+    }
 
     $selectAR_amount =
       NTI($cgi->popup_menu('-name' => "AR_amount_$i",
@@ -843,7 +849,7 @@ $follow_ups_block
 
   # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
   print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
-    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar'));
+    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($total_paid == 0) || ($total_paid eq "")));
 
   if ($form->{id}) {
     if ($form->{radier}) {
@@ -915,6 +921,8 @@ sub update {
 
   $form->{invtotal} = 0;
 
+  delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
+
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(exchangerate creditlimit creditremaining);
 
@@ -954,9 +962,19 @@ sub update {
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
   $form->{invdate} = $form->{transdate};
-  my $save_AR = $form->{AR};
-  check_name("customer");
-  $form->{AR} = $save_AR;
+
+  $form->{invdate} = $form->{transdate};
+
+  my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
+
+  &check_name("customer");
+
+  $form->{AR} = $saved_variables{AR};
+  if ($saved_variables{AR_amount_1} =~ m/.--./) {
+    map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
+  } else {
+    delete $form->{taxchart_1};
+  }
 
   $form->{invtotal} =
     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
@@ -1507,7 +1525,7 @@ sub ar_transactions {
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
 
-  $report->set_export_options('ar_transactions', @hidden_variables);
+  $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
 
   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
@@ -1620,41 +1638,6 @@ sub ar_transactions {
   $lxdebug->leave_sub();
 }
 
-sub sales_invoice {
-  $lxdebug->enter_sub();
-
-  $auth->assert('invoice_edit');
-
-
-  $form->{script} = 'is.pl';
-  $script         = "is";
-  $form->{type} = "invoice";
-  $locale = new Locale "$myconfig{countrycode}", "$script";
-
-  require "bin/mozilla/$form->{script}";
-  &add;
-
-  $lxdebug->leave_sub();
-}
-
-sub ar_transaction {
-  $lxdebug->enter_sub();
-
-  $auth->assert('general_ledger');
-
-
-  $form->{script} = 'ar.pl';
-  $script         = "ar";
-  $locale = new Locale "$myconfig{countrycode}", "$script";
-
-  require "bin/mozilla/$form->{script}";
-  &add;
-
-  $lxdebug->leave_sub();
-}
-
-
-
 sub storno {
   $lxdebug->enter_sub();