EVOLUTION-NINJA
Edit File: Student.php
<?php namespace App\Controllers; use PhpOffice\PhpSpreadsheet\IOFactory; class Student extends BaseController { public function student_from_excel() { // die(); $excelFile = $this->request->getFile('excel'); if ($excelFile->isValid() && !$excelFile->hasMoved()) { $tempFilePath = $excelFile->getTempName(); $spreadsheet = IOFactory::load($tempFilePath); $worksheet = $spreadsheet->getActiveSheet(); $db = \Config\Database::connect(); $builder = $db->table('student_list'); foreach ($worksheet->getRowIterator(2) as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); $rowData = []; foreach ($cellIterator as $cell) { $rowData[] = $cell->getValue(); } // print_r($rowData);die(); $first_name = $rowData[0]? $rowData[0] : ''; $last_name = $rowData[1]? $rowData[1] : ''; $email = $rowData[2]? $rowData[2] : ''; $dob = $rowData[3]? $rowData[3] : ''; $date = $rowData[4]? $rowData[4] : ''; $mobile_no = $rowData[5]? $rowData[5] : ''; $adhaar_no = $rowData[6]? $rowData[6] : ''; $address = $rowData[7]? $rowData[7] : ''; $city = $rowData[8]? $rowData[8] : ''; $course_offered = $rowData[9]? $rowData[9] : ''; $qualification = $rowData[10]? $rowData[10] : ''; $country = $rowData[11]? $rowData[11] : ''; $counselor_name = $rowData[12]? $rowData[12] : ''; $gender = $rowData[13]? $rowData[13] : ''; $source = $rowData[14]? $rowData[14] : ''; $profession = $rowData[15]? $rowData[15] : ''; $status = $rowData[16]? $rowData[16] : ''; $company_name = $rowData[17]? $rowData[17] : ''; $remarks = $rowData[18]? $rowData[18] : ''; $total_fees = $rowData[19]? $rowData[19] : ''; $duration = $rowData[20]? $rowData[20] : ''; $paid_fees = $rowData[21]? $rowData[21] : ''; $created_by = $rowData[22]? $rowData[22] : ''; $created_at = $rowData[23]? $rowData[23] : ''; $dropout = $rowData[24]? $rowData[24] : ''; if($dob){ $dobDate = \DateTime::createFromFormat('d-m-Y', $dob); $dob = $dobDate ? $dobDate->format('Y-m-d') : ''; } if($date){ $dateDate = \DateTime::createFromFormat('d-m-Y', $date); $date = $dateDate ? $dateDate->format('Y-m-d') : ''; } // print_r($rowData[4]);die(); // if($created_at){ // $datecreated_at = \DateTime::createFromFormat('d-m-Y H:i', $created_at); // $created_at = $datecreated_at ? $datecreated_at->format('Y-m-d H:i:s') : null; // }else{ // $created_at=$date; // } $adno_model = $db->table('student_list'); $adno_model->select('admission_no'); $adno_model->like('admission_no', 'GTRAC'); $adno_data = $adno_model->get()->getResultArray(); $last = end($adno_data); if ($last) { $last_admission_no = $last['admission_no']; $ad1 = intval(substr($last_admission_no, 5)) + 1; $ad_no = 'GTRAC' . str_pad($ad1, 6, '0', STR_PAD_LEFT); } else { $ad_no = 'GTRAC000001'; } $inserID= $builder->insert([ 'admission_no'=>$ad_no, 'first_name' => $first_name, 'last_name'=>$last_name, 'email'=>$email, 'dob'=>$dob, 'date'=>$date, 'mobile_no'=>$mobile_no, 'adhaar_no'=>$adhaar_no, 'address'=>$address, 'city'=>$city, 'course_offered'=>$course_offered, 'qualification'=>$qualification, 'counselor_name'=>$counselor_name, 'gender'=>$gender, 'source'=>$source, 'profession'=>$profession, 'status'=>$status, 'company_name'=>$company_name, 'remarks'=>$remarks, 'total_fees'=>$total_fees, 'duration'=>$duration, 'paid_fees'=>$paid_fees, 'created_by'=>$created_by, 'created_at'=>$created_at, 'delete_status'=>1, 'header_name'=>'36', 'value_name'=>'33', 'dropout'=>$dropout ]); $inserID = $db->insertID(); // print_r($inserID);die(); if($inserID){ if($paid_fees!=0 && $paid_fees>0){ $payment_id = "PAY-".date("YmdHis"); $receipt = $db->table('fees_collection'); $receipt->select('recipt_no'); $receipt->like('recipt_no', 'RECIPT'); $receipt->orderBy('recipt_no', 'DESC'); $receipt->limit(1); $recno_data = $receipt->get()->getResultArray(); $last = end($recno_data); if ($last) { $last_receipt_no = $last['recipt_no']; $re_no1 = intval(substr($last_receipt_no, 6)) + 1; $recipt_no = 'RECIPT' . str_pad($re_no1, 6, '0', STR_PAD_LEFT); } else { $recipt_no = 'RECIPT000001'; } $datafees=[ 's_id'=>$inserID, 'admission_no'=>$ad_no, 'payment_id'=>$payment_id, 'amount'=>$paid_fees, 'collected_by'=>$created_by, 'created_at' => date('Y-m-d H:i:s'), 'description'=>'Default', 'recipt_no'=>$recipt_no, 'mode_of_pament'=>'Default' ]; $insert_data=$db->table('fees_collection'); $insert=$insert_data->insert($datafees); } } } return $this->response->setJSON(['result' => 1, 'message' => 'Students imported successfully and Please Update the nesscessary fields and profiile images,documents']); } else { $errors = $excelFile->getErrorString(); return $this->response->setJSON(['result' => 0, 'message' => 'File upload failed: ' . $errors]); } } public function update_dropout_status() { $id = $this->request->getPost('id'); $dropout = $this->request->getPost('dropout'); if ($id !== null && $dropout !== null) { $db = \Config\Database::connect(); $builder = $db->table('student_list'); $builder->set('dropout', $dropout); $builder->where('id', $id); $builder->update(); $message = $dropout == 1 ? 'Dropout' : 'Dropout removed successfully'; return $this->response->setJSON(['result' => 1, 'message' => $message]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid request']); } } public function get_fees() { $id=session()->get('id'); $valueId=$this->request->getVar('id'); if($id){ $db=\Config\Database::connect(); $builder=$db->table('fee_structure'); $builder->where('value_id',$valueId); $data=$builder->get()->getResultArray(); if($data){ return $this->response->setJSON(['result'=>1,'data'=>$data]); }else{ return $this->response->setJSON(['result'=>0,'message'=>'No data ']); } }else{ return $this->response->setJSON(['result'=>0,'message'=>'please login']); } } public function application_form(){ $id=session()->get('id'); if($id){ $db=\Config\Database::connect(); $data=$this->request->getVar(); $data['created_at']=date('Y-m-d H:i:s'); $adno_model = $db->table('student_list'); $adno_model->select('admission_no'); $adno_model->like('admission_no', 'GTRAC'); $adno_data = $adno_model->get()->getResultArray(); $last = end($adno_data); if ($last) { $last_admission_no = $last['admission_no']; $ad1 = intval(substr($last_admission_no, 5)) + 1; $ad_no = 'GTRAC' . str_pad($ad1, 6, '0', STR_PAD_LEFT); } else { $ad_no = 'GTRAC000001'; } $newName=''; $image = $this->request->getFile('profile-image'); // if($image){ if ($image->isValid() && !$image->hasMoved()) { $newName = uniqid() . '.' . $image->getClientExtension(); $image->move('public/assets/studentimages', $newName); } // } // else { // return $this->response->setJSON(['result' => 0, 'message' => 'Failed to upload profile picture']); // // exit(); // } $documents = $this->request->getFiles(); $documentPaths = []; if ($documents && isset($documents['document'])) { foreach ($documents['document'] as $document) { if ($document->isValid() && !$document->hasMoved()) { $docName = uniqid() . '.' . $document->getClientExtension(); $document->move('public/assets/studentdocuments', $docName); $documentPaths[] = $docName; } } } // else{ // echo 'failed to uplaod ';die(); // } $data['documents'] = implode(',', $documentPaths); $data['profile_image']=$newName; $data['admission_no']=$ad_no; $data['created_by']=session()->get('username'); $data['delete_status']=1; $builder=$db->table('student_list'); $insert=$builder->insert($data); if($insert){ $email = \Config\Services::email(); $name=$data['first_name']; $toEmail = $data['email']; $value=$db->table('header_value')->where('id',$data['value_name'])->get()->getRowArray(); $course=$value['value_name']; $subject = 'Congratulations on Your Admission to '.$course.' Dear '.$name.''; $baseUrl = 'https://jayblues.in/gtracERP/public/assets/images/'; $message = ' <section style="display: grid; place-items: center; margin: auto;"> <div style=" height: auto; background: url(' . $baseUrl . 'Group%2079.png) no-repeat top left, url(' . $baseUrl . 'Group%205.png) no-repeat bottom right; overflow: hidden; position: relative;"> <img src="' . $baseUrl . 'Group%2077.png" alt="" style="float:right; max-width: 100%; height: auto;"> <div class="email-detail" style="width: 100%; height: auto; margin: auto; margin: 5px; border-radius: 20px; display: flex; padding-block: 25px; padding-inline: 8px; background: url(' . $baseUrl . 'Mask%20Group.png) no-repeat bottom left, url(' . $baseUrl . 'Mask%20Group%201.png) no-repeat top right; background-color: #F9F7FE;"> <div style="width: 50%; padding: 5px;padding-bottom: 24px;"> <img src="' . $baseUrl . 'mygtrac%20logo%201.png" alt="" style=" margin-block: 10px; max-width: 100%; height: auto;"> <h5 style="font-size: clamp(07px, 2vw, 19px); color: #191E43; font-weight: 600;">We are delighted to inform you that you have been admitted to the '.$course.' at GTRAC.As a newly admitted student, we want to ensure you have all the information you need to get started.</h5> <p style="font-size: clamp(10px, 2vw, 18px); color: #191E43; font-weight: 600; margin-top: 25px;">Admission Number</p> <span style="background-color: #6DA800; padding: 8px 15px; color: white; font-size: 08px; font-weight: 600; border-radius: 7px;">'.$ad_no.'</span> </div> <div style="width: 50%;display: flex; align-items: center; justify-content: center; padding: 8px;"> <img src="' . $baseUrl . 'Image.png" alt="" style="height: auto; width: 100%; "> </div> </div> <div style="padding: 12px; background: linear-gradient(#F4FFF0, #E2EFFF); border-radius: 10px; margin-top: 10px;"> <h6 style="font-size: 12px; font-weight: 600; color: #191E43;">Hello, '.$name.'</h6> <p style="font-size: 8px !important; font-weight: 500; color: #333333;">We are excited to have you join our academic community and look forward to supporting you throughout your educational journey. If you have any questions or need further assistance, please do not hesitate to contact us at <a href="mailto:enquiry09.gta@gmail.com" style="color: #6DA800; text-decoration: none;">enquiry09.gta@gmail.com</a>.</p> <p style="font-size: 8px !important; font-weight: 500; color: #333333;">Once again, congratulations on your admission! We look forward to seeing you in the '.$course.'</p> <p style="color: #426600; font-size: 6px; font-weight: 600; margin: 0;">Best regards,</p> <p style="color: #333333; font-size: 6px; font-weight: 600; margin: 0;">Gtrac Team</p> <p style="color: #333333; font-size: 6px; font-weight: 600; margin: 0;">9606011223</p> <p style="text-align: right; margin: 0;"><a href="http://www.mygtrac.com" style="color: #426600; text-decoration: none; font-weight: 600;">www.mygtrac.com</a></p> </div> </div> </section>'; $email->setFrom('enquiry09.gta@gmail.com', 'GTRAC'); $email->setTo($toEmail); $email->setSubject($subject); $email->setMessage($message); $email->setMailType('html'); if ($email->send()) { return $this->response->setJSON(['result'=>1,'message'=>'Application submitted successfully']); }else{ return $this->response->setJSON(['result'=>1,'message'=>'Application submitted successfully but failed tosend email']); } }else{ return $this->response->setJSON(['result'=>0,'message'=>'Failed to submit']); } }else{ return $this->response->setJSON(['result'=>0,'message'=>'please login']); } } // public function student_list_data() // { // $id = session()->get('id'); // if ($id) { // $db = \Config\Database::connect(); // $builder = $db->table('student_list'); // $builder->select('student_list.*, header.header_name as header, header_value.value_name as value'); // $builder->join('header', 'header.id = student_list.header_name', 'left'); // $builder->join('header_value', 'header_value.id = student_list.value_name', 'left'); // $builder->where('student_list.delete_status', '1'); // $header=$this->request->getvar('header'); // if (!empty($header)) { // $builder->where('header.id', $header); // } // $fromdate = $this->request->getVar('fromdate'); // $todate = $this->request->getVar('todate'); // if ($fromdate && $todate) { // $builder->where('DATE(student_list.created_at) >=', $fromdate); // $builder->where('DATE(student_list.created_at) <=', $todate); // } // $builder->orderBy('student_list.created_at', 'DESC'); // $data = $builder->get()->getResultArray(); // if ($data) { // return $this->response->setJSON($data); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Failed to load data']); // } // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'please login']); // } // } public function student_list_data() { $id = session()->get('id'); if ($id) { $db = \Config\Database::connect(); $builder = $db->table('student_list'); $builder->select('student_list.*, header.header_name as header, header_value.value_name as value'); $builder->join('header', 'header.id = student_list.header_name', 'left'); $builder->join('header_value', 'header_value.id = student_list.value_name', 'left'); $builder->where('student_list.delete_status', '1'); $header = $this->request->getVar('header'); if (!empty($header)) { $builder->where('header.id', $header); } $fromdate = $this->request->getVar('fromdate'); $todate = $this->request->getVar('todate'); if ($fromdate && $todate) { $builder->where('DATE(student_list.created_at) >=', $fromdate); $builder->where('DATE(student_list.created_at) <=', $todate); } $paymentStatus = $this->request->getVar('payment_status'); if ($paymentStatus == 'pending') { $builder->where('student_list.total_fees > student_list.paid_fees'); $builder->where('student_list.dropout !=', 1); } elseif ($paymentStatus == 'full') { $builder->where('student_list.total_fees = student_list.paid_fees'); } $builder->orderBy('student_list.created_at', 'DESC'); $data = $builder->get()->getResultArray(); if ($data) { return $this->response->setJSON($data); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to load data']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Please login']); } } public function student_delete() { $id=$this->request->getVar('id'); // echo $id;die(); $db=\Config\Database::connect(); $builder=$db->table('student_list'); $data=[ 'delete_status'=>0 ]; $builder->where('id',$id); $delete=$builder->update($data); if($delete){ return $this->response->setJSON(['result'=>1]); }else{ return $this->response->setJSON(['result'=>0]); } } public function student_edit() { $id=session()->get('id'); if($id){ $sid=$this->request->getVar('id'); // echo $sid;die(); $db=\Config\Database::connect(); $builder=$db->table('student_list'); $builder->where('id',$sid); $data=$builder->get()->getRowArray(); // print_r($data);die(); // $data['value']=$data; return view('studentapplication/student_edit',$data); }else{ return $this->response->setJSON(['result'=>0,'message'=>'please login']); } } public function application_form_update(){ $id=session()->get('id'); $sid=$this->request->getVar('id'); // echo $sid;die(); if($sid){ $db=\Config\Database::connect(); $data=$this->request->getVar(); $data['created_at']=date('Y-m-d H:i:s'); $image = $this->request->getFile('profile-image'); if ($image->isValid() && !$image->hasMoved()) { $newName = uniqid() . '.' . $image->getClientExtension(); $image->move('public/assets/studentimages', $newName); $data['profile_image']=$newName; } else { $existingImagePath=''; $imagename=$db->table('student_list'); $imagename->where('id',$sid); $imagerow=$imagename->get()->getRowArray(); $imagerow['profile_image'] = $existingImagePath; } $existingDocumentPaths = $db->table('student_list')->select('documents')->where('id', $sid)->get()->getRow()->documents; $existingDocuments = explode(',', $existingDocumentPaths); $documents = $this->request->getFiles(); $documentPaths = []; if ($documents && isset($documents['document'])) { foreach ($documents['document'] as $document) { if ($document->isValid() && !$document->hasMoved()) { $docName = uniqid() . '.' . $document->getClientExtension(); $document->move('public/assets/studentdocuments', $docName); $documentPaths[] = $docName; } } } $finalDocumentPaths = array_merge($existingDocuments, $documentPaths); $data['documents'] = implode(',', $finalDocumentPaths); $data['created_by']=session()->get('username'); $data['delete_status']=1; $builder=$db->table('student_list'); $builder->where('id',$sid); $insert=$builder->update($data); if($insert){ return $this->response->setJSON(['result'=>1,'message'=>'Application submitted successfully']); }else{ return $this->response->setJSON(['result'=>0,'message'=>'Failed to submit']); } }else{ return $this->response->setJSON(['result'=>0,'message'=>'please login']); } } public function student_details() { $id=session()->get('id'); if($id){ $sid=$this->request->getVar('id'); // echo $sid;die(); $db=\Config\Database::connect(); $builder=$db->table('student_list'); $builder->select('student_list.*,header.header_name as header,header_value.value_name as value'); $builder->join('header','header.id=student_list.header_name'); $builder->join('header_value','header_value.id=student_list.value_name'); $builder->where('student_list.id',$sid); $data=$builder->get()->getRowArray(); // print_r($data);die(); // $data['value']=$data; if($data){ return $this->response->setJSON(['result'=>1,'data'=>$data]); }else{ return $this->response->setJSON(['result'=>0,'message'=>'Please fill Complete details by clicking edit to view this Student Details..!']); } }else{ return $this->response->setJSON(['result'=>0,'message'=>'please login']); } } public function student_report_main() { $db = \Config\Database::connect(); $toDate = date('Y-m-d'); $fromDate = date('Y-m-d', strtotime('-3 months', strtotime($toDate))); $fromdate = $this->request->getPost('fromdate'); $todate = $this->request->getPost('todate'); if (!$fromdate || !$todate) { $fromdate = $fromDate; $todate = $toDate; } //headers $builder = $db->table('header'); $builder->select('id, header_name'); $headers = $builder->get()->getResultArray(); $studentCount = []; $totalstudents=0; foreach ($headers as $header) { $id = $header['id']; $builder = $db->table('student_list'); $builder->where('header_name', $id); $builder->where('delete_status', 1); $builder->where('created_at >=', $fromdate . ' 00:00:00'); $builder->where('created_at <=', $todate . ' 23:59:59'); $count=$builder->countAllResults(); // $query=$db->getLastQuery(); // echo $query;die(); $studentCount[$header['header_name']] = $count; $totalstudents+=$count; } $studentCount['totalstudnets']=$totalstudents; //value // print_r($studentCount); // die(); if (!empty($studentCount)) { return $this->response->setJSON(['result' => 1, 'data' => $studentCount]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong']); } } public function drop_student_list() { $id = session()->get('id'); if ($id) { $db = \Config\Database::connect(); $builder = $db->table('student_list'); $builder->select('student_list.*, header.header_name as header, header_value.value_name as value, dropout'); $builder->join('header', 'header.id = student_list.header_name', 'left'); $builder->join('header_value', 'header_value.id = student_list.value_name', 'left'); $builder->where('student_list.dropout', '1'); $builder->orderBy('student_list.date', 'DESC'); $data = $builder->get()->getResultArray(); if ($data) { return $this->response->setJSON($data); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to load data']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'please login']); } } public function fetch_headers() { $db = \Config\Database::connect(); $builder = $db->table('header'); $builder->select('id, header_name'); $query = $builder->get(); $headers = $query->getResultArray(); if ($headers) { return $this->response->setJSON($headers); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No headers found']); } } } ?>