company-assets.typ 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // ==========================================
  2. // INFRASTRUCTURE: ПУБЛИЧНЫЕ ДАННЫЕ КОМПАНИЙ
  3. // ==========================================
  4. #import "../domain/company.typ": company-profile
  5. #import "../domain/document.typ": fail
  6. #let available-companies() = ("scientia", "technology", "too", "test-company")
  7. #let company-data-path(id) = {
  8. if id == "scientia" {
  9. path("../../companies/scientia/data.json")
  10. } else if id == "technology" {
  11. path("../../companies/technology/data.json")
  12. } else if id == "too" {
  13. path("../../companies/too/data.json")
  14. } else if id == "test-company" {
  15. path("../../companies/test-company/data.json")
  16. } else {
  17. fail(
  18. "load-company.id",
  19. "неизвестная компания " + repr(id) + "; доступны " + available-companies().join(", "),
  20. )
  21. }
  22. }
  23. #let internal-asset(value) = {
  24. let value = if value == "" { none } else { value }
  25. if value == none {
  26. none
  27. } else if type(value) == path or type(value) == content {
  28. value
  29. } else if type(value) == str and value.starts-with("companies/") {
  30. path("../../" + value)
  31. } else if type(value) == str {
  32. fail("company-asset", "путь должен начинаться с companies/: " + repr(value))
  33. } else {
  34. fail("company-asset", "ожидались none, str, path или content")
  35. }
  36. }
  37. #let external-resource(value, field) = {
  38. if value == none or type(value) == path or type(value) == content {
  39. value
  40. } else {
  41. fail("load-company." + field, "ожидались none, path или content")
  42. }
  43. }
  44. #let normalize-company-data(id, raw) = {
  45. let jurisdiction = if id == "too" { "KZ" } else { "RU" }
  46. let color-value = raw.at("brand-color", default: "#e39f49")
  47. let brand-color = if type(color-value) == color { color-value } else { rgb(color-value) }
  48. company-profile(
  49. id,
  50. (
  51. name: raw.at("name"),
  52. short-name: raw.at("short-name", default: raw.at("name")),
  53. jurisdiction: jurisdiction,
  54. inn: raw.at("inn", default: none),
  55. kpp: raw.at("kpp", default: none),
  56. ogrn: raw.at("ogrn", default: none),
  57. bin: raw.at("bin", default: none),
  58. kbe: raw.at("kbe", default: none),
  59. ),
  60. contacts: (
  61. email: raw.at("email", default: none),
  62. website: raw.at("website", default: none),
  63. phone: raw.at("phone", default: none),
  64. address: raw.at("address", default: none),
  65. address-en: raw.at("address_en", default: none),
  66. city: raw.at("city", default: none),
  67. summary: raw.at("company_info", default: none),
  68. ),
  69. banking: (
  70. bank: raw.at("bank", default: none),
  71. correspondent-account: raw.at("ks", default: none),
  72. bik: raw.at("bik", default: none),
  73. ),
  74. brand: (color: brand-color),
  75. director: (
  76. title: raw.at("director-title", default: "Директор"),
  77. name: raw.at("director-name", default: none),
  78. ),
  79. resources: (
  80. logo: internal-asset(raw.at("logo_image", default: none)),
  81. signature: internal-asset(raw.at("sign_image", default: none)),
  82. stamp: internal-asset(raw.at("stamp_image", default: none)),
  83. ),
  84. )
  85. }
  86. #let load-company(
  87. id,
  88. logo: auto,
  89. signature: auto,
  90. stamp: auto,
  91. ) = {
  92. if type(id) != str {
  93. fail("load-company.id", "ожидалась строка")
  94. }
  95. let company = normalize-company-data(id, json(company-data-path(id)))
  96. let resources = company.resources
  97. if logo != auto { resources.insert("logo", external-resource(logo, "logo")) }
  98. if signature != auto { resources.insert("signature", external-resource(signature, "signature")) }
  99. if stamp != auto { resources.insert("stamp", external-resource(stamp, "stamp")) }
  100. company.insert("resources", resources)
  101. company
  102. }