@spaceinvoices/react-ui 0.4.12 → 0.4.32
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/cli/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/common/autocomplete.tsx +7 -1
- package/src/components/advance-invoices/advance-invoices.hooks.ts +35 -44
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +190 -73
- package/src/components/advance-invoices/create/locales/bg.ts +17 -9
- package/src/components/advance-invoices/create/locales/cs.ts +17 -9
- package/src/components/advance-invoices/create/locales/de.ts +15 -7
- package/src/components/advance-invoices/create/locales/en.ts +15 -7
- package/src/components/advance-invoices/create/locales/es.ts +15 -7
- package/src/components/advance-invoices/create/locales/et.ts +17 -9
- package/src/components/advance-invoices/create/locales/fi.ts +18 -10
- package/src/components/advance-invoices/create/locales/fr.ts +16 -8
- package/src/components/advance-invoices/create/locales/hr.ts +15 -7
- package/src/components/advance-invoices/create/locales/is.ts +17 -9
- package/src/components/advance-invoices/create/locales/it.ts +15 -7
- package/src/components/advance-invoices/create/locales/nb.ts +17 -9
- package/src/components/advance-invoices/create/locales/nl.ts +15 -7
- package/src/components/advance-invoices/create/locales/pl.ts +17 -9
- package/src/components/advance-invoices/create/locales/pt.ts +16 -8
- package/src/components/advance-invoices/create/locales/sk.ts +17 -9
- package/src/components/advance-invoices/create/locales/sl.ts +14 -5
- package/src/components/advance-invoices/create/locales/sv.ts +17 -9
- package/src/components/advance-invoices/create/prepare-advance-invoice-submission.ts +47 -1
- package/src/components/advance-invoices/list/list-table.tsx +2 -1
- package/src/components/credit-notes/create/create-credit-note-form.tsx +254 -85
- package/src/components/credit-notes/create/locales/bg.ts +22 -8
- package/src/components/credit-notes/create/locales/cs.ts +22 -8
- package/src/components/credit-notes/create/locales/de.ts +20 -7
- package/src/components/credit-notes/create/locales/en.ts +19 -5
- package/src/components/credit-notes/create/locales/es.ts +20 -7
- package/src/components/credit-notes/create/locales/et.ts +22 -8
- package/src/components/credit-notes/create/locales/fi.ts +23 -9
- package/src/components/credit-notes/create/locales/fr.ts +21 -8
- package/src/components/credit-notes/create/locales/hr.ts +20 -7
- package/src/components/credit-notes/create/locales/is.ts +22 -8
- package/src/components/credit-notes/create/locales/it.ts +20 -7
- package/src/components/credit-notes/create/locales/nb.ts +22 -8
- package/src/components/credit-notes/create/locales/nl.ts +20 -7
- package/src/components/credit-notes/create/locales/pl.ts +22 -9
- package/src/components/credit-notes/create/locales/pt.ts +21 -8
- package/src/components/credit-notes/create/locales/sk.ts +22 -8
- package/src/components/credit-notes/create/locales/sl.ts +19 -5
- package/src/components/credit-notes/create/locales/sv.ts +22 -8
- package/src/components/credit-notes/create/prepare-credit-note-submission.ts +35 -1
- package/src/components/credit-notes/credit-notes.hooks.ts +21 -2
- package/src/components/credit-notes/list/list-table.tsx +2 -1
- package/src/components/delivery-notes/create/create-delivery-note-form.tsx +133 -30
- package/src/components/delivery-notes/create/locales/bg.ts +1 -0
- package/src/components/delivery-notes/create/locales/cs.ts +1 -0
- package/src/components/delivery-notes/create/locales/de.ts +1 -0
- package/src/components/delivery-notes/create/locales/en.ts +1 -0
- package/src/components/delivery-notes/create/locales/es.ts +1 -0
- package/src/components/delivery-notes/create/locales/et.ts +1 -0
- package/src/components/delivery-notes/create/locales/fi.ts +1 -0
- package/src/components/delivery-notes/create/locales/fr.ts +1 -0
- package/src/components/delivery-notes/create/locales/hr.ts +1 -0
- package/src/components/delivery-notes/create/locales/is.ts +1 -0
- package/src/components/delivery-notes/create/locales/it.ts +1 -0
- package/src/components/delivery-notes/create/locales/nb.ts +1 -0
- package/src/components/delivery-notes/create/locales/nl.ts +1 -0
- package/src/components/delivery-notes/create/locales/pl.ts +1 -0
- package/src/components/delivery-notes/create/locales/pt.ts +1 -0
- package/src/components/delivery-notes/create/locales/sk.ts +1 -0
- package/src/components/delivery-notes/create/locales/sl.ts +1 -0
- package/src/components/delivery-notes/create/locales/sv.ts +1 -0
- package/src/components/delivery-notes/create/prepare-delivery-note-submission.ts +34 -1
- package/src/components/delivery-notes/delivery-notes.hooks.ts +15 -1
- package/src/components/delivery-notes/list/list-table.tsx +2 -1
- package/src/components/documents/create/custom-create-template.ts +151 -0
- package/src/components/documents/create/document-add-item-form.tsx +12 -8
- package/src/components/documents/create/document-add-item-tax-rate-field.tsx +1 -2
- package/src/components/documents/create/document-date-validation.ts +111 -0
- package/src/components/documents/create/document-details-section.tsx +93 -48
- package/src/components/documents/create/document-form-item.ts +67 -0
- package/src/components/documents/create/document-item-validation.ts +6 -2
- package/src/components/documents/create/form-types.ts +2 -2
- package/src/components/documents/create/linked-documents-info.tsx +2 -11
- package/src/components/documents/create/live-preview.tsx +3 -3
- package/src/components/documents/create/mark-as-paid-section.tsx +14 -11
- package/src/components/documents/create/payment-rows.ts +30 -0
- package/src/components/documents/create/prepare-document-submission.ts +143 -103
- package/src/components/documents/create/prepare-preview-data.ts +12 -0
- package/src/components/documents/create/preserved-expected-total.ts +90 -0
- package/src/components/documents/public/public-document-summary.tsx +6 -13
- package/src/components/documents/view/document-actions-bar.tsx +10 -1
- package/src/components/documents/view/document-details-card.tsx +4 -12
- package/src/components/documents/view/document-relations-list.tsx +4 -4
- package/src/components/documents/view/locales/bg.ts +8 -8
- package/src/components/documents/view/locales/cs.ts +8 -8
- package/src/components/documents/view/locales/de.ts +1 -1
- package/src/components/documents/view/locales/en.ts +14 -14
- package/src/components/documents/view/locales/es.ts +1 -1
- package/src/components/documents/view/locales/et.ts +8 -8
- package/src/components/documents/view/locales/fi.ts +10 -10
- package/src/components/documents/view/locales/fr.ts +1 -1
- package/src/components/documents/view/locales/hr.ts +6 -6
- package/src/components/documents/view/locales/is.ts +8 -8
- package/src/components/documents/view/locales/it.ts +1 -1
- package/src/components/documents/view/locales/nb.ts +8 -8
- package/src/components/documents/view/locales/nl.ts +1 -1
- package/src/components/documents/view/locales/pl.ts +1 -1
- package/src/components/documents/view/locales/pt.ts +1 -1
- package/src/components/documents/view/locales/sk.ts +8 -8
- package/src/components/documents/view/locales/sl.ts +9 -9
- package/src/components/documents/view/locales/sv.ts +1 -1
- package/src/components/documents/view/use-document-download.ts +2 -2
- package/src/components/entities/entity-settings-form/locales/bg.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/cs.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/de.ts +9 -0
- package/src/components/entities/entity-settings-form/locales/en.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/es.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/et.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/fi.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/fr.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/hr.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/is.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/it.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/nb.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/nl.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/pl.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/pt.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/sk.ts +7 -0
- package/src/components/entities/entity-settings-form/locales/sl.ts +12 -4
- package/src/components/entities/entity-settings-form/locales/sv.ts +7 -0
- package/src/components/entities/settings/tax-rules-settings-form.tsx +36 -0
- package/src/components/estimates/create/create-estimate-form.tsx +196 -47
- package/src/components/estimates/create/locales/bg.ts +6 -5
- package/src/components/estimates/create/locales/cs.ts +6 -5
- package/src/components/estimates/create/locales/de.ts +4 -3
- package/src/components/estimates/create/locales/en.ts +4 -3
- package/src/components/estimates/create/locales/es.ts +4 -3
- package/src/components/estimates/create/locales/et.ts +6 -5
- package/src/components/estimates/create/locales/fi.ts +9 -8
- package/src/components/estimates/create/locales/fr.ts +4 -3
- package/src/components/estimates/create/locales/hr.ts +7 -6
- package/src/components/estimates/create/locales/is.ts +6 -5
- package/src/components/estimates/create/locales/it.ts +4 -3
- package/src/components/estimates/create/locales/nb.ts +6 -5
- package/src/components/estimates/create/locales/nl.ts +4 -3
- package/src/components/estimates/create/locales/pl.ts +4 -3
- package/src/components/estimates/create/locales/pt.ts +4 -3
- package/src/components/estimates/create/locales/sk.ts +6 -5
- package/src/components/estimates/create/locales/sl.ts +7 -6
- package/src/components/estimates/create/locales/sv.ts +6 -5
- package/src/components/estimates/create/prepare-estimate-submission.ts +37 -3
- package/src/components/estimates/estimates.hooks.ts +11 -2
- package/src/components/estimates/list/list-table.tsx +11 -1
- package/src/components/estimates/list/locales/bg.ts +2 -0
- package/src/components/estimates/list/locales/cs.ts +2 -0
- package/src/components/estimates/list/locales/de.ts +2 -0
- package/src/components/estimates/list/locales/en.ts +2 -0
- package/src/components/estimates/list/locales/es.ts +2 -0
- package/src/components/estimates/list/locales/et.ts +2 -0
- package/src/components/estimates/list/locales/fi.ts +2 -0
- package/src/components/estimates/list/locales/fr.ts +2 -0
- package/src/components/estimates/list/locales/hr.ts +7 -5
- package/src/components/estimates/list/locales/is.ts +2 -0
- package/src/components/estimates/list/locales/it.ts +2 -0
- package/src/components/estimates/list/locales/nb.ts +2 -0
- package/src/components/estimates/list/locales/nl.ts +2 -0
- package/src/components/estimates/list/locales/pl.ts +2 -0
- package/src/components/estimates/list/locales/pt.ts +2 -0
- package/src/components/estimates/list/locales/sk.ts +2 -0
- package/src/components/estimates/list/locales/sl.ts +9 -7
- package/src/components/estimates/list/locales/sv.ts +2 -0
- package/src/components/invoices/create/create-invoice-form.tsx +231 -60
- package/src/components/invoices/create/locales/bg.ts +23 -14
- package/src/components/invoices/create/locales/cs.ts +23 -14
- package/src/components/invoices/create/locales/de.ts +17 -9
- package/src/components/invoices/create/locales/en.ts +16 -7
- package/src/components/invoices/create/locales/es.ts +18 -9
- package/src/components/invoices/create/locales/et.ts +23 -14
- package/src/components/invoices/create/locales/fi.ts +24 -15
- package/src/components/invoices/create/locales/fr.ts +19 -11
- package/src/components/invoices/create/locales/hr.ts +18 -9
- package/src/components/invoices/create/locales/is.ts +23 -14
- package/src/components/invoices/create/locales/it.ts +19 -11
- package/src/components/invoices/create/locales/nb.ts +23 -14
- package/src/components/invoices/create/locales/nl.ts +19 -10
- package/src/components/invoices/create/locales/pl.ts +19 -11
- package/src/components/invoices/create/locales/pt.ts +19 -10
- package/src/components/invoices/create/locales/sk.ts +23 -14
- package/src/components/invoices/create/locales/sl.ts +17 -9
- package/src/components/invoices/create/locales/sv.ts +17 -8
- package/src/components/invoices/create/prepare-invoice-submission.ts +55 -1
- package/src/components/invoices/invoices.hooks.ts +11 -2
- package/src/components/invoices/list/list-table.tsx +2 -1
- package/src/components/invoices/send-email-dialog/locales/bg.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/cs.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/de.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/en.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/es.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/et.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/fi.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/fr.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/hr.ts +8 -3
- package/src/components/invoices/send-email-dialog/locales/is.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/it.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/nb.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/nl.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/pl.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/pt.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/sk.ts +5 -0
- package/src/components/invoices/send-email-dialog/locales/sl.ts +8 -3
- package/src/components/invoices/send-email-dialog/locales/sv.ts +5 -0
- package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +2 -1
- package/src/components/items/item-combobox.tsx +4 -4
- package/src/components/payments/create-payment-form/create-payment-form.tsx +5 -2
- package/src/components/payments/edit-payment-form/edit-payment-form.tsx +5 -1
- package/src/components/recurring-invoices/create-recurring-invoice-form/create-recurring-invoice-form.tsx +98 -22
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/bg.ts +26 -26
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/cs.ts +25 -25
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/et.ts +26 -26
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/fi.ts +36 -36
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/is.ts +26 -26
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/nb.ts +26 -26
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/sk.ts +25 -25
- package/src/components/recurring-invoices/create-recurring-invoice-form/locales/sv.ts +26 -26
- package/src/components/recurring-invoices/list/list-row-actions.tsx +9 -1
- package/src/components/recurring-invoices/list/list-table.tsx +53 -5
- package/src/components/recurring-invoices/list/locales/bg.ts +4 -0
- package/src/components/recurring-invoices/list/locales/cs.ts +4 -0
- package/src/components/recurring-invoices/list/locales/de.ts +4 -0
- package/src/components/recurring-invoices/list/locales/en.ts +4 -0
- package/src/components/recurring-invoices/list/locales/es.ts +4 -0
- package/src/components/recurring-invoices/list/locales/et.ts +4 -0
- package/src/components/recurring-invoices/list/locales/fi.ts +4 -0
- package/src/components/recurring-invoices/list/locales/fr.ts +4 -0
- package/src/components/recurring-invoices/list/locales/hr.ts +4 -0
- package/src/components/recurring-invoices/list/locales/is.ts +4 -0
- package/src/components/recurring-invoices/list/locales/it.ts +4 -0
- package/src/components/recurring-invoices/list/locales/nb.ts +4 -0
- package/src/components/recurring-invoices/list/locales/nl.ts +4 -0
- package/src/components/recurring-invoices/list/locales/pl.ts +4 -0
- package/src/components/recurring-invoices/list/locales/pt.ts +4 -0
- package/src/components/recurring-invoices/list/locales/sk.ts +4 -0
- package/src/components/recurring-invoices/list/locales/sl.ts +4 -0
- package/src/components/recurring-invoices/list/locales/sv.ts +4 -0
- package/src/components/tax-reports/slovenia-tax-profile-step.tsx +4 -1
- package/src/components/tax-reports/slovenia-yearly-export-form.tsx +3 -0
- package/src/components/tax-reports/slovenia-yearly-review-step.tsx +2 -1
- package/src/components/ui/form.tsx +5 -13
- package/src/components/ui/select.tsx +0 -1
- package/src/components/ui/sidebar.tsx +2 -2
- package/src/generate-schemas.ts +132 -99
- package/src/generated/schemas/acceptentityinvitation_body.ts +4 -3
- package/src/generated/schemas/accountwebhook.ts +4 -8
- package/src/generated/schemas/addentityuser_body.ts +4 -3
- package/src/generated/schemas/advanceinvoice.ts +167 -168
- package/src/generated/schemas/authorizeshopify_body.ts +4 -3
- package/src/generated/schemas/calculatedocumentpreview.ts +120 -0
- package/src/generated/schemas/checktransactiontype.ts +35 -0
- package/src/generated/schemas/creditnote.ts +203 -76
- package/src/generated/schemas/customadvanceinvoice.ts +172 -165
- package/src/generated/schemas/customcreditnote.ts +183 -155
- package/src/generated/schemas/customdeliverynote.ts +166 -0
- package/src/generated/schemas/customer.ts +4 -8
- package/src/generated/schemas/customestimate.ts +123 -97
- package/src/generated/schemas/customincomingpurchasedocument.ts +142 -0
- package/src/generated/schemas/custominvoice.ts +183 -154
- package/src/generated/schemas/deliverynote.ts +124 -79
- package/src/generated/schemas/einvoice.ts +19 -0
- package/src/generated/schemas/einvoicingsettings.ts +21 -0
- package/src/generated/schemas/einvoicingsupplier.ts +45 -0
- package/src/generated/schemas/entity.ts +44 -40
- package/src/generated/schemas/entityapikey.ts +1 -3
- package/src/generated/schemas/entityuserrole.ts +1 -3
- package/src/generated/schemas/estimate.ts +120 -127
- package/src/generated/schemas/exportsloveniavodxml_body.ts +4 -3
- package/src/generated/schemas/exportsloveniayearlynormiranireport_body.ts +4 -3
- package/src/generated/schemas/finadevice.ts +15 -0
- package/src/generated/schemas/finalizedocument.ts +52 -0
- package/src/generated/schemas/finapremise.ts +15 -0
- package/src/generated/schemas/finasettings.ts +1 -3
- package/src/generated/schemas/furselectronicdevice.ts +15 -0
- package/src/generated/schemas/furssettings.ts +1 -3
- package/src/generated/schemas/image.ts +15 -0
- package/src/generated/schemas/incomingpurchasedocument.ts +7 -27
- package/src/generated/schemas/incomingpurchasedocumentattachment.ts +15 -0
- package/src/generated/schemas/incomingpurchasedocumentpayment.ts +1 -3
- package/src/generated/schemas/index.ts +20 -5
- package/src/generated/schemas/invoice.ts +182 -183
- package/src/generated/schemas/item.ts +6 -10
- package/src/generated/schemas/legacymigrationauth.ts +18 -0
- package/src/generated/schemas/me.ts +2 -24
- package/src/generated/schemas/migrationjob.ts +20 -0
- package/src/generated/schemas/order.ts +4 -8
- package/src/generated/schemas/orderintegration.ts +4 -8
- package/src/generated/schemas/payment.ts +4 -8
- package/src/generated/schemas/ptatcudseries.ts +1 -3
- package/src/generated/schemas/queryentitystats.ts +15 -0
- package/src/generated/schemas/recurringinvoice.ts +4 -8
- package/src/generated/schemas/registerfursmovablepremise_body.ts +1 -3
- package/src/generated/schemas/registerfursrealestatepremise_body.ts +1 -3
- package/src/generated/schemas/renderadvanceinvoicepreview_body.ts +10 -16
- package/src/generated/schemas/rendercreditnotepreview_body.ts +10 -16
- package/src/generated/schemas/renderdeliverynotepreview_body.ts +9 -5
- package/src/generated/schemas/renderestimatepreview_body.ts +11 -7
- package/src/generated/schemas/renderinvoicepreview_body.ts +10 -16
- package/src/generated/schemas/reviewsloveniayearlynormiranireport.ts +15 -0
- package/src/generated/schemas/searcheinvoicingcustomer.ts +18 -0
- package/src/generated/schemas/senddocument_body.ts +1 -3
- package/src/generated/schemas/sendemail_body.ts +2 -24
- package/src/generated/schemas/sloveniataxprofile.ts +8 -10
- package/src/generated/schemas/starteslogexport_body.ts +4 -3
- package/src/generated/schemas/startpdfexport_body.ts +8 -87
- package/src/generated/schemas/stripeappconnect_body.ts +4 -3
- package/src/generated/schemas/stripeappcreateinvoice_body.ts +4 -6
- package/src/generated/schemas/stripeappmarketplaceauthorize.ts +15 -0
- package/src/generated/schemas/stripeappupdatesettings_body.ts +6 -6
- package/src/generated/schemas/supplier.ts +4 -8
- package/src/generated/schemas/syncshopifyorders_body.ts +4 -3
- package/src/generated/schemas/tax.ts +6 -8
- package/src/generated/schemas/uploadfile_body.ts +1 -3
- package/src/generated/schemas/uploadfurscertificate_body.ts +6 -6
- package/src/generated/schemas/userfinasettings.ts +1 -3
- package/src/generated/schemas/userfurssettings.ts +1 -3
- package/src/generated/schemas/userptsettings.ts +1 -3
- package/src/generated/schemas/voidinvoice_body.ts +8 -3
- package/src/generated/schemas/webhook.ts +4 -8
- package/src/generated/schemas/wlsubscriptionbillingemail.ts +17 -0
- package/src/hooks/use-duplicate-document.ts +74 -32
- package/src/lib/date-only.ts +58 -0
- package/src/lib/document-display.ts +18 -0
- package/src/lib/payment-display.ts +5 -3
- package/src/lib/schemas/shared.ts +11 -0
- package/src/providers/wl-subscription-provider.tsx +5 -0
- package/src/generated/schemas/account_webhook.ts +0 -43
- package/src/generated/schemas/previewadvanceinvoice_body.ts +0 -354
- package/src/generated/schemas/previewestimate_body.ts +0 -309
- package/src/generated/schemas/registerfinamovablepremise_body.ts +0 -26
- package/src/generated/schemas/registerfinarealestatepremise_body.ts +0 -37
- package/src/generated/schemas/renderdocument_body.ts +0 -594
|
@@ -27,12 +27,14 @@ import {
|
|
|
27
27
|
type PtDocumentInputForm,
|
|
28
28
|
ptDocumentInputFormSchema,
|
|
29
29
|
} from "@/ui/lib/pt-document-input";
|
|
30
|
+
import { normalizeLineItemDiscountsForForm } from "@/ui/lib/schemas/shared";
|
|
30
31
|
import type { ComponentTranslationProps } from "@/ui/lib/translation";
|
|
31
32
|
import { createTranslation } from "@/ui/lib/translation";
|
|
32
33
|
import { cn } from "@/ui/lib/utils";
|
|
33
34
|
import { useEntities } from "@/ui/providers/entities-context";
|
|
34
35
|
import { useFormFooterRegistration } from "@/ui/providers/form-footer-context";
|
|
35
36
|
import { CUSTOMERS_CACHE_KEY } from "../../customers/customers.hooks";
|
|
37
|
+
import { withInvoiceIssueDateValidation } from "../../documents/create/document-date-validation";
|
|
36
38
|
import {
|
|
37
39
|
DocumentDetailsSection,
|
|
38
40
|
DocumentFooterField,
|
|
@@ -55,9 +57,12 @@ import {
|
|
|
55
57
|
serializePaymentRows,
|
|
56
58
|
validatePaymentRows,
|
|
57
59
|
} from "../../documents/create/payment-rows";
|
|
60
|
+
import { prepareDocumentItems } from "../../documents/create/prepare-document-submission";
|
|
61
|
+
import { applyCustomCreateTemplate } from "../../documents/create/custom-create-template";
|
|
62
|
+
import { financialInputsMatchInitial, resolvePreservedExpectedTotal } from "../../documents/create/preserved-expected-total";
|
|
58
63
|
import { scrollToFirstInvalidField } from "../../documents/create/scroll-to-first-invalid-field";
|
|
59
64
|
import type { DocumentTypes } from "../../documents/types";
|
|
60
|
-
import { useCreateInvoice, useNextInvoiceNumber, useUpdateInvoice } from "../invoices.hooks";
|
|
65
|
+
import { useCreateCustomInvoice, useCreateInvoice, useNextInvoiceNumber, useUpdateInvoice } from "../invoices.hooks";
|
|
61
66
|
import {
|
|
62
67
|
buildEslogFieldErrors,
|
|
63
68
|
getEntityErrors,
|
|
@@ -75,7 +80,7 @@ import nl from "./locales/nl";
|
|
|
75
80
|
import pl from "./locales/pl";
|
|
76
81
|
import pt from "./locales/pt";
|
|
77
82
|
import sl from "./locales/sl";
|
|
78
|
-
import { prepareInvoiceSubmission } from "./prepare-invoice-submission";
|
|
83
|
+
import { prepareInvoiceSubmission, prepareInvoiceUpdateSubmission } from "./prepare-invoice-submission";
|
|
79
84
|
import { useInvoiceCustomerForm } from "./use-invoice-customer-form";
|
|
80
85
|
|
|
81
86
|
function calculateDueDate(dateIso: string, days: number): string {
|
|
@@ -84,6 +89,19 @@ function calculateDueDate(dateIso: string, days: number): string {
|
|
|
84
89
|
return date.toISOString();
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
function isSameCalendarDate(left: string | Date | undefined, right: string | Date): boolean {
|
|
93
|
+
if (!left) return false;
|
|
94
|
+
|
|
95
|
+
const leftDate = new Date(left);
|
|
96
|
+
const rightDate = new Date(right);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
leftDate.getFullYear() === rightDate.getFullYear() &&
|
|
100
|
+
leftDate.getMonth() === rightDate.getMonth() &&
|
|
101
|
+
leftDate.getDate() === rightDate.getDate()
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
87
105
|
const DUE_DAYS_PRESETS = [0, 7, 14, 30, 60, 90] as const;
|
|
88
106
|
|
|
89
107
|
const translations = {
|
|
@@ -101,10 +119,12 @@ const translations = {
|
|
|
101
119
|
const DUPLICATE_PREVIEW_SETTLE_MS = 120;
|
|
102
120
|
const DUPLICATE_PREVIEW_MIN_DELAY_MS = 260;
|
|
103
121
|
const FORM_ID = "create-invoice-form";
|
|
104
|
-
const createInvoiceFormSchema =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
const createInvoiceFormSchema = withInvoiceIssueDateValidation(
|
|
123
|
+
withRequiredDocumentItemFields(
|
|
124
|
+
createInvoiceSchema.extend({
|
|
125
|
+
pt: ptDocumentInputFormSchema.optional(),
|
|
126
|
+
}),
|
|
127
|
+
),
|
|
108
128
|
);
|
|
109
129
|
|
|
110
130
|
function emitInvoiceCreateDebug(_detail: Record<string, unknown>) {
|
|
@@ -152,30 +172,41 @@ function buildInvoiceFormValues({
|
|
|
152
172
|
defaultInvoiceNote,
|
|
153
173
|
defaultPaymentTerms,
|
|
154
174
|
defaultFooter,
|
|
175
|
+
defaultSignature,
|
|
155
176
|
defaultInvoiceDueDays,
|
|
177
|
+
isEditMode,
|
|
156
178
|
}: {
|
|
157
179
|
initialValues?: Partial<CreateInvoiceRequest> & { number?: string };
|
|
158
180
|
currencyCode?: string;
|
|
159
181
|
defaultInvoiceNote: string;
|
|
160
182
|
defaultPaymentTerms: string;
|
|
161
183
|
defaultFooter: string;
|
|
184
|
+
defaultSignature: string;
|
|
162
185
|
defaultInvoiceDueDays: number;
|
|
186
|
+
isEditMode: boolean;
|
|
163
187
|
}): CreateInvoiceFormValues {
|
|
164
188
|
return {
|
|
165
189
|
number: initialValues?.number || "",
|
|
190
|
+
calculation_mode: (initialValues as any)?.calculation_mode ?? undefined,
|
|
166
191
|
date: initialValues?.date || new Date().toISOString(),
|
|
167
192
|
customer_id: initialValues?.customer_id ?? undefined,
|
|
168
193
|
customer: (initialValues?.customer as CreateInvoiceFormValues["customer"]) ?? undefined,
|
|
169
194
|
items: initialValues?.items?.length
|
|
170
195
|
? initialValues.items.map((item: any) => ({
|
|
171
|
-
type: item.type,
|
|
196
|
+
type: item.type ?? undefined,
|
|
172
197
|
name: item.name || "",
|
|
173
198
|
description: item.description || "",
|
|
174
199
|
...(item.type !== "separator"
|
|
175
200
|
? {
|
|
201
|
+
item_id: item.item_id,
|
|
202
|
+
classification: item.classification ?? undefined,
|
|
203
|
+
unit: item.unit ?? undefined,
|
|
176
204
|
quantity: item.quantity ?? 1,
|
|
177
205
|
price: item.gross_price ?? item.price,
|
|
206
|
+
gross_price: item.gross_price ?? undefined,
|
|
178
207
|
taxes: item.taxes || [],
|
|
208
|
+
discounts: normalizeLineItemDiscountsForForm(item.discounts),
|
|
209
|
+
metadata: item.metadata ?? undefined,
|
|
179
210
|
}
|
|
180
211
|
: {}),
|
|
181
212
|
}))
|
|
@@ -190,14 +221,20 @@ function buildInvoiceFormValues({
|
|
|
190
221
|
],
|
|
191
222
|
currency_code: initialValues?.currency_code || currencyCode || "EUR",
|
|
192
223
|
reference: (initialValues as any)?.reference ?? "",
|
|
193
|
-
note: initialValues?.note ?? defaultInvoiceNote,
|
|
224
|
+
note: initialValues?.note ?? (isEditMode ? "" : defaultInvoiceNote),
|
|
194
225
|
tax_clause: (initialValues as any)?.tax_clause ?? "",
|
|
195
|
-
payment_terms: initialValues?.payment_terms ?? defaultPaymentTerms,
|
|
196
|
-
footer: (initialValues as any)?.footer ?? defaultFooter,
|
|
226
|
+
payment_terms: initialValues?.payment_terms ?? (isEditMode ? "" : defaultPaymentTerms),
|
|
227
|
+
footer: (initialValues as any)?.footer ?? (isEditMode ? "" : defaultFooter),
|
|
228
|
+
signature: (initialValues as any)?.signature ?? (isEditMode ? "" : defaultSignature),
|
|
197
229
|
date_due:
|
|
198
230
|
initialValues?.date_due ||
|
|
199
|
-
|
|
200
|
-
|
|
231
|
+
(isEditMode
|
|
232
|
+
? undefined
|
|
233
|
+
: calculateDueDate(initialValues?.date || new Date().toISOString(), defaultInvoiceDueDays)),
|
|
234
|
+
date_service:
|
|
235
|
+
(initialValues as any)?.date_service ??
|
|
236
|
+
(isEditMode ? undefined : (initialValues?.date ?? new Date().toISOString())),
|
|
237
|
+
date_service_to: (initialValues as any)?.date_service_to ?? undefined,
|
|
201
238
|
linked_documents: (initialValues as any)?.linked_documents,
|
|
202
239
|
pt: ((initialValues as any)?.pt as PtDocumentInputForm | undefined) ?? undefined,
|
|
203
240
|
};
|
|
@@ -240,6 +277,7 @@ export default function CreateInvoiceForm({
|
|
|
240
277
|
const defaultInvoiceNote = (activeEntity?.settings as any)?.default_invoice_note || "";
|
|
241
278
|
const defaultPaymentTerms = (activeEntity?.settings as any)?.default_invoice_payment_terms || "";
|
|
242
279
|
const defaultFooter = (activeEntity?.settings as any)?.document_footer || "";
|
|
280
|
+
const defaultSignature = (activeEntity?.settings as any)?.default_document_signature || "";
|
|
243
281
|
const defaultInvoiceDueDays = (activeEntity?.settings as any)?.default_invoice_due_days ?? 30;
|
|
244
282
|
|
|
245
283
|
// ============================================================================
|
|
@@ -284,6 +322,36 @@ export default function CreateInvoiceForm({
|
|
|
284
322
|
}, {} as PriceModesMap);
|
|
285
323
|
}, [initialValues?.items]);
|
|
286
324
|
const priceModesRef = useRef<PriceModesMap>(initialPriceModes);
|
|
325
|
+
const customCreateTemplate = (initialValues as any)?._custom_create_template;
|
|
326
|
+
const financialInputsMatchSource = useCallback(
|
|
327
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
328
|
+
financialInputsMatchInitial({
|
|
329
|
+
initialItems: initialValues?.items,
|
|
330
|
+
currentItems: values.items,
|
|
331
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
332
|
+
currentCurrencyCode: values.currency_code,
|
|
333
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
334
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
335
|
+
initialPriceModes,
|
|
336
|
+
currentPriceModes: priceModesRef.current,
|
|
337
|
+
}),
|
|
338
|
+
[initialPriceModes, initialValues],
|
|
339
|
+
);
|
|
340
|
+
const getPreservedExpectedTotalWithTax = useCallback(
|
|
341
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
342
|
+
resolvePreservedExpectedTotal({
|
|
343
|
+
initialExpectedTotalWithTax: (initialValues as any)?._preserved_expected_total_with_tax,
|
|
344
|
+
initialItems: initialValues?.items,
|
|
345
|
+
currentItems: values.items,
|
|
346
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
347
|
+
currentCurrencyCode: values.currency_code,
|
|
348
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
349
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
350
|
+
initialPriceModes,
|
|
351
|
+
currentPriceModes: priceModesRef.current,
|
|
352
|
+
}),
|
|
353
|
+
[initialPriceModes, initialValues],
|
|
354
|
+
);
|
|
287
355
|
|
|
288
356
|
const formDefaultValues = useMemo(
|
|
289
357
|
() =>
|
|
@@ -293,7 +361,9 @@ export default function CreateInvoiceForm({
|
|
|
293
361
|
defaultInvoiceNote,
|
|
294
362
|
defaultPaymentTerms,
|
|
295
363
|
defaultFooter,
|
|
364
|
+
defaultSignature,
|
|
296
365
|
defaultInvoiceDueDays,
|
|
366
|
+
isEditMode,
|
|
297
367
|
}),
|
|
298
368
|
[
|
|
299
369
|
activeEntity?.currency_code,
|
|
@@ -301,7 +371,9 @@ export default function CreateInvoiceForm({
|
|
|
301
371
|
defaultInvoiceDueDays,
|
|
302
372
|
defaultInvoiceNote,
|
|
303
373
|
defaultPaymentTerms,
|
|
374
|
+
defaultSignature,
|
|
304
375
|
initialValues,
|
|
376
|
+
isEditMode,
|
|
305
377
|
],
|
|
306
378
|
);
|
|
307
379
|
|
|
@@ -470,6 +542,10 @@ export default function CreateInvoiceForm({
|
|
|
470
542
|
const useFinaNumbering =
|
|
471
543
|
!!fina.isActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
|
|
472
544
|
const isFinaNonDomestic = !!fina.isActive && !useFinaNumbering;
|
|
545
|
+
const isFiscalizationDateLocked = !isEditMode && (isFursActive || useFinaNumbering);
|
|
546
|
+
const fiscalizationDateLockReason = useFinaNumbering
|
|
547
|
+
? t("FINA fiscalized invoices always use the current date")
|
|
548
|
+
: t("FURS fiscalized invoices always use the current date");
|
|
473
549
|
|
|
474
550
|
// ============================================================================
|
|
475
551
|
// Next Invoice Number Preview
|
|
@@ -501,22 +577,42 @@ export default function CreateInvoiceForm({
|
|
|
501
577
|
: furs.isLoading || !furs.isSelectionReady || fina.isLoading || !fina.isSelectionReady || isNextNumberLoading;
|
|
502
578
|
|
|
503
579
|
// Update header action with FURS and e-SLOG toggle buttons
|
|
580
|
+
const headerActionSignatureRef = useRef<string | null>(null);
|
|
504
581
|
useEffect(() => {
|
|
505
582
|
if (!onHeaderActionChange) return;
|
|
506
583
|
|
|
507
584
|
// Don't set header action while loading or in edit mode (FURS/FINA/e-SLOG not editable)
|
|
508
585
|
if (furs.isLoading || fina.isLoading || isEditMode) {
|
|
586
|
+
if (headerActionSignatureRef.current === null) return;
|
|
587
|
+
headerActionSignatureRef.current = null;
|
|
509
588
|
onHeaderActionChange(null);
|
|
510
589
|
return;
|
|
511
590
|
}
|
|
512
591
|
|
|
513
592
|
const showFursToggle = furs.isEnabled && furs.hasPremises;
|
|
514
593
|
const showEslogToggle = eslog.isAvailable;
|
|
594
|
+
const isFursChecked = !skipFiscalization;
|
|
595
|
+
const isEslogChecked = eslog.isEnabled === true;
|
|
596
|
+
const headerActionSignature =
|
|
597
|
+
showFursToggle || showEslogToggle
|
|
598
|
+
? JSON.stringify({
|
|
599
|
+
showFursToggle,
|
|
600
|
+
showEslogToggle,
|
|
601
|
+
isFursChecked,
|
|
602
|
+
isEslogChecked,
|
|
603
|
+
eslogLabel: t("e-SLOG"),
|
|
604
|
+
eslogEnabledDescription: t("Click to skip e-SLOG validation for this invoice"),
|
|
605
|
+
eslogDisabledDescription: t("Click to enable e-SLOG validation"),
|
|
606
|
+
fiscalizationLabel: t("Fiscally verify"),
|
|
607
|
+
fiscalizationEnabledDescription: t("Click to skip fiscalization for this invoice"),
|
|
608
|
+
fiscalizationDisabledDescription: t("Click to enable fiscalization"),
|
|
609
|
+
})
|
|
610
|
+
: null;
|
|
611
|
+
|
|
612
|
+
if (headerActionSignatureRef.current === headerActionSignature) return;
|
|
613
|
+
headerActionSignatureRef.current = headerActionSignature;
|
|
515
614
|
|
|
516
615
|
if (showFursToggle || showEslogToggle) {
|
|
517
|
-
const isFursChecked = !skipFiscalization;
|
|
518
|
-
const isEslogChecked = eslog.isEnabled === true;
|
|
519
|
-
|
|
520
616
|
onHeaderActionChange(
|
|
521
617
|
<div className="flex items-center gap-2">
|
|
522
618
|
{/* e-SLOG toggle */}
|
|
@@ -615,6 +711,19 @@ export default function CreateInvoiceForm({
|
|
|
615
711
|
}
|
|
616
712
|
}, [nextNumberData?.number, form]);
|
|
617
713
|
|
|
714
|
+
useEffect(() => {
|
|
715
|
+
if (!isFiscalizationDateLocked) return;
|
|
716
|
+
|
|
717
|
+
const today = new Date();
|
|
718
|
+
if (isSameCalendarDate(form.getValues("date"), today)) return;
|
|
719
|
+
|
|
720
|
+
form.setValue("date", today.toISOString(), {
|
|
721
|
+
shouldDirty: true,
|
|
722
|
+
shouldTouch: false,
|
|
723
|
+
shouldValidate: true,
|
|
724
|
+
});
|
|
725
|
+
}, [form, isFiscalizationDateLocked]);
|
|
726
|
+
|
|
618
727
|
// Watch fields needed for document note/payment terms preview
|
|
619
728
|
const watchedNumber = useWatch({ control: form.control, name: "number" });
|
|
620
729
|
const watchedDate = useWatch({ control: form.control, name: "date" });
|
|
@@ -707,16 +816,23 @@ export default function CreateInvoiceForm({
|
|
|
707
816
|
// Auto-populate tax_clause from entity settings when transaction type changes
|
|
708
817
|
const effectiveTransactionType = transactionType ?? "domestic";
|
|
709
818
|
const prevTransactionTypeRef = useRef<string | undefined>(undefined);
|
|
819
|
+
const prevTaxClauseHydrationVersionRef = useRef<number | undefined>(undefined);
|
|
820
|
+
const [taxClauseHydrationVersion, setTaxClauseHydrationVersion] = useState(0);
|
|
710
821
|
useEffect(() => {
|
|
711
|
-
if (
|
|
822
|
+
if (isEditMode) return;
|
|
823
|
+
const transactionTypeChanged = effectiveTransactionType !== prevTransactionTypeRef.current;
|
|
824
|
+
const hydrationVersionChanged = taxClauseHydrationVersion !== prevTaxClauseHydrationVersionRef.current;
|
|
825
|
+
if (!transactionTypeChanged && !hydrationVersionChanged) return;
|
|
826
|
+
|
|
712
827
|
prevTransactionTypeRef.current = effectiveTransactionType;
|
|
828
|
+
prevTaxClauseHydrationVersionRef.current = taxClauseHydrationVersion;
|
|
713
829
|
|
|
714
830
|
const taxClauseDefaults = (activeEntity?.settings as any)?.tax_clause_defaults;
|
|
715
831
|
if (!taxClauseDefaults) return;
|
|
716
832
|
|
|
717
833
|
const clause = taxClauseDefaults[effectiveTransactionType] ?? "";
|
|
718
834
|
form.setValue("tax_clause", clause);
|
|
719
|
-
}, [effectiveTransactionType,
|
|
835
|
+
}, [activeEntity, effectiveTransactionType, form, isEditMode, taxClauseHydrationVersion]);
|
|
720
836
|
|
|
721
837
|
// Extract customer management logic into a custom hook
|
|
722
838
|
const {
|
|
@@ -745,6 +861,19 @@ export default function CreateInvoiceForm({
|
|
|
745
861
|
onError,
|
|
746
862
|
});
|
|
747
863
|
|
|
864
|
+
const { mutate: createCustomInvoice, isPending: isCreateCustomPending } = useCreateCustomInvoice({
|
|
865
|
+
entityId,
|
|
866
|
+
onSuccess: (data) => {
|
|
867
|
+
furs.saveCombo();
|
|
868
|
+
fina.saveCombo();
|
|
869
|
+
if (data.customer_id) {
|
|
870
|
+
queryClient.invalidateQueries({ queryKey: [CUSTOMERS_CACHE_KEY] });
|
|
871
|
+
}
|
|
872
|
+
onSuccess?.(data);
|
|
873
|
+
},
|
|
874
|
+
onError,
|
|
875
|
+
});
|
|
876
|
+
|
|
748
877
|
const { mutate: updateInvoice, isPending: isUpdatePending } = useUpdateInvoice({
|
|
749
878
|
entityId,
|
|
750
879
|
onSuccess: (data) => {
|
|
@@ -759,7 +888,7 @@ export default function CreateInvoiceForm({
|
|
|
759
888
|
onError,
|
|
760
889
|
});
|
|
761
890
|
|
|
762
|
-
const isPending = isCreatePending || isUpdatePending;
|
|
891
|
+
const isPending = isCreatePending || isCreateCustomPending || isUpdatePending;
|
|
763
892
|
|
|
764
893
|
// Shared submit logic for both regular save and save as draft
|
|
765
894
|
const submitInvoice = useCallback(
|
|
@@ -812,35 +941,55 @@ export default function CreateInvoiceForm({
|
|
|
812
941
|
}
|
|
813
942
|
}
|
|
814
943
|
|
|
815
|
-
const payload = prepareInvoiceSubmission(values as any, {
|
|
816
|
-
originalCustomer,
|
|
817
|
-
wasCustomerFormShown: showCustomerForm,
|
|
818
|
-
markAsPaid: isDraft || isEditMode ? false : markAsPaid,
|
|
819
|
-
payments: serializePaymentRows(paymentRows, paymentDocumentTotal),
|
|
820
|
-
furs: fursOptions,
|
|
821
|
-
fina: finaOptions,
|
|
822
|
-
eslog: eslogOptions,
|
|
823
|
-
priceModes: priceModesRef.current,
|
|
824
|
-
isDraft,
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
// Add force_linked_documents if set (used after conflict dialog approval)
|
|
828
|
-
if (forceLinkedDocuments) {
|
|
829
|
-
(payload as any).force_linked_documents = true;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
944
|
if (isEditMode && documentId) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
945
|
+
const updatePayload = prepareInvoiceUpdateSubmission(values as any, {
|
|
946
|
+
originalCustomer,
|
|
947
|
+
wasCustomerFormShown: showCustomerForm,
|
|
948
|
+
eslog: eslogOptions,
|
|
949
|
+
priceModes: priceModesRef.current,
|
|
950
|
+
}) as any;
|
|
951
|
+
|
|
952
|
+
if (forceLinkedDocuments) {
|
|
953
|
+
updatePayload.force_linked_documents = true;
|
|
954
|
+
}
|
|
955
|
+
|
|
836
956
|
updateInvoice({ id: documentId, data: updatePayload });
|
|
837
957
|
} else {
|
|
838
|
-
|
|
958
|
+
const payload = prepareInvoiceSubmission(values as any, {
|
|
959
|
+
originalCustomer,
|
|
960
|
+
wasCustomerFormShown: showCustomerForm,
|
|
961
|
+
markAsPaid: isDraft ? false : markAsPaid,
|
|
962
|
+
payments: serializePaymentRows(paymentRows, paymentDocumentTotal),
|
|
963
|
+
furs: fursOptions,
|
|
964
|
+
fina: finaOptions,
|
|
965
|
+
eslog: eslogOptions,
|
|
966
|
+
priceModes: priceModesRef.current,
|
|
967
|
+
isDraft,
|
|
968
|
+
});
|
|
969
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(values);
|
|
970
|
+
if (preservedExpectedTotalWithTax !== undefined) {
|
|
971
|
+
(payload as any).expected_total_with_tax = preservedExpectedTotalWithTax;
|
|
972
|
+
} else {
|
|
973
|
+
delete (payload as any).expected_total_with_tax;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
if (forceLinkedDocuments) {
|
|
977
|
+
(payload as any).force_linked_documents = true;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
if (customCreateTemplate && financialInputsMatchSource(values)) {
|
|
981
|
+
delete (payload as any).expected_total_with_tax;
|
|
982
|
+
createCustomInvoice(applyCustomCreateTemplate(payload as any, customCreateTemplate));
|
|
983
|
+
} else {
|
|
984
|
+
createInvoice(payload);
|
|
985
|
+
}
|
|
839
986
|
}
|
|
840
987
|
},
|
|
841
988
|
[
|
|
842
989
|
createInvoice,
|
|
990
|
+
createCustomInvoice,
|
|
843
991
|
updateInvoice,
|
|
992
|
+
customCreateTemplate,
|
|
844
993
|
documentId,
|
|
845
994
|
eslog,
|
|
846
995
|
finaValidationError,
|
|
@@ -856,6 +1005,8 @@ export default function CreateInvoiceForm({
|
|
|
856
1005
|
showCustomerForm,
|
|
857
1006
|
skipFiscalization,
|
|
858
1007
|
operatorPrefill,
|
|
1008
|
+
financialInputsMatchSource,
|
|
1009
|
+
getPreservedExpectedTotalWithTax,
|
|
859
1010
|
],
|
|
860
1011
|
);
|
|
861
1012
|
|
|
@@ -908,6 +1059,7 @@ export default function CreateInvoiceForm({
|
|
|
908
1059
|
// Track if initial setup has been done
|
|
909
1060
|
const initialSetupDoneRef = useRef(false);
|
|
910
1061
|
const hasInitialValues = !!initialValues;
|
|
1062
|
+
const hasInitialDueDate = !!initialValues?.date_due;
|
|
911
1063
|
const duplicateHydrationStartedAtRef = useRef<number | null>(hasInitialValues ? performance.now() : null);
|
|
912
1064
|
const duplicateHydrationLoggedRef = useRef(false);
|
|
913
1065
|
const appliedInitialValuesSignatureRef = useRef<string | null>(null);
|
|
@@ -923,6 +1075,7 @@ export default function CreateInvoiceForm({
|
|
|
923
1075
|
duplicateHydrationStartedAtRef.current = performance.now();
|
|
924
1076
|
duplicateHydrationLoggedRef.current = false;
|
|
925
1077
|
form.reset(formDefaultValues);
|
|
1078
|
+
setTaxClauseHydrationVersion((currentVersion) => currentVersion + 1);
|
|
926
1079
|
priceModesRef.current = initialPriceModes;
|
|
927
1080
|
}, [form, formDefaultValues, hasInitialValues, initialPriceModes]);
|
|
928
1081
|
|
|
@@ -932,6 +1085,26 @@ export default function CreateInvoiceForm({
|
|
|
932
1085
|
if (initialSetupDoneRef.current) return;
|
|
933
1086
|
if (!activeEntity) return;
|
|
934
1087
|
|
|
1088
|
+
if (isEditMode) {
|
|
1089
|
+
if (activeEntity.is_tax_subject) {
|
|
1090
|
+
const items = form.getValues("items") || [];
|
|
1091
|
+
if (items.length > 0 && (!items[0].taxes || items[0].taxes.length === 0)) {
|
|
1092
|
+
form.setValue("items.0.taxes", [{ tax_id: undefined }]);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
initialSetupDoneRef.current = true;
|
|
1097
|
+
if (hasInitialValues && duplicateHydrationStartedAtRef.current && !duplicateHydrationLoggedRef.current) {
|
|
1098
|
+
duplicateHydrationLoggedRef.current = true;
|
|
1099
|
+
emitInvoiceCreateDebug({
|
|
1100
|
+
stage: "entity_defaults_applied",
|
|
1101
|
+
hasInitialValues: true,
|
|
1102
|
+
elapsedMs: Number((performance.now() - duplicateHydrationStartedAtRef.current).toFixed(1)),
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
935
1108
|
const entityDefaultNote = (activeEntity.settings as any)?.default_invoice_note;
|
|
936
1109
|
if (entityDefaultNote && !form.getValues("note")) {
|
|
937
1110
|
form.setValue("note", entityDefaultNote);
|
|
@@ -944,13 +1117,12 @@ export default function CreateInvoiceForm({
|
|
|
944
1117
|
if (entityDefaultFooter && !form.getValues("footer")) {
|
|
945
1118
|
form.setValue("footer", entityDefaultFooter);
|
|
946
1119
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
form.setValue("signature", entityDefaultSignature);
|
|
1120
|
+
if (defaultSignature && !form.getValues("signature")) {
|
|
1121
|
+
form.setValue("signature", defaultSignature);
|
|
950
1122
|
}
|
|
951
1123
|
|
|
952
1124
|
// Auto-populate due date and due days type from entity settings when entity loads async
|
|
953
|
-
if (!isEditMode && !
|
|
1125
|
+
if (!isEditMode && !hasInitialDueDate) {
|
|
954
1126
|
const dueDays = (activeEntity.settings as any)?.default_invoice_due_days ?? 30;
|
|
955
1127
|
const currentDate = form.getValues("date");
|
|
956
1128
|
if (currentDate) {
|
|
@@ -976,7 +1148,7 @@ export default function CreateInvoiceForm({
|
|
|
976
1148
|
elapsedMs: Number((performance.now() - duplicateHydrationStartedAtRef.current).toFixed(1)),
|
|
977
1149
|
});
|
|
978
1150
|
}
|
|
979
|
-
}, [activeEntity, form, hasInitialValues,
|
|
1151
|
+
}, [activeEntity, defaultSignature, form, hasInitialDueDate, hasInitialValues, initialValues, isEditMode]);
|
|
980
1152
|
|
|
981
1153
|
// Recalculate due date when document date changes (skip in edit mode and custom due days)
|
|
982
1154
|
const prevDateRef = useRef(form.getValues("date"));
|
|
@@ -1009,20 +1181,10 @@ export default function CreateInvoiceForm({
|
|
|
1009
1181
|
|
|
1010
1182
|
const buildPreviewPayload = useCallback(
|
|
1011
1183
|
(formValues: any): InvoicePreviewPayload => {
|
|
1012
|
-
const
|
|
1013
|
-
const
|
|
1014
|
-
const { id: _id,
|
|
1015
|
-
|
|
1016
|
-
if (item.type === "separator") {
|
|
1017
|
-
return {
|
|
1018
|
-
type: "separator" as const,
|
|
1019
|
-
name: item.name || "",
|
|
1020
|
-
description: item.description || undefined,
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
const isGross = priceModesRef.current[index] ?? false;
|
|
1025
|
-
return isGross ? { ...rest, gross_price: price } : { ...rest, price };
|
|
1184
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(formValues);
|
|
1185
|
+
const previewItems = formValues.items?.map((item: any) => {
|
|
1186
|
+
const { id: _id, ...rest } = item;
|
|
1187
|
+
return rest;
|
|
1026
1188
|
});
|
|
1027
1189
|
return {
|
|
1028
1190
|
number: formValues.number,
|
|
@@ -1031,18 +1193,23 @@ export default function CreateInvoiceForm({
|
|
|
1031
1193
|
date_service_to: formValues.date_service_to,
|
|
1032
1194
|
customer_id: formValues.customer_id,
|
|
1033
1195
|
customer: formValues.customer,
|
|
1034
|
-
items:
|
|
1196
|
+
items: prepareDocumentItems(previewItems, priceModesRef.current),
|
|
1035
1197
|
currency_code: formValues.currency_code,
|
|
1036
1198
|
linked_documents: formValues.linked_documents,
|
|
1037
1199
|
...(forceLinkedDocuments ? { force_linked_documents: true } : {}),
|
|
1038
1200
|
reference: formValues.reference,
|
|
1039
1201
|
note: formValues.note,
|
|
1040
1202
|
payment_terms: formValues.payment_terms,
|
|
1203
|
+
tax_clause: formValues.tax_clause,
|
|
1204
|
+
footer: formValues.footer,
|
|
1041
1205
|
signature: formValues.signature,
|
|
1206
|
+
...(preservedExpectedTotalWithTax !== undefined
|
|
1207
|
+
? { expected_total_with_tax: preservedExpectedTotalWithTax }
|
|
1208
|
+
: {}),
|
|
1042
1209
|
...(normalizePtDocumentInput(formValues.pt) ? { pt: normalizePtDocumentInput(formValues.pt) } : {}),
|
|
1043
1210
|
};
|
|
1044
1211
|
},
|
|
1045
|
-
[forceLinkedDocuments],
|
|
1212
|
+
[forceLinkedDocuments, getPreservedExpectedTotalWithTax],
|
|
1046
1213
|
);
|
|
1047
1214
|
|
|
1048
1215
|
const emitCurrentPreviewPayload = useCallback(() => {
|
|
@@ -1283,6 +1450,10 @@ export default function CreateInvoiceForm({
|
|
|
1283
1450
|
dueDaysType,
|
|
1284
1451
|
onDueDaysTypeChange: handleDueDaysTypeChange,
|
|
1285
1452
|
}}
|
|
1453
|
+
dateLock={{
|
|
1454
|
+
isLocked: isFiscalizationDateLocked,
|
|
1455
|
+
reason: fiscalizationDateLockReason,
|
|
1456
|
+
}}
|
|
1286
1457
|
>
|
|
1287
1458
|
{/* Invoice-specific: Mark as paid section (UI-only state, not in form schema) */}
|
|
1288
1459
|
{/* Hide in edit mode - payments are managed separately */}
|
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
Items: "Артикули",
|
|
12
12
|
"Add item": "Add item",
|
|
13
13
|
Save: "Запази",
|
|
14
|
-
Update: "
|
|
14
|
+
Update: "Актуализирай",
|
|
15
15
|
"Save as Draft": "Save as Draft",
|
|
16
16
|
Quantity: "Quantity",
|
|
17
17
|
Price: "Цена",
|
|
@@ -25,16 +25,16 @@ export default {
|
|
|
25
25
|
"No taxes found": "No taxes found",
|
|
26
26
|
"Add new tax...": "Add new tax...",
|
|
27
27
|
Description: "Описание",
|
|
28
|
-
"Mark as Paid": "
|
|
29
|
-
Paid: "Платено",
|
|
30
|
-
"Invoice will be marked as fully paid upon creation": "
|
|
31
|
-
"Payment Type": "
|
|
28
|
+
"Mark as Paid": "Маркирай като платено",
|
|
29
|
+
"Paid": "Платено",
|
|
30
|
+
"Invoice will be marked as fully paid upon creation": "Фактурата ще бъде маркирана като напълно платена при създаване",
|
|
31
|
+
"Payment Type": "Вид плащане",
|
|
32
32
|
"Select payment type": "Изберете тип плащане",
|
|
33
|
-
Cash: "В брой",
|
|
33
|
+
"Cash": "В брой",
|
|
34
34
|
"Bank Transfer": "Банков превод",
|
|
35
|
-
Card: "Карта",
|
|
36
|
-
Check: "Чек",
|
|
37
|
-
Other: "Друго",
|
|
35
|
+
"Card": "Карта",
|
|
36
|
+
"Check": "Чек",
|
|
37
|
+
"Other": "Друго",
|
|
38
38
|
Note: "Note",
|
|
39
39
|
"Insert variable": "Insert variable",
|
|
40
40
|
"Add payment instructions, terms, or other notes...": "Add payment instructions, terms, or other notes...",
|
|
@@ -126,6 +126,7 @@ export default {
|
|
|
126
126
|
"Delivery note": "Доставна бележка",
|
|
127
127
|
Invoice: "Фактура",
|
|
128
128
|
Estimate: "Оферта",
|
|
129
|
+
"Proforma invoice": "Проформа фактура",
|
|
129
130
|
"Credit note": "Кредитно известие",
|
|
130
131
|
"Advance invoice": "Авансова фактура",
|
|
131
132
|
"FINA fiscalized invoices always use the current date": "FINA fiscalized invoices always use the current date",
|
|
@@ -136,11 +137,11 @@ export default {
|
|
|
136
137
|
"60 days": "60 days",
|
|
137
138
|
"90 days": "90 дни",
|
|
138
139
|
Custom: "Custom",
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
From: "
|
|
143
|
-
To: "
|
|
140
|
+
// Service date
|
|
141
|
+
"Service Date": "Дата на услугата",
|
|
142
|
+
"Service Period": "Период на услугата",
|
|
143
|
+
From: "От",
|
|
144
|
+
To: "До",
|
|
144
145
|
"Add separator": "Add separator",
|
|
145
146
|
"Section header": "Section header",
|
|
146
147
|
"Section title...": "Section title...",
|
|
@@ -161,4 +162,12 @@ export default {
|
|
|
161
162
|
"Domestic B2B invoicing in Croatia is not supported": "Domestic B2B invoicing in Croatia is not supported",
|
|
162
163
|
"FINA fiscalization must be enabled for domestic invoices":
|
|
163
164
|
"FINA fiscalization must be enabled for domestic invoices",
|
|
165
|
+
"Please select": "Моля, изберете",
|
|
166
|
+
"Amount": "Сума",
|
|
167
|
+
"Add payment": "Добави плащане",
|
|
168
|
+
"Recorded now": "Регистрирано сега",
|
|
169
|
+
"Remaining due": "Остава за плащане",
|
|
170
|
+
"Remaining to allocate": "Остава за разпределяне",
|
|
171
|
+
"This document must be fully paid on creation": "Този документ трябва да бъде напълно платен при създаване",
|
|
172
|
+
"Record one or more payments on creation": "Регистрирайте едно или повече плащания при създаване",
|
|
164
173
|
} as const;
|