/
home
/
maktab
/
server
/
app
/
Http
/
Controllers
/
File Upload :
llllll
Current File: /home/maktab/server/app/Http/Controllers/SuperAttendanceController.php
<?php namespace App\Http\Controllers; use App\Models\Attendance; use App\Models\File; use App\Models\Maktab; use App\Models\Message; use App\Models\ReportStudentAttendance; use App\Models\Student; use App\Models\StudentAttendance; use App\Models\User; use App\Models\Sms; use Hekmatinasser\Verta\Verta; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use App\Jobs\SendSms; use Auth; class SuperAttendanceController extends Controller { public function __construct($model, $select = ['*'], $user, $model_name = 'attendance') { $this->model = $model; $this->select = $select; $this->user = $user; $this->model_name = $model_name; } public function getList(Request $request) { $data = $request->all(); if ($this->model_name == 'student_attendance') { $with = ['student']; if ($this->user->type == 4) { $data['teacher_id'] = $this->user->id; $data['maktab_id'] = $this->user->maktab_id; } elseif ($this->user->type == 3) { $data['teacher_id'] = $request->teacher_id; $data['maktab_id'] = $this->user->maktab_id; } elseif (in_array($this->user->type, [1, 2, 5])) { $data['teacher_id'] = $request->teacher_id; $data['maktab_id'] = $request->maktab_id; } } else { $with = ['employee']; if ($this->user->type == 3) { $data['maktab_id'] = $this->user->maktab_id; } elseif (in_array($this->user->type, [1, 2, 5])) { $data['maktab_id'] = $request->maktab_id; } } $at = $this->model::where('report_id', $request->report_id) ->where('maktab_id', $data['maktab_id']); if (isset($data['teacher_id'])) { $at->where('employee_id', $data['teacher_id']); } return response()->json($at->with($with)->orderBy('id', 'desc')->get()); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\jsonResponse */ public function store(Request $request) { $pID =time(); $data = $request->all(); Log::info("attendance"); Log::info($this->user->id); $receive_user_type ="student_attendances"; foreach ($data['present'] as $item) { if ($this->model_name == 'attendance') { $user = User::findOrFail($item['employee_id']); $item['type'] = $user->type_employee; } else { $user = Student::findOrFail($item['employee_id']); if ($user->mother_mobile) { $item['user_number'] = $user->mother_mobile; $receive_user_type .= "_mother"; $item['user_number_type'] = "برای مادر ارسال شد"; } elseif ($user->father_mobile) { $item['user_number'] = $user->father_mobile; $receive_user_type .= "_father"; $item['user_number_type'] = 'تلفن مادر ثبت نشده برای پدر ارسال شد'; } else { $item['user_number'] =0; $item['user_number_number'] = "شماره پدر و مادر ثبت نشده"; } $item['student_id'] = $item['employee_id']; $item['employee_id'] = $user->employee_id; $item['number'] = $user->employee_id; } if ($item["present"] == false && $data["send_sms"] == true) { $userNumber = $item['user_number']; $messageContent = "والدین گرامی فرزند شما امروز در مکتب غایب بود."; $receiveUserType = $receive_user_type; $studentId = $item['student_id']; $sendUserId = auth()->user()->id; SendSms::dispatch($userNumber, $messageContent, $receiveUserType, $studentId, $sendUserId,"student_attendances",$pID); } $item['report_id'] = $data['report_id'] ?? null; $item['name'] = $user->name; $item['maktab_id'] = $user->maktab_id; $item['date_at'] = $data['date_at']; if (isset($item['id'])) { Log::info('update'); $this->model::findOrFail($item['id'])->update($item); } else { Log::info('create'); $this->model::create($item); } if ($this->model_name != 'attendance') { $count = StudentAttendance::where('report_id', $data['report_id'])->where('present', true)->count(); $count_absent = StudentAttendance::where('report_id', $data['report_id'])->where('present', false)->count(); } else { $count = Attendance::where('report_id', $data['report_id'])->where('present', true)->count(); $count_absent = Attendance::where('report_id', $data['report_id'])->where('present', false)->count(); } ReportStudentAttendance::find($data['report_id']) ->update([ 'count' => $count, 'count_absent' => $count_absent ]); } $this->sendSmsToAdminForAttendance($data['report_id']); return response()->json(true); } public function getQuery() { if ($this->model_name == 'attendance') { $maktab_id = Maktab::where('user_id', $this->user->id)->first()->id; $file = File::whereHas('teacher', function ($q) use ($maktab_id) { return $q->where('maktab_id', $maktab_id); })->get()->pluck('full_src')->toArray(); } else { $maktab_id = $this->user->maktab_id; $file = File::whereHas('student', function ($q) { return $q->where('maktab_id', $this->user->maktab_id)->where('employee_id', $this->user->id); })->get()->pluck('full_src')->toArray(); } $count = 5; if (count($file) < 5) { $count = count($file); } $at = $this->model::where('maktab_id', $maktab_id) ->where('present', 1) ->select([ DB::raw('sum(present) as sum'), DB::raw('Date(date_at) as date'), ]) ->groupBy('date') ->orderBy('date', 'desc') ->get() ->toArray(); for ($i = 0; $i < count($at); $i++) { if ($count > 0) { $at[$i]['avatar'] = array_rand(array_flip($file), $count); } $at[$i]['daj'] = Verta::instance($at[$i]['date'])->format('Y/m/d'); } return response()->json($at); } }
Copyright ©2k19 -
Hexid
|
Tex7ure