[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4824] trunk
- Subject: SF.net SVN: ledger-smb:[4824] trunk
- From: ..hidden..
- Date: Sun, 03 Jun 2012 10:24:30 +0000
Revision: 4824
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4824&view=rev
Author: einhverfr
Date: 2012-06-03 10:24:30 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
Natural persons can now be managed as customers and vendors. Not sure if search works. Not sure if old code recognizes change yet.
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Entity/Company.pm
trunk/LedgerSMB/DBObject/Entity/Person.pm
trunk/LedgerSMB/DBObject/Entity.pm
trunk/sql/modules/Person.sql
Modified: trunk/LedgerSMB/DBObject/Entity/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Company.pm 2012-06-03 08:25:16 UTC (rev 4823)
+++ trunk/LedgerSMB/DBObject/Entity/Company.pm 2012-06-03 10:24:30 UTC (rev 4824)
@@ -97,9 +97,7 @@
my ($self, $id) = @_;
my ($ref) = $self->call_procedure(procname => 'company__get',
args => [$id]);
- if (!$ref){
- return undef;
- }
+ return undef unless $ref->{control_code};
$self->prepare_dbhash($ref);
return $self->new(%$ref);
}
@@ -115,9 +113,7 @@
my ($self, $cc) = @_;
my ($ref) = $self->call_procedure(procname => 'company__get_by_cc',
args => [$cc]);
- if (!$ref){
- return undef;
- }
+ return undef unless $ref->{control_code};
$self->prepare_dbhash($ref);
return $self->new(%$ref);
}
Modified: trunk/LedgerSMB/DBObject/Entity/Person.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Person.pm 2012-06-03 08:25:16 UTC (rev 4823)
+++ trunk/LedgerSMB/DBObject/Entity/Person.pm 2012-06-03 10:24:30 UTC (rev 4824)
@@ -130,9 +130,7 @@
my ($self, $id) = @_;
my ($ref) = $self->call_procedure(procname => 'person__get',
args => [$id]);
- if (!$ref){
- die $locale->text('No person found.');
- }
+ return undef unless $ref->{control_code};
$self->prepare_dbhash($ref);
return $self->new(%$ref);
}
@@ -147,7 +145,8 @@
sub get_by_cc {
my ($self, $cc) = @_;
my ($ref) = $self->call_procedure(procname => 'person__get_by_cc',
- args => [$cc]) || return undef;
+ args => [$cc]);
+ return undef unless $ref->{control_code};
$self->prepare_dbhash($ref);
return $self->new(%$ref);
}
Modified: trunk/LedgerSMB/DBObject/Entity.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity.pm 2012-06-03 08:25:16 UTC (rev 4823)
+++ trunk/LedgerSMB/DBObject/Entity.pm 2012-06-03 10:24:30 UTC (rev 4824)
@@ -102,7 +102,7 @@
=cut
sub get{
- my ($id) = @_;
+ my ($self, $id) = @_;
my $entity =
LedgerSMB::DBObject::Entity::Company->get($id) ||
LedgerSMB::DBObject::Entity::Person->get($id);
@@ -111,8 +111,20 @@
=item get_by_cc($control_code)
-This retrieves the entity or person by control code
+This retrieves the entity or person by control code. It has the same return
+possibilities as get() above.
+=cut
+
+sub get_by_cc{
+ my ($self, $control_code) = @_;
+ my $entity =
+ LedgerSMB::DBObject::Entity::Company->get_by_cc($control_code) ||
+ LedgerSMB::DBObject::Entity::Person->get_by_cc($control_code);
+ return $entity;
+}
+
+
=head1 COPYRIGHT
Copyright (C) 2012 The LedgerSMB Core Team. This file may be reused under the
Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql 2012-06-03 08:25:16 UTC (rev 4823)
+++ trunk/sql/modules/Person.sql 2012-06-03 10:24:30 UTC (rev 4824)
@@ -20,6 +20,41 @@
COMMENT ON FUNCTION person__list_languages() IS
$$ Returns a list of languages ordered by code$$;
+DROP TYPE IF EXISTS person_entity CASCADE;
+
+CREATE TYPE person_entity AS (
+ entity_id int,
+ control_code text,
+ name text,
+ country_id int,
+ country_name text,
+ first_name text,
+ middle_name text,
+ last_name text
+);
+
+CREATE FUNCTION person__get(in_entity_id int)
+RETURNS person_entity AS
+$$
+SELECT e.id, e.control_code, e.name, e.country_id, c.name,
+ p.first_name, p.middle_name, p.last_name
+ FROM entity e
+ JOIN country c ON c.id = e.country_id
+ JOIN person p ON p.entity_id = e.id
+ WHERE e.id = $1;
+$$ LANGUAGE SQL;
+
+CREATE FUNCTION person__get_by_cc(in_control_code text)
+RETURNS person_entity AS
+$$
+SELECT e.id, e.control_code, e.name, e.country_id, c.name,
+ p.first_name, p.middle_name, p.last_name
+ FROM entity e
+ JOIN country c ON c.id = e.country_id
+ JOIN person p ON p.entity_id = e.id
+ WHERE e.control_code = $1;
+$$ LANGUAGE SQL;
+
CREATE OR REPLACE FUNCTION person__list_salutations()
RETURNS SETOF salutation AS
$$ SELECT * FROM salutation ORDER BY id ASC $$ language sql;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.