@spaceinvoices/react-ui 0.1.1
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/LICENSE +21 -0
- package/README.md +340 -0
- package/cli/dist/index.js +922 -0
- package/package.json +87 -0
- package/registry.json +600 -0
- package/spaceinvoices.schema.json +47 -0
- package/src/app.tsx +25 -0
- package/src/common/autocomplete.tsx +135 -0
- package/src/components/activities/activity-timeline.tsx +160 -0
- package/src/components/activities/index.ts +1 -0
- package/src/components/activities/locales/de.ts +30 -0
- package/src/components/activities/locales/sl.ts +30 -0
- package/src/components/advance-invoices/advance-invoices.hooks.ts +75 -0
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +702 -0
- package/src/components/advance-invoices/create/locales/de.ts +29 -0
- package/src/components/advance-invoices/create/locales/sl.ts +25 -0
- package/src/components/advance-invoices/create/prepare-advance-invoice-submission.ts +74 -0
- package/src/components/advance-invoices/index.ts +5 -0
- package/src/components/advance-invoices/list/index.ts +3 -0
- package/src/components/advance-invoices/list/list-row-actions.tsx +119 -0
- package/src/components/advance-invoices/list/list-table.tsx +178 -0
- package/src/components/advance-invoices/list/locales/de.ts +32 -0
- package/src/components/advance-invoices/list/locales/sl.ts +32 -0
- package/src/components/advance-invoices/list/use-advance-invoice-download.ts +63 -0
- package/src/components/button-loader.tsx +11 -0
- package/src/components/combobox.tsx +96 -0
- package/src/components/company-registry/company-registry-autocomplete.tsx +151 -0
- package/src/components/company-registry/company-registry.hooks.ts +67 -0
- package/src/components/company-registry/index.ts +7 -0
- package/src/components/credit-notes/create/create-credit-note-form.tsx +332 -0
- package/src/components/credit-notes/create/index.ts +1 -0
- package/src/components/credit-notes/create/locales/de.ts +69 -0
- package/src/components/credit-notes/create/locales/sl.ts +67 -0
- package/src/components/credit-notes/credit-notes.hooks.ts +22 -0
- package/src/components/credit-notes/index.ts +10 -0
- package/src/components/credit-notes/list/index.ts +3 -0
- package/src/components/credit-notes/list/list-row-actions.tsx +116 -0
- package/src/components/credit-notes/list/list-table.tsx +183 -0
- package/src/components/credit-notes/list/locales/de.ts +33 -0
- package/src/components/credit-notes/list/locales/sl.ts +33 -0
- package/src/components/credit-notes/list/use-credit-note-download.ts +65 -0
- package/src/components/customers/create-customer-form/create-customer-form.tsx +134 -0
- package/src/components/customers/create-customer-form/locales/de.ts +20 -0
- package/src/components/customers/create-customer-form/locales/sl.ts +20 -0
- package/src/components/customers/customer-autocomplete.tsx +173 -0
- package/src/components/customers/customer-combobox.tsx +130 -0
- package/src/components/customers/customer-list-table/customer-list-row-actions.tsx +48 -0
- package/src/components/customers/customer-list-table/customer-list-table.tsx +124 -0
- package/src/components/customers/customer-list-table/index.ts +2 -0
- package/src/components/customers/customer-list-table/locales/de.ts +16 -0
- package/src/components/customers/customer-list-table/locales/sl.ts +16 -0
- package/src/components/customers/customers.hooks.test.ts +348 -0
- package/src/components/customers/customers.hooks.ts +57 -0
- package/src/components/customers/index.ts +5 -0
- package/src/components/dashboard/chart-empty-state.tsx +29 -0
- package/src/components/dashboard/collection-rate-card/collection-rate-card.tsx +80 -0
- package/src/components/dashboard/collection-rate-card/index.ts +4 -0
- package/src/components/dashboard/collection-rate-card/locales/sl.ts +3 -0
- package/src/components/dashboard/collection-rate-card/use-collection-rate.ts +74 -0
- package/src/components/dashboard/index.ts +54 -0
- package/src/components/dashboard/invoice-status-chart/index.ts +4 -0
- package/src/components/dashboard/invoice-status-chart/invoice-status-chart.tsx +130 -0
- package/src/components/dashboard/invoice-status-chart/locales/sl.ts +9 -0
- package/src/components/dashboard/invoice-status-chart/use-invoice-status.ts +105 -0
- package/src/components/dashboard/loading-card.tsx +19 -0
- package/src/components/dashboard/payment-methods-chart/index.ts +4 -0
- package/src/components/dashboard/payment-methods-chart/locales/sl.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/payment-methods-chart.tsx +152 -0
- package/src/components/dashboard/payment-methods-chart/use-payment-methods.ts +50 -0
- package/src/components/dashboard/payment-trend-chart/index.ts +4 -0
- package/src/components/dashboard/payment-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/payment-trend-chart/payment-trend-chart.tsx +137 -0
- package/src/components/dashboard/payment-trend-chart/use-payment-trend.ts +92 -0
- package/src/components/dashboard/revenue-card.tsx +49 -0
- package/src/components/dashboard/revenue-trend-chart/index.ts +4 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/revenue-trend-chart/revenue-trend-chart.tsx +137 -0
- package/src/components/dashboard/revenue-trend-chart/use-revenue-trend.ts +93 -0
- package/src/components/dashboard/shared/index.ts +5 -0
- package/src/components/dashboard/shared/use-revenue-data.ts +160 -0
- package/src/components/dashboard/shared/use-stats-counts.ts +89 -0
- package/src/components/dashboard/shared/use-stats-query.ts +38 -0
- package/src/components/dashboard/stat-card.tsx +41 -0
- package/src/components/dashboard/tax-collected-card/index.ts +2 -0
- package/src/components/dashboard/tax-collected-card/tax-collected-card.tsx +77 -0
- package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +145 -0
- package/src/components/dashboard/top-customers-chart/index.ts +4 -0
- package/src/components/dashboard/top-customers-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/top-customers-chart/top-customers-chart.tsx +130 -0
- package/src/components/dashboard/top-customers-chart/use-top-customers.ts +72 -0
- package/src/components/documents/create/document-add-item-form.tsx +379 -0
- package/src/components/documents/create/document-add-item-tax-rate-field.tsx +120 -0
- package/src/components/documents/create/document-details-section.tsx +597 -0
- package/src/components/documents/create/document-items-section.tsx +133 -0
- package/src/components/documents/create/document-recipient-section.tsx +101 -0
- package/src/components/documents/create/form-types.ts +36 -0
- package/src/components/documents/create/index.ts +9 -0
- package/src/components/documents/create/live-preview.tsx +235 -0
- package/src/components/documents/create/mark-as-paid-section.tsx +82 -0
- package/src/components/documents/create/prepare-document-submission.test.ts +132 -0
- package/src/components/documents/create/prepare-document-submission.ts +187 -0
- package/src/components/documents/create/prepare-preview-data.test.ts +155 -0
- package/src/components/documents/create/prepare-preview-data.ts +16 -0
- package/src/components/documents/create/smart-code-insert-button.tsx +139 -0
- package/src/components/documents/create/use-document-customer-form.ts +161 -0
- package/src/components/documents/document-preview.tsx +13 -0
- package/src/components/documents/documents.hooks.ts +146 -0
- package/src/components/documents/index.ts +23 -0
- package/src/components/documents/shared/document-preview-display.tsx +172 -0
- package/src/components/documents/shared/index.ts +3 -0
- package/src/components/documents/shared/scaled-document-preview.tsx +70 -0
- package/src/components/documents/shared/use-a4-scaling.ts +62 -0
- package/src/components/documents/types.ts +61 -0
- package/src/components/documents/view/document-actions-bar.tsx +328 -0
- package/src/components/documents/view/document-details-card.tsx +179 -0
- package/src/components/documents/view/document-payments-list.tsx +256 -0
- package/src/components/documents/view/index.ts +4 -0
- package/src/components/documents/view/locales/de.ts +85 -0
- package/src/components/documents/view/locales/sl.ts +84 -0
- package/src/components/documents/view/use-document-download.ts +125 -0
- package/src/components/entities/create-entity-form.tsx +105 -0
- package/src/components/entities/entities.hooks.ts +50 -0
- package/src/components/entities/entity-settings-form/email-template-variables-info.tsx +103 -0
- package/src/components/entities/entity-settings-form/entity-settings-form.tsx +1326 -0
- package/src/components/entities/entity-settings-form/image-upload-with-crop.tsx +222 -0
- package/src/components/entities/entity-settings-form/index.ts +2 -0
- package/src/components/entities/entity-settings-form/input-with-preview.tsx +190 -0
- package/src/components/entities/entity-settings-form/locales/de.ts +192 -0
- package/src/components/entities/entity-settings-form/locales/sl.ts +188 -0
- package/src/components/entities/furs-settings-form/furs-settings-form.tsx +410 -0
- package/src/components/entities/furs-settings-form/furs-settings.hooks.ts +320 -0
- package/src/components/entities/furs-settings-form/index.ts +3 -0
- package/src/components/entities/furs-settings-form/locales/de.ts +233 -0
- package/src/components/entities/furs-settings-form/locales/en.ts +194 -0
- package/src/components/entities/furs-settings-form/locales/sl.ts +196 -0
- package/src/components/entities/furs-settings-form/sections/certificate-settings-section.tsx +242 -0
- package/src/components/entities/furs-settings-form/sections/enable-fiscalization-section.tsx +139 -0
- package/src/components/entities/furs-settings-form/sections/general-settings-section.tsx +252 -0
- package/src/components/entities/furs-settings-form/sections/premises-management-section.tsx +370 -0
- package/src/components/entities/furs-settings-form/sections/register-premise-dialog.tsx +420 -0
- package/src/components/entities/keys.ts +2 -0
- package/src/components/entities/settings/branding-settings-form.tsx +274 -0
- package/src/components/entities/settings/company-settings-form.tsx +256 -0
- package/src/components/entities/settings/defaults-settings-form.tsx +501 -0
- package/src/components/entities/settings/email-settings-form.tsx +288 -0
- package/src/components/entities/settings/eslog-settings-form.tsx +113 -0
- package/src/components/entities/settings/index.ts +8 -0
- package/src/components/entities/settings/number-format-settings-form.tsx +244 -0
- package/src/components/entities/settings/pdf-template-selector/demo-invoice-data.ts +164 -0
- package/src/components/entities/settings/pdf-template-selector/index.ts +2 -0
- package/src/components/entities/settings/pdf-template-selector/locales/de.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/locales/sl.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/pdf-template-cards.tsx +49 -0
- package/src/components/entities/settings/settings-footer.tsx +16 -0
- package/src/components/entities/settings/tax-rules-settings-form.tsx +346 -0
- package/src/components/estimates/create/create-estimate-form.tsx +384 -0
- package/src/components/estimates/create/locales/de.ts +64 -0
- package/src/components/estimates/create/locales/sl.ts +63 -0
- package/src/components/estimates/create/prepare-estimate-submission.ts +39 -0
- package/src/components/estimates/create/use-estimate-customer-form.ts +5 -0
- package/src/components/estimates/estimates.hooks.ts +15 -0
- package/src/components/estimates/index.ts +6 -0
- package/src/components/estimates/list/index.ts +3 -0
- package/src/components/estimates/list/list-row-actions.tsx +103 -0
- package/src/components/estimates/list/list-table.tsx +171 -0
- package/src/components/estimates/list/locales/de.ts +26 -0
- package/src/components/estimates/list/locales/sl.ts +26 -0
- package/src/components/estimates/list/use-estimate-download.ts +63 -0
- package/src/components/export/document-export-form.tsx +288 -0
- package/src/components/export/index.ts +2 -0
- package/src/components/form/form-input.tsx +89 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/invoices/create/create-invoice-form.tsx +852 -0
- package/src/components/invoices/create/eslog-validation.test.ts +242 -0
- package/src/components/invoices/create/eslog-validation.ts +208 -0
- package/src/components/invoices/create/locales/de.ts +118 -0
- package/src/components/invoices/create/locales/sl.ts +114 -0
- package/src/components/invoices/create/prepare-invoice-submission.test.ts +777 -0
- package/src/components/invoices/create/prepare-invoice-submission.ts +79 -0
- package/src/components/invoices/create/use-invoice-customer-form.ts +5 -0
- package/src/components/invoices/index.ts +9 -0
- package/src/components/invoices/invoices-furs.hooks.ts +28 -0
- package/src/components/invoices/invoices.hooks.ts +110 -0
- package/src/components/invoices/list/index.ts +3 -0
- package/src/components/invoices/list/list-row-actions.tsx +132 -0
- package/src/components/invoices/list/list-table.tsx +165 -0
- package/src/components/invoices/list/locales/de.ts +33 -0
- package/src/components/invoices/list/locales/sl.ts +33 -0
- package/src/components/invoices/list/use-invoice-download.ts +62 -0
- package/src/components/invoices/send-email-dialog/index.ts +1 -0
- package/src/components/invoices/send-email-dialog/locales/de.ts +18 -0
- package/src/components/invoices/send-email-dialog/locales/sl.ts +17 -0
- package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +289 -0
- package/src/components/invoices/send-email-dialog.tsx +2 -0
- package/src/components/invoices/shared/index.ts +2 -0
- package/src/components/invoices/shared/scaled-document-preview.tsx +32 -0
- package/src/components/invoices/shared/use-a4-scaling.tsx +39 -0
- package/src/components/invoices/view/eslog-info-display.tsx +160 -0
- package/src/components/invoices/view/furs-info-display.tsx +213 -0
- package/src/components/items/create-item-form/create-item-form.tsx +155 -0
- package/src/components/items/create-item-form/locales/de.ts +14 -0
- package/src/components/items/create-item-form/locales/en.ts +9 -0
- package/src/components/items/create-item-form/locales/sl.ts +14 -0
- package/src/components/items/item-combobox.tsx +147 -0
- package/src/components/items/item-list-table/item-list-header.tsx +33 -0
- package/src/components/items/item-list-table/item-list-row-actions.tsx +48 -0
- package/src/components/items/item-list-table/item-list-row.tsx +32 -0
- package/src/components/items/item-list-table/item-list-table.tsx +76 -0
- package/src/components/items/item-list-table/locales/de.ts +10 -0
- package/src/components/items/item-list-table/locales/en.ts +10 -0
- package/src/components/items/item-list-table/locales/sl.ts +10 -0
- package/src/components/items/items.hooks.ts +63 -0
- package/src/components/loading-spinner.tsx +24 -0
- package/src/components/payments/create-payment-form/create-payment-form.tsx +222 -0
- package/src/components/payments/create-payment-form/locales/de.ts +20 -0
- package/src/components/payments/create-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/edit-payment-form/edit-payment-form.tsx +230 -0
- package/src/components/payments/edit-payment-form/index.ts +1 -0
- package/src/components/payments/edit-payment-form/locales/de.ts +20 -0
- package/src/components/payments/edit-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/index.ts +4 -0
- package/src/components/payments/list/index.ts +2 -0
- package/src/components/payments/list/list-row-actions.tsx +98 -0
- package/src/components/payments/list/list-table.tsx +186 -0
- package/src/components/payments/list/locales/de.ts +19 -0
- package/src/components/payments/list/locales/sl.ts +19 -0
- package/src/components/payments/payments.hooks.ts +15 -0
- package/src/components/request-logs/index.ts +3 -0
- package/src/components/request-logs/request-log-detail.tsx +242 -0
- package/src/components/request-logs/request-log-list-table.tsx +266 -0
- package/src/components/request-logs/request-logs-page.tsx +10 -0
- package/src/components/table/README.md +410 -0
- package/src/components/table/data-table.tsx +251 -0
- package/src/components/table/date-cell.tsx +35 -0
- package/src/components/table/filter-bar.tsx +114 -0
- package/src/components/table/filter-panel.tsx +407 -0
- package/src/components/table/hooks/use-table-fetch.ts +17 -0
- package/src/components/table/hooks/use-table-query.ts +36 -0
- package/src/components/table/hooks/use-table-state.ts +293 -0
- package/src/components/table/index.ts +35 -0
- package/src/components/table/search-input.tsx +85 -0
- package/src/components/table/sortable-header.tsx +56 -0
- package/src/components/table/table-empty-state.tsx +40 -0
- package/src/components/table/table-no-results.tsx +41 -0
- package/src/components/table/table-pagination.tsx +42 -0
- package/src/components/table/table-skeleton.tsx +54 -0
- package/src/components/table/types.ts +136 -0
- package/src/components/tax-reports/index.ts +1 -0
- package/src/components/tax-reports/kir-export-form.tsx +172 -0
- package/src/components/taxes/create-tax-form/create-tax-form.tsx +112 -0
- package/src/components/taxes/create-tax-form/locales/de.ts +8 -0
- package/src/components/taxes/create-tax-form/locales/en.ts +7 -0
- package/src/components/taxes/create-tax-form/locales/sl.ts +8 -0
- package/src/components/taxes/tax-list-table/locales/de.ts +11 -0
- package/src/components/taxes/tax-list-table/locales/en.ts +10 -0
- package/src/components/taxes/tax-list-table/locales/sl.ts +11 -0
- package/src/components/taxes/tax-list-table/tax-list-header.tsx +29 -0
- package/src/components/taxes/tax-list-table/tax-list-row-actions.tsx +43 -0
- package/src/components/taxes/tax-list-table/tax-list-row.tsx +46 -0
- package/src/components/taxes/tax-list-table/tax-list-table.tsx +59 -0
- package/src/components/taxes/taxes.hooks.ts +35 -0
- package/src/components/ui/alert-dialog.tsx +61 -0
- package/src/components/ui/alert.tsx +72 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/breadcrumb.tsx +132 -0
- package/src/components/ui/button.tsx +61 -0
- package/src/components/ui/calendar.tsx +213 -0
- package/src/components/ui/card.tsx +94 -0
- package/src/components/ui/chart.tsx +380 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +56 -0
- package/src/components/ui/command.tsx +187 -0
- package/src/components/ui/dialog.tsx +187 -0
- package/src/components/ui/drawer.tsx +123 -0
- package/src/components/ui/dropdown-menu.tsx +291 -0
- package/src/components/ui/form.tsx +166 -0
- package/src/components/ui/input-group.tsx +149 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/label.tsx +18 -0
- package/src/components/ui/loading-spinner.tsx +16 -0
- package/src/components/ui/popover.tsx +108 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +145 -0
- package/src/components/ui/sidebar.tsx +771 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/sonner.tsx +60 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/sticky-form-footer.tsx +55 -0
- package/src/components/ui/switch.tsx +30 -0
- package/src/components/ui/table.tsx +101 -0
- package/src/components/ui/tabs.tsx +80 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +89 -0
- package/src/components/wl-subscription/index.ts +2 -0
- package/src/components/wl-subscription/locked-feature.tsx +173 -0
- package/src/components/wl-subscription/upgrade-modal.tsx +209 -0
- package/src/frontend.tsx +28 -0
- package/src/generate-schemas.ts +265 -0
- package/src/generated/schemas/advanceinvoice.ts +177 -0
- package/src/generated/schemas/creditnote.ts +187 -0
- package/src/generated/schemas/customer.ts +29 -0
- package/src/generated/schemas/entity.ts +252 -0
- package/src/generated/schemas/estimate.ts +159 -0
- package/src/generated/schemas/furssettings.ts +25 -0
- package/src/generated/schemas/index.ts +24 -0
- package/src/generated/schemas/invoice.ts +167 -0
- package/src/generated/schemas/item.ts +38 -0
- package/src/generated/schemas/payment.ts +44 -0
- package/src/generated/schemas/previewadvanceinvoice_body.ts +354 -0
- package/src/generated/schemas/previewestimate_body.ts +309 -0
- package/src/generated/schemas/registerfursmovablepremise_body.ts +22 -0
- package/src/generated/schemas/registerfursrealestatepremise_body.ts +32 -0
- package/src/generated/schemas/renderdocument_body.ts +594 -0
- package/src/generated/schemas/sendemail_body.ts +26 -0
- package/src/generated/schemas/startpdfexport_body.ts +20 -0
- package/src/generated/schemas/tax.ts +48 -0
- package/src/generated/schemas/uploadfile_body.ts +23 -0
- package/src/generated/schemas/uploadfurscertificate_body.ts +20 -0
- package/src/generated/schemas/userfurssettings.ts +19 -0
- package/src/hooks/create-resource-hooks.test.ts +483 -0
- package/src/hooks/create-resource-hooks.ts +300 -0
- package/src/hooks/use-debounce.ts +12 -0
- package/src/hooks/use-duplicate-document.ts +185 -0
- package/src/hooks/use-media-query.tsx +19 -0
- package/src/hooks/use-mobile.ts +39 -0
- package/src/hooks/use-next-document-number.ts +57 -0
- package/src/hooks/use-resource-mutation.ts +118 -0
- package/src/hooks/use-vies-check.ts +130 -0
- package/src/index.css +11 -0
- package/src/index.html +13 -0
- package/src/index.tsx +12 -0
- package/src/lib/auth.ts +4 -0
- package/src/lib/browser-cookies.ts +70 -0
- package/src/lib/constants.ts +287 -0
- package/src/lib/cookies.ts +36 -0
- package/src/lib/schemas/advance-invoice.ts +43 -0
- package/src/lib/schemas/credit-note.ts +32 -0
- package/src/lib/schemas/estimate.ts +31 -0
- package/src/lib/schemas/index.ts +18 -0
- package/src/lib/schemas/invoice.ts +43 -0
- package/src/lib/schemas/shared.ts +79 -0
- package/src/lib/translation.ts +38 -0
- package/src/lib/utils.ts +6 -0
- package/src/providers/entities-context.tsx +41 -0
- package/src/providers/entities-provider.tsx +201 -0
- package/src/providers/form-footer-context.tsx +72 -0
- package/src/providers/sdk-provider.tsx +164 -0
- package/src/providers/white-label-provider.tsx +91 -0
- package/src/providers/wl-subscription-provider.tsx +277 -0
- package/src/utils/string-helpers.ts +111 -0
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { CreateInvoiceSchema } from "@/ui/generated/schemas";
|
|
3
|
+
import { prepareInvoiceSubmission } from "./prepare-invoice-submission";
|
|
4
|
+
|
|
5
|
+
describe("prepareInvoiceSubmission", () => {
|
|
6
|
+
describe("customer data transformation", () => {
|
|
7
|
+
test("sends only customer_id when customer not editable", () => {
|
|
8
|
+
const values: CreateInvoiceSchema = {
|
|
9
|
+
customer_id: "cust-123",
|
|
10
|
+
customer: {} as any,
|
|
11
|
+
number: "INV-001",
|
|
12
|
+
date: "2024-01-01",
|
|
13
|
+
date_due: "2024-01-31",
|
|
14
|
+
items: [],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const result = prepareInvoiceSubmission(values, {
|
|
18
|
+
wasCustomerFormShown: false,
|
|
19
|
+
originalCustomer: { name: "Test Customer" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
expect(result.customer_id).toBe("cust-123");
|
|
23
|
+
expect(result.customer).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("sends only customer_id when customer data unchanged", () => {
|
|
27
|
+
const originalCustomer = {
|
|
28
|
+
name: "Test Customer",
|
|
29
|
+
address: "123 Test St",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const values: CreateInvoiceSchema = {
|
|
33
|
+
customer_id: "cust-123",
|
|
34
|
+
customer: originalCustomer as any,
|
|
35
|
+
number: "INV-001",
|
|
36
|
+
date: "2024-01-01",
|
|
37
|
+
date_due: "2024-01-31",
|
|
38
|
+
items: [],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = prepareInvoiceSubmission(values, {
|
|
42
|
+
wasCustomerFormShown: true,
|
|
43
|
+
originalCustomer,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(result.customer_id).toBe("cust-123");
|
|
47
|
+
expect(result.customer).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("sends customer data with save_customer flag when modified", () => {
|
|
51
|
+
const originalCustomer = {
|
|
52
|
+
name: "Test Customer",
|
|
53
|
+
address: "123 Test St",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const modifiedCustomer = {
|
|
57
|
+
name: "Test Customer Modified",
|
|
58
|
+
address: "456 New St",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const values: CreateInvoiceSchema = {
|
|
62
|
+
customer_id: "cust-123",
|
|
63
|
+
customer: modifiedCustomer as any,
|
|
64
|
+
number: "INV-001",
|
|
65
|
+
date: "2024-01-01",
|
|
66
|
+
date_due: "2024-01-31",
|
|
67
|
+
items: [],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const result = prepareInvoiceSubmission(values, {
|
|
71
|
+
wasCustomerFormShown: true,
|
|
72
|
+
originalCustomer,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(result.customer_id).toBe("cust-123");
|
|
76
|
+
expect(result.customer).toEqual({
|
|
77
|
+
...modifiedCustomer,
|
|
78
|
+
save_customer: true,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("creates new customer when customer_id not provided", () => {
|
|
83
|
+
const newCustomer = {
|
|
84
|
+
name: "New Customer",
|
|
85
|
+
address: "789 Fresh St",
|
|
86
|
+
city: "New City",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const values: CreateInvoiceSchema = {
|
|
90
|
+
customer: newCustomer as any,
|
|
91
|
+
number: "INV-001",
|
|
92
|
+
date: "2024-01-01",
|
|
93
|
+
date_due: "2024-01-31",
|
|
94
|
+
items: [],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const result = prepareInvoiceSubmission(values, {
|
|
98
|
+
wasCustomerFormShown: false,
|
|
99
|
+
originalCustomer: null,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(result.customer_id).toBeUndefined();
|
|
103
|
+
expect(result.customer).toEqual({
|
|
104
|
+
...newCustomer,
|
|
105
|
+
save_customer: true,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("removes empty customer fields from submission", () => {
|
|
110
|
+
const customerWithEmpty = {
|
|
111
|
+
name: "Customer",
|
|
112
|
+
address: "",
|
|
113
|
+
city: null,
|
|
114
|
+
state: undefined,
|
|
115
|
+
post_code: "12345",
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const values: CreateInvoiceSchema = {
|
|
119
|
+
customer: customerWithEmpty as any,
|
|
120
|
+
number: "INV-001",
|
|
121
|
+
date: "2024-01-01",
|
|
122
|
+
date_due: "2024-01-31",
|
|
123
|
+
items: [],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const result = prepareInvoiceSubmission(values, {
|
|
127
|
+
wasCustomerFormShown: false,
|
|
128
|
+
originalCustomer: null,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(result.customer).toEqual({
|
|
132
|
+
name: "Customer",
|
|
133
|
+
post_code: "12345",
|
|
134
|
+
save_customer: true,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("removes customer completely when all fields are empty", () => {
|
|
139
|
+
const emptyCustomer = {
|
|
140
|
+
name: "",
|
|
141
|
+
address: "",
|
|
142
|
+
city: null,
|
|
143
|
+
state: undefined,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const values: CreateInvoiceSchema = {
|
|
147
|
+
customer: emptyCustomer as any,
|
|
148
|
+
number: "INV-001",
|
|
149
|
+
date: "2024-01-01",
|
|
150
|
+
date_due: "2024-01-31",
|
|
151
|
+
items: [],
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const result = prepareInvoiceSubmission(values, {
|
|
155
|
+
wasCustomerFormShown: false,
|
|
156
|
+
originalCustomer: null,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(result.customer).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("removes customer_id when empty", () => {
|
|
163
|
+
const values: CreateInvoiceSchema = {
|
|
164
|
+
customer_id: "",
|
|
165
|
+
number: "INV-001",
|
|
166
|
+
date: "2024-01-01",
|
|
167
|
+
date_due: "2024-01-31",
|
|
168
|
+
items: [],
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const result = prepareInvoiceSubmission(values, {
|
|
172
|
+
wasCustomerFormShown: false,
|
|
173
|
+
originalCustomer: null,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(result.customer_id).toBeUndefined();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("date conversion", () => {
|
|
181
|
+
test("converts date string to Date object", () => {
|
|
182
|
+
const values: CreateInvoiceSchema = {
|
|
183
|
+
number: "INV-001",
|
|
184
|
+
date: "2024-01-15",
|
|
185
|
+
date_due: "2024-02-15",
|
|
186
|
+
items: [],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const result = prepareInvoiceSubmission(values, {
|
|
190
|
+
wasCustomerFormShown: false,
|
|
191
|
+
originalCustomer: null,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(result.date).toBeInstanceOf(Date);
|
|
195
|
+
expect((result.date as Date).toISOString()).toContain("2024-01-15");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("converts date_due string to Date object", () => {
|
|
199
|
+
const values: CreateInvoiceSchema = {
|
|
200
|
+
number: "INV-001",
|
|
201
|
+
date: "2024-01-15",
|
|
202
|
+
date_due: "2024-02-15",
|
|
203
|
+
items: [],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const result = prepareInvoiceSubmission(values, {
|
|
207
|
+
wasCustomerFormShown: false,
|
|
208
|
+
originalCustomer: null,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(result.date_due).toBeInstanceOf(Date);
|
|
212
|
+
expect((result.date_due as Date).toISOString()).toContain("2024-02-15");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("handles undefined dates", () => {
|
|
216
|
+
const values: CreateInvoiceSchema = {
|
|
217
|
+
number: "INV-001",
|
|
218
|
+
items: [],
|
|
219
|
+
} as any;
|
|
220
|
+
|
|
221
|
+
const result = prepareInvoiceSubmission(values, {
|
|
222
|
+
wasCustomerFormShown: false,
|
|
223
|
+
originalCustomer: null,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result.date).toBeUndefined();
|
|
227
|
+
expect(result.date_due).toBeUndefined();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe("payment data", () => {
|
|
232
|
+
test("adds payment data when markAsPaid is true", () => {
|
|
233
|
+
const values: CreateInvoiceSchema = {
|
|
234
|
+
number: "INV-001",
|
|
235
|
+
date: "2024-01-15",
|
|
236
|
+
date_due: "2024-02-15",
|
|
237
|
+
items: [],
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const result = prepareInvoiceSubmission(values, {
|
|
241
|
+
wasCustomerFormShown: false,
|
|
242
|
+
originalCustomer: null,
|
|
243
|
+
markAsPaid: true,
|
|
244
|
+
paymentType: "bank_transfer",
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(result.payment).toBeDefined();
|
|
248
|
+
expect(result.payment?.type).toBe("bank_transfer");
|
|
249
|
+
expect(result.payment?.date).toBeInstanceOf(Date);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("uses correct payment type", () => {
|
|
253
|
+
const values: CreateInvoiceSchema = {
|
|
254
|
+
number: "INV-001",
|
|
255
|
+
date: "2024-01-15",
|
|
256
|
+
date_due: "2024-02-15",
|
|
257
|
+
items: [],
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const result = prepareInvoiceSubmission(values, {
|
|
261
|
+
wasCustomerFormShown: false,
|
|
262
|
+
originalCustomer: null,
|
|
263
|
+
markAsPaid: true,
|
|
264
|
+
paymentType: "cash",
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expect(result.payment?.type).toBe("cash");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("uses default payment type when not specified", () => {
|
|
271
|
+
const values: CreateInvoiceSchema = {
|
|
272
|
+
number: "INV-001",
|
|
273
|
+
date: "2024-01-15",
|
|
274
|
+
date_due: "2024-02-15",
|
|
275
|
+
items: [],
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const result = prepareInvoiceSubmission(values, {
|
|
279
|
+
wasCustomerFormShown: false,
|
|
280
|
+
originalCustomer: null,
|
|
281
|
+
markAsPaid: true,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(result.payment?.type).toBe("bank_transfer");
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("does not add payment data when markAsPaid is false", () => {
|
|
288
|
+
const values: CreateInvoiceSchema = {
|
|
289
|
+
number: "INV-001",
|
|
290
|
+
date: "2024-01-15",
|
|
291
|
+
date_due: "2024-02-15",
|
|
292
|
+
items: [],
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const result = prepareInvoiceSubmission(values, {
|
|
296
|
+
wasCustomerFormShown: false,
|
|
297
|
+
originalCustomer: null,
|
|
298
|
+
markAsPaid: false,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
expect(result.payment).toBeUndefined();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("does not add payment data when markAsPaid not provided", () => {
|
|
305
|
+
const values: CreateInvoiceSchema = {
|
|
306
|
+
number: "INV-001",
|
|
307
|
+
date: "2024-01-15",
|
|
308
|
+
date_due: "2024-02-15",
|
|
309
|
+
items: [],
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
313
|
+
wasCustomerFormShown: false,
|
|
314
|
+
originalCustomer: null,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(result.payment).toBeUndefined();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe("edge cases", () => {
|
|
322
|
+
test("handles customer with partial data", () => {
|
|
323
|
+
const customer = {
|
|
324
|
+
name: "Partial Customer",
|
|
325
|
+
city: "Test City",
|
|
326
|
+
// Missing other fields
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const values: CreateInvoiceSchema = {
|
|
330
|
+
customer: customer as any,
|
|
331
|
+
number: "INV-001",
|
|
332
|
+
date: "2024-01-15",
|
|
333
|
+
date_due: "2024-02-15",
|
|
334
|
+
items: [],
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const result = prepareInvoiceSubmission(values, {
|
|
338
|
+
wasCustomerFormShown: false,
|
|
339
|
+
originalCustomer: null,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
expect(result.customer).toEqual({
|
|
343
|
+
name: "Partial Customer",
|
|
344
|
+
city: "Test City",
|
|
345
|
+
save_customer: true,
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("preserves other invoice fields", () => {
|
|
350
|
+
const values: CreateInvoiceSchema = {
|
|
351
|
+
number: "INV-001",
|
|
352
|
+
date: "2024-01-15",
|
|
353
|
+
date_due: "2024-02-15",
|
|
354
|
+
items: [
|
|
355
|
+
{
|
|
356
|
+
name: "Item 1",
|
|
357
|
+
description: "Description",
|
|
358
|
+
quantity: 1,
|
|
359
|
+
price: 100,
|
|
360
|
+
},
|
|
361
|
+
] as any,
|
|
362
|
+
note: "Test notes",
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const result = prepareInvoiceSubmission(values, {
|
|
366
|
+
wasCustomerFormShown: false,
|
|
367
|
+
originalCustomer: null,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
expect(result.items.length).toBe(1);
|
|
371
|
+
expect(result.items[0].name).toBe("Item 1");
|
|
372
|
+
expect(result.note).toBe("Test notes");
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("never includes number in payload (server auto-generates)", () => {
|
|
376
|
+
const values: CreateInvoiceSchema = {
|
|
377
|
+
number: "INV-001", // Even if form has a preview number
|
|
378
|
+
date: "2024-01-15",
|
|
379
|
+
date_due: "2024-02-15",
|
|
380
|
+
items: [],
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const result = prepareInvoiceSubmission(values, {
|
|
384
|
+
wasCustomerFormShown: false,
|
|
385
|
+
originalCustomer: null,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Number should never be sent - server always generates it
|
|
389
|
+
expect(result.number).toBeUndefined();
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe("gross price transformation", () => {
|
|
394
|
+
test("transforms items with priceModes[index]=true to send gross_price", () => {
|
|
395
|
+
const values: CreateInvoiceSchema = {
|
|
396
|
+
number: "INV-001",
|
|
397
|
+
date: "2024-01-15",
|
|
398
|
+
date_due: "2024-02-15",
|
|
399
|
+
items: [
|
|
400
|
+
{
|
|
401
|
+
name: "Item 1",
|
|
402
|
+
quantity: 1,
|
|
403
|
+
price: 122,
|
|
404
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
405
|
+
},
|
|
406
|
+
] as any,
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const result = prepareInvoiceSubmission(values, {
|
|
410
|
+
wasCustomerFormShown: false,
|
|
411
|
+
originalCustomer: null,
|
|
412
|
+
priceModes: { 0: true },
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
expect(result.items[0].gross_price).toBe(122);
|
|
416
|
+
expect(result.items[0].price).toBeUndefined();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test("transforms items with priceModes[index]=false to send price", () => {
|
|
420
|
+
const values: CreateInvoiceSchema = {
|
|
421
|
+
number: "INV-001",
|
|
422
|
+
date: "2024-01-15",
|
|
423
|
+
date_due: "2024-02-15",
|
|
424
|
+
items: [
|
|
425
|
+
{
|
|
426
|
+
name: "Item 1",
|
|
427
|
+
quantity: 1,
|
|
428
|
+
price: 100,
|
|
429
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
430
|
+
},
|
|
431
|
+
] as any,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const result = prepareInvoiceSubmission(values, {
|
|
435
|
+
wasCustomerFormShown: false,
|
|
436
|
+
originalCustomer: null,
|
|
437
|
+
priceModes: { 0: false },
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
expect(result.items[0].price).toBe(100);
|
|
441
|
+
expect(result.items[0].gross_price).toBeUndefined();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test("defaults to net price when priceModes not provided", () => {
|
|
445
|
+
const values: CreateInvoiceSchema = {
|
|
446
|
+
number: "INV-001",
|
|
447
|
+
date: "2024-01-15",
|
|
448
|
+
date_due: "2024-02-15",
|
|
449
|
+
items: [
|
|
450
|
+
{
|
|
451
|
+
name: "Item 1",
|
|
452
|
+
quantity: 1,
|
|
453
|
+
price: 100,
|
|
454
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
455
|
+
},
|
|
456
|
+
] as any,
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const result = prepareInvoiceSubmission(values, {
|
|
460
|
+
wasCustomerFormShown: false,
|
|
461
|
+
originalCustomer: null,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(result.items[0].price).toBe(100);
|
|
465
|
+
expect(result.items[0].gross_price).toBeUndefined();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test("handles mixed net and gross price items via priceModes", () => {
|
|
469
|
+
const values: CreateInvoiceSchema = {
|
|
470
|
+
number: "INV-001",
|
|
471
|
+
date: "2024-01-15",
|
|
472
|
+
date_due: "2024-02-15",
|
|
473
|
+
items: [
|
|
474
|
+
{
|
|
475
|
+
name: "Net Item",
|
|
476
|
+
quantity: 1,
|
|
477
|
+
price: 100,
|
|
478
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
name: "Gross Item",
|
|
482
|
+
quantity: 2,
|
|
483
|
+
price: 244,
|
|
484
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
485
|
+
},
|
|
486
|
+
] as any,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const result = prepareInvoiceSubmission(values, {
|
|
490
|
+
wasCustomerFormShown: false,
|
|
491
|
+
originalCustomer: null,
|
|
492
|
+
priceModes: { 0: false, 1: true },
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
expect(result.items[0].price).toBe(100);
|
|
496
|
+
expect(result.items[0].gross_price).toBeUndefined();
|
|
497
|
+
expect(result.items[1].gross_price).toBe(244);
|
|
498
|
+
expect(result.items[1].price).toBeUndefined();
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
describe("FURS fiscalization data", () => {
|
|
503
|
+
test("adds FURS data when premise and device provided", () => {
|
|
504
|
+
const values: CreateInvoiceSchema = {
|
|
505
|
+
number: "INV-001",
|
|
506
|
+
date: "2024-01-15",
|
|
507
|
+
date_due: "2024-02-15",
|
|
508
|
+
items: [],
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
512
|
+
wasCustomerFormShown: false,
|
|
513
|
+
originalCustomer: null,
|
|
514
|
+
furs: {
|
|
515
|
+
business_premise_name: "P1",
|
|
516
|
+
electronic_device_name: "E1",
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
expect(result.furs).toEqual({
|
|
521
|
+
business_premise_name: "P1",
|
|
522
|
+
electronic_device_name: "E1",
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test("does not add FURS data when no options provided", () => {
|
|
527
|
+
const values: CreateInvoiceSchema = {
|
|
528
|
+
number: "INV-001",
|
|
529
|
+
date: "2024-01-15",
|
|
530
|
+
date_due: "2024-02-15",
|
|
531
|
+
items: [],
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
535
|
+
wasCustomerFormShown: false,
|
|
536
|
+
originalCustomer: null,
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
expect(result.furs).toBeUndefined();
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
test("does not add FURS data when only premise provided", () => {
|
|
543
|
+
const values: CreateInvoiceSchema = {
|
|
544
|
+
number: "INV-001",
|
|
545
|
+
date: "2024-01-15",
|
|
546
|
+
date_due: "2024-02-15",
|
|
547
|
+
items: [],
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
551
|
+
wasCustomerFormShown: false,
|
|
552
|
+
originalCustomer: null,
|
|
553
|
+
furs: {
|
|
554
|
+
business_premise_name: "P1",
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
expect(result.furs).toBeUndefined();
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test("does not add FURS data when only device provided", () => {
|
|
562
|
+
const values: CreateInvoiceSchema = {
|
|
563
|
+
number: "INV-001",
|
|
564
|
+
date: "2024-01-15",
|
|
565
|
+
date_due: "2024-02-15",
|
|
566
|
+
items: [],
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
570
|
+
wasCustomerFormShown: false,
|
|
571
|
+
originalCustomer: null,
|
|
572
|
+
furs: {
|
|
573
|
+
electronic_device_name: "E1",
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
expect(result.furs).toBeUndefined();
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
test("adds skip flag when skip fiscalization is true", () => {
|
|
581
|
+
const values: CreateInvoiceSchema = {
|
|
582
|
+
number: "INV-001",
|
|
583
|
+
date: "2024-01-15",
|
|
584
|
+
date_due: "2024-02-15",
|
|
585
|
+
items: [],
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
589
|
+
wasCustomerFormShown: false,
|
|
590
|
+
originalCustomer: null,
|
|
591
|
+
furs: {
|
|
592
|
+
skip: true,
|
|
593
|
+
},
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
expect(result.furs).toEqual({ skip: true });
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
test("skip flag takes precedence over premise/device", () => {
|
|
600
|
+
const values: CreateInvoiceSchema = {
|
|
601
|
+
number: "INV-001",
|
|
602
|
+
date: "2024-01-15",
|
|
603
|
+
date_due: "2024-02-15",
|
|
604
|
+
items: [],
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
608
|
+
wasCustomerFormShown: false,
|
|
609
|
+
originalCustomer: null,
|
|
610
|
+
furs: {
|
|
611
|
+
skip: true,
|
|
612
|
+
business_premise_name: "P1",
|
|
613
|
+
electronic_device_name: "E1",
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
// Skip should take precedence - don't send premise/device
|
|
618
|
+
expect(result.furs).toEqual({ skip: true });
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
test("FURS data works with payment data", () => {
|
|
622
|
+
const values: CreateInvoiceSchema = {
|
|
623
|
+
number: "INV-001",
|
|
624
|
+
date: "2024-01-15",
|
|
625
|
+
date_due: "2024-02-15",
|
|
626
|
+
items: [],
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
630
|
+
wasCustomerFormShown: false,
|
|
631
|
+
originalCustomer: null,
|
|
632
|
+
markAsPaid: true,
|
|
633
|
+
paymentType: "cash",
|
|
634
|
+
furs: {
|
|
635
|
+
business_premise_name: "P1",
|
|
636
|
+
electronic_device_name: "E1",
|
|
637
|
+
},
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
expect(result.furs).toEqual({
|
|
641
|
+
business_premise_name: "P1",
|
|
642
|
+
electronic_device_name: "E1",
|
|
643
|
+
});
|
|
644
|
+
expect(result.payment).toBeDefined();
|
|
645
|
+
expect(result.payment?.type).toBe("cash");
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe("draft invoices", () => {
|
|
650
|
+
test("sets is_draft to true when isDraft option is true", () => {
|
|
651
|
+
const values: CreateInvoiceSchema = {
|
|
652
|
+
number: "INV-001",
|
|
653
|
+
date: "2024-01-15",
|
|
654
|
+
date_due: "2024-02-15",
|
|
655
|
+
items: [],
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
659
|
+
wasCustomerFormShown: false,
|
|
660
|
+
originalCustomer: null,
|
|
661
|
+
isDraft: true,
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
expect(result.is_draft).toBe(true);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
test("does not set is_draft when isDraft is false", () => {
|
|
668
|
+
const values: CreateInvoiceSchema = {
|
|
669
|
+
number: "INV-001",
|
|
670
|
+
date: "2024-01-15",
|
|
671
|
+
date_due: "2024-02-15",
|
|
672
|
+
items: [],
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
676
|
+
wasCustomerFormShown: false,
|
|
677
|
+
originalCustomer: null,
|
|
678
|
+
isDraft: false,
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
expect(result.is_draft).toBeUndefined();
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
test("draft invoice without FURS data (form skips FURS for drafts)", () => {
|
|
685
|
+
const values: CreateInvoiceSchema = {
|
|
686
|
+
number: "INV-001",
|
|
687
|
+
date: "2024-01-15",
|
|
688
|
+
date_due: "2024-02-15",
|
|
689
|
+
items: [],
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// Form component passes undefined for furs when isDraft=true
|
|
693
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
694
|
+
wasCustomerFormShown: false,
|
|
695
|
+
originalCustomer: null,
|
|
696
|
+
isDraft: true,
|
|
697
|
+
// furs: undefined (not passed for drafts)
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
expect(result.is_draft).toBe(true);
|
|
701
|
+
expect(result.furs).toBeUndefined();
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
test("draft invoice without e-SLOG validation (form skips e-SLOG for drafts)", () => {
|
|
705
|
+
const values: CreateInvoiceSchema = {
|
|
706
|
+
number: "INV-001",
|
|
707
|
+
date: "2024-01-15",
|
|
708
|
+
date_due: "2024-02-15",
|
|
709
|
+
items: [],
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// Form component passes undefined for eslog when isDraft=true
|
|
713
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
714
|
+
wasCustomerFormShown: false,
|
|
715
|
+
originalCustomer: null,
|
|
716
|
+
isDraft: true,
|
|
717
|
+
// eslog: undefined (not passed for drafts)
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
expect(result.is_draft).toBe(true);
|
|
721
|
+
expect(result.eslog).toBeUndefined();
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
test("draft invoice without payment data (form skips markAsPaid for drafts)", () => {
|
|
725
|
+
const values: CreateInvoiceSchema = {
|
|
726
|
+
number: "INV-001",
|
|
727
|
+
date: "2024-01-15",
|
|
728
|
+
date_due: "2024-02-15",
|
|
729
|
+
items: [],
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
// Form component passes markAsPaid=false when isDraft=true
|
|
733
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
734
|
+
wasCustomerFormShown: false,
|
|
735
|
+
originalCustomer: null,
|
|
736
|
+
isDraft: true,
|
|
737
|
+
markAsPaid: false,
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
expect(result.is_draft).toBe(true);
|
|
741
|
+
expect(result.payment).toBeUndefined();
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
test("draft invoice preserves all other invoice data", () => {
|
|
745
|
+
const values: CreateInvoiceSchema = {
|
|
746
|
+
number: "DRAFT-123",
|
|
747
|
+
date: "2024-01-15",
|
|
748
|
+
date_due: "2024-02-15",
|
|
749
|
+
customer_id: "cust-123",
|
|
750
|
+
items: [
|
|
751
|
+
{
|
|
752
|
+
name: "Item 1",
|
|
753
|
+
quantity: 2,
|
|
754
|
+
price: 100,
|
|
755
|
+
taxes: [{ tax_id: "tax-1" }],
|
|
756
|
+
},
|
|
757
|
+
] as any,
|
|
758
|
+
note: "Draft note",
|
|
759
|
+
currency_code: "EUR",
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
const result: any = prepareInvoiceSubmission(values, {
|
|
763
|
+
wasCustomerFormShown: false,
|
|
764
|
+
originalCustomer: null,
|
|
765
|
+
isDraft: true,
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
expect(result.is_draft).toBe(true);
|
|
769
|
+
expect(result.number).toBeUndefined(); // Number is never sent - server auto-generates
|
|
770
|
+
expect(result.customer_id).toBe("cust-123");
|
|
771
|
+
expect(result.items).toHaveLength(1);
|
|
772
|
+
expect(result.items[0].name).toBe("Item 1");
|
|
773
|
+
expect(result.note).toBe("Draft note");
|
|
774
|
+
expect(result.currency_code).toBe("EUR");
|
|
775
|
+
});
|
|
776
|
+
});
|
|
777
|
+
});
|