@spaceinvoices/react-ui 0.4.8 → 0.4.10

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 (258) hide show
  1. package/cli/dist/index.js +1 -1
  2. package/package.json +1 -1
  3. package/src/common/autocomplete.tsx +69 -6
  4. package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +124 -285
  5. package/src/components/advance-invoices/list/list-table.tsx +10 -3
  6. package/src/components/advance-invoices/list/locales/de.ts +2 -0
  7. package/src/components/advance-invoices/list/locales/en.ts +1 -0
  8. package/src/components/advance-invoices/list/locales/es.ts +1 -0
  9. package/src/components/advance-invoices/list/locales/fr.ts +1 -0
  10. package/src/components/advance-invoices/list/locales/hr.ts +1 -0
  11. package/src/components/advance-invoices/list/locales/it.ts +1 -0
  12. package/src/components/advance-invoices/list/locales/nl.ts +1 -0
  13. package/src/components/advance-invoices/list/locales/pl.ts +1 -0
  14. package/src/components/advance-invoices/list/locales/pt.ts +1 -0
  15. package/src/components/advance-invoices/list/locales/sl.ts +1 -0
  16. package/src/components/advance-invoices/list/use-advance-invoice-download.ts +1 -12
  17. package/src/components/credit-notes/create/create-credit-note-form.tsx +116 -238
  18. package/src/components/credit-notes/list/list-table.tsx +6 -3
  19. package/src/components/credit-notes/list/use-credit-note-download.ts +1 -12
  20. package/src/components/customers/customer-autocomplete.tsx +64 -11
  21. package/src/components/customers/customer-list-table/customer-list-table.tsx +3 -2
  22. package/src/components/dashboard/collection-rate-card/collection-rate-card.tsx +9 -1
  23. package/src/components/dashboard/collection-rate-card/locales/bg.ts +3 -0
  24. package/src/components/dashboard/collection-rate-card/locales/cs.ts +3 -0
  25. package/src/components/dashboard/collection-rate-card/locales/et.ts +3 -0
  26. package/src/components/dashboard/collection-rate-card/locales/fi.ts +3 -0
  27. package/src/components/dashboard/collection-rate-card/locales/is.ts +3 -0
  28. package/src/components/dashboard/collection-rate-card/locales/nb.ts +3 -0
  29. package/src/components/dashboard/collection-rate-card/locales/sk.ts +3 -0
  30. package/src/components/dashboard/collection-rate-card/locales/sv.ts +3 -0
  31. package/src/components/dashboard/invoice-status-chart/invoice-status-chart.tsx +10 -2
  32. package/src/components/dashboard/invoice-status-chart/locales/bg.ts +10 -0
  33. package/src/components/dashboard/invoice-status-chart/locales/cs.ts +10 -0
  34. package/src/components/dashboard/invoice-status-chart/locales/de.ts +1 -0
  35. package/src/components/dashboard/invoice-status-chart/locales/es.ts +1 -0
  36. package/src/components/dashboard/invoice-status-chart/locales/et.ts +10 -0
  37. package/src/components/dashboard/invoice-status-chart/locales/fi.ts +10 -0
  38. package/src/components/dashboard/invoice-status-chart/locales/fr.ts +1 -0
  39. package/src/components/dashboard/invoice-status-chart/locales/hr.ts +1 -0
  40. package/src/components/dashboard/invoice-status-chart/locales/is.ts +10 -0
  41. package/src/components/dashboard/invoice-status-chart/locales/it.ts +1 -0
  42. package/src/components/dashboard/invoice-status-chart/locales/nb.ts +10 -0
  43. package/src/components/dashboard/invoice-status-chart/locales/nl.ts +1 -0
  44. package/src/components/dashboard/invoice-status-chart/locales/pl.ts +1 -0
  45. package/src/components/dashboard/invoice-status-chart/locales/pt.ts +1 -0
  46. package/src/components/dashboard/invoice-status-chart/locales/sk.ts +10 -0
  47. package/src/components/dashboard/invoice-status-chart/locales/sl.ts +1 -0
  48. package/src/components/dashboard/invoice-status-chart/locales/sv.ts +10 -0
  49. package/src/components/dashboard/payment-methods-chart/locales/bg.ts +12 -0
  50. package/src/components/dashboard/payment-methods-chart/locales/cs.ts +12 -0
  51. package/src/components/dashboard/payment-methods-chart/locales/et.ts +12 -0
  52. package/src/components/dashboard/payment-methods-chart/locales/fi.ts +12 -0
  53. package/src/components/dashboard/payment-methods-chart/locales/is.ts +12 -0
  54. package/src/components/dashboard/payment-methods-chart/locales/nb.ts +12 -0
  55. package/src/components/dashboard/payment-methods-chart/locales/sk.ts +12 -0
  56. package/src/components/dashboard/payment-methods-chart/locales/sv.ts +12 -0
  57. package/src/components/dashboard/payment-methods-chart/payment-methods-chart.tsx +9 -1
  58. package/src/components/dashboard/payment-trend-chart/locales/bg.ts +6 -0
  59. package/src/components/dashboard/payment-trend-chart/locales/cs.ts +6 -0
  60. package/src/components/dashboard/payment-trend-chart/locales/de.ts +1 -0
  61. package/src/components/dashboard/payment-trend-chart/locales/es.ts +1 -0
  62. package/src/components/dashboard/payment-trend-chart/locales/et.ts +6 -0
  63. package/src/components/dashboard/payment-trend-chart/locales/fi.ts +6 -0
  64. package/src/components/dashboard/payment-trend-chart/locales/fr.ts +1 -0
  65. package/src/components/dashboard/payment-trend-chart/locales/hr.ts +1 -0
  66. package/src/components/dashboard/payment-trend-chart/locales/is.ts +6 -0
  67. package/src/components/dashboard/payment-trend-chart/locales/it.ts +1 -0
  68. package/src/components/dashboard/payment-trend-chart/locales/nb.ts +6 -0
  69. package/src/components/dashboard/payment-trend-chart/locales/nl.ts +1 -0
  70. package/src/components/dashboard/payment-trend-chart/locales/pl.ts +1 -0
  71. package/src/components/dashboard/payment-trend-chart/locales/pt.ts +1 -0
  72. package/src/components/dashboard/payment-trend-chart/locales/sk.ts +6 -0
  73. package/src/components/dashboard/payment-trend-chart/locales/sl.ts +1 -0
  74. package/src/components/dashboard/payment-trend-chart/locales/sv.ts +6 -0
  75. package/src/components/dashboard/payment-trend-chart/payment-trend-chart.tsx +15 -8
  76. package/src/components/dashboard/revenue-trend-chart/locales/bg.ts +6 -0
  77. package/src/components/dashboard/revenue-trend-chart/locales/cs.ts +6 -0
  78. package/src/components/dashboard/revenue-trend-chart/locales/de.ts +1 -0
  79. package/src/components/dashboard/revenue-trend-chart/locales/es.ts +1 -0
  80. package/src/components/dashboard/revenue-trend-chart/locales/et.ts +6 -0
  81. package/src/components/dashboard/revenue-trend-chart/locales/fi.ts +6 -0
  82. package/src/components/dashboard/revenue-trend-chart/locales/fr.ts +1 -0
  83. package/src/components/dashboard/revenue-trend-chart/locales/hr.ts +1 -0
  84. package/src/components/dashboard/revenue-trend-chart/locales/is.ts +6 -0
  85. package/src/components/dashboard/revenue-trend-chart/locales/it.ts +1 -0
  86. package/src/components/dashboard/revenue-trend-chart/locales/nb.ts +6 -0
  87. package/src/components/dashboard/revenue-trend-chart/locales/nl.ts +1 -0
  88. package/src/components/dashboard/revenue-trend-chart/locales/pl.ts +1 -0
  89. package/src/components/dashboard/revenue-trend-chart/locales/pt.ts +1 -0
  90. package/src/components/dashboard/revenue-trend-chart/locales/sk.ts +6 -0
  91. package/src/components/dashboard/revenue-trend-chart/locales/sl.ts +1 -0
  92. package/src/components/dashboard/revenue-trend-chart/locales/sv.ts +6 -0
  93. package/src/components/dashboard/revenue-trend-chart/revenue-trend-chart.tsx +15 -8
  94. package/src/components/dashboard/tax-collected-card/locales.ts +110 -0
  95. package/src/components/dashboard/tax-collected-card/tax-collected-card.tsx +8 -2
  96. package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +4 -4
  97. package/src/components/dashboard/top-customers-chart/locales/bg.ts +7 -0
  98. package/src/components/dashboard/top-customers-chart/locales/cs.ts +7 -0
  99. package/src/components/dashboard/top-customers-chart/locales/de.ts +2 -0
  100. package/src/components/dashboard/top-customers-chart/locales/es.ts +2 -0
  101. package/src/components/dashboard/top-customers-chart/locales/et.ts +7 -0
  102. package/src/components/dashboard/top-customers-chart/locales/fi.ts +7 -0
  103. package/src/components/dashboard/top-customers-chart/locales/fr.ts +2 -0
  104. package/src/components/dashboard/top-customers-chart/locales/hr.ts +2 -0
  105. package/src/components/dashboard/top-customers-chart/locales/is.ts +7 -0
  106. package/src/components/dashboard/top-customers-chart/locales/it.ts +2 -0
  107. package/src/components/dashboard/top-customers-chart/locales/nb.ts +7 -0
  108. package/src/components/dashboard/top-customers-chart/locales/nl.ts +2 -0
  109. package/src/components/dashboard/top-customers-chart/locales/pl.ts +2 -0
  110. package/src/components/dashboard/top-customers-chart/locales/pt.ts +2 -0
  111. package/src/components/dashboard/top-customers-chart/locales/sk.ts +7 -0
  112. package/src/components/dashboard/top-customers-chart/locales/sl.ts +2 -0
  113. package/src/components/dashboard/top-customers-chart/locales/sv.ts +7 -0
  114. package/src/components/dashboard/top-customers-chart/top-customers-chart.tsx +23 -12
  115. package/src/components/delivery-notes/create/create-delivery-note-form.tsx +33 -20
  116. package/src/components/delivery-notes/list/list-table.tsx +22 -13
  117. package/src/components/delivery-notes/list/locales/de.ts +2 -0
  118. package/src/components/delivery-notes/list/locales/en.ts +1 -0
  119. package/src/components/delivery-notes/list/locales/es.ts +1 -0
  120. package/src/components/delivery-notes/list/locales/fr.ts +1 -0
  121. package/src/components/delivery-notes/list/locales/hr.ts +1 -0
  122. package/src/components/delivery-notes/list/locales/it.ts +1 -0
  123. package/src/components/delivery-notes/list/locales/nl.ts +1 -0
  124. package/src/components/delivery-notes/list/locales/pl.ts +1 -0
  125. package/src/components/delivery-notes/list/locales/pt.ts +1 -0
  126. package/src/components/delivery-notes/list/locales/sl.ts +1 -0
  127. package/src/components/delivery-notes/list/use-delivery-note-download.ts +1 -12
  128. package/src/components/documents/create/document-add-item-form.tsx +28 -16
  129. package/src/components/documents/create/document-add-item-tax-rate-field.tsx +12 -2
  130. package/src/components/documents/create/document-items-section.tsx +70 -39
  131. package/src/components/documents/create/document-recipient-section.tsx +10 -1
  132. package/src/components/documents/create/live-preview.tsx +113 -15
  133. package/src/components/documents/create/prepare-document-submission.ts +35 -16
  134. package/src/components/documents/create/use-document-customer-form.ts +14 -3
  135. package/src/components/documents/documents.hooks.ts +7 -2
  136. package/src/components/documents/shared/document-preview-display.tsx +136 -67
  137. package/src/components/documents/shared/scaled-document-preview.tsx +45 -5
  138. package/src/components/documents/view/document-actions-bar.tsx +284 -182
  139. package/src/components/documents/view/document-activities-list.tsx +3 -0
  140. package/src/components/documents/view/document-payments-list.tsx +3 -0
  141. package/src/components/documents/view/locales/de.ts +8 -0
  142. package/src/components/documents/view/locales/es.ts +8 -0
  143. package/src/components/documents/view/locales/fr.ts +8 -0
  144. package/src/components/documents/view/locales/hr.ts +8 -0
  145. package/src/components/documents/view/locales/it.ts +8 -0
  146. package/src/components/documents/view/locales/nl.ts +8 -0
  147. package/src/components/documents/view/locales/pl.ts +8 -0
  148. package/src/components/documents/view/locales/pt.ts +8 -0
  149. package/src/components/documents/view/locales/sl.ts +8 -0
  150. package/src/components/documents/view/use-document-download.ts +14 -25
  151. package/src/components/entities/create-entity-form.tsx +101 -16
  152. package/src/components/entities/fina-settings-form/fina-operator-required-dialog.tsx +3 -3
  153. package/src/components/entities/fina-settings-form/fina-settings-form.tsx +78 -124
  154. package/src/components/entities/fina-settings-form/sections/certificate-settings-section.tsx +8 -1
  155. package/src/components/entities/fina-settings-form/sections/premises-management-section.tsx +14 -2
  156. package/src/components/entities/fina-settings-form/sections/register-premise-dialog.tsx +7 -2
  157. package/src/components/entities/furs-settings-form/furs-settings-form.tsx +56 -130
  158. package/src/components/entities/furs-settings-form/sections/certificate-settings-section.tsx +8 -1
  159. package/src/components/entities/furs-settings-form/sections/enable-fiscalization-section.tsx +1 -0
  160. package/src/components/entities/furs-settings-form/sections/general-settings-section.tsx +15 -2
  161. package/src/components/entities/furs-settings-form/sections/premises-management-section.tsx +20 -3
  162. package/src/components/entities/furs-settings-form/sections/register-premise-dialog.tsx +38 -12
  163. package/src/components/entities/settings/eslog-settings-form.tsx +13 -1
  164. package/src/components/entities/settings/pdf-template-selector/demo-invoice-data.ts +3 -22
  165. package/src/components/entities/shared/fiscalization-step-flow.ts +77 -0
  166. package/src/components/entities/shared/fiscalization-step-tabs.tsx +71 -0
  167. package/src/components/estimates/create/create-estimate-form.tsx +34 -21
  168. package/src/components/estimates/list/list-table.tsx +23 -14
  169. package/src/components/estimates/list/locales/de.ts +2 -0
  170. package/src/components/estimates/list/locales/en.ts +1 -0
  171. package/src/components/estimates/list/locales/es.ts +1 -0
  172. package/src/components/estimates/list/locales/fr.ts +1 -0
  173. package/src/components/estimates/list/locales/hr.ts +1 -0
  174. package/src/components/estimates/list/locales/it.ts +1 -0
  175. package/src/components/estimates/list/locales/nl.ts +1 -0
  176. package/src/components/estimates/list/locales/pl.ts +1 -0
  177. package/src/components/estimates/list/locales/pt.ts +1 -0
  178. package/src/components/estimates/list/locales/sl.ts +1 -0
  179. package/src/components/estimates/list/use-estimate-download.ts +1 -12
  180. package/src/components/export/document-export-form.tsx +33 -7
  181. package/src/components/export/sales-per-item-export-form.tsx +23 -7
  182. package/src/components/invoices/create/create-invoice-form.tsx +295 -329
  183. package/src/components/invoices/create/prepare-invoice-submission.ts +0 -8
  184. package/src/components/invoices/list/list-table.tsx +7 -4
  185. package/src/components/invoices/list/use-invoice-download.ts +1 -11
  186. package/src/components/invoices/send-email-dialog/locales/de.ts +2 -0
  187. package/src/components/invoices/send-email-dialog/locales/es.ts +2 -0
  188. package/src/components/invoices/send-email-dialog/locales/fr.ts +2 -0
  189. package/src/components/invoices/send-email-dialog/locales/hr.ts +2 -0
  190. package/src/components/invoices/send-email-dialog/locales/it.ts +2 -0
  191. package/src/components/invoices/send-email-dialog/locales/nl.ts +2 -0
  192. package/src/components/invoices/send-email-dialog/locales/pl.ts +2 -0
  193. package/src/components/invoices/send-email-dialog/locales/pt.ts +2 -0
  194. package/src/components/invoices/send-email-dialog/locales/sl.ts +2 -0
  195. package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +77 -8
  196. package/src/components/invoices/view/eslog-info-display.tsx +17 -1
  197. package/src/components/invoices/view/fiscalization-status-card.tsx +7 -3
  198. package/src/components/items/item-combobox.tsx +26 -6
  199. package/src/components/items/item-list-table/item-list-table.tsx +5 -2
  200. package/src/components/payments/list/list-table.tsx +14 -4
  201. package/src/components/recurring-invoices/list/list-table.tsx +7 -4
  202. package/src/components/request-logs/locales.ts +412 -0
  203. package/src/components/request-logs/request-log-detail.tsx +37 -21
  204. package/src/components/request-logs/request-log-list-table.tsx +57 -11
  205. package/src/components/table/data-table.tsx +5 -2
  206. package/src/components/table/date-cell.tsx +3 -1
  207. package/src/components/table/filter-bar.tsx +14 -2
  208. package/src/components/table/hooks/use-table-query.ts +1 -1
  209. package/src/components/table/locales.ts +1116 -0
  210. package/src/components/table/search-input.tsx +12 -3
  211. package/src/components/table/selection-toolbar.tsx +23 -6
  212. package/src/components/table/table-empty-state.tsx +43 -3
  213. package/src/components/table/table-no-results.tsx +3 -3
  214. package/src/components/table/table-pagination.tsx +4 -3
  215. package/src/components/table/types.ts +1 -0
  216. package/src/components/tax-reports/index.ts +1 -0
  217. package/src/components/tax-reports/kir-export-form.tsx +46 -8
  218. package/src/components/tax-reports/slovenia-tax-profile-step.tsx +191 -0
  219. package/src/components/tax-reports/slovenia-yearly-export-form.tsx +509 -0
  220. package/src/components/tax-reports/slovenia-yearly-review-step.tsx +253 -0
  221. package/src/components/tax-reports/slovenia-yearly-summary.tsx +19 -0
  222. package/src/components/taxes/tax-list-table/tax-list-table.tsx +3 -2
  223. package/src/components/ui/sticky-form-footer.tsx +7 -1
  224. package/src/components/webhook-logs/index.ts +6 -0
  225. package/src/components/webhook-logs/locales.ts +392 -0
  226. package/src/components/webhook-logs/webhook-delivery-detail.tsx +255 -0
  227. package/src/components/webhook-logs/webhook-delivery-list-table.tsx +278 -0
  228. package/src/components/wl-subscription/index.ts +1 -0
  229. package/src/components/wl-subscription/locked-feature.tsx +1 -0
  230. package/src/components/wl-subscription/paywall.tsx +193 -0
  231. package/src/components/wl-subscription/upgrade-modal.tsx +93 -29
  232. package/src/generate-schemas.ts +10 -5
  233. package/src/generated/schemas/customer.ts +2 -0
  234. package/src/generated/schemas/entity.ts +34 -0
  235. package/src/generated/schemas/me.ts +20 -1
  236. package/src/generated/schemas/renderadvanceinvoicepreview_body.ts +40 -34
  237. package/src/generated/schemas/rendercreditnotepreview_body.ts +42 -36
  238. package/src/generated/schemas/renderdeliverynotepreview_body.ts +23 -13
  239. package/src/generated/schemas/renderestimatepreview_body.ts +23 -13
  240. package/src/generated/schemas/renderinvoicepreview_body.ts +40 -34
  241. package/src/generated/schemas/sendemail_body.ts +44 -0
  242. package/src/generated/schemas/startpdfexport_body.ts +91 -1
  243. package/src/generated/schemas/webhook.ts +10 -0
  244. package/src/hooks/use-duplicate-document.ts +51 -13
  245. package/src/hooks/use-eslog-validation.ts +59 -0
  246. package/src/hooks/use-premise-selection.ts +186 -0
  247. package/src/lib/browser-cookies.ts +4 -4
  248. package/src/lib/date-fns-locale.ts +48 -0
  249. package/src/lib/fiscalization-options.ts +81 -0
  250. package/src/lib/locale.ts +38 -0
  251. package/src/lib/template-variables.tsx +1 -1
  252. package/src/lib/translation.ts +14 -3
  253. package/src/providers/entities-context.tsx +1 -0
  254. package/src/providers/entities-provider.tsx +102 -3
  255. package/src/providers/form-footer-context.tsx +37 -4
  256. package/src/providers/sdk-provider.tsx +7 -2
  257. package/src/providers/white-label-provider.tsx +4 -1
  258. package/src/providers/wl-subscription-provider.tsx +90 -3
@@ -12,8 +12,11 @@ import { Skeleton } from "@/ui/components/ui/skeleton";
12
12
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/ui/components/ui/tooltip";
13
13
  import type { CreateAdvanceInvoiceSchema } from "@/ui/generated/schemas";
14
14
  import { createAdvanceInvoiceSchema } from "@/ui/generated/schemas";
15
+ import { useEslogValidation } from "@/ui/hooks/use-eslog-validation";
15
16
  import { useNextDocumentNumber } from "@/ui/hooks/use-next-document-number";
17
+ import { usePremiseSelection } from "@/ui/hooks/use-premise-selection";
16
18
  import { useTransactionTypeCheck } from "@/ui/hooks/use-transaction-type-check";
19
+ import { buildEslogOptions, buildFinaOptions, buildFursOptions } from "@/ui/lib/fiscalization-options";
17
20
  import type { ComponentTranslationProps } from "@/ui/lib/translation";
18
21
  import { createTranslation } from "@/ui/lib/translation";
19
22
  import { cn } from "@/ui/lib/utils";
@@ -31,16 +34,8 @@ import { DocumentRecipientSection } from "../../documents/create/document-recipi
31
34
  import { MarkAsPaidSection } from "../../documents/create/mark-as-paid-section";
32
35
  import { useDocumentCustomerForm } from "../../documents/create/use-document-customer-form";
33
36
  import type { DocumentTypes } from "../../documents/types";
34
- import { useFinaPremises, useFinaSettings } from "../../entities/fina-settings-form/fina-settings.hooks";
35
- import { useFursPremises, useFursSettings } from "../../entities/furs-settings-form/furs-settings.hooks";
36
37
  import { getEntityErrors, getFormFieldErrors, validateEslogForm } from "../../invoices/create/eslog-validation";
37
- import {
38
- getLastUsedFinaCombo,
39
- getLastUsedFursCombo,
40
- setLastUsedFinaCombo,
41
- setLastUsedFursCombo,
42
- useCreateAdvanceInvoice,
43
- } from "../advance-invoices.hooks";
38
+ import { useCreateAdvanceInvoice } from "../advance-invoices.hooks";
44
39
  import de from "./locales/de";
45
40
  import es from "./locales/es";
46
41
  import fr from "./locales/fr";
@@ -112,43 +107,13 @@ export default function CreateAdvanceInvoiceForm({
112
107
  const defaultFooter = (activeEntity?.settings as any)?.document_footer || "";
113
108
 
114
109
  // ============================================================================
115
- // FURS Settings & Premises
110
+ // FURS & FINA Premise Selection (shared hook)
116
111
  // ============================================================================
117
- const { data: fursSettings, isLoading: isFursSettingsLoading } = useFursSettings(entityId);
118
- const { data: fursPremises, isLoading: isFursPremisesLoading } = useFursPremises(entityId, {
119
- enabled: fursSettings?.enabled === true,
120
- });
121
-
122
- // Loading state for FURS - don't render form until we know if FURS is active
123
- const isFursLoading = isFursSettingsLoading || (fursSettings?.enabled && isFursPremisesLoading);
124
-
125
- // Check if FURS is enabled and has active premises
126
- const isFursEnabled = fursSettings?.enabled === true;
127
- const activePremises = useMemo(() => fursPremises?.filter((p) => p.is_active) || [], [fursPremises]);
128
- const hasFursPremises = activePremises.length > 0;
129
-
130
- // FURS premise/device selection state
131
- const [selectedPremiseName, setSelectedPremiseName] = useState<string | undefined>();
132
- const [selectedDeviceName, setSelectedDeviceName] = useState<string | undefined>();
112
+ const furs = usePremiseSelection({ entityId, type: "furs" });
113
+ const fina = usePremiseSelection({ entityId, type: "fina" });
114
+ const eslog = useEslogValidation(activeEntity);
133
115
  const [skipFiscalization, setSkipFiscalization] = useState(false);
134
116
 
135
- // ============================================================================
136
- // FINA Settings & Premises
137
- // ============================================================================
138
- const { data: finaSettings, isLoading: isFinaSettingsLoading } = useFinaSettings(entityId);
139
- const { data: finaPremises, isLoading: isFinaPremisesLoading } = useFinaPremises(entityId, {
140
- enabled: finaSettings?.enabled === true,
141
- });
142
-
143
- const isFinaLoading = isFinaSettingsLoading || (finaSettings?.enabled && isFinaPremisesLoading);
144
- const isFinaEnabled = finaSettings?.enabled === true;
145
- const activeFinaPremises = useMemo(() => finaPremises?.filter((p: any) => p.is_active) || [], [finaPremises]);
146
- const hasFinaPremises = activeFinaPremises.length > 0;
147
-
148
- // FINA premise/device selection state (no skip - all FINA invoices must be fiscalized)
149
- const [selectedFinaBusinessPremiseName, setSelectedFinaBusinessPremiseName] = useState<string | undefined>();
150
- const [selectedFinaElectronicDeviceName, setSelectedFinaElectronicDeviceName] = useState<string | undefined>();
151
-
152
117
  // UI-only state (not part of API schema)
153
118
  const [markAsPaid, setMarkAsPaid] = useState(true);
154
119
  const [paymentTypes, setPaymentTypes] = useState<string[]>(["bank_transfer"]);
@@ -164,129 +129,6 @@ export default function CreateAdvanceInvoiceForm({
164
129
  }, [initialValues?.items]);
165
130
  const priceModesRef = useRef<PriceModesMap>(initialPriceModes);
166
131
 
167
- // ============================================================================
168
- // e-SLOG Settings (Slovenian e-Invoice)
169
- // ============================================================================
170
- const isSlovenianEntity = activeEntity?.country_code === "SI";
171
- const entityEslogEnabled = !!(activeEntity?.settings as any)?.eslog_validation_enabled;
172
- const isEslogAvailable = isSlovenianEntity && entityEslogEnabled;
173
-
174
- // e-SLOG validation state - defaults to entity setting
175
- const [eslogValidationEnabled, setEslogValidationEnabled] = useState<boolean | undefined>(undefined);
176
- // e-SLOG entity-level errors (require settings update, can't be fixed in form)
177
- const [eslogEntityErrors, setEslogEntityErrors] = useState<Array<{ field: string; message: string }>>([]);
178
-
179
- // Initialize e-SLOG state from entity settings
180
- useEffect(() => {
181
- if (isEslogAvailable && eslogValidationEnabled === undefined) {
182
- setEslogValidationEnabled(true);
183
- }
184
- }, [isEslogAvailable, eslogValidationEnabled]);
185
-
186
- // Clear entity errors when eslog validation is disabled
187
- useEffect(() => {
188
- if (!eslogValidationEnabled) {
189
- setEslogEntityErrors([]);
190
- }
191
- }, [eslogValidationEnabled]);
192
-
193
- // Get active devices for selected premise
194
- const activeDevices = useMemo(() => {
195
- if (!selectedPremiseName) return [];
196
- const premise = activePremises.find((p) => p.business_premise_name === selectedPremiseName);
197
- return premise?.Devices?.filter((d) => d.is_active) || [];
198
- }, [activePremises, selectedPremiseName]);
199
-
200
- // Initialize FURS selection from localStorage or first active combo
201
- useEffect(() => {
202
- if (!isFursEnabled || !hasFursPremises || selectedPremiseName) return;
203
-
204
- const lastUsed = getLastUsedFursCombo(entityId);
205
- if (lastUsed) {
206
- // Verify the last-used combo is still valid (premise/device still exist and active)
207
- const premise = activePremises.find((p) => p.business_premise_name === lastUsed.business_premise_name);
208
- const device = premise?.Devices?.find(
209
- (d) => d.electronic_device_name === lastUsed.electronic_device_name && d.is_active,
210
- );
211
- if (premise && device) {
212
- setSelectedPremiseName(lastUsed.business_premise_name);
213
- setSelectedDeviceName(lastUsed.electronic_device_name);
214
- return;
215
- }
216
- }
217
-
218
- // Fall back to first active premise/device
219
- const firstPremise = activePremises[0];
220
- const firstDevice = firstPremise?.Devices?.find((d) => d.is_active);
221
- if (firstPremise && firstDevice) {
222
- setSelectedPremiseName(firstPremise.business_premise_name);
223
- setSelectedDeviceName(firstDevice.electronic_device_name);
224
- }
225
- }, [isFursEnabled, hasFursPremises, activePremises, entityId, selectedPremiseName]);
226
-
227
- // When premise changes, select first active device
228
- useEffect(() => {
229
- if (!selectedPremiseName) return;
230
- const premise = activePremises.find((p) => p.business_premise_name === selectedPremiseName);
231
- const firstDevice = premise?.Devices?.find((d) => d.is_active);
232
- if (firstDevice && selectedDeviceName !== firstDevice.electronic_device_name) {
233
- // Only update if the current device is not in this premise
234
- const currentDeviceInPremise = premise?.Devices?.find(
235
- (d) => d.electronic_device_name === selectedDeviceName && d.is_active,
236
- );
237
- if (!currentDeviceInPremise) {
238
- setSelectedDeviceName(firstDevice.electronic_device_name);
239
- }
240
- }
241
- }, [selectedPremiseName, activePremises, selectedDeviceName]);
242
-
243
- // Get active FINA devices for selected premise
244
- const activeFinaDevices = useMemo(() => {
245
- if (!selectedFinaBusinessPremiseName) return [];
246
- const premise = activeFinaPremises.find((p: any) => p.business_premise_name === selectedFinaBusinessPremiseName);
247
- return premise?.Devices?.filter((d: any) => d.is_active) || [];
248
- }, [activeFinaPremises, selectedFinaBusinessPremiseName]);
249
-
250
- // Initialize FINA selection from localStorage or first active combo
251
- useEffect(() => {
252
- if (!isFinaEnabled || !hasFinaPremises || selectedFinaBusinessPremiseName) return;
253
-
254
- const lastUsed = getLastUsedFinaCombo(entityId);
255
- if (lastUsed) {
256
- const premise = activeFinaPremises.find((p: any) => p.business_premise_name === lastUsed.business_premise_name);
257
- const device = premise?.Devices?.find(
258
- (d: any) => d.electronic_device_name === lastUsed.electronic_device_name && d.is_active,
259
- );
260
- if (premise && device) {
261
- setSelectedFinaBusinessPremiseName(lastUsed.business_premise_name);
262
- setSelectedFinaElectronicDeviceName(lastUsed.electronic_device_name);
263
- return;
264
- }
265
- }
266
-
267
- const firstPremise = activeFinaPremises[0];
268
- const firstDevice = firstPremise?.Devices?.find((d: any) => d.is_active);
269
- if (firstPremise && firstDevice) {
270
- setSelectedFinaBusinessPremiseName(firstPremise.business_premise_name);
271
- setSelectedFinaElectronicDeviceName(firstDevice.electronic_device_name);
272
- }
273
- }, [isFinaEnabled, hasFinaPremises, activeFinaPremises, entityId, selectedFinaBusinessPremiseName]);
274
-
275
- // When FINA premise changes, select first active device
276
- useEffect(() => {
277
- if (!selectedFinaBusinessPremiseName) return;
278
- const premise = activeFinaPremises.find((p: any) => p.business_premise_name === selectedFinaBusinessPremiseName);
279
- const firstDevice = premise?.Devices?.find((d: any) => d.is_active);
280
- if (firstDevice && selectedFinaElectronicDeviceName !== firstDevice.electronic_device_name) {
281
- const currentDeviceInPremise = premise?.Devices?.find(
282
- (d: any) => d.electronic_device_name === selectedFinaElectronicDeviceName && d.is_active,
283
- );
284
- if (!currentDeviceInPremise) {
285
- setSelectedFinaElectronicDeviceName(firstDevice.electronic_device_name);
286
- }
287
- }
288
- }, [selectedFinaBusinessPremiseName, activeFinaPremises, selectedFinaElectronicDeviceName]);
289
-
290
132
  const form = useForm<CreateAdvanceInvoiceFormValues>({
291
133
  // Cast resolver to accept extended form type (includes UI-only fields)
292
134
  resolver: zodResolver(createAdvanceInvoiceSchema) as Resolver<CreateAdvanceInvoiceFormValues>,
@@ -337,34 +179,24 @@ export default function CreateAdvanceInvoiceForm({
337
179
  }
338
180
  }, [canSkipFiscalization, skipFiscalization]);
339
181
 
340
- // Check if FURS selection is ready (needed to prevent number flashing)
341
- const isFursSelectionReady = !isFursEnabled || !hasFursPremises || (!!selectedPremiseName && !!selectedDeviceName);
342
-
343
182
  // FURS is "active" for this advance invoice if enabled and we have a valid selection (and not skipped)
344
- const isFursActive =
345
- isFursEnabled && hasFursPremises && selectedPremiseName && selectedDeviceName && !skipFiscalization;
346
-
347
- // FINA selection ready and active checks
348
- const isFinaSelectionReady =
349
- !isFinaEnabled || !hasFinaPremises || (!!selectedFinaBusinessPremiseName && !!selectedFinaElectronicDeviceName);
350
- const isFinaActive =
351
- isFinaEnabled && hasFinaPremises && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName;
183
+ const isFursActive = furs.isActive && !skipFiscalization;
352
184
 
353
185
  // Update header action with FURS and e-SLOG toggle buttons
354
186
  useEffect(() => {
355
187
  if (!onHeaderActionChange) return;
356
188
 
357
- if (isFursLoading || isFinaLoading) {
189
+ if (furs.isLoading || fina.isLoading) {
358
190
  onHeaderActionChange(null);
359
191
  return;
360
192
  }
361
193
 
362
- const showFursToggle = isFursEnabled && hasFursPremises;
363
- const showEslogToggle = isEslogAvailable;
194
+ const showFursToggle = furs.isEnabled && furs.hasPremises;
195
+ const showEslogToggle = eslog.isAvailable;
364
196
 
365
197
  if (showFursToggle || showEslogToggle) {
366
198
  const isFursChecked = !skipFiscalization;
367
- const isEslogChecked = eslogValidationEnabled === true;
199
+ const isEslogChecked = eslog.isEnabled === true;
368
200
 
369
201
  onHeaderActionChange(
370
202
  <div className="flex items-center gap-2">
@@ -378,7 +210,7 @@ export default function CreateAdvanceInvoiceForm({
378
210
  variant={isEslogChecked ? "outline" : "ghost"}
379
211
  size="sm"
380
212
  className={cn("h-8 cursor-pointer gap-2", !isEslogChecked && "text-muted-foreground")}
381
- onClick={() => setEslogValidationEnabled(!eslogValidationEnabled)}
213
+ onClick={() => eslog.setEnabled(!eslog.isEnabled)}
382
214
  >
383
215
  <div
384
216
  className={cn(
@@ -447,14 +279,15 @@ export default function CreateAdvanceInvoiceForm({
447
279
  onHeaderActionChange(null);
448
280
  }
449
281
  }, [
450
- isFursLoading,
451
- isFinaLoading,
452
- isFursEnabled,
453
- hasFursPremises,
282
+ furs.isLoading,
283
+ fina.isLoading,
284
+ furs.isEnabled,
285
+ furs.hasPremises,
454
286
  skipFiscalization,
455
287
  canSkipFiscalization,
456
- isEslogAvailable,
457
- eslogValidationEnabled,
288
+ eslog.isAvailable,
289
+ eslog.isEnabled,
290
+ eslog.setEnabled,
458
291
  onHeaderActionChange,
459
292
  t,
460
293
  ]);
@@ -462,6 +295,9 @@ export default function CreateAdvanceInvoiceForm({
462
295
  const formValues = useWatch({
463
296
  control: form.control,
464
297
  });
298
+ const onChangeRef = useRef(onChange);
299
+ onChangeRef.current = onChange;
300
+ const prevPayloadRef = useRef("");
465
301
 
466
302
  // ============================================================================
467
303
  // VIES Check - determine if reverse charge applies
@@ -482,35 +318,35 @@ export default function CreateAdvanceInvoiceForm({
482
318
  });
483
319
 
484
320
  // FINA numbering guard: use FINA numbering for domestic transactions (or all if unified numbering is on)
485
- const finaUnifiedNumbering = finaSettings?.unified_numbering !== false;
321
+ const finaUnifiedNumbering = fina.settings?.unified_numbering !== false;
486
322
  const useFinaNumbering =
487
- !!isFinaActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
488
- const isFinaNonDomestic = !!isFinaActive && !useFinaNumbering;
323
+ !!fina.isActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
324
+ const isFinaNonDomestic = !!fina.isActive && !useFinaNumbering;
489
325
 
490
326
  // ============================================================================
491
327
  // Next Advance Invoice Number Preview
492
328
  // ============================================================================
493
329
  // Use same premise/device params for both FURS and FINA (entity is either one, never both)
494
330
  const activePremiseNameForNumber = isFursActive
495
- ? selectedPremiseName
331
+ ? furs.selectedPremiseName
496
332
  : useFinaNumbering
497
- ? selectedFinaBusinessPremiseName
333
+ ? fina.selectedPremiseName
498
334
  : undefined;
499
335
  const activeDeviceNameForNumber = isFursActive
500
- ? selectedDeviceName
336
+ ? furs.selectedDeviceName
501
337
  : useFinaNumbering
502
- ? selectedFinaElectronicDeviceName
338
+ ? fina.selectedDeviceName
503
339
  : undefined;
504
340
 
505
341
  const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "advance_invoice", {
506
342
  businessPremiseName: activePremiseNameForNumber,
507
343
  electronicDeviceName: activeDeviceNameForNumber,
508
- enabled: !!entityId && !isFursLoading && isFursSelectionReady && !isFinaLoading && isFinaSelectionReady,
344
+ enabled: !!entityId && !furs.isLoading && furs.isSelectionReady && !fina.isLoading && fina.isSelectionReady,
509
345
  });
510
346
 
511
347
  // Overall loading state
512
348
  const isFormDataLoading =
513
- isFursLoading || !isFursSelectionReady || isFinaLoading || !isFinaSelectionReady || isNextNumberLoading;
349
+ furs.isLoading || !furs.isSelectionReady || fina.isLoading || !fina.isSelectionReady || isNextNumberLoading;
514
350
 
515
351
  // Pre-fill advance invoice number from preview
516
352
  useEffect(() => {
@@ -547,19 +383,9 @@ export default function CreateAdvanceInvoiceForm({
547
383
  const { mutate: createAdvanceInvoice, isPending } = useCreateAdvanceInvoice({
548
384
  entityId,
549
385
  onSuccess: (data) => {
550
- // Save FURS combo to localStorage on successful creation
551
- if (isFursActive && selectedPremiseName && selectedDeviceName) {
552
- setLastUsedFursCombo(entityId, {
553
- business_premise_name: selectedPremiseName,
554
- electronic_device_name: selectedDeviceName,
555
- });
556
- }
557
- if (isFinaActive && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName) {
558
- setLastUsedFinaCombo(entityId, {
559
- business_premise_name: selectedFinaBusinessPremiseName,
560
- electronic_device_name: selectedFinaElectronicDeviceName,
561
- });
562
- }
386
+ // Save premise combos to localStorage on successful creation
387
+ furs.saveCombo();
388
+ fina.saveCombo();
563
389
  onSuccess?.(data);
564
390
  },
565
391
  onError,
@@ -569,13 +395,13 @@ export default function CreateAdvanceInvoiceForm({
569
395
  const submitAdvanceInvoice = useCallback(
570
396
  (values: CreateAdvanceInvoiceFormValues, isDraft: boolean) => {
571
397
  // Skip e-SLOG and FURS validation for drafts
572
- if (!isDraft && eslogValidationEnabled) {
398
+ if (!isDraft && eslog.isEnabled) {
573
399
  const validationErrors = validateEslogForm(values as any, activeEntity);
574
400
 
575
401
  if (validationErrors.length > 0) {
576
402
  const entityErrors = getEntityErrors(validationErrors);
577
403
  const formErrors = getFormFieldErrors(validationErrors);
578
- setEslogEntityErrors(entityErrors);
404
+ eslog.setEntityErrors(entityErrors);
579
405
  for (const error of formErrors) {
580
406
  form.setError(error.field as any, {
581
407
  type: "eslog",
@@ -584,32 +410,30 @@ export default function CreateAdvanceInvoiceForm({
584
410
  }
585
411
  return;
586
412
  }
587
- setEslogEntityErrors([]);
413
+ eslog.setEntityErrors([]);
588
414
  }
589
415
 
590
- // Build FURS options (skip for drafts)
591
- const fursOptions =
592
- !isDraft && isFursEnabled
593
- ? skipFiscalization
594
- ? { skip: true }
595
- : selectedPremiseName && selectedDeviceName
596
- ? { business_premise_name: selectedPremiseName, electronic_device_name: selectedDeviceName }
597
- : undefined
598
- : undefined;
599
-
600
- // Build e-SLOG options (skip for drafts)
601
- const eslogOptions =
602
- !isDraft && isEslogAvailable ? { validation_enabled: eslogValidationEnabled === true } : undefined;
603
-
604
- // Build FINA options (skip for drafts; FINA can't be skipped)
605
- const finaOptions =
606
- !isDraft && useFinaNumbering && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName
607
- ? {
608
- business_premise_name: selectedFinaBusinessPremiseName,
609
- electronic_device_name: selectedFinaElectronicDeviceName,
610
- payment_type: paymentTypes[0],
611
- }
612
- : undefined;
416
+ const fursOptions = buildFursOptions({
417
+ isDraft,
418
+ isEnabled: furs.isEnabled,
419
+ skipFiscalization,
420
+ premiseName: furs.selectedPremiseName,
421
+ deviceName: furs.selectedDeviceName,
422
+ });
423
+
424
+ const finaOptions = buildFinaOptions({
425
+ isDraft,
426
+ useFinaNumbering,
427
+ premiseName: fina.selectedPremiseName,
428
+ deviceName: fina.selectedDeviceName,
429
+ paymentType: paymentTypes[0],
430
+ });
431
+
432
+ const eslogOptions = buildEslogOptions({
433
+ isDraft,
434
+ isAvailable: eslog.isAvailable,
435
+ isEnabled: eslog.isEnabled,
436
+ });
613
437
 
614
438
  const payload = prepareAdvanceInvoiceSubmission(values, {
615
439
  originalCustomer,
@@ -628,18 +452,14 @@ export default function CreateAdvanceInvoiceForm({
628
452
  [
629
453
  activeEntity,
630
454
  createAdvanceInvoice,
631
- eslogValidationEnabled,
455
+ eslog,
456
+ furs,
457
+ fina,
632
458
  form,
633
- isEslogAvailable,
634
- isFursEnabled,
635
459
  useFinaNumbering,
636
460
  markAsPaid,
637
461
  originalCustomer,
638
462
  paymentTypes,
639
- selectedDeviceName,
640
- selectedPremiseName,
641
- selectedFinaBusinessPremiseName,
642
- selectedFinaElectronicDeviceName,
643
463
  showCustomerForm,
644
464
  skipFiscalization,
645
465
  ],
@@ -697,34 +517,46 @@ export default function CreateAdvanceInvoiceForm({
697
517
  }
698
518
  }, [activeEntity?.is_tax_subject, form]);
699
519
 
520
+ const buildPreviewPayload = useCallback((values: CreateAdvanceInvoiceFormValues): AdvanceInvoicePreviewPayload => {
521
+ const currentItems = values.items || [];
522
+
523
+ const transformedItems = currentItems.map((item: any, index: number) => {
524
+ const { price, ...rest } = item;
525
+ const isGross = priceModesRef.current[index] ?? false;
526
+ return isGross ? { ...rest, gross_price: price } : { ...rest, price };
527
+ });
528
+
529
+ return {
530
+ number: values.number,
531
+ date: values.date,
532
+ customer_id: values.customer_id,
533
+ customer: values.customer,
534
+ items: transformedItems,
535
+ currency_code: values.currency_code,
536
+ reference: values.reference,
537
+ note: values.note,
538
+ signature: values.signature,
539
+ };
540
+ }, []);
541
+
542
+ const emitPreviewPayload = useCallback((payload: AdvanceInvoicePreviewPayload) => {
543
+ const callback = onChangeRef.current;
544
+ if (!callback) return;
545
+
546
+ const payloadStr = JSON.stringify(payload);
547
+ if (payloadStr === prevPayloadRef.current) return;
548
+ prevPayloadRef.current = payloadStr;
549
+
550
+ callback(payload);
551
+ }, []);
552
+
700
553
  useEffect(() => {
701
- if (onChange) {
702
- const currentItems = form.getValues("items") || [];
703
-
704
- // Transform items to use gross_price when price mode is gross
705
- const transformedItems = currentItems.map((item: any, index: number) => {
706
- const { price, ...rest } = item;
707
- const isGross = priceModesRef.current[index] ?? false;
708
- if (isGross) {
709
- return { ...rest, gross_price: price };
710
- }
711
- return { ...rest, price };
712
- });
554
+ emitPreviewPayload(buildPreviewPayload(formValues as CreateAdvanceInvoiceFormValues));
555
+ }, [buildPreviewPayload, emitPreviewPayload, formValues]);
713
556
 
714
- const payload: AdvanceInvoicePreviewPayload = {
715
- number: formValues.number,
716
- date: formValues.date,
717
- customer_id: formValues.customer_id,
718
- customer: formValues.customer,
719
- items: transformedItems,
720
- currency_code: formValues.currency_code,
721
- reference: formValues.reference,
722
- note: formValues.note,
723
- signature: formValues.signature,
724
- };
725
- onChange(payload);
726
- }
727
- }, [formValues, onChange, form]);
557
+ const emitCurrentPreviewPayload = useCallback(() => {
558
+ emitPreviewPayload(buildPreviewPayload(form.getValues()));
559
+ }, [buildPreviewPayload, emitPreviewPayload, form]);
728
560
 
729
561
  const onSubmit = (values: CreateAdvanceInvoiceFormValues) => {
730
562
  submitAdvanceInvoice(values, false);
@@ -790,14 +622,14 @@ export default function CreateAdvanceInvoiceForm({
790
622
  <Form {...form}>
791
623
  <form id="create-advance-invoice-form" onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
792
624
  {/* e-SLOG entity-level validation errors */}
793
- {eslogEntityErrors.length > 0 && (
625
+ {eslog.entityErrors.length > 0 && (
794
626
  <Alert variant="destructive">
795
627
  <AlertCircle className="h-4 w-4" />
796
628
  <AlertTitle>{t("e-SLOG Validation Failed")}</AlertTitle>
797
629
  <AlertDescription>
798
630
  <p className="mb-2">{t("The following entity settings need to be updated:")}</p>
799
631
  <ul className="list-disc space-y-1 pl-4">
800
- {eslogEntityErrors.map((error) => (
632
+ {eslog.entityErrors.map((error) => (
801
633
  <li key={error.field} className="text-sm">
802
634
  {error.message}
803
635
  </li>
@@ -824,14 +656,20 @@ export default function CreateAdvanceInvoiceForm({
824
656
  documentType={_type}
825
657
  t={t}
826
658
  fursInline={
827
- isFursEnabled && hasFursPremises
659
+ furs.isEnabled && furs.hasPremises
828
660
  ? {
829
- premises: activePremises.map((p) => ({ id: p.id, business_premise_name: p.business_premise_name })),
830
- devices: activeDevices.map((d) => ({ id: d.id, electronic_device_name: d.electronic_device_name })),
831
- selectedPremise: selectedPremiseName,
832
- selectedDevice: selectedDeviceName,
833
- onPremiseChange: setSelectedPremiseName,
834
- onDeviceChange: setSelectedDeviceName,
661
+ premises: furs.activePremises.map((p) => ({
662
+ id: p.id,
663
+ business_premise_name: p.business_premise_name,
664
+ })),
665
+ devices: furs.activeDevices.map((d) => ({
666
+ id: (d as any).id,
667
+ electronic_device_name: d.electronic_device_name,
668
+ })),
669
+ selectedPremise: furs.selectedPremiseName,
670
+ selectedDevice: furs.selectedDeviceName,
671
+ onPremiseChange: furs.setSelectedPremiseName,
672
+ onDeviceChange: furs.setSelectedDeviceName,
835
673
  isSkipped: skipFiscalization,
836
674
  }
837
675
  : undefined
@@ -839,18 +677,18 @@ export default function CreateAdvanceInvoiceForm({
839
677
  finaInline={
840
678
  useFinaNumbering
841
679
  ? {
842
- premises: activeFinaPremises.map((p: any) => ({
680
+ premises: fina.activePremises.map((p: any) => ({
843
681
  id: p.id,
844
682
  business_premise_name: p.business_premise_name,
845
683
  })),
846
- devices: activeFinaDevices.map((d: any) => ({
684
+ devices: fina.activeDevices.map((d: any) => ({
847
685
  id: d.id,
848
686
  electronic_device_name: d.electronic_device_name,
849
687
  })),
850
- selectedPremise: selectedFinaBusinessPremiseName,
851
- selectedDevice: selectedFinaElectronicDeviceName,
852
- onPremiseChange: setSelectedFinaBusinessPremiseName,
853
- onDeviceChange: setSelectedFinaElectronicDeviceName,
688
+ selectedPremise: fina.selectedPremiseName,
689
+ selectedDevice: fina.selectedDeviceName,
690
+ onPremiseChange: fina.setSelectedPremiseName,
691
+ onDeviceChange: fina.setSelectedDeviceName,
854
692
  }
855
693
  : undefined
856
694
  }
@@ -862,7 +700,7 @@ export default function CreateAdvanceInvoiceForm({
862
700
  paymentTypes={paymentTypes}
863
701
  onPaymentTypesChange={setPaymentTypes}
864
702
  t={t}
865
- alwaysShowPaymentType={!!isFinaActive}
703
+ alwaysShowPaymentType={!!fina.isActive}
866
704
  forced
867
705
  />
868
706
  </DocumentDetailsSection>
@@ -884,6 +722,7 @@ export default function CreateAdvanceInvoiceForm({
884
722
  maxTaxesPerItem={activeEntity?.country_rules?.max_taxes_per_item}
885
723
  priceModesRef={priceModesRef}
886
724
  initialPriceModes={initialPriceModes}
725
+ onItemsStateChange={emitCurrentPreviewPayload}
887
726
  />
888
727
 
889
728
  <DocumentNoteField
@@ -4,6 +4,7 @@ import { useCallback, useMemo, useState } from "react";
4
4
  import { DataTable } from "@/ui/components/table/data-table";
5
5
  import { FormattedDate } from "@/ui/components/table/date-cell";
6
6
  import { useTableFetch } from "@/ui/components/table/hooks/use-table-fetch";
7
+ import { withTableTranslations } from "@/ui/components/table/locales";
7
8
  import { SelectionToolbar } from "@/ui/components/table/selection-toolbar";
8
9
  import type {
9
10
  Column,
@@ -31,7 +32,7 @@ import pl from "./locales/pl";
31
32
  import pt from "./locales/pt";
32
33
  import sl from "./locales/sl";
33
34
 
34
- const translations = {
35
+ const translations = withTableTranslations({
35
36
  en,
36
37
  sl,
37
38
  de,
@@ -42,12 +43,13 @@ const translations = {
42
43
  nl,
43
44
  pl,
44
45
  hr,
45
- } as const;
46
+ } as const);
46
47
 
47
48
  type AdvanceInvoiceListTableProps = {
48
49
  t?: (key: string) => string;
49
50
  namespace?: string;
50
51
  locale?: string;
52
+ translationLocale?: string;
51
53
  entityId?: string;
52
54
  onView?: (advanceInvoice: AdvanceInvoice) => void;
53
55
  onAddPayment?: (advanceInvoice: AdvanceInvoice) => void;
@@ -86,6 +88,7 @@ export default function AdvanceInvoiceListTable({
86
88
  }: AdvanceInvoiceListTableProps) {
87
89
  const t = createTranslation({
88
90
  translations,
91
+ locale: i18nProps.translationLocale ?? i18nProps.locale,
89
92
  ...i18nProps,
90
93
  });
91
94
 
@@ -149,11 +152,15 @@ export default function AdvanceInvoiceListTable({
149
152
  const someFailed = failedCount > 0 && failedCount < selectedDocs.length;
150
153
  const showRetry = hasRetry && failedCount > 0;
151
154
 
155
+ const hasDrafts = selectedDocs.some((d) => (d as any).is_draft);
156
+
152
157
  return (
153
158
  <SelectionToolbar
154
159
  selectedCount={count}
155
160
  onExportPdfs={onExportSelected ? handleExportPdfs : undefined}
156
161
  onCopyToInvoice={onCopyToInvoice ? handleCopyToInvoice : undefined}
162
+ copyToInvoiceDisabled={hasDrafts}
163
+ copyToInvoiceTooltip={hasDrafts ? t("Finalize draft documents before copying to invoice") : undefined}
157
164
  onRetryFiscalization={showRetry ? () => onRetryFiscalization(failedDocs.map((d) => d.id)) : undefined}
158
165
  retryFiscalizationDisabled={someFailed && !allFailed}
159
166
  retryFiscalizationTooltip={
@@ -224,7 +231,7 @@ export default function AdvanceInvoiceListTable({
224
231
  {
225
232
  id: "date",
226
233
  header: t("Date"),
227
- cell: (advanceInvoice) => <FormattedDate date={advanceInvoice.date} />,
234
+ cell: (advanceInvoice) => <FormattedDate date={advanceInvoice.date} locale={i18nProps.locale} />,
228
235
  },
229
236
  {
230
237
  id: "total",