@spaceinvoices/react-ui 0.4.6 → 0.4.8

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 (100) hide show
  1. package/cli/dist/index.js +1 -1
  2. package/package.json +1 -1
  3. package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +60 -44
  4. package/src/components/advance-invoices/create/locales/de.ts +2 -1
  5. package/src/components/advance-invoices/create/locales/es.ts +2 -1
  6. package/src/components/advance-invoices/create/locales/fr.ts +2 -1
  7. package/src/components/advance-invoices/create/locales/hr.ts +2 -1
  8. package/src/components/advance-invoices/create/locales/it.ts +2 -1
  9. package/src/components/advance-invoices/create/locales/nl.ts +2 -1
  10. package/src/components/advance-invoices/create/locales/pl.ts +2 -1
  11. package/src/components/advance-invoices/create/locales/pt.ts +2 -1
  12. package/src/components/advance-invoices/create/locales/sl.ts +2 -1
  13. package/src/components/credit-notes/create/create-credit-note-form.tsx +52 -42
  14. package/src/components/credit-notes/create/locales/de.ts +2 -1
  15. package/src/components/credit-notes/create/locales/es.ts +2 -1
  16. package/src/components/credit-notes/create/locales/fr.ts +2 -1
  17. package/src/components/credit-notes/create/locales/hr.ts +2 -1
  18. package/src/components/credit-notes/create/locales/it.ts +2 -1
  19. package/src/components/credit-notes/create/locales/nl.ts +2 -1
  20. package/src/components/credit-notes/create/locales/pl.ts +2 -1
  21. package/src/components/credit-notes/create/locales/pt.ts +2 -1
  22. package/src/components/credit-notes/create/locales/sl.ts +2 -1
  23. package/src/components/dashboard/collection-rate-card/use-collection-rate.ts +48 -92
  24. package/src/components/dashboard/invoice-status-chart/use-invoice-status.ts +48 -82
  25. package/src/components/dashboard/payment-methods-chart/use-payment-methods.ts +22 -31
  26. package/src/components/dashboard/payment-trend-chart/use-payment-trend.ts +33 -48
  27. package/src/components/dashboard/revenue-trend-chart/use-revenue-trend.ts +56 -76
  28. package/src/components/dashboard/shared/index.ts +1 -1
  29. package/src/components/dashboard/shared/use-revenue-data.ts +106 -182
  30. package/src/components/dashboard/shared/use-stats-counts.ts +18 -68
  31. package/src/components/dashboard/shared/use-stats-query.ts +35 -5
  32. package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +57 -75
  33. package/src/components/dashboard/top-customers-chart/use-top-customers.ts +38 -49
  34. package/src/components/delivery-notes/create/create-delivery-note-form.tsx +3 -2
  35. package/src/components/delivery-notes/create/locales/de.ts +2 -1
  36. package/src/components/delivery-notes/create/locales/es.ts +2 -1
  37. package/src/components/delivery-notes/create/locales/fr.ts +2 -1
  38. package/src/components/delivery-notes/create/locales/hr.ts +2 -1
  39. package/src/components/delivery-notes/create/locales/it.ts +2 -1
  40. package/src/components/delivery-notes/create/locales/nl.ts +2 -1
  41. package/src/components/delivery-notes/create/locales/pl.ts +2 -1
  42. package/src/components/delivery-notes/create/locales/pt.ts +2 -1
  43. package/src/components/delivery-notes/create/locales/sl.ts +2 -1
  44. package/src/components/documents/create/document-details-section.tsx +6 -4
  45. package/src/components/documents/create/document-recipient-section.tsx +30 -1
  46. package/src/components/documents/create/live-preview.tsx +15 -28
  47. package/src/components/documents/create/prepare-document-submission.ts +1 -0
  48. package/src/components/documents/create/use-document-customer-form.ts +4 -0
  49. package/src/components/documents/shared/document-preview-skeleton.tsx +63 -0
  50. package/src/components/documents/shared/index.ts +1 -0
  51. package/src/components/documents/view/document-actions-bar.tsx +29 -7
  52. package/src/components/entities/entity-settings-form/locales/de.ts +6 -3
  53. package/src/components/entities/entity-settings-form/locales/es.ts +6 -3
  54. package/src/components/entities/entity-settings-form/locales/fr.ts +6 -3
  55. package/src/components/entities/entity-settings-form/locales/hr.ts +4 -2
  56. package/src/components/entities/entity-settings-form/locales/it.ts +6 -3
  57. package/src/components/entities/entity-settings-form/locales/nl.ts +6 -3
  58. package/src/components/entities/entity-settings-form/locales/pl.ts +6 -2
  59. package/src/components/entities/entity-settings-form/locales/pt.ts +6 -3
  60. package/src/components/entities/entity-settings-form/locales/sl.ts +4 -2
  61. package/src/components/entities/settings/tax-rules-settings-form.tsx +31 -13
  62. package/src/components/estimates/create/create-estimate-form.tsx +3 -2
  63. package/src/components/estimates/create/locales/de.ts +2 -1
  64. package/src/components/estimates/create/locales/es.ts +2 -1
  65. package/src/components/estimates/create/locales/fr.ts +2 -1
  66. package/src/components/estimates/create/locales/hr.ts +2 -1
  67. package/src/components/estimates/create/locales/it.ts +2 -1
  68. package/src/components/estimates/create/locales/nl.ts +2 -1
  69. package/src/components/estimates/create/locales/pl.ts +2 -1
  70. package/src/components/estimates/create/locales/pt.ts +2 -1
  71. package/src/components/estimates/create/locales/sl.ts +2 -1
  72. package/src/components/invoices/create/create-invoice-form.tsx +134 -62
  73. package/src/components/invoices/create/locales/de.ts +8 -1
  74. package/src/components/invoices/create/locales/es.ts +8 -1
  75. package/src/components/invoices/create/locales/fr.ts +8 -1
  76. package/src/components/invoices/create/locales/hr.ts +8 -1
  77. package/src/components/invoices/create/locales/it.ts +8 -1
  78. package/src/components/invoices/create/locales/nl.ts +8 -1
  79. package/src/components/invoices/create/locales/pl.ts +8 -1
  80. package/src/components/invoices/create/locales/pt.ts +8 -1
  81. package/src/components/invoices/create/locales/sl.ts +8 -1
  82. package/src/components/invoices/invoices.hooks.ts +1 -1
  83. package/src/components/ui/progress.tsx +27 -0
  84. package/src/generate-schemas.ts +15 -2
  85. package/src/generated/schemas/advanceinvoice.ts +2 -0
  86. package/src/generated/schemas/creditnote.ts +2 -0
  87. package/src/generated/schemas/customer.ts +2 -0
  88. package/src/generated/schemas/deliverynote.ts +2 -0
  89. package/src/generated/schemas/entity.ts +10 -0
  90. package/src/generated/schemas/estimate.ts +2 -0
  91. package/src/generated/schemas/finasettings.ts +4 -3
  92. package/src/generated/schemas/invoice.ts +2 -0
  93. package/src/generated/schemas/renderadvanceinvoicepreview_body.ts +16 -10
  94. package/src/generated/schemas/rendercreditnotepreview_body.ts +16 -10
  95. package/src/generated/schemas/renderdeliverynotepreview_body.ts +14 -7
  96. package/src/generated/schemas/renderestimatepreview_body.ts +14 -7
  97. package/src/generated/schemas/renderinvoicepreview_body.ts +16 -10
  98. package/src/generated/schemas/startpdfexport_body.ts +12 -17
  99. package/src/hooks/use-transaction-type-check.ts +152 -0
  100. package/src/hooks/use-vies-check.ts +7 -131
package/cli/dist/index.js CHANGED
@@ -870,7 +870,7 @@ async function list(options = {}) {
870
870
 
871
871
  // cli/src/index.ts
872
872
  var program = new Command();
873
- program.name("spaceinvoices-ui").description("CLI for adding Space Invoices React UI components to your project").version("0.4.6");
873
+ program.name("spaceinvoices-ui").description("CLI for adding Space Invoices React UI components to your project").version("0.4.8");
874
874
  program.option("--local <path>", "Use local registry from specified path (for development)");
875
875
  program.command("init").description("Initialize Space Invoices UI in your project").option("-y, --yes", "Skip prompts and use defaults").option("-f, --force", "Overwrite existing configuration").option("--cwd <path>", "Working directory (defaults to current directory)").action(async (options) => {
876
876
  const globalOpts = program.opts();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spaceinvoices/react-ui",
3
3
  "type": "module",
4
- "version": "0.4.6",
4
+ "version": "0.4.8",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "description": "Space Invoices UI components - copy-paste distribution with CLI support",
@@ -13,7 +13,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/ui/c
13
13
  import type { CreateAdvanceInvoiceSchema } from "@/ui/generated/schemas";
14
14
  import { createAdvanceInvoiceSchema } from "@/ui/generated/schemas";
15
15
  import { useNextDocumentNumber } from "@/ui/hooks/use-next-document-number";
16
- import { useViesCheck } from "@/ui/hooks/use-vies-check";
16
+ import { useTransactionTypeCheck } from "@/ui/hooks/use-transaction-type-check";
17
17
  import type { ComponentTranslationProps } from "@/ui/lib/translation";
18
18
  import { createTranslation } from "@/ui/lib/translation";
19
19
  import { cn } from "@/ui/lib/utils";
@@ -350,19 +350,6 @@ export default function CreateAdvanceInvoiceForm({
350
350
  const isFinaActive =
351
351
  isFinaEnabled && hasFinaPremises && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName;
352
352
 
353
- // ============================================================================
354
- // Next Advance Invoice Number Preview
355
- // ============================================================================
356
- const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "advance_invoice", {
357
- businessPremiseName: isFursActive ? selectedPremiseName : undefined,
358
- electronicDeviceName: isFursActive ? selectedDeviceName : undefined,
359
- enabled: !!entityId && !isFursLoading && isFursSelectionReady && !isFinaLoading && isFinaSelectionReady,
360
- });
361
-
362
- // Overall loading state
363
- const isFormDataLoading =
364
- isFursLoading || !isFursSelectionReady || isFinaLoading || !isFinaSelectionReady || isNextNumberLoading;
365
-
366
353
  // Update header action with FURS and e-SLOG toggle buttons
367
354
  useEffect(() => {
368
355
  if (!onHeaderActionChange) return;
@@ -472,13 +459,6 @@ export default function CreateAdvanceInvoiceForm({
472
459
  t,
473
460
  ]);
474
461
 
475
- // Pre-fill advance invoice number from preview
476
- useEffect(() => {
477
- if (nextNumberData?.number) {
478
- form.setValue("number", nextNumberData.number);
479
- }
480
- }, [nextNumberData?.number, form]);
481
-
482
462
  const formValues = useWatch({
483
463
  control: form.control,
484
464
  });
@@ -489,20 +469,55 @@ export default function CreateAdvanceInvoiceForm({
489
469
  const {
490
470
  reverseChargeApplies,
491
471
  transactionType,
492
- customerCountryCode: viesCustomerCountryCode,
493
472
  isFetching: isViesFetching,
494
473
  warning: viesWarning,
495
- } = useViesCheck({
474
+ } = useTransactionTypeCheck({
496
475
  issuerCountryCode: activeEntity?.country_code,
497
476
  isTaxSubject: activeEntity?.is_tax_subject ?? true,
498
477
  customerCountry: formValues.customer?.country,
499
478
  customerCountryCode: formValues.customer?.country_code,
500
479
  customerTaxNumber: formValues.customer?.tax_number,
480
+ customerIsEndConsumer: (formValues.customer as any)?.is_end_consumer,
501
481
  enabled: !!activeEntity,
502
482
  });
503
483
 
504
- // FINA non-domestic guard: hide FINA selectors for non-domestic transactions
505
- const isFinaNonDomestic = isFinaEnabled && viesCustomerCountryCode != null && viesCustomerCountryCode !== "HR";
484
+ // FINA numbering guard: use FINA numbering for domestic transactions (or all if unified numbering is on)
485
+ const finaUnifiedNumbering = finaSettings?.unified_numbering !== false;
486
+ const useFinaNumbering =
487
+ !!isFinaActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
488
+ const isFinaNonDomestic = !!isFinaActive && !useFinaNumbering;
489
+
490
+ // ============================================================================
491
+ // Next Advance Invoice Number Preview
492
+ // ============================================================================
493
+ // Use same premise/device params for both FURS and FINA (entity is either one, never both)
494
+ const activePremiseNameForNumber = isFursActive
495
+ ? selectedPremiseName
496
+ : useFinaNumbering
497
+ ? selectedFinaBusinessPremiseName
498
+ : undefined;
499
+ const activeDeviceNameForNumber = isFursActive
500
+ ? selectedDeviceName
501
+ : useFinaNumbering
502
+ ? selectedFinaElectronicDeviceName
503
+ : undefined;
504
+
505
+ const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "advance_invoice", {
506
+ businessPremiseName: activePremiseNameForNumber,
507
+ electronicDeviceName: activeDeviceNameForNumber,
508
+ enabled: !!entityId && !isFursLoading && isFursSelectionReady && !isFinaLoading && isFinaSelectionReady,
509
+ });
510
+
511
+ // Overall loading state
512
+ const isFormDataLoading =
513
+ isFursLoading || !isFursSelectionReady || isFinaLoading || !isFinaSelectionReady || isNextNumberLoading;
514
+
515
+ // Pre-fill advance invoice number from preview
516
+ useEffect(() => {
517
+ if (nextNumberData?.number) {
518
+ form.setValue("number", nextNumberData.number);
519
+ }
520
+ }, [nextNumberData?.number, form]);
506
521
 
507
522
  // Auto-populate tax_clause from entity settings when transaction type changes
508
523
  const effectiveTransactionType = transactionType ?? "domestic";
@@ -588,11 +603,7 @@ export default function CreateAdvanceInvoiceForm({
588
603
 
589
604
  // Build FINA options (skip for drafts; FINA can't be skipped)
590
605
  const finaOptions =
591
- !isDraft &&
592
- isFinaEnabled &&
593
- !isFinaNonDomestic &&
594
- selectedFinaBusinessPremiseName &&
595
- selectedFinaElectronicDeviceName
606
+ !isDraft && useFinaNumbering && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName
596
607
  ? {
597
608
  business_premise_name: selectedFinaBusinessPremiseName,
598
609
  electronic_device_name: selectedFinaElectronicDeviceName,
@@ -621,8 +632,7 @@ export default function CreateAdvanceInvoiceForm({
621
632
  form,
622
633
  isEslogAvailable,
623
634
  isFursEnabled,
624
- isFinaEnabled,
625
- isFinaNonDomestic,
635
+ useFinaNumbering,
626
636
  markAsPaid,
627
637
  originalCustomer,
628
638
  paymentTypes,
@@ -729,16 +739,24 @@ export default function CreateAdvanceInvoiceForm({
729
739
  <Skeleton className="h-7 w-24" />
730
740
  <Skeleton className="h-10 w-full" />
731
741
  </div>
732
- <div className="flex-1 space-y-4">
742
+ <div className="flex-1 space-y-3">
733
743
  <Skeleton className="h-7 w-20" />
734
- <Skeleton className="h-5 w-16" />
735
- <Skeleton className="h-10 w-full" />
736
- <Skeleton className="h-5 w-12" />
737
- <Skeleton className="h-10 w-full" />
738
- <Skeleton className="h-5 w-16" />
739
- <Skeleton className="h-10 w-full" />
740
- <Skeleton className="h-5 w-20" />
741
- <Skeleton className="h-10 w-full" />
744
+ <div className="flex items-center gap-3">
745
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
746
+ <Skeleton className="h-10 flex-1" />
747
+ </div>
748
+ <div className="flex items-center gap-3">
749
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
750
+ <Skeleton className="h-10 flex-1" />
751
+ </div>
752
+ <div className="flex items-center gap-3">
753
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
754
+ <Skeleton className="h-10 flex-1" />
755
+ </div>
756
+ <div className="flex items-center gap-3">
757
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
758
+ <Skeleton className="h-10 flex-1" />
759
+ </div>
742
760
  <div className="space-y-3 rounded-md border p-4">
743
761
  <div className="flex items-center gap-3">
744
762
  <Skeleton className="h-4 w-4 rounded" />
@@ -764,8 +782,6 @@ export default function CreateAdvanceInvoiceForm({
764
782
  <Skeleton className="h-5 w-12" />
765
783
  <Skeleton className="h-24 w-full" />
766
784
  </div>
767
-
768
- <Skeleton className="h-10 w-24" />
769
785
  </div>
770
786
  );
771
787
  }
@@ -821,7 +837,7 @@ export default function CreateAdvanceInvoiceForm({
821
837
  : undefined
822
838
  }
823
839
  finaInline={
824
- isFinaEnabled && hasFinaPremises && !isFinaNonDomestic
840
+ useFinaNumbering
825
841
  ? {
826
842
  premises: activeFinaPremises.map((p: any) => ({
827
843
  id: p.id,
@@ -42,7 +42,8 @@ export default {
42
42
  Domestic: "Inland",
43
43
  "EU B2B": "EU B2B",
44
44
  "EU B2C": "EU B2C",
45
- Export: "Export",
45
+ "3W B2B": "3W B2B",
46
+ "3W B2C": "3W B2C",
46
47
  "Determining transaction type...": "Transaktionstyp wird ermittelt...",
47
48
  "This invoice will not be fiscalized (non-domestic transaction)":
48
49
  "Diese Rechnung wird nicht fiskalisiert (nicht-inländische Transaktion)",
@@ -42,7 +42,8 @@ export default {
42
42
  Domestic: "Nacional",
43
43
  "EU B2B": "EU B2B",
44
44
  "EU B2C": "EU B2C",
45
- Export: "Exportación",
45
+ "3W B2B": "3W B2B",
46
+ "3W B2C": "3W B2C",
46
47
  "Determining transaction type...": "Determinando tipo de transacción...",
47
48
  "This invoice will not be fiscalized (non-domestic transaction)":
48
49
  "Esta factura no será fiscalizada (transacción no nacional)",
@@ -41,7 +41,8 @@ export default {
41
41
  Domestic: "Nationale",
42
42
  "EU B2B": "EU B2B",
43
43
  "EU B2C": "EU B2C",
44
- Export: "Exportation",
44
+ "3W B2B": "3W B2B",
45
+ "3W B2C": "3W B2C",
45
46
  "Determining transaction type...": "Détermination du type de transaction...",
46
47
  "This invoice will not be fiscalized (non-domestic transaction)":
47
48
  "Cette facture ne sera pas fiscalisée (transaction non nationale)",
@@ -39,7 +39,8 @@ export default {
39
39
  Domestic: "Domaća",
40
40
  "EU B2B": "EU B2B",
41
41
  "EU B2C": "EU B2C",
42
- Export: "Izvoz",
42
+ "3W B2B": "3W B2B",
43
+ "3W B2C": "3W B2C",
43
44
  "Determining transaction type...": "Određivanje vrste transakcije...",
44
45
  "This invoice will not be fiscalized (non-domestic transaction)":
45
46
  "Ovaj račun neće biti fiskaliziran (nedomaća transakcija)",
@@ -42,7 +42,8 @@ export default {
42
42
  Domestic: "Nazionale",
43
43
  "EU B2B": "EU B2B",
44
44
  "EU B2C": "EU B2C",
45
- Export: "Esportazione",
45
+ "3W B2B": "3W B2B",
46
+ "3W B2C": "3W B2C",
46
47
  "Determining transaction type...": "Determinazione tipo di transazione...",
47
48
  "This invoice will not be fiscalized (non-domestic transaction)":
48
49
  "Questa fattura non sarà fiscalizzata (transazione non nazionale)",
@@ -41,7 +41,8 @@ export default {
41
41
  Domestic: "Binnenland",
42
42
  "EU B2B": "EU B2B",
43
43
  "EU B2C": "EU B2C",
44
- Export: "Export",
44
+ "3W B2B": "3W B2B",
45
+ "3W B2C": "3W B2C",
45
46
  "Determining transaction type...": "Transactietype bepalen...",
46
47
  "This invoice will not be fiscalized (non-domestic transaction)":
47
48
  "Deze factuur wordt niet gefiscaliseerd (niet-binnenlandse transactie)",
@@ -40,7 +40,8 @@ export default {
40
40
  Domestic: "Krajowa",
41
41
  "EU B2B": "EU B2B",
42
42
  "EU B2C": "EU B2C",
43
- Export: "Eksport",
43
+ "3W B2B": "3W B2B",
44
+ "3W B2C": "3W B2C",
44
45
  "Determining transaction type...": "Określanie typu transakcji...",
45
46
  "This invoice will not be fiscalized (non-domestic transaction)":
46
47
  "Ta faktura nie będzie fiskalizowana (transakcja niekrajowa)",
@@ -41,7 +41,8 @@ export default {
41
41
  Domestic: "Nacional",
42
42
  "EU B2B": "EU B2B",
43
43
  "EU B2C": "EU B2C",
44
- Export: "Exportação",
44
+ "3W B2B": "3W B2B",
45
+ "3W B2C": "3W B2C",
45
46
  "Determining transaction type...": "Determinando tipo de transação...",
46
47
  "This invoice will not be fiscalized (non-domestic transaction)":
47
48
  "Esta fatura não será fiscalizada (transação não nacional)",
@@ -37,7 +37,8 @@ export default {
37
37
  Domestic: "Domača",
38
38
  "EU B2B": "EU B2B",
39
39
  "EU B2C": "EU B2C",
40
- Export: "Izvoz",
40
+ "3W B2B": "3W B2B",
41
+ "3W B2C": "3W B2C",
41
42
  "Determining transaction type...": "Določanje vrste transakcije...",
42
43
  "This invoice will not be fiscalized (non-domestic transaction)":
43
44
  "Ta račun ne bo fiskaliziran (nedomača transakcija)",
@@ -9,7 +9,7 @@ import { Form } from "@/ui/components/ui/form";
9
9
  import { Skeleton } from "@/ui/components/ui/skeleton";
10
10
  import { createCreditNoteSchema } from "@/ui/generated/schemas";
11
11
  import { useNextDocumentNumber } from "@/ui/hooks/use-next-document-number";
12
- import { useViesCheck } from "@/ui/hooks/use-vies-check";
12
+ import { useTransactionTypeCheck } from "@/ui/hooks/use-transaction-type-check";
13
13
  import type { ComponentTranslationProps } from "@/ui/lib/translation";
14
14
  import { createTranslation } from "@/ui/lib/translation";
15
15
  import { useEntities } from "@/ui/providers/entities-context";
@@ -254,19 +254,6 @@ export default function CreateCreditNoteForm({
254
254
  const isFinaActive =
255
255
  isFinaEnabled && hasFinaPremises && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName;
256
256
 
257
- // ============================================================================
258
- // Next Credit Note Number Preview
259
- // ============================================================================
260
- const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "credit_note", {
261
- businessPremiseName: isFursActive ? selectedPremiseName : undefined,
262
- electronicDeviceName: isFursActive ? selectedDeviceName : undefined,
263
- enabled: !!entityId && !isFursLoading && isFursSelectionReady && !isFinaLoading && isFinaSelectionReady,
264
- });
265
-
266
- // Overall loading state
267
- const isFormDataLoading =
268
- isFursLoading || !isFursSelectionReady || isFinaLoading || !isFinaSelectionReady || isNextNumberLoading;
269
-
270
257
  // No header action for credit notes - FINA can't be skipped
271
258
 
272
259
  // Get default payment terms and footer from entity settings
@@ -324,20 +311,48 @@ export default function CreateCreditNoteForm({
324
311
  const {
325
312
  reverseChargeApplies,
326
313
  transactionType,
327
- customerCountryCode: viesCustomerCountryCode,
328
314
  isFetching: isViesFetching,
329
315
  warning: viesWarning,
330
- } = useViesCheck({
316
+ } = useTransactionTypeCheck({
331
317
  issuerCountryCode: activeEntity?.country_code,
332
318
  isTaxSubject: activeEntity?.is_tax_subject ?? true,
333
319
  customerCountry: formValues.customer?.country,
334
320
  customerCountryCode: formValues.customer?.country_code,
335
321
  customerTaxNumber: formValues.customer?.tax_number,
322
+ customerIsEndConsumer: (formValues.customer as any)?.is_end_consumer,
336
323
  enabled: !!activeEntity,
337
324
  });
338
325
 
339
- // FINA non-domestic guard: hide FINA selectors for non-domestic transactions
340
- const isFinaNonDomestic = isFinaEnabled && viesCustomerCountryCode != null && viesCustomerCountryCode !== "HR";
326
+ // FINA numbering guard: use FINA numbering for domestic transactions (or all if unified numbering is on)
327
+ const finaUnifiedNumbering = finaSettings?.unified_numbering !== false;
328
+ const useFinaNumbering =
329
+ !!isFinaActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
330
+ const isFinaNonDomestic = !!isFinaActive && !useFinaNumbering;
331
+
332
+ // ============================================================================
333
+ // Next Credit Note Number Preview
334
+ // ============================================================================
335
+ // Use same premise/device params for both FURS and FINA (entity is either one, never both)
336
+ const activePremiseNameForNumber = isFursActive
337
+ ? selectedPremiseName
338
+ : useFinaNumbering
339
+ ? selectedFinaBusinessPremiseName
340
+ : undefined;
341
+ const activeDeviceNameForNumber = isFursActive
342
+ ? selectedDeviceName
343
+ : useFinaNumbering
344
+ ? selectedFinaElectronicDeviceName
345
+ : undefined;
346
+
347
+ const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "credit_note", {
348
+ businessPremiseName: activePremiseNameForNumber,
349
+ electronicDeviceName: activeDeviceNameForNumber,
350
+ enabled: !!entityId && !isFursLoading && isFursSelectionReady && !isFinaLoading && isFinaSelectionReady,
351
+ });
352
+
353
+ // Overall loading state
354
+ const isFormDataLoading =
355
+ isFursLoading || !isFursSelectionReady || isFinaLoading || !isFinaSelectionReady || isNextNumberLoading;
341
356
 
342
357
  // Auto-populate tax_clause from entity settings when transaction type changes
343
358
  const effectiveTransactionType = transactionType ?? "domestic";
@@ -408,11 +423,7 @@ export default function CreateCreditNoteForm({
408
423
 
409
424
  // Build FINA options (skip for drafts; FINA can't be skipped)
410
425
  const finaOptions =
411
- !isDraft &&
412
- isFinaEnabled &&
413
- !isFinaNonDomestic &&
414
- selectedFinaBusinessPremiseName &&
415
- selectedFinaElectronicDeviceName
426
+ !isDraft && useFinaNumbering && selectedFinaBusinessPremiseName && selectedFinaElectronicDeviceName
416
427
  ? {
417
428
  business_premise_name: selectedFinaBusinessPremiseName,
418
429
  electronic_device_name: selectedFinaElectronicDeviceName,
@@ -445,8 +456,7 @@ export default function CreateCreditNoteForm({
445
456
  [
446
457
  createCreditNote,
447
458
  isFursEnabled,
448
- isFinaEnabled,
449
- isFinaNonDomestic,
459
+ useFinaNumbering,
450
460
  markAsPaid,
451
461
  originalCustomer,
452
462
  paymentTypes,
@@ -558,21 +568,23 @@ export default function CreateCreditNoteForm({
558
568
  <Skeleton className="h-7 w-24" />
559
569
  <Skeleton className="h-10 w-full" />
560
570
  </div>
561
- <div className="flex-1 space-y-4">
571
+ <div className="flex-1 space-y-3">
562
572
  <Skeleton className="h-7 w-20" />
563
- <Skeleton className="h-5 w-16" />
564
- <Skeleton className="h-10 w-full" />
565
- <Skeleton className="h-5 w-12" />
566
- <Skeleton className="h-10 w-full" />
567
- <Skeleton className="h-5 w-16" />
568
- <Skeleton className="h-10 w-full" />
569
- <Skeleton className="h-5 w-20" />
570
- <Skeleton className="h-10 w-full" />
571
- <div className="space-y-3 rounded-md border p-4">
572
- <div className="flex items-center gap-3">
573
- <Skeleton className="h-4 w-4 rounded" />
574
- <Skeleton className="h-5 w-28" />
575
- </div>
573
+ <div className="flex items-center gap-3">
574
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
575
+ <Skeleton className="h-10 flex-1" />
576
+ </div>
577
+ <div className="flex items-center gap-3">
578
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
579
+ <Skeleton className="h-10 flex-1" />
580
+ </div>
581
+ <div className="flex items-center gap-3">
582
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
583
+ <Skeleton className="h-10 flex-1" />
584
+ </div>
585
+ <div className="flex items-center gap-3">
586
+ <Skeleton className="h-5 w-[6.5rem] shrink-0" />
587
+ <Skeleton className="h-10 flex-1" />
576
588
  </div>
577
589
  </div>
578
590
  </div>
@@ -593,8 +605,6 @@ export default function CreateCreditNoteForm({
593
605
  <Skeleton className="h-5 w-12" />
594
606
  <Skeleton className="h-24 w-full" />
595
607
  </div>
596
-
597
- <Skeleton className="h-10 w-24" />
598
608
  </div>
599
609
  );
600
610
  }
@@ -631,7 +641,7 @@ export default function CreateCreditNoteForm({
631
641
  : undefined
632
642
  }
633
643
  finaInline={
634
- isFinaEnabled && hasFinaPremises && !isFinaNonDomestic
644
+ useFinaNumbering
635
645
  ? {
636
646
  premises: activeFinaPremises.map((p: any) => ({
637
647
  id: p.id,
@@ -88,7 +88,8 @@ export default {
88
88
  Domestic: "Inland",
89
89
  "EU B2B": "EU B2B",
90
90
  "EU B2C": "EU B2C",
91
- Export: "Export",
91
+ "3W B2B": "3W B2B",
92
+ "3W B2C": "3W B2C",
92
93
  "Determining transaction type...": "Transaktionstyp wird ermittelt...",
93
94
  "This invoice will not be fiscalized (non-domestic transaction)":
94
95
  "Diese Rechnung wird nicht fiskalisiert (nicht-inländische Transaktion)",
@@ -87,7 +87,8 @@ export default {
87
87
  Domestic: "Nacional",
88
88
  "EU B2B": "EU B2B",
89
89
  "EU B2C": "EU B2C",
90
- Export: "Exportación",
90
+ "3W B2B": "3W B2B",
91
+ "3W B2C": "3W B2C",
91
92
  "Determining transaction type...": "Determinando tipo de transacción...",
92
93
  "This invoice will not be fiscalized (non-domestic transaction)":
93
94
  "Esta factura no será fiscalizada (transacción no nacional)",
@@ -87,7 +87,8 @@ export default {
87
87
  Domestic: "Nationale",
88
88
  "EU B2B": "EU B2B",
89
89
  "EU B2C": "EU B2C",
90
- Export: "Exportation",
90
+ "3W B2B": "3W B2B",
91
+ "3W B2C": "3W B2C",
91
92
  "Determining transaction type...": "Détermination du type de transaction...",
92
93
  "This invoice will not be fiscalized (non-domestic transaction)":
93
94
  "Cette facture ne sera pas fiscalisée (transaction non nationale)",
@@ -85,7 +85,8 @@ export default {
85
85
  Domestic: "Domaća",
86
86
  "EU B2B": "EU B2B",
87
87
  "EU B2C": "EU B2C",
88
- Export: "Izvoz",
88
+ "3W B2B": "3W B2B",
89
+ "3W B2C": "3W B2C",
89
90
  "Determining transaction type...": "Određivanje vrste transakcije...",
90
91
  "This invoice will not be fiscalized (non-domestic transaction)":
91
92
  "Ovaj račun neće biti fiskaliziran (nedomaća transakcija)",
@@ -88,7 +88,8 @@ export default {
88
88
  Domestic: "Nazionale",
89
89
  "EU B2B": "EU B2B",
90
90
  "EU B2C": "EU B2C",
91
- Export: "Esportazione",
91
+ "3W B2B": "3W B2B",
92
+ "3W B2C": "3W B2C",
92
93
  "Determining transaction type...": "Determinazione tipo di transazione...",
93
94
  "This invoice will not be fiscalized (non-domestic transaction)":
94
95
  "Questa fattura non sarà fiscalizzata (transazione non nazionale)",
@@ -87,7 +87,8 @@ export default {
87
87
  Domestic: "Binnenland",
88
88
  "EU B2B": "EU B2B",
89
89
  "EU B2C": "EU B2C",
90
- Export: "Export",
90
+ "3W B2B": "3W B2B",
91
+ "3W B2C": "3W B2C",
91
92
  "Determining transaction type...": "Transactietype bepalen...",
92
93
  "This invoice will not be fiscalized (non-domestic transaction)":
93
94
  "Deze factuur wordt niet gefiscaliseerd (niet-binnenlandse transactie)",
@@ -85,7 +85,8 @@ export default {
85
85
  Domestic: "Krajowa",
86
86
  "EU B2B": "EU B2B",
87
87
  "EU B2C": "EU B2C",
88
- Export: "Eksport",
88
+ "3W B2B": "3W B2B",
89
+ "3W B2C": "3W B2C",
89
90
  "Determining transaction type...": "Określanie typu transakcji...",
90
91
  "This invoice will not be fiscalized (non-domestic transaction)":
91
92
  "Ta faktura nie będzie fiskalizowana (transakcja niekrajowa)",
@@ -85,7 +85,8 @@ export default {
85
85
  Domestic: "Nacional",
86
86
  "EU B2B": "EU B2B",
87
87
  "EU B2C": "EU B2C",
88
- Export: "Exportação",
88
+ "3W B2B": "3W B2B",
89
+ "3W B2C": "3W B2C",
89
90
  "Determining transaction type...": "Determinando tipo de transação...",
90
91
  "This invoice will not be fiscalized (non-domestic transaction)":
91
92
  "Esta fatura não será fiscalizada (transação não nacional)",
@@ -84,7 +84,8 @@ export default {
84
84
  Domestic: "Domača",
85
85
  "EU B2B": "EU B2B",
86
86
  "EU B2C": "EU B2C",
87
- Export: "Izvoz",
87
+ "3W B2B": "3W B2B",
88
+ "3W B2C": "3W B2C",
88
89
  "Determining transaction type...": "Določanje vrste transakcije...",
89
90
  "This invoice will not be fiscalized (non-domestic transaction)":
90
91
  "Ta račun ne bo fiskaliziran (nedomača transakcija)",