[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1434] trunk/bin



Revision: 1434
          http://svn.sourceforge.net/ledger-smb/?rev=1434&view=rev
Author:   einhverfr
Date:     2007-07-21 10:15:06 -0700 (Sat, 21 Jul 2007)

Log Message:
-----------
Correcting cumulative tax display issues, bug 1745757

Modified Paths:
--------------
    trunk/bin/io.pl
    trunk/bin/ir.pl
    trunk/bin/is.pl
    trunk/bin/pos.pl

Modified: trunk/bin/io.pl
===================================================================
--- trunk/bin/io.pl	2007-07-21 17:14:15 UTC (rev 1433)
+++ trunk/bin/io.pl	2007-07-21 17:15:06 UTC (rev 1434)
@@ -84,6 +84,40 @@
 # $locale->text('Nov')
 # $locale->text('Dec')
 
+sub _calc_taxes {
+    for $i (1 .. $form->{rowcount}){
+        my $linetotal = 
+             $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}) 
+             * $form->parse_amount(\%myconfig, $form->{"qty_$i"}) 
+             * (1 - $form->parse_amount(\%myconfig, $form->{"discount_$i"})
+                    / 100);
+        @taxaccounts = Tax::init_taxes(
+            $form, $form->{"taxaccounts_$i"},
+            $form->{'taxaccounts'}
+        );
+        my $tax;
+        my $fxtax;
+        my $amount;
+        if ( $form->{taxincluded} ) {
+            $tax += $amount =
+              Tax::calculate_taxes( ..hidden.., $form, $linetotal, 1 );
+
+            $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"};
+        }
+        else {
+            $tax += $amount =
+              Tax::calculate_taxes( ..hidden.., $form, $linetotal, 0 );
+            $fxtax +=
+              Tax::calculate_taxes( ..hidden.., $form, $fxlinetotal, 0 )
+              if $fxlinetotal;
+        }        
+        for (@taxaccounts) {
+            $form->{taxes}{$_->account} = 0 if ! $form->{taxes}{$_->account};
+            $form->{taxes}{$_->account} += $_->value;
+        }
+    }
+}
+
 sub display_row {
     my $numrows = shift;
 

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2007-07-21 17:14:15 UTC (rev 1433)
+++ trunk/bin/ir.pl	2007-07-21 17:15:06 UTC (rev 1434)
@@ -469,7 +469,7 @@
 }
 
 sub form_footer {
-
+    _calc_taxes();
     $form->{invtotal} = $form->{invsubtotal};
 
     if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
@@ -483,7 +483,7 @@
 qq|<textarea name=notes rows=$rows cols=35 wrap=soft>$form->{notes}</textarea>|;
     $intnotes =
 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
-
+    $tax = "";
     $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
 
     $taxincluded = "";
@@ -495,26 +495,17 @@
     }
 
     if ( !$form->{taxincluded} ) {
-        my @taxset = Tax::init_taxes( $form, $form->{taxaccounts} );
-        foreach $taxobj (@taxset) {
-            $item = $taxobj->account;
-	    $form->{invtotal} += $form->round_amount(
-                $form->{"${item}_rate"} * $form->{"${item}_base"}, 2);
-            $form->{"${item}_total"} =
-              $form->format_amount( \%myconfig,
-                $form->{"${item}_rate"} * $form->{"${item}_base"}, 2 );
-            if ( $form->{"${item}_base"} ) {
-                $form->{"${item}_total"} =
-                  $form->format_amount( \%myconfig,
-                    $form->round_amount( $taxobj->value, 2 ), 2 );
-
+        foreach $item (keys %{$form->{taxes}}) {
+            my $taccno = $item;
+	    $form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);
+            $form->{"${taccno}_total"} =
+                $form->round_amount($form->{taxes}{$item}, 2);
                 $tax .= qq|
 		<tr>
 		  <th align=right>$form->{"${item}_description"}</th>
 		  <td align=right>$form->{"${item}_total"}</td>
 		</tr>
 |;
-            }
         }
 
         $form->{invsubtotal} =

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2007-07-21 17:14:15 UTC (rev 1433)
+++ trunk/bin/is.pl	2007-07-21 17:15:06 UTC (rev 1434)
@@ -518,7 +518,7 @@
 }
 
 sub form_footer {
-
+    _calc_taxes();
     $form->{invtotal} = $form->{invsubtotal};
 
     if ( ( $rows = $form->numtextrows( $form->{notes}, 35, 8 ) ) < 2 ) {
@@ -549,20 +549,17 @@
     }
 
     if ( !$form->{taxincluded} ) {
-        my @taxes = Tax::init_taxes( $form, $form->{taxaccounts} );
-        foreach $item (@taxes) {
-            my $taccno = $item->account;
-	    $form->{invtotal} += $form->round_amount( 
-                $form->{"${taccno}_rate"} * $form->{"${taccno}_base"}, 2);
+        foreach $item (keys %{$form->{taxes}}) {
+            my $taccno = $item;
+	    $form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);
             $form->{"${taccno}_total"} =
-              $form->format_amount( \%myconfig,
-                $form->{"${taccno}_rate"} * $form->{"${taccno}_base"}, 2 );
+                  $form->format_amount( \%myconfig,
+                    $form->round_amount( $form->{taxes}{$item}, 2 ), 2 );
             $tax .= qq|
         <tr>
       	<th align=right>$form->{"${taccno}_description"}</th>
       	<td align=right>$form->{"${taccno}_total"}</td>
-        </tr>
-	| if $form->{"${taccno}_base"};
+        </tr>|;
         }
 
         $form->{invsubtotal} =
@@ -834,7 +831,7 @@
 }
 
 sub update {
-
+    $form->{taxes} = {};
     $form->{exchangerate} =
       $form->parse_amount( \%myconfig, $form->{exchangerate} );
 
@@ -1011,14 +1008,9 @@
                 for ( split / /, $form->{"taxaccounts_$i"} ) {
                     $form->{"${_}_base"} += $amount;
                 }
-                if ( !$form->{taxincluded} ) {
-                    my @taxes =
-                      Tax::init_taxes( $form, $form->{"taxaccounts_$i"},
-                        $form->{taxaccounts} );
-                    $amount +=
-                      Tax::calculate_taxes( ..hidden.., $form, $amount, 0 );
-                }
 
+
+
                 $form->{creditremaining} -= $amount;
 
                 for (qw(sellprice listprice)) {

Modified: trunk/bin/pos.pl
===================================================================
--- trunk/bin/pos.pl	2007-07-21 17:14:15 UTC (rev 1433)
+++ trunk/bin/pos.pl	2007-07-21 17:15:06 UTC (rev 1434)
@@ -399,7 +399,7 @@
 }
 
 sub form_footer {
-
+    _calc_taxes();
     $form->{invtotal} = $form->{invsubtotal};
 
     $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
@@ -419,25 +419,17 @@
 
     if ( !$form->{taxincluded} ) {
 
-        my @taxset = Tax::init_taxes( $form, $form->{taxaccounts} );
-        foreach $taxobj (@taxset) {
-            $item = $taxobj->account;
-	    $form->{invtotal} += $form->round_amount(
-                $form->{"${item}_rate"} * $form->{"${item}_base"}, 2);
-            $form->{"${item}_total"} =
-              $form->format_amount( \%myconfig,
-                $form->{"${item}_rate"} * $form->{"${item}_base"}, 2 );
-            if ( $form->{"${item}_base"} ) {
-                $form->{"${item}_total"} =
+        foreach $item (keys %{$form->{taxes}}) {
+            my $taccno = $item;
+	    $form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);
+            $form->{"${taccno}_total"} =
                   $form->format_amount( \%myconfig,
-                    $form->round_amount( $taxobj->value, 2 ), 2 );
+                    $form->round_amount( $form->{taxes}{$item}, 2 ), 2 );
                 $tax .= qq|
 		<tr>
 		  <th align=right>$form->{"${item}_description"}</th>
 		  <td align=right>$form->{"${item}_total"}</td>
-		</tr>
-|;
-            }
+		</tr>|;
         }
 
         $form->{invsubtotal} =


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.