@spaceinvoices/react-ui 0.4.8 → 0.4.11
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.
- package/README.md +24 -8
- package/cli/dist/index.js +89 -26
- package/package.json +4 -1
- package/spaceinvoices.schema.json +6 -1
- package/src/common/autocomplete.tsx +69 -6
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +124 -285
- package/src/components/advance-invoices/list/list-table.tsx +10 -3
- package/src/components/advance-invoices/list/locales/de.ts +2 -0
- package/src/components/advance-invoices/list/locales/en.ts +1 -0
- package/src/components/advance-invoices/list/locales/es.ts +1 -0
- package/src/components/advance-invoices/list/locales/fr.ts +1 -0
- package/src/components/advance-invoices/list/locales/hr.ts +1 -0
- package/src/components/advance-invoices/list/locales/it.ts +1 -0
- package/src/components/advance-invoices/list/locales/nl.ts +1 -0
- package/src/components/advance-invoices/list/locales/pl.ts +1 -0
- package/src/components/advance-invoices/list/locales/pt.ts +1 -0
- package/src/components/advance-invoices/list/locales/sl.ts +1 -0
- package/src/components/advance-invoices/list/use-advance-invoice-download.ts +1 -12
- package/src/components/credit-notes/create/create-credit-note-form.tsx +116 -238
- package/src/components/credit-notes/list/list-table.tsx +6 -3
- package/src/components/credit-notes/list/use-credit-note-download.ts +1 -12
- package/src/components/customers/customer-autocomplete.tsx +64 -11
- package/src/components/customers/customer-list-table/customer-list-table.tsx +3 -2
- package/src/components/dashboard/collection-rate-card/collection-rate-card.tsx +9 -1
- package/src/components/dashboard/collection-rate-card/locales/bg.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/cs.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/et.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/fi.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/is.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/nb.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/sk.ts +3 -0
- package/src/components/dashboard/collection-rate-card/locales/sv.ts +3 -0
- package/src/components/dashboard/invoice-status-chart/invoice-status-chart.tsx +10 -2
- package/src/components/dashboard/invoice-status-chart/locales/bg.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/cs.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/de.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/es.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/et.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/fi.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/fr.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/hr.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/is.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/it.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/nb.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/nl.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/pl.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/pt.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/sk.ts +10 -0
- package/src/components/dashboard/invoice-status-chart/locales/sl.ts +1 -0
- package/src/components/dashboard/invoice-status-chart/locales/sv.ts +10 -0
- package/src/components/dashboard/payment-methods-chart/locales/bg.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/cs.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/et.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/fi.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/is.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/nb.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/sk.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/locales/sv.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/payment-methods-chart.tsx +9 -1
- package/src/components/dashboard/payment-trend-chart/locales/bg.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/cs.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/de.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/es.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/et.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/fi.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/fr.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/hr.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/is.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/it.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/nb.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/nl.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/pl.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/pt.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/sk.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/locales/sl.ts +1 -0
- package/src/components/dashboard/payment-trend-chart/locales/sv.ts +6 -0
- package/src/components/dashboard/payment-trend-chart/payment-trend-chart.tsx +15 -8
- package/src/components/dashboard/revenue-trend-chart/locales/bg.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/cs.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/de.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/es.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/et.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/fi.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/fr.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/hr.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/is.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/it.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/nb.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/nl.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/pl.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/pt.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sk.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sl.ts +1 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sv.ts +6 -0
- package/src/components/dashboard/revenue-trend-chart/revenue-trend-chart.tsx +15 -8
- package/src/components/dashboard/tax-collected-card/locales.ts +110 -0
- package/src/components/dashboard/tax-collected-card/tax-collected-card.tsx +8 -2
- package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +4 -4
- package/src/components/dashboard/top-customers-chart/locales/bg.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/cs.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/de.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/es.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/et.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/fi.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/fr.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/hr.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/is.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/it.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/nb.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/nl.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/pl.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/pt.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/sk.ts +7 -0
- package/src/components/dashboard/top-customers-chart/locales/sl.ts +2 -0
- package/src/components/dashboard/top-customers-chart/locales/sv.ts +7 -0
- package/src/components/dashboard/top-customers-chart/top-customers-chart.tsx +23 -12
- package/src/components/delivery-notes/create/create-delivery-note-form.tsx +33 -20
- package/src/components/delivery-notes/list/list-table.tsx +22 -13
- package/src/components/delivery-notes/list/locales/de.ts +2 -0
- package/src/components/delivery-notes/list/locales/en.ts +1 -0
- package/src/components/delivery-notes/list/locales/es.ts +1 -0
- package/src/components/delivery-notes/list/locales/fr.ts +1 -0
- package/src/components/delivery-notes/list/locales/hr.ts +1 -0
- package/src/components/delivery-notes/list/locales/it.ts +1 -0
- package/src/components/delivery-notes/list/locales/nl.ts +1 -0
- package/src/components/delivery-notes/list/locales/pl.ts +1 -0
- package/src/components/delivery-notes/list/locales/pt.ts +1 -0
- package/src/components/delivery-notes/list/locales/sl.ts +1 -0
- package/src/components/delivery-notes/list/use-delivery-note-download.ts +1 -12
- package/src/components/documents/create/document-add-item-form.tsx +28 -16
- package/src/components/documents/create/document-add-item-tax-rate-field.tsx +12 -2
- package/src/components/documents/create/document-items-section.tsx +70 -39
- package/src/components/documents/create/document-recipient-section.tsx +10 -1
- package/src/components/documents/create/live-preview.tsx +113 -15
- package/src/components/documents/create/prepare-document-submission.ts +35 -16
- package/src/components/documents/create/use-document-customer-form.ts +14 -3
- package/src/components/documents/documents.hooks.ts +7 -2
- package/src/components/documents/shared/document-preview-display.tsx +136 -67
- package/src/components/documents/shared/scaled-document-preview.tsx +45 -5
- package/src/components/documents/view/document-actions-bar.tsx +284 -182
- package/src/components/documents/view/document-activities-list.tsx +3 -0
- package/src/components/documents/view/document-payments-list.tsx +3 -0
- package/src/components/documents/view/locales/de.ts +8 -0
- package/src/components/documents/view/locales/es.ts +8 -0
- package/src/components/documents/view/locales/fr.ts +8 -0
- package/src/components/documents/view/locales/hr.ts +8 -0
- package/src/components/documents/view/locales/it.ts +8 -0
- package/src/components/documents/view/locales/nl.ts +8 -0
- package/src/components/documents/view/locales/pl.ts +8 -0
- package/src/components/documents/view/locales/pt.ts +8 -0
- package/src/components/documents/view/locales/sl.ts +8 -0
- package/src/components/documents/view/use-document-download.ts +14 -25
- package/src/components/entities/create-entity-form.tsx +101 -16
- package/src/components/entities/entity-settings-form/entity-settings-form.tsx +10 -10
- package/src/components/entities/entity-settings-form/locales/de.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/es.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/fr.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/hr.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/it.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/nl.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/pl.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/pt.ts +10 -0
- package/src/components/entities/entity-settings-form/locales/sl.ts +10 -0
- package/src/components/entities/fina-settings-form/fina-operator-required-dialog.tsx +3 -3
- package/src/components/entities/fina-settings-form/fina-settings-form.tsx +78 -124
- package/src/components/entities/fina-settings-form/sections/certificate-settings-section.tsx +8 -1
- package/src/components/entities/fina-settings-form/sections/premises-management-section.tsx +14 -2
- package/src/components/entities/fina-settings-form/sections/register-premise-dialog.tsx +7 -2
- package/src/components/entities/furs-settings-form/furs-settings-form.tsx +56 -130
- package/src/components/entities/furs-settings-form/sections/certificate-settings-section.tsx +8 -1
- package/src/components/entities/furs-settings-form/sections/enable-fiscalization-section.tsx +1 -0
- package/src/components/entities/furs-settings-form/sections/general-settings-section.tsx +15 -2
- package/src/components/entities/furs-settings-form/sections/premises-management-section.tsx +20 -3
- package/src/components/entities/furs-settings-form/sections/register-premise-dialog.tsx +38 -12
- package/src/components/entities/settings/defaults-settings-form.tsx +6 -6
- package/src/components/entities/settings/eslog-settings-form.tsx +13 -1
- package/src/components/entities/settings/pdf-template-selector/demo-invoice-data.ts +3 -22
- package/src/components/entities/shared/fiscalization-step-flow.ts +77 -0
- package/src/components/entities/shared/fiscalization-step-tabs.tsx +71 -0
- package/src/components/estimates/create/create-estimate-form.tsx +34 -21
- package/src/components/estimates/list/list-table.tsx +23 -14
- package/src/components/estimates/list/locales/de.ts +2 -0
- package/src/components/estimates/list/locales/en.ts +1 -0
- package/src/components/estimates/list/locales/es.ts +1 -0
- package/src/components/estimates/list/locales/fr.ts +1 -0
- package/src/components/estimates/list/locales/hr.ts +1 -0
- package/src/components/estimates/list/locales/it.ts +1 -0
- package/src/components/estimates/list/locales/nl.ts +1 -0
- package/src/components/estimates/list/locales/pl.ts +1 -0
- package/src/components/estimates/list/locales/pt.ts +1 -0
- package/src/components/estimates/list/locales/sl.ts +1 -0
- package/src/components/estimates/list/use-estimate-download.ts +1 -12
- package/src/components/export/document-export-form.tsx +33 -7
- package/src/components/export/sales-per-item-export-form.tsx +23 -7
- package/src/components/invoices/create/create-invoice-form.tsx +295 -329
- package/src/components/invoices/create/prepare-invoice-submission.ts +0 -8
- package/src/components/invoices/list/list-table.tsx +7 -4
- package/src/components/invoices/list/use-invoice-download.ts +1 -11
- package/src/components/invoices/send-email-dialog/locales/de.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/es.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/fr.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/hr.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/it.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/nl.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/pl.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/pt.ts +20 -0
- package/src/components/invoices/send-email-dialog/locales/sl.ts +20 -0
- package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +77 -8
- package/src/components/invoices/view/eslog-info-display.tsx +17 -1
- package/src/components/invoices/view/fiscalization-status-card.tsx +7 -3
- package/src/components/items/item-combobox.tsx +26 -6
- package/src/components/items/item-list-table/item-list-table.tsx +5 -2
- package/src/components/payments/create-payment-form/index.ts +1 -0
- package/src/components/payments/list/list-table.tsx +14 -4
- package/src/components/recurring-invoices/list/list-table.tsx +7 -4
- package/src/components/request-logs/locales.ts +412 -0
- package/src/components/request-logs/request-log-detail.tsx +37 -21
- package/src/components/request-logs/request-log-list-table.tsx +57 -11
- package/src/components/table/data-table.tsx +5 -2
- package/src/components/table/date-cell.tsx +3 -1
- package/src/components/table/filter-bar.tsx +14 -2
- package/src/components/table/hooks/use-table-query.ts +1 -1
- package/src/components/table/locales.ts +1116 -0
- package/src/components/table/search-input.tsx +12 -3
- package/src/components/table/selection-toolbar.tsx +23 -6
- package/src/components/table/table-empty-state.tsx +43 -3
- package/src/components/table/table-no-results.tsx +3 -3
- package/src/components/table/table-pagination.tsx +4 -3
- package/src/components/table/types.ts +1 -0
- package/src/components/tax-reports/index.ts +1 -0
- package/src/components/tax-reports/kir-export-form.tsx +46 -8
- package/src/components/tax-reports/slovenia-tax-profile-step.tsx +191 -0
- package/src/components/tax-reports/slovenia-yearly-export-form.tsx +509 -0
- package/src/components/tax-reports/slovenia-yearly-review-step.tsx +253 -0
- package/src/components/tax-reports/slovenia-yearly-summary.tsx +19 -0
- package/src/components/taxes/tax-list-table/tax-list-table.tsx +3 -2
- package/src/components/ui/sidebar.tsx +3 -2
- package/src/components/ui/sticky-form-footer.tsx +7 -1
- package/src/components/webhook-logs/index.ts +6 -0
- package/src/components/webhook-logs/locales.ts +392 -0
- package/src/components/webhook-logs/webhook-delivery-detail.tsx +255 -0
- package/src/components/webhook-logs/webhook-delivery-list-table.tsx +278 -0
- package/src/components/wl-subscription/index.ts +1 -0
- package/src/components/wl-subscription/locked-feature.tsx +1 -0
- package/src/components/wl-subscription/paywall.tsx +193 -0
- package/src/components/wl-subscription/upgrade-modal.tsx +93 -29
- package/src/generate-schemas.ts +12 -7
- package/src/generated/schemas/customer.ts +2 -0
- package/src/generated/schemas/entity.ts +134 -0
- package/src/generated/schemas/exportsloveniayearlynormiranireport_body.ts +27 -0
- package/src/generated/schemas/index.ts +2 -0
- package/src/generated/schemas/me.ts +20 -1
- package/src/generated/schemas/renderadvanceinvoicepreview_body.ts +40 -34
- package/src/generated/schemas/rendercreditnotepreview_body.ts +42 -36
- package/src/generated/schemas/renderdeliverynotepreview_body.ts +23 -13
- package/src/generated/schemas/renderestimatepreview_body.ts +23 -13
- package/src/generated/schemas/renderinvoicepreview_body.ts +40 -34
- package/src/generated/schemas/sendemail_body.ts +44 -0
- package/src/generated/schemas/sloveniataxprofile.ts +42 -0
- package/src/generated/schemas/startpdfexport_body.ts +91 -1
- package/src/generated/schemas/webhook.ts +10 -0
- package/src/hooks/use-duplicate-document.ts +51 -13
- package/src/hooks/use-eslog-validation.ts +59 -0
- package/src/hooks/use-premise-selection.ts +186 -0
- package/src/lib/browser-cookies.ts +4 -4
- package/src/lib/date-fns-locale.ts +48 -0
- package/src/lib/fiscalization-options.ts +81 -0
- package/src/lib/locale.ts +38 -0
- package/src/lib/template-variables.tsx +1 -1
- package/src/lib/translation.ts +14 -3
- package/src/providers/entities-context.tsx +1 -0
- package/src/providers/entities-provider.tsx +102 -3
- package/src/providers/form-footer-context.tsx +37 -4
- package/src/providers/sdk-provider.tsx +7 -2
- package/src/providers/white-label-provider.tsx +4 -1
- 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
|
|
110
|
+
// FURS & FINA Premise Selection (shared hook)
|
|
116
111
|
// ============================================================================
|
|
117
|
-
const {
|
|
118
|
-
const {
|
|
119
|
-
|
|
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 (
|
|
189
|
+
if (furs.isLoading || fina.isLoading) {
|
|
358
190
|
onHeaderActionChange(null);
|
|
359
191
|
return;
|
|
360
192
|
}
|
|
361
193
|
|
|
362
|
-
const showFursToggle =
|
|
363
|
-
const showEslogToggle =
|
|
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 =
|
|
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={() =>
|
|
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
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
282
|
+
furs.isLoading,
|
|
283
|
+
fina.isLoading,
|
|
284
|
+
furs.isEnabled,
|
|
285
|
+
furs.hasPremises,
|
|
454
286
|
skipFiscalization,
|
|
455
287
|
canSkipFiscalization,
|
|
456
|
-
|
|
457
|
-
|
|
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 =
|
|
321
|
+
const finaUnifiedNumbering = fina.settings?.unified_numbering !== false;
|
|
486
322
|
const useFinaNumbering =
|
|
487
|
-
!!
|
|
488
|
-
const isFinaNonDomestic = !!
|
|
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
|
-
?
|
|
333
|
+
? fina.selectedPremiseName
|
|
498
334
|
: undefined;
|
|
499
335
|
const activeDeviceNameForNumber = isFursActive
|
|
500
|
-
? selectedDeviceName
|
|
336
|
+
? furs.selectedDeviceName
|
|
501
337
|
: useFinaNumbering
|
|
502
|
-
?
|
|
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 && !
|
|
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
|
-
|
|
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
|
|
551
|
-
|
|
552
|
-
|
|
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 &&
|
|
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
|
-
|
|
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
|
-
|
|
413
|
+
eslog.setEntityErrors([]);
|
|
588
414
|
}
|
|
589
415
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
|
|
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
|
-
|
|
702
|
-
|
|
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
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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
|
-
|
|
659
|
+
furs.isEnabled && furs.hasPremises
|
|
828
660
|
? {
|
|
829
|
-
premises: activePremises.map((p) => ({
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
851
|
-
selectedDevice:
|
|
852
|
-
onPremiseChange:
|
|
853
|
-
onDeviceChange:
|
|
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={!!
|
|
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",
|