feat: implement reports page with analytical charts and data grids, and add payment status tracking to submissions.
This commit is contained in:
+58
-1
@@ -62,7 +62,7 @@ export async function getMyOrders(creator_id: string) {
|
||||
where: { creator_id },
|
||||
include: {
|
||||
available_items: true,
|
||||
submissions: { select: { id: true } }
|
||||
submissions: { select: { id: true, payment_status: true } }
|
||||
},
|
||||
orderBy: { date: 'desc' }
|
||||
})
|
||||
@@ -222,12 +222,28 @@ export async function updateSubmissionPayment(submission_id: string, bill: numbe
|
||||
})
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Gagal menyimpan tagihan.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateBulkSubmissionPayment(submission_ids: string[], payment_status: string) {
|
||||
try {
|
||||
await prisma.submission.updateMany({
|
||||
where: { id: { in: submission_ids } },
|
||||
data: { payment_status }
|
||||
})
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
return { success: false, error: 'Gagal mengubah status tagihan massal.' }
|
||||
}
|
||||
}
|
||||
|
||||
// === SUBMISSION (PESANAN SAYA) ===
|
||||
export async function getUserSubmission(order_id: string, user_id: string) {
|
||||
return await prisma.submission.findFirst({
|
||||
@@ -300,3 +316,44 @@ export async function submitOrder(data: {
|
||||
return { success: false, error: 'Gagal mengirim pesanan.' }
|
||||
}
|
||||
}
|
||||
|
||||
// === REPORT ACTIONS ===
|
||||
export async function getSubmittorReport(user_id: string, startDate?: Date, endDate?: Date) {
|
||||
return await prisma.submission.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
order: {
|
||||
status: 'CLOSE',
|
||||
...(startDate && endDate ? { date: { gte: startDate, lte: endDate } } : {})
|
||||
}
|
||||
},
|
||||
include: {
|
||||
order: {
|
||||
include: { creator: true }
|
||||
},
|
||||
items: true
|
||||
},
|
||||
orderBy: {
|
||||
order: { date: 'desc' }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function getCreatorReport(creator_id: string, startDate?: Date, endDate?: Date) {
|
||||
return await prisma.order.findMany({
|
||||
where: {
|
||||
creator_id,
|
||||
status: 'CLOSE',
|
||||
...(startDate && endDate ? { date: { gte: startDate, lte: endDate } } : {})
|
||||
},
|
||||
include: {
|
||||
submissions: {
|
||||
include: {
|
||||
user: true,
|
||||
items: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: { date: 'desc' }
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user