@golemio/energetics 1.12.2-dev.2739893110 → 1.12.2-dev.2740931754

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/db/example/00_clear_test_data.sql +14 -0
  2. package/db/example/06_eno.sql +25 -0
  3. package/db/example/07_enapo_om_detail.sql +140 -0
  4. package/db/migrations/postgresql/20260805090000-ppas-distribution-installation.js +47 -0
  5. package/db/migrations/postgresql/20260807090000-enapo-gid-mapping-om-detail.js +53 -0
  6. package/db/migrations/postgresql/20260807091000-enapo-om-detail-porsenna.js +53 -0
  7. package/db/migrations/postgresql/sqls/20260805090000-ppas-distribution-installation-down.sql +86 -0
  8. package/db/migrations/postgresql/sqls/20260805090000-ppas-distribution-installation-up.sql +124 -0
  9. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-down.sql +3 -0
  10. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-up.sql +182 -0
  11. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-down.sql +135 -0
  12. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-up.sql +292 -0
  13. package/db/scripts/ded_gid_mapping_mock_import.sql +48 -0
  14. package/dist/integration-engine/enapo/datasources/ppas/distribution/PpasDistributionDatasource.js +2 -5
  15. package/dist/integration-engine/enapo/datasources/ppas/distribution/PpasDistributionDatasource.js.map +1 -1
  16. package/dist/integration-engine/enapo/ioc/Di.js +2 -0
  17. package/dist/integration-engine/enapo/ioc/Di.js.map +1 -1
  18. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.d.ts +1 -0
  19. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js +1 -0
  20. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js.map +1 -1
  21. package/dist/integration-engine/enapo/repositories/ppas/PpasDistributionInvoiceInstallationRepository.d.ts +7 -0
  22. package/dist/integration-engine/enapo/repositories/ppas/PpasDistributionInvoiceInstallationRepository.js +36 -0
  23. package/dist/integration-engine/enapo/repositories/ppas/PpasDistributionInvoiceInstallationRepository.js.map +1 -0
  24. package/dist/integration-engine/enapo/transformations/ppas/PpasDistributionTransformation.d.ts +7 -0
  25. package/dist/integration-engine/enapo/transformations/ppas/PpasDistributionTransformation.js +133 -122
  26. package/dist/integration-engine/enapo/transformations/ppas/PpasDistributionTransformation.js.map +1 -1
  27. package/dist/integration-engine/enapo/workers/task/EnapoPpasDistributionTask.d.ts +3 -1
  28. package/dist/integration-engine/enapo/workers/task/EnapoPpasDistributionTask.js +10 -5
  29. package/dist/integration-engine/enapo/workers/task/EnapoPpasDistributionTask.js.map +1 -1
  30. package/dist/output-gateway/constants/Links.d.ts +1 -0
  31. package/dist/output-gateway/constants/Links.js +2 -1
  32. package/dist/output-gateway/constants/Links.js.map +1 -1
  33. package/dist/output-gateway/controllers/v2/EnoBuildingsController.d.ts +11 -0
  34. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js +53 -0
  35. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js.map +1 -0
  36. package/dist/output-gateway/helpers/objectMappers.d.ts +10 -0
  37. package/dist/output-gateway/helpers/objectMappers.js +37 -0
  38. package/dist/output-gateway/helpers/objectMappers.js.map +1 -0
  39. package/dist/output-gateway/index.js +8 -1
  40. package/dist/output-gateway/index.js.map +1 -1
  41. package/dist/output-gateway/ioc/Di.js +9 -1
  42. package/dist/output-gateway/ioc/Di.js.map +1 -1
  43. package/dist/output-gateway/ioc/ModuleContainerToken.d.ts +4 -0
  44. package/dist/output-gateway/ioc/ModuleContainerToken.js +4 -0
  45. package/dist/output-gateway/ioc/ModuleContainerToken.js.map +1 -1
  46. package/dist/output-gateway/models/EnoBuildingDetailViewModel.d.ts +35 -0
  47. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js +43 -0
  48. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js.map +1 -0
  49. package/dist/output-gateway/models/EnoConsumptionPointViewModel.d.ts +106 -0
  50. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js +119 -0
  51. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js.map +1 -0
  52. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.d.ts +27 -0
  53. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js +41 -0
  54. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js.map +1 -0
  55. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.d.ts +30 -0
  56. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js +3 -0
  57. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js.map +1 -0
  58. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.d.ts +106 -0
  59. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js +3 -0
  60. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js.map +1 -0
  61. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.d.ts +22 -0
  62. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js +3 -0
  63. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js.map +1 -0
  64. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.d.ts +12 -0
  65. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js +41 -0
  66. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js.map +1 -0
  67. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.d.ts +8 -0
  68. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js +62 -0
  69. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js.map +1 -0
  70. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.d.ts +18 -0
  71. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js +100 -0
  72. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js.map +1 -0
  73. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.d.ts +8 -0
  74. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js +51 -0
  75. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js.map +1 -0
  76. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.d.ts +8 -0
  77. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js +51 -0
  78. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js.map +1 -0
  79. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.d.ts +8 -0
  80. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js +52 -0
  81. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js.map +1 -0
  82. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.d.ts +13 -0
  83. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js +39 -0
  84. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js.map +1 -0
  85. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.d.ts +22 -0
  86. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js +3 -0
  87. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js.map +1 -0
  88. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.d.ts +108 -0
  89. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js +3 -0
  90. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js.map +1 -0
  91. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.d.ts +9 -0
  92. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js +40 -0
  93. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js.map +1 -0
  94. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.d.ts +14 -0
  95. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js +150 -0
  96. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js.map +1 -0
  97. package/dist/schema-definitions/datasources/enapo/ppas/distribution/IPpasDistributionInvoiceDetailInput.d.ts +10 -10
  98. package/dist/schema-definitions/datasources/enapo/ppas/distribution/IPpasDistributionInvoiceListInput.d.ts +1 -1
  99. package/dist/schema-definitions/datasources/enapo/ppas/distribution/PpasDistributionSchema.d.ts +1 -3
  100. package/dist/schema-definitions/datasources/enapo/ppas/distribution/PpasDistributionSchema.js +57 -72
  101. package/dist/schema-definitions/datasources/enapo/ppas/distribution/PpasDistributionSchema.js.map +1 -1
  102. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.d.ts +17 -0
  103. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js +63 -0
  104. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js.map +1 -0
  105. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.d.ts +11 -0
  106. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js +3 -0
  107. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js.map +1 -0
  108. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceDeviceModel.d.ts +9 -8
  109. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceDeviceModel.js +10 -8
  110. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceDeviceModel.js.map +1 -1
  111. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceInstallationModel.d.ts +26 -0
  112. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceInstallationModel.js +56 -0
  113. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceInstallationModel.js.map +1 -0
  114. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceModel.d.ts +1 -17
  115. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceModel.js +1 -33
  116. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoiceModel.js.map +1 -1
  117. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoicePriceModel.d.ts +2 -1
  118. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoicePriceModel.js +5 -3
  119. package/dist/schema-definitions/models/enapo/ppas/PpasDistributionInvoicePriceModel.js.map +1 -1
  120. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoice.d.ts +1 -17
  121. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoiceDevice.d.ts +9 -7
  122. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoiceInstallation.d.ts +20 -0
  123. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoiceInstallation.js +3 -0
  124. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoiceInstallation.js.map +1 -0
  125. package/dist/schema-definitions/models/enapo/ppas/interfaces/IPpasDistributionInvoicePrice.d.ts +3 -1
  126. package/dist/schema-definitions/models/eno/AddressModel.d.ts +1 -1
  127. package/dist/schema-definitions/models/eno/AddressModel.js +1 -1
  128. package/dist/schema-definitions/models/eno/AddressModel.js.map +1 -1
  129. package/dist/schema-definitions/models/eno/interfaces/IAddress.d.ts +1 -1
  130. package/docs/implementation_documentation.md +43 -2
  131. package/docs/openapi-output.yaml +263 -1
  132. package/package.json +1 -1
@@ -9,3 +9,17 @@ truncate organizations;
9
9
  truncate access_limitation;
10
10
  truncate enapo_measurements;
11
11
  truncate enapo_pre_metadata_history;
12
+ truncate enapo_gid_mapping;
13
+ truncate eno_budova;
14
+ truncate eno_adresa;
15
+ truncate enapo_ppas_distribution_invoice;
16
+ truncate enapo_ppas_distribution_installation;
17
+ truncate enapo_ppas_distribution_invoice_device;
18
+ truncate enapo_ppas_distribution_invoice_price;
19
+ truncate enapo_ppas_commercial_invoice;
20
+ truncate enapo_ppas_commercial_invoice_installations;
21
+ truncate enapo_ppas_commercial_invoice_device;
22
+ truncate enapo_ppas_commercial_invoice_price;
23
+ truncate enapo_porsenna_buildings;
24
+ truncate enapo_porsenna_devices;
25
+ truncate enapo_porsenna_consumption;
@@ -0,0 +1,25 @@
1
+ INSERT INTO eno_budova (gid, zdroj, nazev, oznaceni, druh_vytapeni, pripojka_elektro, pripojka_voda, pripojka_kanalizace,
2
+ budova_rozdelena_byt_nebyt, celkova_plocha_budova, zastavena_plocha, obestaveny_prostor,
3
+ pocet_byt, pocet_nebyt_budova, pocet_nadzem_podlazi, pocet_podzem_podlazi, pocet_podkrovi, vytah,
4
+ czcc, id_cuzk, id_objekt, kod_vyuziti, nazev_vyuziti, kod_ochrana, nazev_ochrana, platnost_od) VALUES
5
+ ('GID100', 'mhmp', 'ZŠ Testovací', 'ZŠT', 'ústřední dálkové', 'ano', 'ano', 'ano',
6
+ 'ne', 1200.5, 450.0, 5200.0,
7
+ 0, 12, 3, 1, 0, true,
8
+ 112, 100000001, 1001, '7', 'budova pro vzdělávání', NULL, NULL, '2020-01-01'),
9
+ ('GID100', 'stat', 'ZŠ Testovací (stat)', 'ZŠT', 'ústřední dálkové', 'ano', 'ano', 'ano',
10
+ 'ne', 1200.5, 450.0, 5200.0,
11
+ 0, 12, 3, 1, 0, true,
12
+ 112, 100000001, 1001, '7', 'budova pro vzdělávání', NULL, NULL, '2020-01-01'),
13
+ ('GID200', 'mhmp', 'MŠ Vedlejší', 'MŠV', 'plynová kotelna', 'ano', 'ano', 'ne',
14
+ 'ne', 480.0, 220.0, 1600.0,
15
+ 0, 5, 2, 0, 1, false,
16
+ 112, 100000002, 1002, '7', 'budova pro vzdělávání', NULL, NULL, '2021-06-15');
17
+
18
+ INSERT INTO eno_adresa (gid, gid_typ, poradi, zdroj, id, popis, hlavni) VALUES
19
+ ('GID100', 'budova', 1, 'mhmp', 501, 'Testovací 123/4, 100 00 Praha 10', true),
20
+ ('GID100', 'budova', 2, 'mhmp', 502, 'Testovací 125/6, 100 00 Praha 10', false),
21
+ ('GID100', 'budova', 1, 'stat', 501, 'Testovací 123/4, 100 00 Praha 10', true),
22
+ ('GID100', 'budova', 3, 'mhmp', 504, NULL, false),
23
+ ('GID100', 'budova', 4, 'mhmp', 505, NULL, false),
24
+ ('GID200', 'budova', 1, 'mhmp', 503, 'Vedlejší 7, 100 00 Praha 10', true),
25
+ ('GIDADDR1', 'stavba', 1, 'mhmp', 506, 'Stavební 9, 100 00 Praha 10', true);
@@ -0,0 +1,140 @@
1
+ -- Mock GID mapping (link_source = 'mock'); real rows will come from the data-team dbt output later
2
+ INSERT INTO enapo_gid_mapping (place_id, id_type, commodity, gid, is_first_gid, link_source, valid_from, valid_to) VALUES
3
+ ('27ZG100Z0000192O', 'eic', 'gas', 'GID100', true, 'mock', '2019-12-05', NULL),
4
+ ('27ZG100Z0000192O', 'eic', 'gas', 'GID200', false, 'mock', '2019-12-05', NULL),
5
+ ('859182400000000001', 'ean', 'electricity', 'GID100', true, 'mock', '2022-07-28', NULL),
6
+ ('859182400000000002', 'ean', 'electricity', 'GID100', true, 'mock', '2019-12-05', '2025-01-01'),
7
+ ('859182400000000003', 'ean', 'electricity', 'GID999', true, 'mock', '2022-07-28', NULL);
8
+
9
+ -- PRE metadata history: two months for the active EAN (the newer one must win)
10
+ INSERT INTO enapo_pre_metadata_history (ean, "year", "month", month_name, days_in_stored_month, consumption_point,
11
+ address, location_type, company_name, company_id, tarif_type, tarif_1t2t, phases, circuit_breaker, type_b_meter,
12
+ meter_replaced, created_at, updated_at) VALUES
13
+ ('859182400000000001', 2026, 5, 'květen', 31, 'OM Testovací 123',
14
+ 'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x100A', 'ano',
15
+ '53435572', '2026-06-05 00:00:00', NULL),
16
+ ('859182400000000001', 2026, 6, 'červen', 30, 'OM Testovací 123',
17
+ 'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x125A', 'ano',
18
+ '2026-06-19|53435572|54292510', '2026-07-05 00:00:00', NULL);
19
+
20
+ -- PPAS distribution invoices: an older valid one, a newer canceled one (must be skipped)
21
+ INSERT INTO enapo_ppas_distribution_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
22
+ customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
23
+ customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
24
+ customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
25
+ facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
26
+ ('DI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
27
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
28
+ 'Praha', 'Staré Město', '11000', 'CZ',
29
+ 22349995, '2026-03-15', '2026-03-29', 'FAKTURACE', 15250.50,
30
+ 'CZK', 18453.11, false, NULL),
31
+ ('DI-2026-002', 'DI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
32
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
33
+ 'Praha', 'Staré Město', '11000', 'CZ',
34
+ 22349995, '2026-05-20', '2026-06-03', 'STORNO', -15250.50,
35
+ 'CZK', -18453.11, true, 'oprava odečtu');
36
+
37
+ -- Two installations on the valid invoice: only the first one is mapped to a GID, the second exists
38
+ -- to prove devices/prices are scoped by place_id and do not leak across consumption points.
39
+ INSERT INTO enapo_ppas_distribution_installation (invoice_id, customer_id, place_id, eic, billing_class,
40
+ measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
41
+ address_street, address_house_number, address_house_org_number, address_city, address_city_part,
42
+ address_post_code, address_country, address_ruian_id) VALUES
43
+ ('DI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
44
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
45
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
46
+ '10000', 'CZ', 22349996),
47
+ ('DI-2026-001', 'CUST-1', '10101999', '27ZG100Z0000999O', 'MO',
48
+ 'C', 'SML-9', '2019-12-05', '9999-12-31', 'DOM4',
49
+ 'Jiná', '9', NULL, 'Praha', 'Praha 9',
50
+ '19000', 'CZ', 22349999),
51
+ ('DI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
52
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
53
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
54
+ '10000', 'CZ', 22349996);
55
+
56
+ INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
57
+ "type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
58
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
59
+ ('PLYN-001', 'DI-2026-001', '10101325', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
60
+ 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
61
+ 1.0043, 10.55, 1687.2),
62
+ ('PLYN-999', 'DI-2026-001', '10101999', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
63
+ 'řádný', 500.0, 700.0, 200.0, 'm3', 'dálkový', 2113.1,
64
+ 1.0043, 10.55, 200.9);
65
+
66
+ INSERT INTO enapo_ppas_distribution_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
67
+ description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
68
+ ('DI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
69
+ 'D1', 17750.4, 'kWh', 0.35, 0.19355, 6212.64, 'variabilní', 'CZK', 21.0),
70
+ ('DI-2026-001', 'CUST-1', '10101999', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
71
+ 'D1', 2113.1, 'kWh', 0.35, NULL, 739.59, 'variabilní', 'CZK', 21.0);
72
+
73
+ -- PPAS commercial invoices: a valid one and a newer canceled one (must be skipped)
74
+ INSERT INTO enapo_ppas_commercial_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
75
+ customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
76
+ customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
77
+ customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
78
+ facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
79
+ ('CI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
80
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
81
+ 'Praha', 'Staré Město', '11000', 'CZ',
82
+ 22349995, '2026-04-10', '2026-04-24', 'FAKTURACE', 28900.00,
83
+ 'CZK', 34969.00, false, NULL),
84
+ ('CI-2026-002', 'CI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
85
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
86
+ 'Praha', 'Staré Město', '11000', 'CZ',
87
+ 22349995, '2026-06-01', '2026-06-15', 'STORNO', -28900.00,
88
+ 'CZK', -34969.00, true, 'reklamace');
89
+
90
+ INSERT INTO enapo_ppas_commercial_invoice_installations (invoice_id, customer_id, place_id, eic, billing_class,
91
+ measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
92
+ address_street, address_house_number, address_house_org_number, address_city, address_city_part,
93
+ address_post_code, address_country, address_ruian_id) VALUES
94
+ ('CI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
95
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
96
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
97
+ '10000', 'CZ', 22349996),
98
+ ('CI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
99
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
100
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
101
+ '10000', 'CZ', 22349996);
102
+
103
+ INSERT INTO enapo_ppas_commercial_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
104
+ "type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
105
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
106
+ ('PLYN-001', 'CI-2026-001', '10101325', '2025-03-01', '2026-02-28',
107
+ 'G4', 'plynoměr', 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
108
+ 1.0043, 10.55, 1687.2);
109
+
110
+ INSERT INTO enapo_ppas_commercial_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
111
+ description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
112
+ ('CI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'komodita',
113
+ 'Dodávka plynu', 'K1', 17750.4, 'kWh', 1.45, NULL, 25738.08, 'variabilní', 'CZK', 21.0);
114
+
115
+ -- Porsenna (e-manazer): buildings, devices (incl. heat/water and a sub-meter), yearly consumption.
116
+ -- Device types and tenant naming mirror real Porsenna data (electricity_meter/heat_meter/water_meter, tenant prague-7).
117
+ INSERT INTO enapo_porsenna_buildings (source, id, name, street, house_number, street_number, city, postcode, gid) VALUES
118
+ ('prague-7', 1, 'ZŠ Testovací (e-manažer)', 'Testovací', '123', '4', 'Praha 10', '10000', 'GID100'),
119
+ ('prague-7', 2, 'Vrátnice Kundratka', 'Kundratka', '19', NULL, 'Praha 8', '18000', 'GIDPOR1');
120
+
121
+ INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "level", "type", name,
122
+ measurement_target, disabled_at, disable_reason_id, show_in_output, identifier, supply_point_number,
123
+ meter_number, identification_gid) VALUES
124
+ ('prague-7', '11111111-1111-1111-1111-111111111111', 1, NULL, 'main', 'electricity_meter', 'Hlavní elektroměr',
125
+ 'consumption', NULL, NULL, true, '859182400000000001', 'OP-100', 'EL-123', 'GID100'),
126
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 1, NULL, 'main', 'heat_meter', 'Předávací stanice CZT',
127
+ 'consumption', NULL, NULL, true, '40001234', 'OP-101', 'TEP-77', 'GID100'),
128
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 1, NULL, 'main', 'water_meter', 'Hlavní vodoměr',
129
+ 'consumption', '2024-05-31 00:00:00+00', 4, true, '50005678', 'OP-102', 'VOD-55', 'GID100'),
130
+ ('prague-7', '44444444-4444-4444-4444-444444444444', 1, '22222222-2222-2222-2222-222222222222', 'sub',
131
+ 'heat_meter', 'Podružné měření tělocvična', 'tělocvična', NULL, NULL, true, NULL, NULL, 'TEP-78', NULL),
132
+ ('prague-7', '55555555-5555-5555-5555-555555555555', 2, NULL, 'main', 'electricity_meter', 'Elektroměr vrátnice',
133
+ 'consumption', NULL, NULL, true, '859182400000000099', 'OP-200', 'EL-999', 'GIDPOR1');
134
+
135
+ INSERT INTO enapo_porsenna_consumption (source, device_id, "var", "period", value, unit, commodity, "count") VALUES
136
+ ('prague-7', '11111111-1111-1111-1111-111111111111', 'yearly', '2025', 12.4, 'MWH', 'electricity_meter', 365),
137
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, 'GJ', 'heat_meter', 365),
138
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, 'GJ', 'heat_meter', 366),
139
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, 'M3', 'water_meter', 365),
140
+ ('prague-7', '55555555-5555-5555-5555-555555555555', 'yearly', '2024', 5.5, 'MWH', 'electricity_meter', 366);
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ exports.setup = function(options, seedLink) {
11
+ dbm = options.dbmigrate;
12
+ type = dbm.dataType;
13
+ seed = seedLink;
14
+ Promise = options.Promise;
15
+ };
16
+
17
+ exports.up = function(db) {
18
+ var filePath = path.join(__dirname, 'sqls', '20260805090000-ppas-distribution-installation-up.sql');
19
+ return new Promise( function( resolve, reject ) {
20
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
21
+ if (err) return reject(err);
22
+ console.log('received data: ' + data);
23
+ resolve(data);
24
+ });
25
+ })
26
+ .then(function(data) {
27
+ return db.runSql(data);
28
+ });
29
+ };
30
+
31
+ exports.down = function(db) {
32
+ var filePath = path.join(__dirname, 'sqls', '20260805090000-ppas-distribution-installation-down.sql');
33
+ return new Promise( function( resolve, reject ) {
34
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
35
+ if (err) return reject(err);
36
+ console.log('received data: ' + data);
37
+ resolve(data);
38
+ });
39
+ })
40
+ .then(function(data) {
41
+ return db.runSql(data);
42
+ });
43
+ };
44
+
45
+ exports._meta = {
46
+ "version": 1
47
+ };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20260807090000-enapo-gid-mapping-om-detail-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20260807090000-enapo-gid-mapping-om-detail-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20260807091000-enapo-om-detail-porsenna-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20260807091000-enapo-om-detail-porsenna-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,86 @@
1
+ -- Rounding is lossy, but an integer column cannot hold the fractional periods.
2
+ ALTER TABLE enapo_ppas_distribution_invoice_price
3
+ ALTER COLUMN time_slot TYPE int4 USING round(time_slot)::int4;
4
+
5
+ -- Give up the per-installation scoping. The pre-existing keys cannot represent more than one
6
+ -- installation per invoice, so colliding rows beyond the lowest place_id are dropped first -- the same
7
+ -- lossy restore the invoice header gets below.
8
+ DELETE FROM enapo_ppas_distribution_invoice_device d
9
+ USING enapo_ppas_distribution_invoice_device x
10
+ WHERE d.device_serial_number = x.device_serial_number
11
+ AND d.invoice_id = x.invoice_id
12
+ AND d.date_from = x.date_from
13
+ AND d.date_to = x.date_to
14
+ AND d.reading_type = x.reading_type
15
+ AND d.kind = x.kind
16
+ AND d.place_id > x.place_id;
17
+
18
+ DELETE FROM enapo_ppas_distribution_invoice_price p
19
+ USING enapo_ppas_distribution_invoice_price x
20
+ WHERE p.invoice_id = x.invoice_id
21
+ AND p.customer_id = x.customer_id
22
+ AND p.date_from = x.date_from
23
+ AND p.date_to = x.date_to
24
+ AND p.kind = x.kind
25
+ AND p.price_type = x.price_type
26
+ AND p.place_id > x.place_id;
27
+
28
+ -- Dropping the column cascades away both the place_id index and the primary key that contains it.
29
+ ALTER TABLE enapo_ppas_distribution_invoice_device DROP COLUMN place_id;
30
+ ALTER TABLE enapo_ppas_distribution_invoice_device
31
+ ADD CONSTRAINT enapo_ppas_distribution_invoice_device_pk
32
+ PRIMARY KEY (device_serial_number, invoice_id, date_from, date_to, reading_type, kind);
33
+
34
+ ALTER TABLE enapo_ppas_distribution_invoice_price DROP COLUMN place_id;
35
+ ALTER TABLE enapo_ppas_distribution_invoice_price
36
+ ADD CONSTRAINT enapo_ppas_distribution_invoice_price_pk
37
+ PRIMARY KEY (invoice_id, customer_id, date_from, date_to, kind, price_type);
38
+
39
+ ALTER TABLE enapo_ppas_distribution_invoice
40
+ ADD COLUMN eic varchar NULL,
41
+ ADD COLUMN place_id varchar NULL,
42
+ ADD COLUMN installations_billing_class varchar NULL,
43
+ ADD COLUMN installations_measurement_type varchar NULL,
44
+ ADD COLUMN installations_contract_contract_id varchar NULL,
45
+ ADD COLUMN installations_contract_move_in_date date NULL,
46
+ ADD COLUMN installations_contract_move_out_date date NULL,
47
+ ADD COLUMN installations_tdd_class varchar NULL,
48
+ ADD COLUMN installations_address_street varchar NULL,
49
+ ADD COLUMN installations_address_house_number varchar NULL,
50
+ ADD COLUMN installations_address_house_org_number varchar NULL,
51
+ ADD COLUMN installations_address_city varchar NULL,
52
+ ADD COLUMN installations_address_city_part varchar NULL,
53
+ ADD COLUMN installations_address_post_code varchar NULL,
54
+ ADD COLUMN installations_address_country varchar NULL,
55
+ ADD COLUMN installations_address_ruian_id int8 NULL;
56
+
57
+ -- Only one installation fits the invoice header, so the lowest place_id per invoice is restored.
58
+ UPDATE enapo_ppas_distribution_invoice i
59
+ SET
60
+ eic = s.eic,
61
+ place_id = s.place_id,
62
+ installations_billing_class = s.billing_class,
63
+ installations_measurement_type = s.measurement_type,
64
+ installations_contract_contract_id = s.contract_contract_id,
65
+ installations_contract_move_in_date = s.contract_move_in_date,
66
+ installations_contract_move_out_date = s.contract_move_out_date,
67
+ installations_tdd_class = s.tdd_class,
68
+ installations_address_street = s.address_street,
69
+ installations_address_house_number = s.address_house_number,
70
+ installations_address_house_org_number = s.address_house_org_number,
71
+ installations_address_city = s.address_city,
72
+ installations_address_city_part = s.address_city_part,
73
+ installations_address_post_code = s.address_post_code,
74
+ installations_address_country = s.address_country,
75
+ installations_address_ruian_id = s.address_ruian_id
76
+ FROM (
77
+ SELECT DISTINCT ON (invoice_id, customer_id) *
78
+ FROM enapo_ppas_distribution_installation
79
+ ORDER BY invoice_id, customer_id, place_id
80
+ ) s
81
+ WHERE i.id = s.invoice_id AND i.customer_id = s.customer_id;
82
+
83
+ CREATE INDEX idx_ppas_invoice_eic ON enapo_ppas_distribution_invoice(eic);
84
+ CREATE INDEX idx_ppas_invoice_place_id ON enapo_ppas_distribution_invoice(place_id);
85
+
86
+ DROP TABLE enapo_ppas_distribution_installation;
@@ -0,0 +1,124 @@
1
+ CREATE TABLE enapo_ppas_distribution_installation (
2
+ invoice_id varchar,
3
+ customer_id varchar,
4
+ place_id varchar,
5
+ eic varchar NULL,
6
+ billing_class varchar NULL,
7
+ measurement_type varchar NULL,
8
+ contract_contract_id varchar NULL,
9
+ contract_move_in_date date NULL,
10
+ contract_move_out_date date NULL,
11
+ tdd_class varchar NULL,
12
+ address_street varchar NULL,
13
+ address_house_number varchar NULL,
14
+ address_house_org_number varchar NULL,
15
+ address_city varchar NULL,
16
+ address_city_part varchar NULL,
17
+ address_post_code varchar NULL,
18
+ address_country varchar NULL,
19
+ address_ruian_id int8 NULL,
20
+ created_at timestamptz DEFAULT now() NULL,
21
+ updated_at timestamptz NULL,
22
+ CONSTRAINT enapo_ppas_distribution_installation_pk PRIMARY KEY (invoice_id, customer_id, place_id)
23
+ );
24
+
25
+ CREATE INDEX idx_ppas_distribution_installation_eic ON enapo_ppas_distribution_installation(eic);
26
+ CREATE INDEX idx_ppas_distribution_installation_place_id ON enapo_ppas_distribution_installation(place_id);
27
+
28
+ -- Move the already stored installations out of the invoice header, its still necessary to download history because there can be more than one installation per invoice
29
+ INSERT INTO enapo_ppas_distribution_installation (
30
+ invoice_id, customer_id, place_id, eic, billing_class, measurement_type,
31
+ contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
32
+ address_street, address_house_number, address_house_org_number, address_city,
33
+ address_city_part, address_post_code, address_country, address_ruian_id
34
+ )
35
+ SELECT
36
+ id, customer_id, place_id, eic, installations_billing_class, installations_measurement_type,
37
+ installations_contract_contract_id, installations_contract_move_in_date, installations_contract_move_out_date,
38
+ installations_tdd_class, installations_address_street, installations_address_house_number,
39
+ installations_address_house_org_number, installations_address_city, installations_address_city_part,
40
+ installations_address_post_code, installations_address_country, installations_address_ruian_id
41
+ FROM enapo_ppas_distribution_invoice
42
+ WHERE place_id IS NOT NULL
43
+ ON CONFLICT (invoice_id, customer_id, place_id) DO NOTHING;
44
+
45
+ ALTER TABLE enapo_ppas_distribution_invoice_device ADD COLUMN place_id varchar NULL;
46
+ ALTER TABLE enapo_ppas_distribution_invoice_price ADD COLUMN place_id varchar NULL;
47
+
48
+ -- Existing rows were written when only installations[0] was stored
49
+ UPDATE enapo_ppas_distribution_invoice_device d
50
+ SET place_id = s.place_id
51
+ FROM (
52
+ SELECT invoice_id, min(place_id) AS place_id
53
+ FROM enapo_ppas_distribution_installation
54
+ GROUP BY invoice_id
55
+ ) s
56
+ WHERE d.invoice_id = s.invoice_id;
57
+
58
+ UPDATE enapo_ppas_distribution_invoice_price p
59
+ SET place_id = s.place_id
60
+ FROM (
61
+ SELECT invoice_id, customer_id, min(place_id) AS place_id
62
+ FROM enapo_ppas_distribution_installation
63
+ GROUP BY invoice_id, customer_id
64
+ ) s
65
+ WHERE p.invoice_id = s.invoice_id AND p.customer_id = s.customer_id;
66
+
67
+ -- Rows whose invoice never reached the installation table cannot be attributed to a consumption point.
68
+ -- Deleting them here would be silent data loss, so the migration stops instead and leaves the call to us.
69
+ DO $$
70
+ DECLARE
71
+ orphan_devices bigint;
72
+ orphan_prices bigint;
73
+ BEGIN
74
+ SELECT count(*) INTO orphan_devices FROM enapo_ppas_distribution_invoice_device WHERE place_id IS NULL;
75
+ SELECT count(*) INTO orphan_prices FROM enapo_ppas_distribution_invoice_price WHERE place_id IS NULL;
76
+
77
+ IF orphan_devices > 0 OR orphan_prices > 0 THEN
78
+ RAISE EXCEPTION
79
+ 'Cannot scope distribution rows by place_id: % device and % price rows belong to invoices missing from enapo_ppas_distribution_installation. Resolve or remove them, then re-run.',
80
+ orphan_devices, orphan_prices;
81
+ END IF;
82
+ END $$;
83
+
84
+ ALTER TABLE enapo_ppas_distribution_invoice_device
85
+ ALTER COLUMN place_id SET NOT NULL,
86
+ DROP CONSTRAINT enapo_ppas_distribution_invoice_device_pk,
87
+ ADD CONSTRAINT enapo_ppas_distribution_invoice_device_pk
88
+ PRIMARY KEY (device_serial_number, invoice_id, place_id, date_from, date_to, reading_type, kind);
89
+
90
+ ALTER TABLE enapo_ppas_distribution_invoice_price
91
+ ALTER COLUMN place_id SET NOT NULL,
92
+ DROP CONSTRAINT enapo_ppas_distribution_invoice_price_pk,
93
+ ADD CONSTRAINT enapo_ppas_distribution_invoice_price_pk
94
+ PRIMARY KEY (invoice_id, customer_id, place_id, date_from, date_to, kind, price_type);
95
+
96
+ CREATE INDEX idx_ppas_distribution_invoice_device_place_id ON enapo_ppas_distribution_invoice_device(place_id);
97
+ CREATE INDEX idx_ppas_distribution_invoice_price_place_id ON enapo_ppas_distribution_invoice_price(place_id);
98
+
99
+ -- timeSlot is a fraction of the billed period (e.g. 0.19355 = 6 of 31 days), not an int
100
+ ALTER TABLE enapo_ppas_distribution_invoice_price
101
+ ALTER COLUMN time_slot TYPE numeric;
102
+
103
+ DROP INDEX IF EXISTS idx_ppas_invoice_eic;
104
+ DROP INDEX IF EXISTS idx_ppas_invoice_place_id;
105
+
106
+
107
+
108
+ ALTER TABLE enapo_ppas_distribution_invoice
109
+ DROP COLUMN eic,
110
+ DROP COLUMN place_id,
111
+ DROP COLUMN installations_billing_class,
112
+ DROP COLUMN installations_measurement_type,
113
+ DROP COLUMN installations_contract_contract_id,
114
+ DROP COLUMN installations_contract_move_in_date,
115
+ DROP COLUMN installations_contract_move_out_date,
116
+ DROP COLUMN installations_tdd_class,
117
+ DROP COLUMN installations_address_street,
118
+ DROP COLUMN installations_address_house_number,
119
+ DROP COLUMN installations_address_house_org_number,
120
+ DROP COLUMN installations_address_city,
121
+ DROP COLUMN installations_address_city_part,
122
+ DROP COLUMN installations_address_post_code,
123
+ DROP COLUMN installations_address_country,
124
+ DROP COLUMN installations_address_ruian_id;
@@ -0,0 +1,3 @@
1
+ DROP VIEW IF EXISTS v_enapo_building_consumption_points;
2
+ DROP VIEW IF EXISTS v_enapo_building_detail;
3
+ DROP TABLE IF EXISTS enapo_gid_mapping;