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

SF.net SVN: ledger-smb:[3206] trunk



Revision: 3206
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3206&view=rev
Author:   einhverfr
Date:     2011-06-08 23:47:51 +0000 (Wed, 08 Jun 2011)

Log Message:
-----------
Precision fix for invoice/orders with inventory items, so trailing zeroes are preserved

Modified Paths:
--------------
    trunk/LedgerSMB/IR.pm
    trunk/LedgerSMB/IS.pm
    trunk/bin/io.pl
    trunk/bin/ir.pl
    trunk/bin/is.pl
    trunk/sql/Pg-database.sql

Added Paths:
-----------
    trunk/sql/upgrade/3206-invoice_order.sql

Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/LedgerSMB/IR.pm	2011-06-08 23:47:51 UTC (rev 3206)
@@ -204,10 +204,11 @@
               $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
 
             my ($dec) = ( $fxsellprice =~ /\.(\d+)/ );
-            $dec = length $dec;
-            my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
-
             # deduct discount
+            my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
+            $decimalplaces = ($form->{"precision_$i"} > $moneyplaces) 
+                             ? $form->{"precision_$i"}
+                             : $moneyplaces;
             $form->{"sellprice_$i"} = $fxsellprice -
               $form->round_amount( $fxsellprice * $form->{"discount_$i"},
                 $decimalplaces );
@@ -215,10 +216,10 @@
             # linetotal
             my $fxlinetotal =
               $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
-                2 );
+                $moneyplaces );
 
             $amount = $fxlinetotal * $form->{exchangerate};
-            my $linetotal = $form->round_amount( $amount, 2 );
+            my $linetotal = $form->round_amount( $amount, $moneyplaces );
             $fxdiff += $amount - $linetotal;
 
             @taxaccounts = Tax::init_taxes(
@@ -249,15 +250,15 @@
                   $_->value;
             }
 
-            $grossamount = $form->round_amount( $linetotal, 2 );
+            $grossamount = $form->round_amount( $linetotal, $moneyplaces );
 
             if ( $form->{taxincluded} ) {
-                $amount = $form->round_amount( $tax, 2 );
-                $linetotal -= $form->round_amount( $tax - $diff, 2 );
+                $amount = $form->round_amount( $tax, $moneyplaces );
+                $linetotal -= $form->round_amount( $tax - $diff, $moneyplaces );
                 $diff = ( $amount - $tax );
             }
 
-            $amount = $form->round_amount( $linetotal, 2 );
+            $amount = $form->round_amount( $linetotal, $moneyplaces );
             $allocated = 0;
 
             # adjust and round sellprice
@@ -291,6 +292,7 @@
 				       deliverydate = ?,
 				       project_id = ?,
 				       serialnumber = ?,
+                                       precision = ?,
 				       notes = ?
 				 WHERE id = ?|;
             $sth = $dbh->prepare($query);
@@ -301,7 +303,7 @@
                 $form->{"discount_$i"},    $allocated,
                 $form->{"unit_$i"},        $form->{"deliverydate_$i"},
                 $project_id,               $form->{"serialnumber_$i"},
-                $form->{"notes_$i"},       
+                $form->{"precision_$i"},   $form->{"notes_$i"},       
                 $invoice_id
             ) || $form->dberror($query);
 
@@ -1132,7 +1134,7 @@
         $sth->finish;
 
         # get shipto
-        $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
+        $query = qq|SELECT ns.*, l.* FROM new_shipto ns JOIN location l ON ns.location_id = l.id WHERE ns.trans_id = ?|;
         $sth   = $dbh->prepare($query);
         $sth->execute( $form->{id} ) || $form->dberror($query);
 
@@ -1145,7 +1147,7 @@
         # retrieve individual items
         $query = qq|
 			   SELECT i.id as invoice_id,p.partnumber, i.description, i.qty, 
-			          i.fxsellprice, i.sellprice,
+			          i.fxsellprice, i.sellprice, i.precision,
 			          i.parts_id AS id, i.unit, p.bin, 
 			          i.deliverydate,
 			          pr.projectnumber, i.project_id, 
@@ -1314,8 +1316,9 @@
         $form->db_parse_numeric(sth=>$sth, hashref=>$ref);
 
         my ($dec) = ( $ref->{sellprice} =~ /\.(\d+)/ );
+        my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
         $dec = length $dec;
-        my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+        my $decimalplaces = ( $dec > $moneyplaces ) ? $dec : $moneyplaces;
 
         # get taxes for part
         $tth->execute( $ref->{id} );

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/LedgerSMB/IS.pm	2011-06-08 23:47:51 UTC (rev 3206)
@@ -1035,10 +1035,15 @@
             my $fxsellprice =
               $form->parse_amount( $myconfig, $form->{"sellprice_$i"} );
 
-            my ($dec) = ( $fxsellprice =~ /\.(\d+)/ );
-            $dec = length $dec;
-            my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+            my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
+            my $decimalplaces = ($form->{"precision_$i"} > $moneyplaces) 
+                             ? $form->{"precision_$i"}
+                             : $moneyplaces;
+            $form->{"sellprice_$i"} = $fxsellprice -
+              $form->round_amount( $fxsellprice * $form->{"discount_$i"},
+                $decimalplaces );
 
+
             # undo discount formatting
             $form->{"discount_$i"} =
               $form->parse_amount( $myconfig, $form->{"discount_$i"} ) / 100;
@@ -1184,6 +1189,7 @@
 				       description = ?,
 				       qty = ?,
 				       sellprice = ?,
+                                       precision = ?,
 				       fxsellprice = ?,
 				       discount = ?,
 				       allocated = ?,
@@ -1198,11 +1204,11 @@
             $sth->execute(
                 $form->{id},               $form->{"id_$i"},
                 $form->{"description_$i"}, $form->{"qty_$i"},
-                $form->{"sellprice_$i"},   $fxsellprice,
-                $form->{"discount_$i"},    $allocated,
-                $form->{"unit_$i"},        $form->{"deliverydate_$i"},
-                $project_id,               $form->{"serialnumber_$i"},
-                $form->{"notes_$i"},       
+                $form->{"sellprice_$i"},   $form->{"precision_$i"},
+                $fxsellprice,              $form->{"discount_$i"},
+                $allocated,                $form->{"unit_$i"},        
+                $form->{"deliverydate_$i"}, $project_id,               
+                $form->{"serialnumber_$i"}, $form->{"notes_$i"},       
                 $invoice_id
             ) || $form->dberror($query);
 
@@ -1648,7 +1654,7 @@
 
         my $query = qq|
 		   SELECT i.id, i.trans_id, i.qty, i.allocated, i.sellprice,
-		          i.fxsellprice, p.inventory_accno_id, 
+		          i.precision, i.fxsellprice, p.inventory_accno_id, 
 		          p.expense_accno_id, 
 		          (i.qty * -1) - i.allocated AS available
 		     FROM invoice i
@@ -2043,7 +2049,8 @@
         # retrieve individual items
         $query = qq|
 			   SELECT i.id as invoice_id,i.description, i.qty, i.fxsellprice, 
-			          i.sellprice, i.discount, i.parts_id AS id, 
+			          i.sellprice, i.precision, i.discount, 
+                                  i.parts_id AS id, 
 			          i.unit, i.deliverydate, i.project_id, 
 			          pr.projectnumber, i.serialnumber, i.notes,
 			          p.partnumber, p.assembly, p.bin,
@@ -2110,6 +2117,7 @@
             $ref->{sellprice} =
               ( $ref->{fxsellprice} * $form->{ $form->{currency} } );
             $ref->{sellprice} = $ref->{fxsellprice};
+            
 
             $ref->{partsgroup} = $ref->{partsgrouptranslation}
               if $ref->{partsgrouptranslation};

Modified: trunk/bin/io.pl
===================================================================
--- trunk/bin/io.pl	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/bin/io.pl	2011-06-08 23:47:51 UTC (rev 3206)
@@ -234,8 +234,11 @@
         else {
             ( $null, $dec ) = split /,/, $form->{"sellprice_$i"};
         }
+        my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
         $dec = length $dec;
-        $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+        $form->{"precision_$i"} ||= $dec;
+        $dec =  $form->{"precision_$i"};
+        $decimalplaces = ( $dec > $moneyplaces ) ? $dec : $moneyplaces;
 
         # undo formatting
         for (qw(qty oldqty ship discount sellprice)) {
@@ -253,7 +256,9 @@
                     if ( ( $p * 1 ) && ( $form->{"qty_$i"} >= ( $q * 1 ) ) ) {
                         ($dec) = ( $p =~ /\.(\d+)/ );
                         $dec = length $dec;
-                        $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+                        $decimalplaces = ( $dec > $moneyplaces ) 
+                                        ? $dec 
+                                        : $moneyplaces;
                         $form->{"sellprice_$i"} =
                           $form->round_amount( $p / $exchangerate,
                             $decimalplaces );
@@ -265,7 +270,8 @@
         $linetotal = $form->round_amount( $form->{"sellprice_$i"}
                                           * (1 - ($form->{"discount_$i"} / 100)),
                                           $decimalplaces);
-        $linetotal = $form->round_amount( $linetotal * $form->{"qty_$i"}, 2 );
+        $linetotal = $form->round_amount( $linetotal * $form->{"qty_$i"}, 
+                                         $moneyplaces);
 
         if (
             ( $rows = $form->numtextrows( $form->{"description_$i"}, 46, 6 ) ) >
@@ -339,7 +345,7 @@
         $column_data{sellprice} =
           qq|<td align=right><input name="sellprice_$i" size=9 value=|
           . $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
-            $decimalplaces )
+            $form->{"precision_$i"} )
           . qq|></td>|;
         $column_data{discount} =
             qq|<td align=right><input name="discount_$i" size=3 value=|
@@ -365,7 +371,7 @@
 |;
 
         for (
-            qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id invoice_id)
+            qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id invoice_id precision)
           )
         {
             $form->hide_form("${_}_$i");
@@ -553,7 +559,10 @@
 |;
 
         for (
-            qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)
+            qw(partnumber sku description partsgroup partsgroup_id bin weight 
+               sellprice listprice lastcost onhand unit assembly 
+               taxaccounts inventory_accno_id income_accno_id expense_accno_id 
+               pricematrix id notes)
           )
         {
             print
@@ -617,7 +626,9 @@
               if $form->{type} !~ /_quotation/;
 
             for (
-                qw(id partnumber sku description listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)
+                qw(id partnumber sku description listprice lastcost
+                  bin unit weight assembly taxaccounts pricematrix onhand notes 
+                  inventory_accno_id income_accno_id expense_accno_id)
               )
             {
                 $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
@@ -703,7 +714,9 @@
     # delete all the new_ variables
     for $i ( 1 .. $form->{lastndx} ) {
         for (
-            qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)
+            qw(id partnumber sku description sellprice listprice lastcost 
+               bin unit weight assembly taxaccounts pricematrix onhand
+               notes inventory_accno_id income_accno_id expense_accno_id)
           )
         {
             delete $form->{"new_${_}_$i"};
@@ -804,7 +817,6 @@
         exit;
     }
     
-    
 
     &form_header;
     
@@ -860,7 +872,11 @@
     my $i;
     my $j;
     my @flds =
-      qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
+      qw(id runningnumber partnumber description partsgroup qty ship unit 
+         sellprice discount oldqty orderitems_id bin weight listprice 
+         lastcost taxaccounts pricematrix sku onhand assembly 
+         inventory_accno_id income_accno_id expense_accno_id notes reqdate 
+         deliverydate serialnumber projectnumber);
 
     # remove any makes or model rows
     if ( $form->{item} eq 'part' ) {

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/bin/ir.pl	2011-06-08 23:47:51 UTC (rev 3206)
@@ -251,9 +251,11 @@
             $form->{"discount_$i"} =
               $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
 
-            ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+            my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
+            my ($dec) = ($form->{"sellprice_$i"} =~/\.(\d*)/);
             $dec = length $dec;
-            $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+            $form->{"precision_$i"} ||= $dec;
+            $decimalplaces = ( $dec > $moneyplaces ) ? $dec : $moneyplaces;
 
             $form->{"sellprice_$i"} =
               $form->format_amount( \%myconfig, $form->{"sellprice_$i"},

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/bin/is.pl	2011-06-08 23:47:51 UTC (rev 3206)
@@ -283,9 +283,11 @@
             $form->{"discount_$i"} =
               $form->format_amount( \%myconfig, $form->{"discount_$i"} * 100 );
 
-            ($dec) = ( $form->{"sellprice_$i"} =~ /\.(\d+)/ );
+            my $moneyplaces = $LedgerSMB::Sysconfig::decimal_places;
+            my ($dec) = ($form->{"sellprice_$i"} =~/\.(\d*)/);
             $dec = length $dec;
-            $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+            $form->{"precision_$i"} = $dec;
+            $decimalplaces = ( $dec > $moneyplaces ) ? $dec : $moneyplaces;
 
             $form->{"sellprice_$i"} =
               $form->format_amount( \%myconfig, $form->{"sellprice_$i"},

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2011-06-08 20:49:16 UTC (rev 3205)
+++ trunk/sql/Pg-database.sql	2011-06-08 23:47:51 UTC (rev 3206)
@@ -887,6 +887,7 @@
   qty integer,
   allocated integer,
   sellprice NUMERIC,
+  precision int,
   fxsellprice NUMERIC,
   discount numeric,
   assemblyitem bool DEFAULT 'f',
@@ -1217,6 +1218,7 @@
   description text,
   qty numeric,
   sellprice NUMERIC,
+  precision int,
   discount numeric,
   unit varchar(5),
   project_id int,

Added: trunk/sql/upgrade/3206-invoice_order.sql
===================================================================
--- trunk/sql/upgrade/3206-invoice_order.sql	                        (rev 0)
+++ trunk/sql/upgrade/3206-invoice_order.sql	2011-06-08 23:47:51 UTC (rev 3206)
@@ -0,0 +1,2 @@
+ALTER TABLE invoice ADD precision int;
+ALTER TABLE orderitems ADD precision int;


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