diff --git a/README.md b/README.md index eb2ab26..2599aef 100644 --- a/README.md +++ b/README.md @@ -328,18 +328,20 @@ type DeliverySummary = { type DeliveryLine = { id: number, sku: string | null, - customname: string | null, + name: string | null, + pu: number, amount: number, net: number, rebate: number, - tax: number, // tax.rate + tax: number, // manifestarticle.taxrate (also exposed as taxrate) + taxrate: number, comment: string | null, } type Delivery = DeliverySummary & { lines: DeliveryLine[] } ``` -`create` inserts header + lines in one transaction. The `number` is auto-allocated via `getnextnumberwithprefixandpadding` (`numbers` type `delivery`); supply `externalNumber` for an external (supplier) reference. `supplierId` null or a Lieferanten `entity` of the company (else `Supplier not found`). Each line requires either `sku` or `customname`. For delivery manifests, `sku` points to `articlesupplier.sku`; for quote and order manifests, `sku` points to `article.sku`. Lines are stored without FKs so manifest articles are preserved even if articles or suppliers are deleted. `amount`, `net`, `tax` (rate → `tax.ensure`); `rebate` defaults `0`. Empty/invalid `date` → `Invalid delivery`; bad line payload → `Invalid lines`. +`create` inserts header + lines in one transaction. The `number` is auto-allocated via `getnextnumberwithprefixandpadding` (`numbers` type `delivery`); supply `externalNumber` for an external (supplier) reference. `supplierId` null or a Lieferanten `entity` of the company (else `Supplier not found`). Each line requires either `sku` or `name`. For delivery manifests, `sku` points to `articlesupplier.sku`; for quote and order manifests, `sku` points to `article.sku`. Lines are stored without FKs so manifest articles are preserved even if articles or suppliers are deleted. `amount`, `net`, `tax` (rate → `tax.ensure`); `rebate` defaults `0`. Empty/invalid `date` → `Invalid delivery`; bad line payload → `Invalid lines`. `update` patches header fields that are present. If `lines` is present, replace-all lines; if omitted, leave lines unchanged. Returns full `Delivery`. diff --git a/schema-graph.dot b/schema-graph.dot index 01a6fe2..124978b 100644 --- a/schema-graph.dot +++ b/schema-graph.dot @@ -11,14 +11,14 @@ digraph schema { fontcolor="#e2e8f0"; margin=14; meta [label=<
meta
keyNVARCHAR(255)
valueNVARCHAR(MAX)
>]; customergroup [label=<
customergroup
idINT PK
company_id?INT FK
nameNVARCHAR(255)
sortINT
>]; + entity [label=<
entity
idINT PK
customergroup_idINT FK
first_name?NVARCHAR(255)
nameNVARCHAR(255)
number?NVARCHAR(100)
created_atDATETIME2
updated_atDATETIME2
>]; numbers [label=<
numbers
idINT PK
company_idINT FK
typeNVARCHAR(100)
prefixNVARCHAR(50)
paddingINT
nextINT
>]; entityaddress [label=<
entityaddress
idINT PK
entity_idINT FK
first_name?NVARCHAR(255)
name?NVARCHAR(255)
street?NVARCHAR(255)
streetnumber?NVARCHAR(50)
zip?NVARCHAR(50)
city?NVARCHAR(255)
county?NVARCHAR(255)
addresstypeNVARCHAR(50)
sortINT
>]; - entity [label=<
entity
idINT PK
customergroup_idINT FK
first_name?NVARCHAR(255)
nameNVARCHAR(255)
number?NVARCHAR(100)
created_atDATETIME2
updated_atDATETIME2
>]; companyuser [label=<
companyuser
idINT PK
company_idINT FK
google_auth_idINT FK
>]; entitycontact [label=<
entitycontact
idINT PK
entity_idINT FK
contacttypeNVARCHAR(50)
contactNVARCHAR(255)
sortINT
>]; + company [label=<
company
idINT PK
poscustomergroup_idINT FK
default_language_id?INT FK
root_category_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
nameNVARCHAR(255)
>]; syncpos [label=<
syncpos
idINT PK
company_idINT FK
paircodeNVARCHAR(50)
token?NVARCHAR(255)
>]; entityhistory [label=<
entityhistory
idINT PK
entity_idINT FK
companyuser_id?INT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; - company [label=<
company
idINT PK
poscustomergroup_idINT FK
root_category_id?INT FK
default_language_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
nameNVARCHAR(255)
>]; companysetting [label=<
companysetting
idINT PK
company_idINT FK
keyNVARCHAR(255)
valueNVARCHAR(MAX)
frontendBIT
writeonlyBIT
>]; google_auth [label=<
google_auth
idINT PK
selected_company?INT FK
emailNVARCHAR(320)
picture?NVARCHAR(2048)
picturebinary?VARBINARY(MAX)
sub?NVARCHAR(255)
created_atDATETIME2
>]; } @@ -28,47 +28,47 @@ digraph schema { fontcolor="#e2e8f0"; margin=14; language [label=<
language
idINT PK
iso639NVARCHAR(10)
>]; unittext [label=<
unittext
idINT PK
unit_idINT FK
language_idINT FK
symbolNVARCHAR(50)
nameNVARCHAR(255)
>]; - categorytext [label=<
categorytext
idINT PK
category_idINT FK
language_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; - articletext [label=<
articletext
idINT PK
article_idINT FK
language_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; + categorytext [label=<
categorytext
idINT PK
language_idINT FK
category_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; + articletext [label=<
articletext
idINT PK
language_idINT FK
article_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; } subgraph cluster_catalog { label="Catalog"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; + optionslist [label=<
optionslist
idINT PK
>]; categoryarticle [label=<
categoryarticle
idINT PK
category_idINT FK
article_idINT FK
>]; - brand [label=<
brand
idINT PK
company_idINT FK
nameNVARCHAR(255)
gsprpinfo?NVARCHAR(MAX)
>]; + optionslistarticle [label=<
optionslistarticle
idINT PK
optionslist_idINT FK
article_idINT FK
countINT
sortINT
mandatedBIT
>]; category [label=<
category
idINT PK
parent_id?INT FK
sortINT
>]; articlehistory [label=<
articlehistory
idINT PK
companyuser_id?INT FK
article_idINT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; - article [label=<
article
idINT PK
brand_id?INT FK
fatherarticle_id?INT FK
articlelist_id?INT FK
optionslist_id?INT FK
unit_idINT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
is_fatherBIT
fathersortINT
created_atDATETIME2
updated_atDATETIME2
>]; - articleean [label=<
articleean
idINT PK
article_idINT FK
eanNVARCHAR(50)
>]; + article [label=<
article
idINT PK
unit_idINT FK
optionslist_id?INT FK
fatherarticle_id?INT FK
articlelist_id?INT FK
brand_id?INT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
is_fatherBIT
fathersortINT
created_atDATETIME2
updated_atDATETIME2
>]; articlelist [label=<
articlelist
idINT PK
>]; - articlesupplier [label=<
articlesupplier
idINT PK
entity_idINT FK
article_idINT FK
price_id?INT FK
sku?NVARCHAR(100)
stock?FLOAT
puFLOAT
>]; + articleean [label=<
articleean
idINT PK
article_idINT FK
eanNVARCHAR(50)
>]; articlelistarticle [label=<
articlelistarticle
idINT PK
article_idINT FK
articlelist_idINT FK
countINT
sortINT
>]; - optionslistarticle [label=<
optionslistarticle
idINT PK
article_idINT FK
optionslist_idINT FK
countINT
sortINT
mandatedBIT
>]; - optionslist [label=<
optionslist
idINT PK
>]; + brand [label=<
brand
idINT PK
company_idINT FK
nameNVARCHAR(255)
gsprpinfo?NVARCHAR(MAX)
>]; + articlesupplier [label=<
articlesupplier
idINT PK
entity_idINT FK
article_idINT FK
price_id?INT FK
sku?NVARCHAR(100)
stock?FLOAT
puFLOAT
>]; } subgraph cluster_media { label="Media"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; + categorypic [label=<
categorypic
idINT PK
category_idINT FK
pic_idINT FK
sortINT
>]; pic [label=<
pic
idINT PK
wINT
hINT
sizeBIGINT
hashNVARCHAR(64)
thumbwINT
thumbhINT
thumbhashNVARCHAR(64)
sourceNVARCHAR(MAX)
fullbinaryVARBINARY(MAX)
thumbbinaryVARBINARY(MAX)
>]; - categorypic [label=<
categorypic
idINT PK
pic_idINT FK
category_idINT FK
sortINT
>]; - brandpic [label=<
brandpic
idINT PK
pic_idINT FK
brand_idINT FK
sortINT
>]; - articlepic [label=<
articlepic
idINT PK
pic_idINT FK
article_idINT FK
sortINT
>]; + brandpic [label=<
brandpic
idINT PK
brand_idINT FK
pic_idINT FK
sortINT
>]; + articlepic [label=<
articlepic
idINT PK
article_idINT FK
pic_idINT FK
sortINT
>]; } subgraph cluster_manifests { label="Documents"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - manifestarticle [label=<
manifestarticle
idINT PK
manifest_idINT FK
tax_idINT FK
sku?NVARCHAR(100)
customname?NVARCHAR(255)
amountFLOAT
netFLOAT
comment?NVARCHAR(MAX)
rebateFLOAT
>]; - manifest [label=<
manifest
idINT PK
entity_id?INT FK
company_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
external_number?NVARCHAR(100)
dateDATETIME2
>]; ledger [label=<
ledger
idINT PK
manifestarticle_idINT FK
transaction_typeNVARCHAR(100)
amountFLOAT
transaction_textNVARCHAR(MAX)
hash_versionINT
prev_hash?NVARCHAR(128)
>]; + manifest [label=<
manifest
idINT PK
entity_id?INT FK
company_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
external_number?NVARCHAR(100)
dateDATETIME2
>]; + manifestarticle [label=<
manifestarticle
idINT PK
manifest_idINT FK
sku?NVARCHAR(100)
name?NVARCHAR(255)
puFLOAT
amountFLOAT
netFLOAT
comment?NVARCHAR(MAX)
rebateFLOAT
taxrateDECIMAL(18,4)
>]; } subgraph cluster_commerce { label="Pricing"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - tax [label=<
tax
idINT PK
rateDECIMAL(18,4)
>]; + tax [label=<
tax
idINT PK
rateDECIMAL(18,4)
>]; price [label=<
price
idINT PK
customergroup_idINT FK
article_idINT FK
tax_idINT FK
minmultiplierDECIMAL(18,4)
netFLOAT
>]; } subgraph cluster_units { @@ -87,65 +87,64 @@ digraph schema { __legend [label=<
Legend
PKprimary key
FKforeign key
?nullable column
—FOREIGN KEY constraint
- -naming convention only, no constraint
>]; - google_auth:selected_company:sw -> company:in6:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_google_auth_selected_company", weight=3]; + google_auth:selected_company:w -> company:in7:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_google_auth_selected_company", weight=3]; category:parent_id:e -> category:id:e [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_category_parent", constraint=false]; - company:root_category_id:e -> category:in0:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_company_root_category", constraint=false, weight=1]; - company:default_language_id:e -> language:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_company_default_language", constraint=false, weight=1]; - company:taxrate:e -> tax:in2:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_company_taxrate", constraint=false, weight=1]; - company:reducedtaxrate:e -> tax:in1:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_company_reducedtaxrate", weight=3]; - company:taxfreerate:e -> tax:in0:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_company_taxfreerate", constraint=false, weight=1]; - customergroup:company_id:w -> company:in1:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_customergroup_company", weight=3]; + company:root_category_id:w -> category:in1:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_company_root_category", weight=3]; + company:default_language_id:se -> language:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_company_default_language", constraint=false, weight=1]; + company:taxrate:e -> tax:in1:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_company_taxrate", constraint=false, weight=1]; + company:reducedtaxrate:e -> tax:in0:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_company_reducedtaxrate", constraint=false, weight=1]; + company:taxfreerate:e -> tax:in2:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_company_taxfreerate", constraint=false, weight=1]; + customergroup:company_id:e -> company:in2:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_customergroup_company", weight=3]; company:poscustomergroup_id:w -> customergroup:in0:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_company_poscustomergroup", constraint=false, weight=1]; - entity:customergroup_id:w -> customergroup:in1:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_entity_customergroup", weight=3]; - entityaddress:entity_id:ne -> entity:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_entityaddress_entity", weight=3]; - entitycontact:entity_id:sw -> entity:in1:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_entitycontact_entity", weight=3]; - entityhistory:entity_id:sw -> entity:in2:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_entityhistory_entity", weight=3]; - entityhistory:companyuser_id:se -> companyuser:in0:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_entityhistory_companyuser", constraint=false, weight=1]; - unit:company_id:w -> company:in9:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_unit_company", weight=3]; - unittext:unit_id:se -> unit:in1:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_unittext_unit", weight=3]; + entity:customergroup_id:nw -> customergroup:in1:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_entity_customergroup", weight=3]; + entityaddress:entity_id:se -> entity:in1:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_entityaddress_entity", weight=3]; + entitycontact:entity_id:nw -> entity:in2:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_entitycontact_entity", weight=3]; + entityhistory:entity_id:w -> entity:in3:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_entityhistory_entity", weight=3]; + entityhistory:companyuser_id:sw -> companyuser:in0:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_entityhistory_companyuser", constraint=false, weight=1]; + unit:company_id:w -> company:in8:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_unit_company", weight=3]; + unittext:unit_id:sw -> unit:in0:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_unittext_unit", weight=3]; unittext:language_id:nw -> language:in1:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_unittext_language", constraint=false, weight=1]; - brand:company_id:w -> company:in8:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_brand_company", weight=3]; - article:unit_id:e -> unit:in0:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_article_unit", constraint=false, weight=1]; - article:brand_id:sw -> brand:in1:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_article_brand", constraint=false, weight=1]; - article:articlelist_id:sw -> articlelist:in1:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_article_articlelist", weight=3]; - article:optionslist_id:e -> optionslist:in0:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_article_optionslist", constraint=false, weight=1]; + brand:company_id:e -> company:in9:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_brand_company", weight=3]; + article:unit_id:w -> unit:in1:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_article_unit", constraint=false, weight=1]; + article:brand_id:ne -> brand:in0:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_article_brand", constraint=false, weight=1]; + article:articlelist_id:sw -> articlelist:in0:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_article_articlelist", weight=3]; + article:optionslist_id:w -> optionslist:in1:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_article_optionslist", constraint=false, weight=1]; article:fatherarticle_id:e -> article:id:e [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_article_fatherarticle", constraint=false]; - articlehistory:article_id:ne -> article:in2:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articlehistory_article", weight=3]; + articlehistory:article_id:ne -> article:in3:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articlehistory_article", weight=3]; articlehistory:companyuser_id:w -> companyuser:in1:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_articlehistory_companyuser", constraint=false, weight=1]; - articleean:article_id:se -> article:in4:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_articleean_article", weight=3]; - articlepic:article_id:e -> article:in0:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_articlepic_article", weight=3]; - articlepic:pic_id:w -> pic:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_articlepic_pic", constraint=false, weight=1]; - brandpic:brand_id:se -> brand:in0:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_brandpic_brand", weight=3]; - brandpic:pic_id:nw -> pic:in2:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_brandpic_pic", constraint=false, weight=1]; - articlelistarticle:articlelist_id:sw -> articlelist:in0:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articlelistarticle_articlelist", weight=3]; - articlelistarticle:article_id:w -> article:in6:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_articlelistarticle_article", constraint=false, weight=1]; - optionslistarticle:optionslist_id:se -> optionslist:in1:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_optionslistarticle_optionslist", weight=3]; - optionslistarticle:article_id:sw -> article:in7:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_optionslistarticle_article", constraint=false, weight=1]; + articleean:article_id:sw -> article:in6:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_articleean_article", weight=3]; + articlepic:article_id:e -> article:in9:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_articlepic_article", weight=3]; + articlepic:pic_id:w -> pic:in2:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_articlepic_pic", constraint=false, weight=1]; + brandpic:brand_id:e -> brand:in1:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_brandpic_brand", weight=3]; + brandpic:pic_id:nw -> pic:in1:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_brandpic_pic", constraint=false, weight=1]; + articlelistarticle:articlelist_id:sw -> articlelist:in1:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articlelistarticle_articlelist", weight=3]; + articlelistarticle:article_id:w -> article:in8:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_articlelistarticle_article", constraint=false, weight=1]; + optionslistarticle:optionslist_id:sw -> optionslist:in0:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_optionslistarticle_optionslist", weight=3]; + optionslistarticle:article_id:se -> article:in2:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_optionslistarticle_article", constraint=false, weight=1]; categoryarticle:category_id:se -> category:in3:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_categoryarticle_category", weight=3]; - categoryarticle:article_id:se -> article:in1:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_categoryarticle_article", constraint=false, weight=1]; - categorypic:category_id:e -> category:in2:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_categorypic_category", weight=3]; - categorypic:pic_id:e -> pic:in1:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_categorypic_pic", constraint=false, weight=1]; - categorytext:category_id:w -> category:in5:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_categorytext_category", weight=3]; - categorytext:language_id:w -> language:in2:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_categorytext_language", constraint=false, weight=1]; - articletext:article_id:e -> article:in8:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_articletext_article", weight=3]; - articletext:language_id:w -> language:in3:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_articletext_language", constraint=false, weight=1]; - price:tax_id:se -> tax:in4:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_price_tax", constraint=false, weight=1]; - price:article_id:w -> article:in9:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_price_article", weight=3]; - price:customergroup_id:w -> customergroup:in2:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_price_customergroup", constraint=false, weight=1]; - articlesupplier:article_id:nw -> article:in5:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_articlesupplier_article", weight=3]; + categoryarticle:article_id:ne -> article:in0:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_categoryarticle_article", constraint=false, weight=1]; + categorypic:category_id:e -> category:in5:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_categorypic_category", weight=3]; + categorypic:pic_id:nw -> pic:in0:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_categorypic_pic", constraint=false, weight=1]; + categorytext:category_id:se -> category:in2:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_categorytext_category", weight=3]; + categorytext:language_id:nw -> language:in3:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_categorytext_language", constraint=false, weight=1]; + articletext:article_id:w -> article:in1:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_articletext_article", weight=3]; + articletext:language_id:w -> language:in2:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_articletext_language", constraint=false, weight=1]; + price:tax_id:w -> tax:in3:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_price_tax", constraint=false, weight=1]; + price:article_id:e -> article:in7:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_price_article", weight=3]; + price:customergroup_id:e -> customergroup:in2:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_price_customergroup", constraint=false, weight=1]; + articlesupplier:article_id:sw -> article:in5:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_articlesupplier_article", weight=3]; articlesupplier:entity_id:w -> entity:in4:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_articlesupplier_entity", constraint=false, weight=1]; articlesupplier:price_id:e -> price:in0:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articlesupplier_price", constraint=false, weight=1]; - manifest:company_id:w -> company:in7:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_manifest_company", weight=3]; - manifest:entity_id:w -> entity:in3:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_manifest_entity", constraint=false, weight=1]; + manifest:company_id:e -> company:in1:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_manifest_company", weight=3]; + manifest:entity_id:ne -> entity:in0:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_manifest_entity", constraint=false, weight=1]; manifestarticle:manifest_id:sw -> manifest:in0:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_manifestarticle_manifest", weight=3]; - manifestarticle:tax_id:e -> tax:in3:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_manifestarticle_tax", constraint=false, weight=1]; - ledger:manifestarticle_id:sw -> manifestarticle:in0:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_ledger_manifestarticle", weight=3]; - numbers:company_id:e -> company:in2:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_numbers_company", weight=3]; - companyuser:google_auth_id:e -> google_auth:in0:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_companyuser_google_auth", constraint=false, weight=1]; - companyuser:company_id:w -> company:in3:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_companyuser_company", weight=3]; - syncpos:company_id:ne -> company:in4:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_syncpos_company", weight=3]; - companysetting:company_id:sw -> company:in5:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_companysetting_company", weight=3]; - posterminal:company_id:e -> company:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_posterminal_company", weight=3]; - posterminalcategory:posterminal_id:sw -> posterminal:in0:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_posterminalcategory_posterminal", weight=3]; - posterminalcategory:category_id:e -> category:in1:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_posterminalcategory_category", constraint=false, weight=1]; + ledger:manifestarticle_id:se -> manifestarticle:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_ledger_manifestarticle", weight=3]; + numbers:company_id:w -> company:in3:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_numbers_company", weight=3]; + companyuser:google_auth_id:e -> google_auth:in0:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_companyuser_google_auth", constraint=false, weight=1]; + companyuser:company_id:se -> company:in4:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_companyuser_company", weight=3]; + syncpos:company_id:nw -> company:in5:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_syncpos_company", weight=3]; + companysetting:company_id:sw -> company:in6:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_companysetting_company", weight=3]; + posterminal:company_id:e -> company:in0:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_posterminal_company", weight=3]; + posterminalcategory:posterminal_id:sw -> posterminal:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_posterminalcategory_posterminal", weight=3]; + posterminalcategory:category_id:e -> category:in0:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_posterminalcategory_category", constraint=false, weight=1]; } \ No newline at end of file diff --git a/schema-graph.svg b/schema-graph.svg index c5a5538..29e6489 100644 --- a/schema-graph.svg +++ b/schema-graph.svg @@ -1,522 +1,439 @@ - - - + + schema - + cluster_identity - -Identity & Company + +Identity & Company cluster_i18n - -Localization + +Localization cluster_catalog - -Catalog + +Catalog cluster_media - -Media + +Media cluster_manifests - -Documents + +Documents cluster_commerce - -Pricing + +Pricing cluster_units - -Units + +Units cluster_pos - -POS + +POS meta - - -meta - - -key -NVARCHAR(255) - - -value -NVARCHAR(MAX) + + +meta + + +key +NVARCHAR(255) + + +value +NVARCHAR(MAX) customergroup - - - - - -customergroup - - -id -INT -PK - - -company_id -? -INT -FK - - -name -NVARCHAR(255) - - -sort -INT + + + + + +customergroup + + +id +INT +PK + + +company_id +? +INT +FK + + +name +NVARCHAR(255) + + +sort +INT - + company - - - - - - - - - - - - -company - - -id -INT -PK - - -poscustomergroup_id -INT -FK - - -root_category_id -? -INT -FK - - -default_language_id -? -INT -FK - - -taxrate -? -INT -FK - - -reducedtaxrate -? -INT -FK - - -taxfreerate -? -INT -FK - - -name -NVARCHAR(255) + + + + + + + + + + + + +company + + +id +INT +PK + + +poscustomergroup_id +INT +FK + + +default_language_id +? +INT +FK + + +root_category_id +? +INT +FK + + +taxrate +? +INT +FK + + +reducedtaxrate +? +INT +FK + + +taxfreerate +? +INT +FK + + +name +NVARCHAR(255) -customergroup:w->company:n +customergroup:e->company:n - - + + + + + + + +entity + + + + + + + +entity + + +id +INT +PK + + +customergroup_id +INT +FK + + +first_name? +NVARCHAR(255) + + +name +NVARCHAR(255) + + +number? +NVARCHAR(100) + + +created_at +DATETIME2 + + +updated_at +DATETIME2 + + + +entity:nw->customergroup:n + + + - + numbers - - -numbers - - -id -INT -PK - - -company_id -INT -FK - - -type -NVARCHAR(100) - - -prefix -NVARCHAR(50) - - -padding -INT - - -next -INT + + +numbers + + +id +INT +PK + + +company_id +INT +FK + + +type +NVARCHAR(100) + + +prefix +NVARCHAR(50) + + +padding +INT + + +next +INT - -numbers:e->company:n - - - + +numbers:w->company:n + + + - -entityaddress - - -entityaddress - - -id -INT -PK - - -entity_id -INT -FK - - -first_name? -NVARCHAR(255) - - -name? -NVARCHAR(255) - - -street? -NVARCHAR(255) - - -streetnumber? -NVARCHAR(50) - - -zip? -NVARCHAR(50) - - -city? -NVARCHAR(255) - - -county? -NVARCHAR(255) - - -addresstype -NVARCHAR(50) - - -sort -INT - - -entity - - - - - - - -entity - - -id -INT -PK - - -customergroup_id -INT -FK - - -first_name? -NVARCHAR(255) - - -name -NVARCHAR(255) - - -number? -NVARCHAR(100) - - -created_at -DATETIME2 - - -updated_at -DATETIME2 +entityaddress + + +entityaddress + + +id +INT +PK + + +entity_id +INT +FK + + +first_name? +NVARCHAR(255) + + +name? +NVARCHAR(255) + + +street? +NVARCHAR(255) + + +streetnumber? +NVARCHAR(50) + + +zip? +NVARCHAR(50) + + +city? +NVARCHAR(255) + + +county? +NVARCHAR(255) + + +addresstype +NVARCHAR(50) + + +sort +INT -entityaddress:ne->entity:n +entityaddress:se->entity:n - - - - - - - -entity:w->customergroup:n - - - + + companyuser - - - - -companyuser - - -id -INT -PK - - -company_id -INT -FK - - -google_auth_id -INT -FK + + + + +companyuser + + +id +INT +PK + + +company_id +INT +FK + + +google_auth_id +INT +FK - -companyuser:w->company:n - - - + +companyuser:se->company:n + + + google_auth - - - -google_auth - - -id -INT -PK - - -selected_company -? -INT -FK - - -email -NVARCHAR(320) - - -picture? -NVARCHAR(2048) - - -picturebinary? -VARBINARY(MAX) - - -sub? -NVARCHAR(255) - - -created_at -DATETIME2 + + + +google_auth + + +id +INT +PK + + +selected_company +? +INT +FK + + +email +NVARCHAR(320) + + +picture? +NVARCHAR(2048) + + +picturebinary? +VARBINARY(MAX) + + +sub? +NVARCHAR(255) + + +created_at +DATETIME2 - + companyuser:e->google_auth:n - - - + + + entitycontact - - -entitycontact - - -id -INT -PK - - -entity_id -INT -FK - - -contacttype -NVARCHAR(50) - - -contact -NVARCHAR(255) - - -sort -INT + + +entitycontact + + +id +INT +PK + + +entity_id +INT +FK + + +contacttype +NVARCHAR(50) + + +contact +NVARCHAR(255) + + +sort +INT -entitycontact:sw->entity:n +entitycontact:nw->entity:n - - - - - - - -syncpos - - -syncpos - - -id -INT -PK - - -company_id -INT -FK - - -paircode -NVARCHAR(50) - - -token? -NVARCHAR(255) - - - -syncpos:ne->company:n - - - - - - - - -entityhistory - - -entityhistory - - -id -INT -PK - - -entity_id -INT -FK - - -companyuser_id -? -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) - - - -entityhistory:sw->entity:n - - - - - - - - -entityhistory:se->companyuser:n - - - + + @@ -524,104 +441,103 @@ company:w->customergroup:n - - + + language - - - - - - -language - - -id -INT -PK - - -iso639 -NVARCHAR(10) + + + + + + +language + + +id +INT +PK + + +iso639 +NVARCHAR(10) -company:e->language:n +company:se->language:n - - + + - + category - - - - - - - - -category - - -id -INT -PK - - -parent_id -? -INT -FK - - -sort -INT + + + + + + + + +category + + +id +INT +PK + + +parent_id +? +INT +FK + + +sort +INT -company:e->category:n +company:w->category:n - - + + tax - - - - - - - -tax - - -id -INT -PK - - -rate -DECIMAL(18,4) + + + + + + +tax + + +id +INT +PK + + +rate +DECIMAL(18,4) company:e->tax:n - - + + @@ -629,8 +545,8 @@ company:e->tax:n - - + + @@ -638,405 +554,518 @@ company:e->tax:n - - + + + + + + + +syncpos + + +syncpos + + +id +INT +PK + + +company_id +INT +FK + + +paircode +NVARCHAR(50) + + +token? +NVARCHAR(255) + + + +syncpos:nw->company:n + + + + + + + + +entityhistory + + +entityhistory + + +id +INT +PK + + +entity_id +INT +FK + + +companyuser_id +? +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) + + + +entityhistory:w->entity:n + + + + + + + + +entityhistory:sw->companyuser:n + + + companysetting - - -companysetting - - -id -INT -PK - - -company_id -INT -FK - - -key -NVARCHAR(255) - - -value -NVARCHAR(MAX) - - -frontend -BIT - - -writeonly -BIT + + +companysetting + + +id +INT +PK + + +company_id +INT +FK + + +key +NVARCHAR(255) + + +value +NVARCHAR(MAX) + + +frontend +BIT + + +writeonly +BIT - + companysetting:sw->company:n - - - + + + -google_auth:sw->company:n +google_auth:w->company:n - - + + unittext - - -unittext - - -id -INT -PK - - -unit_id -INT -FK - - -language_id -INT -FK - - -symbol -NVARCHAR(50) - - -name -NVARCHAR(255) + + +unittext + + +id +INT +PK + + +unit_id +INT +FK + + +language_id +INT +FK + + +symbol +NVARCHAR(50) + + +name +NVARCHAR(255) unittext:nw->language:n - - + + unit - - - - -unit - - -id -INT -PK - - -company_id -INT -FK - - -si -NVARCHAR(50) - - -basesi -NVARCHAR(50) - - -basesifactor -FLOAT + + + + +unit + + +id +INT +PK + + +company_id +INT +FK + + +si +NVARCHAR(50) + + +basesi +NVARCHAR(50) + + +basesifactor +FLOAT -unittext:se->unit:n +unittext:sw->unit:n - - + + categorytext - - -categorytext - - -id -INT -PK - - -category_id -INT -FK - - -language_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) + + +categorytext + + +id +INT +PK + + +language_id +INT +FK + + +category_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) -categorytext:w->language:n +categorytext:nw->language:n - - + + -categorytext:w->category:n +categorytext:se->category:n - - + + articletext - - -articletext - - -id -INT -PK - - -article_id -INT -FK - - -language_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) + + +articletext + + +id +INT +PK + + +language_id +INT +FK + + +article_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) articletext:w->language:n - - + + - + article - - - - - - - - - - - - -article - - -id -INT -PK - - -brand_id -? -INT -FK - - -fatherarticle_id -? -INT -FK - - -articlelist_id -? -INT -FK - - -optionslist_id -? -INT -FK - - -unit_id -INT -FK - - -sku? -NVARCHAR(100) - - -unitamount -FLOAT - - -weight -FLOAT - - -is_father -BIT - - -fathersort -INT - - -created_at -DATETIME2 - - -updated_at -DATETIME2 + + + + + + + + + + + + +article + + +id +INT +PK + + +unit_id +INT +FK + + +optionslist_id +? +INT +FK + + +fatherarticle_id +? +INT +FK + + +articlelist_id +? +INT +FK + + +brand_id +? +INT +FK + + +sku? +NVARCHAR(100) + + +unitamount +FLOAT + + +weight +FLOAT + + +is_father +BIT + + +fathersort +INT + + +created_at +DATETIME2 + + +updated_at +DATETIME2 -articletext:e->article:n +articletext:w->article:n - - + + - + +optionslist + + + + +optionslist + + +id +INT +PK + + + categoryarticle - - -categoryarticle - - -id -INT -PK - - -category_id -INT -FK - - -article_id -INT -FK + + +categoryarticle + + +id +INT +PK + + +category_id +INT +FK + + +article_id +INT +FK categoryarticle:se->category:n - - + + -categoryarticle:se->article:n +categoryarticle:ne->article:n - - + + - - -brand - - - - -brand - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -gsprpinfo? -NVARCHAR(MAX) + + +optionslistarticle + + +optionslistarticle + + +id +INT +PK + + +optionslist_id +INT +FK + + +article_id +INT +FK + + +count +INT + + +sort +INT + + +mandated +BIT - - -brand:w->company:n - - - + + +optionslistarticle:sw->optionslist:n + + + + + + + + +optionslistarticle:se->article:n + + + @@ -1044,48 +1073,48 @@ category:e->category:e - - + + - + articlehistory - - -articlehistory - - -id -INT -PK - - -companyuser_id -? -INT -FK - - -article_id -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) + + +articlehistory + + +id +INT +PK + + +companyuser_id +? +INT +FK + + +article_id +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) articlehistory:w->companyuser:n - - + + @@ -1093,17 +1122,17 @@ articlehistory:ne->article:n - - + + - - -article:sw->brand:n - - - + + +article:w->optionslist:n + + + @@ -1111,235 +1140,145 @@ article:e->article:e - - + + articlelist - - - - -articlelist - - -id -INT -PK + + + + +articlelist + + +id +INT +PK article:sw->articlelist:n - - + + - - -optionslist - - - - -optionslist - - -id -INT -PK + + +brand + + + + +brand + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +gsprpinfo? +NVARCHAR(MAX) - - -article:e->optionslist:n - - - + + +article:ne->brand:n + + + -article:e->unit:n +article:w->unit:n - - + + - + articleean - - -articleean - - -id -INT -PK - - -article_id -INT -FK - - -ean -NVARCHAR(50) + + +articleean + + +id +INT +PK + + +article_id +INT +FK + + +ean +NVARCHAR(50) -articleean:se->article:n +articleean:sw->article:n - - - - - - - -articlesupplier - - -articlesupplier - - -id -INT -PK - - -entity_id -INT -FK - - -article_id -INT -FK - - -price_id -? -INT -FK - - -sku? -NVARCHAR(100) - - -stock? -FLOAT - - -pu -FLOAT - - - -articlesupplier:w->entity:n - - - - - - - - -articlesupplier:nw->article:n - - - - - - - - -price - - - -price - - -id -INT -PK - - -customergroup_id -INT -FK - - -article_id -INT -FK - - -tax_id -INT -FK - - -minmultiplier -DECIMAL(18,4) - - -net -FLOAT - - - -articlesupplier:e->price:n - - - + + articlelistarticle - - -articlelistarticle - - -id -INT -PK - - -article_id -INT -FK - - -articlelist_id -INT -FK - - -count -INT - - -sort -INT + + +articlelistarticle + + +id +INT +PK + + +article_id +INT +FK + + +articlelist_id +INT +FK + + +count +INT + + +sort +INT articlelistarticle:w->article:n - - + + @@ -1347,194 +1286,254 @@ articlelistarticle:sw->articlelist:n - - + + - - -optionslistarticle - - -optionslistarticle - - -id -INT -PK - - -article_id -INT -FK - - -optionslist_id -INT -FK - - -count -INT - - -sort -INT - - -mandated -BIT - - - -optionslistarticle:sw->article:n - - - + + +brand:e->company:n + + + - - -optionslistarticle:se->optionslist:n - - - + + +articlesupplier + + +articlesupplier + + +id +INT +PK + + +entity_id +INT +FK + + +article_id +INT +FK + + +price_id +? +INT +FK + + +sku? +NVARCHAR(100) + + +stock? +FLOAT + + +pu +FLOAT + + + +articlesupplier:w->entity:n + + + - - -pic - - - - - -pic - - -id -INT -PK - - -w -INT - - -h -INT - - -size -BIGINT - - -hash -NVARCHAR(64) - - -thumbw -INT - - -thumbh -INT - - -thumbhash -NVARCHAR(64) - - -source -NVARCHAR(MAX) - - -fullbinary -VARBINARY(MAX) - - -thumbbinary -VARBINARY(MAX) + + +articlesupplier:sw->article:n + + + + + + + + +price + + + +price + + +id +INT +PK + + +customergroup_id +INT +FK + + +article_id +INT +FK + + +tax_id +INT +FK + + +minmultiplier +DECIMAL(18,4) + + +net +FLOAT + + + +articlesupplier:e->price:n + + + + + - + categorypic - - -categorypic - - -id -INT -PK - - -pic_id -INT -FK - - -category_id -INT -FK - - -sort -INT + + +categorypic + + +id +INT +PK + + +category_id +INT +FK + + +pic_id +INT +FK + + +sort +INT categorypic:e->category:n - - + + + + +pic + + + + + +pic + + +id +INT +PK + + +w +INT + + +h +INT + + +size +BIGINT + + +hash +NVARCHAR(64) + + +thumbw +INT + + +thumbh +INT + + +thumbhash +NVARCHAR(64) + + +source +NVARCHAR(MAX) + + +fullbinary +VARBINARY(MAX) + + +thumbbinary +VARBINARY(MAX) + -categorypic:e->pic:n +categorypic:nw->pic:n - - + + brandpic - - -brandpic - - -id -INT -PK - - -pic_id -INT -FK - - -brand_id -INT -FK - - -sort -INT + + +brandpic + + +id +INT +PK + + +brand_id +INT +FK + + +pic_id +INT +FK + + +sort +INT -brandpic:se->brand:n +brandpic:e->brand:n - - + + @@ -1542,43 +1541,43 @@ brandpic:nw->pic:n - - + + articlepic - - -articlepic - - -id -INT -PK - - -pic_id -INT -FK - - -article_id -INT -FK - - -sort -INT + + +articlepic + + +id +INT +PK + + +article_id +INT +FK + + +pic_id +INT +FK + + +sort +INT articlepic:e->article:n - - + + @@ -1586,204 +1585,198 @@ articlepic:w->pic:n - - + + - + +ledger + + +ledger + + +id +INT +PK + + +manifestarticle_id +INT +FK + + +transaction_type +NVARCHAR(100) + + +amount +FLOAT + + +transaction_text +NVARCHAR(MAX) + + +hash_version +INT + + +prev_hash? +NVARCHAR(128) + + + manifestarticle - - - -manifestarticle - - -id -INT -PK - - -manifest_id -INT -FK - - -tax_id -INT -FK - - -sku? -NVARCHAR(100) - - -customname? -NVARCHAR(255) - - -amount -FLOAT - - -net -FLOAT - - -comment? -NVARCHAR(MAX) - - -rebate -FLOAT + + + +manifestarticle + + +id +INT +PK + + +manifest_id +INT +FK + + +sku? +NVARCHAR(100) + + +name? +NVARCHAR(255) + + +pu +FLOAT + + +amount +FLOAT + + +net +FLOAT + + +comment? +NVARCHAR(MAX) + + +rebate +FLOAT + + +taxrate +DECIMAL(18,4) + + + +ledger:se->manifestarticle:n + + + + + manifest - - - -manifest - - -id -INT -PK - - -entity_id -? -INT -FK - - -company_id -INT -FK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -external_number? -NVARCHAR(100) - - -date -DATETIME2 - - - -manifestarticle:sw->manifest:n - - - - - - - - -manifestarticle:e->tax:n - - - - - + + + +manifest + + +id +INT +PK + + +entity_id +? +INT +FK + + +company_id +INT +FK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +external_number? +NVARCHAR(100) + + +date +DATETIME2 -manifest:w->entity:n +manifest:ne->entity:n - - + + -manifest:w->company:n +manifest:e->company:n - - + + - - -ledger - - -ledger - - -id -INT -PK - - -manifestarticle_id -INT -FK - - -transaction_type -NVARCHAR(100) - - -amount -FLOAT - - -transaction_text -NVARCHAR(MAX) - - -hash_version -INT - - -prev_hash? -NVARCHAR(128) - - - -ledger:sw->manifestarticle:n - - - + + +manifestarticle:sw->manifest:n + + + -price:w->customergroup:n +price:e->customergroup:n - - + + -price:w->article:n +price:e->article:n - - + + -price:se->tax:n +price:w->tax:n - - + + @@ -1791,117 +1784,117 @@ unit:w->company:n - - + + posterminal - - - -posterminal + + + +posterminal + + +id +INT +PK -id -INT -PK - +company_id +INT +FK + -company_id -INT -FK - +name +NVARCHAR(255) + -name +token? NVARCHAR(255) - + -token? -NVARCHAR(255) - - -pairingpin -NVARCHAR(50) +pairingpin +NVARCHAR(50) - + posterminal:e->company:n - - - + + + posterminalcategory - - -posterminalcategory + + +posterminalcategory + + +id +INT +PK -id -INT -PK +posterminal_id +INT +FK -posterminal_id +category_id INT FK - - -category_id -INT -FK - + posterminalcategory:e->category:n - - - + + + - + posterminalcategory:sw->posterminal:n - - - + + + __legend - - - -Legend - -PK - -primary key - -FK - -foreign key - -? - -nullable column - -— - -FOREIGN KEY constraint - -- - - -naming convention only, no constraint + + + +Legend + +PK + +primary key + +FK + +foreign key + +? + +nullable column + +— + +FOREIGN KEY constraint + +- - + +naming convention only, no constraint diff --git a/src/schema.js b/src/schema.js index e8e391f..43f09aa 100644 --- a/src/schema.js +++ b/src/schema.js @@ -573,14 +573,14 @@ BEGIN id INT IDENTITY(1,1) PRIMARY KEY, manifest_id INT NOT NULL, sku NVARCHAR(100) NULL, - customname NVARCHAR(255) NULL, + name NVARCHAR(255) NULL, + pu FLOAT NOT NULL CONSTRAINT DF_manifestarticle_pu DEFAULT 1, amount FLOAT NOT NULL, net FLOAT NOT NULL, comment NVARCHAR(MAX) NULL, rebate FLOAT NOT NULL CONSTRAINT DF_manifestarticle_rebate DEFAULT 0, - tax_id INT NOT NULL, - CONSTRAINT FK_manifestarticle_manifest FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE, - CONSTRAINT FK_manifestarticle_tax FOREIGN KEY (tax_id) REFERENCES tax(id) ON DELETE CASCADE + taxrate DECIMAL(18,4) NOT NULL CONSTRAINT DF_manifestarticle_taxrate DEFAULT 0, + CONSTRAINT FK_manifestarticle_manifest FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE ); END `; diff --git a/src/sql/delivery.js b/src/sql/delivery.js index bd677cb..10a1de5 100644 --- a/src/sql/delivery.js +++ b/src/sql/delivery.js @@ -32,14 +32,15 @@ export const GET_DELIVERY_LINES = ` SELECT ma.id, ma.sku, - ma.customname, + ma.name, + ma.pu, ma.amount, ma.net, ma.rebate, - t.rate AS tax, + ma.taxrate AS tax, + ma.taxrate, ma.comment FROM manifestarticle ma -INNER JOIN tax t ON t.id = ma.tax_id WHERE ma.manifest_id = @manifestId ORDER BY ma.id `; @@ -78,22 +79,24 @@ export const CREATE_LINE = ` INSERT INTO manifestarticle ( manifest_id, sku, - customname, + name, + pu, amount, net, comment, rebate, - tax_id + taxrate ) OUTPUT INSERTED.id VALUES ( @manifestId, @sku, - @customname, + @name, + @pu, @amount, @net, @comment, @rebate, - @taxId + @taxrate ) `; diff --git a/src/sql/manifestDoc.js b/src/sql/manifestDoc.js index 163d0ab..e7573ab 100644 --- a/src/sql/manifestDoc.js +++ b/src/sql/manifestDoc.js @@ -38,14 +38,15 @@ export const GET_MANIFEST_LINES = ` SELECT ma.id, ma.sku, - ma.customname, + ma.name, + ma.pu, ma.amount, ma.net, ma.rebate, - t.rate AS tax, + ma.taxrate AS tax, + ma.taxrate, ma.comment FROM manifestarticle ma -INNER JOIN tax t ON t.id = ma.tax_id WHERE ma.manifest_id = @manifestId ORDER BY ma.id `; @@ -84,22 +85,24 @@ export const CREATE_LINE = ` INSERT INTO manifestarticle ( manifest_id, sku, - customname, + name, + pu, amount, net, comment, rebate, - tax_id + taxrate ) OUTPUT INSERTED.id VALUES ( @manifestId, @sku, - @customname, + @name, + @pu, @amount, @net, @comment, @rebate, - @taxId + @taxrate ) `; diff --git a/src/store/manifestLines.js b/src/store/manifestLines.js index 9eae6e0..5d573c1 100644 --- a/src/store/manifestLines.js +++ b/src/store/manifestLines.js @@ -5,7 +5,7 @@ import request from './request.js'; * Normalizes and validates an array of manifest line inputs. * * @param {Array} lines - The raw line inputs. - * @returns {Array<{sku: string|null, customname: string|null, amount: number, net: number, rebate: number, tax: number, comment: string|null}>} The normalized lines. + * @returns {Array<{sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, tax: number, comment: string|null}>} The normalized lines. * @throws {Error} If the lines are invalid. */ export function normalizeLines(lines) { @@ -15,25 +15,35 @@ export function normalizeLines(lines) { return lines.map((entry) => { const sku = entry?.sku?.trim?.() ? entry.sku.trim() : null; - const customname = - entry?.customname?.trim?.() ? entry.customname.trim() : null; + const name = + entry?.name?.trim?.() + ? entry.name.trim() + : entry?.customname?.trim?.() + ? entry.customname.trim() + : null; - // Must have either an SKU or a custom name. - if (!sku && !customname) { + // Must have either an SKU or a name. + if (!sku && !name) { throw new Error('Invalid lines'); } + const pu = + entry?.pu === undefined || entry?.pu === null ? 1 : entry.pu; const amount = entry?.amount; const net = entry?.net; const rebate = entry?.rebate === undefined || entry?.rebate === null ? 0 : entry.rebate; - const tax = entry?.tax; + const tax = + entry?.taxrate !== undefined && entry?.taxrate !== null + ? entry.taxrate + : entry?.tax; const comment = entry?.comment === undefined || entry?.comment === null ? null : String(entry.comment); if ( + !Number.isFinite(pu) || !Number.isFinite(amount) || !Number.isFinite(net) || !Number.isFinite(rebate) || @@ -42,7 +52,7 @@ export function normalizeLines(lines) { throw new Error('Invalid lines'); } - return { sku, customname, amount, net, rebate, tax, comment }; + return { sku, name, pu, amount, net, rebate, tax, comment }; }); } @@ -72,28 +82,31 @@ export function parseDate(value) { * @returns {object} The shaped line. */ export function shapeLine(row) { + const tax = row.taxrate !== undefined ? Number(row.taxrate) : Number(row.tax); return { id: row.id, sku: row.sku ?? null, - customname: row.customname ?? null, + name: row.name ?? null, + pu: row.pu !== undefined && row.pu !== null ? Number(row.pu) : 1, amount: row.amount, net: row.net, rebate: row.rebate, - tax: row.tax, + tax, + taxrate: tax, comment: row.comment ?? null, }; } /** - * Inserts manifest lines for a document, storing each SKU directly - * and ensuring the tax rate. + * Inserts manifest lines for a document, storing each SKU and taxrate directly, + * and ensuring the tax rate exists in the tax catalog. * * @param {object} pool - The mssql connection pool. * @param {object} tx - The transaction. * @param {object} params - The insert parameters. * @param {number} params.manifestId - The manifest id. * @param {Array} params.lines - The normalized lines. - * @param {Function} params.ensureTax - The tax ensure function. + * @param {Function} [params.ensureTax] - The tax ensure function. * @returns {Promise} */ export async function insertLines( @@ -102,17 +115,20 @@ export async function insertLines( { manifestId, lines, ensureTax }, ) { for (const line of lines) { - const taxId = await ensureTax(line.tax, tx); + if (ensureTax) { + await ensureTax(line.tax, tx); + } await request(pool, tx) .input('manifestId', manifestId) .input('sku', line.sku ?? null) - .input('customname', line.customname ?? null) + .input('name', line.name ?? null) + .input('pu', line.pu ?? 1) .input('amount', line.amount) .input('net', line.net) .input('comment', line.comment) .input('rebate', line.rebate) - .input('taxId', taxId) + .input('taxrate', line.tax) .query(CREATE_LINE); } }