]> wagnertech.de Git - mfinanz.git/blobdiff - SL/AR.pm
Bugfixes zum Rechnungstemplate
[mfinanz.git] / SL / AR.pm
index a211b1fcf6001e81168632305f00760d18c1006d..b48741d34088c9946f127e028df1a6988d4084f4 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -38,7 +38,7 @@ use Data::Dumper;
 use SL::DBUtils;
 use SL::MoreCommon;
 
-our (%myconfig, $form);
+use strict;
 
 sub post_transaction {
   $main::lxdebug->enter_sub();
@@ -252,7 +252,7 @@ sub post_transaction {
         $amount = $form->round_amount( $form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2);
 
         if ($amount != 0) {
-          $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
+          my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
           $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey)
                        VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
           @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno);
@@ -524,18 +524,21 @@ sub setup_form {
 
   my ($self, $form) = @_;
 
-  my ($exchangerate, $key, $akey, $i, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff);
+  my ($exchangerate, $akey, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate,
+      $totalamount, $taxincluded, $tax);
 
   # forex
   $form->{forex} = $form->{exchangerate};
   $exchangerate  = $form->{exchangerate} ? $form->{exchangerate} : 1;
 
-  foreach $key (keys %{ $form->{AR_links} }) {
+  foreach my $key (keys %{ $form->{AR_links} }) {
     # if there is a value we have an old entry
     $j = 0;
     $k = 0;
 
-    for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
+    next unless $form->{acc_trans}{$key};
+
+    for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
       if ($key eq "AR_paid") {
         $j++;
         $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
@@ -606,7 +609,7 @@ sub setup_form {
   if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
 
     # add tax to amounts and invtotal
-    for $i (1 .. $form->{rowcount}) {
+    for my $i (1 .. $form->{rowcount}) {
       $taxamount            = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
       $tax                  = $form->round_amount($taxamount, 2);
       $diff                += ($taxamount - $tax);