Add ledger, address/contact sort, and tighter schema-graph layout.
Replace manifestarticle.transactedamount with an append-only ledger, add sort on entity address/contact, and allow same-rank FKs with crossing-aware exits in the graph.
This commit is contained in:
@@ -33,7 +33,6 @@ SELECT
|
||||
a.sku,
|
||||
ma.amount,
|
||||
ma.net,
|
||||
ma.transactedamount AS transactedAmount,
|
||||
ma.rebate,
|
||||
t.rate AS tax,
|
||||
ma.comment
|
||||
@@ -79,7 +78,6 @@ INSERT INTO manifestarticle (
|
||||
article_id,
|
||||
amount,
|
||||
net,
|
||||
transactedamount,
|
||||
comment,
|
||||
rebate,
|
||||
tax_id
|
||||
@@ -90,7 +88,6 @@ VALUES (
|
||||
@articleId,
|
||||
@amount,
|
||||
@net,
|
||||
@transactedAmount,
|
||||
@comment,
|
||||
@rebate,
|
||||
@taxId
|
||||
|
||||
@@ -8,7 +8,8 @@ export const ADDRESS_COLUMNS = `
|
||||
zip,
|
||||
city,
|
||||
county,
|
||||
addresstype AS addressType
|
||||
addresstype AS addressType,
|
||||
sort
|
||||
`;
|
||||
|
||||
export const LIST_BY_ENTITY = `
|
||||
@@ -16,7 +17,7 @@ SELECT
|
||||
${ADDRESS_COLUMNS}
|
||||
FROM entityaddress
|
||||
WHERE entity_id = @entityId
|
||||
ORDER BY id
|
||||
ORDER BY sort ASC, id ASC
|
||||
`;
|
||||
|
||||
export const GET_BY_ENTITY_AND_ID = `
|
||||
@@ -26,6 +27,12 @@ FROM entityaddress
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM entityaddress
|
||||
WHERE entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO entityaddress (
|
||||
entity_id,
|
||||
@@ -36,7 +43,8 @@ INSERT INTO entityaddress (
|
||||
zip,
|
||||
city,
|
||||
county,
|
||||
addresstype
|
||||
addresstype,
|
||||
sort
|
||||
)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
@@ -48,7 +56,8 @@ OUTPUT
|
||||
INSERTED.zip,
|
||||
INSERTED.city,
|
||||
INSERTED.county,
|
||||
INSERTED.addresstype AS addressType
|
||||
INSERTED.addresstype AS addressType,
|
||||
INSERTED.sort
|
||||
VALUES (
|
||||
@entityId,
|
||||
@firstName,
|
||||
@@ -58,7 +67,8 @@ VALUES (
|
||||
@zip,
|
||||
@city,
|
||||
@county,
|
||||
@addressType
|
||||
@addressType,
|
||||
@sort
|
||||
)
|
||||
`;
|
||||
|
||||
@@ -72,7 +82,8 @@ SET
|
||||
zip = @zip,
|
||||
city = @city,
|
||||
county = @county,
|
||||
addresstype = @addressType
|
||||
addresstype = @addressType,
|
||||
sort = @sort
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
@@ -83,7 +94,8 @@ OUTPUT
|
||||
INSERTED.zip,
|
||||
INSERTED.city,
|
||||
INSERTED.county,
|
||||
INSERTED.addresstype AS addressType
|
||||
INSERTED.addresstype AS addressType,
|
||||
INSERTED.sort
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ export const CONTACT_COLUMNS = `
|
||||
id,
|
||||
entity_id AS entityId,
|
||||
contacttype AS contactType,
|
||||
contact
|
||||
contact,
|
||||
sort
|
||||
`;
|
||||
|
||||
export const LIST_BY_ENTITY = `
|
||||
@@ -10,7 +11,7 @@ SELECT
|
||||
${CONTACT_COLUMNS}
|
||||
FROM entitycontact
|
||||
WHERE entity_id = @entityId
|
||||
ORDER BY id
|
||||
ORDER BY sort ASC, id ASC
|
||||
`;
|
||||
|
||||
export const GET_BY_ENTITY_AND_ID = `
|
||||
@@ -20,24 +21,32 @@ FROM entitycontact
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM entitycontact
|
||||
WHERE entity_id = @entityId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO entitycontact (entity_id, contacttype, contact)
|
||||
INSERT INTO entitycontact (entity_id, contacttype, contact, sort)
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.contacttype AS contactType,
|
||||
INSERTED.contact
|
||||
VALUES (@entityId, @contactType, @contact)
|
||||
INSERTED.contact,
|
||||
INSERTED.sort
|
||||
VALUES (@entityId, @contactType, @contact, @sort)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE entitycontact
|
||||
SET contacttype = @contactType, contact = @contact
|
||||
SET contacttype = @contactType, contact = @contact, sort = @sort
|
||||
OUTPUT
|
||||
INSERTED.id,
|
||||
INSERTED.entity_id AS entityId,
|
||||
INSERTED.contacttype AS contactType,
|
||||
INSERTED.contact
|
||||
INSERTED.contact,
|
||||
INSERTED.sort
|
||||
WHERE id = @id AND entity_id = @entityId
|
||||
`;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export const TABLES = [
|
||||
'posterminalcategory',
|
||||
'posterminal',
|
||||
'numbers',
|
||||
'ledger',
|
||||
'manifestarticle',
|
||||
'manifest',
|
||||
'price',
|
||||
|
||||
Reference in New Issue
Block a user