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

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



Revision: 4979
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4979&view=rev
Author:   einhverfr
Date:     2012-07-14 06:55:38 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------

Using subtypes now for automagic conversion
All GET operations supported for Contacts.

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Report/Aging.pm
    trunk/LedgerSMB/DBObject/Report/Budget/Search.pm
    trunk/LedgerSMB/DBObject/Report/Budget/Variance.pm
    trunk/LedgerSMB/DBObject/Report/Contact/History.pm
    trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm
    trunk/LedgerSMB/DBObject/Report/Contact/Search.pm
    trunk/LedgerSMB/DBObject/Report/GL.pm
    trunk/LedgerSMB/DBObject/Report/Unapproved/Drafts.pm
    trunk/LedgerSMB/DBObject/Report/co/Balance_y_Mayor.pm
    trunk/LedgerSMB/DBObject/Report/co/Caja_Diaria.pm
    trunk/LedgerSMB/DBObject_Moose.pm
    trunk/LedgerSMB/PGDate.pm
    trunk/LedgerSMB/PGNumber.pm
    trunk/LedgerSMB/REST_Class/Contact.pm
    trunk/LedgerSMB/Template/TXT.pm
    trunk/rest-handler.pl

Modified: trunk/LedgerSMB/DBObject/Report/Aging.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Aging.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Aging.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -235,7 +235,7 @@
 
 =cut
 
-has 'date_ref' => (is => 'rw', builder => '_date');
+has 'date_ref' => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item entity_class
 

Modified: trunk/LedgerSMB/DBObject/Report/Budget/Search.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Budget/Search.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Budget/Search.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -156,7 +156,7 @@
 
 =cut
 
-has 'start_date' => (is=> 'rw', builder => '_date');
+has 'start_date' => (is=> 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item end_date
 
@@ -164,7 +164,7 @@
 
 =cut
 
-has 'end_date' => (is=> 'rw', builder => '_date');
+has 'end_date' => (is=> 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item buisness_units
 

Modified: trunk/LedgerSMB/DBObject/Report/Budget/Variance.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Budget/Variance.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Budget/Variance.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -156,13 +156,13 @@
 
 =cut
 
-has start_date => (is => 'ro', builder => '_date');
+has start_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item end_date
 
 =cut
 
-has end_date => (is => 'ro', builder => '_date');
+has end_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =back 
 

Modified: trunk/LedgerSMB/DBObject/Report/Contact/History.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/History.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Contact/History.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -237,7 +237,7 @@
 
 =cut
 
-has from_date => (is => 'ro', builder => '_date');
+has from_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item to_date
 
@@ -245,7 +245,7 @@
 
 =cut
 
-has to_date => (is => 'ro', builder => '_date');
+has to_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item type
 
@@ -277,7 +277,7 @@
 
 =cut
 
-has start_from => (is => 'ro', builder => '_date');
+has start_from => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item start_to
 
@@ -285,7 +285,7 @@
 
 =cut
 
-has start_to => (is => 'ro', builder => '_date');
+has start_to => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item inc_open
 

Modified: trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Contact/Purchase.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -244,7 +244,7 @@
 
 =cut
 
-has from_date => (is => 'ro', builder => '_date');
+has from_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item to_date
 
@@ -252,7 +252,7 @@
 
 =cut
 
-has to_date => (is => 'ro', builder => '_date');
+has to_date => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item as_of
 
@@ -260,7 +260,7 @@
 
 =cut
 
-has as_of => (is => 'ro', builder => '_date');
+has as_of => (is => 'ro', coerce => 1, isa => 'LedgerSMB::DBObject::Date');
 
 =item summarize
 

Modified: trunk/LedgerSMB/DBObject/Report/Contact/Search.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Contact/Search.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Contact/Search.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -222,8 +222,12 @@
 
 =cut
 
-has active_date_from => (is => 'ro', builder => '_date');
-has active_date_to => (is => 'ro', builder => '_date');
+has active_date_from => (is => 'ro', 
+                        isa => 'LedgerSMB::Moose::Date', 
+                     coerce => 1);
+has active_date_to => (is => 'ro', 
+                      isa => 'LedgerSMB::Moose::Date', 
+                   coerce => 1);
 
 =back
 

Modified: trunk/LedgerSMB/DBObject/Report/GL.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/GL.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/GL.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -286,7 +286,7 @@
 
 =cut
 
-has 'from_date' => (is => 'rw', builder => '_date');
+has 'from_date' => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item to_date
 
@@ -294,7 +294,7 @@
 
 =cut
 
-has 'to_date' => (is => 'rw', builder => '_date');
+has 'to_date' => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item approved
 
@@ -316,8 +316,10 @@
 
 =cut
 
-has 'amount_from' => (is => 'rw', builder => '_num');
-has 'amount_to' => (is => 'rw', builder => '_num');
+has 'amount_from' => (is => 'rw', coerce => 1, 
+                     isa => 'LedgerSMB::Moose::Number');
+has 'amount_to' => (is => 'rw', coerce => 1, 
+                   isa => 'LedgerSMB::Moose::Number');
 
 =item business_units
 

Modified: trunk/LedgerSMB/DBObject/Report/Unapproved/Drafts.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/Unapproved/Drafts.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/Unapproved/Drafts.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -178,7 +178,7 @@
 
 =cut
 
-has 'amount_gt' => (is => 'rw', isa => 'Maybe[Str]');
+has 'amount_gt' => (is => 'rw', coerce => 1, isa =>'LedgerSMB::Moose::Number');
 
 =item amount_lt
 
@@ -186,7 +186,7 @@
 
 =cut
 
-has 'amount_lt' => (is => 'rw', isa => 'Maybe[Str]');
+has 'amount_lt' => (is => 'rw', coerce => 1, isa =>'LedgerSMB::Moose::Number'););
 
 =back
 

Modified: trunk/LedgerSMB/DBObject/Report/co/Balance_y_Mayor.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/co/Balance_y_Mayor.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/co/Balance_y_Mayor.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -145,7 +145,7 @@
 
 =cut
 
-has 'date_from' => (is => 'rw', builder => '_date');
+has 'date_from' => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item date_to
 
@@ -153,7 +153,7 @@
 
 =cut
 
-has 'date_to'  => (is => 'rw', builder => '_date');
+has 'date_to'  => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =back
 

Modified: trunk/LedgerSMB/DBObject/Report/co/Caja_Diaria.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Report/co/Caja_Diaria.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject/Report/co/Caja_Diaria.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -146,7 +146,7 @@
 
 =cut
 
-has 'date_from' => (is => 'rw', builder => '_date');
+has 'date_from' => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 =item date_to
 
@@ -154,7 +154,7 @@
 
 =cut
 
-has 'date_to'  => (is => 'rw', builder => '_date');
+has 'date_to'  => (is => 'rw', coerce => 1, isa => 'LedgerSMB::Moose::Date');
 
 
 =item from_accno

Modified: trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- trunk/LedgerSMB/DBObject_Moose.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/DBObject_Moose.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -17,10 +17,8 @@
 use Log::Log4perl;
 use LedgerSMB::DBObject;
 use Moose::Util::TypeConstraints;
-use LedgerSMB::PGNumber;
-use LedgerSMB::PGDate;
+use LedgerSMB::MooseTypes
 
-
 =head1 METHODS
 
 =over
@@ -57,29 +55,6 @@
 
 my $logger = Log::Log4perl->get_logger('LedgerSMB::DBObject');
 
-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;

Modified: trunk/LedgerSMB/PGDate.pm
===================================================================
--- trunk/LedgerSMB/PGDate.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/PGDate.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -124,6 +124,7 @@
 
 sub _parse_string {
     my ($self, $string, $format, $has_time) = @_;
+    $string = undef if $string eq '';
     return undef if !defined $string;
     if (!defined $LedgerSMB::App_State::Locale->{datetime}){
         $LedgerSMB::App_State::Locale->{datetime} = 'en_US';
@@ -153,6 +154,7 @@
 sub from_input{
     my ($self, $input, $has_time) = @_;
     return $input if eval {$input->isa(__PACKAGE__)};
+    $input = undef if $input eq '';
     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/PGNumber.pm
===================================================================
--- trunk/LedgerSMB/PGNumber.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/PGNumber.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -121,6 +121,7 @@
 sub from_input {
     my $self   = shift @_;
     my $string = shift @_;
+    $string = undef if $string eq '';
     my %args   = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;  
     my $format = ($args{format}) ? $args{format}
                               : $LedgerSMB::App_State::User->{numberformat};

Modified: trunk/LedgerSMB/REST_Class/Contact.pm
===================================================================
--- trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -12,6 +12,7 @@
 use LedgerSMB::DBObject::Entity::Company;
 use LedgerSMB::DBObject::Entity::Person;
 use LedgerSMB::DBObject::Entity::Bank;
+use LedgerSMB::DBObject::Report::Contact::Search;
 
 =head1 SYNOPSIS
 
@@ -41,31 +42,65 @@
     my $id = $request->{classes}->{$cname};
     my $data;
     if ($id or ($id eq '0')){
-       my $company = LedgerSMB::DBObject::Entity::Company->get($id);
-       if ($company){
-          $data= $company;
-          $data->{entity_type} = 'Company';
+       return _get_entity($request, $id);
+    } else {
+       if ($request->{args}->{entity_class}) {
+          @{$data->{contacts}} =  _search_entity_class(
+              $request, $request->{args}->{entity_class}
+          ); 
+          return $data;
        } else {
-          my $person = LedgerSMB::DBObject::Entity::Person->get($id);
-          if ($person){
-             $data= $person;
-             $data->{entity_type} = 'Person';
-          } else {
-             die '404 Not Found';
-          }
+            my @results = ();
+            for $ref (LedgerSMB::DBObject::Entity->call_procedure(
+                          procname => 'entity__list_classes'
+                      )
+            ){
+                push @results,  _search_entity_class($request, $ref->{id});
+            }
+            return {contacts => ..hidden..;
        }
-       @{$data->{credit_accounts}} = 
-          LedgerSMB::DBObject::Entity::Credit_Account->list_for_entity($id);
-       @{$data->{locations}} = 
-         LedgerSMB::DBObject::Entity::Location->get_active({entity_id => $id});
-       @{$data->{contact}} =
-         LedgerSMB::DBObject::Entity::Contact->list({{entity_id => $id}});
-       @{$data->{bank_accounts}} = 
-         LedgerSMB::DBObject::Entity::Bank-> list($id);
-       return $data;
+    }
+}
+
+sub _search_entity_class {
+    my ($request, $entity_class) = @_;
+    my $args = $request->{args};
+    $args->{entity_class} = $entity_class;
+    my $report = LedgerSMB::DBObject::Report::Contact::Search->new(%$args);
+    $report->run_report;
+    my @results;
+    for my $r (@{$report->rows}){
+        my @new_results = _get_entity($request, $r->{entity_id});
+        push @results, @new_results;
+    }
+    return @results;
+}
+
+
+sub _get_entity {
+    my ($request, $id) = @_;
+    my $company = LedgerSMB::DBObject::Entity::Company->get($id);
+    if ($company){
+       $data= $company;
+       $data->{entity_type} = 'Company';
     } else {
-       die "Coming Soon";
+       my $person = LedgerSMB::DBObject::Entity::Person->get($id);
+       if ($person){
+          $data= $person;
+          $data->{entity_type} = 'Person';
+       } else {
+          die '404 Not Found';
+       }
     }
+    @{$data->{credit_accounts}} = 
+       LedgerSMB::DBObject::Entity::Credit_Account->list_for_entity($id);
+    @{$data->{locations}} = 
+      LedgerSMB::DBObject::Entity::Location->get_active({entity_id => $id});
+    @{$data->{contact}} =
+      LedgerSMB::DBObject::Entity::Contact->list({{entity_id => $id}});
+    @{$data->{bank_accounts}} = 
+      LedgerSMB::DBObject::Entity::Bank-> list($id);
+    return $data;
 }
 
 =item post

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/LedgerSMB/Template/TXT.pm	2012-07-14 06:55:38 UTC (rev 4979)
@@ -98,8 +98,6 @@
     }
      
     return $vars;
-    my $rawvars = shift;
-    return $rawvars;
 }
 
 sub process {

Modified: trunk/rest-handler.pl
===================================================================
--- trunk/rest-handler.pl	2012-07-14 00:21:58 UTC (rev 4978)
+++ trunk/rest-handler.pl	2012-07-14 06:55:38 UTC (rev 4979)
@@ -146,6 +146,7 @@
   lib->import($FindBin::Bin) unless $ENV{mod_perl}
 }
 
+use DBI;
 use CGI::Simple;
 use Try::Tiny;
 use LedgerSMB::App_State;
@@ -160,6 +161,8 @@
 # happens.  So hard-coded to English here.  --CT
 my $locale = LedgerSMB::Locale->get_handle('en');
 $LedgerSMB::App_State::Locale = $locale;
+$LedgerSMB::App_State::User = {numberformat => '1000.00', 
+                                 dateformat => 'YYYY-MM-DD'};
 
 process_request();
 
@@ -266,21 +269,21 @@
     $request->{method} = $ENV{REQUEST_METHOD};
     $request->{payload} = $cgi->param( "$request->{method}DATA" );
     $url =~ s|.*/rest-handler.pl/(.*)|$1|;
-    $url =~ s|\.([^/.]*$)||;
+    $url =~ s|\.([^/.?]*)(\?.*)?$||;
     $request->{format} = $1;
 
     my @components = split /\//, $url;
     my $version = shift @components;
     my $company = shift @components;
     die '400 Unsupported Version' if ($version ne '1.4');
-    $request->{dbh} = DBI->connect(
+    $LedgerSMB::App_State::DBH = DBI->connect(
         "dbi:Pg:dbname=$company", 
         "$creds->{login}", "$creds->{password}", 
             { AutoCommit => 0 }
     );
-    $LedgerSMB::App_State::DBH = $request->{dbh};
+    $request->{args}->{dbh} = $LedgerSMB::App_State::DBH;
 
-    if (!$request->{dbh}) {
+    if (!$request->{args}->{dbh}) {
            die '401 Unauthorized';
     }
 

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