]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Form.pm
Merge von 833,836-838 aus unstable: Lieferdatum in Rechnungen
[mfinanz.git] / SL / Form.pm
index 5fb58aff2fff5134dfabdcd845a8d274f2048e41..f82a70f661b842c93f25763a7f46ba910e52ef86 100644 (file)
@@ -412,14 +412,14 @@ function fokus(){document.$self->{fokus}.focus();}
   $main::lxdebug->leave_sub();
 }
 
-# write Trigger JavaScript-Code ($qty = 1 - only one Trigger)
+# write Trigger JavaScript-Code ($qty = quantity of Triggers)
+# changed it to accept an arbitrary number of triggers - sschoeling
 sub write_trigger {
   $main::lxdebug->enter_sub();
 
-  my ($self,         $myconfig, $qty,
-      $inputField_1, $align_1,  $button_1,
-      $inputField_2, $align_2,  $button_2)
-    = @_;
+  my $self     = shift;
+  my $myconfig = shift;
+  my $qty      = shift;
 
   # set dateform for jsscript
   # default
@@ -448,35 +448,21 @@ sub write_trigger {
     }
   }
 
-  $trigger_1 = qq|
+  while ($#_ >= 2) {
+    push @triggers, qq|
        Calendar.setup(
       {
-      inputField : "$inputField_1",
+      inputField : "|.(shift).qq|",
       ifFormat :"$ifFormat",
-      align : "$align_1", 
-      button : "$button_1"
+      align : "|.(shift).qq|", 
+      button : "|.(shift).qq|"
       }
       );
        |;
-
-  if ($qty == 2) {
-    $trigger_2 = qq|
-       Calendar.setup(
-       {
-      inputField : "$inputField_2",
-      ifFormat :"$ifFormat",
-      align : "$align_2", 
-      button : "$button_2"
-      }
-      );
-        |;
   }
   $jsscript = qq|
        <script type="text/javascript">
-       <!--
-       $trigger_1
-       $trigger_2
-        //-->
+       <!--|.join("", @triggers).qq|//-->
         </script>
         |;
 
@@ -519,6 +505,12 @@ sub format_amount {
   $main::lxdebug->enter_sub();
 
   my ($self, $myconfig, $amount, $places, $dash) = @_;
+  
+  #Workaround for $format_amount calls without $places
+  if (!defined $places){
+  (my $dec) = ($amount =~ /\.(\d+)/);
+  $places           = length $dec;
+  }                    
 
   if ($places =~ /\d/) {
     $amount = $self->round_amount($amount, $places);
@@ -584,19 +576,44 @@ sub parse_amount {
   $main::lxdebug->enter_sub();
 
   my ($self, $myconfig, $amount) = @_;
-
-  if (!(substr($amount, -3, 1) eq ".")) {
-    if (   ($myconfig->{numberformat} eq '1.000,00')
-        || ($myconfig->{numberformat} eq '1000,00')) {
-      $amount =~ s/\.//g;
-      $amount =~ s/,/\./;
-    }
-
-    $amount =~ s/,//g;
-  }
-
+  $main::lxdebug->message(LXDebug::DEBUG2, "Start amount: $amount");  
+  if ($myconfig->{in_numberformat} == 1){
+    # Extra input number format 1000.00 or 1000,00
+    $main::lxdebug->message(LXDebug::DEBUG2, "in_numberformat: " . $main::locale->text('1000,00 or 1000.00'));
+    $amount =~ s/,/\./g;
+    #$main::lxdebug->message(LXDebug::DEBUG2, "1.Parsed Number: $amount") if ($amount);
+    $amount = scalar reverse $amount;
+    #$main::lxdebug->message(LXDebug::DEBUG2, "2.Parsed Number: $amount") if ($amount);
+    $amount =~ s/\./DOT/;
+    #$main::lxdebug->message(LXDebug::DEBUG2, "3.Parsed Number: $amount") if ($amount);
+    $amount =~ s/\.//g;
+    #$main::lxdebug->message(LXDebug::DEBUG2, "4.Parsed Number: $amount") if ($amount);
+    $amount =~ s/DOT/\./;
+    #$main::lxdebug->message(LXDebug::DEBUG2, "5.Parsed Number:" . $amount) if ($amount);
+    $amount = scalar reverse $amount ;
+    $main::lxdebug->message(LXDebug::DEBUG2, "Parsed amount:" . $amount . "\n");
+
+    return ($amount * 1);
+
+  }
+  $main::lxdebug->message(LXDebug::DEBUG2, "in_numberformat: " . $main::locale->text('equal Outputformat'));
+  $main::lxdebug->message(LXDebug::DEBUG2, " = numberformat: $myconfig->{numberformat}");
+  if (   ($myconfig->{numberformat} eq '1.000,00')
+      || ($myconfig->{numberformat} eq '1000,00')) {
+    $amount =~ s/\.//g;
+    $amount =~ s/,/\./;
+  }
+
+  if ($myconfig->{numberformat} eq "1'000.00") {
+      $amount =~ s/'//g;
+  }
+
+  $amount =~ s/,//g;
+  
+  $main::lxdebug->message(LXDebug::DEBUG2, "Parsed amount:" . $amount. "\n") if ($amount);
   $main::lxdebug->leave_sub();
-
+  
   return ($amount * 1);
 }
 
@@ -846,6 +863,7 @@ sub parse_template {
     }
 
     s/<%(.+?)%>/$self->{$1}/g;
+    s/<nobr><\/nobr>/&nbsp;/g;
     print OUT;
   }
 
@@ -1599,7 +1617,7 @@ sub create_links {
 
   # now get the account numbers
   $query =
-    qq|SELECT c.accno, SUBSTRING(c.description,1,50) as description, c.link, c.taxkey_id
+    qq|SELECT c.accno, c.description, c.link, c.taxkey_id
               FROM chart c
              WHERE c.link LIKE '%$module%'
              ORDER BY c.accno|;
@@ -1672,7 +1690,7 @@ sub create_links {
                LEFT Join tax t ON (a.taxkey = t.taxkey)
                WHERE a.trans_id = $self->{id}
                AND a.fx_transaction = '0'
-               ORDER BY a.transdate|;
+               ORDER BY a.oid,a.transdate|;
     $sth = $dbh->prepare($query);
     $sth->execute || $self->dberror($query);
 
@@ -1682,12 +1700,17 @@ sub create_links {
     $self->{exchangerate} =
       $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
                               $fld);
+    my $index=0;
 
     # store amounts in {acc_trans}{$key} for multiple accounts
     while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
       $ref->{exchangerate} =
         $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate},
                                 $fld);
+      if ( !($xkeyref{ $ref->{accno} } =~ /tax/)) {
+        $index++;
+      }
+      $ref->{index} = $index;
 
       push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
     }
@@ -1765,10 +1788,9 @@ sub lastname_used {
     $where = "quotation = '1'";
   }
 
-  my $query = qq|SELECT id FROM $arap
-                 WHERE id IN (SELECT MAX(id) FROM $arap
+  my $query = qq|SELECT MAX(id) FROM $arap
                              WHERE $where
-                             AND ${table}_id > 0)|;
+                             AND ${table}_id > 0|;
   my $sth = $dbh->prepare($query);
   $sth->execute || $self->dberror($query);