EVOLUTION-NINJA
Edit File: Document.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH . '../vendor/autoload.php'; use Mpdf\Mpdf; class Document extends CI_Controller { public function __construct() { parent::__construct(); $this->load->database(); $this->load->model('Certificate_model'); $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); $this->output->set_header('Pragma: no-cache'); $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); $this->load->model('yaskawa_model'); date_default_timezone_set('asia/kolkata'); } public function experience_letter_female(){ $admin_id = $this->session->userdata('admin_id'); if($admin_id) { $data['company_details']=$this->yaskawa_model->fetch_company_details(); $this->load->view('documents/experience_letter_female',$data); } else { redirect('/'); } } public function experience_letter_male(){ $admin_id = $this->session->userdata('admin_id'); if($admin_id) { $data['company_details']=$this->yaskawa_model->fetch_company_details(); $this->load->view('documents/experience_letter_male',$data); } else { redirect('/'); } } public function offer_letter(){ $admin_id = $this->session->userdata('admin_id'); if($admin_id) { $data['company_details']=$this->yaskawa_model->fetch_company_details(); $this->load->view('documents/offer_letter',$data); } else { redirect('/'); } } public function offer_letter_thirdParty(){ $admin_id = $this->session->userdata('admin_id'); if($admin_id) { $data['company_details']=$this->yaskawa_model->fetch_company_details(); $this->load->view('documents/thirdParty_offer_letter',$data); } else { redirect('/'); } } public function autocomplete_emp_id_third_party() { if ($this->input->is_ajax_request()) { $query = $this->input->get('query'); $this->load->database(); $this->db->select('emp_id, employee_id, first_name ,last_name'); $this->db->from('employees'); // Always restrict to Third Party $this->db->where('employee_type', 'Third Party'); if (!empty($query)) { $this->db->group_start(); $this->db->like('employee_id', $query); $this->db->or_like('first_name', $query); $this->db->group_end(); } $this->db->limit(10); $result = $this->db->get()->result_array(); echo json_encode($result); exit; } show_404(); } public function autocomplete_female_emp_id() { if ($this->input->is_ajax_request()) { $query = $this->input->get('query'); $this->load->database(); $this->db->select('emp_id, employee_id, first_name ,last_name'); $this->db->from('employees'); if (!empty($query)) { $this->db->group_start(); $this->db->like('employee_id', $query); $this->db->or_like('first_name', $query); $this->db->group_end(); } $this->db->limit(10); $result = $this->db->get()->result_array(); echo json_encode($result); exit; } show_404(); } public function get_female_employee_data() { $admission_no = $this->input->get('admission_no'); $this->load->database(); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employee_id', $admission_no); $data = $this->db->get()->row(); $this->load->view('documents/experience-letter-female', ['data' => $data]); } public function autocomplete_male_emp_id() { if ($this->input->is_ajax_request()) { $query = $this->input->get('query'); $this->load->database(); $this->db->select('emp_id, employee_id, first_name ,last_name'); $this->db->from('employees'); if (!empty($query)) { $this->db->group_start(); $this->db->like('employee_id', $query); $this->db->or_like('first_name', $query); $this->db->group_end(); } $this->db->limit(10); $result = $this->db->get()->result_array(); echo json_encode($result); exit; } show_404(); } public function get_male_employee_data() { $admission_no = $this->input->get('admission_no'); $this->load->database(); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employee_id', $admission_no); $data = $this->db->get()->row(); $this->load->view('documents/experience-letter-male', ['data' => $data]); } public function autocomplete_emp_id() { if ($this->input->is_ajax_request()) { $query = $this->input->get('query'); $this->load->database(); $this->db->select('emp_id, employee_id, first_name ,last_name'); $this->db->from('employees'); if (!empty($query)) { $this->db->group_start(); $this->db->like('employee_id', $query); $this->db->or_like('first_name', $query); $this->db->group_end(); } $this->db->limit(10); $result = $this->db->get()->result_array(); echo json_encode($result); exit; } show_404(); } public function get_employee_data() { $admission_no = $this->input->get('admission_no'); $this->load->database(); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employee_id', $admission_no); $data = $this->db->get()->row(); $this->load->view('documents/offer-letter', ['data' => $data]); } public function get_employee_data_third_party() { $admission_no = $this->input->get('admission_no'); $this->load->database(); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employee_id', $admission_no); $data = $this->db->get()->row(); $this->load->view('documents/thirdParty-offer-letter', ['data' => $data]); } public function Revision_remuneration(){ $admin_id = $this->session->userdata('admin_id'); if($admin_id) { $data['company_details']=$this->yaskawa_model->fetch_company_details(); $this->load->view('documents/Revision_remuneration',$data); } else { redirect('/'); } } public function get_employee_data1() { $admission_no = $this->input->get('admission_no'); $this->load->database(); $this->db->select('*'); $this->db->from('employees'); $this->db->where('employee_id', $admission_no); $data = $this->db->get()->row(); $this->load->view('documents/Revision-remuneration-letter', ['data' => $data]); } // public function save_certificate() { // $data = array( // 'date'=>$this->input->post('date'), // 'first_name' => $this->input->post('first_name'), // 'date_of_joining' => $this->input->post('date_of_joining'), // 'end_date' => $this->input->post('end_date'), // 'designation' => $this->input->post('designation'), // 'salary' => $this->input->post('salary'), // 'employee_id'=>$this->input->post('employee_id'), // ); // $first_name=$this->input->post('first_name'); // $insert_id = $this->Certificate_model->insert_certificate($data); // if ($insert_id) { // // Include mPDF // require_once FCPATH . 'vendor/autoload.php'; // $mpdf = new \Mpdf\Mpdf(['format' => 'A4']); // // Generate HTML for the PDF // $html = ' // <!DOCTYPE html> // <html lang="en"> // <head> // <meta charset="UTF-8"> // <title>Experience Certificate</title> // <style> // body { // font-family: Arial, sans-serif; // margin: 40px; // } // .container { // width: 100%; // max-width: 800px; // margin: 0 auto; // text-align: justify; // } // .date { // text-align: right; // font-size: 16px; // font-weight: bold; // } // .header { // text-align: center; // font-size: 24px; // font-weight: bold; // text-decoration: underline; // margin: 20px 0; // } // .content { // font-size: 18px; // line-height: 1.6; // } // .signature { // margin-top: 50px; // font-size: 18px; // font-weight: bold; // text-align: left; // } // </style> // </head> // <body> // <div class="container"> // <p class="date" style="float:right;">Date: ' . htmlspecialchars($data['date']) . '</p> // <h2 class="header">To Whom so ever It May Concern</h2> // <p class="content"> // This is to certify that <b>Ms. ' . htmlspecialchars($data['first_name']) . '</b> // has worked with us from <b>' . htmlspecialchars($data['date_of_joining']) . '</b> // to <b>' . htmlspecialchars($data['end_date']) . '</b>. // At the time of leaving our organization, she was designated as // <b>' . htmlspecialchars($data['designation']) . '</b>. Her last drawn salary was // <b>Rs. ' . htmlspecialchars($data['salary']) . '</b>. // </p> // <p class="content"> // During her tenure, we found her to be regular, honest, and diligent in her duties and responsibilities. // We wish her all success in her future endeavors. // </p> // <div class="signature"> // <p>Ajay Kumar HS</p> // <p>CEO</p> // <p>Jay Blues Technologies</p> // </div> // </div> // </body> // </html>'; // // Ensure directory exists // $upload_path = FCPATH . "uploads/certificates/"; // if (!is_dir($upload_path)) { // mkdir($upload_path, 0777, true); // } // // Define PDF save path // $pdf_path = $upload_path . "experience_certificate_{$first_name}.pdf"; // // Generate and save the PDF // $mpdf->WriteHTML($html); // $mpdf->Output($pdf_path, \Mpdf\Output\Destination::FILE); // echo json_encode(['status' => 'success', 'message' => 'Certificate saved successfully!', 'pdf' => base_url("uploads/certificates/certificate_{$insert_id}.pdf")]); // } else { // echo json_encode(['status' => 'error', 'message' => 'Failed to save certificate.']); // } // } public function save_certificate() { $data = array( 'date' => $this->input->post('date'), 'first_name' => $this->input->post('first_name'), 'date_of_joining' => $this->input->post('date_of_joining'), 'end_date' => $this->input->post('end_date'), 'designation' => $this->input->post('designation'), 'salary' => $this->input->post('salary'), 'employee_id' => $this->input->post('employee_id'), ); $first_name = $this->input->post('first_name'); $insert_id = $this->Certificate_model->insert_certificate($data); if ($insert_id) { // Include mPDF require_once FCPATH . 'vendor/autoload.php'; $mpdf = new \Mpdf\Mpdf(['format' => 'A4']); $html = ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Experience Certificate</title> <style> body { font-family: Arial, sans-serif; margin: 40px; } .container { width: 90%; max-width: 450px; margin: 150px auto !important; padding: 20px; text-align: justify; } .date { text-align: left; font-size: 16px; font-weight: bold; margin-bottom: 10px; margin-top:60px; } .header { text-align: center; font-size: 22px; /* Slightly reduce size */ font-weight: bold; text-decoration: underline; margin: 30px 0; /* Increase top margin */ } .content { font-size: 16px; /* Reduce font size for better fit */ line-height: 1.5; margin-top: 20px; } .signature { margin-top: 40px; font-size: 16px; font-weight: bold; text-align: left; } </style> </head> <body> <div class="container"> <p class="date" >Date: ' . htmlspecialchars($data['date']) . '</p> <h2 class="header">To Whom so ever It May Concern</h2> <p class="content"> This is to certify that <b>Ms. ' . htmlspecialchars($data['first_name']) . '</b> has worked with us from <b>' . htmlspecialchars($data['date_of_joining']) . '</b> to <b>' . htmlspecialchars($data['end_date']) . '</b>. At the time of leaving our organization, she was designated as <b>' . htmlspecialchars($data['designation']) . '</b>. Her last drawn salary was <b>Rs. ' . htmlspecialchars($data['salary']) . '</b>. </p> <p class="content"> During her tenure, we found her to be regular, honest, and diligent in her duties and responsibilities. We wish her all success in her future endeavors. </p> <div class="signature"> <p>Ajay Kumar HS</p> <p>CEO</p> <p>Jay Blues Technologies</p> </div> </div> </body> </html>'; // Ensure directory exists $upload_path = FCPATH . "uploads/certificates/"; if (!is_dir($upload_path)) { mkdir($upload_path, 0777, true); } // Define PDF file name and save path $pdf_file_name = "experience_certificate_{$first_name}.pdf"; $pdf_path = $upload_path . $pdf_file_name; $pdf_url = base_url("uploads/certificates/" . $pdf_file_name); $mpdf->WriteHTML($html); $mpdf->Output($pdf_path, \Mpdf\Output\Destination::FILE); $update_data = [ 'document' => $pdf_file_name, ]; $this->Certificate_model->update_certificate($insert_id, $update_data); echo json_encode(['status' => 'success', 'message' => 'Certificate saved successfully!', 'pdf' => $pdf_url]); } else { echo json_encode(['status' => 'error', 'message' => 'Failed to save certificate.']); } } }?>