Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/erp/controllers/
Upload File :
Current File : /var/www/html/mmishra/erp/controllers/hrm_controller.php

<?php
//if (!class_exists($erpController)) {
	require_once __DIR__."/erp_controller.php";
//}
class hrmController extends erpController {

    var $model;    
	
    public function __construct($model) {
		// call parent constructor
		// parent::__construct();
        // initialize variables
		
		$this->model 			= $model;
		$this->model->tupleID	= $this->tuple;

		$this->userIP 			= $this->getIP(); 			// requires in log entry			
		$this->appURL 			= $_SERVER['REQUEST_URI'];	// this is Request URI for log entry
		$this->referer 			= $_SERVER['HTTP_REFERER'];	// requires for log entry, not mandatory

		// maintain erp activity log for inner contents
		if ($_SESSION["loginID"] && strpos($this->appURL, 'inner')) {
			$this->model->erpLog($this->userIP, $this->appURL, $this->referer);
		} else if ($this->model->getMenuProtection($this->menu)) {
			print("<h1>Session expired. Please sign-in again.</h1>");
			exit;
		}			
    }

    public function __destruct() {
		
		//'Destroying: ', $this->moduleID, PHP_EOL;
        // log sql operation on corresponding table
        // call $erpModel->erpSql($sql);
        // print("Thanks.");
    }

	public function manageCadre($action, $cadreID) {
		$this->model->tableID 			= 'hrm_cadres';
		$this->model->tupleID 			= $cadreID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
            	$cadreCode				= strtoupper($_POST['cadreCode']);
				$cadreName				= ucwords(strtolower($_POST['cadreName']));
				
				$this->model->saveCadre($cadreCode,$cadreName);
                $this->model->sqlLog();
                $this->errorText 		= 'Cadre record saved successfully.';				
                break;
            case 'enable':
                // enable record
                $this->model->enableCadre();
                $this->model->sqlLog();
                $this->errorText 		= 'Cadre record enabled successfully.';
                break;
            case 'disable':
                // disable record
                $this->model->disableCadre();
                $this->model->sqlLog();
                $this->errorText 		= 'Cadre record disabled successfully.';
                break;
            case 'delete':
                // delete record
                $this->model->deleteCadre();
                $this->model->sqlLog();
                $this->errorText 		= 'Cadre record deleted successfully.';
            	break;
        }
		return $this->model->tupleID;
    }	

	public function managePayband($action, $payID) {
		$this->model->tableID 			= 'hrm_paybands';
		$this->model->tupleID 			= $payID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$payLevel				= $_POST['payLevel'];
				$minPay					= $_POST['minPay'];
				$maxPay					= $_POST['maxPay'];
				$gradePay				= $_POST['gradePay'];
				
				if ($minPay > $maxPay) {
					$tmp 				= $minPay;
					$minPay				= $maxPay;
					$maxPay 			= $tmp;
				}
				$this->model->savePayband($payLevel,$minPay,$maxPay,$gradePay);
                $this->model->sqlLog();
                $this->errorText 		= 'Payband record saved successfully.';
                break;
            case 'enable':
                // enable record
                $this->model->enablePayband();
                $this->model->sqlLog();
                $this->errorText 		= 'Payband record enabled successfully.';
                break;
            case 'disable':
                // disable record
                $this->model->disablePayband();
                $this->model->sqlLog();
                $this->errorText 		= 'Payband record disabled successfully.';
                break;
            case 'delete':
                // delete record
                $this->model->deletePayband();
                $this->model->sqlLog();
                $this->errorText 		= 'Payband record deleted successfully.';
            	break;
        }
		return $this->model->tupleID;
    }	
	
	public function manageDesignation($action, $desiID) {
		$this->model->tableID 			= 'hrm_designations';
		$this->model->tupleID 			= $desiID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$desiCode				= strtoupper($_POST['desiCode']);
				$desiEnglish			= ucwords(strtolower($_POST['desiEnglish']));
				$desiHindi				= $_POST['desiHindi'];
				$cadreID				= $_POST['cadreID'];
				
				$this->model->saveDesignation($desiCode,$desiEnglish,$desiHindi,$cadreID);
                $this->model->sqlLog();
                $this->errorText 		= 'Designation record saved successfully.';
                break;
            case 'enable':
                // enable record
                $this->model->enableDesignation();
                $this->model->sqlLog();
                $this->errorText 		= 'Designation record enabled successfully.';
                break;
            case 'disable':
                // disable record
                $this->model->disableDesignation();
                $this->model->sqlLog();
                $this->errorText 		= 'Designation record disabled successfully.';
                break;
            case 'delete':
                // delete record
                $this->model->deleteDesignation();
                $this->model->sqlLog();
                $this->errorText 		= 'Designation record deleted successfully.';
            	break;
        }
		return $this->model->tupleID;
    }	

	public function manageLeavetype($action, $leaveID) {
		$this->model->tableID 			= 'hrm_leavetypes';
		$this->model->tupleID 			= $leaveID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$leaveCode				= strtoupper($_POST['leaveCode']);
				$leaveName				= ucwords(strtolower($_POST['leaveName']));
				$payTerm				= $_POST['payTerm'];
				$yearDays				= $_POST['yearDays'];
				$accumulative			= $_POST['accumulative'];
				
				$this->model->saveLeavetype($leaveCode,$leaveName,$payTerm,$yearDays,$accumulative);
                $this->model->sqlLog();
                $this->errorText 		= 'Leavetype record saved successfully.';
                break;
            case 'enable':
                // enable record
                $this->model->enableLeavetype();
                $this->model->sqlLog();
                $this->errorText 		= 'Leavetype record enabled successfully.';
                break;
            case 'disable':
                // disable record
                $this->model->disableLeavetype();
                $this->model->sqlLog();
                $this->errorText 		= 'Leavetype record disabled successfully.';
                break;
            case 'delete':
                // delete record
                $this->model->deleteLeavetype();
                $this->model->sqlLog();
                $this->errorText 		= 'Leavetype record deleted successfully.';
            	break;
        }
		return $this->model->tupleID;
    }	

	public function manageDepartment($action, $deptID) {
		$this->model->tableID 			= 'hrm_departments';
		$this->model->tupleID 			= $deptID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$deptCode				= strtoupper($_POST['deptCode']);
				$deptName				= ucwords(strtolower($_POST['deptName']));
				$hodID					= $_POST['hodID'];
				
				$this->model->saveDepartment($deptCode,$deptName,$hodID);
                $this->model->sqlLog();
                $this->errorText 		= 'Department record saved successfully.';
                break;
            case 'enable':
                // enable record
                $this->model->enableDepartment();
                $this->model->sqlLog();
                $this->errorText 		= 'Department record enabled successfully.';
                break;
            case 'disable':
                // disable record
                $this->model->disableDepartment();
                $this->model->sqlLog();
                $this->errorText 		= 'Department record disabled successfully.';
                break;
            case 'delete':
                // delete record
                $this->model->deleteDepartment();
                $this->model->sqlLog();
                $this->errorText 		= 'Department record deleted successfully.';
            	break;
        }
		return $this->model->tupleID;
    }	

	public function manageEmployee($action, $employeeID) {
		$this->model->tableID 			= 'hrm_employees';
		$this->model->tupleID 			= $employeeID;
		switch ($action) {
            case 'new':
				break;
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
			case 'help':
			case 'trash':
				break;
			case 'save':	
                // save record
				$studentID				= $_POST['studentID'];

                // check whether new or old enrolment
				
				$accountID				= $this->model->getAccountIDByStudentID($studentID);	// not allowed to change
				if (!$accountID) 	$accountID		= 0;

				// get form values of below editable fields
				$nameEnglish			= ucwords($_POST['nameEnglish']);	// not allowed to change
				$nameHindi				= $_POST['nameHindi'];
				$fatherName				= $_POST['fatherTitle']. ' ' .ucwords($_POST['fatherName']);
				$dateBirth				= $_POST['dateBirth'];		// not allowed to change
				$gender					= $_POST['gender'];			// not allowed to change
				$pwdStatus				= $_POST['pwdStatus'];		// not allowed to change
				$bloodGroup				= $_POST['bloodGroup'];
				$maritalStatus			= $_POST['maritalStatus'];
				$category				= $_POST['category'];
				$subCategory			= $_POST['subCategory'];
				$religion				= $_POST['religion'];
				$nationality			= $_POST['nationality'];
				$aadhaarNo				= $_POST['aadhaarNo'];
				$phoneNo				= $_POST['phoneNo']; 		// unique
				$mobileNo				= $_POST['mobileNo']; 		// unique
				$email					= $_POST['email']; 
				$homeAddress 			= $_POST['homeAddress'];
				$homePIN 				= $_POST['homePIN'];
				$area					= $_POST['area'];
				$policeStation			= $_POST['policeStation'];
				$homeState				= $_POST['homeState'];		// changes for CCMT/DASA
				$homeDistrict 			= $_POST['homeDistrict'];
				$commAddress 			= $_POST['commAddress'];
				$commPIN 				= $_POST['commPIN'];
/*
				$xGrade 				= $_POST['xGrade'];
				$xYear 					= $_POST['xYear'];
				$xBoard 				= $_POST['xBoard'];
				$xiiGrade 				= $_POST['xiiGrade'];
				$xiiYear 				= $_POST['xiiYear'];
				$xiiBoard 				= $_POST['xiiBoard'];
				$ugGrade 				= $_POST['ugGrade'];
				$ugYear 				= $_POST['ugYear'];
				$ugInstitute			= $_POST['ugInstitute'];
				$pgGrade 				= $_POST['pgGrade'];
				$pgYear 				= $_POST['pgYear'];
				$pgInstitute			= $_POST['pgInstitute'];
*/
				$accountNo				= $_POST['accountNo']; 	
				$holderName				= ucwords($_POST['holderName']); 	
				$bankName				= ucwords($_POST['bankName']); 	
				$ifscCode				= strtoupper($_POST['ifscCode']); 	
				$remark					= $_POST['remark'];	// AAA may over write remark
				
				if (!$homeDistrict)		$homeDistrict 	= 0;
				if (!$homePIN) 			$homePIN		= 0;
				if (!$commPIN)			$commPIN		= 0;
				if (!$xYear) 			$xYear 			= 0;
				if (!$xiiYear) 			$xiiYear		= 0;
				if (!$ugYear) 			$ugYear			= 0;
				if (!$pgYear) 			$pgYear			= 0;
				if (!$hbookNo)			$hbookNo		= 0;
				
				// save student record with phoneNo unique key
				$employeeID = $this->model->saveEmployee($employeeID,$employeeNo,$nameEnglish,$nameHindi,$dateBirth,$gender,$bloodGroup,$pwdStatus,$maritalStatus,$category,$subCategory,$religion,$nationality,$aadhaarNo,$phoneNo,$mobileNo,$email,$homeAddress,$homePIN,$homeState,$homeDistrict,$area,$policeStation,$commAddress,$commPIN,$remark);
				$this->model->sqlLog();
				$this->errorText= $employeeNo. ' record saved successfully.';
				break;
			case 'mail':
            case 'delete':
                // delete record
                //$this->model->deleteEmployee();
                //$this->model->sqlLog();
                $this->errorText 		= 'Employee record deletion not permitted';//ed successfully.';
            	break;
			case 'excel':
				$rows 					= $this->model->listEmployees($cadreID);
				foreach ($rows as $row) {
					$i++;	
					$j = 0;			
					$vals = '';
					foreach ($row as $key => $value) {
						$j++;
						if ($j > 1) {
							if ($i == 1) $colh .= '"' .ucfirst($key). '",';
							$vals .= '"' .$value. '",';
						}
					}
					$colv .= rtrim($vals, -1). "\n";
				}
				$data 					= rtrim($colh, -1). "\n" .$colv;
				$f 						= fopen('uploads/excel-' .$cadreID. '.csv' , 'wb');
				fwrite($f , $data);
				fclose($f);
				break;
        }
		return $this->model->tupleID;
    }	

	


}
?>