siddharth_application/application/controllers/user.php

1574 lines
49 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : User (UserController)
* User Class to control all user related operations.
* @author : Kishor Mali
* @version : 1.1
* @since : 15 November 2016
*/
class user extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->model('dahsboard_Model');
$this->load->library('form_validation');
$this->load->model('costcenter_model');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the user
*/
public function index()
{
// echo 'dash';
// print_r($this->session->userdata ( 'name' ));
log_message('ERROR','#####Dashboard session name : ' . $this->session->userdata ( 'name' ));
//print_r($this->dummy);//die();
$this->global['pageTitle'] = 'Siddharth : Dashboard';
$this->load->model('employeedetails_model');
$this->load->model('dahsboard_Model');
$data['EmpCount'] = $this->employeedetails_model->getEmployeeCount();
$data['totalpurchaseorder']=$this->dahsboard_Model->totalpurchaseorder();
//print_r( $data['totalpurchaseorder']);
$data['totalordervalue']=$this->dahsboard_Model->totalordervalue();
$data['pendingpo']=$this->dahsboard_Model->pendingpo();
// $data['totalserviceamount']=$this->dahsboard_Model->totalserviceamount();
// $data['totalcapitalamount']=$this->dahsboard_Model->totalcapitalamount();
// $data['totalimportamount']=$this->dahsboard_Model->totalimportamount();
// $data['totalrevenueamount']=$this->dahsboard_Model->totalrevenueamount();
// $data['totalservicepo']=$this->dahsboard_Model->totalservicepo();
// $data['totalrevenuepo']=$this->dahsboard_Model->totalrevenuepo();
$data['totalimportpo']=$this->dahsboard_Model->totalimportpo();
//$data['totalcapitalpo']=$this->dahsboard_Model->totalcapitalpo();
$data['details']=$this->dahsboard_Model->reqdetail();
$data['pending_details']=$this->dahsboard_Model->req_pending();
// $data['list']=$this->dahsboard_Model->req_list();
$data['serviceprogress']=$this->dahsboard_Model->serviceprogress();
$data['revenueprogress']=$this->dahsboard_Model->revenueprogress();
$data['importprogress']=$this->dahsboard_Model->importprogress();
$data['capitalprogress']=$this->dahsboard_Model->capitalprogress();
//month-wise area chart
$data['getTotalServicePoCount'] = $this->dahsboard_Model->getTotalServicePoCount();
$data['getTotalimportPoCount'] = $this->dahsboard_Model->getTotalimportPoCount();
$data['getTotalcapitalPoCount'] = $this->dahsboard_Model->getTotalcapitalPoCount();
$data['getTotalrevenuePoCount'] = $this->dahsboard_Model->getTotalrevenuePoCount();
//dashboard pie chart
$data['importbudgt'] = $this->dahsboard_Model->importbudgt();
$data['servicebudgt'] = $this->dahsboard_Model->servicebudgt();
$data['revenuebudgt'] = $this->dahsboard_Model->revenuebudgt();
$data['capitalbud'] = $this->dahsboard_Model->capitalbud();
$data['typebal'] = $this->dahsboard_Model->typebal();
/* HR DASHBOARD Controller Start*/
$data['totemp'] = $this->dahsboard_Model->totemp();
$data['totloan'] = $this->dahsboard_Model->totloan();
$data['totpay'] = $this->dahsboard_Model->totpay();
$data['totrec'] = $this->dahsboard_Model->totrec();
$data['emplist'] = $this->dahsboard_Model->emplist();
//print_r($data['totemp']);die;
$date = $this->input->post("id");
$dates = date('Y-m');
$date = $dates . '-01';
// // // echo $date;
$dat = date('d', strtotime("-1 days"));
// //echo $date;
$WH = 'WH' . date('j', strtotime("-1 days"));
$yesterday = $this->dahsboard_Model->attyesterday($WH, $date);
//print_r($yesterday);die;
// echo $values;
//$data['today'] = sizeof($yesterday);
// $date = $this->input->post("id");
// echo $date;
$daydate = date('Y-m',strtotime($date));
//echo $date; die;
$daydate = $daydate . '-01';
$yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate);
// print_r($yesterday);
//$absEmp =array($absEmp);
$values = 0;
$absEmp = array();
//echo $value; die;
foreach ($yesterday as $weekda => $value)
{
// echo $value[$WH];
if ($value[$WH] == 0)
{
$values++;
$absendId = $value['EmpID'];
$absendName = $value['FirstName'];
$absEmp [] = $absendId . "-" . $absendName; //absend empid and name list
}
}
//print_r($absentName);die;
$data['today'] = sizeof($absEmp);
$data['abs_name'] = $absEmp;
$OT = 'OT' . date('j',strtotime($date));
$CUR_month = date('t');
//echo $CUR_month;
//echo $daydate;
$toDayEmployee = $this->dahsboard_Model->yesterdayAllPersentEmpSalary($WH, $OT, $daydate);
//$EmpID = $toDayEmployee[0]->EmpID;
//print_r($toDayEmployee); die;
$EmpID = 0;
$employeeSalary = 0;
foreach ($toDayEmployee as $value)
{
$values = 0;
$totalothour = 0;
if ($value[$WH] != 0)
{
$totalothour = $value[$OT];
//echo $totalothour;die;
$values = 1;
//print_r($values); die;
$Empid = $value['EmpID'];
//print_r($value['EmpID']);
$totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid);
// echo $Empid;
// print_r($totalEmployeePersent);
if(!empty($totalEmployeePersent))
{
$HRA_Amount = $totalEmployeePersent[0]->HRA_Amount;
$Basic_Pay = $totalEmployeePersent[0]->Basic_Pay;
$totalsalary = $totalEmployeePersent[0]->TotalSalary;
$dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances;
//$allowances =$totalEmployeePersent[0]->Allowances;
//echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary));
//$Allowances = $allowances * $values;
$Food_Allowances = $dayFoodAmt * $values;
$daySalary = $Basic_Pay / $CUR_month;
/**per day salary working hour**/
//echo $daySalary.'<br/>';
$dayHra = $HRA_Amount / $CUR_month;
/** per day hra amount **/
//echo $dayHra.'<br/>';
$onehoursSalary = ($daySalary + $dayHra) / 8;
/**one hour salay ot calculation**/
if ($totalothour != 0) /** if ot not equal zero **/
{
$totSalayOT = $totalothour * $onehoursSalary;
}
else
{
$totSalayOT = 0;
}
$currentDaySalary = $daySalary * $values;
/** current day salary working days calculation**/
$currentDayHra = $dayHra * $values;
/** total working days hra calculations**/
// echo $currentDayHra.'<br/>';
$currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT;
/** current date pf calculation**/
if ($totalsalary <= 20000)
{
$esiAmount = $currentDatePF * 1.75 / 100;
/** esiamount not elgiable for 20000 **/
}
else
{
$esiAmount = 0;
}
$pfAmount = $currentDaySalary * 12 / 100;
/** pf amount per day**/
//echo $totalothour;die;
$salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances;
$salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount);
$employeeSalary += round($salaryInCurrentday);
}
// echo $employeeSalary;
}
}
//$salaryInCurrentday++;
$data['employeeSalary'] = $employeeSalary;
$working = array();
$overtime = array();
//$holid = array();
for ($i = 1; $i <= $dat; $i++) //echo $dat; die;
{
$Working [] = 'WH' . $i;
$overtime [] = 'OT' . $i;
$CUR_month = date('t');
// echo $CUR_month; die;
// foreach ($holiday as $value)
// {
// //$holid []= 'WH'.$value;
// if($i==$value) {
// $holid []=$value;
// }
// }
}
//print_r($WH);die;
$WH = implode(",", $Working);
$OT = implode(",", $overtime);
$salarycurrentdate = array();
$toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $date);
$totalSalary = 0;
$working = explode(",", $WH);
$overtime = explode(",", $OT);
foreach ($toDayEmployee as $value)
{
$values = 0;
foreach ($working as $work)
{
// foreach ($overtime as $extra) {
if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0)
{
$totalothour = $value['OT' . substr($work, 2)];
//echo $totalothour;
$values = 1;
//print_r($values); die;
$Empid = $value['EmpID'];
//echo $Empid;
$totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid);
if(!empty($totalEmployeePersent))
{
$HRA_Amount = $totalEmployeePersent[0]->HRA_Amount;
$Basic_Pay = $totalEmployeePersent[0]->Basic_Pay;
$totalsalary = $totalEmployeePersent[0]->TotalSalary;
$dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances;
//$allowances =$totalEmployeePersent[0]->Allowances;
// $Allowances = $allowances * $values;
$Food_Allowances = $dayFoodAmt * $values;
$daySalary = $Basic_Pay / $CUR_month;
/**per day salary working hour**/
//echo $daySalary.'<br/>';
$dayHra = $HRA_Amount / $CUR_month;
/** per day hra amount **/
//echo $dayHra.'<br/>';
$onehoursSalary = ($daySalary + $dayHra) / 8;
/**one hour salay ot calculation**/
if ($totalothour != 0) /** if ot not equal zero **/
{
$totSalayOT = $totalothour * $onehoursSalary;
}
else
{
$totSalayOT = 0;
}
$currentDaySalary = $daySalary * $values;
/** current day salary working days calculation**/
$currentDayHra = $dayHra * $values;
/** total working days hra calculations**/
// echo $currentDayHra.'<br/>';
$currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT;
/** current date pf calculation**/
if ($totalsalary <= 20000)
{
$esiAmount = $currentDatePF * 1.75 / 100;
/** esiamount not elgiable for 20000 **/
} else {
$esiAmount = 0;
}
$pfAmount = $currentDaySalary * 12 / 100;
/** pf amount per day**/
//echo $totalothour;die;
$salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ;
$salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount);
$totalSalarys = $totalSalary + $salaryInCurrentday;
$totalSalary = round($totalSalarys);
// $salarycurrentdate[] = $salaryInCurrentday;;
// echo 'totalSalary';
}
}
}
}
$data['totalSalary'] = $totalSalary;
// print_r( 'totalSalary');die;
$this->loadViews("dashboard", $this->global, $data, NULL);
}
/*date click on day salary,absent name, total absent display*/
function dateFunctionChangeVales()
{
$date = $this->input->post("id");
$dates = date('Y-m');
$date = $dates . '-01';
// // echo $date;
// $dat = date('d', strtotime("-1 days"));
//echo $date;
$WH = 'WH' . date('j', strtotime("-1 days"));
//echo($WH);
$yesterday = $this->dahsboard_Model->attyesterday($WH, $date);
//print_r($yesterday);die;
$values = 0;
foreach ($yesterday as $weekda => $value)
{
if ($value[$WH] == 0)
{
$values++;
}
}
// echo $values;
$data['values'] = $values;
$date = $this->input->post("id");
// echo $date;
$daydate = date('Y-m',strtotime($date));
//echo $date; die;
$daydate = $daydate . '-01';
//$dat = date('d');
// echo $daydate; echo "";
$WH = 'WH' . date('j',strtotime($date));
// echo $WH;
$yesterday = $this->dahsboard_Model->attyesterday($WH, $daydate);
// print_r($yesterday);
//$absEmp =array($absEmp);
$values = 0;
$absEmp = array();
//echo $value; die;
foreach ($yesterday as $weekda => $value)
{
// echo $value[$WH];
if ($value[$WH] == 0)
{
$values++;
$absendId = $value['EmpID'];
$absendName = $value['FirstName'];
$absEmp [] = $absendId . "-" . $absendName; //absend empid and name list
}
}
//print_r($absentName);die;
$data['today'] = $values;
$data['absname'] = $absEmp;
$OT = 'OT' . date('j',strtotime($date));
$CUR_month = date('t');
//echo $CUR_month;
//echo $daydate;
$toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate);
//$EmpID = $toDayEmployee[0]->EmpID;
//print_r($toDayEmployee); die;
$EmpID = 0;
$employeeSalary = 0;
foreach ($toDayEmployee as $value)
{
$values = 0;
$totalothour = 0;
if ($value[$WH] != 0)
{
$totalothour = $value[$OT];
//echo $totalothour;die;
$values = 1;
//print_r($values); die;
$Empid = $value['EmpID'];
//print_r($value['EmpID']);
$totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid);
// echo $Empid;
// print_r($totalEmployeePersent);
if(!empty($totalEmployeePersent))
{
$HRA_Amount = $totalEmployeePersent[0]->HRA_Amount;
$Basic_Pay = $totalEmployeePersent[0]->Basic_Pay;
$totalsalary = $totalEmployeePersent[0]->TotalSalary;
$dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances;
//$allowances =$totalEmployeePersent[0]->Allowances;
//echo "hra amount";print_r(array($HRA_Amount,$Basic_Pay,$totalsalary));
//$Allowances = $allowances * $values;
$Food_Allowances = $dayFoodAmt * $values;
$daySalary = $Basic_Pay / $CUR_month;
/**per day salary working hour**/
//echo $daySalary.'<br/>';
$dayHra = $HRA_Amount / $CUR_month;
/** per day hra amount **/
//echo $dayHra.'<br/>';
$onehoursSalary = ($daySalary + $dayHra) / 8;
/**one hour salay ot calculation**/
if ($totalothour != 0) /** if ot not equal zero **/
{
$totSalayOT = $totalothour * $onehoursSalary;
} else {
$totSalayOT = 0;
}
$currentDaySalary = $daySalary * $values;
/** current day salary working days calculation**/
$currentDayHra = $dayHra * $values;
/** total working days hra calculations**/
// echo $currentDayHra.'<br/>';
$currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT;
/** current date pf calculation**/
if ($totalsalary <= 20000)
{
$esiAmount = $currentDatePF * 1.75 / 100;
/** esiamount not elgiable for 20000 **/
} else {
$esiAmount = 0;
}
$pfAmount = $currentDaySalary * 12 / 100;
/** pf amount per day**/
//echo $totalothour;die;
$salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances;
$salaryInCurrentday = $salaryInCurrentdays - ($esiAmount + $pfAmount);
$employeeSalary += round($salaryInCurrentday);
}
// echo $employeeSalary;
}
}
//$salaryInCurrentday++;
$data['employeeSalary'] = $employeeSalary;
$working = array();
$overtime = array();
//$holid = array();
$len = date('d',strtotime($date));
for ($i = 1; $i <= $len; $i++) //echo $dat; die;
{
$Working [] = 'WH' . $i;
$overtime [] = 'OT' . $i;
$CUR_month = date('t');
// echo $CUR_month; die;
// foreach ($holiday as $value)
// {
// //$holid []= 'WH'.$value;
// if($i==$value) {
// $holid []=$value;
// }
// }
}
//print_r($Working);die;
$WH = implode(",", $Working);
$OT = implode(",", $overtime);
$salarycurrentdate = array();
$toDayEmployee = $this->dahsboard_Model->dayAllPersentEmpSalary($WH, $OT, $daydate);
$totalSalary = 0;
$working = explode(",", $WH);
$overtime = explode(",", $OT);
foreach ($toDayEmployee as $value)
{
$values = 0;
foreach ($working as $work)
{
// foreach ($overtime as $extra) {
if ($value[$work] != 0 || $value['OT' . substr($work, 2)] != 0)
{
$totalothour = $value['OT' . substr($work, 2)];
//echo $totalothour;
$values = 1;
//print_r($values); die;
$Empid = $value['EmpID'];
//echo $Empid;
$totalEmployeePersent = $this->dahsboard_Model->persentEmployeeDetails($Empid);
if(!empty($totalEmployeePersent))
{
$HRA_Amount = $totalEmployeePersent[0]->HRA_Amount;
$Basic_Pay = $totalEmployeePersent[0]->Basic_Pay;
$totalsalary = $totalEmployeePersent[0]->TotalSalary;
$dayFoodAmt = $totalEmployeePersent[0]->Food_Allowances;
//$allowances =$totalEmployeePersent[0]->Allowances;
// $Allowances = $allowances * $values;
$Food_Allowances = $dayFoodAmt * $values;
$daySalary = $Basic_Pay / $CUR_month;
/**per day salary working hour**/
//echo $daySalary.'<br/>';
$dayHra = $HRA_Amount / $CUR_month;
/** per day hra amount **/
//echo $dayHra.'<br/>';
$onehoursSalary = ($daySalary + $dayHra) / 8;
/**one hour salay ot calculation**/
if ($totalothour != 0) /** if ot not equal zero **/
{
$totSalayOT = $totalothour * $onehoursSalary;
}
else
{
$totSalayOT = 0;
}
$currentDaySalary = $daySalary * $values;
/** current day salary working days calculation**/
$currentDayHra = $dayHra * $values;
/** total working days hra calculations**/
// echo $currentDayHra.'<br/>';
$currentDatePF = $currentDaySalary + $currentDayHra + $totSalayOT;
/** current date pf calculation**/
if ($totalsalary <= 20000)
{
$esiAmount = $currentDatePF * 1.75 / 100;
/** esiamount not elgiable for 20000 **/
} else {
$esiAmount = 0;
}
$pfAmount = $currentDaySalary * 12 / 100;
/** pf amount per day**/
//echo $totalothour;die;
$salaryInCurrentdays = $currentDaySalary + $totSalayOT + $currentDayHra + $Food_Allowances ;
$salaryInCurrentday = $salaryInCurrentdays -($esiAmount+$pfAmount);
$totalSalarys = $totalSalary + $salaryInCurrentday;
$totalSalary = round($totalSalarys);
// $salarycurrentdate[] = $salaryInCurrentday;;
// echo 'totalSalary';
}
}
}
}
$data['totalSalary'] = $totalSalary;
//print_r($data['totalSalary']);die;
// }
echo json_encode($data);
}
/*this function uesd to finance startdate */
public function getFinancialStartDate()
{
$CURMONTH = date('n');
$CURYEAR = date('Y');
$FINYEAR = 0;
if ($CURMONTH >= 4)
{
$FINYEAR = $CURYEAR;
} else
{
$FINYEAR = $CURYEAR - 1;
}
$dateInString = $FINYEAR . '-4-1';
$result = date_create($dateInString);
// print_r($result);
return $result;
}
/*this function uesd to finance EndDate */
public function getFinancialEndDate()
{
$CURMONTH = date('n');
$CURYEAR = date('Y');
$FINYEAR = 0;
if ($CURMONTH < 4)
{
$FINYEAR = $CURYEAR;
} else
{
$FINYEAR = $CURYEAR + 1;
}
$dateInString = $FINYEAR . '-3-31';
$result = date_create($dateInString);
// print_r($result);
return $result;
}
/*this function used to speedometer month emp performances display*/
function monthattendance($empID ='')
{
$date = date('Y-m');
//echo $date;
$dates = $date . '-01';
$EmpID = '';
if(empty($empID)){
$EmpID = $this->input->post('id');
}
else
{
$EmpID = $empID;
}
// echo $EmpID;die;
$monthabs = $this->dahsboard_Model->attendance($EmpID, $dates);
$persent_month = date('t');//current month of days 31
$values = array();
$otvalues = array();
$weekdays = array();
$otHours = array();
$date = date('j');//current month current date
$CURDATE =date('d');//current month current date
$CUR_month = date('t'); //current month of days 31
$CURYEAR = date('Y');
$CURMONTH = date('m');
$datejoin = $this->dahsboard_Model->joindate($EmpID);
$DateofJoiningInString = $datejoin[0]->DateofJoining;
$DateofJoining = date_create($DateofJoiningInString);
$doj_month = date_format($DateofJoining, "n");
$doj_year = date_format($DateofJoining, "Y");
$doj_day = date_format($DateofJoining, "j");
//echo $doj_day;
for ($i = 1; $i <= $persent_month; $i++)
{
$weekdays[] = 'WH' . $i;
$otHours[] = 'OT' . $i;
}
$totalwhhours=0;
foreach ($monthabs as $weekda)
{
//print_r($weekda);
foreach ($weekda as $key => $value)
{
//print_r($key);
foreach ($weekdays as $weeks)
{
if ($weeks == $key)
{
//print_r($key);
if ($value != 0)
{
//echo $value;
$values[] = $value;
}
//echo $values;
}
}
foreach ($otHours as $ot)
{
if ($ot == $key)
{
if ($value != 0)
{
$otvalues [] = $value;
}
}
}
}
}
$totalothour = array_sum($otvalues);
//$totalwhhour = sizeof($values);
$totalwhhours = array_sum($values);
$totalwhhour = $totalwhhours/8;
//echo $totalwhhour;
if ($CURMONTH == $doj_month && $CURYEAR == $doj_year)
{
//echo $doj_day;
$data['CUR_month'] = $CURDATE - $doj_day + 1;
//print_r($month);
}
else
{
$data['CUR_month'] = $date;
}
if ($totalwhhour != 0)
{
$year = date('Y');
$current_month = date('m');
$data['values'] = $totalwhhour;
//$data['salaryInCurrentday'] = round($salaryInCurrentday);
$data['present_percentage'] = round(($totalwhhour / $data['CUR_month']) * 100);
}
else {
$data['values'] = 0;
//$data['salaryInCurrentday'] = 0;
$data['present_percentage'] = 0;
}
if(empty($empID)){
echo json_encode( $data);
}
else{
return $data;
}
}
/*this function used to speedometer year emp performances display*/
function attendanceyear($empID ='')
{
$CURMONTH = date('m');
$CURDATE = date('d');
$CURYEAR = date('Y');
$EmpID = '';
if(empty($empID))
{
$EmpID = $this->input->post('id');
}
else
{
$EmpID = $empID;
}
$day = array();
$datejoin = $this->dahsboard_Model->joindate($EmpID);
$DateofJoiningInString = $datejoin[0]->DateofJoining;
$DateofJoining = date_create($DateofJoiningInString);
// print_r($DateofJoining);
$doj_month = date_format($DateofJoining, "n");
$doj_year = date_format($DateofJoining, "Y");
$doj_day = date_format($DateofJoining, "j");
$finStart = $this->getFinancialStartDate();
$finEnd = $this->getFinancialEndDate();
$JoinedMonth = date_format($DateofJoining, "n");
// print_r($finStart);print_r($finEnd);
//print $JoinedMonth;
if ($DateofJoining >= $finStart && $DateofJoining <= $finEnd)
{
$JoinedMonthAttendance = $this->dahsboard_Model->getAllAttendances($EmpID,$JoinedMonth);
$joinedMonthDaysCount = cal_days_in_month(CAL_GREGORIAN, $doj_month, $doj_year);
if ($CURMONTH == $doj_month && $CURYEAR == $doj_year)
{
$joinedMonthWorkingDayCount = $CURDATE - $doj_day +1 ;
}
else
{
$joinedMonthWorkingDayCount = $joinedMonthDaysCount - $doj_day +1;
}
$joinedMonthDays = 0;
for ($j = $doj_day; $j <= $joinedMonthDaysCount; $j++)
{
$weekdays[] = 'WH' . $j;
}
foreach ($JoinedMonthAttendance as $day)
{
foreach ($day as $key => $value)
{
foreach ($weekdays as $weeks)
{
if ($weeks == $key)
{
if ($value != 0)
{
// echo $value;
$joinedMonthDays++;
}
}
}
}
}
//echo $joinedMonthDays;die;
$result = $this->dahsboard_Model->attendanceyear($EmpID, $JoinedMonth + 1);
//print_r($result);
$yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH);
$TotalNoofDays = $result[0]->TotalWorkingDays;
$DaysWorked = $result[0]->DaysWorked;
// echo $TotalNoofDays;
// echo $DaysWorked;die;
$values = 0;
$values = array();
$weekdays = array();
$date = date('d');
$Work = array_sum($weekdays);
for ($j = 1; $j <= $date; $j++)
{
$weekdays[] = 'WH' . $j;
}
$totalhours =0;
foreach ($yearabs as $day)
{
foreach ($day as $key => $value)
{
foreach ($weekdays as $weeks)
{
if ($weeks == $key)
{
if ($value != 0)
{
//$values++;
//$totalhours = array_sum($value);
$values[] = $value;
}
}
}
}
}
$DaysWorked = 0;
$totalhours = array_sum($values);
$values = $totalhours/8;
//print_r($totalhours);
if ($CURMONTH == $doj_month && $CURYEAR == $doj_year)
{
$TotalNoofDays = $TotalNoofDays + $joinedMonthWorkingDayCount;
$DaysWorked = $joinedMonthDays;
}
else
{
$TotalNoofDays = $TotalNoofDays + $CURDATE + $joinedMonthWorkingDayCount;
$DaysWorked = $DaysWorked + $joinedMonthDays + $values;
}
$final_res = round(($DaysWorked / $TotalNoofDays) * 100);
// echo "------";
//echo $final_res;exit();
$data['workeds'] = $DaysWorked;
$data['yeardata'] = $final_res;
$data['totaldays'] = $TotalNoofDays;
}
else
{
$result = $this->dahsboard_Model->attendanceyear($EmpID, 4);
$yearabs = $this->dahsboard_Model->getAllAttendance($EmpID, $CURMONTH);
$TotalNoofDays = $result[0]->TotalWorkingDays;
$DaysWorked = $result[0]->DaysWorked;
$values = 0;
$values = array();
$weekdays = array();
$date = date('d');
$Work = array_sum($weekdays);
for ($j = 1; $j <= $date; $j++)
{
$weekdays[] = 'WH' . $j;
}
foreach ($yearabs as $day)
{
foreach ($day as $key => $value)
{
foreach ($weekdays as $weeks)
{
if ($weeks == $key)
{
if ($value != 0)
{
$values[]=$value;
}
}
}
}
}
$totalhours = array_sum($values);
$values = $totalhours/8;
$TotalNoofDays = $TotalNoofDays + $CURDATE;
$DaysWorked = $DaysWorked + $values;
$final_res = round(($DaysWorked / $TotalNoofDays) * 100);
// echo "------";
//echo $final_res;exit();
$data['workeds'] = $DaysWorked;
$data['yeardata'] = $final_res;
$data['totaldays'] = $TotalNoofDays;
}
if(empty($empID))
{
echo json_encode($data);
}
else
{
return $data;
}
}
/****************HR DASHBOART Controller END **************************************/
/**
* This function is used to load the user list
*/
function userListing()
{
// if($this->isAdmin() == TRUE)
// {
// $this->loadThis();
// }
// else
// {
$data['userRecords'] = $this->user_model->userListing();
$this->global['pageTitle'] = 'Siddharth : User Listing';
$this->loadViews("users", $this->global, $data, NULL);
//}
}
/**
* This function is used to load the add new form
*/
function addNew()
{
// if($this->isAdmin() == TRUE)
// {
// $this->loadThis();
// }
// else
// {
$data['EmpList'] = $this->user_model->getAllEmployees();
$data['roles'] = $this->user_model->getUserRoles();
$data['Department'] = $this->costcenter_model->getDepartment();
$this->global['pageTitle'] = 'Siddharth : Add New User';
$this->loadViews("addNew", $this->global, $data, NULL);
// }
}
/**
* This function is used to check whether email already exist or not
*/
function checkEmailExists()
{
$userId = $this->input->post("userId");
$email = $this->input->post("email");
if(empty($userId)){
$result = $this->user_model->checkEmailExists($email);
} else {
$result = $this->user_model->checkEmailExists($email, $userId);
}
if(empty($result)){ echo("true"); }
else { echo("false"); }
}
/* Validation for Employee Dropdown
*/
function Employee_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if($selectValue == '0')
{
$this->form_validation->set_message('Employee_validate', 'Please Select Employee.');
return false;
}
else // user picked something
{
return true;
}
}
/* Validation for Employee Dropdown
*/
function Role_validate($selectValue)
{
//echo 'select_validate method called';
// 'none' is the first option and the text says something like "-Choose one-"
if($selectValue == '0')
{
$this->form_validation->set_message('Role_validate', 'Please Select Role.');
return false;
}
else // user picked something
{
return true;
}
}
/**
* This function is used to add new user to the system
*/
function addNewUser()
{
// if($this->isAdmin() == TRUE)
// {
// $this->loadThis();
// }
// else
// {
$this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS');
// $this->form_validation->set_rules('role','role','trim|callback_Role_validate');
$this->form_validation->set_rules('password','Password','required|max_length[20]');
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]');
if($this->form_validation->run() == FALSE)
{
$this->addNew();
}
else
{
$EmpID = $this->input->post('EmpList');
$roleId = '2';
$password = $this->input->post('password');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Createddt = $dt->format('Y-m-d H:i:s');
$email = $this->input->post('MailID');
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
$comma_separated = explode(':', $SelectedDepartment);
$userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt);
//die();
$result = $this->user_model->addNewUser($userInfo);
if($SelectedDepartment != '')
{
for ($j = 0; $j < count($comma_separated); $j++)
{
$DeptCode = $comma_separated[$j];
//echo $DeptCode;
$userdept=array('EmpID'=>$EmpID,'Departmentcode'=>$DeptCode);
//print_r($userdept);
$access= $this->user_model->addAccess($userdept);
//echo $access;
}
}
if($result > 0)
{
echo "<script>alert('New User Created successfully!');</script>";
redirect('userListing','refresh');
}
else
{
redirect('userListing','refresh');
echo "<script>alert('Failiure User Creation!');</script>";
}
}
//}
}
function Adduserdepartment()
{
$empid= $this->input->post('Eid');
$Depcode= $this->input->post('Department');
$userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode);
$access= $this->user_model->addAccess($userdept);
if($access>0)
{
echo "Successfully Added";
}
}
function Deleteuserdepartment()
{
$empid= $this->input->post('Eid');
$Depcode= $this->input->post('Department');
$userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode);
$access= $this->user_model->DeleteAccess($empid,$Depcode);
if($access>0)
{
echo "Successfully Deleted";
}
}
/**
* This function is used load user edit information
* @param number $userId : Optional : This is user id
*/
function editOld($UserId = '')
{
// if($this->isAdmin() == TRUE )
// {
// $this->loadThis();
// }
// else
// {
if($UserId == '')
{
// redirect('userListing');
}
$Uid = $_GET['UID'];
$Empid = $_GET['EMPID'];
$data['roles'] = $this->user_model->getUserRoles();
//print_r($data);
$data['EmpList'] = $this->user_model->GetEmployeeDetails($Uid);
//print_r($data);
$data['Departmentlist'] = $this->costcenter_model->getDepartmentnotadded($Empid);
$data['EmpRole'] = $this->user_model->GetRoleNameByUserID($Uid);
$data['AccessDept'] = $this->costcenter_model ->getaccessDept($Empid);
// $data['userInfo'] = $this->user_model->getUserInfo($userId);
$this->global['pageTitle'] = 'Siddharth : Edit User';
$this->loadViews("editOld", $this->global, $data, NULL);
//}
}
/**
* This function is used to edit the user information
*/
function editUser()
{
// if($this->isAdmin() == TRUE)
// {
// $this->loadThis();
// }
// else
// {
$userId = $this->input->post('EmpList');
$this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS');
$this->form_validation->set_rules('role','role','trim|callback_Role_validate');
$this->form_validation->set_rules('password','Password','required|max_length[20]');
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]');
if($this->form_validation->run() == FALSE)
{
$this->editOld($userId);
}
else
{
$EmpID = $this->input->post('EmpList');
$role = $this->input->post('role');
$password = $this->input->post('password');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updatedDate = $dt->format('Y-m-d H:i:s');
// echo $EmpID;
$userInfo = array();
$userInfo = array('password'=>getHashedPassword($password),'roleId'=>$role,'EmpId'=>$EmpID,'updatedDtm'=>$updatedDate);
$result = $this->user_model->editUser($userInfo, $EmpID);
if($result == true)
{
$this->session->set_flashdata('success', 'User updated successfully');
}
else
{
$this->session->set_flashdata('error', 'User updation failed');
}
redirect('userListing');
}
//}
}
/**
* This function is used to delete the user using userId
* @return boolean $result : TRUE / FALSE
*/
function deleteUser()
{
echo 'Delete';
$Uid = $this->input->post('id');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updatedDate = $dt->format('Y-m-d H:i:s');
$userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>$updatedDate);
$result = $this->user_model->deleteUser($Uid, $userInfo);
echo 'Succssfully change the user status to InAcive';
}
/**
* This function is used to load the change password screen
*/
function loadChangePass()
{
$this->global['pageTitle'] = 'Siddharth : Change Password';
$this->loadViews("changePassword", $this->global, NULL, NULL);
}
/**
* This function is used to change the password of the user
*/
function changePassword()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('oldPassword','Old password','required|max_length[20]');
$this->form_validation->set_rules('newPassword','New password','required|max_length[20]');
$this->form_validation->set_rules('cNewPassword','Confirm new password','required|matches[newPassword]|max_length[20]');
if($this->form_validation->run() == FALSE)
{
$this->loadChangePass();
}
else
{
$oldPassword = $this->input->post('oldPassword');
$newPassword = $this->input->post('newPassword');
$resultPas = $this->user_model->matchOldPassword($this->vendorId, $oldPassword);
if(empty($resultPas))
{
$this->session->set_flashdata('nomatch', 'Your old password not correct');
redirect('loadChangePass');
}
else
{
$usersData = array('password'=>getHashedPassword($newPassword), 'updatedBy'=>$this->vendorId,
'updatedDtm'=>date('Y-m-d H:i:sa'));
$result = $this->user_model->changePassword($this->vendorId, $usersData);
if($result > 0) { $this->session->set_flashdata('success', 'Password updation successful'); }
else { $this->session->set_flashdata('error', 'Password updation failed'); }
redirect('loadChangePass');
}
}
}
function pageNotFound()
{
$this->global['pageTitle'] = 'Siddharth : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
//this function used to delivery performances
function deliver_perform()
{
$this->global['pageTitle'] = 'Siddharth : Delivery Performance';
if ($this->input->post('btn_submit')) {
$ab=$this->input->post('financialyear');
$fa=substr($ab,0,-5);
$aa=substr($ab,5,5);
$m=$this->input->post('month');
//print_r($prod);
//die;
$data['fy']=$this->user_model->fincalYear();
$data['per']=$this->user_model->deliver_perform($fa,$aa,$m);
// // print_r( $data['spurchse']);
}
$data['fy']=$this->user_model->fincalYear();
$this->loadviews("deliver_perform",$this->global,$data,NULL);
}
/*
*favourite add function and load view
*/
function favourite()
{
$this->global['pageTitle'] = 'Siddharth :Favourite ';
// $data['ponoreset']=$this->purchaseorder_model->ponoresetfinyear();
$this->loadViews("Favourite", $this->global,Null);
}
function favouriteadd()
{
$name = $this->input->post('name');
$url = $this->input->post('url');
$status = $this->input->post('status');
$CreateBy = $this->session->userdata ( 'userId' );
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$menu = $this->input->post('menu');
// $RowCount = $this->input->post('txtRowCount');
// $DeletedRow = $this->input->post('txtDeletedRow');
// $comma_separated = explode(':', $DeletedRow);
$favourite = array('Menu_Name'=>$name,'Menu_URL'=>$url,'Status'=>$status,'Created_BY'=>$CreateBy,'Created_ON'=>$createddt,'Menu_ID'=>$menu);
$getdata= $this->user_model->favouriteadd($favourite);
// print_r($favourite);
// die();
if($getdata==1)
{
echo"success";
}
else{
echo"failed";
}
}
}
?>