@stacksjs/defaults 0.75.489 → 0.75.492
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/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +20 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-search-engine/SKILL.md +14 -0
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
- package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
- package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
- package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
- package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
- package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
- package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
- package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
- package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
- package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
- package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
- package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
- package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
- package/app/Actions/Dashboard/Content/content-list.ts +10 -0
- package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
- package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
- package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
- package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
- package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
- package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
- package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
- package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
- package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
- package/app/Actions/Dashboard/named-search.test.ts +36 -0
- package/app/Actions/Dashboard/named-search.ts +80 -0
- package/app/Models/Request.ts +4 -2
- package/functions/commerce/shippings/dashboard-resource.ts +12 -1
- package/functions/commerce/shippings/delivery-routes.ts +1 -0
- package/functions/commerce/shippings/license-keys.ts +1 -0
- package/functions/dashboard-list.test.ts +146 -1
- package/functions/dashboard-list.ts +216 -1
- package/functions/queue.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +2 -2
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
- package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
<script client>
|
|
2
|
+
import type { PaymentBreakdown } from '../../../../app/Actions/Dashboard/Commerce/commerce-payment-list'
|
|
2
3
|
import type { PaymentRecord, PaymentSummary } from '../../../../app/Actions/Dashboard/Commerce/payment-records'
|
|
3
|
-
import {
|
|
4
|
-
paymentsToCsv,
|
|
5
|
-
summarizePayments,
|
|
6
|
-
} from '../../../../app/Actions/Dashboard/Commerce/payment-records'
|
|
7
4
|
import { dashboardApi } from '../../../../functions/dashboard-api'
|
|
8
5
|
import { pushToast } from '../../../../functions/toasts'
|
|
9
6
|
|
|
10
7
|
interface CommercePaymentsResponse {
|
|
11
8
|
records: PaymentRecord[]
|
|
9
|
+
total: number
|
|
10
|
+
page: number
|
|
11
|
+
perPage: number
|
|
12
|
+
summary: PaymentSummary
|
|
13
|
+
breakdown: PaymentBreakdown
|
|
14
|
+
statuses: string[]
|
|
15
|
+
methods: string[]
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
const emptySummary: PaymentSummary = { total: 0, successful: 0, currencies: [], capturedByCurrency: {}, refundedByCurrency: {}, successRate: 0 }
|
|
14
19
|
const records = state<PaymentRecord[]>([])
|
|
20
|
+
// The server's answer for the current search, filters and range
|
|
21
|
+
// (stacksjs/stacks#3218): it searches, filters, sorts, pages and summarises
|
|
22
|
+
// every payment, where this page used to do all of that with the newest 500.
|
|
23
|
+
const summary = state<PaymentSummary>({ ...emptySummary })
|
|
24
|
+
const breakdown = state<PaymentBreakdown>({ statuses: [], methods: [], currencies: [] })
|
|
25
|
+
const matchingTotal = state(0)
|
|
26
|
+
const page = state(1)
|
|
27
|
+
const perPage = state(25)
|
|
28
|
+
const statusChoices = state<string[]>([])
|
|
29
|
+
const methodChoices = state<string[]>([])
|
|
30
|
+
const appliedSearch = state('')
|
|
31
|
+
const headerSort = state<{ sort: string, direction: string } | null>(null)
|
|
32
|
+
let listRequest = 0
|
|
33
|
+
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
|
15
34
|
const search = state('')
|
|
16
35
|
const statusFilter = state('all')
|
|
17
36
|
const methodFilter = state('all')
|
|
@@ -23,62 +42,55 @@ const detailsRecord = state<PaymentRecord | null>(null)
|
|
|
23
42
|
const refundRecord = state<PaymentRecord | null>(null)
|
|
24
43
|
const refunding = state(false)
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
/** The select's four orders, as the server's sort and direction. */
|
|
46
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: string }> = {
|
|
47
|
+
newest: { sort: 'created', direction: 'desc' },
|
|
48
|
+
oldest: { sort: 'created', direction: 'asc' },
|
|
49
|
+
amount: { sort: 'amount', direction: 'desc' },
|
|
50
|
+
status: { sort: 'status', direction: 'asc' },
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The table's sortable columns, as the server's sort names. */
|
|
54
|
+
const COLUMN_SORTS: Record<string, string> = {
|
|
55
|
+
paymentLabel: 'id',
|
|
56
|
+
billingLabel: 'billing',
|
|
57
|
+
amount: 'amount',
|
|
58
|
+
methodLabel: 'method',
|
|
59
|
+
statusTone: 'status',
|
|
60
|
+
createdAt: 'created',
|
|
29
61
|
}
|
|
30
62
|
|
|
31
63
|
function statuses(): string[] {
|
|
32
|
-
return
|
|
64
|
+
return statusChoices()
|
|
33
65
|
}
|
|
34
66
|
|
|
35
67
|
function methods(): string[] {
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function visibleRecords(): PaymentRecord[] {
|
|
40
|
-
const query = search().trim().toLowerCase()
|
|
41
|
-
const selectedStatus = statusFilter()
|
|
42
|
-
const selectedMethod = methodFilter()
|
|
43
|
-
const days = timeRange() === 'all' ? 0 : Number(timeRange())
|
|
44
|
-
const cutoff = days ? Date.now() - days * 86400000 : 0
|
|
45
|
-
|
|
46
|
-
return [...records()]
|
|
47
|
-
.filter((record) => {
|
|
48
|
-
if (selectedStatus !== 'all' && record.status !== selectedStatus)
|
|
49
|
-
return false
|
|
50
|
-
if (selectedMethod !== 'all' && record.method !== selectedMethod)
|
|
51
|
-
return false
|
|
52
|
-
if (cutoff && timestamp(record.createdAt) < cutoff)
|
|
53
|
-
return false
|
|
54
|
-
return !query || [
|
|
55
|
-
record.id,
|
|
56
|
-
record.referenceNumber,
|
|
57
|
-
record.billingEmail,
|
|
58
|
-
record.transactionId,
|
|
59
|
-
record.paymentProvider,
|
|
60
|
-
record.orderId,
|
|
61
|
-
record.method,
|
|
62
|
-
record.status,
|
|
63
|
-
].some(value => value.toLowerCase().includes(query))
|
|
64
|
-
})
|
|
65
|
-
.sort((left, right) => {
|
|
66
|
-
if (sort() === 'oldest')
|
|
67
|
-
return timestamp(left.createdAt) - timestamp(right.createdAt)
|
|
68
|
-
if (sort() === 'amount')
|
|
69
|
-
return right.amount - left.amount
|
|
70
|
-
if (sort() === 'status')
|
|
71
|
-
return left.status.localeCompare(right.status) || timestamp(right.createdAt) - timestamp(left.createdAt)
|
|
72
|
-
return timestamp(right.createdAt) - timestamp(left.createdAt)
|
|
73
|
-
})
|
|
68
|
+
return methodChoices()
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
/** The search, filters, range and order, as the query the server takes. */
|
|
72
|
+
function filterParams(): URLSearchParams {
|
|
73
|
+
const params = new URLSearchParams()
|
|
74
|
+
const order = headerSort() ?? SELECT_SORTS[sort()] ?? SELECT_SORTS.newest
|
|
75
|
+
params.set('sort', order.sort)
|
|
76
|
+
params.set('direction', order.direction)
|
|
77
|
+
params.set('days', timeRange())
|
|
78
|
+
if (appliedSearch())
|
|
79
|
+
params.set('q', appliedSearch())
|
|
80
|
+
if (statusFilter() !== 'all')
|
|
81
|
+
params.set('status', statusFilter())
|
|
82
|
+
if (methodFilter() !== 'all')
|
|
83
|
+
params.set('method', methodFilter())
|
|
84
|
+
return params
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function matchingLabel(): string {
|
|
88
|
+
const count = matchingTotal()
|
|
89
|
+
return `${count.toLocaleString()} matching ${count === 1 ? 'payment' : 'payments'}`
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
81
|
-
const current =
|
|
93
|
+
const current = summary()
|
|
82
94
|
return [
|
|
83
95
|
{ label: 'Transactions', value: String(current.total), detail: 'In the current view' },
|
|
84
96
|
{ label: 'Successful', value: String(current.successful), detail: 'Captured at least once' },
|
|
@@ -91,32 +103,99 @@ function metricCards(): Array<{ label: string, value: string, detail: string }>
|
|
|
91
103
|
]
|
|
92
104
|
}
|
|
93
105
|
|
|
106
|
+
/** Every matching payment as CSV, built by the server, not just the page shown. */
|
|
94
107
|
function exportHref(): string {
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function exportFilename(): string {
|
|
99
|
-
return `payments-${new Date().toISOString().slice(0, 10)}.csv`
|
|
108
|
+
return `/api/dashboard/commerce/payments/export?${filterParams()}`
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
async function loadPayments(): Promise<void> {
|
|
112
|
+
const request = ++listRequest
|
|
103
113
|
loading.set(true)
|
|
104
114
|
loadError.set('')
|
|
105
115
|
try {
|
|
106
|
-
const
|
|
116
|
+
const params = filterParams()
|
|
117
|
+
params.set('page', String(page()))
|
|
118
|
+
params.set('per_page', String(perPage()))
|
|
119
|
+
const data = await dashboardApi<CommercePaymentsResponse>(`/api/dashboard/commerce/payments?${params}`)
|
|
120
|
+
// Only the newest request lands.
|
|
121
|
+
if (request !== listRequest)
|
|
122
|
+
return
|
|
107
123
|
records.set(Array.isArray(data.records) ? data.records : [])
|
|
124
|
+
summary.set(data.summary ?? { ...emptySummary })
|
|
125
|
+
breakdown.set(data.breakdown ?? { statuses: [], methods: [], currencies: [] })
|
|
126
|
+
matchingTotal.set(Number(data.total) || 0)
|
|
127
|
+
page.set(Number(data.page) || 1)
|
|
128
|
+
statusChoices.set(Array.isArray(data.statuses) ? data.statuses : [])
|
|
129
|
+
methodChoices.set(Array.isArray(data.methods) ? data.methods : [])
|
|
108
130
|
}
|
|
109
131
|
catch (error) {
|
|
132
|
+
if (request !== listRequest)
|
|
133
|
+
return
|
|
110
134
|
loadError.set('Payment records could not be loaded.')
|
|
111
135
|
pushToast('error', 'Could not load payments', {
|
|
112
136
|
detail: error instanceof Error ? error.message : String(error),
|
|
113
137
|
})
|
|
114
138
|
}
|
|
115
139
|
finally {
|
|
116
|
-
|
|
140
|
+
if (request === listRequest)
|
|
141
|
+
loading.set(false)
|
|
117
142
|
}
|
|
118
143
|
}
|
|
119
144
|
|
|
145
|
+
function eventValue<T>(value: T | CustomEvent<T>): T {
|
|
146
|
+
return value instanceof CustomEvent ? value.detail : value
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function changePage(value: number | CustomEvent<number>): void {
|
|
150
|
+
page.set(Number(eventValue(value)) || 1)
|
|
151
|
+
void loadPayments()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function changePageSize(value: number | CustomEvent<number>): void {
|
|
155
|
+
perPage.set(Number(eventValue(value)) || 25)
|
|
156
|
+
page.set(1)
|
|
157
|
+
void loadPayments()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function changeColumnSort(value: { key: string, direction: string } | CustomEvent<{ key: string, direction: string }>): void {
|
|
161
|
+
const column = eventValue(value)
|
|
162
|
+
const serverSort = COLUMN_SORTS[column.key]
|
|
163
|
+
headerSort.set(serverSort ? { sort: serverSort, direction: column.direction === 'asc' ? 'asc' : 'desc' } : null)
|
|
164
|
+
page.set(1)
|
|
165
|
+
void loadPayments()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// The filters, range and select ask the server for page 1 when they change, and
|
|
169
|
+
// the search once typing pauses. A select change hands the order back from a
|
|
170
|
+
// column header.
|
|
171
|
+
let shownFilters = JSON.stringify([statusFilter(), methodFilter(), timeRange(), sort()])
|
|
172
|
+
effect(() => {
|
|
173
|
+
const filters = JSON.stringify([statusFilter(), methodFilter(), timeRange(), sort()])
|
|
174
|
+
if (filters === shownFilters)
|
|
175
|
+
return
|
|
176
|
+
const sortChanged = JSON.parse(shownFilters)[3] !== sort()
|
|
177
|
+
shownFilters = filters
|
|
178
|
+
if (sortChanged)
|
|
179
|
+
headerSort.set(null)
|
|
180
|
+
page.set(1)
|
|
181
|
+
void loadPayments()
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
let shownSearch = search().trim()
|
|
185
|
+
effect(() => {
|
|
186
|
+
const term = search().trim()
|
|
187
|
+
if (term === shownSearch)
|
|
188
|
+
return
|
|
189
|
+
shownSearch = term
|
|
190
|
+
if (searchTimer)
|
|
191
|
+
clearTimeout(searchTimer)
|
|
192
|
+
searchTimer = setTimeout(() => {
|
|
193
|
+
appliedSearch.set(term)
|
|
194
|
+
page.set(1)
|
|
195
|
+
void loadPayments()
|
|
196
|
+
}, 250)
|
|
197
|
+
})
|
|
198
|
+
|
|
120
199
|
function openDetails(record: PaymentRecord): void {
|
|
121
200
|
detailsRecord.set(record)
|
|
122
201
|
}
|
|
@@ -173,7 +252,7 @@ onMount(() => {
|
|
|
173
252
|
<PageHeader title="Payments" description="Inspect native Payment records, export the current view, and record confirmed refunds.">
|
|
174
253
|
<div class="flex flex-wrap gap-2">
|
|
175
254
|
<Button variant="secondary" :loading="loading()" @click="loadPayments"><span :if="!loading()" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
176
|
-
<Button tag="a" :href="exportHref()"
|
|
255
|
+
<Button tag="a" :href="exportHref()" download><span class="h-4 w-4 i-hugeicons-download-04"></span>Export current view</Button>
|
|
177
256
|
</div>
|
|
178
257
|
</PageHeader>
|
|
179
258
|
|
|
@@ -181,7 +260,7 @@ onMount(() => {
|
|
|
181
260
|
|
|
182
261
|
<MetricCards label="Payment metrics" columns="grid-cols-2 lg:grid-cols-4" :items="metricCards()" />
|
|
183
262
|
|
|
184
|
-
<CommercePaymentsBreakdown :
|
|
263
|
+
<CommercePaymentsBreakdown :breakdown="breakdown()" />
|
|
185
264
|
|
|
186
265
|
<section class="space-y-3">
|
|
187
266
|
<div class="grid gap-3 grid-cols-1 sm:grid-cols-2 xl:grid-cols-5">
|
|
@@ -196,11 +275,11 @@ onMount(() => {
|
|
|
196
275
|
</div>
|
|
197
276
|
|
|
198
277
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
199
|
-
<p class="text-gray-500 text-sm dark:text-neutral-400">{{
|
|
278
|
+
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
200
279
|
<label class="flex gap-2 items-center text-gray-500 text-sm dark:text-neutral-400">Sort<select x-model="sort" class="px-3 py-1.5 text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700"><option value="newest">Newest</option><option value="oldest">Oldest</option><option value="amount">Highest amount</option><option value="status">Status</option></select></label>
|
|
201
280
|
</div>
|
|
202
281
|
|
|
203
|
-
<CommercePaymentsTable :sort-reset-key="sort()" :records="
|
|
282
|
+
<CommercePaymentsTable :sort-reset-key="sort()" :records="records()" :total="matchingTotal()" :current-page="page()" :per-page="perPage()" :loading="loading()" @view="openDetails" @page-change="changePage" @page-size-change="changePageSize" @sort="changeColumnSort" />
|
|
204
283
|
</section>
|
|
205
284
|
</div>
|
|
206
285
|
|
|
@@ -8,7 +8,13 @@ const records = useReactiveProp('records', [] as PaymentRecord[])
|
|
|
8
8
|
const loading = useReactiveProp('loading', false)
|
|
9
9
|
/** The parent's sort select; a change hands the order back from a header sort. */
|
|
10
10
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
11
|
-
|
|
11
|
+
// One page the server chose (stacksjs/stacks#3218): it searches, filters, sorts
|
|
12
|
+
// and pages the payments, so this shows them as given and hands paging and
|
|
13
|
+
// column sorting back to the parent.
|
|
14
|
+
const total = useReactiveProp('total', 0)
|
|
15
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
16
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
17
|
+
const emit = defineEmits(['view', 'page-change', 'page-size-change', 'sort'])
|
|
12
18
|
|
|
13
19
|
/** `partiallyRefunded` and `bank_transfer` as words, each capitalized. */
|
|
14
20
|
function label(value: string): string {
|
|
@@ -82,6 +88,18 @@ const rows = derived(() => records().map(record => ({
|
|
|
82
88
|
function handleRowAction(payload: { action: string, row: PaymentRecord }): void {
|
|
83
89
|
emit(payload.action, payload.row)
|
|
84
90
|
}
|
|
91
|
+
|
|
92
|
+
function changePage(page: number): void {
|
|
93
|
+
emit('page-change', page)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function changePageSize(size: number): void {
|
|
97
|
+
emit('page-size-change', size)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
101
|
+
emit('sort', sort)
|
|
102
|
+
}
|
|
85
103
|
</script>
|
|
86
104
|
|
|
87
105
|
<Table
|
|
@@ -92,10 +110,17 @@ function handleRowAction(payload: { action: string, row: PaymentRecord }): void
|
|
|
92
110
|
:row-actions="ROW_ACTIONS"
|
|
93
111
|
action-label-key="id"
|
|
94
112
|
paginated
|
|
95
|
-
|
|
113
|
+
manual-pagination
|
|
114
|
+
manual-sort
|
|
115
|
+
:total="total()"
|
|
116
|
+
:current-page="currentPage()"
|
|
117
|
+
:page-size="perPage()"
|
|
96
118
|
empty-title="No payments found"
|
|
97
119
|
empty-description="Adjust the filters to inspect another part of the native ledger."
|
|
98
120
|
@row-action="handleRowAction"
|
|
121
|
+
@page-change="changePage"
|
|
122
|
+
@page-size-change="changePageSize"
|
|
123
|
+
@sort="changeSort"
|
|
99
124
|
>
|
|
100
125
|
<template #cell="{ row }">
|
|
101
126
|
<p class="font-medium text-gray-900 text-sm dark:text-white" x-text="row.amountLabel"></p>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@import('../UI/Pagination')
|
|
2
|
+
|
|
1
3
|
<script client>
|
|
2
4
|
import type { CommercePosProduct } from '../../../../app/Actions/Dashboard/Commerce/commerce-pos'
|
|
3
5
|
import type { ProductOption } from '../../../../app/Actions/Dashboard/Commerce/commerce-product-records'
|
|
@@ -10,7 +12,18 @@ const category = useReactiveProp('category', 'all')
|
|
|
10
12
|
const availability = useReactiveProp('availability', 'sellable')
|
|
11
13
|
const currency = useReactiveProp('currency', 'USD')
|
|
12
14
|
const loading = useReactiveProp('loading', false)
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The server searches and pages the catalogue (stacksjs/stacks#3218): how
|
|
17
|
+
* many products match, the page shown and its size.
|
|
18
|
+
*/
|
|
19
|
+
const total = useReactiveProp('total', 0)
|
|
20
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
21
|
+
const perPage = useReactiveProp('perPage', 50)
|
|
22
|
+
const emit = defineEmits(['search', 'category', 'availability', 'add', 'page'])
|
|
23
|
+
|
|
24
|
+
function changePage(page: number): void {
|
|
25
|
+
emit('page', page)
|
|
26
|
+
}
|
|
14
27
|
|
|
15
28
|
function initials(name: string): string {
|
|
16
29
|
return name.split(/\s+/).filter(Boolean).slice(0, 2).map(part => part[0]?.toUpperCase() || '').join('') || 'PR'
|
|
@@ -78,4 +91,7 @@ function sellable(product: CommercePosProduct): boolean {
|
|
|
78
91
|
</article>
|
|
79
92
|
</template>
|
|
80
93
|
</div>
|
|
94
|
+
<div :if="!loading() && total() > 0" class="mt-4">
|
|
95
|
+
<Pagination :currentPage="currentPage()" :totalItems="total()" :itemsPerPage="perPage()" showTotalItems @page="changePage" />
|
|
96
|
+
</div>
|
|
81
97
|
</section>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script client>
|
|
2
|
-
import type {
|
|
2
|
+
import type { CustomerChoice } from '../../../../app/Actions/Dashboard/Commerce/commerce-choice-records'
|
|
3
|
+
import { dashboardApi } from '../../../../functions/dashboard-api'
|
|
3
4
|
import { formatCurrency } from '@stacksjs/commerce/money'
|
|
4
5
|
|
|
5
6
|
interface PosPaymentMethod {
|
|
@@ -8,7 +9,6 @@ interface PosPaymentMethod {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const open = useReactiveProp('open', false)
|
|
11
|
-
const customers = useReactiveProp('customers', [] as CommercePosCustomer[])
|
|
12
12
|
const paymentMethods = useReactiveProp('paymentMethods', [] as PosPaymentMethod[])
|
|
13
13
|
const currency = useReactiveProp('currency', 'USD')
|
|
14
14
|
const subtotal = useReactiveProp('subtotal', 0)
|
|
@@ -24,6 +24,48 @@ const paymentMethod = state('cash')
|
|
|
24
24
|
const specialInstructions = state('')
|
|
25
25
|
let hydrated = false
|
|
26
26
|
|
|
27
|
+
// The customers are a server search over Active customers
|
|
28
|
+
// (stacksjs/stacks#3218): this used to be handed the first 500 by name, so a
|
|
29
|
+
// sale could not be given a customer past the 500th.
|
|
30
|
+
const customers = state<CustomerChoice[]>([])
|
|
31
|
+
const customerMatches = state(0)
|
|
32
|
+
const customerQuery = state('')
|
|
33
|
+
let customerRequest = 0
|
|
34
|
+
let customerTimer: ReturnType<typeof setTimeout> | null = null
|
|
35
|
+
|
|
36
|
+
async function loadCustomers(term: string): Promise<void> {
|
|
37
|
+
const request = ++customerRequest
|
|
38
|
+
const params = new URLSearchParams({ active: '1' })
|
|
39
|
+
if (term)
|
|
40
|
+
params.set('q', term)
|
|
41
|
+
let found: CustomerChoice[] = []
|
|
42
|
+
let count = 0
|
|
43
|
+
try {
|
|
44
|
+
const data = await dashboardApi<{ choices?: CustomerChoice[], total?: number }>(`/api/dashboard/commerce/customer-choices?${params}`)
|
|
45
|
+
found = Array.isArray(data.choices) ? data.choices : []
|
|
46
|
+
count = Number(data.total) || found.length
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Soft-fail: a guest sale needs no customer.
|
|
50
|
+
}
|
|
51
|
+
if (request !== customerRequest)
|
|
52
|
+
return
|
|
53
|
+
customers.set(found)
|
|
54
|
+
customerMatches.set(count)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function searchCustomersSoon(): void {
|
|
58
|
+
if (customerTimer)
|
|
59
|
+
clearTimeout(customerTimer)
|
|
60
|
+
customerTimer = setTimeout(() => { void loadCustomers(customerQuery().trim()) }, 250)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function moreCustomersLabel(): string {
|
|
64
|
+
const shown = customers().length
|
|
65
|
+
const total = customerMatches()
|
|
66
|
+
return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching customers. Search to narrow it down.` : ''
|
|
67
|
+
}
|
|
68
|
+
|
|
27
69
|
effect(() => {
|
|
28
70
|
if (!open()) {
|
|
29
71
|
hydrated = false
|
|
@@ -33,6 +75,8 @@ effect(() => {
|
|
|
33
75
|
return
|
|
34
76
|
hydrated = true
|
|
35
77
|
customerId.set('')
|
|
78
|
+
customerQuery.set('')
|
|
79
|
+
void loadCustomers('')
|
|
36
80
|
orderType.set('TAKEOUT')
|
|
37
81
|
paymentMethod.set(paymentMethods()[0]?.id || 'cash')
|
|
38
82
|
specialInstructions.set('')
|
|
@@ -63,7 +107,7 @@ function submit(): void {
|
|
|
63
107
|
<div :if="error()" class="mb-4 p-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/30 border border-red-200 rounded-lg dark:border-red-900">{{ error() }}</div>
|
|
64
108
|
|
|
65
109
|
<div class="grid gap-4 grid-cols-1 sm:grid-cols-2">
|
|
66
|
-
<
|
|
110
|
+
<div class="sm:col-span-2"><label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Customer</span><input x-model="customerQuery" @input="searchCustomersSoon()" type="search" name="customer_search" aria-label="Search customers by name, email or phone" placeholder="Search by name, email or phone" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label><select x-model="customerId" aria-label="Customer" class="mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Guest sale</option><template :for="customer in customers()" :key="customer.id"><option :value="customer.id" :selected="customer.id === customerId()">{{ customer.label }}{{ customer.email ? ' · ' + customer.email : '' }}</option></template></select><p :if="moreCustomersLabel()" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreCustomersLabel()"></p></div>
|
|
67
111
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Order type</span><select x-model="orderType" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="TAKEOUT">Takeout</option><option value="DINE_IN">Dine in</option></select></label>
|
|
68
112
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Payment</span><select x-model="paymentMethod" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><template :for="method in paymentMethods()" :key="method.id"><option :value="method.id">{{ method.label }}</option></template></select></label>
|
|
69
113
|
<label class="block sm:col-span-2"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Order instructions</span><textarea x-model="specialInstructions" rows="3" maxlength="1000" placeholder="Optional instructions for the whole sale" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"></textarea></label>
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
<script client>
|
|
2
|
-
import type {
|
|
3
|
-
CommercePosCustomer,
|
|
4
|
-
CommercePosProduct,
|
|
5
|
-
} from '../../../../app/Actions/Dashboard/Commerce/commerce-pos'
|
|
2
|
+
import type { CommercePosProduct } from '../../../../app/Actions/Dashboard/Commerce/commerce-pos'
|
|
6
3
|
import type { ProductOption } from '../../../../app/Actions/Dashboard/Commerce/commerce-product-records'
|
|
7
4
|
import { dashboardApi } from '../../../../functions/dashboard-api'
|
|
5
|
+
import { useServerList } from '../../../../functions/dashboard-list'
|
|
8
6
|
import { pushToast } from '../../../../functions/toasts'
|
|
9
7
|
import { formatCurrency } from '@stacksjs/commerce/money'
|
|
10
8
|
|
|
@@ -20,9 +18,7 @@ interface PosSummary {
|
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
interface PosIndexResponse {
|
|
23
|
-
products: CommercePosProduct[]
|
|
24
21
|
categories: ProductOption[]
|
|
25
|
-
customers: CommercePosCustomer[]
|
|
26
22
|
taxRate: number
|
|
27
23
|
defaultCurrency: string
|
|
28
24
|
paymentMethods: PosPaymentMethod[]
|
|
@@ -72,18 +68,15 @@ interface PosCheckoutResponse {
|
|
|
72
68
|
receipt: PosReceipt
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
const products = state<CommercePosProduct[]>([])
|
|
76
71
|
const categories = state<ProductOption[]>([])
|
|
77
|
-
const customers = state<CommercePosCustomer[]>([])
|
|
78
72
|
const paymentMethods = state<PosPaymentMethod[]>([])
|
|
79
73
|
const summary = state<PosSummary>({ products: 0, sellable: 0, inventory: 0 })
|
|
80
74
|
const taxRate = state(0)
|
|
81
75
|
const defaultCurrency = state('USD')
|
|
82
|
-
const search = state('')
|
|
83
76
|
const categoryFilter = state('all')
|
|
84
77
|
const availabilityFilter = state('sellable')
|
|
85
78
|
const cartLines = state<PosCartLine[]>([])
|
|
86
|
-
const
|
|
79
|
+
const settingsLoading = state(true)
|
|
87
80
|
const loadError = state('')
|
|
88
81
|
const checkoutOpen = state(false)
|
|
89
82
|
const checkoutBusy = state(false)
|
|
@@ -118,25 +111,31 @@ function formatMoney(value: number): string {
|
|
|
118
111
|
return formatCurrency(value, defaultCurrency())
|
|
119
112
|
}
|
|
120
113
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
})
|
|
114
|
+
// The catalogue is the server's, searched and paged (stacksjs/stacks#3218):
|
|
115
|
+
// this screen used to read the first 500 products by name and filter them
|
|
116
|
+
// here, so a later product could not be rung up.
|
|
117
|
+
const {
|
|
118
|
+
records: products,
|
|
119
|
+
total: matchingProducts,
|
|
120
|
+
page: catalogPage,
|
|
121
|
+
perPage: catalogPerPage,
|
|
122
|
+
search,
|
|
123
|
+
loading: catalogLoading,
|
|
124
|
+
load: loadCatalog,
|
|
125
|
+
changePage: changeCatalogPage,
|
|
126
|
+
} = useServerList<CommercePosProduct>({
|
|
127
|
+
fetch: params => dashboardApi<{ records: CommercePosProduct[], total: number, page: number }>(`/api/dashboard/commerce/pos/products?${params}`),
|
|
128
|
+
defaultSort: { sort: 'name', direction: 'asc' },
|
|
129
|
+
filters: () => ({
|
|
130
|
+
category: categoryFilter(),
|
|
131
|
+
availability: availabilityFilter() === 'unavailable' ? 'unsellable' : availabilityFilter(),
|
|
132
|
+
}),
|
|
133
|
+
perPage: 50,
|
|
134
|
+
onError: error => pushToast('error', 'Could not load products', { detail: error instanceof Error ? error.message : String(error) }),
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
function loading(): boolean {
|
|
138
|
+
return settingsLoading() || catalogLoading()
|
|
140
139
|
}
|
|
141
140
|
|
|
142
141
|
function metricCards(): Array<{ label: string, value: string, detail: string }> {
|
|
@@ -148,32 +147,43 @@ function metricCards(): Array<{ label: string, value: string, detail: string }>
|
|
|
148
147
|
]
|
|
149
148
|
}
|
|
150
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Bring the cart's lines up to date with exactly the products they hold, as
|
|
152
|
+
* they are now: a new price or stock level, or gone when a product is no
|
|
153
|
+
* longer sellable. The catalogue page on screen may not include them.
|
|
154
|
+
*/
|
|
155
|
+
async function refreshCart(): Promise<void> {
|
|
156
|
+
const ids = cartLines().map(line => line.productId)
|
|
157
|
+
if (ids.length === 0)
|
|
158
|
+
return
|
|
159
|
+
const data = await dashboardApi<{ records?: CommercePosProduct[] }>(`/api/dashboard/commerce/pos/products?ids=${ids.join(',')}`)
|
|
160
|
+
const currentProducts = new Map((data.records ?? []).map(product => [product.id, product]))
|
|
161
|
+
cartLines.set(cartLines().flatMap((line) => {
|
|
162
|
+
const product = currentProducts.get(line.productId)
|
|
163
|
+
if (!product || !product.isAvailable || product.inventoryCount <= 0)
|
|
164
|
+
return []
|
|
165
|
+
return [{
|
|
166
|
+
...line,
|
|
167
|
+
name: product.name,
|
|
168
|
+
unitPrice: product.price,
|
|
169
|
+
inventoryCount: product.inventoryCount,
|
|
170
|
+
quantity: Math.min(line.quantity, product.inventoryCount),
|
|
171
|
+
}]
|
|
172
|
+
}))
|
|
173
|
+
}
|
|
174
|
+
|
|
151
175
|
async function loadPos(): Promise<void> {
|
|
152
|
-
|
|
176
|
+
settingsLoading.set(true)
|
|
153
177
|
loadError.set('')
|
|
178
|
+
void loadCatalog()
|
|
154
179
|
try {
|
|
155
180
|
const data = await dashboardApi<PosIndexResponse>('/api/dashboard/commerce/pos')
|
|
156
|
-
products.set(Array.isArray(data.products) ? data.products : [])
|
|
157
181
|
categories.set(Array.isArray(data.categories) ? data.categories : [])
|
|
158
|
-
customers.set(Array.isArray(data.customers) ? data.customers : [])
|
|
159
182
|
paymentMethods.set(Array.isArray(data.paymentMethods) ? data.paymentMethods : [])
|
|
160
183
|
taxRate.set(Number(data.taxRate) || 0)
|
|
161
184
|
defaultCurrency.set(data.defaultCurrency || 'USD')
|
|
162
185
|
summary.set(data.summary ?? { products: 0, sellable: 0, inventory: 0 })
|
|
163
|
-
|
|
164
|
-
const currentProducts = new Map(products().map(product => [product.id, product]))
|
|
165
|
-
cartLines.set(cartLines().flatMap((line) => {
|
|
166
|
-
const product = currentProducts.get(line.productId)
|
|
167
|
-
if (!product || !product.isAvailable || product.inventoryCount <= 0)
|
|
168
|
-
return []
|
|
169
|
-
return [{
|
|
170
|
-
...line,
|
|
171
|
-
name: product.name,
|
|
172
|
-
unitPrice: product.price,
|
|
173
|
-
inventoryCount: product.inventoryCount,
|
|
174
|
-
quantity: Math.min(line.quantity, product.inventoryCount),
|
|
175
|
-
}]
|
|
176
|
-
}))
|
|
186
|
+
await refreshCart()
|
|
177
187
|
}
|
|
178
188
|
catch (error) {
|
|
179
189
|
loadError.set('Point of sale data could not be loaded.')
|
|
@@ -182,7 +192,7 @@ async function loadPos(): Promise<void> {
|
|
|
182
192
|
})
|
|
183
193
|
}
|
|
184
194
|
finally {
|
|
185
|
-
|
|
195
|
+
settingsLoading.set(false)
|
|
186
196
|
}
|
|
187
197
|
}
|
|
188
198
|
|
|
@@ -323,10 +333,10 @@ onMount(() => {
|
|
|
323
333
|
<MetricCards label="Point of sale metrics" columns="grid-cols-2 xl:grid-cols-4" :items="metricCards()" />
|
|
324
334
|
|
|
325
335
|
<div class="grid gap-6 grid-cols-1 items-start lg:grid-cols-[minmax(0,1fr)_20rem]">
|
|
326
|
-
<CommercePosCatalog :products="
|
|
336
|
+
<CommercePosCatalog :products="products()" :categories="categories()" :search="search()" :category="categoryFilter()" :availability="availabilityFilter()" :currency="defaultCurrency()" :loading="catalogLoading()" :total="matchingProducts()" :current-page="catalogPage()" :per-page="catalogPerPage()" @search="search.set($event)" @category="categoryFilter.set($event)" @availability="availabilityFilter.set($event)" @add="addProduct" @page="changeCatalogPage" />
|
|
327
337
|
<CommercePosCart :lines="cartLines()" :currency="defaultCurrency()" :subtotal="subtotal()" :tax-rate="taxRate()" :tax-amount="taxAmount()" :total-amount="totalAmount()" @increase="increaseLine" @decrease="decreaseLine" @remove="removeLine" @instructions="updateInstructions" @clear="clearCart()" @checkout="openCheckout()" />
|
|
328
338
|
</div>
|
|
329
339
|
</div>
|
|
330
340
|
|
|
331
|
-
<CommercePosCheckoutDialog :open="checkoutOpen()" :
|
|
341
|
+
<CommercePosCheckoutDialog :open="checkoutOpen()" :payment-methods="paymentMethods()" :currency="defaultCurrency()" :subtotal="subtotal()" :tax-amount="taxAmount()" :total-amount="totalAmount()" :unit-count="cartUnits()" :busy="checkoutBusy()" :error="checkoutError()" @submit="completeCheckout" @close="closeCheckout()" />
|
|
332
342
|
<CommercePosReceiptDialog :open="receiptOpen()" :receipt="receipt()" @close="closeReceipt()" />
|