load->model('department_model'); $this->load->library('Excel'); $this->isLoggedIn(); $this->CompanyName = $this->global['CompanyName']; } /** * Index Page for this controller(default function of the class) */ public function index() { //$this->global['pageTitle'] = 'Resico : Department Details'; $this->global['pageTitle'] = $this->CompanyName.' : Department Details'; $this->loadViews("departmentListing", $this->global, NULL , NULL); } /** * To load the Department list */ function departmentListing() { // if($this->isAdmin() == TRUE) // { // $this->loadThis(); // } // else // { $this->load->model('department_model'); $data['userRecords'] = $this->department_model->departmentListing(); //$this->global['pageTitle'] = 'Resico : Department Listing'; $this->global['pageTitle'] = $this->CompanyName.' : Department Listing'; $this->loadViews("departmentListing", $this->global, $data, NULL); //} } /** * To load the add new department */ function adddepartment() { $data['depcode'] = $this->department_model->getdepcode(); //$this->global['pageTitle'] = 'Resico : Add New Department'; $this->global['pageTitle'] = $this->CompanyName.' : Add New Department'; $this->loadViews("adddepartment", $this->global,$data, NULL); } /** * To store the value of add new department */ function addNewdepartment() { $DepartmentName = $this->input->post('DepartmentName'); $DEPCode = $this->input->post('DEPCode'); $HeadDept = $this->input->post('HeadDept'); $Createdby = $this->session->userdata ( 'userId' ); $chked = $this->input->post('IsActive'); if( $chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $department = array('DepartmentName'=>$DepartmentName, 'DEPCode'=>$DEPCode, 'HeadDept'=>$HeadDept,'Createdby'=>$Createdby,'IsActive'=>$IsActive); $result = $this->department_model->addNewdepartment($department); if($result > 0) { echo ""; redirect('departmentListing','refresh'); } else { echo ""; redirect('departmentListing','refresh'); } } /** * To Convert the dateformat (date with time) and stored into DB */ function getDateformat($Val) { $date = new DateTime($Val); $retDate = $date->format('Y-m-d H:i:s'); return $retDate; } /** * To edit the department information */ function editdepartment() { $DepartmentName = $this->input->post('DepartmentName'); $DEPCode = $this->input->post('DEPCode'); $HeadDept = $this->input->post('HeadDept'); $Createdby = $this->session->userdata ( 'userId' ); $chked = $this->input->post('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) { echo ""; redirect('departmentListing','refresh'); } else { echo ""; redirect('departmentListing','refresh'); } } /** * To view the departmant information and load's the edit department screen */ function viewdepartment($SID = '') { if($SID == '') { $DepartmentID = $_GET['SID']; } else { $DepartmentID = $SID; } $data['department'] = $this->department_model->getDeptInfo($DepartmentID); $data['depcode'] = $this->department_model->getdepcode(); //$this->global['pageTitle'] = 'Resico : Edit Department'; $this->global['pageTitle'] = $this->CompanyName.' : Edit Department'; $this->loadViews("editdepartment", $this->global,$data, NULL); } /** * To export report of supplier details in excel */ function export_departmentdetails(){ $this->load->library('excel'); $this->excel->setActiveSheetIndex(0)->mergeCells('C3:H3'); $this->excel->setActiveSheetIndex(0)->getStyle('C3')->getAlignment()->applyFromArray( array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,) ); $this->excel->getActiveSheet()->setTitle('Department Details'); $this->excel->getActiveSheet()->setCellValue('C3', 'RESICO INDUSTRIES Department Details'); $this->excel->getActiveSheet()->setCellValue('C5', 'Department ID'); $this->excel->getActiveSheet()->setCellValue('D5', 'Department Name'); $this->excel->getActiveSheet()->setCellValue('E5', 'Head Deptment ID'); $this->excel->getActiveSheet()->setCellValue('F5', 'Is Active'); $this->excel->getActiveSheet()->setCellValue('G5', 'Created By'); $this->excel->getActiveSheet()->setCellValue('H5', 'Created Date'); $this->excel->getActiveSheet()->getStyle('C5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('C5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('D5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('D5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('E5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('E5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('F5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('F5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('G5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('G5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('H5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('H5')->getFont()->setBold(true); $exportData = $this->department_model->export_excel(); if ($exportData) { $i = 6; $s = 1; foreach ($exportData as $data) { $this->excel->getActiveSheet()->setCellValue('C' . $i,$data['DEPCode']); $this->excel->getActiveSheet()->setCellValue('D' . $i,$data['DepartmentName']); $this->excel->getActiveSheet()->setCellValue('E' . $i,$data['HeadDept']); $this->excel->getActiveSheet()->setCellValue('F' . $i,$data['firstname']); $this->excel->getActiveSheet()->setCellValue('G' . $i,$data['CreatedDt']); $this->excel->getActiveSheet()->setCellValue('H' . $i,$data['IsActive']); $i++; $s++; } } $filename = 'departmentdetails' .' '. '.xls'; //save our workbook as this file name header('Content-Type: application/vnd.ms-excel'); //mime type header('Content-Disposition: attachment;filename="' . $filename . '"'); //tell browser what's the file name header('Cache-Control: max-age=0'); //no cache $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); if (ob_get_contents()) ob_end_clean(); ob_start(); $objWriter->save('php://output'); } /** * To load pagenotfound view */ function pageNotFound() { //$this->global['pageTitle'] = 'Resico : 404 - Page Not Found'; $this->global['pageTitle'] = $this->CompanyName.' : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } } ?>