From: Moritz Bunkus Date: Mon, 30 Jan 2017 10:13:18 +0000 (+0100) Subject: Belegvorlagen: Zeilen ohne Betrag beibehalten X-Git-Tag: release-3.5.4~1622 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=101b9705bda052abb1237c92d3920f6ddbf12d04;p=kivitendo-erp.git Belegvorlagen: Zeilen ohne Betrag beibehalten --- diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 98f6df750..23d1b0a5c 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -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(); } diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 540c8fb31..66e5008f9 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -112,7 +112,7 @@ sub load_record_template { $::form->{AR_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 employee_id notes); @@ -150,7 +150,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 { @@ -163,7 +166,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->{"AR_amount_chart_id_${_}"}, amount1 => $::form->parse_amount(\%::myconfig, $::form->{"amount_${_}"}), @@ -567,6 +570,7 @@ sub show_draft { } sub update { + my %params = @_; $main::lxdebug->enter_sub(); $main::auth->assert('ar_transactions'); @@ -591,7 +595,7 @@ sub update { 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, {}; my $j = $#a; my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); @@ -606,7 +610,7 @@ sub update { } $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); - $form->{rowcount} = $count + 1; + $form->{rowcount} = $count + ($params{dont_add_new_row} ? 0 : 1); map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount}); $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy'); @@ -641,7 +645,7 @@ sub update { $form->{oldinvtotal} = $form->{invtotal}; $form->{oldtotalpaid} = $form->{totalpaid}; - &display_form; + display_form(); $main::lxdebug->leave_sub(); } diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index de007c5b6..fc8a162e6 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -105,7 +105,7 @@ sub load_record_template { $::form->{title} = "Add"; $::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 taxincluded ob_transaction cb_transaction reference description); $::form->{$_} = $dummy_form->{$_} for qw(closedto revtrans previous_id previous_gldate); @@ -139,7 +139,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 { @@ -152,7 +155,7 @@ sub save_record_template { $js->dialog->close('#record_template_dialog'); my @items = grep { - $_->{chart_id} && (($_->{tax_id} // '') ne '') && (($_->{amount1} != 0) || ($_->{amount2} != 0)) + $_->{chart_id} && (($_->{tax_id} // '') ne '') } map { +{ chart_id => $::form->{"accno_id_${_}"}, amount1 => $::form->parse_amount(\%::myconfig, $::form->{"debit_${_}"}), @@ -628,6 +631,8 @@ sub show_draft { } sub update { + my %params = @_; + $main::lxdebug->enter_sub(); $main::auth->assert('gl_transactions'); @@ -653,69 +658,65 @@ sub update { qw(accno debit credit projectnumber fx_transaction source memo tax taxchart); for my $i (1 .. $form->{rowcount}) { + $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) for qw(debit credit tax); - unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) { - for (qw(debit credit tax)) { - $form->{"${_}_$i"} = - $form->parse_amount(\%myconfig, $form->{"${_}_$i"}); - } + next if !$form->{"debit_$i"} && !$form->{"credit_$i"} && !$params{keep_rows_without_amount}; + + push @a, {}; + $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1"; + if ($debitcredit) { + $debitcount++; + } else { + $creditcount++; + } - push @a, {}; - $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1"; + if (($debitcount >= 2) && ($creditcount == 2)) { + $form->{"credit_$i"} = 0; + $form->{"tax_$i"} = 0; + $creditcount--; + $form->{creditlock} = 1; + } + if (($creditcount >= 2) && ($debitcount == 2)) { + $form->{"debit_$i"} = 0; + $form->{"tax_$i"} = 0; + $debitcount--; + $form->{debitlock} = 1; + } + if (($creditcount == 1) && ($debitcount == 2)) { + $form->{creditlock} = 1; + } + if (($creditcount == 2) && ($debitcount == 1)) { + $form->{debitlock} = 1; + } + if ($debitcredit && $credittax) { + $form->{"taxchart_$i"} = "$notax_id--0.00"; + } + if (!$debitcredit && $debittax) { + $form->{"taxchart_$i"} = "$notax_id--0.00"; + } + $amount = + ($form->{"debit_$i"} == 0) + ? $form->{"credit_$i"} + : $form->{"debit_$i"}; + my $j = $#a; + if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) { + $form->{"taxchart_$i"} = "$notax_id--0.00"; + $form->{"tax_$i"} = 0; + } + my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + my $iswithouttax = grep { $_->{id} == $taxkey } @{ $zerotaxes }; + if (!$iswithouttax) { if ($debitcredit) { - $debitcount++; + $debittax = 1; } else { - $creditcount++; - } - - if (($debitcount >= 2) && ($creditcount == 2)) { - $form->{"credit_$i"} = 0; - $form->{"tax_$i"} = 0; - $creditcount--; - $form->{creditlock} = 1; - } - if (($creditcount >= 2) && ($debitcount == 2)) { - $form->{"debit_$i"} = 0; - $form->{"tax_$i"} = 0; - $debitcount--; - $form->{debitlock} = 1; - } - if (($creditcount == 1) && ($debitcount == 2)) { - $form->{creditlock} = 1; - } - if (($creditcount == 2) && ($debitcount == 1)) { - $form->{debitlock} = 1; - } - if ($debitcredit && $credittax) { - $form->{"taxchart_$i"} = "$notax_id--0.00"; - } - if (!$debitcredit && $debittax) { - $form->{"taxchart_$i"} = "$notax_id--0.00"; - } - $amount = - ($form->{"debit_$i"} == 0) - ? $form->{"credit_$i"} - : $form->{"debit_$i"}; - my $j = $#a; - if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) { - $form->{"taxchart_$i"} = "$notax_id--0.00"; - $form->{"tax_$i"} = 0; + $credittax = 1; } - my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); - my $iswithouttax = grep { $_->{id} == $taxkey } @{ $zerotaxes }; - if (!$iswithouttax) { - if ($debitcredit) { - $debittax = 1; - } else { - $credittax = 1; - } - }; - my ($tmpnetamount,$tmpdiff); - ($tmpnetamount,$form->{"tax_$i"},$tmpdiff) = $form->calculate_tax($amount,$rate,$form->{taxincluded} *= 1,2); + }; + my ($tmpnetamount,$tmpdiff); + ($tmpnetamount,$form->{"tax_$i"},$tmpdiff) = $form->calculate_tax($amount,$rate,$form->{taxincluded} *= 1,2); - for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } - $count++; - } + for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } + $count++; } for my $i (1 .. $count) { @@ -727,9 +728,9 @@ sub update { for (@flds) { delete $form->{"${_}_$i"} } } - $form->{rowcount} = $count + 1; + $form->{rowcount} = $count + ($params{dont_add_new_row} ? 0 : 1); - &display_form; + display_form(); $main::lxdebug->leave_sub(); } diff --git a/sql/Pg-upgrade2/convert_drafts_to_record_templates.pl b/sql/Pg-upgrade2/convert_drafts_to_record_templates.pl index d4faaaa73..3cad8ca8d 100644 --- a/sql/Pg-upgrade2/convert_drafts_to_record_templates.pl +++ b/sql/Pg-upgrade2/convert_drafts_to_record_templates.pl @@ -123,8 +123,7 @@ sub migrate_ar_drafts { # $tax_id may be 0 as there's an entry in tax with id = 0. # $chart_id must not be 0 as there's no entry in chart with id = 0. - # No $amount means empty row. - next unless $amount && $chart_id && (($tax_id // '') ne ''); + next unless $chart_id && (($tax_id // '') ne ''); @values = ( # record_template_id, @@ -198,8 +197,7 @@ sub migrate_ap_drafts { # $tax_id may be 0 as there's an entry in tax with id = 0. # $chart_id must not be 0 as there's no entry in chart with id = 0. - # No $amount means empty row. - next unless $amount && $chart_id && (($tax_id // '') ne ''); + next unless $chart_id && (($tax_id // '') ne ''); @values = ( # record_template_id, @@ -271,8 +269,7 @@ sub migrate_gl_drafts { # $tax_id may be 0 as there's an entry in tax with id = 0. # $chart_id must not be 0 as there's no entry in chart with id = 0. - # No $debit and no $credit means empty row. - next unless ($debit || $credit) && $chart_id && (($tax_id // '') ne ''); + next unless $chart_id && (($tax_id // '') ne ''); @values = ( # record_template_id, @@ -323,8 +320,6 @@ sub run { $self->clean_drafts; $self->finish_statements; - # die "boom!"; - return 1; }