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

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



Revision: 4968
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4968&view=rev
Author:   einhverfr
Date:     2012-07-11 10:27:36 +0000 (Wed, 11 Jul 2012)
Log Message:
-----------
Fixes so that dates and numbers can be made to work transparently in reports, etc

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Report/GL.pm
    trunk/LedgerSMB/DBObject/Report.pm
    trunk/LedgerSMB/DBObject_Moose.pm
    trunk/LedgerSMB/PGDate.pm
    trunk/LedgerSMB/Scripts/journal.pm
    trunk/LedgerSMB/Scripts/reports.pm
    trunk/LedgerSMB.pm

Modified: trunk/LedgerSMB/DBObject/Report/GL.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/GL.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/DBObject/Report/GL.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -168,6 +168,7 @@
                        name => $locale->text($class->label),
                        type => 'text',
                      pwidth => '2'};
+    }
     return ..hidden..;
 }
 
@@ -285,7 +286,7 @@
 
 =cut
 
-has 'from_date' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+has 'from_date' => (is => 'rw', builder => '_date');
 
 =item to_date
 
@@ -293,7 +294,7 @@
 
 =cut
 
-has 'to_date' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+has 'to_date' => (is => 'rw', builder => '_date');
 
 =item approved
 
@@ -315,8 +316,8 @@
 
 =cut
 
-has 'amount_from' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGNumber]');
-has 'amount_to' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGNumber]');
+has 'amount_from' => (is => 'rw', builder => '_num');
+has 'amount_to' => (is => 'rw', builder => '_num');
 
 =item business_units
 
@@ -332,18 +333,6 @@
 
 =over
 
-=item prepare_criteria($request)
-
-Instantiates the PGDate and PGNumber inputs.
-
-=cut
-
-sub prepare_criteria{
-    my ($self, $request) = @_;
-    $self->prepare_input($request);
-    $request->{accno} =~ s/--.*$//;
-}
-
 =item run_report()
 
 Runs the report, and assigns rows to $self->rows.

Modified: trunk/LedgerSMB/DBObject/Report.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/DBObject/Report.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -333,7 +333,7 @@
     my ($self, $ref) = @_;
     for my $bu (@{$ref->{business_units}}){
         push @{$ref->{$bu->[0]}}, $bu->[1] 
-                 unless grep /$bu->[1]/ @{$ref->{$bu->[0]}};
+                 unless grep(/$bu->[1]/, @{$ref->{$bu->[0]}});
     }
 }
 

Modified: trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- trunk/LedgerSMB/DBObject_Moose.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/DBObject_Moose.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -7,6 +7,20 @@
 
 This module creates object instances based on LedgerSMB's in-database ORM, using Moose.
 
+=cut
+
+package LedgerSMB::DBObject_Moose;
+use Moose;
+use LedgerSMB::DBObject;
+use LedgerSMB;
+use Scalar::Util;
+use Log::Log4perl;
+use LedgerSMB::DBObject;
+use Moose::Util::TypeConstraints;
+use LedgerSMB::PGNumber;
+use LedgerSMB::PGDate;
+
+
 =head1 METHODS
 
 =over
@@ -41,20 +55,31 @@
 
 =cut
 
-package LedgerSMB::DBObject_Moose;
-use LedgerSMB::DBObject;
-use LedgerSMB;
-use Moose;
-use Scalar::Util;
-use Log::Log4perl;
-use LedgerSMB::DBObject;
-
 my $logger = Log::Log4perl->get_logger('LedgerSMB::DBObject');
 
-sub __validate__ {}
-
 has 'dbh' => (is => 'ro', isa => 'DBI::db', required => '1');
 
+=item _num 
+
+Turns a number value into PGNumber object.
+
+=cut
+
+sub _num {
+    return LedgerSMB::PGNumber->from_input(@_);
+}
+
+=item _date
+
+Turns a value into a PGDate object
+
+=cut
+
+sub _date {
+    return LedgerSMB::PGDate->from_input(@_);
+}
+
+
 sub prepare_dbhash {
     my $self = shift;
     my $target = shift;
@@ -127,28 +152,9 @@
                end => LedgerSMB::PGDate->from_db($end, 'date') };   
 }
 
-__PACKAGE__->meta->make_immutable;
 
-1;
-
 =back
 
-=head1 COERCIONS
-
-=over
-
-=item Str -> LedgerSMB::PGNumber via from_input()
-
-=item Str -> LedgerSMB::PGDate via from_input
-
-=cut
-
-coerce 'LedgerSMB::PGNumber' from 'Str' 
-   via { LedgerSMB::PGNumber->from_input($_) };
-
-coerce 'LedgerSMB::PGDate' from 'Str' 
-   via { LedgerSMB::PGDate->from_input($_) };
-
 =head1 Copyright (C) 2007, The LedgerSMB core team.
 
 This file is licensed under the Gnu General Public License version 2, or at your
@@ -156,3 +162,7 @@
 your software.
 
 =cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;

Modified: trunk/LedgerSMB/PGDate.pm
===================================================================
--- trunk/LedgerSMB/PGDate.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/PGDate.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -152,6 +152,7 @@
 
 sub from_input{
     my ($self, $input, $has_time) = @_;
+    return $input if eval {$input->isa(__PACKAGE__)};
     return undef if !defined $input;
     my $format = $LedgerSMB::App_State::User->{dateformat};
     my $dt =  _parse_string($self, $input, uc($format), $has_time);

Modified: trunk/LedgerSMB/Scripts/journal.pm
===================================================================
--- trunk/LedgerSMB/Scripts/journal.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/Scripts/journal.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -111,7 +111,7 @@
          push @{$request->{business_units}}, $request->{"business_unit_$count"}
                if $request->{"business_unit_$count"};
     }
-    LedgerSMB::DBObject::Report::GL->prepare_criteria($request);
+    #LedgerSMB::DBObject::Report::GL->prepare_criteria($request);
     my $report = LedgerSMB::DBObject::Report::GL->new(%$request);
     $report->run_report;
     $report->render($request);

Modified: trunk/LedgerSMB/Scripts/reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/reports.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB/Scripts/reports.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -73,7 +73,7 @@
         die $request->{_locale}->text('No report specified');
     }
     @{$request->{country_list}} = $request->call_procedure( 
-                   ocname => 'location_list_country'
+                   procname => 'location_list_country'
     );
     my $template = LedgerSMB::Template->new(
         user => $request->{_user},

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2012-07-11 08:34:42 UTC (rev 4967)
+++ trunk/LedgerSMB.pm	2012-07-11 10:27:36 UTC (rev 4968)
@@ -810,7 +810,7 @@
 sub error {
 
     my ( $self, $msg ) = @_;
-    Carp::confess();
+    #Carp::confess();
     if ( $ENV{GATEWAY_INTERFACE} ) {
 
         $self->{msg}    = $msg;

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