company.typ 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // ==========================================
  2. // DOMAIN: ПРОФИЛЬ ОРГАНИЗАЦИИ
  3. // ==========================================
  4. #import "document.typ": fail, ensure-dictionary
  5. #let optional-text(value) = {
  6. if value == none {
  7. none
  8. } else if type(value) != str {
  9. value
  10. } else if value.trim() == "" {
  11. none
  12. } else {
  13. value
  14. }
  15. }
  16. #let fill-defaults(defaults, values) = {
  17. let result = defaults
  18. for (key, value) in values {
  19. result.insert(key, optional-text(value))
  20. }
  21. result
  22. }
  23. #let company-profile(
  24. id,
  25. legal,
  26. contacts: (:),
  27. banking: (:),
  28. brand: (:),
  29. director: (:),
  30. resources: (:),
  31. ) = {
  32. if type(id) != str or id.trim() == "" {
  33. fail("company.id", "нужна непустая строка")
  34. }
  35. let legal = fill-defaults(
  36. (
  37. name: none,
  38. short-name: none,
  39. jurisdiction: none,
  40. inn: none,
  41. kpp: none,
  42. ogrn: none,
  43. bin: none,
  44. kbe: none,
  45. ),
  46. ensure-dictionary(legal, "company.legal"),
  47. )
  48. let contacts = fill-defaults(
  49. (
  50. email: none,
  51. website: none,
  52. phone: none,
  53. address: none,
  54. address-en: none,
  55. city: none,
  56. summary: none,
  57. ),
  58. ensure-dictionary(contacts, "company.contacts"),
  59. )
  60. let banking = fill-defaults(
  61. (
  62. bank: none,
  63. account: none,
  64. correspondent-account: none,
  65. bik: none,
  66. iban: none,
  67. ),
  68. ensure-dictionary(banking, "company.banking"),
  69. )
  70. let brand = fill-defaults(
  71. (color: rgb("e39f49"),),
  72. ensure-dictionary(brand, "company.brand"),
  73. )
  74. let director = fill-defaults(
  75. (title: none, name: none),
  76. ensure-dictionary(director, "company.director"),
  77. )
  78. let resources = fill-defaults(
  79. (logo: none, signature: none, stamp: none),
  80. ensure-dictionary(resources, "company.resources"),
  81. )
  82. let profile = (
  83. kind: "company-profile",
  84. id: id,
  85. legal: legal,
  86. contacts: contacts,
  87. banking: banking,
  88. brand: brand,
  89. director: director,
  90. resources: resources,
  91. )
  92. profile
  93. }
  94. #let validate-company(profile) = {
  95. let profile = ensure-dictionary(profile, "company")
  96. if profile.at("kind", default: none) != "company-profile" {
  97. fail("company.kind", "ожидался company-profile")
  98. }
  99. for key in ("legal", "contacts", "banking", "brand", "director", "resources") {
  100. if key not in profile or type(profile.at(key)) != dictionary {
  101. fail("company." + key, "ожидался dictionary")
  102. }
  103. }
  104. let name = profile.legal.at("name", default: none)
  105. if type(name) != str or name.trim() == "" {
  106. fail("company.legal.name", "полное наименование обязательно")
  107. }
  108. let jurisdiction = profile.legal.at("jurisdiction", default: none)
  109. if type(jurisdiction) != str or jurisdiction.trim() == "" {
  110. fail("company.legal.jurisdiction", "юрисдикция обязательна")
  111. }
  112. for key in ("title", "name") {
  113. let value = profile.director.at(key, default: none)
  114. if type(value) != str or value.trim() == "" {
  115. fail("company.director." + key, "поле обязательно")
  116. }
  117. }
  118. if type(profile.brand.color) != color {
  119. fail("company.brand.color", "ожидался color")
  120. }
  121. for key in ("logo", "signature", "stamp") {
  122. let resource = profile.resources.at(key, default: none)
  123. if resource != none and type(resource) not in (path, content) {
  124. fail("company.resources." + key, "ожидались none, path или content")
  125. }
  126. }
  127. profile
  128. }
  129. #let company-display-name(profile, short: false) = {
  130. let profile = validate-company(profile)
  131. if short {
  132. profile.legal.at("short-name", default: profile.legal.name)
  133. } else {
  134. profile.legal.name
  135. }
  136. }
  137. #let company-resource(profile, key) = {
  138. validate-company(profile).resources.at(key, default: none)
  139. }