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

SF.net SVN: ledger-smb:[4004] branches/1.3



Revision: 4004
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4004&view=rev
Author:   tshvr
Date:     2011-11-14 21:57:48 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
first trial to integrate parse_amount,format_amount in payments

Modified Paths:
--------------
    branches/1.3/LedgerSMB.pm
    branches/1.3/UI/payments/payment2.html
    branches/1.3/scripts/payment.pl

Modified: branches/1.3/LedgerSMB.pm
===================================================================
--- branches/1.3/LedgerSMB.pm	2011-11-14 21:32:40 UTC (rev 4003)
+++ branches/1.3/LedgerSMB.pm	2011-11-14 21:57:48 UTC (rev 4004)
@@ -559,7 +559,19 @@
 
     my $negative;
     if (defined $amount and ! UNIVERSAL::isa($amount, 'Math::BigFloat' )) {
-        $amount = $self->parse_amount( 'user' => $myconfig, 'amount' => $amount );
+        #tshvr many numbers which should really be BigFloat, are not! 
+        # e.g. calculations in the template system are not BigFloat. 
+        # so string,but virtual bigfloat '270.94', comes out as '27.094' when going through parse_amount with numberformat 1.000,00
+        # so if we have a virtual BigFloat, we might consider not going through parse_amount
+        my $test_bf=new Math::BigFloat($amount);
+        if($test_bf->is_nan())
+        {
+         $amount = $self->parse_amount( 'user' => $myconfig, 'amount' => $amount );
+        }
+        else
+        {
+         $amount = $test_bf;
+        }
     }
     $negative = ( $amount < 0 );
     $amount->babs();

Modified: branches/1.3/UI/payments/payment2.html
===================================================================
--- branches/1.3/UI/payments/payment2.html	2011-11-14 21:32:40 UTC (rev 4003)
+++ branches/1.3/UI/payments/payment2.html	2011-11-14 21:57:48 UTC (rev 4004)
@@ -174,8 +174,8 @@
     <td><div id="<?lsmb "div_topay_invoice_$i" ?>"><?lsmb row.due_fx ?></div></td>
    <?lsmb END ?> 
     <?lsmb #This should be computed and updated to the div using  ?> 
-    <td align="center"><?lsmb  row.topay_fx.id = row.topay_fx.name ;INCLUDE input element_data=row.topay_fx;
-    	       topay_subtotal = topay_subtotal + row.topay_fx.value -?>
+    <?lsmb topay_subtotal=topay_subtotal + row.topay_fx.value; -?>
+    <td align="center"><?lsmb  row.topay_fx.id=row.topay_fx.name;INCLUDE input element_data={id=>row.topay_fx.id,name=>row.topay_fx.name,value=>format_amount(row.topay_fx.value)}; -?>
     <?lsmb # A DEGRADABLE JAVASCRIPT IS USED, BECAUSE OF THE VISUAL IMPACT
     	   # THAT CAUSES THE SIZE OF THIS DIV -?>
     <img src="UI/payments/img/up.gif" id="button_topay_<?lsmb row.invoice.id ?>" name="<?lsmb "button_topay_$i" ?>"
@@ -222,7 +222,7 @@
    <?lsmb  colspan = column_count - 2 # We will use this later on totals -?>
    <tr class="listsubtotal">
    <th colspan="<?lsmb colspan -?>" align="right"><?lsmb text('Subtotal') -?></th>
-   <th colspan="2"><?lsmb topay_subtotal -?>&nbsp;<?lsmb curr.value -?></th>
+   <th colspan="2"><?lsmb format_amount(topay_subtotal) -?>&nbsp;<?lsmb curr.value -?></th>
    </tr>
    </table>
    <table width="100%">
@@ -321,7 +321,7 @@
    <tr class="listtotal">
    <?lsmb payment_total = overpayment_subtotal + topay_subtotal -?>
    <th colspan="5" align="right"><?lsmb text('Total') -?></th>
-   <th colspan="2"><?lsmb payment_total -?>&nbsp;<?lsmb curr.value -?></th>
+   <th colspan="2"><?lsmb format_amount(payment_total) -?>&nbsp;<?lsmb curr.value -?></th>
    </tr>
    </table>
    
@@ -330,13 +330,13 @@
          update.title       = "UPDATE ALT+U";
          update.name        = "action";
          update.value	    = "payment2";
-         update.text        = text("UPDATE");
+         update.text        = text("Update");
          INCLUDE button element_data=update -?>
   <?lsmb post.accesskey   = "P";
          post.title	  = "POST ALT+P";
          post.name	  = "action";
          post.value	  = "post_payment";
-         post.text	  = text("POST"); 
+         post.text	  = text("Post"); 
          INCLUDE button element_data=post -?>
   <?lsmb post_and_print.accesskey = "R";
          post_and_print.title     = "POST AND PRINT ALT+R";

Modified: branches/1.3/scripts/payment.pl
===================================================================
--- branches/1.3/scripts/payment.pl	2011-11-14 21:32:40 UTC (rev 4003)
+++ branches/1.3/scripts/payment.pl	2011-11-14 21:57:48 UTC (rev 4004)
@@ -934,6 +934,7 @@
 my $unhandled_overpayment;
 for my $ref (0 .. $#array_options) {
  if (  !$request->{"checkbox_$array_options[$ref]->{invoice_id}"}) {
+   my $request_topay_fx_bigfloat=$Payment->parse_amount(amount=>$request->{"topay_fx_$array_options[$ref]->{invoice_id}"});
 # SHOULD I APPLY DISCCOUNTS?   
       $request->{"optional_discount_$array_options[$ref]->{invoice_id}"} = $request->{first_load}? "on":  $request->{"optional_discount_$array_options[$ref]->{invoice_id}"};
 
@@ -963,10 +964,11 @@
        
 # XXX:  This causes issues currently, so display of unhandled overpayment has
 # disabled.  Was getting numbers that didn't make a lot of sense to me. --CT
-      if ( $due_fx <  $request->{"topay_fx_$array_options[$ref]->{invoice_id}"}) {
+      if ( $due_fx <  $request_topay_fx_bigfloat) {
          # We need to store all the overpayments so we can use it on the screen
-         $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} - $due_fx );
-         $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} = "$due_fx";
+         $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request_topay_fx_bigfloat - $due_fx );
+         #$request->{"topay_fx_$array_options[$ref]->{invoice_id}"} = "$due_fx";
+         $request_topay_fx_bigfloat=$due_fx;
      } 
 #Now its time to build the link to the invoice :)
 
@@ -978,8 +980,8 @@
                                             href   => $uri
                                            },  
                                invoice_date      => "$array_options[$ref]->{invoice_date}",
-                               amount            => "$array_options[$ref]->{amount}",
-                               due               => $request->{"optional_discount_$array_options[$ref]->{invoice_id}"}?  "$array_options[$ref]->{due}" : "$array_options[$ref]->{due}" + "$array_options[$ref]->{discount}",
+                               amount            => $Payment->format_amount(amount=>$array_options[$ref]->{amount}),
+                               due               => $Payment->format_amount(amount=>$request->{"optional_discount_$array_options[$ref]->{invoice_id}"}?  $array_options[$ref]->{due} : $array_options[$ref]->{due} + $array_options[$ref]->{discount}),
                                paid              => "$array_options[$ref]->{amount}" - "$array_options[$ref]->{due}"-"$array_options[$ref]->{discount}",
                                discount          => $request->{"optional_discount_$array_options[$ref]->{invoice_id}"} ? "$array_options[$ref]->{discount}" : 0 ,
                                optional_discount =>  $request->{"optional_discount_$array_options[$ref]->{invoice_id}"},
@@ -994,10 +996,10 @@
                                                        value => $request->{"memo_invoice_$array_options[$ref]->{invoice_id}"}      
                                                      },#END HASH
                                topay_fx          =>  { name  => "topay_fx_$array_options[$ref]->{invoice_id}",
-                                                       value => $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} ? 
+                                                       value =>  $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} ? 
                                                            $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} eq 'N/A' ?
                                                            "$topay_fx_value" :
-                                                           $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} :
+                                                           "$request_topay_fx_bigfloat":
                                                            "$topay_fx_value"
                                                            # Ugly hack, but works ;) ... 
                                                  }#END HASH
@@ -1123,7 +1125,8 @@
  selectedcheckboxes => @selected_checkboxes  ? ..hidden.. : '',
  notes => $request->{notes},
  overpayment         => ..hidden..,
- overpayment_account => ..hidden..
+ overpayment_account => ..hidden..,
+ format_amount => sub {return $Payment->format_amount(amount=>@_)}
 };
 my $template = LedgerSMB::Template->new(
   user     => $request->{_user},
@@ -1216,16 +1219,17 @@
          # we will assume that a discount should apply only
          # if this is the last payment of an invoice
      my  $temporary_discount = 0;
-     if (($request->{"optional_discount_$array_options[$ref]->{invoice_id}"})&&("$array_options[$ref]->{due_fx}" <=  $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} +  $array_options[$ref]->{discount_fx})) {
+     my  $request_topay_fx_bigfloat=$Payment->parse_amount(amount=>$request->{"topay_fx_$array_options[$ref]->{invoice_id}"});
+     if (($request->{"optional_discount_$array_options[$ref]->{invoice_id}"})&&("$array_options[$ref]->{due_fx}" <=  $request_topay_fx_bigfloat +  $array_options[$ref]->{discount_fx})) {
          $temporary_discount = $array_options[$ref]->{discount_fx};
      }   
          #
          # The prefix cash is to set the movements of the cash accounts, 
          # same names are used for ap/ar accounts w/o the cash prefix.
          #
-     if ( "$array_options[$ref]->{due_fx}" <  $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} ) {
+     if ( "$array_options[$ref]->{due_fx}" <  $request_topay_fx_bigfloat ) {
          # We need to store all the overpayments so we can use it on a new payment2 screen
-         $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $temporary_discount - $array_options[$ref]->{amount}) ;
+         $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request_topay_fx_bigfloat + $temporary_discount - $array_options[$ref]->{amount}) ;
 
      }
          if ($temporary_discount != 0) {
@@ -1234,7 +1238,7 @@
              push @source, $locale->text('Applied discount');
              push @transaction_id, $array_options[$ref]->{invoice_id};        
          } 
-         push @amount,   $request->{"topay_fx_$array_options[$ref]->{invoice_id}"}; # We'll use this for both cash and ap/ar accounts
+         push @amount,   $request_topay_fx_bigfloat; # We'll use this for both cash and ap/ar accounts
          push @cash_account_id,  $request->{"optional_pay_$array_options[$ref]->{invoice_id}"} ? $request->{"account_$array_options[$ref]->{invoice_id}"} : $request->{account};
          push @source, $request->{"optional_pay_$array_options[$ref]"} ?
                        $request->{"source_$array_options[$ref]->{invoice_id}"}.' '.$request->{"source_text_$array_options[$ref]->{invoice_id}"} 

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