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

SF.net SVN: ledger-smb:[3895] trunk/LedgerSMB



Revision: 3895
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3895&view=rev
Author:   einhverfr
Date:     2011-10-20 07:56:45 +0000 (Thu, 20 Oct 2011)
Log Message:
-----------
More fixes to PGDate and PGNumbers

Modified Paths:
--------------
    trunk/LedgerSMB/PGDate.pm
    trunk/LedgerSMB/Scripts/asset.pm
    trunk/LedgerSMB/Scripts/customer.pm
    trunk/LedgerSMB/Scripts/recon.pm
    trunk/LedgerSMB/Scripts/taxform.pm
    trunk/LedgerSMB/Scripts/vendor.pm

Added Paths:
-----------
    trunk/LedgerSMB/PGNumber.pm

Modified: trunk/LedgerSMB/PGDate.pm
===================================================================
--- trunk/LedgerSMB/PGDate.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/PGDate.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -11,6 +11,8 @@
    use LedgerSMB::SODA;
    LedgerSMB::SODA->register_type({sql_type => 'date', 
                                  perl_class => 'LedgerSMB::PGDate');
+   LedgerSMB::SODA->register_type({sql_type => 'datetime', 
+                                 perl_class => 'LedgerSMB::PGDate');
    LedgerSMB::SODA->register_type({sql_type => 'timestamp', 
                                  perl_class => 'LedgerSMB::PGDate');
 }
@@ -150,7 +152,7 @@
         if ($has_time or ! defined $has_time){
             my $parser = new DateTime::Format::Strptime(
                      pattern => $fmt . ' %T',
-                      locale => $LedgerSMB::Web_App::Locale->{datetime},
+                      locale => $LedgerSMB::App_State::Locale->{datetime},
            }
             if (my $dt = $parser->parse_datetime($string)){
                 return $dt;
@@ -159,7 +161,7 @@
         if (!$has_time or ! defined $has_time){
             my $parser = new DateTime::Format::Strptime(
                      pattern => $fmt,
-                      locale => $LedgerSMB::Web_App::Locale->{datetime},
+                      locale => $LedgerSMB::App_State::Locale->{datetime},
             }
             if (my $dt = $parser->parse_datetime($string)){
                 return $dt;
@@ -171,7 +173,7 @@
 
 sub from_input{
     my ($self, $input, $has_date) = @_;
-    my $format = $LedgerSMB::Web_App::user->dateformat;
+    my $format = $LedgerSMB::App_State::User->dateformat;
     my $dt =  _parse_string($self, $input, $format, $has_time);
     return $self->new({date => $dt});
 }
@@ -186,10 +188,10 @@
 
 sub to_output {
     my ($self) = @_;
-    my $fmt = $formats->{$LedgerSMB::Web_App::user->dateformat}->[0];
+    my $fmt = $formats->{$LedgerSMB::App_State::User->dateformat}->[0];
     my $formatter = new DateTime::Format::Strptime(
              pattern => $fmt,
-              locale => $LedgerSMB::Web_App::Locale->{datetime},
+              locale => $LedgerSMB::App_State::Locale->{datetime},
             on_error => 'croak',
     }
     return $formatter->format_datetime($self->date);
@@ -228,7 +230,7 @@
     $fmt .= ' %T' if ($self->date->hour);
     my $formatter = new DateTime::Format::Strptime(
              pattern => $fmt,
-              locale => $LedgerSMB::Web_App::Locale->{datetime},
+              locale => $LedgerSMB::App_State::Locale->{datetime},
             on_error => 'croak',
     }
     return $formatter->format_datetime($self->date);

Added: trunk/LedgerSMB/PGNumber.pm
===================================================================
--- trunk/LedgerSMB/PGNumber.pm	                        (rev 0)
+++ trunk/LedgerSMB/PGNumber.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -0,0 +1,217 @@
+=head1 NAME
+
+LedgerSMB::PGNumeric
+
+=cut
+
+use strict;
+use warnings;
+use Number::Format;
+
+package LedgerSMB::PGNumeric;
+
+BEGIN {
+   use LedgerSMB::SODA;
+   LedgerSMB::SODA->register_type({sql_type => 'float', 
+                                 perl_class => 'LedgerSMB::PGNumeric');
+   LedgerSMB::SODA->register_type({sql_type => 'double', 
+                                 perl_class => 'LedgerSMB::PGNumeric');
+   LedgerSMB::SODA->register_type({sql_type => 'numeric', 
+                                 perl_class => 'LedgerSMB::PGNumeric');
+}
+
+=head1 SYNPOSIS
+
+This is a wrapper class for handling a database interface for numeric (int, 
+float, numeric) data types to/from the database and to/from user input.
+
+This extends Math::BigFloat and can be used in this way.
+
+=head1 INHERITS
+
+=over
+
+=item Math::BigFloat
+
+=back
+
+=cut
+
+use base qw(Math::BigFloat);
+
+=head1 SUPPORTED I/O FORMATS
+
+=over
+
+=cut
+
+our $lsmb_formats = {
+      "1000.00" => { thousands_sep => '',  decimal_sep => '.' },
+=item 1000.00 (default)
+
+=cut
+      "1000,00" => { thousands_sep => '',  decimal_sep => ',' },
+=item 1000,00
+
+=cut
+     "1 000.00" => { thousands_sep => ' ', decimal_sep => '.' },
+=item 1 000.00
+
+=cut
+     "1 000,00" => { thousands_sep => ' ', decimal_sep => ',' },
+=item 1 000,00
+
+=cut
+     "1,000.00" => { thousands_sep => ',', decimal_sep => '.' },
+=item 1,000.00
+
+=cut
+     "1.000,00" => { thousands_sep => '.', decimal_sep => ',' },
+=item 1.000,00
+
+=cut
+     "1'000,00" => { thousands_sep => "'", decimal_sep => ',' },
+=item 1'000,00
+
+=cut
+
+};
+
+=back
+
+=head1 SUPPORTED NEGATIVE FORMATS
+
+All use 123.45 as an example.
+
+=over
+
+=cut
+
+my $lsmb_neg_formats = {
+  'def' => { pos => '%s',   neg => '-%s'   },
+
+=item def (DEFAULT)
+
+positive:  123.45
+negative: -123.45
+
+=cut
+ 'DRCR' => { pos => '%s CR' neg => '%s DR' },
+=item DRCR
+
+positive:  123.45 CR
+negative:  123.45 DR
+
+=cut
+    'paren' => { pos => '%s',   neg => '(%s)'  },
+=item paren
+
+positive:  123.45
+negative: (123.45)
+
+=cut
+}
+
+=back
+
+=head1 I/O METHODS
+
+=over
+
+=item from_input
+
+=cut
+
+sub from_input {
+    use Number::Format qw(:subs :vars);
+    my ($self, $string) = @_; 
+    $format = ($args{format}) ? $args{format}
+                              : $LedgerSMB::App_State::User->{numberformat};
+
+    my $places = ($args{places}) ? $args{places} : undef;
+    $places = $LedgerSMB::Sysconfig::decimal_places if $args{money};
+
+    $DECIMAL_FILL    = 0;
+    $DECIMAL_DIGITS  = $places if defined $places;
+    $THOUSANDS_SEP   = $lsmb_formats->{format}->{thousands_sep};
+    $DECIMAL_POINT   = $lsmb_formats->{format}->{decimal_sep};
+    my $pgnum = $self->new(unformat_number($string));
+    die 'LedgerSMB::PGNumber Invalid Number' if $pgnum->isnan();
+}
+
+=item to_output($hashref or %hash);
+
+All arguments are optional.  Hash or hashref arguments include
+
+=over
+
+=item format
+
+Override user's default output format with specified format for this number.
+
+=item places
+
+Specifies the number of places to round
+
+=item money
+
+Specifies to round to configured number format for money
+
+=item neg_format
+
+Specifies the negative format
+
+=item locale
+
+=back
+
+=cut
+
+sub to_output {
+    use Number::Format qw(:subs :vars);
+    my ($self) = shift;
+    my %args  = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;  
+    my $is_neg = $self->is_neg;
+    $self->bmul(-1) if $is_neg;
+
+    my $str = $self->bstr;
+    $format = ($args{format}) ? $args{format}
+                              : $LedgerSMB::App_State::User->{numberformat};
+
+    $THOUSANDS_SEP   = $lsmb_formats->{format}->{thousands_sep};
+    $DECIMAL_POINT   = $lsmb_formats->{format}->{decimal_sep};
+    $str = format_number($str);
+
+    my $neg_format = ($args{neg_format}) ? $args{neg_format} : 'def';
+    my $fmt = ($is_neg) ? $lsmb_neg_formats->{$neg_format}->{neg}
+                        : $lsmb_neg_formats->{$neg_format}->{pos};
+   
+    return sprintf($fmt, $str);
+}
+
+=item from_db
+
+=cut
+
+sub from_db {
+    my ($self, $string) = @_;
+    return $self->new($string);
+}
+
+=item to_db
+
+=cut
+
+sub to_db {
+    my ($self) = @_; 
+    return $self->to_output({format => '1000.00'});
+}
+
+1;
+
+=head1 Copyright (C) 2011, The LedgerSMB core team.
+
+This file is licensed under the Gnu General Public License version 2, or at your
+option any later version.  A copy of the license should have been included with
+your software.
+

Modified: trunk/LedgerSMB/Scripts/asset.pm
===================================================================
--- trunk/LedgerSMB/Scripts/asset.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/Scripts/asset.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -922,7 +922,7 @@
     });
 }
 
-=sub disposal_details_approve
+=item disposal_details_approve
 
 Pass through function for form-dynatable's action munging.  An lias for 
 report_details_approve.
@@ -933,7 +933,7 @@
     report_details_approve(@_);
 }
 
-=iten report_details_approve
+=item report_details_approve
 
 Approves disposal details.  id must be set,
 

Modified: trunk/LedgerSMB/Scripts/customer.pm
===================================================================
--- trunk/LedgerSMB/Scripts/customer.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/Scripts/customer.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -37,8 +37,6 @@
 }
 
 
-=back
-
 =head1 INHERITS
 
 LedgerSMB::ScriptLib::Company

Modified: trunk/LedgerSMB/Scripts/recon.pm
===================================================================
--- trunk/LedgerSMB/Scripts/recon.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/Scripts/recon.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -475,10 +475,6 @@
     return search($request);
 }
 
-=pod
-
-=over
-
 =item approve ($self, $request, $user)
 
 Requires report_id
@@ -489,8 +485,6 @@
 Returns a success page on success, returns a new report on failure, showing 
 the uncorrected entries.
 
-=back
-
 =cut
 
 sub approve {
@@ -544,18 +538,12 @@
     }
 }
 
-=pod
-
-=over
-
 =item pending ($self, $request, $user)
 
 Requires {date} and {month}, to handle the month-to-month pending transactions
 in the database. No mechanism is provided to grab ALL pending transactions 
 from the acc_trans table.
 
-=back
-
 =cut
 
 
@@ -612,7 +600,7 @@
  eval { do "scripts/custom/recon.pl" };
 1;
 
-=pod
+=back
 
 =head1 Copyright (C) 2007, The LedgerSMB core team.
 

Modified: trunk/LedgerSMB/Scripts/taxform.pm
===================================================================
--- trunk/LedgerSMB/Scripts/taxform.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/Scripts/taxform.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -37,8 +37,6 @@
 
 Display the filter screen by default.
 
-=back
-
 =cut
 
 sub __default {
@@ -71,14 +69,10 @@
 
 =pod
 
-=over
-
 =item add_taxform
 
 Display the "add taxform" screen.
 
-=back
-
 =cut
 
 sub add_taxform 
@@ -257,6 +251,8 @@
     });
 }
 
+=back
+
 =head1 Copyright (C) 2010 The LedgerSMB Core Team
 
 Licensed under the GNU General Public License version 2 or later (at your 

Modified: trunk/LedgerSMB/Scripts/vendor.pm
===================================================================
--- trunk/LedgerSMB/Scripts/vendor.pm	2011-10-19 23:32:23 UTC (rev 3894)
+++ trunk/LedgerSMB/Scripts/vendor.pm	2011-10-20 07:56:45 UTC (rev 3895)
@@ -40,8 +40,6 @@
 eval { do "scripts/custom/vendor.pl"};
     
 
-=back
-
 =head1 INHERITS
 
 LedgerSMB::ScriptLib::Company

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