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

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



Revision: 4331
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4331&view=rev
Author:   einhverfr
Date:     2012-02-18 10:58:38 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
Framework fixes.  Can now log in and edit users in trunk

Modified Paths:
--------------
    trunk/LedgerSMB/App_State.pm
    trunk/LedgerSMB/PGDate.pm
    trunk/LedgerSMB.pm
    trunk/Makefile.PL
    trunk/dists/rpm/ledgersmb.spec
    trunk/lsmb-request.pl

Modified: trunk/LedgerSMB/App_State.pm
===================================================================
--- trunk/LedgerSMB/App_State.pm	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/LedgerSMB/App_State.pm	2012-02-18 10:58:38 UTC (rev 4331)
@@ -69,7 +69,7 @@
     my ($username, $credential, $company) = @_;
     $SODA   = LedgerSMB::SODA->new({db => $company, 
                               username => $username,
-                                  cred => $cred});
+                                  cred => $credential});
     $User   = LedgerSMB::User->fetch_config($SODA);
     $Locale = LedgerSMB::Locale->get_handle($User->{language});
 }

Modified: trunk/LedgerSMB/PGDate.pm
===================================================================
--- trunk/LedgerSMB/PGDate.pm	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/LedgerSMB/PGDate.pm	2012-02-18 10:58:38 UTC (rev 4331)
@@ -3,18 +3,19 @@
 
 =cut
 
+package LedgerSMB::PGDate;
 use Moose;
 use DateTime::Format::Strptime;
-package LedgerSMB::PGDate;
+use Carp;
 
 BEGIN {
    use LedgerSMB::SODA;
    LedgerSMB::SODA->register_type({sql_type => 'date', 
-                                 perl_class => 'LedgerSMB::PGDate');
+                                 perl_class => 'LedgerSMB::PGDate'});
    LedgerSMB::SODA->register_type({sql_type => 'datetime', 
-                                 perl_class => 'LedgerSMB::PGDate');
+                                 perl_class => 'LedgerSMB::PGDate'});
    LedgerSMB::SODA->register_type({sql_type => 'timestamp', 
-                                 perl_class => 'LedgerSMB::PGDate');
+                                 perl_class => 'LedgerSMB::PGDate'});
 }
 
 =head1 SYNPOSIS
@@ -46,73 +47,46 @@
 
 =item 'YYYY-MM-DD'
 
-=cut
-
-our $formats = { 
-    'YYYY-MM-DD' => ['%F'],
-
 =item DD-MM-YYYY
 
-=cut
 
-    'DD-MM-YYYY' => ['%d-%m-%Y', '%d-%m-%y'],
-
 =item DD/MM/YYYY
 
-=cut
-    'DD/MM/YYYY' > ['%d/%m/%Y', '%D'],
-
 =item MM-DD-YYYY
 
-=cut
-
-    'MM-DD-YYYY' => ['%m-%d-%Y', '%m-%d-%y'],
-
 =item MM/DD/YYYY 
 
-=cut
-    'MM/DD/YYYY' => ['%d/%m/%Y', '%d/%m/%y'],
-
 =item YYYYMMDD
 
-=cut
-
-      'YYYYMMDD' => ['%Y%m%d'],
-
 =item YYMMDD
 
-=cut
-        'YYMMDD' => ['%y%m%d'],
-
 =item DDMMYYYY
 
-=cut
-
-      'DDMMYYYY' => ['%d%m%Y'],
-
 =item DDMMYY
 
-=cut
-        'DDMMYY' => ['%d%m%y'],
-
 =item MMDDYYYY
 
-=cut
-
-      'MMDDYYYY' => ['%m%d%Y'],
-
 =item MMDDYY
 
-=cut
-        'MMDDYY' => ['%m%d%y'],
-
 =item DDmonYYYY
 
 =cut
+
+our $formats = { 
+    'YYYY-MM-DD' => ['%F'],
+    'DD-MM-YYYY' => ['%d-%m-%Y', '%d-%m-%y'],
+    'DD/MM/YYYY' => ['%d/%m/%Y', '%D'],
+    'MM-DD-YYYY' => ['%m-%d-%Y', '%m-%d-%y'],
+    'MM/DD/YYYY' => ['%d/%m/%Y', '%d/%m/%y'],
+      'YYYYMMDD' => ['%Y%m%d'],
+        'YYMMDD' => ['%y%m%d'],
+      'DDMMYYYY' => ['%d%m%Y'],
+        'DDMMYY' => ['%d%m%y'],
+      'MMDDYYYY' => ['%m%d%Y'],
+        'MMDDYY' => ['%m%d%y'],
      'DDmonYYYY' => ['%d%b%Y', '%d%b%y']
+};
 
-}
-
 =back
 
 =head1 CONSTRUCTOR SYNTAX
@@ -150,12 +124,15 @@
 
 sub _parse_string {
     my ($self, $string, $format, $has_time) = @_;
+    if (!defined $LedgerSMB::App_State::Locale->{datetime}){
+        $LedgerSMB::App_State::Locale->{datetime} = 'en_US';
+    }
     for my $fmt (@{$formats->{$format}}){
         if ($has_time or ! defined $has_time){
             my $parser = new DateTime::Format::Strptime(
                      pattern => $fmt . ' %T',
                       locale => $LedgerSMB::App_State::Locale->{datetime},
-           }
+            );
             if (my $dt = $parser->parse_datetime($string)){
                 return $dt;
             } 
@@ -164,17 +141,17 @@
             my $parser = new DateTime::Format::Strptime(
                      pattern => $fmt,
                       locale => $LedgerSMB::App_State::Locale->{datetime},
-            }
+            );
             if (my $dt = $parser->parse_datetime($string)){
                 return $dt;
             }
         }
     }
-    die 'LedgerSMB::PGDate Invalid Date';
+    confess 'LedgerSMB::PGDate Invalid Date';
 }
 
 sub from_input{
-    my ($self, $input, $has_date) = @_;
+    my ($self, $input, $has_time) = @_;
     my $format = $LedgerSMB::App_State::User->dateformat;
     my $dt =  _parse_string($self, $input, $format, $has_time);
     return $self->new({date => $dt});
@@ -187,7 +164,6 @@
 used.  If $format is not supplied, the dateformat of the user is used.
 
 =cut
-
 sub to_output {
     my ($self) = @_;
     my $fmt = $formats->{$LedgerSMB::App_State::User->dateformat}->[0];
@@ -195,7 +171,7 @@
              pattern => $fmt,
               locale => $LedgerSMB::App_State::Locale->{datetime},
             on_error => 'croak',
-    }
+    );
     return $formatter->format_datetime($self->date);
 }
 
@@ -207,15 +183,16 @@
 =cut
 
 sub from_db {
+    use Carp;
     my ($self, $input, $type) = @_;
     my $format = 'YYYY-MM-DD';
-    my $has_timme;
+    my $has_time;
     if ((lc($type) eq 'datetime') or (lc($type) eq 'timestamp')) {
         $has_time = 1;
     } elsif(lc($type) eq 'date'){
         $has_time = 0;
     } else {
-       die 'LedgerSMB::PGDate Invalid DB Type';
+       confess 'LedgerSMB::PGDate Invalid DB Type';
     }
     my $dt =  _parse_string($self, $input, $format, $has_time);
     return $self->new({date => $dt});
@@ -234,7 +211,7 @@
              pattern => $fmt,
               locale => $LedgerSMB::App_State::Locale->{datetime},
             on_error => 'croak',
-    }
+    );
     return $formatter->format_datetime($self->date);
 }
 

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/LedgerSMB.pm	2012-02-18 10:58:38 UTC (rev 4331)
@@ -204,6 +204,7 @@
 use CGI::Simple;
 $CGI::Simple::DISABLE_UPLOADS = 0;
 use LedgerSMB::PGNumber;
+use LedgerSMB::PGDate;
 use LedgerSMB::Sysconfig;
 use Data::Dumper;
 use Error;
@@ -710,11 +711,11 @@
 	for (0 .. $#names){
             #   numeric            float4/real
             if ($types[$_] == 3 or $types[$_] == 2) {
-                $ref->{$names[$_]} = Math::BigFloat->new($ref->{$names[$_]});
+                $ref->{$names[$_]} = Math::BigFloat->new($ref->{$names[$_]}, 'datetime') if defined $ref->{$names[$_]};
             }
             #    DATE                TIMESTAMP
             if ($types[$_] == 91 or $types[$_] == 11){
-                $ref->{$names[$_]} = LedgerSMB::PGDate->from_db($ref->{$names[$_]});
+                $ref->{$names[$_]} = LedgerSMB::PGDate->from_db($ref->{$names[$_]}, 'date') if defined $ref->{$names[$_]};
             }
         }
         push @results, $ref;

Modified: trunk/Makefile.PL
===================================================================
--- trunk/Makefile.PL	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/Makefile.PL	2012-02-18 10:58:38 UTC (rev 4331)
@@ -33,6 +33,7 @@
 requires 'CGI::Simple';
 requires 'File::MimeInfo';
 requires 'Number::Format';
+requires 'DateTime::Format::Strptime';
 
 recommends 'perl-Math-BigInt-GMP';
 

Modified: trunk/dists/rpm/ledgersmb.spec
===================================================================
--- trunk/dists/rpm/ledgersmb.spec	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/dists/rpm/ledgersmb.spec	2012-02-18 10:58:38 UTC (rev 4331)
@@ -19,7 +19,7 @@
 Requires: perl-Locale-Maketext-Lexicon >= 0.62
 Requires: perl-IO-String 
 Requires: perl-Math-BigInt-GMP
-Requires: perl-Log-Log4perl perl-DateTime
+Requires: perl-Log-Log4perl perl-DateTime perl-DateTime-Format-Strptime
 Requires: perl-Config-Std
 BuildRequires: perl
 # avoid bogus autodetection of perl modules:

Modified: trunk/lsmb-request.pl
===================================================================
--- trunk/lsmb-request.pl	2012-02-18 09:40:50 UTC (rev 4330)
+++ trunk/lsmb-request.pl	2012-02-18 10:58:38 UTC (rev 4331)
@@ -29,6 +29,7 @@
 binmode (STDIN, ':utf8');
 binmode (STDOUT, ':utf8');
 use LedgerSMB::User;
+use LedgerSMB::App_State;
 use LedgerSMB;
 use LedgerSMB::Locale;
 use Data::Dumper;
@@ -59,7 +60,9 @@
 my $locale;
 
 if ($request->{_user}){
+    $LedgerSMB::App_State::User = $request->{_user};
     $locale =  LedgerSMB::Locale->get_handle($request->{_user}->{language});
+    $LedgerSMB::App_State::Locale = $locale;
 } else {
     $locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
        or $request->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );

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