$::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);
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 {
$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_${_}"}),
}
sub update {
+ my %params = @_;
+
$main::lxdebug->enter_sub();
my $form = $main::form;
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"});
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;
$form->{oldinvtotal} = $form->{invtotal};
$form->{oldtotalpaid} = $totalpaid;
- &display_form;
+ display_form();
$main::lxdebug->leave_sub();
}