X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Fap.pl;h=24c9f594371a2035b2d4c5d18980cd42f5f50ea8;hb=4d20c18172f57d1cb809334683f5b844ca02a5e6;hp=ac63057278a2286b4d0cf5e8a0e0f9b507c5f619;hpb=fb4d2ffa6aae03b36e4db77be10c3d9dce4413f8;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index ac6305727..24c9f5943 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -33,6 +33,7 @@ use SL::AP; use SL::IR; +use SL::IS; use SL::PE; require "bin/mozilla/arap.pl"; @@ -671,6 +672,7 @@ $jsscript ? $locale->text('Tax Included') : $locale->text('Tax'); + $form->{invtotal_unformatted} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); $APselected = @@ -740,7 +742,9 @@ $jsscript "; - my @triggers = (); + my @triggers = (); + my $totalpaid = 0; + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { print " @@ -754,6 +758,8 @@ $jsscript '-labels' => \%AP_paid_labels, '-default' => $form->{"AP_paid_$i"})); + $totalpaid += $form->{"paid_$i"}; + # format amounts if ($form->{"paid_$i"}) { $form->{"paid_$i"} = @@ -804,7 +810,23 @@ $jsscript "; push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + + my $paid_missing = $form->{invtotal_unformatted} - $totalpaid; + + print qq| + + + + | . $locale->text('Total') . qq| + | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| + + + + + | . $locale->text('Missing amount') . qq| + | . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq| + +| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . qq| {paidaccounts}> @@ -850,43 +872,30 @@ sub form_footer { $transdate = $form->datetonum($form->{transdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); - print qq||; + # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it + print qq|| + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap') && !$form->{paid_1}); - if ($form->{id}) { + print qq||; - # print qq| - # |; + if ($form->{id}) { if ($form->{radier}) { - print qq| - - + print qq| + |; } - print qq| - - + print qq| + |; } elsif (($transdate > $closedto) && !$form->{id}) { print qq| - | . - NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), - '-class' => 'submit')); + | . + NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit')); } # button for saving history if($form->{id} ne "") { - print qq| - |; + print qq| |; } # /button for saving history print " @@ -993,7 +1002,7 @@ sub update { sub post_payment { $lxdebug->enter_sub(); for $i (1 .. $form->{paidaccounts}) { - if ($form->{"paid_$i"}) { + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); @@ -1012,7 +1021,7 @@ sub post_payment { ($form->{AP}) = split /--/, $form->{AP}; ($form->{AP_paid}) = split /--/, $form->{AP_paid}; - $form->redirect($locale->text(' Payment posted!')) + $form->redirect($locale->text('Payment posted!')) if (AP->post_payment(\%myconfig, \%$form)); $form->error($locale->text('Cannot post payment!')); @@ -1031,9 +1040,17 @@ sub post { $closedto = $form->datetonum($form->{closedto}, \%myconfig); $transdate = $form->datetonum($form->{transdate}, \%myconfig); + $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); + + my $zero_amount_posting = 1; + for $i (1 .. $form->{rowcount}) { + if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) { + $zero_amount_posting = 0; + last; + } + } - $form->error($locale->text('Cannot post transaction for a closed period!')) - if ($transdate <= $closedto); + $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting; $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); @@ -1737,3 +1754,43 @@ sub ap_subtotal { $lxdebug->leave_sub(); } + +sub storno { + $lxdebug->enter_sub(); + + if (IS->has_storno(\%myconfig, $form, 'ap')) { + $form->{title} = $locale->text("Cancel Accounts Payables Transaction"); + $form->error($locale->text("Transaction has already been cancelled!")); + } + + # negate amount/taxes + for my $i (1 .. $form->{rowcount}) { + $form->{"amount_$i"} *= -1; + $form->{"tax_$i"} *= -1; + } + + # format things + for my $i (1 .. $form->{rowcount}) { + for (qw(amount tax)) { + $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) if $form->{"${_}_$i"}; + } + } + + $form->{storno} = 1; + $form->{storno_id} = $form->{id}; + $form->{id} = 0; + + $form->{invnumber} = "Storno-" . $form->{invnumber}; + + post(); + + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{snumbers} = "ordnumber_$form->{ordnumber}"; + $form->{addition} = "STORNO"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + + $lxdebug->leave_sub(); +}