department_model = new Department_model(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); // $this->load->library('pagination'); // $this->load->library('Excel'); $this->isLoggedIn(); } /** * This function used to load the first screen of the user */ public function index() { // if($this->isAdmin() == TRUE) // { // $this->loadThis(); // } // else // { $this->department_model = new department_model(); //$searchText = $this->request->getPost('searchText'); //$data['searchText'] = $searchText; //$count = $this->department_model->departmentListing($searchText); //$returns = $this->paginationCompress ( "departmentListing/", $count, 20 ); $data['userRecords'] = $this->department_model->departmentListing(); //$searchText, $returns["page"], $returns["segment"]); $this->global['pageTitle'] = 'Department Listing'; $this->loadViews("departmentListing", $this->global, $data, NULL); //} } /** * This function is used to load the add new supplier */ function adddepartment() { //$data['payment'] = $this->department_model->getpayment(); //$data['depcode'] = $this->department_model->getdepcode(); $data['depcode'] = $this->department_model->getdepcode(); $this->global['pageTitle'] = 'AddNew Department'; $this->loadViews("adddepartment", $this->global, $data, NULL); } function savedepartment() { $DepartmentName = $this->request->getPost('DepartmentName'); $DEPCode = $this->request->getPost('DEPCode'); $HeadDept = $this->request->getPost('HeadDept'); $Createdby = $this->session->get('userId'); $chked = $this->request->getPost('IsActive'); if ($chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $department = array('DepartmentName' => $DepartmentName, 'DEPCode' => $DEPCode, 'HeadDept' => $HeadDept, 'Createdby' => $Createdby, 'IsActive' => $IsActive); $result = $this->department_model->savedepartment($department); if ($result > 0) { $this->session->setFlashdata('success', 'Department Created successfully!'); }else{ $this->session->setFlashdata('error', 'Department Record Not Created!'); } return redirect()->route('departmentListing'); } /** * This function is used to edit the department information */ function editdepartment() { $DepartmentName = $this->request->getPost('DepartmentName'); $DEPCode = $this->request->getPost('DEPCode'); $HeadDept = $this->request->getPost('HeadDept'); $Createdby = $this->session->get('userId'); $chked = $this->request->getPost('IsActive'); if ($chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $department = array('DepartmentName' => $DepartmentName, 'DEPCode' => $DEPCode, 'HeadDept' => $HeadDept, 'IsActive' => $IsActive); $result = $this->department_model->Updatedepartment($department, $DEPCode); if ($result == True) { $this->session->setFlashdata('success', 'Department Record Successfully Updated!'); }else{ $this->session->setFlashdata('error', 'Department Record Not Updated!'); } return redirect()->route('departmentListing'); } function reActivateDepartment(){ $depCode = $this->request->getGet('SID'); $updateInfo = ['IsActive' => 1]; $result = $this->department_model->reActivateDepartment($depCode , $updateInfo); return redirect()->route('departmentListing'); } function deleteDepartment(){ $depCode = $this->request->getGet('SID'); $updateInfo = ['IsActive' => 0]; $result = $this->department_model->reActivateDepartment($depCode , $updateInfo); return redirect()->route('departmentListing'); } function viewdepartment($SID = '') { //print_r('hello');die(); if ($SID == '') { $DepartmentID = $_GET['SID']; } else { $DepartmentID = $SID; } $data['department'] = $this->department_model->getDeptInfo($DepartmentID); $data['depcode'] = $this->department_model->getdepcode(); $this->global['pageTitle'] = 'Edit Department'; $this->loadViews("editdepartment", $this->global, $data, NULL); } function exportdepartment() { $exportData = $this->department_model->export_excel(); $file_name = 'Department_Details' .' '. '.xls'; //save our workbook as this file name $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Department Details'); $headers = [ 'A1'=>'Department ID','B1'=>'Department Name','C1'=>'Head Deptment ID','D1'=>'Is Active','E1'=>'Created By','F1'=>'Created Date' ]; foreach ($headers as $cell => $value) { $sheet->setCellValue($cell, $value); $sheet->getStyle($cell)->getFont()->setSize(12); $sheet->getStyle($cell)->getFont()->setBold(true); } if($exportData){ $i = 6; foreach ($exportData as $data) { $rowData = [ 'A' . $i=>$data['DEPCode'], 'B' . $i=>$data['DepartmentName'], 'C' . $i=>$data['HeadDept'], 'D' . $i=>$data['firstname'], 'E' . $i=>$data['CreatedDt'], 'F' . $i=>$data['IsActive'] ]; foreach ($rowData as $cell => $value) { $sheet->setCellValue($cell, $value); } $i++; } } // $writer = new Xlsx($spreadsheet); // $writer->save($file_name); // header("Content-Type: application/vnd.ms-excel"); // header('Content-Disposition: attachment; filename="' . basename($file_name) . '"'); // header('Expires: 0'); // header('Cache-Control: must-revalidate'); // header('Pragma: public'); // header('Content-Length:' . filesize($file_name)); // flush(); // readfile($file_name); // exit; // Clear the output buffer to prevent any other output ob_clean(); $writer = new Xlsx($spreadsheet); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="'. $file_name .'"'); header('Cache-Control: max-age=0'); header('Expires: 0'); header('Pragma: public'); $writer->save('php://output'); exit; } }