Ersatzmuster für Lieferanten/Kundennamen, die \n und/oder \r enthalten eingefügt...
[kivitendo-erp.git] / bin / mozilla / ar.pl
index da4315b..7f67058 100644 (file)
@@ -89,8 +89,10 @@ sub add {
     "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
-  &create_links;
   AR->get_transdate(\%myconfig, $form);
+  $form->{initial_transdate} = $form->{transdate};
+  &create_links;
+  $form->{transdate} = $form->{initial_transdate};
   &display_form;
   $lxdebug->leave_sub();
 }
@@ -134,6 +136,9 @@ sub create_links {
   $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
   $form->{rowcount}    = 1;
 
+  # notes
+  $form->{notes} = $form->{intnotes} unless $form->{notes};
+
   # currencies
   @curr = split(/:/, $form->{currencies});
   chomp $curr[0];
@@ -257,8 +262,6 @@ sub create_links {
     }
   }
 
-  $lxdebug->message(0, "1 ARselected $form->{ARselected}");
-
   $form->{taxincluded}  = $taxincluded if ($form->{id});
   $form->{paidaccounts} = 1            if not defined $form->{paidaccounts};
 
@@ -359,8 +362,6 @@ sub form_header {
     }
   }
 
-  $taxincluded = "";
-
   $taxincluded = qq|
              <tr>
                <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
@@ -428,6 +429,7 @@ sub form_header {
   my (%AR_amount_labels, @AR_amount_values);
   my (%AR_labels, @AR_values);
   my (%AR_paid_labels, @AR_paid_values);
+  my %charts;
   my $taxchart_init;
 
   foreach my $item (@{ $form->{ALL_CHARTS} }) {
@@ -447,16 +449,20 @@ sub form_header {
       $AR_paid_labels{$item->{accno}} =
         "$item->{accno}--$item->{description}";
     }
+
+    $charts{$item->{accno}} = $item;
   }
 
   my %taxchart_labels = ();
   my @taxchart_values = ();
+  my %taxcharts = ();
   foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
     my $key = "$item->{id}--$item->{rate}";
     $taxchart_init = $key if ($taxchart_init eq $item->{id});
     push(@taxchart_values, $key);
     $taxchart_labels{$key} =
       "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
+    $taxcharts{$item->{id}} = $item;
   }
 
   $form->{fokus} = "arledger.customer";
@@ -610,6 +616,24 @@ $jsscript
       $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
     $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
 
+    my $selected_accno_full;
+    my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
+    my $item = $charts{$accno_row};
+    $selected_accno_full = "$item->{accno}--$item->{tax_id}";
+
+    my $selected_taxchart = $form->{"taxchart_$i"};
+    my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
+    my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
+
+    if ($previous_accno &&
+        ($previous_accno eq $selected_accno) &&
+        ($previous_tax_id ne $selected_tax_id)) {
+      my $item = $taxcharts{$selected_tax_id};
+      $selected_taxchart = "$item->{id}--$item->{rate}";
+    }
+
+    $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
+
     $selectAR_amount =
       NTI($cgi->popup_menu('-name' => "AR_amount_$i",
                            '-id' => "AR_amount_$i",
@@ -617,7 +641,9 @@ $jsscript
                            '-onChange' => "setTaxkey(this, $i)",
                            '-values' => \@AR_amount_values,
                            '-labels' => \%AR_amount_labels,
-                           '-default' => $form->{"AR_amount_$i"}));
+                           '-default' => $selected_accno_full))
+      . $cgi->hidden('-name' => "previous_AR_amount_$i",
+                     '-default' => $selected_accno_full);
 
     $tax = qq|<td>| .
       NTI($cgi->popup_menu('-name' => "taxchart_$i",
@@ -625,8 +651,7 @@ $jsscript
                            '-style' => 'width:200px',
                            '-values' => \@taxchart_values,
                            '-labels' => \%taxchart_labels,
-                           '-default' => $form->{"taxchart_$i"} eq "" ?
-                           $taxchart_init : $form->{"taxchart_$i"}))
+                           '-default' => $selected_taxchart))
       . qq|</td>|;
 
     $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
@@ -824,6 +849,15 @@ sub form_footer {
 <br>
 |;
 
+  if (!$form->{id} && $form->{draft_id}) {
+    print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
+                             '-value' => 1, '-checked' => $form->{remove_draft},
+                             '-label' => '')) .
+          qq|&nbsp;<label for="remove_draft">| .
+          $locale->text("Remove draft when posting") .
+          qq|</label><br>|);
+  }
+
   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
@@ -1050,9 +1084,6 @@ sub post {
 
   $form->{AR}{receivables} = $form->{ARselected};
 
-  $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
-    unless $form->{invnumber};
-
   $form->{id} = 0 if $form->{postasnew};
   if (AR->post_transaction(\%myconfig, \%$form)) {
     # saving the history