@spaceinvoices/react-ui 0.4.12 → 0.4.31
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 +189 -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 +253 -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 +132 -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 +114 -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 +195 -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 +230 -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 +61 -30
- 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,40 @@ 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),
|
|
179
209
|
}
|
|
180
210
|
: {}),
|
|
181
211
|
}))
|
|
@@ -190,14 +220,20 @@ function buildInvoiceFormValues({
|
|
|
190
220
|
],
|
|
191
221
|
currency_code: initialValues?.currency_code || currencyCode || "EUR",
|
|
192
222
|
reference: (initialValues as any)?.reference ?? "",
|
|
193
|
-
note: initialValues?.note ?? defaultInvoiceNote,
|
|
223
|
+
note: initialValues?.note ?? (isEditMode ? "" : defaultInvoiceNote),
|
|
194
224
|
tax_clause: (initialValues as any)?.tax_clause ?? "",
|
|
195
|
-
payment_terms: initialValues?.payment_terms ?? defaultPaymentTerms,
|
|
196
|
-
footer: (initialValues as any)?.footer ?? defaultFooter,
|
|
225
|
+
payment_terms: initialValues?.payment_terms ?? (isEditMode ? "" : defaultPaymentTerms),
|
|
226
|
+
footer: (initialValues as any)?.footer ?? (isEditMode ? "" : defaultFooter),
|
|
227
|
+
signature: (initialValues as any)?.signature ?? (isEditMode ? "" : defaultSignature),
|
|
197
228
|
date_due:
|
|
198
229
|
initialValues?.date_due ||
|
|
199
|
-
|
|
200
|
-
|
|
230
|
+
(isEditMode
|
|
231
|
+
? undefined
|
|
232
|
+
: calculateDueDate(initialValues?.date || new Date().toISOString(), defaultInvoiceDueDays)),
|
|
233
|
+
date_service:
|
|
234
|
+
(initialValues as any)?.date_service ??
|
|
235
|
+
(isEditMode ? undefined : (initialValues?.date ?? new Date().toISOString())),
|
|
236
|
+
date_service_to: (initialValues as any)?.date_service_to ?? undefined,
|
|
201
237
|
linked_documents: (initialValues as any)?.linked_documents,
|
|
202
238
|
pt: ((initialValues as any)?.pt as PtDocumentInputForm | undefined) ?? undefined,
|
|
203
239
|
};
|
|
@@ -240,6 +276,7 @@ export default function CreateInvoiceForm({
|
|
|
240
276
|
const defaultInvoiceNote = (activeEntity?.settings as any)?.default_invoice_note || "";
|
|
241
277
|
const defaultPaymentTerms = (activeEntity?.settings as any)?.default_invoice_payment_terms || "";
|
|
242
278
|
const defaultFooter = (activeEntity?.settings as any)?.document_footer || "";
|
|
279
|
+
const defaultSignature = (activeEntity?.settings as any)?.default_document_signature || "";
|
|
243
280
|
const defaultInvoiceDueDays = (activeEntity?.settings as any)?.default_invoice_due_days ?? 30;
|
|
244
281
|
|
|
245
282
|
// ============================================================================
|
|
@@ -284,6 +321,36 @@ export default function CreateInvoiceForm({
|
|
|
284
321
|
}, {} as PriceModesMap);
|
|
285
322
|
}, [initialValues?.items]);
|
|
286
323
|
const priceModesRef = useRef<PriceModesMap>(initialPriceModes);
|
|
324
|
+
const customCreateTemplate = (initialValues as any)?._custom_create_template;
|
|
325
|
+
const financialInputsMatchSource = useCallback(
|
|
326
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
327
|
+
financialInputsMatchInitial({
|
|
328
|
+
initialItems: initialValues?.items,
|
|
329
|
+
currentItems: values.items,
|
|
330
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
331
|
+
currentCurrencyCode: values.currency_code,
|
|
332
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
333
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
334
|
+
initialPriceModes,
|
|
335
|
+
currentPriceModes: priceModesRef.current,
|
|
336
|
+
}),
|
|
337
|
+
[initialPriceModes, initialValues],
|
|
338
|
+
);
|
|
339
|
+
const getPreservedExpectedTotalWithTax = useCallback(
|
|
340
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
341
|
+
resolvePreservedExpectedTotal({
|
|
342
|
+
initialExpectedTotalWithTax: (initialValues as any)?._preserved_expected_total_with_tax,
|
|
343
|
+
initialItems: initialValues?.items,
|
|
344
|
+
currentItems: values.items,
|
|
345
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
346
|
+
currentCurrencyCode: values.currency_code,
|
|
347
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
348
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
349
|
+
initialPriceModes,
|
|
350
|
+
currentPriceModes: priceModesRef.current,
|
|
351
|
+
}),
|
|
352
|
+
[initialPriceModes, initialValues],
|
|
353
|
+
);
|
|
287
354
|
|
|
288
355
|
const formDefaultValues = useMemo(
|
|
289
356
|
() =>
|
|
@@ -293,7 +360,9 @@ export default function CreateInvoiceForm({
|
|
|
293
360
|
defaultInvoiceNote,
|
|
294
361
|
defaultPaymentTerms,
|
|
295
362
|
defaultFooter,
|
|
363
|
+
defaultSignature,
|
|
296
364
|
defaultInvoiceDueDays,
|
|
365
|
+
isEditMode,
|
|
297
366
|
}),
|
|
298
367
|
[
|
|
299
368
|
activeEntity?.currency_code,
|
|
@@ -301,7 +370,9 @@ export default function CreateInvoiceForm({
|
|
|
301
370
|
defaultInvoiceDueDays,
|
|
302
371
|
defaultInvoiceNote,
|
|
303
372
|
defaultPaymentTerms,
|
|
373
|
+
defaultSignature,
|
|
304
374
|
initialValues,
|
|
375
|
+
isEditMode,
|
|
305
376
|
],
|
|
306
377
|
);
|
|
307
378
|
|
|
@@ -470,6 +541,10 @@ export default function CreateInvoiceForm({
|
|
|
470
541
|
const useFinaNumbering =
|
|
471
542
|
!!fina.isActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
|
|
472
543
|
const isFinaNonDomestic = !!fina.isActive && !useFinaNumbering;
|
|
544
|
+
const isFiscalizationDateLocked = !isEditMode && (isFursActive || useFinaNumbering);
|
|
545
|
+
const fiscalizationDateLockReason = useFinaNumbering
|
|
546
|
+
? t("FINA fiscalized invoices always use the current date")
|
|
547
|
+
: t("FURS fiscalized invoices always use the current date");
|
|
473
548
|
|
|
474
549
|
// ============================================================================
|
|
475
550
|
// Next Invoice Number Preview
|
|
@@ -501,22 +576,42 @@ export default function CreateInvoiceForm({
|
|
|
501
576
|
: furs.isLoading || !furs.isSelectionReady || fina.isLoading || !fina.isSelectionReady || isNextNumberLoading;
|
|
502
577
|
|
|
503
578
|
// Update header action with FURS and e-SLOG toggle buttons
|
|
579
|
+
const headerActionSignatureRef = useRef<string | null>(null);
|
|
504
580
|
useEffect(() => {
|
|
505
581
|
if (!onHeaderActionChange) return;
|
|
506
582
|
|
|
507
583
|
// Don't set header action while loading or in edit mode (FURS/FINA/e-SLOG not editable)
|
|
508
584
|
if (furs.isLoading || fina.isLoading || isEditMode) {
|
|
585
|
+
if (headerActionSignatureRef.current === null) return;
|
|
586
|
+
headerActionSignatureRef.current = null;
|
|
509
587
|
onHeaderActionChange(null);
|
|
510
588
|
return;
|
|
511
589
|
}
|
|
512
590
|
|
|
513
591
|
const showFursToggle = furs.isEnabled && furs.hasPremises;
|
|
514
592
|
const showEslogToggle = eslog.isAvailable;
|
|
593
|
+
const isFursChecked = !skipFiscalization;
|
|
594
|
+
const isEslogChecked = eslog.isEnabled === true;
|
|
595
|
+
const headerActionSignature =
|
|
596
|
+
showFursToggle || showEslogToggle
|
|
597
|
+
? JSON.stringify({
|
|
598
|
+
showFursToggle,
|
|
599
|
+
showEslogToggle,
|
|
600
|
+
isFursChecked,
|
|
601
|
+
isEslogChecked,
|
|
602
|
+
eslogLabel: t("e-SLOG"),
|
|
603
|
+
eslogEnabledDescription: t("Click to skip e-SLOG validation for this invoice"),
|
|
604
|
+
eslogDisabledDescription: t("Click to enable e-SLOG validation"),
|
|
605
|
+
fiscalizationLabel: t("Fiscally verify"),
|
|
606
|
+
fiscalizationEnabledDescription: t("Click to skip fiscalization for this invoice"),
|
|
607
|
+
fiscalizationDisabledDescription: t("Click to enable fiscalization"),
|
|
608
|
+
})
|
|
609
|
+
: null;
|
|
610
|
+
|
|
611
|
+
if (headerActionSignatureRef.current === headerActionSignature) return;
|
|
612
|
+
headerActionSignatureRef.current = headerActionSignature;
|
|
515
613
|
|
|
516
614
|
if (showFursToggle || showEslogToggle) {
|
|
517
|
-
const isFursChecked = !skipFiscalization;
|
|
518
|
-
const isEslogChecked = eslog.isEnabled === true;
|
|
519
|
-
|
|
520
615
|
onHeaderActionChange(
|
|
521
616
|
<div className="flex items-center gap-2">
|
|
522
617
|
{/* e-SLOG toggle */}
|
|
@@ -615,6 +710,19 @@ export default function CreateInvoiceForm({
|
|
|
615
710
|
}
|
|
616
711
|
}, [nextNumberData?.number, form]);
|
|
617
712
|
|
|
713
|
+
useEffect(() => {
|
|
714
|
+
if (!isFiscalizationDateLocked) return;
|
|
715
|
+
|
|
716
|
+
const today = new Date();
|
|
717
|
+
if (isSameCalendarDate(form.getValues("date"), today)) return;
|
|
718
|
+
|
|
719
|
+
form.setValue("date", today.toISOString(), {
|
|
720
|
+
shouldDirty: true,
|
|
721
|
+
shouldTouch: false,
|
|
722
|
+
shouldValidate: true,
|
|
723
|
+
});
|
|
724
|
+
}, [form, isFiscalizationDateLocked]);
|
|
725
|
+
|
|
618
726
|
// Watch fields needed for document note/payment terms preview
|
|
619
727
|
const watchedNumber = useWatch({ control: form.control, name: "number" });
|
|
620
728
|
const watchedDate = useWatch({ control: form.control, name: "date" });
|
|
@@ -707,16 +815,23 @@ export default function CreateInvoiceForm({
|
|
|
707
815
|
// Auto-populate tax_clause from entity settings when transaction type changes
|
|
708
816
|
const effectiveTransactionType = transactionType ?? "domestic";
|
|
709
817
|
const prevTransactionTypeRef = useRef<string | undefined>(undefined);
|
|
818
|
+
const prevTaxClauseHydrationVersionRef = useRef<number | undefined>(undefined);
|
|
819
|
+
const [taxClauseHydrationVersion, setTaxClauseHydrationVersion] = useState(0);
|
|
710
820
|
useEffect(() => {
|
|
711
|
-
if (
|
|
821
|
+
if (isEditMode) return;
|
|
822
|
+
const transactionTypeChanged = effectiveTransactionType !== prevTransactionTypeRef.current;
|
|
823
|
+
const hydrationVersionChanged = taxClauseHydrationVersion !== prevTaxClauseHydrationVersionRef.current;
|
|
824
|
+
if (!transactionTypeChanged && !hydrationVersionChanged) return;
|
|
825
|
+
|
|
712
826
|
prevTransactionTypeRef.current = effectiveTransactionType;
|
|
827
|
+
prevTaxClauseHydrationVersionRef.current = taxClauseHydrationVersion;
|
|
713
828
|
|
|
714
829
|
const taxClauseDefaults = (activeEntity?.settings as any)?.tax_clause_defaults;
|
|
715
830
|
if (!taxClauseDefaults) return;
|
|
716
831
|
|
|
717
832
|
const clause = taxClauseDefaults[effectiveTransactionType] ?? "";
|
|
718
833
|
form.setValue("tax_clause", clause);
|
|
719
|
-
}, [effectiveTransactionType,
|
|
834
|
+
}, [activeEntity, effectiveTransactionType, form, isEditMode, taxClauseHydrationVersion]);
|
|
720
835
|
|
|
721
836
|
// Extract customer management logic into a custom hook
|
|
722
837
|
const {
|
|
@@ -745,6 +860,19 @@ export default function CreateInvoiceForm({
|
|
|
745
860
|
onError,
|
|
746
861
|
});
|
|
747
862
|
|
|
863
|
+
const { mutate: createCustomInvoice, isPending: isCreateCustomPending } = useCreateCustomInvoice({
|
|
864
|
+
entityId,
|
|
865
|
+
onSuccess: (data) => {
|
|
866
|
+
furs.saveCombo();
|
|
867
|
+
fina.saveCombo();
|
|
868
|
+
if (data.customer_id) {
|
|
869
|
+
queryClient.invalidateQueries({ queryKey: [CUSTOMERS_CACHE_KEY] });
|
|
870
|
+
}
|
|
871
|
+
onSuccess?.(data);
|
|
872
|
+
},
|
|
873
|
+
onError,
|
|
874
|
+
});
|
|
875
|
+
|
|
748
876
|
const { mutate: updateInvoice, isPending: isUpdatePending } = useUpdateInvoice({
|
|
749
877
|
entityId,
|
|
750
878
|
onSuccess: (data) => {
|
|
@@ -759,7 +887,7 @@ export default function CreateInvoiceForm({
|
|
|
759
887
|
onError,
|
|
760
888
|
});
|
|
761
889
|
|
|
762
|
-
const isPending = isCreatePending || isUpdatePending;
|
|
890
|
+
const isPending = isCreatePending || isCreateCustomPending || isUpdatePending;
|
|
763
891
|
|
|
764
892
|
// Shared submit logic for both regular save and save as draft
|
|
765
893
|
const submitInvoice = useCallback(
|
|
@@ -812,35 +940,55 @@ export default function CreateInvoiceForm({
|
|
|
812
940
|
}
|
|
813
941
|
}
|
|
814
942
|
|
|
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
943
|
if (isEditMode && documentId) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
944
|
+
const updatePayload = prepareInvoiceUpdateSubmission(values as any, {
|
|
945
|
+
originalCustomer,
|
|
946
|
+
wasCustomerFormShown: showCustomerForm,
|
|
947
|
+
eslog: eslogOptions,
|
|
948
|
+
priceModes: priceModesRef.current,
|
|
949
|
+
}) as any;
|
|
950
|
+
|
|
951
|
+
if (forceLinkedDocuments) {
|
|
952
|
+
updatePayload.force_linked_documents = true;
|
|
953
|
+
}
|
|
954
|
+
|
|
836
955
|
updateInvoice({ id: documentId, data: updatePayload });
|
|
837
956
|
} else {
|
|
838
|
-
|
|
957
|
+
const payload = prepareInvoiceSubmission(values as any, {
|
|
958
|
+
originalCustomer,
|
|
959
|
+
wasCustomerFormShown: showCustomerForm,
|
|
960
|
+
markAsPaid: isDraft ? false : markAsPaid,
|
|
961
|
+
payments: serializePaymentRows(paymentRows, paymentDocumentTotal),
|
|
962
|
+
furs: fursOptions,
|
|
963
|
+
fina: finaOptions,
|
|
964
|
+
eslog: eslogOptions,
|
|
965
|
+
priceModes: priceModesRef.current,
|
|
966
|
+
isDraft,
|
|
967
|
+
});
|
|
968
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(values);
|
|
969
|
+
if (preservedExpectedTotalWithTax !== undefined) {
|
|
970
|
+
(payload as any).expected_total_with_tax = preservedExpectedTotalWithTax;
|
|
971
|
+
} else {
|
|
972
|
+
delete (payload as any).expected_total_with_tax;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
if (forceLinkedDocuments) {
|
|
976
|
+
(payload as any).force_linked_documents = true;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
if (customCreateTemplate && financialInputsMatchSource(values)) {
|
|
980
|
+
delete (payload as any).expected_total_with_tax;
|
|
981
|
+
createCustomInvoice(applyCustomCreateTemplate(payload as any, customCreateTemplate));
|
|
982
|
+
} else {
|
|
983
|
+
createInvoice(payload);
|
|
984
|
+
}
|
|
839
985
|
}
|
|
840
986
|
},
|
|
841
987
|
[
|
|
842
988
|
createInvoice,
|
|
989
|
+
createCustomInvoice,
|
|
843
990
|
updateInvoice,
|
|
991
|
+
customCreateTemplate,
|
|
844
992
|
documentId,
|
|
845
993
|
eslog,
|
|
846
994
|
finaValidationError,
|
|
@@ -856,6 +1004,8 @@ export default function CreateInvoiceForm({
|
|
|
856
1004
|
showCustomerForm,
|
|
857
1005
|
skipFiscalization,
|
|
858
1006
|
operatorPrefill,
|
|
1007
|
+
financialInputsMatchSource,
|
|
1008
|
+
getPreservedExpectedTotalWithTax,
|
|
859
1009
|
],
|
|
860
1010
|
);
|
|
861
1011
|
|
|
@@ -908,6 +1058,7 @@ export default function CreateInvoiceForm({
|
|
|
908
1058
|
// Track if initial setup has been done
|
|
909
1059
|
const initialSetupDoneRef = useRef(false);
|
|
910
1060
|
const hasInitialValues = !!initialValues;
|
|
1061
|
+
const hasInitialDueDate = !!initialValues?.date_due;
|
|
911
1062
|
const duplicateHydrationStartedAtRef = useRef<number | null>(hasInitialValues ? performance.now() : null);
|
|
912
1063
|
const duplicateHydrationLoggedRef = useRef(false);
|
|
913
1064
|
const appliedInitialValuesSignatureRef = useRef<string | null>(null);
|
|
@@ -923,6 +1074,7 @@ export default function CreateInvoiceForm({
|
|
|
923
1074
|
duplicateHydrationStartedAtRef.current = performance.now();
|
|
924
1075
|
duplicateHydrationLoggedRef.current = false;
|
|
925
1076
|
form.reset(formDefaultValues);
|
|
1077
|
+
setTaxClauseHydrationVersion((currentVersion) => currentVersion + 1);
|
|
926
1078
|
priceModesRef.current = initialPriceModes;
|
|
927
1079
|
}, [form, formDefaultValues, hasInitialValues, initialPriceModes]);
|
|
928
1080
|
|
|
@@ -932,6 +1084,26 @@ export default function CreateInvoiceForm({
|
|
|
932
1084
|
if (initialSetupDoneRef.current) return;
|
|
933
1085
|
if (!activeEntity) return;
|
|
934
1086
|
|
|
1087
|
+
if (isEditMode) {
|
|
1088
|
+
if (activeEntity.is_tax_subject) {
|
|
1089
|
+
const items = form.getValues("items") || [];
|
|
1090
|
+
if (items.length > 0 && (!items[0].taxes || items[0].taxes.length === 0)) {
|
|
1091
|
+
form.setValue("items.0.taxes", [{ tax_id: undefined }]);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
initialSetupDoneRef.current = true;
|
|
1096
|
+
if (hasInitialValues && duplicateHydrationStartedAtRef.current && !duplicateHydrationLoggedRef.current) {
|
|
1097
|
+
duplicateHydrationLoggedRef.current = true;
|
|
1098
|
+
emitInvoiceCreateDebug({
|
|
1099
|
+
stage: "entity_defaults_applied",
|
|
1100
|
+
hasInitialValues: true,
|
|
1101
|
+
elapsedMs: Number((performance.now() - duplicateHydrationStartedAtRef.current).toFixed(1)),
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
935
1107
|
const entityDefaultNote = (activeEntity.settings as any)?.default_invoice_note;
|
|
936
1108
|
if (entityDefaultNote && !form.getValues("note")) {
|
|
937
1109
|
form.setValue("note", entityDefaultNote);
|
|
@@ -944,13 +1116,12 @@ export default function CreateInvoiceForm({
|
|
|
944
1116
|
if (entityDefaultFooter && !form.getValues("footer")) {
|
|
945
1117
|
form.setValue("footer", entityDefaultFooter);
|
|
946
1118
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
form.setValue("signature", entityDefaultSignature);
|
|
1119
|
+
if (defaultSignature && !form.getValues("signature")) {
|
|
1120
|
+
form.setValue("signature", defaultSignature);
|
|
950
1121
|
}
|
|
951
1122
|
|
|
952
1123
|
// Auto-populate due date and due days type from entity settings when entity loads async
|
|
953
|
-
if (!isEditMode && !
|
|
1124
|
+
if (!isEditMode && !hasInitialDueDate) {
|
|
954
1125
|
const dueDays = (activeEntity.settings as any)?.default_invoice_due_days ?? 30;
|
|
955
1126
|
const currentDate = form.getValues("date");
|
|
956
1127
|
if (currentDate) {
|
|
@@ -976,7 +1147,7 @@ export default function CreateInvoiceForm({
|
|
|
976
1147
|
elapsedMs: Number((performance.now() - duplicateHydrationStartedAtRef.current).toFixed(1)),
|
|
977
1148
|
});
|
|
978
1149
|
}
|
|
979
|
-
}, [activeEntity, form, hasInitialValues,
|
|
1150
|
+
}, [activeEntity, defaultSignature, form, hasInitialDueDate, hasInitialValues, initialValues, isEditMode]);
|
|
980
1151
|
|
|
981
1152
|
// Recalculate due date when document date changes (skip in edit mode and custom due days)
|
|
982
1153
|
const prevDateRef = useRef(form.getValues("date"));
|
|
@@ -1009,20 +1180,10 @@ export default function CreateInvoiceForm({
|
|
|
1009
1180
|
|
|
1010
1181
|
const buildPreviewPayload = useCallback(
|
|
1011
1182
|
(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 };
|
|
1183
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(formValues);
|
|
1184
|
+
const previewItems = formValues.items?.map((item: any) => {
|
|
1185
|
+
const { id: _id, ...rest } = item;
|
|
1186
|
+
return rest;
|
|
1026
1187
|
});
|
|
1027
1188
|
return {
|
|
1028
1189
|
number: formValues.number,
|
|
@@ -1031,18 +1192,23 @@ export default function CreateInvoiceForm({
|
|
|
1031
1192
|
date_service_to: formValues.date_service_to,
|
|
1032
1193
|
customer_id: formValues.customer_id,
|
|
1033
1194
|
customer: formValues.customer,
|
|
1034
|
-
items:
|
|
1195
|
+
items: prepareDocumentItems(previewItems, priceModesRef.current),
|
|
1035
1196
|
currency_code: formValues.currency_code,
|
|
1036
1197
|
linked_documents: formValues.linked_documents,
|
|
1037
1198
|
...(forceLinkedDocuments ? { force_linked_documents: true } : {}),
|
|
1038
1199
|
reference: formValues.reference,
|
|
1039
1200
|
note: formValues.note,
|
|
1040
1201
|
payment_terms: formValues.payment_terms,
|
|
1202
|
+
tax_clause: formValues.tax_clause,
|
|
1203
|
+
footer: formValues.footer,
|
|
1041
1204
|
signature: formValues.signature,
|
|
1205
|
+
...(preservedExpectedTotalWithTax !== undefined
|
|
1206
|
+
? { expected_total_with_tax: preservedExpectedTotalWithTax }
|
|
1207
|
+
: {}),
|
|
1042
1208
|
...(normalizePtDocumentInput(formValues.pt) ? { pt: normalizePtDocumentInput(formValues.pt) } : {}),
|
|
1043
1209
|
};
|
|
1044
1210
|
},
|
|
1045
|
-
[forceLinkedDocuments],
|
|
1211
|
+
[forceLinkedDocuments, getPreservedExpectedTotalWithTax],
|
|
1046
1212
|
);
|
|
1047
1213
|
|
|
1048
1214
|
const emitCurrentPreviewPayload = useCallback(() => {
|
|
@@ -1283,6 +1449,10 @@ export default function CreateInvoiceForm({
|
|
|
1283
1449
|
dueDaysType,
|
|
1284
1450
|
onDueDaysTypeChange: handleDueDaysTypeChange,
|
|
1285
1451
|
}}
|
|
1452
|
+
dateLock={{
|
|
1453
|
+
isLocked: isFiscalizationDateLocked,
|
|
1454
|
+
reason: fiscalizationDateLockReason,
|
|
1455
|
+
}}
|
|
1286
1456
|
>
|
|
1287
1457
|
{/* Invoice-specific: Mark as paid section (UI-only state, not in form schema) */}
|
|
1288
1458
|
{/* 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;
|