ria/application/controllers/department.php
2022-03-22 15:28:00 +05:30

261 lines
8.6 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Supplier Controller (supplier)
* User Class to control all user related operations.
* @author : Gandhimathi
* @version : 1.1
* @since : 12 Apr 2017
*/
class department extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('department_model');
// $this->load->library('form_validation');
// $this->load->library('pagination');
$this->load->library('Excel');
$this->isLoggedIn();
$this->CompanyName = "RESICO";
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->global['pageTitle'] = $this->CompanyName.' : Department Details';
$this->loadViews("departmentListing", $this->global, NULL , NULL);
}
/**
* This function is used to load the Department list
*/
function departmentListing()
{
// if($this->isAdmin() == TRUE)
// {
// $this->loadThis();
// }
// else
// {
$this->load->model('department_model');
//$searchText = $this->input->post('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'] = 'RESICO : 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'] = $this->CompanyName.' : AddNew Department';
$this->loadViews("adddepartment", $this->global,$data, NULL);
}
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 "<script>alert('Department Created successfully!');</script>";
redirect('departmentListing','refresh');
}
else
{
echo "<script>alert('Department Record Not Created!');</script>";
redirect('departmentListing','refresh');
}
}
function getDateformat($Val)
{
$date = new DateTime($Val);
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
/**
* This function is used 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 "<script>alert('Department Record Successfully Updated!');</script>";
redirect('departmentListing','refresh');
}
else
{
echo "<script>alert('Department Record Not Updated!');</script>";
redirect('departmentListing','refresh');
}
}
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'] = $this->CompanyName.' : Edit Department';
$this->loadViews("editdepartment", $this->global,$data, NULL);
}
/** this function can be use for excel report **/
function export_departmentdetails(){
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('Department Details');
$this->excel->getActiveSheet()->setCellValue('A1', 'Department ID');
$this->excel->getActiveSheet()->setCellValue('B1', 'Department Name');
$this->excel->getActiveSheet()->setCellValue('C1', 'Head Deptment ID');
$this->excel->getActiveSheet()->setCellValue('D1', 'Is Active');
$this->excel->getActiveSheet()->setCellValue('E1', 'Created By');
$this->excel->getActiveSheet()->setCellValue('F1', 'Created Date');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('E1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('F1')->getFont()->setSize(12);
$this->excel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true);
$exportData = $this->department_model->export_excel();
if ($exportData) {
$i = 2;
$s = 1;
foreach ($exportData as $data) {
$this->excel->getActiveSheet()->setCellValue('A' . $i,$data['DEPCode']);
$this->excel->getActiveSheet()->setCellValue('B' . $i,$data['DepartmentName']);
$this->excel->getActiveSheet()->setCellValue('C' . $i,$data['HeadDept']);
$this->excel->getActiveSheet()->setCellValue('D' . $i,$data['firstname']);
$this->excel->getActiveSheet()->setCellValue('E' . $i,$data['CreatedDt']);
$this->excel->getActiveSheet()->setCellValue('F' . $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');
}
function pageNotFound()
{
$this->global['pageTitle'] = $this->CompanyName.' : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>