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

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



Revision: 865
          http://svn.sourceforge.net/ledger-smb/?rev=865&view=rev
Author:   einhverfr
Date:     2007-03-08 11:02:30 -0800 (Thu, 08 Mar 2007)

Log Message:
-----------
Adding a business location object as well

Modified Paths:
--------------
    trunk/sql/upgrade/1.2-1.3.sql

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

Added: trunk/LedgerSMB/Location.pm
===================================================================
--- trunk/LedgerSMB/Location.pm	                        (rev 0)
+++ trunk/LedgerSMB/Location.pm	2007-03-08 19:02:30 UTC (rev 865)
@@ -0,0 +1,58 @@
+=head1 NAME
+
+LedgerSMB::Location - LedgerSMB class for managing Business Locations
+
+=head1 SYOPSIS
+
+This module creates object instances based on LedgerSMB's in-database ORM.  
+
+=head1 METHODS
+
+The following method is static:
+=item new ($LedgerSMB object);
+
+The following methods are passed through to stored procedures:
+=item save
+=item get
+=item search
+=item list_all
+=item delete (via Autoload)
+
+The above list may grow over time, and may depend on other installed modules.
+
+=head1 Copyright (C) 2007, 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.
+
+=back
+
+=cut
+
+package LedgerSMB::Location;
+use LedgerSMB;
+use LedgerSMB::DBObject;
..hidden.. = (LedgerSMB::DBObject);
+
+sub AUTOLOAD {
+	my $procname = "location_$LedgerSMB::Location::Autoload";
+	$self->exec_method($procname);
+}
+
+sub save {
+	$ref = shift @{$self->exec_method("location_save")};
+	$self->merge($ref, 'id');
+}
+
+sub get {
+	$ref = shift @{$self->exec_method('location_get')};
+	$self->merge($ref, keys $ref);
+}
+
+sub search {
+	$self->{search_results} = $self->exec_method('location_search');
+}
+
+sub list_all {
+	$self->{search_results} = $self->exec_method('location_list_all');
+}

Modified: trunk/sql/upgrade/1.2-1.3.sql
===================================================================
--- trunk/sql/upgrade/1.2-1.3.sql	2007-03-08 18:28:59 UTC (rev 864)
+++ trunk/sql/upgrade/1.2-1.3.sql	2007-03-08 19:02:30 UTC (rev 865)
@@ -181,4 +181,60 @@
 END;
 $$ language plpgsql;
 
+CREATE OR REPLACE FUNCTION location_get (in_id integer) returns locations AS
+$$
+DECLARE
+	location locations%ROWTYPE;
+BEGIN
+	SELECT * INTO location FROM locations WHERE id = in_id;
+	RETURN location;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION location_search 
+(in_companyname varchar, in_address1 varchar, in_address2 varchar, 
+	in_city varchar, in_state varchar, in_zipcode varchar, 
+	in_country varchar)
+RETURNS SETOF locations
+AS
+$$
+DECLARE
+	location locations%ROWTYPE;
+BEGIN
+	FOR location IN
+		SELECT * FROM locations 
+		WHERE companyname ilike '%' || in_companyname || '%'
+			AND address1 ilike '%' || in_address1 || '%'
+			AND address2 ilike '%' || in_address2 || '%'
+			AND in_city ilike '%' || in_city || '%'
+			AND in_state ilike '%' || in_state || '%'
+			AND in_zipcode ilike '%' || in_zipcode || '%'
+			AND in_country ilike '%' || in_country || '%'
+	LOOP
+		RETURN NEXT location;
+	END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION location_list_all () RETURNS SETOF locations AS
+$$
+DECLARE 
+	location locations%ROWTYPE;
+BEGIN
+	FOR location IN
+		SELECT * FROM locations 
+		ORDER BY company_name, city, state, country
+	LOOP
+		RETURN NEXT location;
+	END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION location_delete (in_id integer) RETURNS VOID AS
+$$
+BEGIN
+	DELETE FROM locations WHERE id = in_id;
+END;
+$$ language plpgsql;
+
 COMMIT;


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