SQL-Ledger Homepage

SQL-Ledger User Forum

Forum index page

Log in | Register

Back to the board
Thread view  Mix view  Order
joe(R)

03.02.2015, 19:40
 

Incorrect selling price sometimes shown on pdf parts report (General)

Using Version 3.0.6

When the number format preference is set to '1,000.00', selling prices on the pdf version of a parts report are shown incorrectly in cases when they are >= 1,000.00. Specifically, digits after the first ',' are lost. For example, 1,234.56 becomes 1.00 on the report.

The problem is a result of attempting to apply SL::Form::format_amount() twice in succession to an amount.

The following patch removes one of the calls to format_amount() (the other call is in gentex()) and is thought to fix the problem (watch out for possibly incorrect line wrapping below):

--- sql-ledger.orig/bin/mozilla/ic.pl 2015-02-01 18:55:58.000000000 -0500
+++ sql-ledger/bin/mozilla/ic.pl 2015-02-01 18:53:24.000000000 -0500
@@ -2047,9 +2047,6 @@
}
$ref->{ship} = $ref->{onhand};

- for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
- for (qw(qty rop)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}) }
-
# build arrays
for (@columns) {
push @{ $form->{$_} }, $ref->{$_};
--- sql-ledger.orig/bin/lynx/ic.pl 2015-02-01 18:55:58.000000000 -0500
+++ sql-ledger/bin/lynx/ic.pl 2015-02-01 18:54:11.000000000 -0500
@@ -2047,9 +2047,6 @@
}
$ref->{ship} = $ref->{onhand};

- for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
- for (qw(qty rop)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}) }
-
# build arrays
for (@columns) {
push @{ $form->{$_} }, $ref->{$_};


Not a lot of testing has been done, but it's presumed that other number formats are affected as well (except for '1000.00'), and that other amounts on the report are affected (list price, last cost, avg cost).

Dieter Simader(R)

04.02.2015, 11:36

@ joe

Incorrect selling price sometimes shown on pdf parts report

Using Version 3.0.6

When the number format preference is set to '1,000.00', selling prices on
the pdf version of a parts report are shown incorrectly in cases when they
are >= 1,000.00. Specifically, digits after the first ',' are lost. For
example, 1,234.56 becomes 1.00 on the report.

The problem is a result of attempting to apply SL::Form::format_amount()
twice in succession to an amount.

The following patch removes one of the calls to format_amount() (the other
call is in gentex()) and is thought to fix the problem (watch out for
possibly incorrect line wrapping below):

--- sql-ledger.orig/bin/mozilla/ic.pl 2015-02-01 18:55:58.000000000
-0500
+++ sql-ledger/bin/mozilla/ic.pl 2015-02-01 18:53:24.000000000
-0500
@@ -2047,9 +2047,6 @@
}
$ref->{ship} = $ref->{onhand};

- for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} =
$form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
- for (qw(qty rop)) { $ref->{$_} = $form->format_amount(\%myconfig,
$ref->{$_}) }
-
# build arrays
for (@columns) {
push @{ $form->{$_} }, $ref->{$_};
--- sql-ledger.orig/bin/lynx/ic.pl 2015-02-01 18:55:58.000000000
-0500
+++ sql-ledger/bin/lynx/ic.pl 2015-02-01 18:54:11.000000000 -0500
@@ -2047,9 +2047,6 @@
}
$ref->{ship} = $ref->{onhand};

- for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} =
$form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
- for (qw(qty rop)) { $ref->{$_} = $form->format_amount(\%myconfig,
$ref->{$_}) }
-
# build arrays
for (@columns) {
push @{ $form->{$_} }, $ref->{$_};


Not a lot of testing has been done, but it's presumed that other number
formats are affected as well (except for '1000.00'), and that other amounts
on the report are affected (list price, last cost, avg cost).

The only change required is in sub gentex, line 1311

if ($self->{temp} && $hdr->{$_}{type} ne 'n') {
$self->format_string(temp) unless $hdr->{$_}{image};
}

amounts are formatted in the frontend otherwise the html report won't work. For some reason number formatting also slipped into the gentex function which is not correct.

joe(R)

04.02.2015, 16:16

@ Dieter Simader

Incorrect selling price sometimes shown on pdf parts report

The only change required is in sub gentex, line 1311

if ($self->{temp} && $hdr->{$_}{type} ne 'n') {
$self->format_string(temp) unless $hdr->{$_}{image};
}

amounts are formatted in the frontend otherwise the html report won't work.
For some reason number formatting also slipped into the gentex function
which is not correct.

Evidently you are looking at a version other than 3.0.6 (the line numbers don't match, and I find no prior definition/initialization of $hdr->{$_}{image} anywhere).

I presume the equivalent 3.0.6 change would be:


--- a/SL/Form.pm  2015-02-04 12:57:55.000000000 -0500
+++ b/SL/Form.pm  2015-02-04 14:46:25.000000000 -0500
@@ -1292,9 +1292,7 @@
     $line = "";
     for (@{$column}) {
       $self->{temp} = $self->{$_}[$i];
-      if ($hdr->{$_}{type} eq 'n') {
-       $self->{temp} = $self->format_amount($myconfig, $self->{temp}, $hdr->{$_}{precision});
-      } else {
+      if ($hdr->{$_}{type} ne 'n') {
        $self->format_string(temp);
       }
       $line .= qq|$self->{temp} \& |;



The problem with this alternative change is that it results in certain amounts never receiving any formatting. For example, a pdf of a parts report which includes a "weight" column ends up with weights like "1234" rather than "1,234". This was not a problem with the change as I suggested. Also, I have yet to observe any problems with the html version of the report. The sub generate_report in ic.pl makes its own calls to format_amount() when generating the html. Those calls are separate from the calls which I proposed for deletion.

If all formatting is to be done in the front end, then code must be added to ic.pl so that all amounts are properly formatted before gentex is called.

Dieter Simader(R)

04.02.2015, 17:48

@ joe

Incorrect selling price sometimes shown on pdf parts report

The only change required is in sub gentex, line 1311

if ($self->{temp} && $hdr->{$_}{type} ne 'n') {
$self->format_string(temp) unless $hdr->{$_}{image};
}

amounts are formatted in the frontend otherwise the html report won't
work.
For some reason number formatting also slipped into the gentex function
which is not correct.

Evidently you are looking at a version other than 3.0.6 (the line numbers
don't match, and I find no prior definition/initialization of
$hdr->{$_}{image} anywhere).

I presume the equivalent 3.0.6 change would be:


 --- a/SL/Form.pm  2015-02-04 12:57:55.000000000 -0500
 +++ b/SL/Form.pm  2015-02-04 14:46:25.000000000 -0500
 @@ -1292,9 +1292,7 @@
 $line = "";
 for (@{$column}) {
 $self->{temp} = $self->{$_}[$i];
 -      if ($hdr->{$_}{type} eq 'n') {
 -       $self->{temp} = $self->format_amount($myconfig, $self->{temp},
 $hdr->{$_}{precision});
 -      } else {
 +      if ($hdr->{$_}{type} ne 'n') {
 $self->format_string(temp);
 }
 $line .= qq|$self->{temp} \& |;
 



The problem with this alternative change is that it results in certain
amounts never receiving any formatting. For example, a pdf of a parts
report which includes a "weight" column ends up with weights like "1234"
rather than "1,234". This was not a problem with the change as I
suggested. Also, I have yet to observe any problems with the html version
of the report. The sub generate_report in ic.pl makes its own calls to
format_amount() when generating the html. Those calls are separate from
the calls which I proposed for deletion.

If all formatting is to be done in the front end, then code must be added
to ic.pl so that all amounts are properly formatted before gentex is
called.

gentex is called after the amounts are formatted. Anyway, I did not check if there is an image variable defined in this version, I took the line from another version where this error was corrected. It does not matter if $hdr->{$_}{image} is there because if it isn't defined the variable 'temp' will be formatted regardless (its an unless variable defined condition). Change the line in gentex to

$self->format_string(temp);

if you like, it works either way.

as for the weight, add it in the foreach loop in ic.pl
while you are at it add ship and onhand too.

foreach $ref (@{ $form->{parts} }) {
$ref->{sku} = $ref->{partnumber};
$ref->{number} = $ref->{sku};
$ref->{sell} = $ref->{sellprice};

if ($form->{formname} eq 'barcode') {
$ref->{onhand} = 1 if $ref->{onhand} <= 0;
}
$ref->{ship} = $ref->{onhand};

for (qw(sell sellprice listprice lastcost avgcost)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, $form->{precision}) }
for (qw(qty rop ship onhand weight)) { $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}) }

Back to the board
Thread view  Mix view  Order
986 Postings in 325 Threads, 327 registered users, 115 users online (0 registered, 115 guests)
SQL-Ledger User Forum | Admin contact
RSS-Feed
powered by my little forum