summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-10 21:16:16 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-10 21:16:16 +0000
commit601652599b9a439c3bf3c4b2b25534ca88f9ca59 (patch)
tree4a25bf2dbb94747ff1ad561c386ea8f08a46d01d /sql
parent47025e9f26cf3f037841dcae5b281fc38f5051ba (diff)
Fixes Add Vendor, to correctly work with the new entity_credit_account table, in place of the customer/vendor tables.
Removes the Vendor and Customer tables, replacing them with entity_credit_account (previously entity_metadata) and Vendor and Customer as a view, mimicking the original Vendor and Customer tables. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1373 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql')
-rw-r--r--sql/Pg-database.sql110
1 files changed, 76 insertions, 34 deletions
diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql
index 9cb6c87f..a5cb9e31 100644
--- a/sql/Pg-database.sql
+++ b/sql/Pg-database.sql
@@ -324,21 +324,18 @@ ALTER TABLE invoice_note ADD FOREIGN KEY (ref_key) REFERENCES invoice(id);
--
--
-CREATE TABLE customer (
- id serial PRIMARY KEY,
- entity_id int references entity(id),
+
+CREATE TABLE entity_credit_account (
+ entity_id int not null references entity(id),
+ entity_class int not null references entity_class(id) check ( entity_class in (1,2) ),
discount numeric,
taxincluded bool default 'f',
creditlimit NUMERIC default 0,
terms int2 default 0,
- customernumber varchar(32),
+ meta_number varchar(32),
cc text,
bcc text,
business_id int,
- invoice_notes text,
- sic_code varchar(6),
- iban varchar(34),
- bic varchar(11),
language_code varchar(6),
pricegroup_id int,
curr char(3),
@@ -346,9 +343,78 @@ CREATE TABLE customer (
enddate date
);
-COMMENT ON TABLE customer IS $$ This is now a metadata table that holds information specific to customers. Source info is not part of the entity management $$;
-COMMENT ON COLUMN customer.entity_id IS $$ This is the relationship between entities and customers $$;
+CREATE TABLE entity_bank_account (
+ id serial not null,
+ entity_id int references entity(id) not null,
+ bic varchar,
+ iban varchar,
+ UNIQUE (id),
+ PRIMARY KEY (bic, iban)
+);
+
+CREATE TABLE entity_invoice_notes (
+ id serial not null,
+ entity_id int not null references entity(id),
+ note text,
+ unique (id)
+);
+CREATE VIEW customer AS
+ SELECT emd.entity_id,
+ emd.entity_class,
+ emd.discount,
+ emd.taxincluded,
+ emd.creditlimit,
+ emd.terms,
+ emd.meta_number as customernumber,
+ emd.cc,
+ emd.bcc,
+ emd.business_id,
+ emd.language_code,
+ emd.pricegroup_id,
+ emd.curr,
+ emd.startdate,
+ emd.enddate,
+ eba.bic,
+ eba.iban,
+ ein.note as
+ invoice_notes
+ FROM entity_credit_account emd
+ join entity_bank_account eba on emd.entity_id = eba.entity_id
+ join entity_invoice_notes ein on ein.entity_id = emd.entity_id
+ where emd.entity_class = 2;
+
+CREATE VIEW vendor AS
+ SELECT emd.entity_id,
+ emd.entity_class,
+ emd.discount,
+ emd.taxincluded,
+ emd.creditlimit,
+ emd.terms,
+ emd.meta_number as vendornumber,
+ emd.cc,
+ emd.bcc,
+ emd.business_id,
+ emd.language_code,
+ emd.pricegroup_id,
+ emd.curr,
+ emd.startdate,
+ emd.enddate,
+ eba.bic,
+ eba.iban,
+ ein.note as
+ invoice_notes
+ FROM entity_credit_account emd
+ join entity_bank_account eba on emd.entity_id = eba.entity_id
+ join entity_invoice_notes ein on ein.entity_id = emd.entity_id
+ where emd.entity_class = 1;
+
+COMMENT ON TABLE entity_metadata IS $$ This is a metadata table for ALL entities in LSMB; it deprecates the use of customer and vendor specific tables (which were nearly identical and largely redundant), and replaces it with a single point of metadata. $$;
+
+COMMENT ON COLUMN entity_metadata.entity_id IS $$ This is the relationship between entities and their metadata. $$;
+COMMENT ON COLUMN entity_metadata.entity_class IS $$ A reference to entity_class, requiring that entity_metadata only apply to vendors and customers, using the entity_class table as the Point Of Truth. $$;
+
+ALTER TABLE company ADD COLUMN sic_code varchar;
--
--
@@ -634,30 +700,6 @@ create table shipto (
-- SHIPTO really needs to be pushed into entities too
--
-CREATE TABLE vendor (
- entity_id int references entity(id) not null PRIMARY KEY,
- entity_class_id int references entity_class(id) not null check (entity_class_id = 1),
- terms int2 default 0,
- taxincluded bool default 'f',
- vendornumber varchar(32),
- cc text,
- bcc text,
- gifi_accno varchar(30),
- business_id int,
- taxnumber varchar(32),
- sic_code varchar(6),
- discount numeric,
- creditlimit numeric default 0,
- iban varchar(34),
- bic varchar(11),
- language_code varchar(6),
- pricegroup_id int,
- curr char(3),
- startdate date,
- enddate date
-);
-
-COMMENT ON TABLE vendor IS $$ Now a meta data table $$;
--
CREATE TABLE project (