Add invoice send, status transitions, and live settings/notifications.
Let admins send priced invoices, change order status via allowedTransitions or forced manual jumps, persist notification reads, and save SystemSettings to the API. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,8 @@ import { computed, inject, onMounted, provide, reactive, ref, type InjectionKey
|
||||
import { useRouter } from 'vue-router'
|
||||
import { companiesApi, mapAdminOrder, ordersApi } from '@/services/api'
|
||||
import { ApiError } from '@/services/http'
|
||||
import type { Company, Order, SettlementMethod } from '@/types'
|
||||
import type { Company, Order, RawOrderStatus, SettlementMethod } from '@/types'
|
||||
import { rawStatusLabel } from '@/utils/orderStatus'
|
||||
|
||||
import { useToast } from '@/composables/useToast'
|
||||
|
||||
@@ -93,10 +94,42 @@ export function useOrdersPage() {
|
||||
showDetailModal.value = false
|
||||
}
|
||||
|
||||
function settlementLabel(method: string) {
|
||||
function settlementLabel(method?: string | null) {
|
||||
if (!method) return 'انتخابنشده'
|
||||
return method === 'check' ? 'چکی' : 'نقدی'
|
||||
}
|
||||
|
||||
const statusSaving = ref(false)
|
||||
|
||||
async function changeStatus(payload: {
|
||||
orderId: string
|
||||
status: RawOrderStatus
|
||||
note?: string
|
||||
reason?: string
|
||||
force?: boolean
|
||||
}) {
|
||||
if (statusSaving.value) return null
|
||||
statusSaving.value = true
|
||||
try {
|
||||
const updated = await ordersApi.updateStatus(payload.orderId, {
|
||||
status: payload.status,
|
||||
note: payload.note,
|
||||
reason: payload.reason,
|
||||
force: payload.force,
|
||||
})
|
||||
const mapped = mapAdminOrder(updated) as Order
|
||||
const index = orderList.value.findIndex((o) => o.id === payload.orderId)
|
||||
if (index >= 0) orderList.value[index] = { ...orderList.value[index]!, ...mapped }
|
||||
toast.success(`وضعیت سفارش به «${rawStatusLabel(payload.status)}» تغییر کرد.`)
|
||||
return mapped
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : 'تغییر وضعیت انجام نشد.')
|
||||
return null
|
||||
} finally {
|
||||
statusSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function goPricing(order: Order) {
|
||||
router.push(`/orders/${order.id}/pricing`)
|
||||
}
|
||||
@@ -105,6 +138,10 @@ export function useOrdersPage() {
|
||||
router.push(`/orders/${order.id}/checks`)
|
||||
}
|
||||
|
||||
function goCashReceipt(order: Order) {
|
||||
router.push({ path: '/cash-payments', query: { order: order.orderNumber } })
|
||||
}
|
||||
|
||||
function openAddModal() {
|
||||
Object.assign(form, emptyForm())
|
||||
formError.value = ''
|
||||
@@ -162,8 +199,11 @@ export function useOrdersPage() {
|
||||
closeDetailPanel,
|
||||
closeDetailModal,
|
||||
settlementLabel,
|
||||
changeStatus,
|
||||
statusSaving,
|
||||
goPricing,
|
||||
goChecks,
|
||||
goCashReceipt,
|
||||
openAddModal,
|
||||
closeAddModal,
|
||||
submitAddOrder,
|
||||
|
||||
Reference in New Issue
Block a user