@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
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { Entity, Estimate, Invoice, TransactionTypeCheckResponse } from "@spaceinvoices/js-sdk";
|
|
6
6
|
import { CalendarIcon, ChevronDown, Globe, Info, Loader2 } from "lucide-react";
|
|
7
7
|
import { useRef, useState } from "react";
|
|
8
|
+
import { useWatch } from "react-hook-form";
|
|
8
9
|
import { Badge } from "@/ui/components/ui/badge";
|
|
9
10
|
import { Button } from "@/ui/components/ui/button";
|
|
10
11
|
import { Calendar } from "@/ui/components/ui/calendar";
|
|
@@ -15,10 +16,11 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/ui/components/ui/popo
|
|
|
15
16
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/ui/components/ui/select";
|
|
16
17
|
import { Textarea } from "@/ui/components/ui/textarea";
|
|
17
18
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/ui/components/ui/tooltip";
|
|
19
|
+
import { normalizeDateOnlyInput, toLocalDateOnlyString } from "@/ui/lib/date-only";
|
|
18
20
|
import { CURRENCY_CODES } from "@/ui/lib/constants";
|
|
19
21
|
import { replaceTemplateVariablesForPreview } from "@/ui/lib/template-variables";
|
|
20
22
|
import { cn } from "@/ui/lib/utils";
|
|
21
|
-
import type
|
|
23
|
+
import { getDocumentConfig, type DocumentTypes } from "../types";
|
|
22
24
|
import type { AnyControl } from "./form-types";
|
|
23
25
|
import { SmartCodeInsertButton } from "./smart-code-insert-button";
|
|
24
26
|
|
|
@@ -73,7 +75,21 @@ type DueDaysProps = {
|
|
|
73
75
|
onDueDaysTypeChange: (type: number | "custom") => void;
|
|
74
76
|
};
|
|
75
77
|
|
|
78
|
+
type DateLockProps = {
|
|
79
|
+
isLocked: boolean;
|
|
80
|
+
reason: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
76
83
|
const LABEL_WIDTH = "w-[6.5rem] shrink-0";
|
|
84
|
+
const MIN_DOCUMENT_DATE = new Date("1900-01-01");
|
|
85
|
+
|
|
86
|
+
function isAfterDateOnly(date: Date, maxDateOnly: string | undefined): boolean {
|
|
87
|
+
return !!maxDateOnly && toLocalDateOnlyString(date) > maxDateOnly;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isBeforeDateOnly(date: Date, minDateOnly: string | undefined): boolean {
|
|
91
|
+
return !!minDateOnly && toLocalDateOnlyString(date) < minDateOnly;
|
|
92
|
+
}
|
|
77
93
|
|
|
78
94
|
function extractSequenceNumber(fullNumber: string, premise?: string, device?: string): string {
|
|
79
95
|
if (!fullNumber || (!premise && !device)) return fullNumber;
|
|
@@ -92,6 +108,7 @@ type DocumentDetailsSectionProps = {
|
|
|
92
108
|
finaInline?: FinaInlineProps; // FINA premise/device inline with number
|
|
93
109
|
serviceDate?: ServiceDateProps; // Service date section (invoice only)
|
|
94
110
|
dueDays?: DueDaysProps; // Due days selector (invoice only)
|
|
111
|
+
dateLock?: DateLockProps;
|
|
95
112
|
};
|
|
96
113
|
|
|
97
114
|
export function DocumentDetailsSection({
|
|
@@ -104,12 +121,18 @@ export function DocumentDetailsSection({
|
|
|
104
121
|
finaInline,
|
|
105
122
|
serviceDate,
|
|
106
123
|
dueDays,
|
|
124
|
+
dateLock,
|
|
107
125
|
}: DocumentDetailsSectionProps) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
126
|
+
const documentConfig = getDocumentConfig(documentType);
|
|
127
|
+
const hasSecondaryDate = documentConfig.dateFieldName !== null;
|
|
128
|
+
const dateFieldName = documentConfig.dateFieldName;
|
|
129
|
+
const dateFieldLabel = documentConfig.dateFieldLabel ? t(documentConfig.dateFieldLabel) : "";
|
|
130
|
+
const watchedIssueDate = useWatch({ control, name: "date" });
|
|
131
|
+
const watchedServiceStartDate = useWatch({ control, name: "date_service" });
|
|
132
|
+
const issueDateOnly = normalizeDateOnlyInput(typeof watchedIssueDate === "string" ? watchedIssueDate : undefined);
|
|
133
|
+
const serviceStartDateOnly = normalizeDateOnlyInput(
|
|
134
|
+
typeof watchedServiceStartDate === "string" ? watchedServiceStartDate : undefined,
|
|
135
|
+
);
|
|
113
136
|
|
|
114
137
|
// Check if FURS/FINA inline should show premise/device selects
|
|
115
138
|
const showFursSelects = fursInline && !fursInline.isSkipped;
|
|
@@ -259,18 +282,18 @@ export function DocumentDetailsSection({
|
|
|
259
282
|
<FormItem>
|
|
260
283
|
<div className="flex items-center gap-3">
|
|
261
284
|
<FormLabel className={LABEL_WIDTH}>{t("Date")} *</FormLabel>
|
|
262
|
-
{
|
|
285
|
+
{dateLock?.isLocked ? (
|
|
263
286
|
<Tooltip>
|
|
264
287
|
<TooltipTrigger asChild>
|
|
265
288
|
<FormControl>
|
|
266
289
|
<Button variant="outline" disabled className="flex-1 pl-3 text-left font-normal">
|
|
267
|
-
{new Date().toLocaleDateString(locale)}
|
|
290
|
+
{new Date(field.value || new Date()).toLocaleDateString(locale)}
|
|
268
291
|
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
|
269
292
|
</Button>
|
|
270
293
|
</FormControl>
|
|
271
294
|
</TooltipTrigger>
|
|
272
295
|
<TooltipContent>
|
|
273
|
-
<p>{
|
|
296
|
+
<p>{dateLock.reason}</p>
|
|
274
297
|
</TooltipContent>
|
|
275
298
|
</Tooltip>
|
|
276
299
|
) : (
|
|
@@ -278,6 +301,7 @@ export function DocumentDetailsSection({
|
|
|
278
301
|
<PopoverTrigger asChild>
|
|
279
302
|
<FormControl>
|
|
280
303
|
<Button
|
|
304
|
+
type="button"
|
|
281
305
|
variant="outline"
|
|
282
306
|
className={cn("flex-1 pl-3 text-left font-normal", !field.value && "text-muted-foreground")}
|
|
283
307
|
>
|
|
@@ -291,14 +315,14 @@ export function DocumentDetailsSection({
|
|
|
291
315
|
</FormControl>
|
|
292
316
|
</PopoverTrigger>
|
|
293
317
|
<PopoverContent className="w-auto p-0" align="start">
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
318
|
+
<Calendar
|
|
319
|
+
mode="single"
|
|
320
|
+
selected={field.value ? new Date(field.value) : undefined}
|
|
321
|
+
onSelect={(date) => field.onChange(date?.toISOString())}
|
|
322
|
+
disabled={(date) => date > new Date() || date < MIN_DOCUMENT_DATE}
|
|
323
|
+
initialFocus
|
|
324
|
+
/>
|
|
325
|
+
</PopoverContent>
|
|
302
326
|
</Popover>
|
|
303
327
|
)}
|
|
304
328
|
</div>
|
|
@@ -325,11 +349,11 @@ export function DocumentDetailsSection({
|
|
|
325
349
|
"h-auto border-none p-0 font-medium text-sm shadow-none [&>svg]:ml-1 [&>svg]:size-3.5",
|
|
326
350
|
)}
|
|
327
351
|
>
|
|
328
|
-
<SelectValue>{serviceDate.dateType === "single" ? t("
|
|
352
|
+
<SelectValue>{serviceDate.dateType === "single" ? t("Service Date") : t("Service Period")}</SelectValue>
|
|
329
353
|
</SelectTrigger>
|
|
330
354
|
<SelectContent>
|
|
331
|
-
<SelectItem value="single">{t("
|
|
332
|
-
<SelectItem value="range">{t("
|
|
355
|
+
<SelectItem value="single">{t("Service Date")}</SelectItem>
|
|
356
|
+
<SelectItem value="range">{t("Service Period")}</SelectItem>
|
|
333
357
|
</SelectContent>
|
|
334
358
|
</Select>
|
|
335
359
|
{serviceDate.dateType === "single" ? (
|
|
@@ -337,6 +361,7 @@ export function DocumentDetailsSection({
|
|
|
337
361
|
<PopoverTrigger asChild>
|
|
338
362
|
<FormControl>
|
|
339
363
|
<Button
|
|
364
|
+
type="button"
|
|
340
365
|
variant="outline"
|
|
341
366
|
className={cn("flex-1 pl-3 text-left font-normal", !field.value && "text-muted-foreground")}
|
|
342
367
|
>
|
|
@@ -354,6 +379,9 @@ export function DocumentDetailsSection({
|
|
|
354
379
|
mode="single"
|
|
355
380
|
selected={field.value ? new Date(field.value) : undefined}
|
|
356
381
|
onSelect={(date) => field.onChange(date?.toISOString())}
|
|
382
|
+
disabled={(date) =>
|
|
383
|
+
date > new Date() || date < MIN_DOCUMENT_DATE || isAfterDateOnly(date, issueDateOnly)
|
|
384
|
+
}
|
|
357
385
|
initialFocus
|
|
358
386
|
/>
|
|
359
387
|
</PopoverContent>
|
|
@@ -364,6 +392,7 @@ export function DocumentDetailsSection({
|
|
|
364
392
|
<PopoverTrigger asChild>
|
|
365
393
|
<FormControl>
|
|
366
394
|
<Button
|
|
395
|
+
type="button"
|
|
367
396
|
variant="outline"
|
|
368
397
|
className={cn("w-full pl-3 text-left font-normal", !field.value && "text-muted-foreground")}
|
|
369
398
|
>
|
|
@@ -377,6 +406,9 @@ export function DocumentDetailsSection({
|
|
|
377
406
|
mode="single"
|
|
378
407
|
selected={field.value ? new Date(field.value) : undefined}
|
|
379
408
|
onSelect={(date) => field.onChange(date?.toISOString())}
|
|
409
|
+
disabled={(date) =>
|
|
410
|
+
date > new Date() || date < MIN_DOCUMENT_DATE || isAfterDateOnly(date, issueDateOnly)
|
|
411
|
+
}
|
|
380
412
|
initialFocus
|
|
381
413
|
/>
|
|
382
414
|
</PopoverContent>
|
|
@@ -386,32 +418,44 @@ export function DocumentDetailsSection({
|
|
|
386
418
|
control={control}
|
|
387
419
|
name="date_service_to"
|
|
388
420
|
render={({ field: toField }) => (
|
|
389
|
-
<
|
|
390
|
-
<
|
|
391
|
-
<
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
421
|
+
<FormItem>
|
|
422
|
+
<Popover>
|
|
423
|
+
<PopoverTrigger asChild>
|
|
424
|
+
<FormControl>
|
|
425
|
+
<Button
|
|
426
|
+
type="button"
|
|
427
|
+
variant="outline"
|
|
428
|
+
className={cn(
|
|
429
|
+
"w-full pl-3 text-left font-normal",
|
|
430
|
+
!toField.value && "text-muted-foreground",
|
|
431
|
+
)}
|
|
432
|
+
>
|
|
433
|
+
{toField.value ? (
|
|
434
|
+
new Date(toField.value).toLocaleDateString(locale)
|
|
435
|
+
) : (
|
|
436
|
+
<span>{t("To")}</span>
|
|
437
|
+
)}
|
|
438
|
+
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
|
|
439
|
+
</Button>
|
|
440
|
+
</FormControl>
|
|
441
|
+
</PopoverTrigger>
|
|
442
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
443
|
+
<Calendar
|
|
444
|
+
mode="single"
|
|
445
|
+
selected={toField.value ? new Date(toField.value) : undefined}
|
|
446
|
+
onSelect={(date) => toField.onChange(date?.toISOString())}
|
|
447
|
+
disabled={(date) =>
|
|
448
|
+
date > new Date() ||
|
|
449
|
+
date < MIN_DOCUMENT_DATE ||
|
|
450
|
+
isAfterDateOnly(date, issueDateOnly) ||
|
|
451
|
+
isBeforeDateOnly(date, serviceStartDateOnly)
|
|
452
|
+
}
|
|
453
|
+
initialFocus
|
|
454
|
+
/>
|
|
455
|
+
</PopoverContent>
|
|
456
|
+
</Popover>
|
|
457
|
+
<FormMessage />
|
|
458
|
+
</FormItem>
|
|
415
459
|
)}
|
|
416
460
|
/>
|
|
417
461
|
</div>
|
|
@@ -426,7 +470,7 @@ export function DocumentDetailsSection({
|
|
|
426
470
|
{hasSecondaryDate && (
|
|
427
471
|
<FormField
|
|
428
472
|
control={control}
|
|
429
|
-
name={dateFieldName}
|
|
473
|
+
name={dateFieldName!}
|
|
430
474
|
render={({ field }) => (
|
|
431
475
|
<FormItem>
|
|
432
476
|
<div className="flex items-center gap-3">
|
|
@@ -459,6 +503,7 @@ export function DocumentDetailsSection({
|
|
|
459
503
|
<PopoverTrigger asChild>
|
|
460
504
|
<FormControl>
|
|
461
505
|
<Button
|
|
506
|
+
type="button"
|
|
462
507
|
variant="outline"
|
|
463
508
|
className={cn("flex-1 pl-3 text-left font-normal", !field.value && "text-muted-foreground")}
|
|
464
509
|
>
|
|
@@ -481,7 +526,7 @@ export function DocumentDetailsSection({
|
|
|
481
526
|
dueDays.onDueDaysTypeChange("custom");
|
|
482
527
|
}
|
|
483
528
|
}}
|
|
484
|
-
disabled={(date) => date <
|
|
529
|
+
disabled={(date) => date < MIN_DOCUMENT_DATE || isBeforeDateOnly(date, issueDateOnly)}
|
|
485
530
|
initialFocus
|
|
486
531
|
/>
|
|
487
532
|
</PopoverContent>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
type SourceDocumentTax = {
|
|
2
|
+
tax_id?: string | null;
|
|
3
|
+
rate?: number | null;
|
|
4
|
+
classification?: string | null;
|
|
5
|
+
reverse_charge?: boolean | null;
|
|
6
|
+
pt_exemption_code?: string | null;
|
|
7
|
+
pt_exemption_reason?: string | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type SourceDocumentDiscount = {
|
|
11
|
+
value: number;
|
|
12
|
+
type?: string | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type SourceDocumentItem = {
|
|
16
|
+
type?: string | null;
|
|
17
|
+
item_id?: string | null;
|
|
18
|
+
name?: string | null;
|
|
19
|
+
description?: string | null;
|
|
20
|
+
quantity?: number | null;
|
|
21
|
+
price?: number | null;
|
|
22
|
+
gross_price?: number | null;
|
|
23
|
+
unit?: string | null;
|
|
24
|
+
classification?: string | null;
|
|
25
|
+
taxes?: SourceDocumentTax[] | null;
|
|
26
|
+
discounts?: SourceDocumentDiscount[] | null;
|
|
27
|
+
metadata?: Record<string, unknown> | null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function toDocumentFormTaxes(taxes: SourceDocumentTax[] | null | undefined) {
|
|
31
|
+
return (taxes ?? []).map((tax) => ({
|
|
32
|
+
tax_id: tax?.tax_id ?? undefined,
|
|
33
|
+
rate: tax?.rate ?? undefined,
|
|
34
|
+
classification: tax?.classification ?? undefined,
|
|
35
|
+
reverse_charge: tax?.reverse_charge ?? undefined,
|
|
36
|
+
pt_exemption_code: tax?.pt_exemption_code ?? undefined,
|
|
37
|
+
pt_exemption_reason: tax?.pt_exemption_reason ?? undefined,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function toDocumentFormDiscounts(discounts: SourceDocumentDiscount[] | null | undefined) {
|
|
42
|
+
return (discounts ?? []).map((discount) => ({
|
|
43
|
+
value: discount.value,
|
|
44
|
+
type: discount.type ?? undefined,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function toDocumentFormItem(item: SourceDocumentItem) {
|
|
49
|
+
return {
|
|
50
|
+
type: item.type ?? undefined,
|
|
51
|
+
name: item.name ?? "",
|
|
52
|
+
description: item.description ?? undefined,
|
|
53
|
+
...(item.type !== "separator"
|
|
54
|
+
? {
|
|
55
|
+
item_id: item.item_id ?? undefined,
|
|
56
|
+
quantity: item.quantity ?? 1,
|
|
57
|
+
price: item.gross_price ?? item.price ?? undefined,
|
|
58
|
+
gross_price: item.gross_price ?? undefined,
|
|
59
|
+
unit: item.unit ?? undefined,
|
|
60
|
+
classification: item.classification ?? undefined,
|
|
61
|
+
taxes: toDocumentFormTaxes(item.taxes),
|
|
62
|
+
discounts: toDocumentFormDiscounts(item.discounts),
|
|
63
|
+
metadata: item.metadata ?? undefined,
|
|
64
|
+
}
|
|
65
|
+
: {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -13,10 +13,14 @@ export function withRequiredDocumentItemFields<T extends z.ZodTypeAny>(schema: T
|
|
|
13
13
|
if (item?.type === "separator") return;
|
|
14
14
|
|
|
15
15
|
const name = typeof item?.name === "string" ? item.name.trim() : "";
|
|
16
|
+
const itemId = typeof item?.item_id === "string" ? item.item_id.trim() : "";
|
|
16
17
|
const quantity = item?.quantity;
|
|
17
18
|
const price = item?.price;
|
|
19
|
+
const grossPrice = item?.gross_price;
|
|
20
|
+
const hasPrice = !(price == null || Number.isNaN(price as number));
|
|
21
|
+
const hasGrossPrice = !(grossPrice == null || Number.isNaN(grossPrice as number));
|
|
18
22
|
|
|
19
|
-
if (!name) {
|
|
23
|
+
if (!name && !itemId) {
|
|
20
24
|
ctx.addIssue({
|
|
21
25
|
code: z.ZodIssueCode.custom,
|
|
22
26
|
path: ["items", index, "name"],
|
|
@@ -32,7 +36,7 @@ export function withRequiredDocumentItemFields<T extends z.ZodTypeAny>(schema: T
|
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
if (
|
|
39
|
+
if (!hasPrice && !hasGrossPrice) {
|
|
36
40
|
ctx.addIssue({
|
|
37
41
|
code: z.ZodIssueCode.custom,
|
|
38
42
|
path: ["items", index, "price"],
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* This file provides type utilities to handle react-hook-form's complex generic types
|
|
5
5
|
* when passing control and other form utilities between components.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { UseFormGetValues, UseFormSetValue, UseFormWatch } from "react-hook-form";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A more permissive Control type that accepts any form control.
|
|
11
11
|
* Use this in component props when the component doesn't need to know
|
|
12
12
|
* the exact form type, only that it has certain fields.
|
|
13
13
|
*/
|
|
14
|
-
export type AnyControl =
|
|
14
|
+
export type AnyControl = any;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Base props for document form sections that receive form utilities.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/ui/components/ui/table";
|
|
2
|
+
import { formatDateOnlyForDisplay } from "@/ui/lib/date-only";
|
|
2
3
|
|
|
3
4
|
export type LinkedDocumentSummary = {
|
|
4
5
|
id: string;
|
|
@@ -21,17 +22,7 @@ export function LinkedDocumentsInfo({ documents, locale, t }: LinkedDocumentsInf
|
|
|
21
22
|
|
|
22
23
|
const currencyCode = validDocuments[0].currency_code || "EUR";
|
|
23
24
|
|
|
24
|
-
const formatDate = (dateStr: string) =>
|
|
25
|
-
try {
|
|
26
|
-
return new Date(dateStr).toLocaleDateString(locale, {
|
|
27
|
-
year: "numeric",
|
|
28
|
-
month: "short",
|
|
29
|
-
day: "numeric",
|
|
30
|
-
});
|
|
31
|
-
} catch {
|
|
32
|
-
return dateStr;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
25
|
+
const formatDate = (dateStr: string) => formatDateOnlyForDisplay(dateStr, locale);
|
|
35
26
|
|
|
36
27
|
const formatCurrency = (amount: number) => {
|
|
37
28
|
try {
|
|
@@ -10,7 +10,7 @@ import { DocumentPreviewSkeleton } from "../shared/document-preview-skeleton";
|
|
|
10
10
|
import { ScaledDocumentPreview } from "../shared/scaled-document-preview";
|
|
11
11
|
import { useA4Scaling } from "../shared/use-a4-scaling";
|
|
12
12
|
import type { DocumentTypes } from "../types";
|
|
13
|
-
import { filterUnresolvedTaxes } from "./prepare-preview-data";
|
|
13
|
+
import { filterUnresolvedTaxes, normalizeDocumentPreviewDates } from "./prepare-preview-data";
|
|
14
14
|
|
|
15
15
|
const LIVE_PREVIEW_TIMING_EVENT = "si:live-preview-timing";
|
|
16
16
|
const LIVE_PREVIEW_DEBOUNCE_MS = 300;
|
|
@@ -126,7 +126,7 @@ export function LiveInvoicePreview({
|
|
|
126
126
|
// Prepare preview data with active entity as issuer (if not already set)
|
|
127
127
|
// Exclude 'number' as it's auto-generated by the render endpoint
|
|
128
128
|
const { number: _number, ...invoiceDataWithoutNumber } = invoiceData as any;
|
|
129
|
-
const previewData = {
|
|
129
|
+
const previewData = normalizeDocumentPreviewDates({
|
|
130
130
|
...invoiceDataWithoutNumber,
|
|
131
131
|
// Filter out unresolved tax_ids (race condition: form may add
|
|
132
132
|
// { tax_id: undefined } before the tax dropdown auto-selects a value)
|
|
@@ -142,7 +142,7 @@ export function LiveInvoicePreview({
|
|
|
142
142
|
tax_number: activeEntity.tax_number,
|
|
143
143
|
...invoiceData.issuer,
|
|
144
144
|
},
|
|
145
|
-
};
|
|
145
|
+
});
|
|
146
146
|
const requestKey = JSON.stringify({
|
|
147
147
|
documentType,
|
|
148
148
|
template,
|
|
@@ -61,6 +61,7 @@ export function MarkAsPaidSection({
|
|
|
61
61
|
}: MarkAsPaidSectionProps) {
|
|
62
62
|
const showPaymentTypes = forced || checked || alwaysShowPaymentType;
|
|
63
63
|
const showPaymentAmounts = paymentRows.length > 1;
|
|
64
|
+
const showPaymentSummary = paymentRows.length > 1;
|
|
64
65
|
const derivedAmounts = derivePaymentRowAmounts(paymentRows, documentTotal);
|
|
65
66
|
const recordedTotal = getRecordedPaymentTotal(paymentRows, documentTotal);
|
|
66
67
|
const remainingTotal = Math.max(0, Math.round((documentTotal - recordedTotal) * 100) / 100);
|
|
@@ -120,7 +121,7 @@ export function MarkAsPaidSection({
|
|
|
120
121
|
}}
|
|
121
122
|
>
|
|
122
123
|
<SelectTrigger className="w-full md:w-fit">
|
|
123
|
-
<SelectValue placeholder={t("
|
|
124
|
+
<SelectValue placeholder={t("Select payment type")}>
|
|
124
125
|
{row.type ? t(PAYMENT_TYPE_LABELS[row.type]) : undefined}
|
|
125
126
|
</SelectValue>
|
|
126
127
|
</SelectTrigger>
|
|
@@ -176,17 +177,19 @@ export function MarkAsPaidSection({
|
|
|
176
177
|
<Plus className="size-4" />
|
|
177
178
|
{t("Add payment")}
|
|
178
179
|
</Button>
|
|
179
|
-
{validationMessage && <p className="text-destructive text-sm">{validationMessage}</p>}
|
|
180
|
-
|
|
181
|
-
<div className="
|
|
182
|
-
<
|
|
183
|
-
|
|
180
|
+
{validationMessage && <p className="text-destructive text-sm">{t(validationMessage)}</p>}
|
|
181
|
+
{showPaymentSummary && (
|
|
182
|
+
<div className="grid gap-1 text-muted-foreground text-sm">
|
|
183
|
+
<div className="flex items-center justify-between">
|
|
184
|
+
<span>{t("Recorded now")}</span>
|
|
185
|
+
<span>{recordedTotal.toFixed(2)}</span>
|
|
186
|
+
</div>
|
|
187
|
+
<div className="flex items-center justify-between">
|
|
188
|
+
<span>{requireFullPayment ? t("Remaining to allocate") : t("Remaining due")}</span>
|
|
189
|
+
<span>{remainingTotal.toFixed(2)}</span>
|
|
190
|
+
</div>
|
|
184
191
|
</div>
|
|
185
|
-
|
|
186
|
-
<span>{requireFullPayment ? t("Remaining to allocate") : t("Remaining due")}</span>
|
|
187
|
-
<span>{remainingTotal.toFixed(2)}</span>
|
|
188
|
-
</div>
|
|
189
|
-
</div>
|
|
192
|
+
)}
|
|
190
193
|
</div>
|
|
191
194
|
)}
|
|
192
195
|
</div>
|
|
@@ -16,6 +16,11 @@ export type SerializedPaymentRow = {
|
|
|
16
16
|
amount: number;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
export type ApiSerializedPaymentRow = {
|
|
20
|
+
type: RegularPaymentType;
|
|
21
|
+
amount?: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
19
24
|
export type PaymentRowsEvaluation = {
|
|
20
25
|
payments: SerializedPaymentRow[];
|
|
21
26
|
totalAmount: number;
|
|
@@ -289,3 +294,28 @@ export function validatePaymentRows(
|
|
|
289
294
|
export function serializePaymentRows(paymentRows: DraftPaymentRow[], documentTotal: number): SerializedPaymentRow[] {
|
|
290
295
|
return evaluatePaymentRows(paymentRows, documentTotal).payments;
|
|
291
296
|
}
|
|
297
|
+
|
|
298
|
+
export function serializePaymentRowsForApi(
|
|
299
|
+
paymentRows: DraftPaymentRow[],
|
|
300
|
+
documentTotal: number,
|
|
301
|
+
options?: { preserveUntouchedAmounts?: boolean },
|
|
302
|
+
): ApiSerializedPaymentRow[] {
|
|
303
|
+
const resolvedPayments = evaluatePaymentRows(paymentRows, documentTotal).payments;
|
|
304
|
+
|
|
305
|
+
if (!options?.preserveUntouchedAmounts) {
|
|
306
|
+
return resolvedPayments;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return paymentRows.flatMap((row, index) => {
|
|
310
|
+
if (!isValidPaymentTypeSelection(row.type)) {
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const resolvedPayment = resolvedPayments[index];
|
|
315
|
+
if (!resolvedPayment) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return row.amountTouched ? [resolvedPayment] : [{ type: resolvedPayment.type }];
|
|
320
|
+
});
|
|
321
|
+
}
|