| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- // ==========================================
- // 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)
- }
|