@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
2
|
-
import type { CreateCreditNoteRequest, CreditNote } from "@spaceinvoices/js-sdk";
|
|
2
|
+
import type { CreateCreditNoteRequest, CreditNote, UpdateCreditNote } from "@spaceinvoices/js-sdk";
|
|
3
3
|
import { useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { Check, X } from "lucide-react";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
@@ -21,12 +21,14 @@ import {
|
|
|
21
21
|
type PtDocumentInputForm,
|
|
22
22
|
ptDocumentInputFormSchema,
|
|
23
23
|
} from "@/ui/lib/pt-document-input";
|
|
24
|
+
import { normalizeLineItemDiscountsForForm } from "@/ui/lib/schemas/shared";
|
|
24
25
|
import type { ComponentTranslationProps } from "@/ui/lib/translation";
|
|
25
26
|
import { createTranslation } from "@/ui/lib/translation";
|
|
26
27
|
import { cn } from "@/ui/lib/utils";
|
|
27
28
|
import { useEntities } from "@/ui/providers/entities-context";
|
|
28
29
|
import { useFormFooterRegistration } from "@/ui/providers/form-footer-context";
|
|
29
30
|
import { CUSTOMERS_CACHE_KEY } from "../../customers/customers.hooks";
|
|
31
|
+
import { withCreditNoteIssueDateValidation } from "../../documents/create/document-date-validation";
|
|
30
32
|
import {
|
|
31
33
|
DocumentDetailsSection,
|
|
32
34
|
DocumentFooterField,
|
|
@@ -48,9 +50,21 @@ import {
|
|
|
48
50
|
serializePaymentRows,
|
|
49
51
|
validatePaymentRows,
|
|
50
52
|
} from "../../documents/create/payment-rows";
|
|
53
|
+
import { prepareDocumentItems } from "../../documents/create/prepare-document-submission";
|
|
54
|
+
import { applyCustomCreateTemplate } from "../../documents/create/custom-create-template";
|
|
55
|
+
import { financialInputsMatchInitial, resolvePreservedExpectedTotal } from "../../documents/create/preserved-expected-total";
|
|
51
56
|
import { useDocumentCustomerForm } from "../../documents/create/use-document-customer-form";
|
|
52
57
|
import type { DocumentTypes } from "../../documents/types";
|
|
53
|
-
import
|
|
58
|
+
import invoiceDe from "../../invoices/create/locales/de";
|
|
59
|
+
import invoiceEs from "../../invoices/create/locales/es";
|
|
60
|
+
import invoiceFr from "../../invoices/create/locales/fr";
|
|
61
|
+
import invoiceHr from "../../invoices/create/locales/hr";
|
|
62
|
+
import invoiceIt from "../../invoices/create/locales/it";
|
|
63
|
+
import invoiceNl from "../../invoices/create/locales/nl";
|
|
64
|
+
import invoicePl from "../../invoices/create/locales/pl";
|
|
65
|
+
import invoicePt from "../../invoices/create/locales/pt";
|
|
66
|
+
import invoiceSl from "../../invoices/create/locales/sl";
|
|
67
|
+
import { useCreateCreditNote, useCreateCustomCreditNote, useUpdateCreditNote } from "../credit-notes.hooks";
|
|
54
68
|
import de from "./locales/de";
|
|
55
69
|
import es from "./locales/es";
|
|
56
70
|
import fr from "./locales/fr";
|
|
@@ -60,25 +74,40 @@ import nl from "./locales/nl";
|
|
|
60
74
|
import pl from "./locales/pl";
|
|
61
75
|
import pt from "./locales/pt";
|
|
62
76
|
import sl from "./locales/sl";
|
|
63
|
-
import { prepareCreditNoteSubmission } from "./prepare-credit-note-submission";
|
|
77
|
+
import { prepareCreditNoteSubmission, prepareCreditNoteUpdateSubmission } from "./prepare-credit-note-submission";
|
|
64
78
|
|
|
65
79
|
const translations = {
|
|
66
|
-
sl,
|
|
67
|
-
de,
|
|
68
|
-
it,
|
|
69
|
-
fr,
|
|
70
|
-
es,
|
|
71
|
-
pt,
|
|
72
|
-
nl,
|
|
73
|
-
pl,
|
|
74
|
-
hr,
|
|
80
|
+
sl: { ...invoiceSl, ...sl },
|
|
81
|
+
de: { ...invoiceDe, ...de },
|
|
82
|
+
it: { ...invoiceIt, ...it },
|
|
83
|
+
fr: { ...invoiceFr, ...fr },
|
|
84
|
+
es: { ...invoiceEs, ...es },
|
|
85
|
+
pt: { ...invoicePt, ...pt },
|
|
86
|
+
nl: { ...invoiceNl, ...nl },
|
|
87
|
+
pl: { ...invoicePl, ...pl },
|
|
88
|
+
hr: { ...invoiceHr, ...hr },
|
|
75
89
|
} as const;
|
|
76
|
-
const createCreditNoteFormSchema =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
const createCreditNoteFormSchema = withCreditNoteIssueDateValidation(
|
|
91
|
+
withRequiredDocumentItemFields(
|
|
92
|
+
createCreditNoteSchema.extend({
|
|
93
|
+
pt: ptDocumentInputFormSchema.optional(),
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
80
96
|
);
|
|
81
97
|
|
|
98
|
+
function isSameCalendarDate(left: string | Date | undefined, right: string | Date): boolean {
|
|
99
|
+
if (!left) return false;
|
|
100
|
+
|
|
101
|
+
const leftDate = new Date(left);
|
|
102
|
+
const rightDate = new Date(right);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
leftDate.getFullYear() === rightDate.getFullYear() &&
|
|
106
|
+
leftDate.getMonth() === rightDate.getMonth() &&
|
|
107
|
+
leftDate.getDate() === rightDate.getDate()
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
82
111
|
// Form values: extend schema with local-only fields (number is for display, not sent to API)
|
|
83
112
|
type CreateCreditNoteFormValues = z.infer<typeof createCreditNoteFormSchema> & {
|
|
84
113
|
number?: string;
|
|
@@ -99,6 +128,8 @@ type CreateCreditNoteFormProps = {
|
|
|
99
128
|
initialValues?: Partial<CreateCreditNoteRequest>;
|
|
100
129
|
/** Whether draft actions should be available in the UI */
|
|
101
130
|
allowDrafts?: boolean;
|
|
131
|
+
mode?: "create" | "edit";
|
|
132
|
+
documentId?: string;
|
|
102
133
|
/** Optional app-level content rendered inside the details section. */
|
|
103
134
|
detailsExtras?: ReactNode;
|
|
104
135
|
/** Request-scoped operator override for embed fiscalization flows. */
|
|
@@ -116,6 +147,8 @@ export default function CreateCreditNoteForm({
|
|
|
116
147
|
onHeaderActionChange,
|
|
117
148
|
initialValues,
|
|
118
149
|
allowDrafts = true,
|
|
150
|
+
mode = "create",
|
|
151
|
+
documentId,
|
|
119
152
|
detailsExtras,
|
|
120
153
|
operatorPrefill,
|
|
121
154
|
translationLocale,
|
|
@@ -133,6 +166,7 @@ export default function CreateCreditNoteForm({
|
|
|
133
166
|
|
|
134
167
|
const { activeEntity } = useEntities();
|
|
135
168
|
const queryClient = useQueryClient();
|
|
169
|
+
const isEditMode = mode === "edit";
|
|
136
170
|
|
|
137
171
|
// ============================================================================
|
|
138
172
|
// FURS & FINA Premise Selection (shared hook)
|
|
@@ -161,31 +195,68 @@ export default function CreateCreditNoteForm({
|
|
|
161
195
|
}, {} as PriceModesMap);
|
|
162
196
|
}, [initialValues?.items]);
|
|
163
197
|
const priceModesRef = useRef<PriceModesMap>(initialPriceModes);
|
|
198
|
+
const customCreateTemplate = (initialValues as any)?._custom_create_template;
|
|
199
|
+
const financialInputsMatchSource = useCallback(
|
|
200
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
201
|
+
financialInputsMatchInitial({
|
|
202
|
+
initialItems: initialValues?.items,
|
|
203
|
+
currentItems: values.items,
|
|
204
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
205
|
+
currentCurrencyCode: values.currency_code,
|
|
206
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
207
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
208
|
+
initialPriceModes,
|
|
209
|
+
currentPriceModes: priceModesRef.current,
|
|
210
|
+
}),
|
|
211
|
+
[initialPriceModes, initialValues],
|
|
212
|
+
);
|
|
213
|
+
const getPreservedExpectedTotalWithTax = useCallback(
|
|
214
|
+
(values: { items?: any[]; currency_code?: string; calculation_mode?: string | null }) =>
|
|
215
|
+
resolvePreservedExpectedTotal({
|
|
216
|
+
initialExpectedTotalWithTax: (initialValues as any)?._preserved_expected_total_with_tax,
|
|
217
|
+
initialItems: initialValues?.items,
|
|
218
|
+
currentItems: values.items,
|
|
219
|
+
initialCurrencyCode: initialValues?.currency_code,
|
|
220
|
+
currentCurrencyCode: values.currency_code,
|
|
221
|
+
initialCalculationMode: (initialValues as any)?.calculation_mode ?? null,
|
|
222
|
+
currentCalculationMode: values.calculation_mode ?? null,
|
|
223
|
+
initialPriceModes,
|
|
224
|
+
currentPriceModes: priceModesRef.current,
|
|
225
|
+
}),
|
|
226
|
+
[initialPriceModes, initialValues],
|
|
227
|
+
);
|
|
164
228
|
|
|
165
229
|
// Get default payment terms and footer from entity settings
|
|
166
230
|
const defaultPaymentTerms = (activeEntity?.settings as any)?.default_credit_note_payment_terms || "";
|
|
167
231
|
const defaultFooter = (activeEntity?.settings as any)?.document_footer || "";
|
|
232
|
+
const defaultSignature = (activeEntity?.settings as any)?.default_document_signature || "";
|
|
168
233
|
|
|
169
234
|
const form = useForm<CreateCreditNoteFormValues>({
|
|
170
235
|
// Cast resolver to accept extended form type (includes UI-only fields)
|
|
171
236
|
resolver: zodResolver(createCreditNoteFormSchema) as Resolver<CreateCreditNoteFormValues>,
|
|
172
237
|
defaultValues: {
|
|
173
|
-
number: "",
|
|
238
|
+
number: (initialValues as any)?.number ?? "",
|
|
239
|
+
calculation_mode: (initialValues as any)?.calculation_mode ?? undefined,
|
|
174
240
|
date: initialValues?.date || new Date().toISOString(),
|
|
175
241
|
customer_id: initialValues?.customer_id ?? undefined,
|
|
176
242
|
// Cast customer to form schema type (API type may have additional fields)
|
|
177
243
|
customer: (initialValues?.customer as CreateCreditNoteFormValues["customer"]) ?? undefined,
|
|
178
244
|
items: initialValues?.items?.length
|
|
179
245
|
? initialValues.items.map((item: any) => ({
|
|
180
|
-
type: item.type,
|
|
246
|
+
type: item.type ?? undefined,
|
|
181
247
|
name: item.name || "",
|
|
182
248
|
description: item.description || "",
|
|
183
249
|
...(item.type !== "separator"
|
|
184
250
|
? {
|
|
251
|
+
item_id: item.item_id ?? undefined,
|
|
185
252
|
quantity: item.quantity ?? 1,
|
|
186
|
-
// Use gross_price if set, otherwise use price
|
|
187
253
|
price: item.gross_price ?? item.price,
|
|
254
|
+
gross_price: item.gross_price ?? undefined,
|
|
255
|
+
unit: item.unit ?? undefined,
|
|
256
|
+
classification: item.classification ?? undefined,
|
|
188
257
|
taxes: item.taxes || [],
|
|
258
|
+
discounts: normalizeLineItemDiscountsForForm(item.discounts),
|
|
259
|
+
metadata: item.metadata ?? undefined,
|
|
189
260
|
}
|
|
190
261
|
: {}),
|
|
191
262
|
}))
|
|
@@ -198,13 +269,17 @@ export default function CreateCreditNoteForm({
|
|
|
198
269
|
taxes: [],
|
|
199
270
|
},
|
|
200
271
|
],
|
|
201
|
-
date_service:
|
|
272
|
+
date_service:
|
|
273
|
+
(initialValues as any)?.date_service ??
|
|
274
|
+
(isEditMode ? undefined : (initialValues?.date ?? new Date().toISOString())),
|
|
275
|
+
date_service_to: (initialValues as any)?.date_service_to ?? undefined,
|
|
202
276
|
currency_code: initialValues?.currency_code || activeEntity?.currency_code || "EUR",
|
|
203
277
|
reference: (initialValues as any)?.reference ?? "",
|
|
204
|
-
note: initialValues?.note ?? "",
|
|
278
|
+
note: initialValues?.note ?? (isEditMode ? "" : ""),
|
|
205
279
|
tax_clause: (initialValues as any)?.tax_clause ?? "",
|
|
206
|
-
payment_terms: initialValues?.payment_terms ?? defaultPaymentTerms,
|
|
207
|
-
footer: (initialValues as any)?.footer ?? defaultFooter,
|
|
280
|
+
payment_terms: initialValues?.payment_terms ?? (isEditMode ? "" : defaultPaymentTerms),
|
|
281
|
+
footer: (initialValues as any)?.footer ?? (isEditMode ? "" : defaultFooter),
|
|
282
|
+
signature: (initialValues as any)?.signature ?? (isEditMode ? "" : defaultSignature),
|
|
208
283
|
pt: ((initialValues as any)?.pt as PtDocumentInputForm | undefined) ?? undefined,
|
|
209
284
|
},
|
|
210
285
|
});
|
|
@@ -250,15 +325,19 @@ export default function CreateCreditNoteForm({
|
|
|
250
325
|
!!fina.isActive && (finaUnifiedNumbering || transactionType == null || transactionType === "domestic");
|
|
251
326
|
const isFinaNonDomestic = !!fina.isActive && !useFinaNumbering;
|
|
252
327
|
const isFursActive = furs.isActive && !skipFiscalization;
|
|
328
|
+
const isFiscalizationDateLocked = isFursActive || useFinaNumbering;
|
|
329
|
+
const fiscalizationDateLockReason = useFinaNumbering
|
|
330
|
+
? t("FINA fiscalized invoices always use the current date")
|
|
331
|
+
: t("FURS fiscalized invoices always use the current date");
|
|
253
332
|
|
|
254
333
|
useEffect(() => {
|
|
255
|
-
if (skipPreferenceInitializedRef.current || furs.isLoading) return;
|
|
334
|
+
if (skipPreferenceInitializedRef.current || furs.isLoading || isEditMode) return;
|
|
256
335
|
|
|
257
336
|
skipPreferenceInitializedRef.current = true;
|
|
258
337
|
if (furs.settings?.default_skip_fiscalization === true) {
|
|
259
338
|
setSkipFiscalization(true);
|
|
260
339
|
}
|
|
261
|
-
}, [furs.isLoading, furs.settings?.default_skip_fiscalization]);
|
|
340
|
+
}, [furs.isLoading, furs.settings?.default_skip_fiscalization, isEditMode]);
|
|
262
341
|
|
|
263
342
|
useEffect(() => {
|
|
264
343
|
const skipJustEnabled = skipFiscalization && !previousSkipFiscalizationRef.current;
|
|
@@ -312,15 +391,21 @@ export default function CreateCreditNoteForm({
|
|
|
312
391
|
const { data: nextNumberData, isLoading: isNextNumberLoading } = useNextDocumentNumber(entityId, "credit_note", {
|
|
313
392
|
businessPremiseName: activePremiseNameForNumber,
|
|
314
393
|
electronicDeviceName: activeDeviceNameForNumber,
|
|
315
|
-
enabled:
|
|
394
|
+
enabled:
|
|
395
|
+
!!entityId && !furs.isLoading && furs.isSelectionReady && !fina.isLoading && fina.isSelectionReady && !isEditMode,
|
|
316
396
|
});
|
|
317
397
|
|
|
318
398
|
// Overall loading state
|
|
319
|
-
const isFormDataLoading =
|
|
320
|
-
|
|
399
|
+
const isFormDataLoading = isEditMode
|
|
400
|
+
? false
|
|
401
|
+
: furs.isLoading || !furs.isSelectionReady || fina.isLoading || !fina.isSelectionReady || isNextNumberLoading;
|
|
321
402
|
|
|
322
403
|
useEffect(() => {
|
|
323
404
|
if (!onHeaderActionChange) return;
|
|
405
|
+
if (isEditMode) {
|
|
406
|
+
onHeaderActionChange(null);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
324
409
|
|
|
325
410
|
if (furs.isLoading || fina.isLoading) {
|
|
326
411
|
onHeaderActionChange(null);
|
|
@@ -365,7 +450,16 @@ export default function CreateCreditNoteForm({
|
|
|
365
450
|
</Tooltip>
|
|
366
451
|
</TooltipProvider>,
|
|
367
452
|
);
|
|
368
|
-
}, [
|
|
453
|
+
}, [
|
|
454
|
+
fina.isLoading,
|
|
455
|
+
furs.hasPremises,
|
|
456
|
+
furs.isEnabled,
|
|
457
|
+
furs.isLoading,
|
|
458
|
+
isEditMode,
|
|
459
|
+
onHeaderActionChange,
|
|
460
|
+
skipFiscalization,
|
|
461
|
+
t,
|
|
462
|
+
]);
|
|
369
463
|
|
|
370
464
|
// Auto-populate tax_clause from entity settings when transaction type changes
|
|
371
465
|
const effectiveTransactionType = transactionType ?? "domestic";
|
|
@@ -373,13 +467,14 @@ export default function CreateCreditNoteForm({
|
|
|
373
467
|
useEffect(() => {
|
|
374
468
|
if (effectiveTransactionType === prevTransactionTypeRef.current) return;
|
|
375
469
|
prevTransactionTypeRef.current = effectiveTransactionType;
|
|
470
|
+
if (isEditMode) return;
|
|
376
471
|
|
|
377
472
|
const taxClauseDefaults = (activeEntity?.settings as any)?.tax_clause_defaults;
|
|
378
473
|
if (!taxClauseDefaults) return;
|
|
379
474
|
|
|
380
475
|
const clause = taxClauseDefaults[effectiveTransactionType] ?? "";
|
|
381
476
|
form.setValue("tax_clause", clause);
|
|
382
|
-
}, [effectiveTransactionType, activeEntity, form]);
|
|
477
|
+
}, [effectiveTransactionType, activeEntity, form, isEditMode]);
|
|
383
478
|
|
|
384
479
|
// Clear date_service_to when switching from range to single
|
|
385
480
|
useEffect(() => {
|
|
@@ -401,10 +496,25 @@ export default function CreateCreditNoteForm({
|
|
|
401
496
|
|
|
402
497
|
// Pre-fill credit note number from preview
|
|
403
498
|
useEffect(() => {
|
|
499
|
+
if (isEditMode) return;
|
|
404
500
|
if (nextNumberData?.number) {
|
|
405
501
|
form.setValue("number", nextNumberData.number);
|
|
406
502
|
}
|
|
407
|
-
}, [nextNumberData?.number, form]);
|
|
503
|
+
}, [nextNumberData?.number, form, isEditMode]);
|
|
504
|
+
|
|
505
|
+
useEffect(() => {
|
|
506
|
+
if (isEditMode) return;
|
|
507
|
+
if (!isFiscalizationDateLocked) return;
|
|
508
|
+
|
|
509
|
+
const today = new Date();
|
|
510
|
+
if (isSameCalendarDate(form.getValues("date"), today)) return;
|
|
511
|
+
|
|
512
|
+
form.setValue("date", today.toISOString(), {
|
|
513
|
+
shouldDirty: true,
|
|
514
|
+
shouldTouch: false,
|
|
515
|
+
shouldValidate: true,
|
|
516
|
+
});
|
|
517
|
+
}, [form, isEditMode, isFiscalizationDateLocked]);
|
|
408
518
|
|
|
409
519
|
const { mutate: createCreditNote, isPending } = useCreateCreditNote({
|
|
410
520
|
entityId,
|
|
@@ -420,10 +530,42 @@ export default function CreateCreditNoteForm({
|
|
|
420
530
|
},
|
|
421
531
|
onError,
|
|
422
532
|
});
|
|
533
|
+
const { mutate: createCustomCreditNote, isPending: isCreateCustomPending } = useCreateCustomCreditNote({
|
|
534
|
+
entityId,
|
|
535
|
+
onSuccess: (data) => {
|
|
536
|
+
furs.saveCombo();
|
|
537
|
+
fina.saveCombo();
|
|
538
|
+
if (data.customer_id) {
|
|
539
|
+
queryClient.invalidateQueries({ queryKey: [CUSTOMERS_CACHE_KEY] });
|
|
540
|
+
}
|
|
541
|
+
onSuccess?.(data);
|
|
542
|
+
},
|
|
543
|
+
onError,
|
|
544
|
+
});
|
|
545
|
+
const { mutate: updateCreditNote, isPending: isUpdatePending } = useUpdateCreditNote({
|
|
546
|
+
entityId,
|
|
547
|
+
onSuccess,
|
|
548
|
+
onError,
|
|
549
|
+
});
|
|
423
550
|
|
|
424
551
|
// Shared submit logic for both regular save and save as draft
|
|
425
552
|
const submitCreditNote = useCallback(
|
|
426
553
|
(values: CreateCreditNoteFormValues, isDraft: boolean) => {
|
|
554
|
+
if (isEditMode) {
|
|
555
|
+
if (!documentId) {
|
|
556
|
+
throw new Error("Credit note edit mode requires a documentId");
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const updatePayload = prepareCreditNoteUpdateSubmission(values as any, {
|
|
560
|
+
originalCustomer,
|
|
561
|
+
wasCustomerFormShown: showCustomerForm,
|
|
562
|
+
priceModes: priceModesRef.current,
|
|
563
|
+
}) as UpdateCreditNote;
|
|
564
|
+
|
|
565
|
+
updateCreditNote({ id: documentId, data: updatePayload });
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
|
|
427
569
|
// Build FURS options (skip for drafts; user can also skip fiscalization explicitly)
|
|
428
570
|
const fursOptions = buildFursOptions({
|
|
429
571
|
isDraft,
|
|
@@ -463,6 +605,12 @@ export default function CreateCreditNoteForm({
|
|
|
463
605
|
priceModes: priceModesRef.current,
|
|
464
606
|
isDraft,
|
|
465
607
|
});
|
|
608
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(values);
|
|
609
|
+
if (preservedExpectedTotalWithTax !== undefined) {
|
|
610
|
+
(payload as any).expected_total_with_tax = preservedExpectedTotalWithTax;
|
|
611
|
+
} else {
|
|
612
|
+
delete (payload as any).expected_total_with_tax;
|
|
613
|
+
}
|
|
466
614
|
|
|
467
615
|
// Add FURS data to payload
|
|
468
616
|
if (fursOptions) {
|
|
@@ -474,12 +622,20 @@ export default function CreateCreditNoteForm({
|
|
|
474
622
|
(payload as any).fina = finaOptions;
|
|
475
623
|
}
|
|
476
624
|
|
|
477
|
-
|
|
625
|
+
if (customCreateTemplate && financialInputsMatchSource(values)) {
|
|
626
|
+
delete (payload as any).expected_total_with_tax;
|
|
627
|
+
createCustomCreditNote(applyCustomCreateTemplate(payload as any, customCreateTemplate));
|
|
628
|
+
} else {
|
|
629
|
+
createCreditNote(payload as CreateCreditNoteRequest);
|
|
630
|
+
}
|
|
478
631
|
},
|
|
479
632
|
[
|
|
480
633
|
createCreditNote,
|
|
634
|
+
createCustomCreditNote,
|
|
635
|
+
documentId,
|
|
481
636
|
fina,
|
|
482
637
|
furs,
|
|
638
|
+
isEditMode,
|
|
483
639
|
markAsPaid,
|
|
484
640
|
originalCustomer,
|
|
485
641
|
paymentDocumentTotal,
|
|
@@ -487,6 +643,10 @@ export default function CreateCreditNoteForm({
|
|
|
487
643
|
showCustomerForm,
|
|
488
644
|
skipFiscalization,
|
|
489
645
|
operatorPrefill,
|
|
646
|
+
customCreateTemplate,
|
|
647
|
+
financialInputsMatchSource,
|
|
648
|
+
getPreservedExpectedTotalWithTax,
|
|
649
|
+
updateCreditNote,
|
|
490
650
|
useFinaNumbering,
|
|
491
651
|
],
|
|
492
652
|
);
|
|
@@ -507,20 +667,22 @@ export default function CreateCreditNoteForm({
|
|
|
507
667
|
|
|
508
668
|
useFormFooterRegistration({
|
|
509
669
|
formId: "create-credit-note-form",
|
|
510
|
-
isPending,
|
|
670
|
+
isPending: isPending || isCreateCustomPending || isUpdatePending,
|
|
511
671
|
isDirty: form.formState.isDirty || !!initialValues,
|
|
512
|
-
label: t("Save"),
|
|
513
|
-
secondaryAction:
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
672
|
+
label: isEditMode ? t("Update") : t("Save"),
|
|
673
|
+
secondaryAction:
|
|
674
|
+
allowDrafts && !isEditMode
|
|
675
|
+
? {
|
|
676
|
+
label: t("Save as Draft"),
|
|
677
|
+
onClick: handleSaveAsDraft,
|
|
678
|
+
isPending: isDraftPending,
|
|
679
|
+
}
|
|
680
|
+
: undefined,
|
|
520
681
|
});
|
|
521
682
|
|
|
522
683
|
// Set default note and payment terms from entity settings when entity data is available
|
|
523
684
|
useEffect(() => {
|
|
685
|
+
if (isEditMode) return;
|
|
524
686
|
const entityDefaultNote = (activeEntity?.settings as any)?.default_credit_note_note;
|
|
525
687
|
if (entityDefaultNote && !form.getValues("note")) {
|
|
526
688
|
form.setValue("note", entityDefaultNote);
|
|
@@ -537,7 +699,7 @@ export default function CreateCreditNoteForm({
|
|
|
537
699
|
if (entityDefaultSignature && !form.getValues("signature")) {
|
|
538
700
|
form.setValue("signature", entityDefaultSignature);
|
|
539
701
|
}
|
|
540
|
-
}, [activeEntity, form]);
|
|
702
|
+
}, [activeEntity, form, isEditMode]);
|
|
541
703
|
|
|
542
704
|
// Auto-add tax field for tax subject entities
|
|
543
705
|
useEffect(() => {
|
|
@@ -549,31 +711,32 @@ export default function CreateCreditNoteForm({
|
|
|
549
711
|
}
|
|
550
712
|
}, [activeEntity?.is_tax_subject, form]);
|
|
551
713
|
|
|
552
|
-
const buildPreviewPayload = useCallback(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
714
|
+
const buildPreviewPayload = useCallback(
|
|
715
|
+
(values: CreateCreditNoteFormValues): CreditNotePreviewPayload => {
|
|
716
|
+
const preservedExpectedTotalWithTax = getPreservedExpectedTotalWithTax(values);
|
|
717
|
+
return {
|
|
718
|
+
number: values.number,
|
|
719
|
+
date: values.date,
|
|
720
|
+
date_service: (values as any).date_service,
|
|
721
|
+
date_service_to: (values as any).date_service_to,
|
|
722
|
+
customer_id: values.customer_id,
|
|
723
|
+
customer: values.customer,
|
|
724
|
+
items: prepareDocumentItems(values.items, priceModesRef.current),
|
|
725
|
+
currency_code: values.currency_code,
|
|
726
|
+
reference: values.reference,
|
|
727
|
+
note: values.note,
|
|
728
|
+
tax_clause: values.tax_clause,
|
|
729
|
+
payment_terms: values.payment_terms,
|
|
730
|
+
signature: values.signature,
|
|
731
|
+
footer: values.footer,
|
|
732
|
+
...(preservedExpectedTotalWithTax !== undefined
|
|
733
|
+
? { expected_total_with_tax: preservedExpectedTotalWithTax }
|
|
734
|
+
: {}),
|
|
735
|
+
...(normalizePtDocumentInput(values.pt) ? { pt: normalizePtDocumentInput(values.pt) } : {}),
|
|
736
|
+
};
|
|
737
|
+
},
|
|
738
|
+
[getPreservedExpectedTotalWithTax],
|
|
739
|
+
);
|
|
577
740
|
|
|
578
741
|
const emitPreviewPayload = useCallback((payload: CreditNotePreviewPayload) => {
|
|
579
742
|
const callback = onChangeRef.current;
|
|
@@ -670,7 +833,7 @@ export default function CreateCreditNoteForm({
|
|
|
670
833
|
t={t}
|
|
671
834
|
locale={locale}
|
|
672
835
|
fursInline={
|
|
673
|
-
furs.isEnabled && furs.hasPremises
|
|
836
|
+
!isEditMode && furs.isEnabled && furs.hasPremises
|
|
674
837
|
? {
|
|
675
838
|
premises: furs.activePremises.map((p) => ({
|
|
676
839
|
id: p.id,
|
|
@@ -693,7 +856,7 @@ export default function CreateCreditNoteForm({
|
|
|
693
856
|
onDateTypeChange: setServiceDateType,
|
|
694
857
|
}}
|
|
695
858
|
finaInline={
|
|
696
|
-
useFinaNumbering
|
|
859
|
+
!isEditMode && useFinaNumbering
|
|
697
860
|
? {
|
|
698
861
|
premises: fina.activePremises.map((p: any) => ({
|
|
699
862
|
id: p.id,
|
|
@@ -710,24 +873,30 @@ export default function CreateCreditNoteForm({
|
|
|
710
873
|
}
|
|
711
874
|
: undefined
|
|
712
875
|
}
|
|
876
|
+
dateLock={{
|
|
877
|
+
isLocked: !isEditMode && isFiscalizationDateLocked,
|
|
878
|
+
reason: !isEditMode ? fiscalizationDateLockReason : "",
|
|
879
|
+
}}
|
|
713
880
|
>
|
|
714
881
|
{/* Credit note specific: Mark as paid section (UI-only state, not in form schema) */}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
882
|
+
{!isEditMode && (
|
|
883
|
+
<MarkAsPaidSection
|
|
884
|
+
checked={markAsPaid}
|
|
885
|
+
onCheckedChange={(checked) => {
|
|
886
|
+
setMarkAsPaid(checked);
|
|
887
|
+
setPaymentValidationMessage(undefined);
|
|
888
|
+
}}
|
|
889
|
+
paymentRows={paymentRows}
|
|
890
|
+
onPaymentRowsChange={(rows) => {
|
|
891
|
+
setPaymentRows(rows);
|
|
892
|
+
setPaymentValidationMessage(undefined);
|
|
893
|
+
}}
|
|
894
|
+
documentTotal={paymentDocumentTotal}
|
|
895
|
+
t={t}
|
|
896
|
+
alwaysShowPaymentType={!!fina.isActive}
|
|
897
|
+
validationMessage={paymentValidationMessage}
|
|
898
|
+
/>
|
|
899
|
+
)}
|
|
731
900
|
{detailsExtras}
|
|
732
901
|
</DocumentDetailsSection>
|
|
733
902
|
</div>
|
|
@@ -10,6 +10,7 @@ export default {
|
|
|
10
10
|
Items: "Артикули",
|
|
11
11
|
"Add item": "Add item",
|
|
12
12
|
Save: "Запази",
|
|
13
|
+
Update: "Актуализирай",
|
|
13
14
|
"Save as Draft": "Save as Draft",
|
|
14
15
|
Quantity: "Quantity",
|
|
15
16
|
Price: "Цена",
|
|
@@ -23,16 +24,16 @@ export default {
|
|
|
23
24
|
"No taxes found": "No taxes found",
|
|
24
25
|
"Add new tax...": "Add new tax...",
|
|
25
26
|
Description: "Описание",
|
|
26
|
-
"Mark as Paid": "
|
|
27
|
-
Paid: "Платено",
|
|
28
|
-
"Credit note will be marked as fully paid upon creation": "
|
|
29
|
-
"Payment Type": "
|
|
27
|
+
"Mark as Paid": "Маркирай като платено",
|
|
28
|
+
"Paid": "Платено",
|
|
29
|
+
"Credit note will be marked as fully paid upon creation": "Кредитното известие ще бъде маркирано като напълно платено при създаване",
|
|
30
|
+
"Payment Type": "Вид плащане",
|
|
30
31
|
"Select payment type": "Изберете тип плащане",
|
|
31
|
-
Cash: "В брой",
|
|
32
|
+
"Cash": "В брой",
|
|
32
33
|
"Bank Transfer": "Банков превод",
|
|
33
|
-
Card: "Карта",
|
|
34
|
-
Check: "Чек",
|
|
35
|
-
Other: "Друго",
|
|
34
|
+
"Card": "Карта",
|
|
35
|
+
"Check": "Чек",
|
|
36
|
+
"Other": "Друго",
|
|
36
37
|
Note: "Note",
|
|
37
38
|
"Insert variable": "Insert variable",
|
|
38
39
|
"Add payment instructions, terms, or other notes...": "Add payment instructions, terms, or other notes...",
|
|
@@ -84,4 +85,17 @@ export default {
|
|
|
84
85
|
Footer: "Footer",
|
|
85
86
|
"Add document footer...": "Add document footer...",
|
|
86
87
|
"Reverse charge - tax exempt EU B2B sale": "Reverse charge - tax exempt EU B2B sale",
|
|
88
|
+
"Please select": "Моля, изберете",
|
|
89
|
+
"Amount": "Сума",
|
|
90
|
+
"Add payment": "Добави плащане",
|
|
91
|
+
"Recorded now": "Регистрирано сега",
|
|
92
|
+
"Remaining due": "Остава за плащане",
|
|
93
|
+
"Remaining to allocate": "Остава за разпределяне",
|
|
94
|
+
"This document must be fully paid on creation": "Този документ трябва да бъде напълно платен при създаване",
|
|
95
|
+
"Record one or more payments on creation": "Регистрирайте едно или повече плащания при създаване",
|
|
96
|
+
// Service date
|
|
97
|
+
"Service Date": "Дата на услугата",
|
|
98
|
+
"Service Period": "Период на услугата",
|
|
99
|
+
From: "От",
|
|
100
|
+
To: "До",
|
|
87
101
|
} as const;
|