147 lines
3.7 KiB
Typst
147 lines
3.7 KiB
Typst
// ==========================================
|
|
// DOMAIN: ПРОФИЛЬ ОРГАНИЗАЦИИ
|
|
// ==========================================
|
|
#import "document.typ": fail, ensure-dictionary
|
|
|
|
#let optional-text(value) = {
|
|
if value == none {
|
|
none
|
|
} else if type(value) != str {
|
|
value
|
|
} else if value.trim() == "" {
|
|
none
|
|
} else {
|
|
value
|
|
}
|
|
}
|
|
|
|
#let fill-defaults(defaults, values) = {
|
|
let result = defaults
|
|
for (key, value) in values {
|
|
result.insert(key, optional-text(value))
|
|
}
|
|
result
|
|
}
|
|
|
|
#let company-profile(
|
|
id,
|
|
legal,
|
|
contacts: (:),
|
|
banking: (:),
|
|
brand: (:),
|
|
director: (:),
|
|
resources: (:),
|
|
) = {
|
|
if type(id) != str or id.trim() == "" {
|
|
fail("company.id", "нужна непустая строка")
|
|
}
|
|
let legal = fill-defaults(
|
|
(
|
|
name: none,
|
|
short-name: none,
|
|
jurisdiction: none,
|
|
inn: none,
|
|
kpp: none,
|
|
ogrn: none,
|
|
bin: none,
|
|
kbe: none,
|
|
),
|
|
ensure-dictionary(legal, "company.legal"),
|
|
)
|
|
let contacts = fill-defaults(
|
|
(
|
|
email: none,
|
|
website: none,
|
|
phone: none,
|
|
address: none,
|
|
address-en: none,
|
|
city: none,
|
|
summary: none,
|
|
),
|
|
ensure-dictionary(contacts, "company.contacts"),
|
|
)
|
|
let banking = fill-defaults(
|
|
(
|
|
bank: none,
|
|
account: none,
|
|
correspondent-account: none,
|
|
bik: none,
|
|
iban: none,
|
|
),
|
|
ensure-dictionary(banking, "company.banking"),
|
|
)
|
|
let brand = fill-defaults(
|
|
(color: rgb("e39f49"),),
|
|
ensure-dictionary(brand, "company.brand"),
|
|
)
|
|
let director = fill-defaults(
|
|
(title: none, name: none),
|
|
ensure-dictionary(director, "company.director"),
|
|
)
|
|
let resources = fill-defaults(
|
|
(logo: none, signature: none, stamp: none),
|
|
ensure-dictionary(resources, "company.resources"),
|
|
)
|
|
|
|
let profile = (
|
|
kind: "company-profile",
|
|
id: id,
|
|
legal: legal,
|
|
contacts: contacts,
|
|
banking: banking,
|
|
brand: brand,
|
|
director: director,
|
|
resources: resources,
|
|
)
|
|
profile
|
|
}
|
|
|
|
#let validate-company(profile) = {
|
|
let profile = ensure-dictionary(profile, "company")
|
|
if profile.at("kind", default: none) != "company-profile" {
|
|
fail("company.kind", "ожидался company-profile")
|
|
}
|
|
for key in ("legal", "contacts", "banking", "brand", "director", "resources") {
|
|
if key not in profile or type(profile.at(key)) != dictionary {
|
|
fail("company." + key, "ожидался dictionary")
|
|
}
|
|
}
|
|
let name = profile.legal.at("name", default: none)
|
|
if type(name) != str or name.trim() == "" {
|
|
fail("company.legal.name", "полное наименование обязательно")
|
|
}
|
|
let jurisdiction = profile.legal.at("jurisdiction", default: none)
|
|
if type(jurisdiction) != str or jurisdiction.trim() == "" {
|
|
fail("company.legal.jurisdiction", "юрисдикция обязательна")
|
|
}
|
|
for key in ("title", "name") {
|
|
let value = profile.director.at(key, default: none)
|
|
if type(value) != str or value.trim() == "" {
|
|
fail("company.director." + key, "поле обязательно")
|
|
}
|
|
}
|
|
if type(profile.brand.color) != color {
|
|
fail("company.brand.color", "ожидался color")
|
|
}
|
|
for key in ("logo", "signature", "stamp") {
|
|
let resource = profile.resources.at(key, default: none)
|
|
if resource != none and type(resource) not in (path, content) {
|
|
fail("company.resources." + key, "ожидались none, path или content")
|
|
}
|
|
}
|
|
profile
|
|
}
|
|
|
|
#let company-display-name(profile, short: false) = {
|
|
let profile = validate-company(profile)
|
|
if short {
|
|
profile.legal.at("short-name", default: profile.legal.name)
|
|
} else {
|
|
profile.legal.name
|
|
}
|
|
}
|
|
|
|
#let company-resource(profile, key) = {
|
|
validate-company(profile).resources.at(key, default: none)
|
|
}
|