505 lines
21 KiB
TypeScript
505 lines
21 KiB
TypeScript
import { ref, computed } from 'vue'
|
||
import * as XLSX from 'xlsx'
|
||
|
||
export type AttendanceStatus = 'present' | 'absent' | 'late' | 'excused'
|
||
|
||
export interface Student {
|
||
id: string
|
||
name: string
|
||
code: string
|
||
avatar?: string
|
||
}
|
||
|
||
export interface ClassItem {
|
||
id: string
|
||
title: string
|
||
code: string
|
||
teacherId: string
|
||
teacherName: string
|
||
days: string[]
|
||
time: string
|
||
startTime: string // مثلا "08:00"
|
||
endTime: string // مثلا "09:30"
|
||
room: string
|
||
studentCount: number
|
||
studentIds: string[]
|
||
isOngoingToday?: boolean
|
||
currentSessionTopic?: string
|
||
}
|
||
|
||
export interface AttendanceRecord {
|
||
id: string
|
||
classId: string
|
||
studentId: string
|
||
studentName: string
|
||
studentCode: string
|
||
date: string // تاریخ شمسی
|
||
status: AttendanceStatus
|
||
delayMinutes: number
|
||
delayReason?: string
|
||
recordedAt?: string
|
||
}
|
||
|
||
export interface StudentClassReport {
|
||
classId: string
|
||
className: string
|
||
teacherName: string
|
||
totalSessions: number
|
||
absentCount: number
|
||
lateCount: number
|
||
excusedCount: number
|
||
presentCount: number
|
||
isDropped: boolean // آیا به دلیل غیبت بیش از ۳ جلسه حذف شده
|
||
status: 'normal' | 'warning' | 'dropped' // وضعیت
|
||
sessions: {
|
||
date: string
|
||
sessionNumber: number
|
||
status: AttendanceStatus
|
||
delayMinutes?: number
|
||
reason?: string
|
||
}[]
|
||
}
|
||
|
||
// لیست طلاب حوزه
|
||
const mockStudentsList: Student[] = [
|
||
{ id: 's-101', name: 'محمدصادق حسینی', code: '۱۴۰۱۰۱۲۳' },
|
||
{ id: 's-102', name: 'علیرضا موسوینژاد', code: '۱۴۰۱۰۱۲۴' },
|
||
{ id: 's-103', name: 'امیرحسین رضایی', code: '۱۴۰۱۰۱۲۵' },
|
||
{ id: 's-104', name: 'مهدی تقوی', code: '۱۴۰۱۰۱۲۶' },
|
||
{ id: 's-105', name: 'حسین شمسآبادی', code: '۱۴۰۱۰۱۲۷' },
|
||
{ id: 's-106', name: 'سید علی فاطمی', code: '۱۴۰۱۰۱۲۸' },
|
||
{ id: 's-107', name: 'جعفر ابراهیمی', code: '۱۴۰۱۰۱۲۹' },
|
||
{ id: 's-108', name: 'رضا کریمیان', code: '۱۴۰۱۰۱۳۰' },
|
||
]
|
||
|
||
// اساتید حوزه
|
||
export const mockTeachersList = [
|
||
{ id: 't-201', name: 'حجتالاسلام والمسلمین استاد رفیعی' },
|
||
{ id: 't-202', name: 'آیتالله موسوی تهرانی' },
|
||
{ id: 't-203', name: 'استاد حسینی قمی' },
|
||
{ id: 't-204', name: 'حجتالاسلام والمسلمین استاد فرحزاد' },
|
||
]
|
||
|
||
// لیست کلاسهای تعریفشده
|
||
const initialClasses: ClassItem[] = [
|
||
{
|
||
id: 'c-1',
|
||
title: 'مکاسب محرمه (شیخ انصاری)',
|
||
code: 'FIQH-401',
|
||
teacherId: 't-201',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد رفیعی',
|
||
days: ['شنبه', 'دوشنبه', 'چهارشنبه'],
|
||
time: '۰۸:۰۰ الی ۰۹:۳۰',
|
||
startTime: '08:00',
|
||
endTime: '09:30',
|
||
room: 'مدرس علامه طباطبایی (ره)',
|
||
studentCount: 8,
|
||
studentIds: ['s-101', 's-102', 's-103', 's-104', 's-105', 's-106', 's-107', 's-108'],
|
||
isOngoingToday: true,
|
||
currentSessionTopic: 'مسئله بیع عذره و اعیان نجسه'
|
||
},
|
||
{
|
||
id: 'c-2',
|
||
title: 'کفایة الاصول (آخوند خراسانی)',
|
||
code: 'USUL-402',
|
||
teacherId: 't-201',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد رفیعی',
|
||
days: ['یکشنبه', 'سهشنبه'],
|
||
time: '۱۰:۰۰ الی ۱۱:۳۰',
|
||
startTime: '10:00',
|
||
endTime: '11:30',
|
||
room: 'مدرس شهید مطهری',
|
||
studentCount: 7,
|
||
studentIds: ['s-101', 's-102', 's-103', 's-104', 's-106', 's-107', 's-108'],
|
||
isOngoingToday: true,
|
||
currentSessionTopic: 'مبحث مشتق و ادوار آن'
|
||
},
|
||
{
|
||
id: 'c-3',
|
||
title: 'تفسیر ترتیبی قرآن کریم',
|
||
code: 'TAFS-301',
|
||
teacherId: 't-202',
|
||
teacherName: 'آیتالله موسوی تهرانی',
|
||
days: ['شنبه', 'چهارشنبه'],
|
||
time: '۱۱:۴۵ الی ۱۲:۴۵',
|
||
startTime: '11:45',
|
||
endTime: '12:45',
|
||
room: 'شبستان امام صادق (ع)',
|
||
studentCount: 8,
|
||
studentIds: ['s-101', 's-102', 's-103', 's-104', 's-105', 's-106', 's-107', 's-108'],
|
||
isOngoingToday: true,
|
||
currentSessionTopic: 'آیات ولایت و هدایت سوره مائده'
|
||
},
|
||
{
|
||
id: 'c-4',
|
||
title: 'فن خطابه و مهارتهای تبلیغی',
|
||
code: 'KHTB-201',
|
||
teacherId: 't-204',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد فرحزاد',
|
||
days: ['دوشنبه'],
|
||
time: '۱۵:۰۰ الی ۱۶:۳۰',
|
||
startTime: '15:00',
|
||
endTime: '16:30',
|
||
room: 'سالن همایشهای بینالمللی حوزه',
|
||
studentCount: 6,
|
||
studentIds: ['s-101', 's-103', 's-104', 's-105', 's-106', 's-108'],
|
||
isOngoingToday: false,
|
||
currentSessionTopic: 'اصول جذب مخاطب جوان'
|
||
}
|
||
]
|
||
|
||
// سوابق حضور و غیاب امروز (قابل تغییر)
|
||
const initialAttendanceRecords: AttendanceRecord[] = [
|
||
// کلاس ۱ امروز
|
||
{ id: 'att-1', classId: 'c-1', studentId: 's-101', studentName: 'محمدصادق حسینی', studentCode: '۱۴۰۱۰۱۲۳', date: '۱۴۰۵/۰۸/۱۴', status: 'late', delayMinutes: 15, delayReason: 'مشکل حملونقل و ترافیک بینشهری', recordedAt: '۰۸:۱۵' },
|
||
{ id: 'att-2', classId: 'c-1', studentId: 's-102', studentName: 'علیرضا موسوینژاد', studentCode: '۱۴۰۱۰۱۲۴', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۷:۵۵' },
|
||
{ id: 'att-3', classId: 'c-1', studentId: 's-103', studentName: 'امیرحسین رضایی', studentCode: '۱۴۰۱۰۱۲۵', date: '۱۴۰۵/۰۸/۱۴', status: 'absent', delayMinutes: 0 },
|
||
{ id: 'att-4', classId: 'c-1', studentId: 's-104', studentName: 'مهدی تقوی', studentCode: '۱۴۰۱۰۱۲۶', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۸:۰۲' },
|
||
{ id: 'att-5', classId: 'c-1', studentId: 's-105', studentName: 'حسین شمسآبادی', studentCode: '۱۴۰۱۰۱۲۷', date: '۱۴۰۵/۰۸/۱۴', status: 'excused', delayMinutes: 0, delayReason: 'گواهی پزشکی ارائه شده' },
|
||
{ id: 'att-6', classId: 'c-1', studentId: 's-106', studentName: 'سید علی فاطمی', studentCode: '۱۴۰۱۰۱۲۸', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۷:۵۸' },
|
||
{ id: 'att-7', classId: 'c-1', studentId: 's-107', studentName: 'جعفر ابراهیمی', studentCode: '۱۴۰۱۰۱۲۹', date: '۱۴۰۵/۰۸/۱۴', status: 'absent', delayMinutes: 0 },
|
||
{ id: 'att-8', classId: 'c-1', studentId: 's-108', studentName: 'رضا کریمیان', studentCode: '۱۴۰۱۰۱۳۰', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۸:۰۰' },
|
||
|
||
// کلاس ۲ امروز
|
||
{ id: 'att-9', classId: 'c-2', studentId: 's-101', studentName: 'محمدصادق حسینی', studentCode: '۱۴۰۱۰۱۲۳', date: '۱۴۰۵/۰۸/۱۴', status: 'absent', delayMinutes: 0 },
|
||
{ id: 'att-10', classId: 'c-2', studentId: 's-102', studentName: 'علیرضا موسوینژاد', studentCode: '۱۴۰۱۰۱۲۴', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۱۰:۰۱' },
|
||
{ id: 'att-11', classId: 'c-2', studentId: 's-103', studentName: 'امیرحسین رضایی', studentCode: '۱۴۰۱۰۱۲۵', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۹:۵۵' },
|
||
{ id: 'att-12', classId: 'c-2', studentId: 's-104', studentName: 'مهدی تقوی', studentCode: '۱۴۰۱۰۱۲۶', date: '۱۴۰۵/۰۸/۱۴', status: 'late', delayMinutes: 20, delayReason: 'تحویل کتاب به کتابخانه مرکزی', recordedAt: '۱۰:۲۰' },
|
||
{ id: 'att-13', classId: 'c-2', studentId: 's-106', studentName: 'سید علی فاطمی', studentCode: '۱۴۰۱۰۱۲۸', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۱۰:۰۵' },
|
||
{ id: 'att-14', classId: 'c-2', studentId: 's-107', studentName: 'جعفر ابراهیمی', studentCode: '۱۴۰۱۰۱۲۹', date: '۱۴۰۵/۰۸/۱۴', status: 'absent', delayMinutes: 0 },
|
||
{ id: 'att-15', classId: 'c-2', studentId: 's-108', studentName: 'رضا کریمیان', studentCode: '۱۴۰۱۰۱۳۰', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۰۹:۵۸' },
|
||
|
||
// کلاس ۳ امروز
|
||
{ id: 'att-16', classId: 'c-3', studentId: 's-101', studentName: 'محمدصادق حسینی', studentCode: '۱۴۰۱۰۱۲۳', date: '۱۴۰۵/۰۸/۱4', status: 'absent', delayMinutes: 0 },
|
||
{ id: 'att-17', classId: 'c-3', studentId: 's-102', studentName: 'علیرضا موسوینژاد', studentCode: '۱۴۰۱۰۱۲۴', date: '۱۴۰۵/۰۸/۱۴', status: 'present', delayMinutes: 0, recordedAt: '۱۱:۴۰' },
|
||
]
|
||
|
||
// دادههای ریز تاریخچه جلسات برای طلبه جاری
|
||
const mockStudentHistory: StudentClassReport[] = [
|
||
{
|
||
classId: 'c-1',
|
||
className: 'مکاسب محرمه (شیخ انصاری)',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد رفیعی',
|
||
totalSessions: 16,
|
||
absentCount: 2,
|
||
lateCount: 3,
|
||
excusedCount: 1,
|
||
presentCount: 10,
|
||
isDropped: false,
|
||
status: 'warning',
|
||
sessions: [
|
||
{ date: '۱۴۰۵/۰۸/۱۴', sessionNumber: 16, status: 'late', delayMinutes: 15, reason: 'مشکل حملونقل و ترافیک بینشهری' },
|
||
{ date: '۱۴۰۵/۰۸/۱۲', sessionNumber: 15, status: 'present' },
|
||
{ date: '۱۴۰۵/۰۸/۰۹', sessionNumber: 14, status: 'absent', reason: 'عدم حضور بدون هماهنگی' },
|
||
{ date: '۱۴۰۵/۰۸/۰۷', sessionNumber: 13, status: 'late', delayMinutes: 10, reason: 'جلسه با معاونت پژوهش' },
|
||
{ date: '۱۴۰۵/۰۸/۰۵', sessionNumber: 12, status: 'present' },
|
||
{ date: '۱۴۰۵/۰۸/۰۲', sessionNumber: 11, status: 'excused', reason: 'ماموریت تبلیغی معتبر' },
|
||
{ date: '۱۴۰۵/۰۷/۳۰', sessionNumber: 10, status: 'absent', reason: 'غیبت غیرموجه' },
|
||
{ date: '۱۴۰۵/۰۷/۲۸', sessionNumber: 9, status: 'present' }
|
||
]
|
||
},
|
||
{
|
||
classId: 'c-2',
|
||
className: 'کفایة الاصول (آخوند خراسانی)',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد رفیعی',
|
||
totalSessions: 14,
|
||
absentCount: 4,
|
||
lateCount: 1,
|
||
excusedCount: 0,
|
||
presentCount: 9,
|
||
isDropped: true, // غیبت بیش از ۳ جلسه -> حذف
|
||
status: 'dropped',
|
||
sessions: [
|
||
{ date: '۱۴۰۵/۰۸/۱۴', sessionNumber: 14, status: 'absent', reason: 'عدم ثبت حضور' },
|
||
{ date: '۱۴۰۵/۰۸/۱۰', sessionNumber: 13, status: 'absent', reason: 'غیبت غیرموجه' },
|
||
{ date: '۱۴۰۵/۰۸/۰۸', sessionNumber: 12, status: 'absent', reason: 'غیبت غیرموجه' },
|
||
{ date: '۱4۰۵/۰۸/۰۳', sessionNumber: 11, status: 'absent', reason: 'غیبت غیرموجه' },
|
||
{ date: '۱۴۰۵/۰۸/۰۱', sessionNumber: 10, status: 'late', delayMinutes: 25, reason: 'تاخیر شدید در ورود به مدرسه' },
|
||
{ date: '۱۴۰۵/۰۷/۲۶', sessionNumber: 9, status: 'present' }
|
||
]
|
||
},
|
||
{
|
||
classId: 'c-3',
|
||
className: 'تفسیر ترتیبی قرآن کریم',
|
||
teacherName: 'آیتالله موسوی تهرانی',
|
||
totalSessions: 12,
|
||
absentCount: 0,
|
||
lateCount: 1,
|
||
excusedCount: 0,
|
||
presentCount: 11,
|
||
isDropped: false,
|
||
status: 'normal',
|
||
sessions: [
|
||
{ date: '۱۴۰۵/۰۸/۱۴', sessionNumber: 12, status: 'late', delayMinutes: 5, reason: 'تاخیر جزئی پس از اذان' },
|
||
{ date: '۱۴۰۵/۰۸/۰۹', sessionNumber: 11, status: 'present' },
|
||
{ date: '۱۴۰۵/۰۸/۰۷', sessionNumber: 10, status: 'present' },
|
||
{ date: '۱۴۰۵/۰۸/۰۲', sessionNumber: 9, status: 'present' }
|
||
]
|
||
},
|
||
{
|
||
classId: 'c-4',
|
||
className: 'فن خطابه و مهارتهای تبلیغی',
|
||
teacherName: 'حجتالاسلام والمسلمین استاد فرحزاد',
|
||
totalSessions: 8,
|
||
absentCount: 1,
|
||
lateCount: 0,
|
||
excusedCount: 1,
|
||
presentCount: 6,
|
||
isDropped: false,
|
||
status: 'normal',
|
||
sessions: [
|
||
{ date: '۱۴۰۵/۰۸/۰۴', sessionNumber: 8, status: 'present' },
|
||
{ date: '۱۴۰۵/۰۷/۲۷', sessionNumber: 7, status: 'excused', reason: 'هماهنگی با مدیر گروه تبلیغ' },
|
||
{ date: '۱۴۰۵/۰۷/۲۰', sessionNumber: 6, status: 'absent', reason: 'غیبت' }
|
||
]
|
||
}
|
||
]
|
||
|
||
// State های سراسری
|
||
const classes = ref<ClassItem[]>([...initialClasses])
|
||
const attendanceRecords = ref<AttendanceRecord[]>([...initialAttendanceRecords])
|
||
const students = ref<Student[]>([...mockStudentsList])
|
||
const studentReports = ref<StudentClassReport[]>([...mockStudentHistory])
|
||
|
||
export const useMockData = () => {
|
||
// تاریخ امروز به شمسی
|
||
const todayShamsi = 'چهارشنبه، ۱۴ آبان ۱۴۰۵'
|
||
|
||
// محاسبه تاخیر نسبت به ساعت شروع کلاس
|
||
const calculateDelay = (startTime: string): { isLate: boolean; minutes: number } => {
|
||
try {
|
||
const now = new Date()
|
||
const currentHours = now.getHours()
|
||
const currentMinutes = now.getMinutes()
|
||
|
||
const [startHourStr, startMinStr] = startTime.split(':')
|
||
const startH = parseInt(startHourStr, 10)
|
||
const startM = parseInt(startMinStr, 10)
|
||
|
||
const startTotalMinutes = startH * 60 + startM
|
||
const currentTotalMinutes = currentHours * 60 + currentMinutes
|
||
|
||
const diff = currentTotalMinutes - startTotalMinutes
|
||
|
||
if (diff > 0) {
|
||
return { isLate: true, minutes: diff }
|
||
}
|
||
return { isLate: false, minutes: 0 }
|
||
} catch {
|
||
return { isLate: false, minutes: 0 }
|
||
}
|
||
}
|
||
|
||
// ثبت حضور توسط طلبه
|
||
const submitStudentAttendance = (classId: string, studentId: string, delayMinutes: number, delayReason?: string) => {
|
||
const student = students.value.find(s => s.id === studentId) || { name: 'طلبه', code: '۰' }
|
||
const status: AttendanceStatus = delayMinutes > 0 ? 'late' : 'present'
|
||
|
||
const existingIndex = attendanceRecords.value.findIndex(r => r.classId === classId && r.studentId === studentId)
|
||
|
||
const now = new Date()
|
||
const recordedAt = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`
|
||
|
||
if (existingIndex > -1) {
|
||
attendanceRecords.value[existingIndex] = {
|
||
...attendanceRecords.value[existingIndex],
|
||
status,
|
||
delayMinutes,
|
||
delayReason: delayReason || attendanceRecords.value[existingIndex].delayReason,
|
||
recordedAt
|
||
}
|
||
} else {
|
||
attendanceRecords.value.push({
|
||
id: `att-${Date.now()}`,
|
||
classId,
|
||
studentId,
|
||
studentName: student.name,
|
||
studentCode: student.code,
|
||
date: '۱۴۰۵/۰۸/۱۴',
|
||
status,
|
||
delayMinutes,
|
||
delayReason,
|
||
recordedAt
|
||
})
|
||
}
|
||
|
||
// بهروزرسانی گزارش طلبه در صورت نیاز
|
||
const report = studentReports.value.find(r => r.classId === classId)
|
||
if (report) {
|
||
const existingSession = report.sessions.find(s => s.date === '۱۴۰۵/۰۸/۱۴')
|
||
if (existingSession) {
|
||
existingSession.status = status
|
||
existingSession.delayMinutes = delayMinutes
|
||
existingSession.reason = delayReason
|
||
} else {
|
||
report.sessions.unshift({
|
||
date: '۱۴۰۵/۰۸/۱۴',
|
||
sessionNumber: report.totalSessions + 1,
|
||
status,
|
||
delayMinutes,
|
||
reason: delayReason
|
||
})
|
||
report.totalSessions++
|
||
}
|
||
// بازسازی شمارشها
|
||
report.presentCount = report.sessions.filter(s => s.status === 'present').length
|
||
report.lateCount = report.sessions.filter(s => s.status === 'late').length
|
||
report.absentCount = report.sessions.filter(s => s.status === 'absent').length
|
||
report.excusedCount = report.sessions.filter(s => s.status === 'excused').length
|
||
report.isDropped = report.absentCount >= 3
|
||
report.status = report.isDropped ? 'dropped' : report.absentCount >= 2 ? 'warning' : 'normal'
|
||
}
|
||
|
||
return true
|
||
}
|
||
|
||
// ویرایش سریع حضور و غیاب توسط استاد
|
||
const updateStudentStatus = (classId: string, studentId: string, newStatus: AttendanceStatus, delayMinutes = 0, delayReason = '') => {
|
||
const student = students.value.find(s => s.id === studentId)
|
||
const existingIndex = attendanceRecords.value.findIndex(r => r.classId === classId && r.studentId === studentId)
|
||
|
||
if (existingIndex > -1) {
|
||
attendanceRecords.value[existingIndex].status = newStatus
|
||
if (newStatus === 'late') {
|
||
attendanceRecords.value[existingIndex].delayMinutes = delayMinutes || 10
|
||
if (delayReason) attendanceRecords.value[existingIndex].delayReason = delayReason
|
||
} else {
|
||
attendanceRecords.value[existingIndex].delayMinutes = 0
|
||
if (newStatus === 'excused' && delayReason) {
|
||
attendanceRecords.value[existingIndex].delayReason = delayReason
|
||
}
|
||
}
|
||
} else if (student) {
|
||
attendanceRecords.value.push({
|
||
id: `att-${Date.now()}`,
|
||
classId,
|
||
studentId,
|
||
studentName: student.name,
|
||
studentCode: student.code,
|
||
date: '۱۴۰۵/۰۸/۱۴',
|
||
status: newStatus,
|
||
delayMinutes: newStatus === 'late' ? (delayMinutes || 10) : 0,
|
||
delayReason,
|
||
recordedAt: '۰۸:۳۰'
|
||
})
|
||
}
|
||
}
|
||
|
||
// مدیریت کلاسها توسط آموزش
|
||
const addClass = (newClass: Omit<ClassItem, 'id' | 'studentCount'>) => {
|
||
const id = `c-${Date.now()}`
|
||
const created: ClassItem = {
|
||
...newClass,
|
||
id,
|
||
studentCount: newClass.studentIds.length,
|
||
isOngoingToday: true
|
||
}
|
||
classes.value.push(created)
|
||
return created
|
||
}
|
||
|
||
const updateClass = (classId: string, payload: Partial<ClassItem>) => {
|
||
const index = classes.value.findIndex(c => c.id === classId)
|
||
if (index > -1) {
|
||
classes.value[index] = {
|
||
...classes.value[index],
|
||
...payload,
|
||
studentCount: payload.studentIds ? payload.studentIds.length : classes.value[index].studentCount
|
||
}
|
||
}
|
||
}
|
||
|
||
const deleteClass = (classId: string) => {
|
||
classes.value = classes.value.filter(c => c.id !== classId)
|
||
attendanceRecords.value = attendanceRecords.value.filter(r => r.classId !== classId)
|
||
}
|
||
|
||
// استخراج فایل اکسل با xlsx
|
||
const exportToExcel = (data: any[], fileName: string, sheetName = 'گزارش حضور و غیاب') => {
|
||
try {
|
||
const worksheet = XLSX.utils.json_to_sheet(data)
|
||
const workbook = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName)
|
||
|
||
// تنظیم راستچین و جهت شیت در صورت امکان
|
||
if (!workbook.Workbook) workbook.Workbook = {}
|
||
if (!workbook.Workbook.Views) workbook.Workbook.Views = []
|
||
workbook.Workbook.Views[0] = { RTL: true }
|
||
|
||
XLSX.writeFile(workbook, `${fileName}.xlsx`)
|
||
return true
|
||
} catch (err) {
|
||
console.error('خطا در صدور فایل اکسل:', err)
|
||
return false
|
||
}
|
||
}
|
||
|
||
// گزارش آمار طلبه جاری
|
||
const studentTotalStats = computed(() => {
|
||
let totalClasses = studentReports.value.length
|
||
let totalSessions = 0
|
||
let totalAbsents = 0
|
||
let totalLates = 0
|
||
let totalExcused = 0
|
||
let totalPresents = 0
|
||
|
||
studentReports.value.forEach(r => {
|
||
totalSessions += r.totalSessions
|
||
totalAbsents += r.absentCount
|
||
totalLates += r.lateCount
|
||
totalExcused += r.excusedCount
|
||
totalPresents += r.presentCount
|
||
})
|
||
|
||
const presentRate = totalSessions > 0 ? Math.round(((totalPresents + totalLates + totalExcused) / totalSessions) * 100) : 100
|
||
|
||
return {
|
||
totalClasses,
|
||
totalSessions,
|
||
totalAbsents,
|
||
totalLates,
|
||
totalExcused,
|
||
presentRate,
|
||
droppedClassesCount: studentReports.value.filter(r => r.isDropped).length
|
||
}
|
||
})
|
||
|
||
// گزارش آمار آموزش کلی حوزه
|
||
const adminOverallStats = computed(() => {
|
||
const totalClassesCount = classes.value.length
|
||
const totalTeachersCount = mockTeachersList.length
|
||
const totalStudentsCount = students.value.length
|
||
|
||
// میانگین حضور در رکوردهای ثبتشده
|
||
const recorded = attendanceRecords.value
|
||
const presentOrLate = recorded.filter(r => r.status === 'present' || r.status === 'late').length
|
||
const attendancePercentage = recorded.length > 0 ? Math.round((presentOrLate / recorded.length) * 100) : 92
|
||
|
||
return {
|
||
totalClassesCount,
|
||
totalTeachersCount,
|
||
totalStudentsCount,
|
||
attendancePercentage,
|
||
totalRecordsToday: recorded.length
|
||
}
|
||
})
|
||
|
||
return {
|
||
classes,
|
||
students,
|
||
teachers: mockTeachersList,
|
||
attendanceRecords,
|
||
studentReports,
|
||
todayShamsi,
|
||
calculateDelay,
|
||
submitStudentAttendance,
|
||
updateStudentStatus,
|
||
addClass,
|
||
updateClass,
|
||
deleteClass,
|
||
exportToExcel,
|
||
studentTotalStats,
|
||
adminOverallStats
|
||
}
|
||
}
|