@spaceinvoices/react-ui 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +340 -0
- package/cli/dist/index.js +922 -0
- package/package.json +87 -0
- package/registry.json +600 -0
- package/spaceinvoices.schema.json +47 -0
- package/src/app.tsx +25 -0
- package/src/common/autocomplete.tsx +135 -0
- package/src/components/activities/activity-timeline.tsx +160 -0
- package/src/components/activities/index.ts +1 -0
- package/src/components/activities/locales/de.ts +30 -0
- package/src/components/activities/locales/sl.ts +30 -0
- package/src/components/advance-invoices/advance-invoices.hooks.ts +75 -0
- package/src/components/advance-invoices/create/create-advance-invoice-form.tsx +702 -0
- package/src/components/advance-invoices/create/locales/de.ts +29 -0
- package/src/components/advance-invoices/create/locales/sl.ts +25 -0
- package/src/components/advance-invoices/create/prepare-advance-invoice-submission.ts +74 -0
- package/src/components/advance-invoices/index.ts +5 -0
- package/src/components/advance-invoices/list/index.ts +3 -0
- package/src/components/advance-invoices/list/list-row-actions.tsx +119 -0
- package/src/components/advance-invoices/list/list-table.tsx +178 -0
- package/src/components/advance-invoices/list/locales/de.ts +32 -0
- package/src/components/advance-invoices/list/locales/sl.ts +32 -0
- package/src/components/advance-invoices/list/use-advance-invoice-download.ts +63 -0
- package/src/components/button-loader.tsx +11 -0
- package/src/components/combobox.tsx +96 -0
- package/src/components/company-registry/company-registry-autocomplete.tsx +151 -0
- package/src/components/company-registry/company-registry.hooks.ts +67 -0
- package/src/components/company-registry/index.ts +7 -0
- package/src/components/credit-notes/create/create-credit-note-form.tsx +332 -0
- package/src/components/credit-notes/create/index.ts +1 -0
- package/src/components/credit-notes/create/locales/de.ts +69 -0
- package/src/components/credit-notes/create/locales/sl.ts +67 -0
- package/src/components/credit-notes/credit-notes.hooks.ts +22 -0
- package/src/components/credit-notes/index.ts +10 -0
- package/src/components/credit-notes/list/index.ts +3 -0
- package/src/components/credit-notes/list/list-row-actions.tsx +116 -0
- package/src/components/credit-notes/list/list-table.tsx +183 -0
- package/src/components/credit-notes/list/locales/de.ts +33 -0
- package/src/components/credit-notes/list/locales/sl.ts +33 -0
- package/src/components/credit-notes/list/use-credit-note-download.ts +65 -0
- package/src/components/customers/create-customer-form/create-customer-form.tsx +134 -0
- package/src/components/customers/create-customer-form/locales/de.ts +20 -0
- package/src/components/customers/create-customer-form/locales/sl.ts +20 -0
- package/src/components/customers/customer-autocomplete.tsx +173 -0
- package/src/components/customers/customer-combobox.tsx +130 -0
- package/src/components/customers/customer-list-table/customer-list-row-actions.tsx +48 -0
- package/src/components/customers/customer-list-table/customer-list-table.tsx +124 -0
- package/src/components/customers/customer-list-table/index.ts +2 -0
- package/src/components/customers/customer-list-table/locales/de.ts +16 -0
- package/src/components/customers/customer-list-table/locales/sl.ts +16 -0
- package/src/components/customers/customers.hooks.test.ts +348 -0
- package/src/components/customers/customers.hooks.ts +57 -0
- package/src/components/customers/index.ts +5 -0
- package/src/components/dashboard/chart-empty-state.tsx +29 -0
- package/src/components/dashboard/collection-rate-card/collection-rate-card.tsx +80 -0
- package/src/components/dashboard/collection-rate-card/index.ts +4 -0
- package/src/components/dashboard/collection-rate-card/locales/sl.ts +3 -0
- package/src/components/dashboard/collection-rate-card/use-collection-rate.ts +74 -0
- package/src/components/dashboard/index.ts +54 -0
- package/src/components/dashboard/invoice-status-chart/index.ts +4 -0
- package/src/components/dashboard/invoice-status-chart/invoice-status-chart.tsx +130 -0
- package/src/components/dashboard/invoice-status-chart/locales/sl.ts +9 -0
- package/src/components/dashboard/invoice-status-chart/use-invoice-status.ts +105 -0
- package/src/components/dashboard/loading-card.tsx +19 -0
- package/src/components/dashboard/payment-methods-chart/index.ts +4 -0
- package/src/components/dashboard/payment-methods-chart/locales/sl.ts +12 -0
- package/src/components/dashboard/payment-methods-chart/payment-methods-chart.tsx +152 -0
- package/src/components/dashboard/payment-methods-chart/use-payment-methods.ts +50 -0
- package/src/components/dashboard/payment-trend-chart/index.ts +4 -0
- package/src/components/dashboard/payment-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/payment-trend-chart/payment-trend-chart.tsx +137 -0
- package/src/components/dashboard/payment-trend-chart/use-payment-trend.ts +92 -0
- package/src/components/dashboard/revenue-card.tsx +49 -0
- package/src/components/dashboard/revenue-trend-chart/index.ts +4 -0
- package/src/components/dashboard/revenue-trend-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/revenue-trend-chart/revenue-trend-chart.tsx +137 -0
- package/src/components/dashboard/revenue-trend-chart/use-revenue-trend.ts +93 -0
- package/src/components/dashboard/shared/index.ts +5 -0
- package/src/components/dashboard/shared/use-revenue-data.ts +160 -0
- package/src/components/dashboard/shared/use-stats-counts.ts +89 -0
- package/src/components/dashboard/shared/use-stats-query.ts +38 -0
- package/src/components/dashboard/stat-card.tsx +41 -0
- package/src/components/dashboard/tax-collected-card/index.ts +2 -0
- package/src/components/dashboard/tax-collected-card/tax-collected-card.tsx +77 -0
- package/src/components/dashboard/tax-collected-card/use-tax-collected.ts +145 -0
- package/src/components/dashboard/top-customers-chart/index.ts +4 -0
- package/src/components/dashboard/top-customers-chart/locales/sl.ts +5 -0
- package/src/components/dashboard/top-customers-chart/top-customers-chart.tsx +130 -0
- package/src/components/dashboard/top-customers-chart/use-top-customers.ts +72 -0
- package/src/components/documents/create/document-add-item-form.tsx +379 -0
- package/src/components/documents/create/document-add-item-tax-rate-field.tsx +120 -0
- package/src/components/documents/create/document-details-section.tsx +597 -0
- package/src/components/documents/create/document-items-section.tsx +133 -0
- package/src/components/documents/create/document-recipient-section.tsx +101 -0
- package/src/components/documents/create/form-types.ts +36 -0
- package/src/components/documents/create/index.ts +9 -0
- package/src/components/documents/create/live-preview.tsx +235 -0
- package/src/components/documents/create/mark-as-paid-section.tsx +82 -0
- package/src/components/documents/create/prepare-document-submission.test.ts +132 -0
- package/src/components/documents/create/prepare-document-submission.ts +187 -0
- package/src/components/documents/create/prepare-preview-data.test.ts +155 -0
- package/src/components/documents/create/prepare-preview-data.ts +16 -0
- package/src/components/documents/create/smart-code-insert-button.tsx +139 -0
- package/src/components/documents/create/use-document-customer-form.ts +161 -0
- package/src/components/documents/document-preview.tsx +13 -0
- package/src/components/documents/documents.hooks.ts +146 -0
- package/src/components/documents/index.ts +23 -0
- package/src/components/documents/shared/document-preview-display.tsx +172 -0
- package/src/components/documents/shared/index.ts +3 -0
- package/src/components/documents/shared/scaled-document-preview.tsx +70 -0
- package/src/components/documents/shared/use-a4-scaling.ts +62 -0
- package/src/components/documents/types.ts +61 -0
- package/src/components/documents/view/document-actions-bar.tsx +328 -0
- package/src/components/documents/view/document-details-card.tsx +179 -0
- package/src/components/documents/view/document-payments-list.tsx +256 -0
- package/src/components/documents/view/index.ts +4 -0
- package/src/components/documents/view/locales/de.ts +85 -0
- package/src/components/documents/view/locales/sl.ts +84 -0
- package/src/components/documents/view/use-document-download.ts +125 -0
- package/src/components/entities/create-entity-form.tsx +105 -0
- package/src/components/entities/entities.hooks.ts +50 -0
- package/src/components/entities/entity-settings-form/email-template-variables-info.tsx +103 -0
- package/src/components/entities/entity-settings-form/entity-settings-form.tsx +1326 -0
- package/src/components/entities/entity-settings-form/image-upload-with-crop.tsx +222 -0
- package/src/components/entities/entity-settings-form/index.ts +2 -0
- package/src/components/entities/entity-settings-form/input-with-preview.tsx +190 -0
- package/src/components/entities/entity-settings-form/locales/de.ts +192 -0
- package/src/components/entities/entity-settings-form/locales/sl.ts +188 -0
- package/src/components/entities/furs-settings-form/furs-settings-form.tsx +410 -0
- package/src/components/entities/furs-settings-form/furs-settings.hooks.ts +320 -0
- package/src/components/entities/furs-settings-form/index.ts +3 -0
- package/src/components/entities/furs-settings-form/locales/de.ts +233 -0
- package/src/components/entities/furs-settings-form/locales/en.ts +194 -0
- package/src/components/entities/furs-settings-form/locales/sl.ts +196 -0
- package/src/components/entities/furs-settings-form/sections/certificate-settings-section.tsx +242 -0
- package/src/components/entities/furs-settings-form/sections/enable-fiscalization-section.tsx +139 -0
- package/src/components/entities/furs-settings-form/sections/general-settings-section.tsx +252 -0
- package/src/components/entities/furs-settings-form/sections/premises-management-section.tsx +370 -0
- package/src/components/entities/furs-settings-form/sections/register-premise-dialog.tsx +420 -0
- package/src/components/entities/keys.ts +2 -0
- package/src/components/entities/settings/branding-settings-form.tsx +274 -0
- package/src/components/entities/settings/company-settings-form.tsx +256 -0
- package/src/components/entities/settings/defaults-settings-form.tsx +501 -0
- package/src/components/entities/settings/email-settings-form.tsx +288 -0
- package/src/components/entities/settings/eslog-settings-form.tsx +113 -0
- package/src/components/entities/settings/index.ts +8 -0
- package/src/components/entities/settings/number-format-settings-form.tsx +244 -0
- package/src/components/entities/settings/pdf-template-selector/demo-invoice-data.ts +164 -0
- package/src/components/entities/settings/pdf-template-selector/index.ts +2 -0
- package/src/components/entities/settings/pdf-template-selector/locales/de.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/locales/sl.ts +18 -0
- package/src/components/entities/settings/pdf-template-selector/pdf-template-cards.tsx +49 -0
- package/src/components/entities/settings/settings-footer.tsx +16 -0
- package/src/components/entities/settings/tax-rules-settings-form.tsx +346 -0
- package/src/components/estimates/create/create-estimate-form.tsx +384 -0
- package/src/components/estimates/create/locales/de.ts +64 -0
- package/src/components/estimates/create/locales/sl.ts +63 -0
- package/src/components/estimates/create/prepare-estimate-submission.ts +39 -0
- package/src/components/estimates/create/use-estimate-customer-form.ts +5 -0
- package/src/components/estimates/estimates.hooks.ts +15 -0
- package/src/components/estimates/index.ts +6 -0
- package/src/components/estimates/list/index.ts +3 -0
- package/src/components/estimates/list/list-row-actions.tsx +103 -0
- package/src/components/estimates/list/list-table.tsx +171 -0
- package/src/components/estimates/list/locales/de.ts +26 -0
- package/src/components/estimates/list/locales/sl.ts +26 -0
- package/src/components/estimates/list/use-estimate-download.ts +63 -0
- package/src/components/export/document-export-form.tsx +288 -0
- package/src/components/export/index.ts +2 -0
- package/src/components/form/form-input.tsx +89 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/invoices/create/create-invoice-form.tsx +852 -0
- package/src/components/invoices/create/eslog-validation.test.ts +242 -0
- package/src/components/invoices/create/eslog-validation.ts +208 -0
- package/src/components/invoices/create/locales/de.ts +118 -0
- package/src/components/invoices/create/locales/sl.ts +114 -0
- package/src/components/invoices/create/prepare-invoice-submission.test.ts +777 -0
- package/src/components/invoices/create/prepare-invoice-submission.ts +79 -0
- package/src/components/invoices/create/use-invoice-customer-form.ts +5 -0
- package/src/components/invoices/index.ts +9 -0
- package/src/components/invoices/invoices-furs.hooks.ts +28 -0
- package/src/components/invoices/invoices.hooks.ts +110 -0
- package/src/components/invoices/list/index.ts +3 -0
- package/src/components/invoices/list/list-row-actions.tsx +132 -0
- package/src/components/invoices/list/list-table.tsx +165 -0
- package/src/components/invoices/list/locales/de.ts +33 -0
- package/src/components/invoices/list/locales/sl.ts +33 -0
- package/src/components/invoices/list/use-invoice-download.ts +62 -0
- package/src/components/invoices/send-email-dialog/index.ts +1 -0
- package/src/components/invoices/send-email-dialog/locales/de.ts +18 -0
- package/src/components/invoices/send-email-dialog/locales/sl.ts +17 -0
- package/src/components/invoices/send-email-dialog/send-email-dialog.tsx +289 -0
- package/src/components/invoices/send-email-dialog.tsx +2 -0
- package/src/components/invoices/shared/index.ts +2 -0
- package/src/components/invoices/shared/scaled-document-preview.tsx +32 -0
- package/src/components/invoices/shared/use-a4-scaling.tsx +39 -0
- package/src/components/invoices/view/eslog-info-display.tsx +160 -0
- package/src/components/invoices/view/furs-info-display.tsx +213 -0
- package/src/components/items/create-item-form/create-item-form.tsx +155 -0
- package/src/components/items/create-item-form/locales/de.ts +14 -0
- package/src/components/items/create-item-form/locales/en.ts +9 -0
- package/src/components/items/create-item-form/locales/sl.ts +14 -0
- package/src/components/items/item-combobox.tsx +147 -0
- package/src/components/items/item-list-table/item-list-header.tsx +33 -0
- package/src/components/items/item-list-table/item-list-row-actions.tsx +48 -0
- package/src/components/items/item-list-table/item-list-row.tsx +32 -0
- package/src/components/items/item-list-table/item-list-table.tsx +76 -0
- package/src/components/items/item-list-table/locales/de.ts +10 -0
- package/src/components/items/item-list-table/locales/en.ts +10 -0
- package/src/components/items/item-list-table/locales/sl.ts +10 -0
- package/src/components/items/items.hooks.ts +63 -0
- package/src/components/loading-spinner.tsx +24 -0
- package/src/components/payments/create-payment-form/create-payment-form.tsx +222 -0
- package/src/components/payments/create-payment-form/locales/de.ts +20 -0
- package/src/components/payments/create-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/edit-payment-form/edit-payment-form.tsx +230 -0
- package/src/components/payments/edit-payment-form/index.ts +1 -0
- package/src/components/payments/edit-payment-form/locales/de.ts +20 -0
- package/src/components/payments/edit-payment-form/locales/sl.ts +20 -0
- package/src/components/payments/index.ts +4 -0
- package/src/components/payments/list/index.ts +2 -0
- package/src/components/payments/list/list-row-actions.tsx +98 -0
- package/src/components/payments/list/list-table.tsx +186 -0
- package/src/components/payments/list/locales/de.ts +19 -0
- package/src/components/payments/list/locales/sl.ts +19 -0
- package/src/components/payments/payments.hooks.ts +15 -0
- package/src/components/request-logs/index.ts +3 -0
- package/src/components/request-logs/request-log-detail.tsx +242 -0
- package/src/components/request-logs/request-log-list-table.tsx +266 -0
- package/src/components/request-logs/request-logs-page.tsx +10 -0
- package/src/components/table/README.md +410 -0
- package/src/components/table/data-table.tsx +251 -0
- package/src/components/table/date-cell.tsx +35 -0
- package/src/components/table/filter-bar.tsx +114 -0
- package/src/components/table/filter-panel.tsx +407 -0
- package/src/components/table/hooks/use-table-fetch.ts +17 -0
- package/src/components/table/hooks/use-table-query.ts +36 -0
- package/src/components/table/hooks/use-table-state.ts +293 -0
- package/src/components/table/index.ts +35 -0
- package/src/components/table/search-input.tsx +85 -0
- package/src/components/table/sortable-header.tsx +56 -0
- package/src/components/table/table-empty-state.tsx +40 -0
- package/src/components/table/table-no-results.tsx +41 -0
- package/src/components/table/table-pagination.tsx +42 -0
- package/src/components/table/table-skeleton.tsx +54 -0
- package/src/components/table/types.ts +136 -0
- package/src/components/tax-reports/index.ts +1 -0
- package/src/components/tax-reports/kir-export-form.tsx +172 -0
- package/src/components/taxes/create-tax-form/create-tax-form.tsx +112 -0
- package/src/components/taxes/create-tax-form/locales/de.ts +8 -0
- package/src/components/taxes/create-tax-form/locales/en.ts +7 -0
- package/src/components/taxes/create-tax-form/locales/sl.ts +8 -0
- package/src/components/taxes/tax-list-table/locales/de.ts +11 -0
- package/src/components/taxes/tax-list-table/locales/en.ts +10 -0
- package/src/components/taxes/tax-list-table/locales/sl.ts +11 -0
- package/src/components/taxes/tax-list-table/tax-list-header.tsx +29 -0
- package/src/components/taxes/tax-list-table/tax-list-row-actions.tsx +43 -0
- package/src/components/taxes/tax-list-table/tax-list-row.tsx +46 -0
- package/src/components/taxes/tax-list-table/tax-list-table.tsx +59 -0
- package/src/components/taxes/taxes.hooks.ts +35 -0
- package/src/components/ui/alert-dialog.tsx +61 -0
- package/src/components/ui/alert.tsx +72 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/breadcrumb.tsx +132 -0
- package/src/components/ui/button.tsx +61 -0
- package/src/components/ui/calendar.tsx +213 -0
- package/src/components/ui/card.tsx +94 -0
- package/src/components/ui/chart.tsx +380 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +56 -0
- package/src/components/ui/command.tsx +187 -0
- package/src/components/ui/dialog.tsx +187 -0
- package/src/components/ui/drawer.tsx +123 -0
- package/src/components/ui/dropdown-menu.tsx +291 -0
- package/src/components/ui/form.tsx +166 -0
- package/src/components/ui/input-group.tsx +149 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/label.tsx +18 -0
- package/src/components/ui/loading-spinner.tsx +16 -0
- package/src/components/ui/popover.tsx +108 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +145 -0
- package/src/components/ui/sidebar.tsx +771 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/sonner.tsx +60 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/sticky-form-footer.tsx +55 -0
- package/src/components/ui/switch.tsx +30 -0
- package/src/components/ui/table.tsx +101 -0
- package/src/components/ui/tabs.tsx +80 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +89 -0
- package/src/components/wl-subscription/index.ts +2 -0
- package/src/components/wl-subscription/locked-feature.tsx +173 -0
- package/src/components/wl-subscription/upgrade-modal.tsx +209 -0
- package/src/frontend.tsx +28 -0
- package/src/generate-schemas.ts +265 -0
- package/src/generated/schemas/advanceinvoice.ts +177 -0
- package/src/generated/schemas/creditnote.ts +187 -0
- package/src/generated/schemas/customer.ts +29 -0
- package/src/generated/schemas/entity.ts +252 -0
- package/src/generated/schemas/estimate.ts +159 -0
- package/src/generated/schemas/furssettings.ts +25 -0
- package/src/generated/schemas/index.ts +24 -0
- package/src/generated/schemas/invoice.ts +167 -0
- package/src/generated/schemas/item.ts +38 -0
- package/src/generated/schemas/payment.ts +44 -0
- package/src/generated/schemas/previewadvanceinvoice_body.ts +354 -0
- package/src/generated/schemas/previewestimate_body.ts +309 -0
- package/src/generated/schemas/registerfursmovablepremise_body.ts +22 -0
- package/src/generated/schemas/registerfursrealestatepremise_body.ts +32 -0
- package/src/generated/schemas/renderdocument_body.ts +594 -0
- package/src/generated/schemas/sendemail_body.ts +26 -0
- package/src/generated/schemas/startpdfexport_body.ts +20 -0
- package/src/generated/schemas/tax.ts +48 -0
- package/src/generated/schemas/uploadfile_body.ts +23 -0
- package/src/generated/schemas/uploadfurscertificate_body.ts +20 -0
- package/src/generated/schemas/userfurssettings.ts +19 -0
- package/src/hooks/create-resource-hooks.test.ts +483 -0
- package/src/hooks/create-resource-hooks.ts +300 -0
- package/src/hooks/use-debounce.ts +12 -0
- package/src/hooks/use-duplicate-document.ts +185 -0
- package/src/hooks/use-media-query.tsx +19 -0
- package/src/hooks/use-mobile.ts +39 -0
- package/src/hooks/use-next-document-number.ts +57 -0
- package/src/hooks/use-resource-mutation.ts +118 -0
- package/src/hooks/use-vies-check.ts +130 -0
- package/src/index.css +11 -0
- package/src/index.html +13 -0
- package/src/index.tsx +12 -0
- package/src/lib/auth.ts +4 -0
- package/src/lib/browser-cookies.ts +70 -0
- package/src/lib/constants.ts +287 -0
- package/src/lib/cookies.ts +36 -0
- package/src/lib/schemas/advance-invoice.ts +43 -0
- package/src/lib/schemas/credit-note.ts +32 -0
- package/src/lib/schemas/estimate.ts +31 -0
- package/src/lib/schemas/index.ts +18 -0
- package/src/lib/schemas/invoice.ts +43 -0
- package/src/lib/schemas/shared.ts +79 -0
- package/src/lib/translation.ts +38 -0
- package/src/lib/utils.ts +6 -0
- package/src/providers/entities-context.tsx +41 -0
- package/src/providers/entities-provider.tsx +201 -0
- package/src/providers/form-footer-context.tsx +72 -0
- package/src/providers/sdk-provider.tsx +164 -0
- package/src/providers/white-label-provider.tsx +91 -0
- package/src/providers/wl-subscription-provider.tsx +277 -0
- package/src/utils/string-helpers.ts +111 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/ui/components/ui/card";
|
|
4
|
+
|
|
5
|
+
export type StatCardProps = {
|
|
6
|
+
title: string;
|
|
7
|
+
value: string | number | undefined;
|
|
8
|
+
href?: string;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function StatCard({ title, value, href, onClick }: StatCardProps) {
|
|
13
|
+
const content = (
|
|
14
|
+
<Card className="cursor-pointer transition-colors hover:bg-accent/50">
|
|
15
|
+
<CardHeader className="pb-2">
|
|
16
|
+
<CardTitle className="font-medium text-muted-foreground text-sm">{title}</CardTitle>
|
|
17
|
+
</CardHeader>
|
|
18
|
+
<CardContent>
|
|
19
|
+
<div className="font-bold text-2xl">{value ?? 0}</div>
|
|
20
|
+
</CardContent>
|
|
21
|
+
</Card>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (href) {
|
|
25
|
+
return (
|
|
26
|
+
<a href={href} onClick={onClick}>
|
|
27
|
+
{content}
|
|
28
|
+
</a>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (onClick) {
|
|
33
|
+
return (
|
|
34
|
+
<button type="button" onClick={onClick} className="w-full text-left">
|
|
35
|
+
{content}
|
|
36
|
+
</button>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return content;
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/ui/components/ui/card";
|
|
4
|
+
import { Skeleton } from "@/ui/components/ui/skeleton";
|
|
5
|
+
import type { TaxByRate } from "./use-tax-collected";
|
|
6
|
+
|
|
7
|
+
export type TaxCollectedCardProps = {
|
|
8
|
+
title: string;
|
|
9
|
+
periodLabel: string;
|
|
10
|
+
taxes: TaxByRate[];
|
|
11
|
+
total: number;
|
|
12
|
+
currency: string;
|
|
13
|
+
isLoading?: boolean;
|
|
14
|
+
locale?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function formatCurrency(value: number, currency: string, locale?: string): string {
|
|
18
|
+
return new Intl.NumberFormat(locale, {
|
|
19
|
+
style: "currency",
|
|
20
|
+
currency,
|
|
21
|
+
minimumFractionDigits: 2,
|
|
22
|
+
}).format(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function TaxCollectedCard({
|
|
26
|
+
title,
|
|
27
|
+
periodLabel,
|
|
28
|
+
taxes,
|
|
29
|
+
total,
|
|
30
|
+
currency,
|
|
31
|
+
isLoading,
|
|
32
|
+
locale,
|
|
33
|
+
}: TaxCollectedCardProps) {
|
|
34
|
+
if (isLoading) {
|
|
35
|
+
return (
|
|
36
|
+
<Card>
|
|
37
|
+
<CardHeader className="pb-2">
|
|
38
|
+
<CardTitle className="font-medium text-muted-foreground text-sm">{title}</CardTitle>
|
|
39
|
+
</CardHeader>
|
|
40
|
+
<CardContent className="space-y-2">
|
|
41
|
+
<Skeleton className="h-6 w-24" />
|
|
42
|
+
<Skeleton className="h-4 w-32" />
|
|
43
|
+
<Skeleton className="h-4 w-28" />
|
|
44
|
+
</CardContent>
|
|
45
|
+
</Card>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Card>
|
|
51
|
+
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
|
52
|
+
<CardTitle className="font-medium text-muted-foreground text-sm">{title}</CardTitle>
|
|
53
|
+
<span className="text-muted-foreground text-xs">{periodLabel}</span>
|
|
54
|
+
</CardHeader>
|
|
55
|
+
<CardContent>
|
|
56
|
+
{/* Total */}
|
|
57
|
+
<div className="mb-3 font-bold text-2xl">{formatCurrency(total, currency, locale)}</div>
|
|
58
|
+
|
|
59
|
+
{/* Tax breakdown */}
|
|
60
|
+
{taxes.length > 0 ? (
|
|
61
|
+
<div className="space-y-1">
|
|
62
|
+
{taxes.map((tax) => (
|
|
63
|
+
<div key={`${tax.name}-${tax.rate}`} className="flex items-center justify-between text-sm">
|
|
64
|
+
<span className="text-muted-foreground">
|
|
65
|
+
{tax.name} {tax.rate}%
|
|
66
|
+
</span>
|
|
67
|
+
<span className="font-medium">{formatCurrency(tax.amount, currency, locale)}</span>
|
|
68
|
+
</div>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
) : (
|
|
72
|
+
<p className="text-muted-foreground text-sm">No tax data</p>
|
|
73
|
+
)}
|
|
74
|
+
</CardContent>
|
|
75
|
+
</Card>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tax collected hook - uses stats API to aggregate tax amounts by rate.
|
|
3
|
+
* Shows tax breakdown for previous month and current year.
|
|
4
|
+
*/
|
|
5
|
+
import type { StatsQueryDataItem } from "@spaceinvoices/js-sdk";
|
|
6
|
+
import { useQueries } from "@tanstack/react-query";
|
|
7
|
+
import { useSDK } from "@/ui/providers/sdk-provider";
|
|
8
|
+
|
|
9
|
+
export const TAX_COLLECTED_CACHE_KEY = "dashboard-tax-collected";
|
|
10
|
+
|
|
11
|
+
function getPreviousMonthDateRange() {
|
|
12
|
+
const now = new Date();
|
|
13
|
+
const firstDay = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
14
|
+
const lastDay = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
15
|
+
return {
|
|
16
|
+
from: firstDay.toISOString().split("T")[0],
|
|
17
|
+
to: lastDay.toISOString().split("T")[0],
|
|
18
|
+
label: firstDay.toLocaleDateString("en-US", { month: "short", year: "numeric" }),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getYearDateRange() {
|
|
23
|
+
const year = new Date().getFullYear();
|
|
24
|
+
return {
|
|
25
|
+
from: `${year}-01-01`,
|
|
26
|
+
to: `${year}-12-31`,
|
|
27
|
+
label: `${year}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type TaxByRate = {
|
|
32
|
+
name: string;
|
|
33
|
+
rate: number;
|
|
34
|
+
amount: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type TaxCollectedData = {
|
|
38
|
+
previousMonth: {
|
|
39
|
+
label: string;
|
|
40
|
+
taxes: TaxByRate[];
|
|
41
|
+
total: number;
|
|
42
|
+
};
|
|
43
|
+
currentYear: {
|
|
44
|
+
label: string;
|
|
45
|
+
taxes: TaxByRate[];
|
|
46
|
+
total: number;
|
|
47
|
+
};
|
|
48
|
+
currency: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Transform stats response to TaxByRate array
|
|
53
|
+
*/
|
|
54
|
+
function transformTaxData(data: StatsQueryDataItem[]): TaxByRate[] {
|
|
55
|
+
return data
|
|
56
|
+
.filter((row) => row.rate != null && row.tax_total != null)
|
|
57
|
+
.map((row) => ({
|
|
58
|
+
name: "Tax", // Could be enhanced to include tax name if available
|
|
59
|
+
rate: Number(row.rate),
|
|
60
|
+
amount: Number(row.tax_total),
|
|
61
|
+
}))
|
|
62
|
+
.sort((a, b) => b.rate - a.rate); // Sort by rate descending
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function useTaxCollectedData(entityId: string | undefined) {
|
|
66
|
+
const { sdk } = useSDK();
|
|
67
|
+
const prevMonthRange = getPreviousMonthDateRange();
|
|
68
|
+
const yearRange = getYearDateRange();
|
|
69
|
+
|
|
70
|
+
const queries = useQueries({
|
|
71
|
+
queries: [
|
|
72
|
+
// Previous month taxes - aggregated by rate using stats API
|
|
73
|
+
{
|
|
74
|
+
queryKey: [TAX_COLLECTED_CACHE_KEY, entityId, "prev-month", prevMonthRange.from],
|
|
75
|
+
queryFn: async () => {
|
|
76
|
+
if (!entityId || !sdk) throw new Error("Missing entity or SDK");
|
|
77
|
+
// Use invoice_taxes virtual table to aggregate taxes by rate
|
|
78
|
+
return sdk.entityStats.queryEntityStats(
|
|
79
|
+
{
|
|
80
|
+
table: "invoice_taxes",
|
|
81
|
+
metrics: [{ type: "sum", field: "tax", alias: "tax_total" }],
|
|
82
|
+
group_by: ["rate", "quote_currency"],
|
|
83
|
+
date_from: prevMonthRange.from,
|
|
84
|
+
date_to: prevMonthRange.to,
|
|
85
|
+
filters: { is_draft: false, voided_at: null },
|
|
86
|
+
},
|
|
87
|
+
{ entity_id: entityId },
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
enabled: !!entityId && !!sdk,
|
|
91
|
+
staleTime: 60_000, // 1 minute
|
|
92
|
+
},
|
|
93
|
+
// Current year taxes - aggregated by rate using stats API
|
|
94
|
+
{
|
|
95
|
+
queryKey: [TAX_COLLECTED_CACHE_KEY, entityId, "year", yearRange.from],
|
|
96
|
+
queryFn: async () => {
|
|
97
|
+
if (!entityId || !sdk) throw new Error("Missing entity or SDK");
|
|
98
|
+
return sdk.entityStats.queryEntityStats(
|
|
99
|
+
{
|
|
100
|
+
table: "invoice_taxes",
|
|
101
|
+
metrics: [{ type: "sum", field: "tax", alias: "tax_total" }],
|
|
102
|
+
group_by: ["rate", "quote_currency"],
|
|
103
|
+
date_from: yearRange.from,
|
|
104
|
+
date_to: yearRange.to,
|
|
105
|
+
filters: { is_draft: false, voided_at: null },
|
|
106
|
+
},
|
|
107
|
+
{ entity_id: entityId },
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
enabled: !!entityId && !!sdk,
|
|
111
|
+
staleTime: 60_000,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const [prevMonthQuery, yearQuery] = queries;
|
|
117
|
+
|
|
118
|
+
// Transform stats data to TaxByRate arrays
|
|
119
|
+
const prevMonthTaxes = transformTaxData(prevMonthQuery.data?.data || []);
|
|
120
|
+
const yearTaxes = transformTaxData(yearQuery.data?.data || []);
|
|
121
|
+
|
|
122
|
+
// Get currency from first result or default
|
|
123
|
+
const currency =
|
|
124
|
+
(prevMonthQuery.data?.data?.[0]?.quote_currency as string) ||
|
|
125
|
+
(yearQuery.data?.data?.[0]?.quote_currency as string) ||
|
|
126
|
+
"EUR";
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
data: {
|
|
130
|
+
previousMonth: {
|
|
131
|
+
label: prevMonthRange.label,
|
|
132
|
+
taxes: prevMonthTaxes,
|
|
133
|
+
total: prevMonthTaxes.reduce((sum, t) => sum + t.amount, 0),
|
|
134
|
+
},
|
|
135
|
+
currentYear: {
|
|
136
|
+
label: yearRange.label,
|
|
137
|
+
taxes: yearTaxes,
|
|
138
|
+
total: yearTaxes.reduce((sum, t) => sum + t.amount, 0),
|
|
139
|
+
},
|
|
140
|
+
currency,
|
|
141
|
+
} as TaxCollectedData,
|
|
142
|
+
isLoading: queries.some((q) => q.isLoading),
|
|
143
|
+
error: queries.find((q) => q.error)?.error,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { TopCustomersChartData, TopCustomersChartProps } from "./top-customers-chart";
|
|
2
|
+
export { TopCustomersChart } from "./top-customers-chart";
|
|
3
|
+
export type { TopCustomersData } from "./use-top-customers";
|
|
4
|
+
export { TOP_CUSTOMERS_CACHE_KEY, useTopCustomersData } from "./use-top-customers";
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Bar, BarChart, XAxis, YAxis } from "recharts";
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/ui/components/ui/card";
|
|
5
|
+
import { type ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "@/ui/components/ui/chart";
|
|
6
|
+
import { createTranslation } from "@/ui/lib/translation";
|
|
7
|
+
import { ChartEmptyState } from "../chart-empty-state";
|
|
8
|
+
import { LoadingCard } from "../loading-card";
|
|
9
|
+
import sl from "./locales/sl";
|
|
10
|
+
import { useTopCustomersData } from "./use-top-customers";
|
|
11
|
+
|
|
12
|
+
const translations = { sl } as const;
|
|
13
|
+
|
|
14
|
+
export type TopCustomersChartData = { name: string; revenue: number }[];
|
|
15
|
+
|
|
16
|
+
type BaseProps = {
|
|
17
|
+
locale?: string;
|
|
18
|
+
t?: (key: string) => string;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type DataProps = BaseProps & {
|
|
23
|
+
data: TopCustomersChartData;
|
|
24
|
+
currency: string;
|
|
25
|
+
entityId?: never;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type TurnkeyProps = BaseProps & {
|
|
29
|
+
entityId: string;
|
|
30
|
+
data?: never;
|
|
31
|
+
currency?: never;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type TopCustomersChartProps = DataProps | TurnkeyProps;
|
|
35
|
+
|
|
36
|
+
const chartConfig = {
|
|
37
|
+
revenue: {
|
|
38
|
+
label: "Revenue",
|
|
39
|
+
color: "var(--chart-1)",
|
|
40
|
+
},
|
|
41
|
+
} satisfies ChartConfig;
|
|
42
|
+
|
|
43
|
+
function formatCurrency(value: number, currency: string, locale?: string): string {
|
|
44
|
+
return new Intl.NumberFormat(locale, {
|
|
45
|
+
style: "currency",
|
|
46
|
+
currency,
|
|
47
|
+
minimumFractionDigits: 0,
|
|
48
|
+
maximumFractionDigits: 0,
|
|
49
|
+
}).format(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function TopCustomersChart(props: TopCustomersChartProps) {
|
|
53
|
+
const { locale, t: externalT, namespace } = props;
|
|
54
|
+
const t = createTranslation({ t: externalT, namespace, locale, translations });
|
|
55
|
+
|
|
56
|
+
// Turnkey mode - fetch own data
|
|
57
|
+
const hookResult = useTopCustomersData("entityId" in props ? props.entityId : undefined);
|
|
58
|
+
|
|
59
|
+
// Determine data source
|
|
60
|
+
const data = "entityId" in props ? hookResult.data : props.data;
|
|
61
|
+
const currency = "entityId" in props ? hookResult.currency : props.currency;
|
|
62
|
+
const isLoading = "entityId" in props ? hookResult.isLoading : false;
|
|
63
|
+
|
|
64
|
+
if (isLoading) {
|
|
65
|
+
return <LoadingCard className="h-full min-h-[280px]" />;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const hasData = data.length > 0;
|
|
69
|
+
|
|
70
|
+
// Placeholder data for empty state
|
|
71
|
+
const placeholderData = [
|
|
72
|
+
{ name: "Customer A", displayName: "Customer A", revenue: 1500 },
|
|
73
|
+
{ name: "Customer B", displayName: "Customer B", revenue: 1200 },
|
|
74
|
+
{ name: "Customer C", displayName: "Customer C", revenue: 900 },
|
|
75
|
+
{ name: "Customer D", displayName: "Customer D", revenue: 600 },
|
|
76
|
+
{ name: "Customer E", displayName: "Customer E", revenue: 300 },
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
// Truncate long names for display
|
|
80
|
+
const chartData = hasData
|
|
81
|
+
? data.map((d) => ({
|
|
82
|
+
...d,
|
|
83
|
+
displayName: d.name.length > 18 ? `${d.name.substring(0, 18)}...` : d.name,
|
|
84
|
+
}))
|
|
85
|
+
: placeholderData;
|
|
86
|
+
|
|
87
|
+
const chartContent = (
|
|
88
|
+
<ChartContainer config={chartConfig} className="h-full min-h-[200px] w-full">
|
|
89
|
+
<BarChart data={chartData} layout="vertical" margin={{ left: 8, right: 12 }}>
|
|
90
|
+
<XAxis
|
|
91
|
+
type="number"
|
|
92
|
+
tickLine={false}
|
|
93
|
+
axisLine={false}
|
|
94
|
+
tickFormatter={(value) => formatCurrency(value, currency, locale)}
|
|
95
|
+
/>
|
|
96
|
+
<YAxis
|
|
97
|
+
type="category"
|
|
98
|
+
dataKey="displayName"
|
|
99
|
+
tickLine={false}
|
|
100
|
+
axisLine={false}
|
|
101
|
+
tickMargin={4}
|
|
102
|
+
width={120}
|
|
103
|
+
style={{ fontSize: "12px" }}
|
|
104
|
+
/>
|
|
105
|
+
<ChartTooltip
|
|
106
|
+
cursor={false}
|
|
107
|
+
content={
|
|
108
|
+
<ChartTooltipContent
|
|
109
|
+
labelFormatter={(_, payload) => payload?.[0]?.payload?.name || ""}
|
|
110
|
+
formatter={(value) => formatCurrency(Number(value), currency, locale)}
|
|
111
|
+
/>
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
<Bar dataKey="revenue" fill="var(--chart-1)" radius={4} />
|
|
115
|
+
</BarChart>
|
|
116
|
+
</ChartContainer>
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Card className="flex h-full flex-col">
|
|
121
|
+
<CardHeader>
|
|
122
|
+
<CardTitle>{t("Top Customers")}</CardTitle>
|
|
123
|
+
<CardDescription>{t("Top 5 customers by revenue")}</CardDescription>
|
|
124
|
+
</CardHeader>
|
|
125
|
+
<CardContent className="flex-1">
|
|
126
|
+
{hasData ? chartContent : <ChartEmptyState label={t("No data available")}>{chartContent}</ChartEmptyState>}
|
|
127
|
+
</CardContent>
|
|
128
|
+
</Card>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Top customers hook using the entity stats API.
|
|
3
|
+
* Server-side aggregation by customer for accurate rankings.
|
|
4
|
+
*/
|
|
5
|
+
import type { StatsQueryDataItem } from "@spaceinvoices/js-sdk";
|
|
6
|
+
import { useQuery } from "@tanstack/react-query";
|
|
7
|
+
import { useSDK } from "@/ui/providers/sdk-provider";
|
|
8
|
+
import { STATS_QUERY_CACHE_KEY } from "../shared/use-stats-query";
|
|
9
|
+
|
|
10
|
+
export const TOP_CUSTOMERS_CACHE_KEY = "dashboard-top-customers";
|
|
11
|
+
|
|
12
|
+
export type TopCustomersData = { name: string; revenue: number }[];
|
|
13
|
+
|
|
14
|
+
export function useTopCustomersData(entityId: string | undefined, limit = 5) {
|
|
15
|
+
const { sdk } = useSDK();
|
|
16
|
+
|
|
17
|
+
const query = useQuery({
|
|
18
|
+
queryKey: [STATS_QUERY_CACHE_KEY, entityId, "top-customers", limit],
|
|
19
|
+
queryFn: async () => {
|
|
20
|
+
if (!entityId || !sdk) throw new Error("Missing entity or SDK");
|
|
21
|
+
return sdk.entityStats.queryEntityStats(
|
|
22
|
+
{
|
|
23
|
+
metrics: [
|
|
24
|
+
{ type: "sum", field: "total_with_tax_converted", alias: "revenue" },
|
|
25
|
+
{ type: "count", alias: "invoice_count" },
|
|
26
|
+
],
|
|
27
|
+
table: "invoices",
|
|
28
|
+
filters: { is_draft: false, voided_at: null },
|
|
29
|
+
group_by: ["customer_name", "quote_currency"], // Include currency for display
|
|
30
|
+
order_by: [{ field: "revenue", direction: "desc" }],
|
|
31
|
+
limit: limit * 2, // Get more results to aggregate across currencies
|
|
32
|
+
},
|
|
33
|
+
{ entity_id: entityId },
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
enabled: !!entityId && !!sdk,
|
|
37
|
+
staleTime: 30_000,
|
|
38
|
+
select: (response) => {
|
|
39
|
+
const data = response.data || [];
|
|
40
|
+
|
|
41
|
+
// Aggregate by customer name (in case of multiple quote_currency rows)
|
|
42
|
+
const customerMap: Record<string, number> = {};
|
|
43
|
+
let currency = "EUR";
|
|
44
|
+
|
|
45
|
+
for (const row of data as StatsQueryDataItem[]) {
|
|
46
|
+
const name = String(row.customer_name || "Unknown");
|
|
47
|
+
customerMap[name] = (customerMap[name] || 0) + (Number(row.revenue) || 0);
|
|
48
|
+
// Get currency from first row with data
|
|
49
|
+
if (row.quote_currency && currency === "EUR") {
|
|
50
|
+
currency = String(row.quote_currency);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Convert to array, sort by revenue, and take top 'limit'
|
|
55
|
+
const customers = Object.entries(customerMap)
|
|
56
|
+
.map(([name, revenue]) => ({ name, revenue }))
|
|
57
|
+
.sort((a, b) => b.revenue - a.revenue)
|
|
58
|
+
.slice(0, limit);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
data: customers,
|
|
62
|
+
currency, // Currency from document data
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
data: query.data?.data || [],
|
|
69
|
+
currency: query.data?.currency || "EUR",
|
|
70
|
+
isLoading: query.isLoading,
|
|
71
|
+
};
|
|
72
|
+
}
|