]> wagnertech.de Git - mfinanz.git/blobdiff - bin/mozilla/ap.pl
Belegvorlagen: Zeilen ohne Betrag beibehalten
[mfinanz.git] / bin / mozilla / ap.pl
index 98f6df7504648e4454094758cf6e5e884014c1d7..23d1b0a5c8325f19c9c0a7b786ec37abc591feca 100644 (file)
@@ -114,7 +114,7 @@ sub load_record_template {
   $::form->{AP_chart_id}      = $template->ar_ap_chart_id;
   $::form->{transdate}        = $today->to_kivitendo;
   $::form->{duedate}          = $today->to_kivitendo;
-  $::form->{rowcount}         = @{ $template->items } + 1;
+  $::form->{rowcount}         = @{ $template->items };
   $::form->{paidaccounts}     = 1;
   $::form->{$_}               = $template->$_ for qw(department_id ordnumber taxincluded notes);
 
@@ -152,7 +152,10 @@ sub load_record_template {
 
   flash('info', $::locale->text("The record template '#1' has been loaded.", $template->template_name));
 
-  update();
+  update(
+    keep_rows_without_amount => 1,
+    dont_add_new_row         => 1,
+  );
 }
 
 sub save_record_template {
@@ -165,7 +168,7 @@ sub save_record_template {
   $js->dialog->close('#record_template_dialog');
 
   my @items = grep {
-    $_->{chart_id} && (($_->{tax_id} // '') ne '') && ($_->{amount1} != 0)
+    $_->{chart_id} && (($_->{tax_id} // '') ne '')
   } map {
     +{ chart_id   => $::form->{"AP_amount_chart_id_${_}"},
        amount1    => $::form->parse_amount(\%::myconfig, $::form->{"amount_${_}"}),
@@ -584,6 +587,8 @@ sub show_draft {
 }
 
 sub update {
+  my %params = @_;
+
   $main::lxdebug->enter_sub();
 
   my $form     = $main::form;
@@ -605,7 +610,7 @@ sub update {
   my (@a, $j, $totaltax);
   for my $i (1 .. $form->{rowcount}) {
     $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
-    if ($form->{"amount_$i"}) {
+    if ($form->{"amount_$i"} || $params{keep_rows_without_amount}) {
       push @a, {};
       $j = $#a;
       my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
@@ -632,7 +637,7 @@ sub update {
     IR->get_vendor(\%::myconfig, $form);
   }
 
-  $form->{rowcount} = $count + 1;
+  $form->{rowcount} = $count + ($params{dont_add_new_row} ? 0 : 1);
 
   $form->{invtotal} =
     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
@@ -658,7 +663,7 @@ sub update {
   $form->{oldinvtotal}  = $form->{invtotal};
   $form->{oldtotalpaid} = $totalpaid;
 
-  &display_form;
+  display_form();
 
   $main::lxdebug->leave_sub();
 }