diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 755225a96..b3d8fe0ed 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,99 +1,23 @@ CHANGELOG Sentrifugo ==================== -RELEASE 2.1 ------------ +RELEASE 2.1.1 +------------- Changes in Controllers ------------------------ -./application/modules/default/controllers/addemployeeleavesController.php -./application/modules/default/controllers/empleavesummaryController.php -./application/modules/default/controllers/leaverequestController.php -./application/modules/default/controllers/visaandimmigrationController.php -./application/modules/default/controllers/empjobhistoryController.php -./application/modules/default/controllers/wizardController.php -./application/modules/default/controllers/HrwizardController.php -./application/modules/default/controllers/appraisalinitController.php -./application/modules/default/controllers/IndexController.php -./application/modules/default/controllers/policydocumentsController.php -./application/modules/timemanagement/controllers/clientsController.php -./application/modules/timemanagement/controllers/defaulttasksController.php -./application/modules/timemanagement/controllers/EmployeeprojectsController.php -./application/modules/timemanagement/controllers/EmptimesheetsController.php -./application/modules/timemanagement/controllers/ExpensecategoryController.php -./application/modules/timemanagement/controllers/ExpensesController.php + ./application/modules/timemanagement/controllers/IndexController.php -./application/modules/timemanagement/controllers/LeadprojectsController.php -./application/modules/timemanagement/controllers/ProjectresourcesController.php ./application/modules/timemanagement/controllers/ProjectsController.php -./application/modules/timemanagement/controllers/ProjecttasksController.php -./application/modules/timemanagement/controllers/ReportsController.php - -- addemployeeleavesController.php - Add leaves for multiple employees according to BusinessUnit and Departments. - -- empleavesummaryController.php - Management can view the employee who are on leave or have applied for leave. - -- leaverequestController.php - Employee can directly apply for leave for the current day using 'Apply Leave' - -- visaandimmigrationController.php - Employee can add multiple visa details. - -- empjobhistoryController.php - Employee can add client & vendor details. - -- wizardController.php - Consists of 5 steps now for Super Admin. (add Organization,Add Business Unit & Departments, Add Service Request,modules,site configuration,) - -- HrwizardController.php - Consists of 3 steps for HR. (Configure Leave Types, Configure Holidays, Appraisals) -- appraisalinitController.php - The option Appraisal settings has been removed and we have its functionality in Initialize appraisal. - -- policydocumentsController.php - contains the documents about Organization. - -- clientsController.php - Manager can Create, edit,view, delete client information . -- defaulttasksController.php - Manager can Create, edit,view, delete defaulttasks. - -- EmployeeprojectsController.php - Employee can view assigned projects and related tasks. - -- EmptimesheetsController.php - Manager can view employee time sheet status. - + - IndexController.php Display holidays, weekends , enter time sheet , edit time sheet , erase time sheet , submit time sheet , apply leaves. -- ProjectresourcesController.php - view project resources. - ProjectsController.php Manager can create , edit , view, delete projects. -- ProjecttasksController.php - View tasks of projects assigned to resources. - -- ReportsController.php - Admin can view Reports. - -Note: You can find the respective view files in below scripts: -./application/modules/default/views/scripts - - -Changes in scripts ------------------------- -./public/media/js/hrms.js -./public/media/js/joyride.js -./public/media/js/hrmsv2.js -./public/media/js/pa.js -./public/media/css/style.css -./public/media/css/successstyle.css Note: You can find the respective view files in below scripts: ./application/modules/timemanagement/views/scripts diff --git a/Zend/View/Helper/Recentlyviewed.php b/Zend/View/Helper/Recentlyviewed.php index dfb088f80..6d558cac0 100644 --- a/Zend/View/Helper/Recentlyviewed.php +++ b/Zend/View/Helper/Recentlyviewed.php @@ -393,7 +393,7 @@ public function recentlyviewed() if($pagesplitName == 'defaulttasks') $menuName ='Default Tasks'; else if($pagesplitName == 'emptimesheets') - $menuName ='Employee Time Sheets'; + $menuName ='Employee Timesheets'; else if($pagesplitName == 'employeeprojects') $menuName ='Projects'; else diff --git a/application/layouts/scripts/hrmsfooter.phtml b/application/layouts/scripts/hrmsfooter.phtml index ee8d25c85..ff1106d5a 100644 --- a/application/layouts/scripts/hrmsfooter.phtml +++ b/application/layouts/scripts/hrmsfooter.phtml @@ -60,7 +60,7 @@
Here for the first time?
- For maximum assistance, using this tour maximize your browser. + For the best Sentrifugo tour experience, please maximize your browser.

Start the tour
- Back to Dashboard - Help -
- + Back to Dashboard + Help + +
+ 0 && !($employeeDOJ['date_of_joining']>=$week_start && $employeeDOJ['date_of_joining']<=$week_start)) { + ?> + () + + + + + 0) { ?> +
+ () +
+ + + +
-
Drag & Drop the selected menu to the below box
+
Drag & Drop the menu items on the left into the box below
diff --git a/application/modules/default/views/scripts/dashboard/viewsettings.phtml b/application/modules/default/views/scripts/dashboard/viewsettings.phtml index f5ef0b626..54beccb19 100644 --- a/application/modules/default/views/scripts/dashboard/viewsettings.phtml +++ b/application/modules/default/views/scripts/dashboard/viewsettings.phtml @@ -751,7 +751,7 @@ if($this->menuidcount > 0){
Shortcuts
-
Drag & Drop the selected menu to the below box
+
Drag & Drop the menu items on the left into the box below
diff --git a/application/modules/default/views/scripts/leavemanagement/add.phtml b/application/modules/default/views/scripts/leavemanagement/add.phtml index 2b0914b04..11f7a8ec1 100644 --- a/application/modules/default/views/scripts/leavemanagement/add.phtml +++ b/application/modules/default/views/scripts/leavemanagement/add.phtml @@ -75,7 +75,7 @@
- +
form->weekend_startday; ?>
msgarray['weekend_startday'])){?> msgarray['weekend_startday'];?> @@ -83,7 +83,7 @@
- +
form->weekend_endday; ?>
msgarray['weekend_endday'])){?> msgarray['weekend_endday'];?> diff --git a/application/modules/default/views/scripts/leavemanagement/edit.phtml b/application/modules/default/views/scripts/leavemanagement/edit.phtml index 9d0834a8b..99d3b149e 100644 --- a/application/modules/default/views/scripts/leavemanagement/edit.phtml +++ b/application/modules/default/views/scripts/leavemanagement/edit.phtml @@ -66,7 +66,7 @@ sapp_Global::generateClientValidations($this->form);?>
- +
form->weekend_startday; ?>
msgarray['weekend_startday'])){?> msgarray['weekend_startday'];?> @@ -74,7 +74,7 @@ sapp_Global::generateClientValidations($this->form);?>
- +
form->weekend_endday; ?>
msgarray['weekend_endday'])){?> msgarray['weekend_endday'];?> diff --git a/application/modules/default/views/scripts/mailtemplates/newpassword.phtml b/application/modules/default/views/scripts/mailtemplates/newpassword.phtml index 51faaedba..91b4ee24b 100644 --- a/application/modules/default/views/scripts/mailtemplates/newpassword.phtml +++ b/application/modules/default/views/scripts/mailtemplates/newpassword.phtml @@ -28,7 +28,7 @@
Username: emp_id;?>
Password: password;?>
-
Please click here to login to your Sentrifugo account.
+
Please click here to login to your Sentrifugo account.
diff --git a/application/modules/default/views/scripts/reports/interviewrounds.phtml b/application/modules/default/views/scripts/reports/interviewrounds.phtml index 665eb1263..cfeb81034 100644 --- a/application/modules/default/views/scripts/reports/interviewrounds.phtml +++ b/application/modules/default/views/scripts/reports/interviewrounds.phtml @@ -178,7 +178,7 @@ $(document).ready(function(){ if(item.id != '') { return $( "
  • " ) - .append( "" + item.label + "" ) + .append( "" + item.label + "") .appendTo( ul ); } else @@ -208,7 +208,7 @@ $(document).ready(function(){ if(item.id != '') { return $( "
  • " ) - .append( "" + item.label + "" ) + .append( "" + item.label + "" ) .appendTo( ul ); } else diff --git a/application/modules/default/views/scripts/roles/getgroupmenu.ajax.phtml b/application/modules/default/views/scripts/roles/getgroupmenu.ajax.phtml index d4acaa685..2683cdcf5 100644 --- a/application/modules/default/views/scripts/roles/getgroupmenu.ajax.phtml +++ b/application/modules/default/views/scripts/roles/getgroupmenu.ajax.phtml @@ -261,7 +261,7 @@ function setAccordionActive(acc_class) } ?> - \ No newline at end of file diff --git a/application/modules/default/views/scripts/wizard/configureunitsanddepartments.phtml b/application/modules/default/views/scripts/wizard/configureunitsanddepartments.phtml index 1e6871020..6226d95ae 100644 --- a/application/modules/default/views/scripts/wizard/configureunitsanddepartments.phtml +++ b/application/modules/default/views/scripts/wizard/configureunitsanddepartments.phtml @@ -229,7 +229,7 @@ function saveBusinessUnit()
    - +
    diff --git a/application/modules/timemanagement/controllers/ClientsController.php b/application/modules/timemanagement/controllers/ClientsController.php index ce722e58e..ec179938d 100644 --- a/application/modules/timemanagement/controllers/ClientsController.php +++ b/application/modules/timemanagement/controllers/ClientsController.php @@ -42,6 +42,13 @@ class Timemanagement_ClientsController extends Zend_Controller_Action */ public function preDispatch() { + /*$userModel = new Timemanagement_Model_Users(); + $checkTmEnable = $userModel->checkTmEnable(); + + if(!$checkTmEnable){ + $this->_redirect('error'); + }*/ + //check Time management module enable if(!sapp_Helper::checkTmEnable()) $this->_redirect('error'); diff --git a/application/modules/timemanagement/controllers/ConfigurationController.php b/application/modules/timemanagement/controllers/ConfigurationController.php new file mode 100644 index 000000000..731a8823c --- /dev/null +++ b/application/modules/timemanagement/controllers/ConfigurationController.php @@ -0,0 +1,198 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ + +class Timemanagement_ConfigurationController extends Zend_Controller_Action +{ + + private $options; + public function preDispatch() + { + /*$userModel = new Timemanagement_Model_Users(); + $checkTmEnable = $userModel->checkTmEnable(); + + if(!$checkTmEnable){ + $this->_redirect('error'); + }*/ + + //check Time management module enable + if(!sapp_Helper::checkTmEnable()) + $this->_redirect('error'); + + } + + public function init() + { + $this->_options= $this->getInvokeArg('bootstrap')->getOptions(); + + } + + public function indexAction() + { + $configurationModel = new Timemanagement_Model_Configuration(); + $activerecordArr = $configurationModel->getActiveRecord(); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $sess_values = $auth->getStorage()->read(); + } + if(!empty($activerecordArr)) + $this->view->dataArray = $activerecordArr; + + $this->view->messages = $this->_helper->flashMessenger->getMessages(); + $this->view->admin = 'Yes'; + $this->view->sess_values = $sess_values; + } + + public function addAction() + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()){ + $loginUserId = $auth->getStorage()->read()->id; + $loginuserRole = $auth->getStorage()->read()->emprole; + $loginuserGroup = $auth->getStorage()->read()->group_id; + } + + $configurationForm = new Timemanagement_Form_Configuration(); + $configurationModel = new Timemanagement_Model_Configuration(); + $activerecordArr = $configurationModel->getActiveRecord(); + + $msgarray = array(); + + $configurationForm->setAttrib('action',BASE_URL.'timemanagement/configuration/add'); + $this->view->form = $configurationForm; + $this->view->msgarray = $msgarray; + if(count($activerecordArr)>0) + { + $this->view->nodata = ""; + $activerecordArr = $configurationModel->getActiveRecord(); + if(count($activerecordArr[0])>0) + { + foreach($activerecordArr[0] as $key=>$val) + { + $activerecordArr[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8"); + } + } + + $configurationForm->submit->setLabel('UPDATE'); + $configurationForm->populate($activerecordArr); + } + if($this->getRequest()->getPost()){ + if($configurationForm->isValid($this->_request->getPost())){ + $result = $this->save($configurationForm); + $this->view->msgarray = $msgarray; + }else + { + $messages = $configurationForm->getMessages(); + foreach ($messages as $key => $val) + { + foreach($val as $key2 => $val2) + { + $msgarray[$key] = $val2; + break; + } + } + $this->view->msgarray = $msgarray; + } + } + + } + + public function save($configurationForm) + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $loginUserId = $auth->getStorage()->read()->id; + } + if($configurationForm->isValid($this->_request->getPost())) + { + $trDb = Zend_Db_Table::getDefaultAdapter(); + // starting transaction + $trDb->beginTransaction(); + try + { + $configurationModel = new Timemanagement_Model_Configuration(); + $id = (int)$this->_request->getParam('id'); + $id = abs($id); + //$ts_block_reminder_day = $this->_request->getParam('ts_block_reminder_day'); + //$ts_blocking_day = $this->_request->getParam('ts_blocking_day'); + $ts_weekly_reminder_day = $this->_request->getParam('ts_weekly_reminder_day'); + $ts_block_dates_range = $this->_request->getParam('ts_block_dates_range'); + + $date = new Zend_Date(); + $data = array( + //'ts_block_reminder_day'=>$ts_block_reminder_day, + // 'ts_blocking_day'=>$ts_blocking_day, + 'ts_weekly_reminder_day'=>$ts_weekly_reminder_day, + 'ts_block_dates_range'=>$ts_block_dates_range, + 'created_by' => $loginUserId, + 'modified_by'=>$loginUserId, + 'modified'=>$date->get('yyyy-MM-dd HH:mm:ss'), + 'created'=>$date->get('yyyy-MM-dd HH:mm:ss'), + 'is_active'=>1 + ); + + $update_arr = array( + 'is_active' => 0, + 'modified'=>$date->get('yyyy-MM-dd HH:mm:ss'), + 'modified_by'=>$loginUserId, + ); + + $configurationModel->SaveorUpdateConfigurationData($update_arr, array('is_active'=>1)); + + $Id = $configurationModel->SaveorUpdateConfigurationData($data, $where=''); + + if($id!='') + { + $this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Configuration updated successfully.")); + } + else + { + $this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Configuration added successfully.")); + } + + $trDb->commit(); + } + catch (Exception $e) + { + $trDb->rollBack(); + $this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Something went wrong,please try again later.")); + } + $this->_redirect('timemanagement/configuration'); + } + else + { + $messages = $configurationForm->getMessages(); + foreach ($messages as $key => $val) + { + foreach($val as $key2 => $val2) + { + $msgarray[$key] = $val2; + break; + } + } + return $msgarray; + } + } + +} + diff --git a/application/modules/timemanagement/controllers/CronjobController.php b/application/modules/timemanagement/controllers/CronjobController.php new file mode 100644 index 000000000..2aa2e2603 --- /dev/null +++ b/application/modules/timemanagement/controllers/CronjobController.php @@ -0,0 +1,850 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ + +class Timemanagement_CronjobController extends Zend_Controller_Action +{ + + private $options; + public function preDispatch() + { + //check Time management module enable + if(!sapp_Helper::checkTmEnable()) + $this->_redirect('error'); + + } + + public function init() + { + + $this->_options= $this->getInvokeArg('bootstrap')->getOptions(); + } + + public function indexAction() + { + + $this->_helper->viewRenderer->setNoRender(true); + $this->_helper->layout()->disableLayout(); + + $date = new Zend_Date(); + + //parameter wise cronjob start + $a_date = ($this->_getParam('date'))?$this->_getParam('date'):""; + //parameter wise cronjob end + if($a_date!="") + { + $a_date = date("Y-m-d", strtotime($a_date)); + } + + //weekly mail reminder function + $this->mailreminder($a_date); + //monthly mail reminder function + $this->monthlyempblockremainder($a_date); + + //monthly block function + $this->monthlyblockedemp($a_date); + + $tm_cronjob_statusModel = new Timemanagement_Model_Cronjobstatus; + $checkAnyCronRunning = $tm_cronjob_statusModel->checkCronRunning(); + if(count($checkAnyCronRunning) == 0){ + $cronstatusData = array('cronjob_status' => 'running', + 'start_date' => gmdate("Y-m-d H:i:s"), + 'end_date'=>gmdate("Y-m-d H:i:s") + ); + + $insertedCronjobStatusId = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,''); + + $this->tmmailscron(); + + $cronstatusData = array('cronjob_status' => 'stopped', + 'end_date'=>gmdate("Y-m-d H:i:s") + ); + $whereCronstatus = array('id=?'=>$insertedCronjobStatusId); + + $updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus); + + }else{ + echo 'Some cron running'; + } + }//end of index action + + /*****Timemanagememt crons ********/ + //weekly reminder mail cron + public function mailreminder($aDate) + { + $this->_helper->viewRenderer->setNoRender(true); + // the above is to stop search for view file + $this->_helper->layout()->disableLayout(); + + $tm_cronjob_statusModel = new Timemanagement_Model_Cronjobstatus; + $checkAnyCronRunning = $tm_cronjob_statusModel->checkCronRunning(); + if(count($checkAnyCronRunning) == 0){ + $cronstatusData = array('cronjob_status' => 'running', + 'start_date' => gmdate("Y-m-d H:i:s"), + 'end_date'=>gmdate("Y-m-d H:i:s") + ); + + $insertedCronjobStatusId = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,''); + + $tmconf_model = new Timemanagement_Model_Configuration(); + $getTmConfig = $tmconf_model->getActiveRecord(); + + if(!empty($getTmConfig)){ + try{ + + $weekCon_arr = array('sun'=>'Sunday','mon'=>'Monday','tue'=>'Tuesday','wed'=>'Wednesday','thu'=>'Thursday','fri'=>'Friday','sat'=>'Saturday'); + $startday_err=array('Sunday'=>7,'Monday'=>8,'Tuesday'=>9,'Wednesday'=>10,'Thursday'=>11,'Friday'=>12,'Saturday'=>13); + $endday_err=array('Sunday'=>1,'Monday'=>2,'Tuesday'=>3,'Wednesday'=>4,'Thursday'=>5,'Friday'=>6,'Saturday'=>7); + + //$a_date = $this->_getParam('date'); + //$a_date = '2015-06-04'; + $a_date=($aDate!="")?$aDate:date('Y-m-d'); + $date = new DateTime($a_date); + //echo $date->format('l').'----'. $weekCon_arr[$getTmConfig[0]['ts_weekly_reminder_day']];exit; + if($date->format('l') == $weekCon_arr[$getTmConfig[0]['ts_weekly_reminder_day']]){ + + $cron_day=$date->format('l'); + + $start_interval='P'.$startday_err[$cron_day].'D'; + $end_interval='P'.$endday_err[$cron_day].'D'; + $date->sub(new DateInterval($start_interval)); + $ls_week=$date->format('Y-m-d'); + $date = new DateTime($a_date); + $date->sub(new DateInterval($end_interval)); + $ls_day=$date->format('Y-m-d'); + //echo $ls_week.'-----'.$ls_day;//exit; + + $tmUsers_model=new Timemanagement_Model_Users(); + + $mgr_list=$tmUsers_model->getManagers(); //echo '
    ';print_r($mgr_list);exit;
    +
    +						//reporting to managers
    +						foreach($mgr_list as $mgr)
    +						{
    +							$emp_data = $tmUsers_model->getEmployeesReportingTo($mgr['user_id'],$cron_day);
    +
    +							$emp_arr=array();
    +							if(count($emp_data) > 0){
    +								foreach($emp_data as $emp)
    +								{
    +									$emp_joindate = new DateTime($emp['date_of_joining']);
    +									$emp_joindate = $emp_joindate->format('Y-m-d');
    +
    +									$not_fill_arr = $tmUsers_model->checkweekdaysdatacron($ls_week, $ls_day, $emp['user_id'],$emp['department_id'],$emp['holiday_group'],$emp_joindate);
    +									//echo "
    ";print_r($not_fill_arr);exit;
    +
    +									if(count($not_fill_arr)>0)
    +									{
    +										$pre_fin_dates = $not_fill_arr;
    +										//echo "
    ";print_r($pre_fin_dates);
    +
    +										//echo "
    ";print_r($fin_dates);
    +										$fin_dates = $pre_fin_dates; //print_r($fin_dates);
    +										if(count($fin_dates)>0)
    +										{
    +											$this->send_mail_emp($emp['user_id'],$ls_week,$ls_day,$emp['userfullname'],$emp['emailaddress'],$fin_dates,'weekly');
    +											$emp_arr[$emp['user_id']]=$emp['userfullname'];
    +										}
    +									}
    +								}
    +								$this->send_mail_manager($emp_arr,$ls_week,$ls_day,$mgr['user_id'],$mgr['userfullname'],$mgr['emailaddress'],'weeklyreminder');
    +							}
    +
    +						}
    +					}else{
    +						echo "Date doesn't match";
    +					}
    +
    +					$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +					$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +					$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +				}
    +				catch(Exception $e)
    +				{
    +					print_r($e); die;
    +				}
    +			}else{
    +				echo 'Timemanagement configuration not yet set.';
    +				
    +				$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +				$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +				$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +			}
    +		}else{
    +			echo 'Cron running';
    +		}
    +	}
    +
    +	public function send_mail_emp($empid,$ls_week,$ls_day,$emp_name,$emp_email,$days,$whichremainder,$blockreminderday = '')
    +	{
    +		$base_url = 'http://'.$this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
    +		$period = $ls_week.' to '.$ls_day;
    +		$view = $this->getHelper('ViewRenderer')->view;
    +
    +		$this->view->base_url=$base_url;
    +		$this->view->emp_name=$emp_name;
    +		$this->view->days=$days;
    +		$this->view->period=$period;
    +
    +		$text = '';
    +		$mail_type = '';
    +		if($whichremainder == 'weekly'){
    +			$text = $view->render('tmmailtemplates/ts_weekly_employee.phtml');
    +			$mail_type = 'submit_pending';
    +		}else if($whichremainder == 'monthly'){
    +			$this->view->blockreminderday = $blockreminderday;
    +			$text = $view->render('tmmailtemplates/empmonthlyremainder.phtml');
    +			$mail_type = 'reminder';
    +		}else if($whichremainder == 'empblock'){
    +			$text = $view->render('tmmailtemplates/monthlytimesheetstatus.phtml');
    +			$mail_type = 'block';
    +		}
    +
    +		/*Insert data to send mail*/
    +		$totDays = implode(",", $days);
    +		$mailslist_data = array('emp_id'=>$empid,
    +								'mail_type'=>$mail_type,
    +								'ts_dates'=>$totDays,
    +		                        'emp_full_name'=>$emp_name,
    +								'email'=>$emp_email,
    +								'ts_start_date'=>$ls_week,
    +								'ts_end_date'=>$ls_day,
    +								'mail_content'=>$text,
    +								'is_mail_sent'=>0,
    +								'created' => gmdate("Y-m-d H:i:s"),
    +		);
    +
    +		$mailslist_where = '';
    +
    +		$tmMail_model = new Timemanagement_Model_Mailslist();
    +		$id = $tmMail_model->addOrUpdateMailsList($mailslist_data,$mailslist_where);
    +		/*end*/
    +	}
    +
    +	public function send_mail_manager($emp_arr,$ls_week,$ls_day,$mgr_id,$mgr_name,$mgr_mail,$whichremainder)
    +	{
    +		$base_url = 'http://'.$this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
    +
    +		$emp_names='';
    +		foreach($emp_arr as $key=>$value)
    +		{
    +			$emp_names.=$value."
    "; + } + if(count($emp_arr) > 0) + { + $view = $this->getHelper('ViewRenderer')->view; + $period = $ls_week.' to '.$ls_day; + $this->view->mgr_name=$mgr_name; + $this->view->base_url=$base_url; + $this->view->ls_week=$ls_week; + $this->view->ls_day=$ls_day; + $this->view->emp_names=$emp_names; + $this->view->emp_arr=$emp_arr; + $this->view->period=$period; + + + + if($whichremainder == 'weeklyreminder'){ + $mail_type = 'submit_pending'; + $text = $view->render('tmmailtemplates/ts_weekly_manager.phtml'); + + }else if($whichremainder == 'monthlyblock'){ + $mail_type = 'block'; + $text = $view->render('tmmailtemplates/monthlyemptimesheet.phtml'); + } + + $trDb = Zend_Db_Table::getDefaultAdapter(); + // starting transaction + $trDb->beginTransaction(); + try + { + $mailslist_data = array('emp_id'=>$mgr_id, + 'mail_type'=>$mail_type, + 'ts_dates'=>'', + 'emp_full_name'=>$mgr_name, + 'email'=>$mgr_mail, + 'ts_start_date'=>$ls_week, + 'ts_end_date'=>$ls_day, + 'mail_content'=>$text, + 'is_mail_sent'=>0, + 'created' => gmdate("Y-m-d H:i:s"), + ); + + $mailslist_where = ''; + + $tmMail_model = new Timemanagement_Model_Mailslist(); + $id = $tmMail_model->addOrUpdateMailsList($mailslist_data,$mailslist_where); + //End + $trDb->commit(); + }catch (Exception $e) + { + $trDb->rollBack(); + } + } + } + + //Employee Mail remainder for blocking his monthly timesheet. + public function monthlyempblockremainder($aDate) + { + $this->_helper->viewRenderer->setNoRender(true); + // the above is to stop search for view file + $this->_helper->layout()->disableLayout(); + + $tm_cronjob_statusModel = new Timemanagement_Model_Cronjobstatus; + $checkAnyCronRunning = $tm_cronjob_statusModel->checkCronRunning(); + if(count($checkAnyCronRunning) == 0){ + $cronstatusData = array('cronjob_status' => 'running', + 'start_date' => gmdate("Y-m-d H:i:s"), + 'end_date'=>gmdate("Y-m-d H:i:s") + ); + + $insertedCronjobStatusId = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,''); + + $tmconf_model = new Timemanagement_Model_Configuration(); + $getTmConfig = $tmconf_model->getActiveRecord(); + $blockReminderConfigDay =''; + + if(!empty($getTmConfig)){ + + if(trim($getTmConfig[0]['ts_block_dates_range']) == '1-31'){ + $blockReminderConfigDay = 2; + }else if(trim($getTmConfig[0]['ts_block_dates_range']) == '26-25'){ + $blockReminderConfigDay = 27; + } + + if(strlen($blockReminderConfigDay) == 1){ + $blockReminderConfigDay = '0'.$blockReminderConfigDay; + } + + //$a_date = '2015-07-27'; + $a_date=($aDate!="")?$aDate:date('Y-m-d'); + //$a_date = $this->_getParam('date'); + $date = new DateTime($a_date); + //echo $date->format('d').'-----'.$blockReminderConfigDay.'------';exit; + if($date->format('d') == $blockReminderConfigDay){ + $tmUsers_model=new Timemanagement_Model_Users(); + $mgr_list=$tmUsers_model->getManagers(); + + $today = new DateTime($a_date); + $cron_run_date = $today->format('Y').'-'.$today->format('m').'-'.$blockReminderConfigDay; + $cron_run_date = strtotime($cron_run_date); + $cron_run_date = date('Y-m-d',$cron_run_date); + + /*$tdate = new DateTime(date('Y-m-d')); + $ctdate = new DateTime(date('Y-m-d'));*/ + + $tdate = new DateTime($a_date); + $ctdate = new DateTime($a_date); + + if($blockReminderConfigDay == 2){ + //First day of the previous month: + $tdate->sub(new DateInterval('P1M')); + $firstday_prev_month =$tdate->format('Y-m-01'); + $hidstartweek_date = $firstday_prev_month; + + //Last day of the previous month: + $lastday_prev_month = $tdate->format('Y').'-'.$tdate->format('m').'-31'; + $lastday_prev_month = strtotime($lastday_prev_month); + $lastday_prev_month = date('Y-m-d',$lastday_prev_month); + $hidendweek_date = $lastday_prev_month; + + $lastday_prev_month = new DateTime(date($lastday_prev_month)); + if($lastday_prev_month->format('m') != 31){ + $hidendweek_date = date("Y-m-t", strtotime($tdate->format('Y').'-'.$tdate->format('m').'-01')); + } + + $month_name = date("F, Y", strtotime($hidendweek_date)); + }else if($blockReminderConfigDay == 27){ + //First day of the previous month: + $tdate->sub(new DateInterval('P1M')); + $firstday_prev_month =$tdate->format('Y-m-26'); + $hidstartweek_date = $firstday_prev_month; + + //Last day of the previous month: + $lastday_prev_month = $ctdate->format('Y-m-25'); + $hidendweek_date = $lastday_prev_month; + $month_name = date("F, Y", strtotime($hidendweek_date)); + } + + //echo 'TM_BLOCK_START_DAY---'.TM_BLOCK_START_DAY.'---startdate----'.$hidstartweek_date;echo '
    '; + //echo 'TM_BLOCK_END_DAY---'.TM_BLOCK_END_DAY.'---enddate----'.$hidendweek_date;echo '
    '; + + $month_name = date("F, Y", strtotime($hidendweek_date)); + + // managers loop + if(count($mgr_list) > 0){ + foreach($mgr_list as $mgr) + { + $emp_data = $tmUsers_model->getEmployeesReportingTo($mgr['user_id'],$cron_run_date); + + $emp_arr=array(); + if(count($emp_data)>0){ + foreach($emp_data as $emp) + { + $emp_joindate = new DateTime($emp['date_of_joining']); + $emp_joindate = $emp_joindate->format('Y-m-d'); + + $not_fill_arr = $tmUsers_model->checkweekdaysdatacron($hidstartweek_date, $hidendweek_date, $emp['user_id'],$emp['department_id'],$emp['holiday_group'],$emp_joindate); + //echo "
    ";print_r($not_fill_arr);exit;
    +
    +									if(count($not_fill_arr)>0)
    +									{
    +										$this->send_mail_emp($emp['user_id'],$hidstartweek_date,$hidendweek_date,$emp['userfullname'],$emp['emailaddress'],$not_fill_arr,'monthly',$blockReminderConfigDay);
    +										$emp_arr[$emp['user_id']]=$emp['userfullname'];
    +									}
    +								}
    +							}
    +						}
    +					}
    +
    +					$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +					$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +					$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +				}else{
    +					echo "Date doesn't match";
    +					
    +					$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +					$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +					$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +				}
    +			}else{
    +				echo 'Timemanagement configuration not yet set.';
    +				
    +				$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +				$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +				$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +			}
    +		}else{
    +			echo 'Some cron running';
    +		}
    +	}
    +	//End
    +
    +
    +	//Block timesheet monthly and send a mails.
    +	public function monthlyblockedemp($aDate)
    +	{
    +
    +		$this->_helper->viewRenderer->setNoRender(true);
    +		// the above is to stop search for view file
    +		$this->_helper->layout()->disableLayout();
    +
    +		$tmconf_model = new Timemanagement_Model_Configuration();
    +		$getTmConfig = $tmconf_model->getActiveRecord();
    +		$blockConfigDay = '';
    +
    +		$tm_cronjob_statusModel = new Timemanagement_Model_Cronjobstatus;
    +		$checkAnyCronRunning = $tm_cronjob_statusModel->checkCronRunning();
    +		if(count($checkAnyCronRunning) == 0){
    +			$cronstatusData = array('cronjob_status' => 'running',
    +									'start_date' => gmdate("Y-m-d H:i:s"),
    +									'end_date'=>gmdate("Y-m-d H:i:s")
    +			);
    +
    +			$insertedCronjobStatusId = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,'');
    +
    +			if(!empty($getTmConfig)){
    +
    +				if(trim($getTmConfig[0]['ts_block_dates_range']) == '1-31'){
    +					$blockConfigDay = 3;
    +				}else if(trim($getTmConfig[0]['ts_block_dates_range']) == '26-25'){
    +					$blockConfigDay = 28;
    +				}
    +
    +				if(strlen($blockConfigDay) == 1){
    +					$blockConfigDay = '0'.$blockConfigDay;
    +				}
    +
    +				//$a_date = '2015-07-28';
    +				  $a_date=($aDate!="")?$aDate:date('Y-m-d');
    +				//$a_date = $this->_getParam('date');
    +				$date = new DateTime($a_date);
    +				//echo $date->format('d').'-----'.$blockConfigDay.'------';
    +				if($date->format('d') == $blockConfigDay){
    +					$tmUsers_model=new Timemanagement_Model_Users();
    +					$mgr_list=$tmUsers_model->getManagers();
    +					//$lead_list=$tmUsers_model->getEmployees('lead');//echo '
    '; print_r($lead_list);exit;
    +
    +					$today = new DateTime($a_date);
    +					$cron_run_date =  $today->format('Y').'-'.$today->format('m').'-'.$blockConfigDay;
    +					$cron_run_date = strtotime($cron_run_date);
    +					$cron_run_date = date('Y-m-d',$cron_run_date);
    +
    +					/*$tdate = new DateTime(date('Y-m-d'));
    +					 $ctdate = new DateTime(date('Y-m-d'));*/
    +
    +					$tdate = new DateTime($a_date);
    +					$ctdate = new DateTime($a_date);
    +
    +					if($blockConfigDay == 3){
    +						//First day of the previous month:
    +						$tdate->sub(new DateInterval('P1M'));
    +						$firstday_prev_month =$tdate->format('Y-m-01');
    +						$hidstartweek_date = $firstday_prev_month;
    +
    +						//Last day of the previous month:
    +						$lastday_prev_month =  $tdate->format('Y').'-'.$tdate->format('m').'-31';
    +						$lastday_prev_month = strtotime($lastday_prev_month);
    +						$lastday_prev_month = date('Y-m-d',$lastday_prev_month);
    +						$hidendweek_date = $lastday_prev_month;
    +
    +						$lastday_prev_month = new DateTime(date($lastday_prev_month));
    +						if($lastday_prev_month->format('m') != 31){
    +							$hidendweek_date = date("Y-m-t", strtotime($tdate->format('Y').'-'.$tdate->format('m').'-01'));
    +						}
    +
    +						$month_name = date("F, Y", strtotime($hidendweek_date));
    +					}else if($blockConfigDay == 28){
    +						//First day of the previous month:
    +						$tdate->sub(new DateInterval('P1M'));
    +						$firstday_prev_month =$tdate->format('Y-m-26');
    +						$hidstartweek_date = $firstday_prev_month;
    +
    +						//Last day of the previous month:
    +						$lastday_prev_month = $ctdate->format('Y-m-25');
    +						$hidendweek_date = $lastday_prev_month;
    +						$month_name = date("F, Y", strtotime($hidendweek_date));
    +					}
    +
    +					//echo 'TM_BLOCK_START_DAY---'.TM_BLOCK_START_DAY.'---startdate----'.$hidstartweek_date;echo '
    '; + //echo 'TM_BLOCK_END_DAY---'.TM_BLOCK_END_DAY.'---enddate----'.$hidendweek_date;echo '
    ';exit; + + $month_name = date("F, Y", strtotime($hidendweek_date)); + + // managers loop + $atleastOneEmpBlocked = false; + if(count($mgr_list) > 0){ + foreach($mgr_list as $mgr) + { + $emp_data = $tmUsers_model->getEmployeesReportingTo($mgr['user_id'],$cron_run_date); + + $emp_arr=array(); + if(count($emp_data) > 0){ + foreach($emp_data as $emp) + { + $emp_joindate = new DateTime($emp['date_of_joining']); + $emp_joindate = $emp_joindate->format('Y-m-d'); + + $not_fill_arr = $tmUsers_model->checkweekdaysdatacron($hidstartweek_date, $hidendweek_date, $emp['user_id'],$emp['department_id'],$emp['holiday_group'],$emp_joindate); + //echo "
    ";print_r($not_fill_arr);exit;
    +
    +									if(count($not_fill_arr)>0)
    +									{
    +                                        $atleastOneEmpBlocked = true;
    +										$this->notfilledDays($emp['user_id'],$not_fill_arr,$blockConfigDay);
    +										$this->send_mail_emp($emp['user_id'],$hidstartweek_date,$hidendweek_date,$emp['userfullname'],$emp['emailaddress'],$not_fill_arr,'empblock');
    +										$emp_arr[$emp['user_id']]=$emp['userfullname'];
    +									}
    +								}
    +								$this->send_mail_manager($emp_arr,$hidstartweek_date,$hidendweek_date,$mgr['user_id'],$mgr['userfullname'],$mgr['emailaddress'],'monthlyblock');
    +							}
    +						}
    +					}
    +
    +					/*insert record in mail_list table for front end use*/
    +					if(!$atleastOneEmpBlocked){
    +
    +						$mailslistdummy_data = array('emp_id'=> NULL,
    +								'mail_type'=>'block',
    +								'ts_dates'=> NULL,
    +								'emp_full_name'=> NULL,
    +								'email'=> NULL,
    +								'ts_start_date'=>$hidstartweek_date,
    +								'ts_end_date'=>$hidendweek_date,
    +								'mail_content'=> NULL,
    +								'is_mail_sent'=>1,
    +								'created' => gmdate("Y-m-d H:i:s"),
    +						);
    +
    +						$mailslist_where = '';
    +						
    +						$tmMail_model = new Timemanagement_Model_Mailslist();
    +						$id = $tmMail_model->addOrUpdateMailsList($mailslistdummy_data,$mailslist_where);
    +					}
    +						/*end insert record in mail_list table for front end use*/
    +
    +					// cronstatus update
    +					$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +					$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +					$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +					//end cronstatus update
    +				}else{
    +					echo "Date doesn't match";					
    +					
    +					// cronstatus update
    +					$cronstatusData = array('cronjob_status' => 'stopped',
    +										'end_date'=>gmdate("Y-m-d H:i:s")
    +					);
    +					$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +					$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +					//end cronstatus update
    +				}
    +			}else{
    +				echo 'Timemanagement configuration not yet set.';
    +				
    +				
    +				// cronstatus update
    +				$cronstatusData = array('cronjob_status' => 'stopped',
    +									'end_date'=>gmdate("Y-m-d H:i:s")
    +				);
    +				$whereCronstatus = array('id=?'=>$insertedCronjobStatusId);
    +
    +				$updateCronjobStatus = $tm_cronjob_statusModel->saveorUpdateCronjobStatusData($cronstatusData,$whereCronstatus);
    +				//end cronstatus update
    +			}
    +		}else{
    +			echo 'Some cron running';
    +		}
    +	}
    +	//End
    +
    +	//child function to block
    +	function notfilledDays($user_id,$fin_dates,$blockConfigDay){
    +		$monthCalWeek = array(); //cal_weeks in a month for notfilleddates
    +		$monthCalWeekDates = array();
    +
    +		foreach($fin_dates as $notFilledDate){
    +			//echo $notFilledDate.'
    '; + $cal_week = strftime('%U',strtotime($notFilledDate)); + if(!in_array($cal_week,$monthCalWeek)){ + $monthCalWeek[] = $cal_week; + } + /* $monthCalWeekDates(create individual cal_week dates array), This array not for specific month week */ + $monthCalWeekDates[$cal_week][] = $notFilledDate; + } + + if(count($monthCalWeek) > 0){ + foreach($monthCalWeek as $key => $calWeekVal){ + if(count($monthCalWeekDates[$calWeekVal])){ + $calWeekDate = $monthCalWeekDates[$calWeekVal][0]; + $ts_model = new Timemanagement_Model_Timesheetstatus(); + + //get start date of the week + $getDayString = strftime('%A',strtotime($calWeekDate)); + if($getDayString == 'Sunday'){ + $startDateOfWeek = date('F d, Y', strtotime($calWeekDate)); + }else{ + $startDateOfWeek = date('F d, Y', strtotime('last sunday', strtotime($calWeekDate))); + } + + $YearFromStartDate = strftime('%Y',strtotime($startDateOfWeek)); + + $weekDates = array(date('Y-m-d', strtotime($startDateOfWeek)), + date('Y-m-d', strtotime($startDateOfWeek . " +1 days")), + date('Y-m-d', strtotime($startDateOfWeek . " +2 days")), + date('Y-m-d', strtotime($startDateOfWeek . " +3 days")), + date('Y-m-d', strtotime($startDateOfWeek . " +4 days")), + date('Y-m-d', strtotime($startDateOfWeek . " +5 days")), + date('Y-m-d', strtotime($startDateOfWeek . " +6 days")), + ); + + $loopDate = $weekDates[0]; + + $yearCalWeekArray = array(); + $monthCalWeekArray = $monthWeekCalDatesArray = array(); + + while (strtotime($loopDate) <= strtotime($weekDates[6])) { + + $dateYearVal = strftime('%Y',strtotime($loopDate)); + $dateMonthVal = (int)strftime('%m',strtotime($loopDate)); + + $yearCalWeekArray[] = $dateYearVal; + $monthCalWeekArray[] = (int)$dateMonthVal; + $monthWeekCalDatesArray[$dateMonthVal][] = $loopDate; + + if(!in_array($loopDate,$monthWeekCalDatesArray[$dateMonthVal])){ + $monthCalWeekArray[$dateMonthVal][] = $loopDate; + } + $loopDate = date ("Y-m-d", strtotime("+1 day", strtotime($loopDate))); + } + + $yearCalWeekArray = array_unique($yearCalWeekArray); + $monthCalWeekArray = array_unique($monthCalWeekArray); + //echo '
    ';
    +					//print_r($monthWeekCalDatesArray); exit;
    +					foreach($monthCalWeekArray as $monthnum){
    +						$monthCalFirstWeek = date("Y-m-d", strtotime(strftime('%Y',strtotime($monthWeekCalDatesArray[$monthnum][0])).'-'.strftime('%m',strtotime($monthWeekCalDatesArray[$monthnum][0])).'-01'));
    +						$monthCalFirstWeek = strftime('%U',strtotime($monthCalFirstWeek));
    +
    +						$year = strftime('%Y',strtotime($monthWeekCalDatesArray[$monthnum][0]));
    +						$week = ($calWeekVal-$monthCalFirstWeek) + 1;
    +						$monthnum = (int)$monthnum;
    +						$empTsDataByDate = $ts_model->getTsRecordExists($user_id,$year,$monthnum,$week,$calWeekVal);//print_r($empTsDataByDate);exit;
    +
    +						$weekTableDateKeys = array('sun_date','mon_date','tue_date','wed_date','thu_date','fri_date','sat_date');
    +						$weekTableStatusKeys = array('sun_status','mon_status','tue_status','wed_status','thu_status','fri_status','sat_status');
    +						$projWeekTableStatusKeys = array('sun_project_status','mon_project_status','tue_project_status','wed_project_status','thu_project_status','fri_project_status','sat_project_status');
    +
    +						if(count($empTsDataByDate) == 0){
    +							$insertData = array('emp_id'=>$user_id,
    +											 'ts_year'=>$year,
    +											 'ts_month' => $monthnum,
    +											 'ts_week' => $week,
    +											 'cal_week'=>$calWeekVal,
    +											 'is_active' => 1,
    +						                     'created_by' => 1,
    +											 'created' => gmdate("Y-m-d H:i:s"),
    +											 'modified' => gmdate("Y-m-d H:i:s"),
    +							);
    +
    +							$tableStatusArray = array();
    +							$blockedFlag = false;
    +							$projStatusArray = array();
    +							foreach($weekTableDateKeys as $key => $tableDate){
    +								$projStatusArray[$projWeekTableStatusKeys[$key]] = 'no_entry';
    +								$insertData[$tableDate] = $weekDates[$key];
    +
    +								if(in_array($weekDates[$key],$monthCalWeekDates[$calWeekVal])){
    +									if(in_array($weekDates[$key],$monthWeekCalDatesArray[$monthnum])){ 
    +										$blockedFlag = true;
    +										$tableStatusArray[$weekTableStatusKeys[$key]] = 'blocked';
    +									}else{
    +										$tableStatusArray[$weekTableStatusKeys[$key]] = 'no_entry';
    +									}
    +								}else{
    +									$tableStatusArray[$weekTableStatusKeys[$key]] = 'no_entry';
    +								}
    +							}
    +
    +							// row not exists in tbl_ts_status, insert in 3 tables(tbl_ts_status,tm_emp_timesheets,tm_emp_ts_notes)
    +							$insertedEmpTsid = $ts_model->SaveEmpTsData($insertData);
    +							$insertedEmpTsNoesid = $ts_model->SaveEmpTsNotesData($insertData);
    +
    +							// add day status and week status to inserted array
    +							if($blockedFlag){
    +								$week_status = array('week_status' => 'blocked');
    +							}else{
    +								$week_status = array('week_status' => 'no_entry');
    +							}
    +
    +							$tsinsertData = $insertData + $tableStatusArray+ $week_status+$projStatusArray;
    +							$insertedTsid = $ts_model->SaveTsData($tsinsertData);
    +
    +						}else{ // update tbl_ts_status table for not not filled dates
    +							$updateData = array();
    +							$blockedFlag = false;
    +							foreach($weekTableDateKeys as $key => $tableDate){
    +								if(in_array($weekDates[$key],$monthCalWeekDates[$calWeekVal])){
    +									if(in_array($weekDates[$key],$monthWeekCalDatesArray[$monthnum])){ 
    +									    $blockedFlag = true;
    +										$updateData[$weekTableStatusKeys[$key]] = 'blocked';
    +									}else{
    +										$updateData[$weekTableStatusKeys[$key]]  = 'no_entry';
    +									}
    +								}
    +							}
    +							
    +							// add day status and week status to inserted array
    +							if($blockedFlag){
    +								$week_status_text = 'blocked';
    +							}else{
    +								$week_status_text = 'no_entry';
    +							}
    +							
    +							$updateData = $updateData + array('week_status' => $week_status_text,'modified' => gmdate("Y-m-d H:i:s"));
    +							$where['emp_id = ?'] = $user_id;
    +							$where['ts_year = ?'] = $year;
    +							$where['ts_month = ?'] = $monthnum;
    +							$where['ts_week = ?'] = $week;
    +							$where['cal_week = ?'] = $calWeekVal;
    +
    +							$updateTs = $ts_model->updateTsData($updateData,$where);
    +						}
    +					}
    +				}//end if(dates count in a week)
    +			}//end foreach $monthCalWeek Array
    +		}//end if $monthCalWeek count > 0
    +	}
    +
    +
    +	//cron to send timemanagement mails from tm_mailing_list
    +	function tmmailscron()
    +	{
    +		try{
    +			$tmMail_model = new Timemanagement_Model_Mailslist();
    +			$mails_data =  $tmMail_model->getPendingMailsData();
    +			//echo "
    ";print_r($mails_data);exit;
    +			if(count($mails_data) > 0)
    +			{
    +				foreach($mails_data as $mail)
    +				{
    +					if($mail['mail_type'] == 'submit_pending'){
    +						$options['subject'] = APPLICATION_NAME.': Pending Submission';
    +						$options['header'] = 'Pending Submission';
    +					}else if($mail['mail_type'] == 'reminder'){
    +						$options['subject'] = $options['subject'] = APPLICATION_NAME.': Timesheet Pending Reminder';
    +						$options['header'] = 'Timesheet Pending Reminder';
    +					}else if($mail['mail_type'] == 'block'){
    +						if(trim($mail['ts_dates']) == ''){
    +							$options['subject'] = APPLICATION_NAME.': Employee Timesheet Blocked';
    +							$options['header'] = 'Notification';
    +						}else if(trim($mail['ts_dates']) != ''){
    +							$options['subject'] = APPLICATION_NAME.': Timesheet Blocked';
    +							$options['header'] = 'Notification';
    +						}
    +					}
    +
    +					$options['toEmail'] = $mail['email'];
    +					$options['toName'] = $mail['emp_full_name'];
    +					$options['message'] = $mail['mail_content'];
    +
    +					$mail_status = sapp_Mail::_email($options);
    +
    +					$mail_where = array('id=?' => $mail['id']);
    +					$new_maildata['is_mail_sent'] = 1;
    +					if($mail_status === true)
    +					{
    +						//to udpate email table that mail is sent.
    +						$id = $tmMail_model->addOrUpdateMailsList($new_maildata,$mail_where);
    +					}
    +				}
    +			}
    +			else
    +			{
    +				echo "No any pending mails";
    +			}
    +		}
    +		catch(Exception $e){
    +			echo $e->getMessage();
    +		}
    +	}
    +	/*****END Timemanagememt crons ********/
    +
    +}
    +
    diff --git a/application/modules/timemanagement/controllers/DefaulttasksController.php b/application/modules/timemanagement/controllers/DefaulttasksController.php
    index c53d74d05..ac7f5153c 100644
    --- a/application/modules/timemanagement/controllers/DefaulttasksController.php
    +++ b/application/modules/timemanagement/controllers/DefaulttasksController.php
    @@ -36,6 +36,12 @@ public function init()
     	
     	public function preDispatch()
     	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
     		
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
    @@ -249,6 +255,7 @@ public function deleteAction()
     				$Id = $taskModel->SaveorUpdateTaskData($data, $where);
     				if($Id == 'update')
     				{
    +					//sapp_Global::send_configuration_mail("Default Task", $taskData[0]['task']);
     					$messages['message'] = 'Default task deleted successfully.';
     					$messages['msgtype'] = 'success';
     				}
    diff --git a/application/modules/timemanagement/controllers/EmptimesheetsController.php b/application/modules/timemanagement/controllers/EmptimesheetsController.php
    index 651cc1087..d99b6cdff 100644
    --- a/application/modules/timemanagement/controllers/EmptimesheetsController.php
    +++ b/application/modules/timemanagement/controllers/EmptimesheetsController.php
    @@ -39,6 +39,12 @@ class Timemanagement_EmptimesheetsController extends Zend_Controller_Action
     	 */
     	public function preDispatch()
     	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
     		
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
    @@ -50,6 +56,11 @@ public function preDispatch()
     		$ajaxContext->addActionContext('accordion', 'html')->initContext();
     		$ajaxContext->addActionContext('emptimesheetmonthly', 'html')->initContext();
     		$ajaxContext->addActionContext('emptimesheetweekly', 'html')->initContext();
    +		$ajaxContext->addActionContext('enabletimesheet', 'json')->initContext();
    +		$ajaxContext->addActionContext('approvetimesheet', 'json')->initContext();
    +		$ajaxContext->addActionContext('rejecttimesheet', 'json')->initContext();
    +		$ajaxContext->addActionContext('approvedaytimesheet', 'json')->initContext();
    +		$ajaxContext->addActionContext('rejectdaytimesheet', 'json')->initContext();
     		$ajaxContext->addActionContext('getweekstartenddates', 'json')->initContext();
     	}
     
    @@ -188,6 +199,7 @@ public function getmonthlyspanAction()
     	 */
     	public function accordionAction()
     	{
    +		//print_r($this->_getAllParams());exit();
     		$emp_list_flag=$this->_getParam('emp_list_flag','');
     		$hidweek=$this->_getParam('hidweek');
     		$type=$this->_getParam('type');
    @@ -298,6 +310,7 @@ public function emptimesheetmonthlyAction(){
     		$yrMon = explode('-', $selYrMon);
     
     		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +		//$empMYTSModel = new Timemanagement_Model_MyTimesheet();
     
     		$empMonthTSData = $empTSModel->getMonthTimesheetData($user_id, $yrMon[0],$yrMon[1],$project_ids,$emplistflag);
     			
    @@ -371,6 +384,7 @@ public function emptimesheetweeklyAction(){
     		$empDoj = $usersModel->getEmployeeDoj($user_id);
     		$dateEmpDoj = date('Y-m',strtotime($empDoj['date_of_joining']));
     
    +		$approvedAlert = $usersModel->getEmpApprovalStatusDteails($user_id);
     			
     		$selYrMon = ($selYrMon != '')?$selYrMon:$now->format('Y-m');
     		$yrMon = explode('-', $selYrMon);
    @@ -396,6 +410,7 @@ public function emptimesheetweeklyAction(){
     		$empHolidaysWeekendsData = $usersModel->getEmployeeHolidaysNWeekends($user_id, $yrMon[0],$yrMon[1],$calWeek);
     
     		$startDate = date("Y-m-d", strtotime("{$yrMon[0]}-W{$calWeek}-7"));
    +		//$startDate =  date("Y-m-d",strtotime('last sunday', strtotime($yrMon[0].'W'.str_pad($calWeek+1, 2, 0, STR_PAD_LEFT))));
     		$endDate = date("Y-m-d",strtotime('next saturday',strtotime($startDate)));
     			
     		$empLeavesData = $usersModel->getEmpLeaves($user_id,$startDate,$endDate,'all');
    @@ -416,6 +431,7 @@ public function emptimesheetweeklyAction(){
     		$this->view->weekNotesData = $weekNotes;
     		$this->view->empHolidaysWeekends = $empHolidaysWeekendsData[0];
     		$this->view->leavesData = $empLeavesData;
    +		$this->view->approvedAlert =  $approvedAlert;
     		$this->view->weekDaysStatus = $weekDaysStatus;
     		$this->view->empData = $empData;
     		$this->view->emplistflag = $emplistflag;
    @@ -427,20 +443,174 @@ public function emptimesheetweeklyAction(){
     
     	}
     
    +	/**
    +	 * Action to enable employee timesheet for month or week based on calender week.
    +	 */
    +	public function enabletimesheetAction (){
    +		$selYrMon = $this->_getParam('selmn');
    +		$emp_id = $this->_getParam('emp_id');
    +		$type = $this->_getParam('type');
    +		$week = $this->_getParam('hideweek');
    +		$emplistflag = $this->_getParam('emplistflag');
    +		$yrMon = explode('-', $selYrMon);
    +		$year = $yrMon[0];
    +		$month = $yrMon[1];
    +
    +		$result = false;
    +		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +
    +		$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
    +		$firstCalWeek = strftime('%U',strtotime($year.'-'.$month.'-01'));
    +		$lastCalWeek = strftime('%U',strtotime($selYrMon.'-'.$lastday));
    +		$calenderWeek = array();
    +		$calenderWeeksArray = range($firstCalWeek, $lastCalWeek);
    +		if($type == 'month'){
    +			$calenderWeek = $calenderWeeksArray;
    +		}
    +		if($type == 'week'){
    +			$calenderWeek[0] = $calenderWeeksArray[$week-1];
    +		}
    +		$result = $empTSModel-> updateEmployeeTimesheet($emp_id,$year,$month,$lastday,$calenderWeek,"enable","",$emplistflag);
    +		$this->_helper->json(array('saved'=>$result));
    +	}
    +
    +	/**
    +	 * Action to Approve employee timesheet for month or week based on calender week.
    +	 */
    +	public function approvetimesheetAction (){
    +		$selYrMon = $this->_getParam('selmn');
    +		$emp_id = $this->_getParam('emp_id');
    +		$type = $this->_getParam('type');
    +		$week = $this->_getParam('hideweek');
    +		$emplistflag = $this->_getParam('emplistflag');
    +		$yrMon = explode('-', $selYrMon);
    +		$year = $yrMon[0];
    +		$month = $yrMon[1];
    +
    +		$result = false;
    +		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +
    +		$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
    +		$firstCalWeek = strftime('%U',strtotime($year.'-'.$month.'-01'));
    +		$lastCalWeek = strftime('%U',strtotime($selYrMon.'-'.$lastday));
    +
    +		$calenderWeek = array();
    +		$calenderWeeksArray = range($firstCalWeek, $lastCalWeek);
    +		if($type == 'month'){
    +			$calenderWeek = $calenderWeeksArray;
    +		}
    +		if($type == 'week'){
    +			$calenderWeek[0] = $calenderWeeksArray[$week-1];
    +		}
    +		$result = $empTSModel-> updateEmployeeTimesheet($emp_id,$year,$month,$lastday,$calenderWeek,"approve","",$emplistflag);
    +		$this->_helper->json(array('saved'=>$result));
    +	}
    +
    +	/**
    +	 * Action to reject employee timesheet for month or week based on calender week.
    +	 */
    +	public function rejecttimesheetAction (){
    +		$selYrMon = $this->_getParam('selmn');
    +		$emp_id = $this->_getParam('emp_id');
    +		$type = $this->_getParam('type');
    +		$week = $this->_getParam('hideweek');
    +		$rejnote = $this->_getParam('rejnote');
    +		$emplistflag = $this->_getParam('emplistflag');
    +
    +		$yrMon = explode('-', $selYrMon);
    +		$year = $yrMon[0];
    +		$month = $yrMon[1];
    +
    +		$result = false;
    +		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +
    +		$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
    +		$firstCalWeek = strftime('%U',strtotime($year.'-'.$month.'-01'));
    +		$lastCalWeek = strftime('%U',strtotime($selYrMon.'-'.$lastday));
    +
    +		$calenderWeek = array();
    +		$calenderWeeksArray = range($firstCalWeek, $lastCalWeek);
    +		if($type == 'month'){
    +			$calenderWeek = $calenderWeeksArray;
    +		}
    +		if($type == 'week'){
    +			$calenderWeek[0] = $calenderWeeksArray[$week-1];
    +		}
    +		$result = $empTSModel-> updateEmployeeTimesheet($emp_id,$year,$month,$lastday,$calenderWeek,"reject",$rejnote,$emplistflag);
    +		$this->_helper->json(array('saved'=>$result));
    +	}
    +
    +	/**
    +	 * Action to approve employee timesheet for a particular day.
    +	 */
    +	public function approvedaytimesheetAction(){
    +		$selYrMon = $this->_getParam('selmn');
    +		$emp_id = $this->_getParam('emp_id');
    +		$day = $this->_getParam('day');
    +		$emplistflag = $this->_getParam('emplistflag');
    +
    +		$approvedDate = $selYrMon."-".$day;
    +		$yrMon = explode('-', $selYrMon);
    +		$year = $yrMon[0];
    +		$month = $yrMon[1];
    +		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +
    +		$approvedDateTimestamp = strtotime(DATE($approvedDate));
    +		$approvedDate_day = strtolower(DATE('D', $approvedDateTimestamp));
    +		$approvedDate = DATE('Y-m-d', $approvedDateTimestamp);
    +
    +		$calweek=strftime('%U',strtotime($approvedDate));
    +
    +		$result = $empTSModel->updateEmployeeDayTimesheet($emp_id,$calweek,$year,$month,$approvedDate_day,$approvedDate, "approve", "",$emplistflag);
    +
    +		$this->_helper->json(array('saved'=>$result));
    +	}
    +
    +	/**
    +	 * Action to reject employee timesheet for a particular day.
    +	 */
    +	public function rejectdaytimesheetAction(){
    +		$selYrMon = $this->_getParam('selmn');
    +		$emp_id = $this->_getParam('emp_id');
    +		$day = $this->_getParam('day');
    +		$rejnote = $this->_getParam('rejnote');
    +		$emplistflag = $this->_getParam('emplistflag');
    +
    +		$approvedDate = $selYrMon."-".$day;
    +		$yrMon = explode('-', $selYrMon);
    +		$year = $yrMon[0];
    +		$month = $yrMon[1];
    +		$empTSModel = new Timemanagement_Model_Emptimesheets();
    +
    +		$approvedDateTimestamp = strtotime(DATE($approvedDate));
    +		$approvedDate_day = strtolower(DATE('D', $approvedDateTimestamp));
    +		$approvedDate = DATE('Y-m-d', $approvedDateTimestamp);
    +
    +		$calweek=strftime('%U',strtotime($approvedDate));
    +		$result = $empTSModel->updateEmployeeDayTimesheet($emp_id,$calweek,$year,$month,$approvedDate_day,$approvedDate, "reject",$rejnote,$emplistflag);
    +
    +		$this->_helper->json(array('saved'=>$result));
    +
    +	}
     	//function to get week start end dates
     	public function getweekstartenddatesAction()
     	{
     		$selYrMon = $this->_getParam('selmn');
     		$week = $this->_getParam('hidweek');
     		$currentMonth = date($selYrMon);
    +		//$datesArray =  iterator_to_array(new DatePeriod(new DateTime("first sunday of $currentMonth"),
    +		//DateInterval::createFromDateString('next sunday'),new DateTime("last day of $currentMonth")));
    +		
     		
     		$selectedYrMon = explode('-', $currentMonth);
    +      	//$selMonName = date('F', mktime(0, 0, 0, $selectedYrMon[1], 10)); 
           	$firstday = date("w", mktime(0, 0, 0, $selectedYrMon[1], 1, $selectedYrMon[0])); 
             $lastday = date("t", mktime(0, 0, 0, $selectedYrMon[1], 1, $selectedYrMon[0])); 
     		$noOfweeks = 1 + ceil(($lastday-7+$firstday)/7);
     		 
     		
     		$selWeek = $week;
    +		//$nextMonth = $selectedYrMon[1]+1;
     		if($selectedYrMon[1] < 12) 
     			$nextMonth = $selectedYrMon[1]+1;
     		else 
    @@ -456,7 +626,7 @@ public function getweekstartenddatesAction()
     			
     		if($week == 1) {
     			$startDate = $currentMonth."-1";
    -			
    +			//$weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate)));
     			$startDateName = date('D', strtotime($startDate));
     			if($startDateName != "Sun") {
     				$weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate)));
    diff --git a/application/modules/timemanagement/controllers/IndexController.php b/application/modules/timemanagement/controllers/IndexController.php
    index 94c17b39d..b53f0193e 100644
    --- a/application/modules/timemanagement/controllers/IndexController.php
    +++ b/application/modules/timemanagement/controllers/IndexController.php
    @@ -24,12 +24,21 @@ class Timemanagement_IndexController extends Zend_Controller_Action
     	private $options;
     	public function preDispatch()
     	{
    +		// $userModel = new Timemanagement_Model_Users();
    +		// $checkTmEnable = $userModel->checkTmEnable();
     
    +		// if(!$checkTmEnable){
    +			// $this->_redirect('error');
    +		// }
    +		
    +		
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
     			$this->_redirect('error');
     
     		$ajaxContext = $this->_helper->getHelper('AjaxContext');
    +		$ajaxContext->addActionContext('getapprovedtimesheet', 'html')->initContext();
    +		$ajaxContext->addActionContext('closeapprovealert', 'json')->initContext();
     		$ajaxContext->addActionContext('save', 'json')->initContext();
     		$ajaxContext->addActionContext('submit', 'json')->initContext();
     		$ajaxContext->addActionContext('eraseweek', 'json')->initContext();
    @@ -52,22 +61,48 @@ public function indexAction()
     			
     		$selYrMon = $this->_getParam('selYrMon');
     
    +		//$startYrMon = $this->_getParam('startYrMon');
     		$flag = $this->_getParam('flag');
    -	
    +			
    +		//        $month = $this->_getParam('month');
    +		//    	$year = $this->_getParam('year');
    +			
    +		//$empid = $this->_getParam('empid');
    +		//echo " MONTH ".$month. "  YEAR ".$year; exit;
    +
    +		$approvedAlert = $usersModel->getEmpApprovalStatusDteails($data->id);
    +			
     		$empDoj = $usersModel->getEmployeeDoj($data->id);
    -		
     		$this->view->empDoj=$empDoj['date_of_joining'];
     		$dateEmpDoj = date('Y-m',strtotime($empDoj['date_of_joining']));
     			
    -		
    +		//    	$datestring='2011-01 last month';
    +		//		$dt=date_create($datestring);
    +		//		echo $dt->format('Y-m'); //2011-02
    +		//	$YrMonths = array();
     		$now = new DateTime();
    -		
    +		//		if($flag == 'next' || $flag == '') {
    +		//			$YrMonths[3] = ($startYrMon != '')?$startYrMon: $now->format('Y-m');
    +		//			for($i = 2,$j=0; $i >=0; $i--) {
    +		//				$dt=date_create($YrMonths[3-$j].'last month');
    +		//				$YrMonths[$i] = $dt->format('Y-m');
    +		//				$j++;
    +		//			}
    +		//		} else {
    +		//			$YrMonths[0] = ($startYrMon != '')?$startYrMon: $now->format('Y-m');
    +		//			for($i = 1; $i <=3; $i++) {
    +		//				$dt=date_create($YrMonths[$i-1].'next month');
    +		//				$YrMonths[$i] = $dt->format('Y-m');
    +		//			}
    +		//		}
    +		//$YrMonths[3] = ($startYrMon != '')?$startYrMon: $now->format('Y-m');
     		if($selYrMon != '') {
     			$selYrMon = date('Y-m',strtotime($selYrMon));
     			if($flag == 'next') {
     				if($selYrMon < $now->format('Y-m'))
     				$selYrMon = date_create($selYrMon.'next month')->format('Y-m');
     			}else if($flag == 'pre'){
    +				//echo " selYrMon ".$selYrMon." dateEmpDoj ".$dateEmpDoj;
     				if($selYrMon > $dateEmpDoj)
     				$selYrMon = date_create($selYrMon.'last month')->format('Y-m');
     				else
    @@ -78,29 +113,61 @@ public function indexAction()
     
     		$selYrMon = ($selYrMon != '')?$selYrMon:$now->format('Y-m');
     
    +		//ksort($YrMonths);
     			
     		$yrMon = explode('-', $selYrMon);
     		$empTSModel = new Timemanagement_Model_MyTimesheet();
     		$empMonthTSData = $empTSModel->getMonthTimesheetData($data->id, $yrMon[0],$yrMon[1]);
    -		
    +		//print_r($empMonthTSData); exit;
     		$empHolidaysWeekendsData = $usersModel->getEmployeeHolidaysNWeekends($data->id, $yrMon[0],$yrMon[1]);
    -		
    +		//print_r($empHolidaysWeekendsData); exit;
    +			
    +		//echo $selYrMon;
     		$firstday = $yrMon[0]."-".$yrMon[1].'-01';
     		$noOfDaysMonth = date("t", mktime(0, 0, 0, $yrMon[1], 1, $yrMon[0]));
     		$lastday =   $yrMon[0]."-".$yrMon[1]."-".$noOfDaysMonth;
     			
     		$empLeavesData = $usersModel->getEmpLeaves($data->id,$firstday,$lastday,'all');
    -		$cronDetails = array();
    +
    +		$cronDetails = $empTSModel->getCronDetailsForMonth($yrMon[0],$yrMon[1]);
     		$cronStartDay = "";
     		$cronEndDay = "";
    +		if(!empty($cronDetails)) {
    +			$cronStartDay = date('d',strtotime($cronDetails[0]['ts_start_date']));
    +			if($cronStartDay != 1) {
    +				$cronStartDay = 1;
    +				$mon = $yrMon[1]+1;
    +				$yr = ($mon == 12)?($yrMon[0] +1):$yrMon[0];
    +				$nextMonCronDetails = $empTSModel->getCronDetailsForMonth($yr,$mon);
    +				if(!empty($nextMonCronDetails)) {
    +					$cronEndDay = $noOfDaysMonth;
    +				} else {
    +					$cronEndDay = date('d',strtotime($cronDetails[0]['ts_end_date']));
    +				}
    +			}
    +		} else {
    +			$mon = $yrMon[1]+1;
    +			$yr = ($mon == 12)?($yrMon[0] +1):$yrMon[0];
    +			$nextMonCronDetails = $empTSModel->getCronDetailsForMonth($yr,$mon);
    +
    +			if(!empty($nextMonCronDetails)) {
    +				if($yrMon[1]  == date('m',strtotime($nextMonCronDetails[0]['ts_start_date'])))
    +				$cronStartDay = date('d',strtotime($nextMonCronDetails[0]['ts_start_date']));
    +				$cronEndDay = $noOfDaysMonth;
    +			}
    +
    +		}
     
     		$this->view->empMonthTSData = $empMonthTSData;
     		$this->view->empHolidaysWeekends = $empHolidaysWeekendsData[0];
    -
    +		//	$this->view->month = $month;
    +		//	$this->view->year = $year;
    +		//$this->view->YrMonths = $YrMonths;
     		$this->view->selYrMon =  $selYrMon;
     		$this->view->leavesData = $empLeavesData;
     		$this->view->cronStartDay = $cronStartDay;
     		$this->view->cronEndDay = $cronEndDay;
    +		$this->view->approvedAlert =  $approvedAlert;
     
     
     
    @@ -109,7 +176,6 @@ public function indexAction()
          	if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     		}
    -		
     		$leaverequestform = new Default_Form_leaverequest();
     		$leaverequestform->setAttrib('action',BASE_URL.'leaverequest');
     		$leaverequestmodel = new Default_Model_Leaverequest();
    @@ -294,6 +360,28 @@ public function indexAction()
     		$this->view->loginUserId = $loginUserId;
     		$this->view->messages = $this->_helper->flashMessenger->getMessages();
     		/*leave request code ends*/
    +		
    +		
    +		//START code to show pending weeks for submit in current month
    +
    +		$projmodel = new Timemanagement_Model_Projects();
    +		$prevweeks = $projmodel->getprevmonthweeks(date('Y-m') , date('d'));
    +		 $end_date = max($prevweeks[count($prevweeks)]);//get previous week end date
    +		 $start_date = min($prevweeks[count($prevweeks)]);//get previous week start date
    +				       $prev_str='';
    +		if($start_date>=date('Y-m-01') && $start_date<=date('Y-m-t'))
    +		{
    +		// echo " TM Role >> ".Zend_Registry::get('tm_role');
    +				$prev_week_status=$projmodel->prev_weeksubmit_status($prevweeks,$data->id,$empDoj);
    +
    +		
    +		       if($prev_week_status!='')
    +		       {
    +		          $this->view->prev_str=$prev_week_status;
    +		       }
    +		}	   
    +		//END code to show pending weeks for submit in current month
    +
     	}
     
     	public function weekAction()
    @@ -313,6 +401,8 @@ public function weekAction()
     		if($data->id == 1)
     		$this->_redirect('error');
     
    +
    +		$approvedAlert = $usersModel->getEmpApprovalStatusDteails($data->id);
     		$selYrMon = ($selYrMon != '')?$selYrMon:$now->format('Y-m');
     		$yrMon = explode('-', $selYrMon);
     
    @@ -324,9 +414,13 @@ public function weekAction()
     		}
     
     		$empDoj = $usersModel->getEmployeeDoj($data->id);
    +		//$dateEmpDoj = date('Y-m',strtotime($empDoj['date_of_joining']));
    +
     
     		$selYrMonArray = explode('-', $selYrMon);
     
    +		//if($calWeek == null || $calWeek == '') {
    +		//$calWeekNo = gmstrftime('%U',strtotime($selYrMon.'-01'));
     
     		if($selDay != '') {
     			$calWeek = strftime('%U',strtotime($selYrMon.'-'.$selDay));
    @@ -336,38 +430,69 @@ public function weekAction()
     			if($calWeek == '')
     			$calWeek = strftime('%U',strtotime($selYrMon.'-01'));
     		}
    -
    +		//	}
     		$myTsModel = new Timemanagement_Model_MyTimesheet();
    -		
    +		//$myTsWeekData = $myTsModel->getWeeklyTimesheetData($data->id,$selYrMonArray[0],$selYrMonArray[1],$week);
     		if($timeFlag == 'time') {
     			$myTsWeekData = $myTsModel->getWeeklyTimesheetData($data->id,$selYrMonArray[0],$selYrMonArray[1],$week);
     		} else {
     			$myTsWeekData = $myTsModel->getWeeklyTimesheetData($data->id,$selYrMonArray[0],$selYrMonArray[1],$week,'view');
     		}
    +		//print_r($myTsWeekData);
    +		$empHolidaysWeekendsData = $usersModel->getEmployeeHolidaysNWeekends($data->id, $yrMon[0],$yrMon[1],$calWeek);
    +		//echo date("Y-m-d", strtotime("{$yrMon[0]}-W{$calWeek}-7"));
     		
    +		//$startDate = date("Y-m-d", strtotime("{$yrMon[0]}-W{$calWeek}-7"));
     		
    -		$empHolidaysWeekendsData = $usersModel->getEmployeeHolidaysNWeekends($data->id, $yrMon[0],$yrMon[1],$calWeek);
    -
    -		$startDate = date("Y-m-d", strtotime("{$yrMon[0]}-W{$calWeek}-7"));
    +		if($calWeek>=1 && $calWeek<=9)
    +			$calWeek = '0'.$calWeek;
    +		
    +		$startDate = date("Y-m-d", strtotime("{$yrMon[0]}-W{$calWeek}, -1 day"));
    +		
    +		//$startDate =  date("Y-m-d",strtotime('last sunday', strtotime($yrMon[0].'W'.str_pad($calWeek+1, 2, 0, STR_PAD_LEFT))));
     		
     		$endDate = date("Y-m-d",strtotime('next saturday',strtotime($startDate)));
     
     		$empLeavesData = $usersModel->getEmpLeaves($data->id,$startDate,$endDate,'all');
    -		
    +		//print_r($empLeavesData);
     		$weekNotes = $myTsModel->getWeekNotes($data->id,$selYrMonArray[0],$selYrMonArray[1],$week);
     
    -		
    +		//$weekDaysStatus =  $myTsModel->getWeekDaysStatus($data->id,$selYrMonArray[0],$calWeek);
     		$weekDaysStatus =  $myTsModel->getWeekDaysStatus($data->id,$selYrMonArray[0],$selYrMonArray[1],$week);
     		$weekDaysProjStatus =  $myTsModel->getWeekDaysProjStatus($data->id,$selYrMonArray[0],$selYrMonArray[1],$week);
     		
    -		
    +		//print_r($weekDaysStatus);
    +		//print_r($weekNotes);
    +		$cronDetails = $myTsModel->getCronDetailsForMonth($selYrMonArray[0],$selYrMonArray[1]);
     		$noOfDaysMonth = date("t", mktime(0, 0, 0, $selYrMonArray[1], 1, $selYrMonArray[0]));
     		$cronStartDay = "";
     		$cronEndDay = "";
    -		
    -
    +		if(!empty($cronDetails)) {
    +			$cronStartDay = date('d',strtotime($cronDetails[0]['ts_start_date']));
    +			if($cronStartDay != 1) {
    +				$cronStartDay = 1;
    +				$mon = $yrMon[1]+1;
    +				$yr = ($mon == 12)?($selYrMonArray[0] +1):$selYrMonArray[0];
    +				$nextMonCronDetails = $myTsModel->getCronDetailsForMonth($yr,$mon);
    +				if(!empty($nextMonCronDetails)) {
    +					$cronEndDay = $noOfDaysMonth;
    +				} else {
    +					$cronEndDay = date('d',strtotime($cronDetails[0]['ts_end_date']));
    +				}
    +			}
    +		} else {
     			$mon = $yrMon[1]+1;
     			$yr = ($mon == 12)?($selYrMonArray[0] +1):$selYrMonArray[0];
    +			$nextMonCronDetails = $myTsModel->getCronDetailsForMonth($yr,$mon);
    +				
    +			if(!empty($nextMonCronDetails)) {
    +				if($yrMon[1]  == date('m',strtotime($nextMonCronDetails[0]['ts_start_date'])))
    +				$cronStartDay = date('d',strtotime($nextMonCronDetails[0]['ts_start_date']));
    +				$cronEndDay = $noOfDaysMonth;
    +			}
    +				
    +		}
    +
     		if($selDay != '') {
     			$this->view->selDay =  date("D",strtotime($selYrMon.'-'.$selDay));
     		}
    @@ -378,19 +503,28 @@ public function weekAction()
     		$this->view->weekNotesData = $weekNotes;
     		$this->view->empHolidaysWeekends = $empHolidaysWeekendsData[0];
     		$this->view->leavesData = $empLeavesData;
    -		
    +		$this->view->approvedAlert =  $approvedAlert;
     		$this->view->weekDaysStatus = $weekDaysStatus;
     		$this->view->weekDaysProjStatus = $weekDaysProjStatus;		
     		$this->view->cronStartDay = $cronStartDay;
     		$this->view->cronEndDay = $cronEndDay;
     
    -		
    +		//if($timeFlag == 'time') $this->renderScript('index/enter_time.phtml');
    +
    +
     		//START code to show pending weeks for submit in current month
     
     		$projmodel = new Timemanagement_Model_Projects();
     		$prevweeks = $projmodel->getprevmonthweeks(date('Y-m') , date('d'));
    -		
    -		
    +		// echo " TM Role >> ".Zend_Registry::get('tm_role');
    +		//		$prev_week_status=$projmodel->prev_weeksubmit_status($prevweeks,$data->id,$empDoj);
    +		//        $prev_str='';
    +		//
    +		//        if($prev_week_status!='')
    +		//        {
    +		//           $this->view->prev_str=$prev_week_status;
    +		//        }
    +		//END code to show pending weeks for submit in current month
     			
     		/*Leave request code starts*/
     		$auth = Zend_Auth::getInstance();
    @@ -422,7 +556,6 @@ public function weekAction()
     		$businessunitid = '';
     		$hremailgroup = '';
     		
    -		
     		/* Start
     		   Queries to fetch user details,reporting manager details and weekend details from users table and employees table
     		*/
    @@ -448,6 +581,7 @@ public function weekAction()
     						$employeeDepartmentId = $loggedInEmployeeDetails[0]['department_id'];
     						$employeeEmploymentStatusId = $loggedInEmployeeDetails[0]['emp_status_id'];
     						$employeeHolidayGroupId = $loggedInEmployeeDetails[0]['holiday_group'];
    +						
     						$reportingManagerDetails = $usersmodel->getUserDetailsByID($reportingmanagerId);
     						$weekendDatailsArr = $leavemanagementmodel->getWeekendDetails($employeeDepartmentId);
                             $employeeemail = $loggedinEmpId[0]['emailaddress'];
    @@ -503,9 +637,9 @@ public function weekAction()
     				    	  else
     				    	  	$searchMeFlag = 'false';	
     				    	}	  	
    +				    	
     				    	if($searchMeFlag == 'true')
     							$leaverequestdetails = $leaverequestmodel->getUserApprovedOrPendingLeavesData($loginUserId);
    -						
     						/* Start -For Checking if logged in user is reporting manager */
     						$isReportingManager = $employeesmodel->CheckIfReportingManager($loginUserId);
     						if(!empty($isReportingManager) && $isReportingManager[0]['count']>0) {
    @@ -536,6 +670,7 @@ public function weekAction()
     					}   					
     			}
     		/* End */
    +		
     		/* 
     		 Start
     		 Query to fetch and build multioption for Leavetype dropdown
    @@ -555,7 +690,6 @@ public function weekAction()
     				$msgarray['leavetypeid'] = ' Leave types are not configured yet.';
     			}
     			$this->view->leavetype = $leavetype;
    -			
     		/* End */
     		
     		/*
    @@ -575,12 +709,14 @@ public function weekAction()
     			$this->view->getavailbaleleaves = $getavailbaleleaves;	
     	    /* END */
     		
    +		
     		$this->view->form = $leaverequestform; 
     		$this->view->msgarray = $msgarray;
     		$this->view->loginUserId = $loginUserId;
     		$this->view->messages = $this->_helper->flashMessenger->getMessages();
     		/*leave request code ends*/
    -		
    +
    +
     		if($timeFlag != '') {
     			$this->_helper->viewRenderer('entertime');
     		}
    @@ -589,6 +725,19 @@ public function weekAction()
     
     	public function saveAction()
     	{
    +		
    +		
    +		$usersModel = new Timemanagement_Model_Users();
    +		$storage = new Zend_Auth_Storage_Session();
    +		$data = $storage->read();
    +		$empDoj = $usersModel->getEmployeeDoj($data->id);
    +		
    +		$doj = $empDoj['date_of_joining'];
    +		if($doj>date('Y-m-d'))
    +		{
    +			$this->view->status = 'failure';
    +		}else
    +		{	
     
     		$tasksHrsData = $this->_getParam('data');
     		$calWeek = $this->_getParam('calWeek');
    @@ -597,7 +746,7 @@ public function saveAction()
     		$weekEndDate = $this->_getParam('weekEnd');
     		$selYrMon = $this->_getParam('selYrMon');
     		$tasksData = explode(',',$tasksHrsData);
    -		
    +		//echo "tasksData ".sizeof($tasksData);
     		$callval = $this->getRequest()->getParam('call');
     		$sunNote = $this->_getParam('sun_note');
     		$monNote = $this->_getParam('mon_note');
    @@ -608,6 +757,8 @@ public function saveAction()
     		$satNote = $this->_getParam('sat_note');
     		$weekNote = $this->_getParam('week_note');
     
    +
    +		//$msgarray = array();
     		$storage = new Zend_Auth_Storage_Session();
     		$sessionData = $storage->read();
     
    @@ -622,17 +773,17 @@ public function saveAction()
     			foreach($tasksData as $data) {
     
     				$taskDataArray = explode('#',$data);
    -				
    +				//echo " SUN ".$taskDataArray[2];
     				$sun_hrs =($taskDataArray[2] != null)? $taskDataArray[2]:0;
    -				
    +				//echo " sun_hrs ".$sun_hrs;
     				$sun_tot = 0;
     				if(!empty($sun_hrs)) {
     					$sun_dur = explode(':',$sun_hrs);
     					$sun_tot += $sun_dur[0] * 60;
    -				
    +					//echo " Hrs ".$sun_dur[0];
     					$sun_tot += $sun_dur[1];
     				}
    -				
    +				//echo " sun_tot ".$sun_tot;
     				$mon_hrs =($taskDataArray[3] != null)? $taskDataArray[3]:0;
     				$mon_tot = 0;
     				if(!empty($mon_hrs)) {
    @@ -686,7 +837,7 @@ public function saveAction()
     				if(strlen($wkHrsPart.'') == 1) $wkHrsPart = '0'.$wkHrsPart;
     				if(strlen($wkMinsPart.'') == 1) $wkMinsPart = '0'.$wkMinsPart;
     
    -				
    +				//$week_tot = floor($week_tot_time / 60).':'.$week_tot_time % 60 ;
     				$week_tot = $wkHrsPart.':'.$wkMinsPart;
     
     				array_push($projTasksArray, $taskDataArray[0]);
    @@ -714,9 +865,9 @@ public function saveAction()
     			  			  'sat_duration'=>($taskDataArray[8] != null)?$taskDataArray[8]:'00:00',			
     						  'week_duration'=>$week_tot,
     						  'created_by'=>$sessionData->id,
    -				
    +				//  'modified_by'=>NULL,
     			        	  'is_active'=>1,
    -			  			  'created'=> Zend_Registry::get('currentdate') 
    +			  			  'created'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
     				);
     				$checkProjNull = $myTsModel->getProjNullRecordCountInTimeSheet($sessionData->id,$selYrMonArray[0],$selYrMonArray[1],$week);				
     				
    @@ -728,7 +879,8 @@ public function saveAction()
     					$myTsModel->updateTimesheetRecord($data,$where);
     				} else {					
     					$myTsModel->SaveOrUpdateTimesheet($data);
    -				
    +					//print_r($data);
    +					//exit;
     				}	
     				if($projectId != $taskDataArray[1]) {
     					$projectId = $taskDataArray[1];
    @@ -739,7 +891,7 @@ public function saveAction()
     			foreach($projsArray as $proj) {
     
     				$projHrsData = $myTsModel->getWeekProjectHrs($sessionData->id,$proj,$selYrMonArray[0],$selYrMonArray[1],$week);
    -				
    +				//	print_r($projHrsData); exit;
     
     				$statusData = array('emp_id'=>$sessionData->id,
     						  'project_id'=>$proj,
    @@ -751,36 +903,43 @@ public function saveAction()
     						  'sun_project_status'=>($projHrsData[0]['sun_duration'] !='00:00')?'saved':'no_entry',
     						  'sun_status'=>($projHrsData[0]['sun_duration'] !='00:00')?'saved':'no_entry',
     						  'sun_status_date'=>Zend_Registry::get('currentdate'),
    +						  'sun_reject_note'=>'',
     					 	  'mon_date'=>date('Y-m-d', strtotime('+1 day', strtotime($weekStartDate))),
     						  'mon_project_status'=>($projHrsData[0]['mon_duration'] !='00:00')?'saved':'no_entry',
     						  'mon_status'=>($projHrsData[0]['mon_duration'] !='00:00')?'saved':'no_entry',
     						  'mon_status_date'=>Zend_Registry::get('currentdate'),
    +						  'mon_reject_note'=>'',
     						  'tue_date'=>date('Y-m-d', strtotime('+2 day', strtotime($weekStartDate))),
     					 	  'tue_project_status'=>($projHrsData[0]['tue_duration'] !='00:00')?'saved':'no_entry',
     						  'tue_status'=>($projHrsData[0]['tue_duration'] !='00:00')?'saved':'no_entry',
     						  'tue_status_date'=>Zend_Registry::get('currentdate'),
    +						  'tue_reject_note'=>'',
     						  'wed_date'=>date('Y-m-d', strtotime('+3 day', strtotime($weekStartDate))),
     					 	  'wed_project_status'=>($projHrsData[0]['wed_duration'] !='00:00')?'saved':'no_entry',
     						  'wed_status'=>($projHrsData[0]['wed_duration'] !='00:00')?'saved':'no_entry',
     						  'wed_status_date'=>Zend_Registry::get('currentdate'),
    +						  'wed_reject_note'=>'',	
     						  'thu_date'=>date('Y-m-d', strtotime('+4 day', strtotime($weekStartDate))),
     					 	  'thu_project_status'=>($projHrsData[0]['thu_duration'] !='00:00')?'saved':'no_entry',
     						  'thu_status'=>($projHrsData[0]['thu_duration'] !='00:00')?'saved':'no_entry',
     						  'thu_status_date'=>Zend_Registry::get('currentdate'),
    +						  'thu_reject_note'=>'', 	
     						  'fri_date'=>date('Y-m-d', strtotime('+5 day', strtotime($weekStartDate))),	
     					 	  'fri_project_status'=>($projHrsData[0]['fri_duration'] !='00:00')?'saved':'no_entry',
     						  'fri_status'=>($projHrsData[0]['fri_duration'] !='00:00')?'saved':'no_entry',
     						  'fri_status_date'=>Zend_Registry::get('currentdate'),
    +						  'fri_reject_note'=>'', 	
     						  'sat_date'=>date('Y-m-d', strtotime('+6 day', strtotime($weekStartDate))),		
     						  'sat_project_status'=>($projHrsData[0]['sat_duration'] !='00:00')?'saved':'no_entry',
     						  'sat_status'=>($projHrsData[0]['sat_duration'] !='00:00')?'saved':'no_entry',
     						  'sat_status_date'=>Zend_Registry::get('currentdate'),
    +						  'sat_reject_note'=>'',		
     						  'week_status'=>($projHrsData[0]['week_duration'] !='00:00')?'saved':'no_entry',
     					 	  'created_by'=>$sessionData->id,
     			        	  'is_active'=>1,
    -			  			  'created'=> Zend_Registry::get('currentdate') 
    +			  			  'created'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
     				);
    -				
    +				//print_r($statusData); //exit;
     				$checkProjNull = $myTsModel->getProjNullRecordCountInStatus($sessionData->id,$selYrMonArray[0],$selYrMonArray[1],$week);				
     				
     				if($checkProjNull != 0 ) {		
    @@ -793,6 +952,7 @@ public function saveAction()
     					$myTsModel->SaveOrUpdateTimesheetStatus($statusData);
     				}
     			}
    +			
     			$notesData = array('emp_id'=>$sessionData->id,
     						  'ts_year'=>$selYrMonArray[0],
     						  'ts_month'=>$selYrMonArray[1],
    @@ -800,28 +960,37 @@ public function saveAction()
     						  'cal_week'=>$calWeek,
     						  'sun_date'=>date('Y-m-d', strtotime($weekStartDate)),
     						  'sun_note'=> $sunNote,
    +						  'sun_reject_note'=> '', 	
     						  'mon_date'=>date('Y-m-d', strtotime('+1 day', strtotime($weekStartDate))),
     						  'mon_note'=> $monNote,
    +						  'mon_reject_note'=> '',	
     						  'tue_date'=>date('Y-m-d', strtotime('+2 day', strtotime($weekStartDate))),
     						  'tue_note'=>$tueNote,
    +						  'tue_reject_note'=> '',
     						  'wed_date'=>date('Y-m-d', strtotime('+3 day', strtotime($weekStartDate))),
     						  'wed_note'=>$wedNote,
    +						  'wed_reject_note'=> '',	
     						  'thu_date'=>date('Y-m-d', strtotime('+4 day', strtotime($weekStartDate))),
    -						  'thu_note'=>$thuNote,	
    +						  'thu_note'=>$thuNote,
    +						  'thu_reject_note'=> '',	
     						  'fri_date'=>date('Y-m-d', strtotime('+5 day', strtotime($weekStartDate))),
    -						  'fri_note'=>$friNote, 	
    +						  'fri_note'=>$friNote,
    +						  'fri_reject_note'=> '', 	
     						  'sat_date'=>date('Y-m-d', strtotime('+6 day', strtotime($weekStartDate))),
    -						  'sat_note'=>$satNote,							  			
    +						  'sat_note'=>$satNote,
    +						  'sat_reject_note'=> '',							  			
     						  'week_note'=>$weekNote,	
     			 			  'created_by'=>$sessionData->id,					
     			        	  'is_active'=>1,
    -			  			  'created'=> Zend_Registry::get('currentdate')
    +			  			  'created'=> Zend_Registry::get('currentdate')//gmdate("Y-m-d H:i:s")
     			);
     			$myTsModel->SaveOrUpdateTimesheetNotes($notesData);
     		}
     
     		$empDeletedTasks = $myTsModel->empployeeDeletedTasks($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week, $calWeek,$projTasksArray);
    -			if(is_array($empDeletedTasks)) {
    +		//print_r($empDeletedTasks);
    +		//if(sizeof($empDeletedTasks) > 0 ) {
    +		if(is_array($empDeletedTasks)) {
     
     			foreach($empDeletedTasks as $taskId) {
     				$deleteTasksData = array('emp_id'=>$sessionData->id,
    @@ -840,19 +1009,19 @@ public function saveAction()
     						  'week_duration'=>'00:00',						
     			        	  'is_active'=>0,
     						  'modified_by'=>$sessionData->id,
    -			  			  'modified'=> Zend_Registry::get('currentdate')
    +			  			  'modified'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
     				);
     
     				$myTsModel->deleteTimesheetTask($sessionData->id,$deleteTasksData,$taskId, $selYrMonArray[0], $selYrMonArray[1], $week);
     			}
     		}
     		$empDeletedProjects = $myTsModel->empployeeDeletedProjects($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week, $calWeek,$projsArray);
    -	
    +		//	if(sizeof($empDeletedProjects) > 0 ) {
     		if(is_array($empDeletedProjects)) {
     
     			foreach($empDeletedProjects as $projId) {
     				$deleteProjectsData = array('emp_id'=>$sessionData->id,
    -			              'project_id'=>$taskId,						  
    +			              'project_id'=>$projId,						  
     						  'ts_year'=>$selYrMonArray[0],
     						  'ts_month'=>$selYrMonArray[1],
     						  'ts_week'=>$week,
    @@ -864,15 +1033,16 @@ public function saveAction()
     			   			  'thu_project_status'=>'no_entry',			  			
     			  			  'fri_project_status'=>'no_entry',			  			
     			  			  'sat_project_status'=>'no_entry',
    -	
    +				//  'week_status'=>'no_entry',
     			        	  'is_active'=>0,
     						  'modified_by'=>$sessionData->id,
    -			  			  'modified'=> Zend_Registry::get('currentdate')
    +			  			  'modified'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
     				);
    +				
     
     				$myTsModel->deleteWeekProjectStatus($sessionData->id,$deleteProjectsData,$projId, $selYrMonArray[0], $selYrMonArray[1], $week);
     			}
    -			
    +			//updateDayStatus($sessionData->id,$selYrMonArray[0], $selYrMonArray[1], $week);
     		}
     		$myTsModel->updateDayStatus($sessionData->id,$selYrMonArray[0], $selYrMonArray[1], $week);
     		$myTsModel->updateWeekStatus($sessionData->id,$selYrMonArray[0], $selYrMonArray[1], $week);
    @@ -880,9 +1050,27 @@ public function saveAction()
     		if($callval == 'ajaxcall')
     		$this->_helper->layout->disableLayout();
     
    +		//		$usersModel = new Timemanagement_Model_Users();
    +		//		$storage = new Zend_Auth_Storage_Session();
    +		//        $data = $storage->read();
    +		//
    +		//        $selYrMon = $this->_getParam('selYrMon');
    +		//        $empDoj = $usersModel->getEmployeeDoj($data->id);
    +		//
    +		//    	$dateEmpDoj = date('Y-m',strtotime($empDoj['date_of_joining']));
    +		//
    +		//    	$selYrMon = ($selYrMon != '')?$selYrMon:$now->format('Y-m');
    +		//
    +		//		$month = $this->_getParam('month');
    +		//    	$year = $this->_getParam('year');
    +		//
    +		//    	$this->view->empDoj=$empDoj['date_of_joining'];
    +		//    	//$empid = $this->_getParam('empid');
    +		//$msgArray['status'] = 'success';
     		$this->view->status = 'success';
    -		$this->view->message = 'Time sheet saved successfully.';
    -		
    +		$this->view->message = 'Timesheet saved successfully.';
    +		//$this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Time sheet saved successfully."));
    +		}
     	}
     
     	public function submitAction() {
    @@ -914,22 +1102,24 @@ public function submitAction() {
     						  'modified'=> Zend_Registry::get('currentdate')				 	  
     		);
     		if($selDay != '') {
    +			//$statusData[$dayName.'_project_status']= 'submitted';
     			$statusData[$dayName.'_status']= 'submitted';
     			$statusData[$dayName.'_status_date'] = Zend_Registry::get('currentdate');
     		} else {
     			$weekDaysStatus =  $myTsModel->getWeekDaysDailyStatus($sessionData->id,$yrMon[0],$yrMon[1],$week);
    +			//print_r($weekDaysStatus);
     			foreach ($weekDaysStatus[0] as $key => $value) {				
     				if($value == 'saved') {
    -					
    +					//echo $key."   ".$value; 
     					$dayName =  substr($key,0,3);
    -				
    +					//$statusData[$dayName.'_project_status']= 'submitted';
     					$statusData[$dayName.'_status']= 'submitted';
     					$statusData[$dayName.'_status_date'] = Zend_Registry::get('currentdate');
     				}
     			}			
     		}
     		$weekDaysProjStatus =  $myTsModel->getWeekDaysProjStatus($sessionData->id,$yrMon[0],$yrMon[1],$week);
    -		
    +		//	foreach ($weekDaysProjStatus[0] as $key => $value) {
     		
     		$projId = '';		
     		foreach ($weekDaysProjStatus as $projStatusArray) {
    @@ -947,7 +1137,9 @@ public function submitAction() {
     				}	
     			}
     		}
    -	
    +	//	print_r($statusData); 
    +	//	print_r($weekDaysProjStatus);	
    +	//exit;
     		$myTsModel->updateSubmitStatus($sessionData->id,$yrMon[0], $yrMon[1], $week,$statusData);
     		$myTsModel->updateWeekStatus($sessionData->id,$yrMon[0], $yrMon[1], $week);
     		if($callval == 'ajaxcall')
    @@ -966,48 +1158,64 @@ public function eraseweekAction() {
     
     		$storage = new Zend_Auth_Storage_Session();
     		$sessionData = $storage->read();
    -		$myTsModel = new Timemanagement_Model_MyTimesheet();
    +		
    +		$usersModel = new Timemanagement_Model_Users();
    +		$data = $storage->read();
    +		$empDoj = $usersModel->getEmployeeDoj($sessionData->id);
    +		
    +		$doj = $empDoj['date_of_joining'];
    +		if($doj>date('Y-m-d'))
    +		{
    +			$this->view->status = 'failure';
    +		}
    +		else
    +		{
     
    -		$selYrMon = $this->_getParam('selYrMon');
    -		$callval = $this->getRequest()->getParam('call');
    -		$week = $this->_getParam('week');
    -		$calWeek = $this->_getParam('calWeek');
    -		$yrMon = explode('-', $selYrMon);
    +			$myTsModel = new Timemanagement_Model_MyTimesheet();
     
    -		$statusData = array('modified_by' => $sessionData->id,
    -						  'modified'=> Zend_Registry::get('currentdate')				 	  
    -		);
    -		$TasksData = array('modified_by'=>$sessionData->id,
    -			  			  'modified'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
    -		);
    -		$notesData = array('modified_by'=>$sessionData->id,
    -			  			  'modified'=> Zend_Registry::get('currentdate')//gmdate("Y-m-d H:i:s")
    -		);
    -		$weekDaysStatus =  $myTsModel->getWeekDaysDailyStatus($sessionData->id,$yrMon[0],$yrMon[1],$week);
    -		foreach ($weekDaysStatus[0] as $key => $value) {
    -			if($value == 'saved') {
    -				$dayName =  substr($key,0,3);
    -				$statusData[$dayName.'_project_status']= 'no_entry';
    -				$statusData[$dayName.'_status']= 'no_entry';
    -				$statusData[$dayName.'_status_date'] = Zend_Registry::get('currentdate');
    -
    -				$TasksData[$dayName.'_duration']='00:00';
    -				$notesData[$dayName.'_note'] = '';
    +			$selYrMon = $this->_getParam('selYrMon');
    +			$callval = $this->getRequest()->getParam('call');
    +			$week = $this->_getParam('week');
    +			$calWeek = $this->_getParam('calWeek');
    +			$yrMon = explode('-', $selYrMon);
    +
    +			$statusData = array('modified_by' => $sessionData->id,
    +							  'modified'=> Zend_Registry::get('currentdate')				 	  
    +			);
    +			$TasksData = array('modified_by'=>$sessionData->id,
    +							  'modified'=> Zend_Registry::get('currentdate') //gmdate("Y-m-d H:i:s")
    +			);
    +			$notesData = array('modified_by'=>$sessionData->id,
    +							  'modified'=> Zend_Registry::get('currentdate')//gmdate("Y-m-d H:i:s")
    +			);
    +			$weekDaysStatus =  $myTsModel->getWeekDaysDailyStatus($sessionData->id,$yrMon[0],$yrMon[1],$week);
    +			foreach ($weekDaysStatus[0] as $key => $value) {
    +				if($value == 'saved') {
    +					$dayName =  substr($key,0,3);
    +					$statusData[$dayName.'_project_status']= 'no_entry';
    +					$statusData[$dayName.'_status']= 'no_entry';
    +					$statusData[$dayName.'_status_date'] = Zend_Registry::get('currentdate');
    +
    +					$TasksData[$dayName.'_duration']='00:00';
    +					$notesData[$dayName.'_note'] = '';
    +				}
     			}
    -		}
    -		
    -		if($callval == 'ajaxcall')
    -		$this->_helper->layout->disableLayout();
    +			//		print_r($TasksData);
    +			//		print_r($statusData);
    +			//		print_r($notesData);
     
    -		$myTsModel->updateTimesheet($sessionData->id,$yrMon[0], $yrMon[1], $week,$TasksData);
    -		$myTsModel->updateTimesheetStatus($sessionData->id,$yrMon[0], $yrMon[1], $week,$statusData);
    -		$myTsModel->updateTimesheetNotes($sessionData->id,$yrMon[0], $yrMon[1], $week,$notesData);
    -		$myTsModel->updateWeekStatus($sessionData->id,$yrMon[0], $yrMon[1], $week);
    -		$myTsModel->updateWeekDuration($sessionData->id,$yrMon[0], $yrMon[1], $week);
    +			if($callval == 'ajaxcall')
    +			$this->_helper->layout->disableLayout();
     
    -		$this->view->status = 'success';
    -		$this->view->message = 'Timesheet erased successfully for week '.$week;
    +			$myTsModel->updateTimesheet($sessionData->id,$yrMon[0], $yrMon[1], $week,$TasksData);
    +			$myTsModel->updateTimesheetStatus($sessionData->id,$yrMon[0], $yrMon[1], $week,$statusData);
    +			$myTsModel->updateTimesheetNotes($sessionData->id,$yrMon[0], $yrMon[1], $week,$notesData);
    +			$myTsModel->updateWeekStatus($sessionData->id,$yrMon[0], $yrMon[1], $week);
    +			$myTsModel->updateWeekDuration($sessionData->id,$yrMon[0], $yrMon[1], $week);
     
    +			$this->view->status = 'success';
    +			$this->view->message = 'Timesheet erased successfully for week '.$week.'.';
    +		}
     	}
     	public function getstatesAction()
     	{
    @@ -1022,12 +1230,29 @@ public function getstatesAction()
     		}
     		$this->_helper->json(array('options'=>utf8_encode($opt)));
     	}
    +	//get notification alerts
    +	public function getapprovedtimesheetAction()
    +	{
    +		$storage = new Zend_Auth_Storage_Session();
    +		$data = $storage->read();
    +		$usersModel = new Timemanagement_Model_Users();
    +		$approvedAlert = $usersModel->getEmpApprovalStatusDteails($data->id);
    +		$this->view->approvalAlertData =  $approvedAlert;
    +	}
    +	//update notification alert as closed
    +	public function closeapprovealertAction()
    +	{
    +		$usersModel = new Timemanagement_Model_Users();
    +		$storage = new Zend_Auth_Storage_Session();
    +		$data = $storage->read();
    +		$emp_approval_status = $usersModel->addOrUpdateTstatusData($data->id);
    +	}
     	public function converdateAction()
     	{
    -		 $selYrMon = $this->_getParam('day');
    -		 $callval = $this->_getParam('yearmonth');
    -		 $date = sapp_Global::change_date($callval,'view');
    -		 $this->_helper->json(array('conerteddate'=>$date));
    +		$selYrMon = $this->_getParam('day');
    +		$callval = $this->_getParam('yearmonth');
    +		$date = sapp_Global::change_date($callval,'view');
    +		$this->_helper->json(array('conerteddate'=>$date));
     	}
     
     
    diff --git a/application/modules/timemanagement/controllers/NotificationsController.php b/application/modules/timemanagement/controllers/NotificationsController.php
    new file mode 100644
    index 000000000..a872374bf
    --- /dev/null
    +++ b/application/modules/timemanagement/controllers/NotificationsController.php
    @@ -0,0 +1,618 @@
    +.
    + *
    + *  Sentrifugo Support 
    + ********************************************************************************/
    +
    +class Timemanagement_NotificationsController extends Zend_Controller_Action
    +{
    +	private $options;
    +	public function preDispatch()
    +	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
    +		
    +		//check Time management module enable
    +		if(!sapp_Helper::checkTmEnable())
    +			$this->_redirect('error');
    +		$ajaxContext = $this->_helper->getHelper('AjaxContext');
    +		$ajaxContext->addActionContext('getnotifications', 'html')->initContext();
    +		$ajaxContext->addActionContext('pendingsubmissionsweeklyview', 'html')->initContext();
    +		$ajaxContext->addActionContext('weeklymonthlyview', 'html')->initContext();
    +	}
    +
    +	public function init()
    +	{
    +		$this->_options= $this->getInvokeArg('bootstrap')->getOptions();
    +	}
    +	public function indexAction()
    +	{
    +		$perPage = PERPAGE;
    +		$auth = Zend_Auth::getInstance();
    +		$loginUserId=0;
    +		if($auth->hasIdentity()){
    +			$loginUserId = $auth->getStorage()->read()->id;
    +		}
    +		$yet_to_submit_dates = array();
    +		$notificationModel = new Timemanagement_Model_Notifications();
    +		$usersModel = new Timemanagement_Model_Users();
    +		$employeeDOJ = $usersModel->getEmployeeDoj($loginUserId);
    +		$loginUserGroupId = $employeeDOJ['holiday_group'];
    +		$department_id = $employeeDOJ['department_id'];
    +		$weekend_date = date('Y-m-d', strtotime('last saturday'));
    +		$notificationArray = array();
    +		$submitted_notificationArray = array();
    +		$final_notification_Arry = array();
    +		$notificationArray = $notificationModel->getnotifications($loginUserId,$weekend_date);
    +		$submitted_notificationArray = $notificationModel->getSubmittedNotifications($loginUserId,$weekend_date);
    +		$employeeLeaves = array();
    +		$getWeekends = array();
    +		$employeeLeaves = $usersModel->getEmpLeaves($loginUserId,$employeeDOJ['date_of_joining'],$weekend_date);
    +		$getWeekends = $usersModel->getWeekend($employeeDOJ['date_of_joining'],$weekend_date,$department_id);
    +		$between_days = array();
    +		$between_days = sapp_Global::createDateRangeArray($employeeDOJ['date_of_joining'],$weekend_date);
    +		$holidayDatesArr =  array();
    +		$holidayDateslistArr=array();
    +		if( isset($loginUserId) && $loginUserId !=''){
    +			$holidaydatesmodel = new Default_Model_Holidaydates();
    +			if($loginUserGroupId>0)
    +			{
    +				$holidayDateslistArr = $holidaydatesmodel->getHolidayDatesListForGroup($loginUserGroupId);
    +			}
    +			if(!empty($holidayDateslistArr))
    +			{
    +				for($i=0;$i0)
    +		{
    +			$submittes_ts_dates_with_status = '';
    +			foreach($submitted_notificationArray as $sub_array)
    +			{
    +				$submittes_ts_dates_with_status.=$sub_array['ts_week_dates'];
    +				$submittes_ts_dates_with_status.='$';
    +			}
    +			$ts_date_with_status_array = array_filter(explode('$',$submittes_ts_dates_with_status));
    +			$tsEnteredDates = implode('#',$ts_date_with_status_array);
    +			$tsEnteredDatesArray = explode('#',$tsEnteredDates);
    +		}
    +
    +		if(count($notificationArray)>0 || count($submitted_notificationArray)>0)//if employee not saved timesheet
    +		{
    +			//get entered timesheet dates
    +			$timesheet_dates_with_status = '';
    +			foreach($notificationArray as $array)
    +			{
    +				$timesheet_dates_with_status.= $array['ts_week_dates'];
    +				$timesheet_dates_with_status.='$';
    +			}
    +			$timesheet_date_with_status_array = array_filter(explode('$',$timesheet_dates_with_status));
    +			//print_r($timesheet_date_with_status_array);
    +			$timesheetEnteredDates = implode('#',$timesheet_date_with_status_array);
    +			//echo $timesheetEnteredDates;
    +			$timesheetEnteredDates_Array = explode('#',$timesheetEnteredDates);
    +			$timesheetEnteredDatesArray = $timesheetEnteredDates_Array;
    +			if(count($tsEnteredDatesArray)>0)
    +			{
    +				$timesheetEnteredDatesArray = array_merge($timesheetEnteredDates_Array,$tsEnteredDatesArray);
    +			}
    +			$enteredDatesArray = array();
    +			$statusArray = array('saved','enabled','rejected','blocked','no_entry','submitted','approved');
    +			$enteredDateStatusArr = array();
    +			foreach($timesheetEnteredDatesArray as $date)
    +			{
    +				if(!empty($date))
    +				{
    +					if(!in_array($date,$statusArray))
    +					{
    +						$enteredDatesArray[] = $date;
    +					}
    +					else
    +					{
    +						$enteredDateStatusArr[] = $date;
    +					}
    +				}
    +			}
    +			$not_ts_weekend_ts = array();
    +			foreach($enteredDatesArray as $key=>$value)
    +			{
    +				if(isset($key)){
    +					if(in_array($value,$hol_leav_weknd) && $enteredDateStatusArr[$key]=='no_entry')
    +					{
    +						$not_ts_weekend_ts[] = $value;
    +					}
    +					$not_ts_weekend_ts[] = $value;
    +					if($enteredDateStatusArr[$key]=='saved' || ($enteredDateStatusArr[$key]=='no_entry' && !in_array($value,$hol_leav_weknd)))
    +					{
    +						$yet_to_submit_array[$value] = $enteredDateStatusArr[$key];
    +					}else if($enteredDateStatusArr[$key]=='rejected')
    +					{
    +						$rejected_array[$value] = $enteredDateStatusArr[$key];
    +					}else if($enteredDateStatusArr[$key]=='blocked')
    +					{
    +						$blocked_array[$value] = $enteredDateStatusArr[$key];
    +					}else if($enteredDateStatusArr[$key]=='enabled')
    +					{
    +						$enabled_array[$value] = $enteredDateStatusArr[$key];
    +					}
    +					$dates_with_status[$value] = $enteredDateStatusArr[$key];
    +				}
    +			}
    +			$remainingDays = array_diff($working_days,$enteredDatesArray);
    +
    +			foreach($remainingDays as $dates)
    +			{
    +				$dates_without_status[$dates] = 'no_entry';
    +			}
    +			$display_dates = array_merge($dates_with_status,$dates_without_status);
    +		}
    +		else
    +		{
    +			$remainingDays = $working_days;
    +			foreach($remainingDays as $dates)
    +			{
    +				$dates_without_status[$dates] = 'no_entry';
    +			}
    +			$display_dates = $dates_without_status;
    +		}
    +		$display_dates_array = array();
    +		foreach($display_dates as $keydate => $statusarr)
    +		{
    +			if($keydate>=$employeeDOJ['date_of_joining'] && !($display_dates[$keydate]=='no_entry' && in_array($keydate,$hol_leav_weknd)))
    +			{
    +				if($display_dates[$keydate]!='submitted' && $display_dates[$keydate]!='approved') {
    +					$display_dates_array[$keydate] = $statusarr;
    +				}
    +			}
    +		}
    +		$this->view->allCount = count($display_dates_array);
    +		$this->view->enabledCount = count($enabled_array);
    +		$this->view->rejectedCount = count($rejected_array);
    +		$this->view->blockedCount = count($blocked_array);
    +		$yet_to_submit_arr = array();
    +		foreach($yet_to_submit_array as $key =>$valu)
    +		{
    +			if($key>=$employeeDOJ['date_of_joining'])
    +			{
    +				$yet_to_submit_arr[$key] = $valu;
    +			}
    +		}
    +		$this->view->pageNo = 1;
    +		$this->view->perPage = $perPage;
    +		$yet_to_submit_dates = array_merge($yet_to_submit_arr,$dates_without_status);
    +		$this->view->yet_to_submit_dates = $yet_to_submit_dates;
    +		$this->view->totalJsonCount = count($yet_to_submit_dates);
    +	}
    +	//function by sravani for displaying notifications
    +	public function getnotificationsAction()
    +	{
    +		$type = $this->_getParam('type');
    +		$perPage = PERPAGE;
    +		$auth = Zend_Auth::getInstance();
    +		$loginUserId=0;
    +		if($auth->hasIdentity()){
    +			$loginUserId = $auth->getStorage()->read()->id;
    +		}
    +		$yet_to_submit_dates = array();
    +		$notificationModel = new Timemanagement_Model_Notifications();
    +		$usersModel = new Timemanagement_Model_Users();
    +		$employeeDOJ = $usersModel->getEmployeeDoj($loginUserId);
    +		$loginUserGroupId = $employeeDOJ['holiday_group'];
    +		$department_id = $employeeDOJ['department_id'];
    +		$weekend_date = date('Y-m-d', strtotime('last saturday'));
    +		$notificationArray=array();
    +		$submitted_notificationArray = array();
    +		$notificationArray = $notificationModel->getnotifications($loginUserId,$weekend_date);
    +		$submitted_notificationArray = $notificationModel->getSubmittedNotifications($loginUserId,$weekend_date);
    +		$employeeLeaves = array();
    +		$getWeekends=array();
    +		$employeeLeaves = $usersModel->getEmpLeaves($loginUserId,$employeeDOJ['date_of_joining'],$weekend_date);
    +		$getWeekends = $usersModel->getWeekend($employeeDOJ['date_of_joining'],$weekend_date,$department_id);
    +		$between_days=array();
    +		$between_days = sapp_Global::createDateRangeArray($employeeDOJ['date_of_joining'],$weekend_date);
    +		$holidayDatesArr =  array();
    +		if( isset($loginUserId) && $loginUserId !=''){
    +			$holidaydatesmodel = new Default_Model_Holidaydates();
    +			if($loginUserGroupId>0)
    +			{
    +				$holidayDateslistArr = $holidaydatesmodel->getHolidayDatesListForGroup($loginUserGroupId);
    +			}
    +			if(!empty($holidayDateslistArr))
    +			{
    +				for($i=0;$i0)
    +		{
    +			$submittes_ts_dates_with_status = '';
    +			foreach($submitted_notificationArray as $sub_array)
    +			{
    +				$submittes_ts_dates_with_status.=$sub_array['ts_week_dates'];
    +				$submittes_ts_dates_with_status.='$';
    +			}
    +			$ts_date_with_status_array = array_filter(explode('$',$submittes_ts_dates_with_status));
    +			$tsEnteredDates = implode('#',$ts_date_with_status_array);
    +			$tsEnteredDatesArray = explode('#',$tsEnteredDates);
    +		}
    +
    +		if(count($notificationArray)>0 || count($submitted_notificationArray)>0) {
    +			//get entered timesheet dates
    +			$timesheet_dates_with_status = '';
    +			foreach($notificationArray as $array)
    +			{
    +				$timesheet_dates_with_status.= $array['ts_week_dates'];
    +				$timesheet_dates_with_status.='$';
    +			}
    +			$timesheet_date_with_status_array = array_filter(explode('$',$timesheet_dates_with_status));
    +			//print_r($timesheet_date_with_status_array);
    +			$timesheetEnteredDates = implode('#',$timesheet_date_with_status_array);
    +			//echo $timesheetEnteredDates;
    +			$timesheetEnteredDates_Array = explode('#',$timesheetEnteredDates);
    +			$timesheetEnteredDatesArray = $timesheetEnteredDates_Array;
    +			if(count($tsEnteredDatesArray)>0)
    +			{
    +				$timesheetEnteredDatesArray = array_merge($timesheetEnteredDates_Array,$tsEnteredDatesArray);
    +			}
    +			$enteredDatesArray = array();
    +			//$statusArray = array('saved','enabled','rejected','blocked','no_entry');
    +			$statusArray = array('saved','enabled','rejected','blocked','no_entry','submitted','approved');
    +			$enteredDateStatusArr = array();
    +			foreach($timesheetEnteredDatesArray as $date)
    +			{
    +				if(!empty($date))
    +				{
    +					if(!in_array($date,$statusArray))
    +					{
    +						$enteredDatesArray[] = $date;
    +					}
    +					else
    +					{
    +						$enteredDateStatusArr[] = $date;
    +					}
    +				}
    +			}
    +			foreach($enteredDatesArray as $key=>$value)
    +			{
    +				if(isset($key)){
    +					if($type == 'yet_to_submit')
    +					{
    +						if($enteredDateStatusArr[$key]=='saved' || ($enteredDateStatusArr[$key]=='no_entry' && !in_array($value,$hol_leav_weknd)))
    +						{
    +							$yet_to_submit_array[$value] = $enteredDateStatusArr[$key];
    +						}
    +					}else if($type == 'rejected')
    +					{
    +						if($enteredDateStatusArr[$key]=='rejected')
    +						{
    +							$rejected_array[$value] = $enteredDateStatusArr[$key];
    +						}
    +					}else if($type == 'blocked')
    +					{
    +						if($enteredDateStatusArr[$key]=='blocked')
    +						{
    +							$blocked_array[$value] = $enteredDateStatusArr[$key];
    +						}
    +					}else if($type == 'enabled')
    +					{
    +						if($enteredDateStatusArr[$key]=='enabled')
    +						{
    +							$enabled_array[$value] = $enteredDateStatusArr[$key];
    +						}
    +					}else if($type == 'all')
    +					{
    +						if(!($enteredDateStatusArr[$key]=='no_entry' && in_array($value,$hol_leav_weknd)))
    +						{
    +							if($enteredDateStatusArr[$key]!='submitted' && $enteredDateStatusArr[$key]!='approved') {
    +								$dates_with_status[$value] = $enteredDateStatusArr[$key];
    +							}
    +						}
    +					}
    +				}
    +			}
    +			$remainingDays = array_diff($working_days,$enteredDatesArray);
    +
    +			foreach($remainingDays as $dates)
    +			{
    +				$dates_without_status[$dates] = 'no_entry';
    +			}
    +			$display_dates = array_merge($dates_with_status,$dates_without_status);
    +		}
    +		else
    +		{
    +			$remainingDays = $working_days;
    +			foreach($remainingDays as $dates)
    +			{
    +				$dates_without_status[$dates] = 'no_entry';
    +			}
    +			$display_dates = $dates_without_status;
    +		}
    +
    +		$display_dates_array = array();
    +		foreach($display_dates as $keydate => $statusarr)
    +		{
    +			if($keydate>=$employeeDOJ['date_of_joining'] && !($display_dates[$keydate]=='no_entry' && in_array($keydate,$hol_leav_weknd)))
    +			{
    +				$display_dates_array[$keydate] = $statusarr;
    +			}
    +		}
    +
    +		$this->view->pageNo = 1;
    +		$this->view->perPage = $perPage;
    +		$yet_to_submit_dates_array = array_merge($yet_to_submit_array,$dates_without_status);
    +		foreach($yet_to_submit_dates_array as $key =>$valu)
    +		{
    +			if($key>=$employeeDOJ['date_of_joining'])
    +			{
    +				$yet_to_submit_dates[$key] = $valu;
    +			}
    +		}
    +
    +		if($type == 'all')
    +		{
    +			$this->view->dataArray = $display_dates_array;
    +			$this->view->totalJsonCount = count($display_dates_array);
    +		}else if($type == 'enabled')
    +		{
    +			$this->view->dataArray = $enabled_array;
    +			$this->view->totalJsonCount = count($enabled_array);
    +		}else if($type == 'blocked')
    +		{
    +			$this->view->dataArray = $blocked_array;
    +			$this->view->totalJsonCount = count($blocked_array);
    +		}else if($type == 'rejected')
    +		{
    +			$this->view->dataArray = $rejected_array;
    +			$this->view->totalJsonCount = count($rejected_array);
    +		}else if($type == 'yet_to_submit')
    +		{
    +			$this->view->dataArray = $yet_to_submit_dates;
    +			$this->view->totalJsonCount = count($yet_to_submit_dates);
    +		}
    +		$this->view->type=$type;
    +	}
    +	//function to get pending submissions
    +	public function pendingsubmissionsAction()
    +	{
    +		$auth = Zend_Auth::getInstance();
    +		$loginUserId=0;
    +		if($auth->hasIdentity()){
    +			$loginUserId = $auth->getStorage()->read()->id;
    +		}
    +		$weekend_date = date('Y-m-d', strtotime('last saturday'));
    +		$notificationModel = new Timemanagement_Model_Notifications();
    +		$getManagerEmployees = array();
    +		$getManagerEmployees = $notificationModel->getManagerEmployees($loginUserId);
    +		$concat_array = array();
    +		if(count($getManagerEmployees)>0)
    +		{
    +			$is_current_week = 1;
    +			$usersModel = new Timemanagement_Model_Users();
    +			$projmodel = new Timemanagement_Model_Projects();
    +			$prevweeks = $projmodel->getprevmonthweeks(date('Y-m') , date('d'));
    +			$end_date = max($prevweeks[count($prevweeks)]);//get previous week end date
    +			$start_date = min($prevweeks[count($prevweeks)]);//get previous week start date
    +			if(!($end_date>=date('Y-m-01') && $end_date<=date('Y-m-t')))//check previous week end date is in current month or not
    +			{	
    +				$is_current_week = 0;
    +				$sunday = strtotime("last sunday");
    +				$sunday = date('w', $sunday)==date('w') ? $sunday+7*86400 : $sunday;
    +				$satday = strtotime(date("Y-m-d",$sunday)." +6 days");
    +				$this_week_sd = date("Y-m-d",$sunday);
    +				$this_week_ed = date("Y-m-d",$satday);
    +				
    +				if($this_week_sd==date('Y-m-01'))//if month starts with sunday
    +				{
    +					$previous_week = strtotime("-1 week +1 day");
    +
    +					$start_week = strtotime("last sunday",$previous_week);
    +					$end_week = strtotime("next saturday",$start_week);
    +
    +					$start_week = date("Y-m-d",$start_week);
    +					$end_week = date("Y-m-d",$end_week);
    +
    +					//	echo $start_week.' '.$end_week ;
    +					$this_week_sd = $start_week;
    +					$this_week_ed = $end_week;
    +				}	
    +
    +				//To get day in the week
    +				$weekDatesArray = sapp_Global::createDateRangeArray($this_week_sd,$this_week_ed);
    +				//End
    +				
    +				foreach($weekDatesArray as $this_date)
    +				{
    +					if(!($this_date>=date('Y-m-01') && $this_date<=date('Y-m-t')))
    +					{
    +						$concat_array[] = $this_date;
    +					}
    +				}
    +			}
    +			if(count($concat_array)>0)
    +			{
    +				$prevweeks[count($prevweeks)+1] = $concat_array;
    +			}
    +			$prev_week_status = array();
    +			$emp_names = array();
    +			foreach($getManagerEmployees as $emp)
    +			{
    +				$emp_names[$emp['user_id']] = $emp['userfullname'];
    +				$empDoj = $usersModel->getEmployeeDoj($emp['user_id']);
    +				$prev_week_status[$emp['user_id']]=$projmodel->getPreviousDaysTSStatus($prevweeks,$emp['user_id'],$empDoj);
    +			}
    +			$total_weeks=0;
    +			$this->view->total_weeks = count($prevweeks);
    +		}
    +		$this->view->pending_submission = $prev_week_status;
    +		$this->view->prevweeks = $prevweeks;
    +		$this->view->emp_names = $emp_names;
    +		$this->view->is_current_week = $is_current_week;
    +	}
    +	//function to show pending submission weekly view
    +	public function pendingsubmissionsweeklyviewAction()
    +	{
    +		$post_array=$this->_getParam('display_array');
    +		$weekly_preview=$this->_getParam('weekly_preview');
    +		$emp_names=$this->_getParam('emp_names');
    +		$selType=$this->_getParam('type');
    +		$is_current_week=$this->_getParam('is_current_week');
    +		$display_date = json_decode($post_array,true);
    +		$week_dates = json_decode($weekly_preview,true);
    +		$emp_names = json_decode($emp_names,true);
    +		$this->view->pending_submission = $display_date;
    +		$this->view->prevweeks = $week_dates;
    +		$this->view->emp_names = $emp_names;
    +		$this->view->is_current_week = $is_current_week;
    +		$this->view->type = $selType;
    +		$currentMonth = date('Y-m');
    +		if($is_current_week==0)
    +		{
    +			$currentMonth = date('Y-m', strtotime(date('Y-m')." -1 month"));
    +		}
    +		$week = $selType;
    +		$datesArray =  iterator_to_array(new DatePeriod(new DateTime("first sunday of $currentMonth"),
    +    	DateInterval::createFromDateString('next sunday'),new DateTime("last day of $currentMonth")));
    +		
    +		$firstDay = DateTime::createFromFormat('Y-m-d', "$currentMonth".'-1');
    +		$firstDayName =  $firstDay->format('D');
    +		$wCounter = 1;
    +		if($firstDayName != 'Sun')  $wCounter = 2;
    +			
    +		if($week == 1) {
    +			$startDate = $currentMonth."-1";
    +			$weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate)));
    +			if($startDate==date('Y-m-1'))
    +			{
    +				$weekStartDay = date('F d, Y', strtotime($startDate));		
    +			}
    +		} else  {
    +			$startDate = $datesArray[($week-$wCounter)]->format("Y-m-d");
    +			$weekStartDay = date('F d, Y', strtotime($startDate));
    +		}
    +		$lastwkend_date_mnth = date('Y-m',strtotime('next saturday', strtotime($weekStartDay)));
    +		$lastweek_start_mnth = date('Y-m', strtotime('last sunday', strtotime($startDate)));
    +		$weekendDay = date('F d, Y', strtotime('next saturday', strtotime($weekStartDay)));
    +		if($lastweek_start_mnth != $lastwkend_date_mnth && $is_current_week==0)
    +		{
    +			$weekendDay = date("F d, Y", strtotime("last day of previous month"));
    +		}
    +		
    +		
    +		$hidstartweek_date=min($week_dates[$week]);
    +		$hidendweek_date=max($week_dates[$week]);
    +		$weekStartDay = date('F d, Y', strtotime($hidstartweek_date));
    +		$weekendDay = date("F d, Y", strtotime($hidendweek_date));
    +		
    +		$display_date = $weekStartDay.' - '.$weekendDay;
    +		$this->view->weekStartDay =$weekStartDay;
    +		$this->view->weekendDay =$weekendDay;
    +		$this->view->display_date =$display_date;
    +		
    +	}
    +	//function to get monthly,weely view
    +	public function weeklymonthlyviewAction()
    +	{
    +		$post_array=$this->_getParam('display_array');
    +		$weekly_preview=$this->_getParam('weekly_preview');
    +		$emp_names=$this->_getParam('emp_names');
    +		$input_type=$this->_getParam('input_type');
    +		$total_weeks=$this->_getParam('total_weeks');
    +		$div_name=$this->_getParam('div_name');
    +		$is_current_week=$this->_getParam('is_current_week');
    +		$display_date = json_decode($post_array,true);
    +		$week_dates = json_decode($weekly_preview,true);
    +		$emp_names = json_decode($emp_names,true);
    +		$this->view->pending_submission = $display_date;
    +		$this->view->prevweeks = $week_dates;
    +		$this->view->emp_names = $emp_names;
    +		$this->view->input_type = $input_type;
    +		$this->view->total_weeks = $total_weeks;
    +		$this->view->div_name = $div_name;
    +		$this->view->is_current_week = $is_current_week;
    +	}
    +}
    +?>
    diff --git a/application/modules/timemanagement/controllers/ProjectresourcesController.php b/application/modules/timemanagement/controllers/ProjectresourcesController.php
    index 665d396de..c69657100 100644
    --- a/application/modules/timemanagement/controllers/ProjectresourcesController.php
    +++ b/application/modules/timemanagement/controllers/ProjectresourcesController.php
    @@ -32,6 +32,12 @@ public function init()
     	}
     	public function preDispatch()
     	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
     			$this->_redirect('error');
    @@ -118,14 +124,28 @@ public function resourcesAction()
     		$resMessages = array();
     
     		if($this->getRequest()->getPost()){
    +			//echo '
    '; print_r($this->getRequest()->getPost());exit;
     			$resourceprojectIds = $this->getRequest()->getParam('hid_resourceprojid');
     			$projectId = $this->getRequest()->getParam('project_id');
     			$empIds = $this->getRequest()->getParam('hid_resourceid');
     			$projectResourceData = array();
     			if(count($resourceprojectIds) > 0){
     				foreach($resourceprojectIds as $key=>$resourceProjectId){
    +					if($this->getRequest()->getParam('txt_cost_rate'.$resourceProjectId) != ''){
    +						$cost_rate =  $this->getRequest()->getParam('txt_cost_rate'.$resourceProjectId);
    +					}else{
    +						$cost_rate =  "";
    +					}
    +					if($this->getRequest()->getParam('txt_billable_rate'.$resourceProjectId) != ''){
    +						$billable_rate =  $this->getRequest()->getParam('txt_billable_rate'.$resourceProjectId);
    +					}else{
    +						$billable_rate =  "";
    +					}
    +
     					$projectResourceData = array( 'project_id'=>trim($projectId),
     				               'emp_id'=>trim($empIds[$key]), 
    +							   'cost_rate'=> $cost_rate,
    +							   'billable_rate'=>$billable_rate, 
     			     	           'is_active' => 1,
     				   			   'modified_by'=>$loginUserId,
     							   'modified'=>gmdate("Y-m-d H:i:s")	
    @@ -146,7 +166,7 @@ public function resourcesAction()
     				if(is_numeric($projectId) && $projectId>0){
     					$projectModel = new Timemanagement_Model_Projects();
     					$projectData = $projectModel->getSingleProjectData($projectId);
    -					$projectResourcesData = $projectResourcesModel->getProjectResourcesData($projectId);
    +					$projectResourcesData = $projectResourcesModel->getProjectResourcesData($projectId); //echo '
    ';print_r($projectResourcesData); exit;
     
     					if($projectResourcesData == 'norows')
     					{
    @@ -185,10 +205,13 @@ public function addresourcesprojectAction()
     	{
     		$type=$this->_getParam('type');
     		$projectId = $this->_getParam('projectId');
    -		$projectResourcesModel = new Timemanagement_Model_Projectresources();	
    +		$projectResourcesModel = new Timemanagement_Model_Projectresources();
    +		//$userModel = new Timemanagement_Model_Users();
    +		//print_r($userModel->getEmployees('manager'));exit;
     		$otherResources = 'norows';
     		if($type == 'manager'){
     			$added_mngr_emp_str = $this->_getParam('addedempstr');
    +			//echo "
    ";print_r($added_emp_str);exit;
     			$added_mgr_arr = array();
     			$added_mgr_data = '';
     			if(isset($added_mngr_emp_str) && $added_mngr_emp_str != '')
    @@ -202,6 +225,8 @@ public function addresourcesprojectAction()
     		if($type == 'emp'){
     			$added_emp_str = $this->_getParam('addedempstr');
     			$added_mgr_str = $this->_getParam('mngrstr');
    +				
    +			//echo "
    ";print_r($added_emp_str);exit;
     			$added_mgr_arr = array();
     			$added_mgr_data = $added_emp_data='';
     			if(isset($added_emp_str) && $added_emp_str != '')
    @@ -226,7 +251,7 @@ public function addresourcesprojectAction()
     	}
     
     	public function addresourcesAction(){
    -		$auth = Zend_Auth::getInstance(); 
    +		$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     			$loginuserRole = $auth->getStorage()->read()->emprole;
    @@ -256,12 +281,16 @@ public function addresourcesAction(){
     					);
     					$result = $projectResourcesModel->SaveorUpdateProjectResourceData($projectResourceData,'');
     				}
    +
    +				//$this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"$type added successfully."));
    +
    +
     				$projectResourcesData = $projectData = array();
     				try{
     					if(is_numeric($projectId) && $projectId>0){
     						$projectModel = new Timemanagement_Model_Projects();
     						$projectData = $projectModel->getSingleProjectData($projectId);
    -						$projectResourcesData = $projectResourcesModel->getProjectResourcesData($projectId); 
    +						$projectResourcesData = $projectResourcesModel->getProjectResourcesData($projectId); //echo '
    ';print_r($projectResourcesData); exit;
     
     						if($projectResourcesData == 'norows')
     						{
    @@ -299,7 +328,7 @@ public function viewemptasksAction()
     
     	//delete resource from project
     	public function deleteprojectresourceAction(){
    -		$auth = Zend_Auth::getInstance(); 
    +		$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     			$projectId=$this->_getParam('projectId');
    @@ -325,6 +354,8 @@ public function deleteprojectresourceAction(){
     						$where_cond = array('emp_id=?'=>$empId,'project_id=?'=>$projectId);
     							
     						$Id = $task_resource_model->SaveorUpdateProjectTaskResourceData($update_data, $where_cond);
    +
    +
     						//sapp_Global::send_configuration_mail("Default Task", $taskData[0]['task']);
     						$messages['message'] = 'Resource deleted successfully.';
     						$messages['msgtype'] = 'success';
    diff --git a/application/modules/timemanagement/controllers/ProjectsController.php b/application/modules/timemanagement/controllers/ProjectsController.php
    index 6aac36e56..623d95747 100644
    --- a/application/modules/timemanagement/controllers/ProjectsController.php
    +++ b/application/modules/timemanagement/controllers/ProjectsController.php
    @@ -32,6 +32,13 @@ public function init()
     	}
     	public function preDispatch()
     	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
    +		
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
     			$this->_redirect('error');
    @@ -40,7 +47,7 @@ public function preDispatch()
     		$ajaxContext->addActionContext('addtasksproject', 'html')->initContext();
     		$ajaxContext->addActionContext('addtasks', 'html')->initContext();
     		$ajaxContext->addActionContext('checkempforprojects', 'json')->initContext();
    -	
    +		//echo Zend_Registry::get( 'tm_role' );
     	}
     
     	/**
    @@ -108,7 +115,7 @@ public function viewAction()
     		{
     			if(is_numeric($id) && $id>0)
     			{
    -				$auth = Zend_Auth::getInstance();  
    +				$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     				if($auth->hasIdentity()){
     					$loginUserId = $auth->getStorage()->read()->id;
     					$loginuserRole = $auth->getStorage()->read()->emprole;
    @@ -273,6 +280,21 @@ public function editAction()
     			$msgarray['client_id'] = 'Clients are not configured yet.';
     			$emptyFlag++;
     		}
    +
    +		$currencyModel = new Default_Model_Currency();
    +		$currencyData = $currencyModel->getCurrencyList();
    +		if(sizeof($currencyData) > 0)
    +		{
    +			foreach ($currencyData as $currency){
    +				$projectsForm->currency_id->addMultiOption($currency['id'],utf8_encode($currency['currency']));
    +			}
    +
    +		}else
    +		{
    +			$msgarray['currency_id'] = 'Currency are not configured yet.';
    +			$emptyFlag++;
    +		}
    +
     		$base_projectData = $projectModel->getProjectList();
     		if(sizeof($base_projectData) > 0)
     		{
    @@ -286,12 +308,12 @@ public function editAction()
     		$this->view->emptyFlag = $emptyFlag;
     		try
     		{
    +
     			if($id)
    -			{	
    -				//Edit Record...
    +			{	//Edit Record...
     				if(is_numeric($id) && $id>0)
     				{
    -					$auth = Zend_Auth::getInstance(); 
    +					$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     					if($auth->hasIdentity()){
     						$loginUserId = $auth->getStorage()->read()->id;
     						$loginuserRole = $auth->getStorage()->read()->emprole;
    @@ -307,6 +329,17 @@ public function editAction()
     							
     							$projectsForm->populate($data[0]);
     							$projectsForm->submit->setLabel('Update');
    +							if($data[0]['start_date'] !='' && $data[0]['start_date'] !='0000-00-00')
    +							{
    +								$estimated_start_date = sapp_Global::change_date($data[0]['start_date'],'view');
    +								$projectsForm->start_date->setValue($estimated_start_date);
    +							}
    +
    +							if($data[0]['end_date'] !='' && $data[0]['end_date'] !='0000-00-00')
    +							{
    +								$estimated_end_date = sapp_Global::change_date($data[0]['end_date'],'view');
    +								$projectsForm->end_date->setValue($estimated_end_date);
    +							}
     							$this->view->form = $projectsForm;
     							$this->view->controllername = $objName;
     							$this->view->data = $data;
    @@ -355,23 +388,46 @@ public function editAction()
     		}
     		if($this->getRequest()->getPost()){
     			if($projectsForm->isValid($this->_request->getPost())){
    +				//print_r($this->_request->getPost());exit;
     				$id = $this->_request->getParam('id');
     				$project_name = $this->_request->getParam('project_name');
     				$project_status = $this->_request->getParam('project_status');
     				$base_project = $this->_request->getParam('base_project');
     				$client_id = $this->_request->getParam('client_id');
    +				$currency_id = $this->_request->getParam('currency_id');
    +				$project_type = $this->_request->getParam('project_type');
    +				$start_date = $this->_request->getParam('start_date');
    +				$start_date = sapp_Global::change_date($start_date,'database');
    +				$end_date = $this->_request->getParam('end_date');
    +				$end_date = sapp_Global::change_date($end_date,'database');
    +				$estimated_hrs = $this->_request->getParam('estimated_hrs');
     				$description = $this->_request->getParam('description');
     
     				$date = new Zend_Date();
     				$data = array('project_name'=>ucfirst(trim($project_name)),
     				              'project_status'=>trim($project_status),
     							  'base_project'=>(trim($base_project)!=''?$base_project:NUll),
    +							  'start_date'=>(trim($start_date)!=''?$start_date:NUll),
    +							  'end_date'=>(trim($end_date)!=''?$end_date:NUll),
    +							  'estimated_hrs'=>(trim($estimated_hrs)!=''?$estimated_hrs:NUll),
     							  'description'=>trim($description),
     							  'client_id'=>trim($client_id),
    +							  'currency_id'=>trim($currency_id),
    +							  'project_type'=>trim($project_type),
     				              'modified_by'=>$loginUserId,
     							  'modified'=>gmdate("Y-m-d H:i:s")
     				);
     
    +				if($project_status == 'initiated'){
    +					$data['initiated_date'] = gmdate("Y-m-d H:i:s");
    +				}
    +				if($project_status == 'hold'){
    +					$data['hold_date'] = gmdate("Y-m-d H:i:s");
    +				}
    +				if($project_status == 'completed'){
    +					$data['completed_date'] = gmdate("Y-m-d H:i:s");
    +				}
    +
     				if($id!=''){
     					$where = array('id=?'=>$id);
     				}
    @@ -382,6 +438,7 @@ public function editAction()
     					$data['is_active'] = 1;
     					$where = '';
     				}
    +
     				$insertedId = $projectModel->SaveorUpdateProjectsData($data, $where);
     				if($insertedId == 'update')
     				{
    @@ -404,6 +461,7 @@ public function editAction()
     					$id = $insertedId;
     					$this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Project added successfully."));
     				}
    +
     				$this->_redirect('timemanagement/projects/tasks/projectid/'.$id);
     			}else
     			{
    @@ -419,6 +477,8 @@ public function editAction()
     
     				if(sizeof($clientData) < 1)
     				$msgarray['client_id'] = 'Clients not configured yet.';
    +				if(sizeof($currencyData) < 1)
    +				$msgarray['currency_id'] = 'Currency not configured yet.';
     				$this->view->msgarray = $msgarray;
     			}
     		}
    @@ -430,7 +490,7 @@ public function editAction()
     	 */
     	public function tasksAction()
     	{
    -		$auth = Zend_Auth::getInstance();
    +		$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     			$loginuserRole = $auth->getStorage()->read()->emprole;
    @@ -438,7 +498,9 @@ public function tasksAction()
     		}
     		$projectTasksData = $projectData = array();
     		$projectId = $this->getRequest()->getParam('projectid',null);
    +
     		if($this->getRequest()->getPost()){
    +			//echo '
    '; print_r($this->getRequest()->getPost());exit;
     			$taskprojectIds = $this->getRequest()->getParam('hid_taskprojid');
     			$projectId = $this->getRequest()->getParam('project_id');
     			$taskIds = $this->getRequest()->getParam('hid_taskid');
    @@ -446,8 +508,26 @@ public function tasksAction()
     			$projectTasksModel = new Timemanagement_Model_Projecttasks();
     			if(count($taskprojectIds) > 0){
     				foreach($taskprojectIds as $key=>$taskProjectId){
    +					if($this->getRequest()->getParam('txt_taskhrs'.$taskProjectId) != ''){
    +						$estimated_hrs =  $this->getRequest()->getParam('txt_taskhrs'.$taskProjectId);
    +					}else{
    +						$estimated_hrs =  "";
    +					}
    +					if($this->getRequest()->getParam('txt_taskbillable_rate'.$taskProjectId) != ''){
    +						$billable_rate =  $this->getRequest()->getParam('txt_taskbillable_rate'.$taskProjectId);
    +					}else{
    +						$billable_rate =  "";
    +					}
    +					if($this->getRequest()->getParam('txt_taskbillable'.$taskProjectId,'') != ''){
    +						$is_billable =  ($this->getRequest()->getParam('txt_taskbillable'.$taskProjectId) == 'on')?'1':'0';
    +					}else{
    +						$is_billable =  0;
    +					}
     					$projectTaskData = array( 'project_id'=>trim($projectId),
     				               'task_id'=>trim($taskIds[$key]), 
    +							   'estimated_hrs'=> $estimated_hrs,
    +							   'billable_rate'=>$billable_rate, 
    +			     	           'is_billable' => $is_billable, 
     							   'is_active' => 1,
     				   			   'modified_by'=>$loginUserId,
     							   'modified'=>gmdate("Y-m-d H:i:s")	
    @@ -463,10 +543,11 @@ public function tasksAction()
     		$projectResourcesModel = new Timemanagement_Model_Projectresources();
     		$checkResourceExistsforProject = $projectResourcesModel->checkProjectResource($projectId,$loginUserId);
     		if($loginUserId == 1 || $checkResourceExistsforProject > 0){
    +
     			try{
     				if(is_numeric($projectId) && $projectId>0){
     					$projectTasksModel = new Timemanagement_Model_Projecttasks();
    -					$projectTasksData = $projectTasksModel->getProjectTasksData($projectId);
    +					$projectTasksData = $projectTasksModel->getProjectTasksData($projectId); //echo '
    ';print_r($projectTasksData); exit;
     					$projectModel = new Timemanagement_Model_Projects();
     					$projectData = $projectModel->getSingleProjectData($projectId);
     					if($projectTasksData == 'norows')
    @@ -515,7 +596,7 @@ public function addtasksprojectAction()
     	}
     
     	public function addtasksAction(){
    -		$auth = Zend_Auth::getInstance(); 
    +		$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     			$loginuserRole = $auth->getStorage()->read()->emprole;
    @@ -553,6 +634,7 @@ public function addtasksAction(){
     							   'modified'=>gmdate("Y-m-d H:i:s")	
     						);
     						$result = $projectTasksModel->SaveorUpdateProjectTaskData($projectTaskData,'');
    +						//$this->_helper->getHelper("FlashMessenger")->addMessage(array("success"=>"Task added successfully."));
     					}
     
     				}
    @@ -600,7 +682,7 @@ public function addtasksAction(){
     				}
     
     				$projectTasksData = array();
    -				$projectTasksData = $projectTasksModel->getProjectTasksData($projectId); 
    +				$projectTasksData = $projectTasksModel->getProjectTasksData($projectId); //echo '
    ';print_r($projectTasksData); exit;
     				if($projectTasksData == 'norows')
     				{
     					$this->view->rowexist = "norows";
    @@ -611,6 +693,7 @@ public function addtasksAction(){
     				}
     				$this->view->projectTasksData = $projectTasksData;
     				$this->view->projectId = $projectId;
    +				$this->view->projectCurrencyCode = $projectData[0]['currencycode'];
     			}
     		}
     	}
    diff --git a/application/modules/timemanagement/controllers/ProjecttasksController.php b/application/modules/timemanagement/controllers/ProjecttasksController.php
    index acb9f1f15..26f3ade72 100644
    --- a/application/modules/timemanagement/controllers/ProjecttasksController.php
    +++ b/application/modules/timemanagement/controllers/ProjecttasksController.php
    @@ -32,6 +32,13 @@ public function init()
     	}
     	public function preDispatch()
     	{
    +		/*$userModel = new Timemanagement_Model_Users();
    +		$checkTmEnable = $userModel->checkTmEnable();
    +
    +		if(!$checkTmEnable){
    +			$this->_redirect('error');
    +		}*/
    +		
     		//check Time management module enable
     		if(!sapp_Helper::checkTmEnable())
     			$this->_redirect('error');
    @@ -60,6 +67,7 @@ public function indexAction()
     		$refresh = $this->_getParam('refresh');
     		$dashboardcall = $this->_getParam('dashboardcall');
     		$projectId = $this->_getParam('projectId');
    +
     		$data = array();
     		$searchQuery = '';
     		$searchArray = array();
    @@ -118,6 +126,7 @@ public function deletetaskAction(){
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     		}
    +
     		$projectId=$this->_getParam('projectId');
     		$projectTaskId=$this->_getParam('projectTaskId');
     		$taskId=$this->_getParam('taskId');
    @@ -199,6 +208,8 @@ public function assignresourcestotaskAction(){
     			$this->view->assignedEmployees = $assignedEmployees;
     			$this->view->notAssignedEmployees = $notAssignedEmployees;
     			$this->view->existedEmpIdArray =$existedEmpArray;
    +
    +			//$this->view->projectEmployees = $projectEmployees;
     			$this->view->taskDetails = $taskDetails;
     			$this->view->projectTaskEmployees = $projectTaskEmployees;
     		}
    @@ -231,7 +242,7 @@ function array_column(array $input, $columnKey, $indexKey = null) {
     	}
     
     	public function saveresourcesAction(){
    -		$auth = Zend_Auth::getInstance(); 
    +		$auth = Zend_Auth::getInstance();  //echo '
    ';print_r($auth->getStorage()->read()); exit;
     		if($auth->hasIdentity()){
     			$loginUserId = $auth->getStorage()->read()->id;
     
    @@ -242,12 +253,15 @@ public function saveresourcesAction(){
     				$newRes = $this->_getParam('newRes');
     				$taskId = $this->_getParam('taskId');
     				$projectTaskId = $this->_getParam('projectTaskId');
    +					
     				$oldRes_arr = $newRes_arr = array();
    +				//echo $oldRes.'
    '; if(isset($oldRes) && $oldRes != '') { $projRes = trim($oldRes,","); $oldRes_arr = explode(",",$oldRes); } + //echo $newRes.'
    '; if(isset($newRes) && $newRes != '') { $projRes = trim($newRes,","); @@ -257,7 +271,7 @@ public function saveresourcesAction(){ if(!empty($newRes_arr)){ foreach($newRes_arr as $newRess){ if(in_array($newRess, $oldRes_arr)){ - $key = array_search($newRess, $oldRes_arr); + $key = array_search($newRess, $oldRes_arr); //echo $key; unset($oldRes_arr[$key]); // check already exists or not continue; }else{ @@ -277,6 +291,7 @@ public function saveresourcesAction(){ $result = $projectTaskResourceModel->SaveorUpdateProjectTaskResourceData($projectTaskResourceData,''); } + //echo $result; } } } diff --git a/application/modules/timemanagement/controllers/ReportsController.php b/application/modules/timemanagement/controllers/ReportsController.php index 0b2f1a3dc..ded0f5b4c 100644 --- a/application/modules/timemanagement/controllers/ReportsController.php +++ b/application/modules/timemanagement/controllers/ReportsController.php @@ -24,6 +24,16 @@ class Timemanagement_ReportsController extends Zend_Controller_Action private $options; public function preDispatch() { + /*$userModel = new Timemanagement_Model_Users(); + $checkTmEnable = $userModel->checkTmEnable(); + + if(!$checkTmEnable){ + $this->_redirect('error'); + }*/ + + //check Time management module enable + // if(!sapp_Helper::checkTmEnable()) + // $this->_redirect('error'); $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('employeereports', 'html')->initContext(); @@ -52,7 +62,10 @@ public function tmreportAction() $start_date = ($this->_getParam('start_date')!='')? $this->_getParam('start_date'):$year_first_day; $end_date = ($this->_getParam('end_date')!='')? $this->_getParam('end_date'):$today; - + // if($start_date != '') + // $start_date = $start_date.' 00:00:00'; + // if($end_date != '') + // $end_date = $end_date.' 23:59:59'; $this->view->start_date = ($this->_getParam('start_date')!='')? $this->_getParam('start_date'):$year_first_day; $this->view->end_date = ($this->_getParam('end_date')!='')? $this->_getParam('end_date'):$today; @@ -78,7 +91,10 @@ public function employeereportsAction(){ $org_start_date = $start_date; $org_end_date = $end_date; - + // if($start_date != '') + // $start_date = $start_date; + // if($end_date != '') + // $end_date = $end_date; $call = $this->_getParam('call'); @@ -127,7 +143,7 @@ public function employeereportsAction(){ $this->view->call = $call ; $this->view->start_date = ($this->_getParam('start_date')!='')? $this->_getParam('start_date'):$year_first_day; $this->view->end_date = ($this->_getParam('end_date')!='')? $this->_getParam('end_date'):$today; - + //$this->view->count=$paginator->getTotalItemCount(); $this->view->selcetedproj =$projid; $this->view->selected_period_hidden = ($this->_getParam('selected_period_hidden')!='')? $this->_getParam('selected_period_hidden'):''; @@ -149,7 +165,11 @@ public function projectsreportsAction(){ $org_start_date = $start_date; $org_end_date = $end_date; - + // if($start_date != '') + // $start_date = $start_date.' 00:00:00'; + // if($end_date != '') + // $end_date = $end_date.' 23:59:59'; + $call = $this->_getParam('call'); if($call == 'ajaxcall'){ @@ -192,12 +212,15 @@ public function projectsreportsAction(){ $param = $this->_getParam('selected_period_hidden'); $employeedata = $reportsmodel->getProjectReportsbyEmployeeId($sort, $by, $perPage, $pageNo, $searchData, $call, $dashboardcall, $start_date, $end_date, $empid,$org_start_date,$org_end_date,$param); + + //print_r($employeedata); + //exit(); array_push($data,$employeedata); $this->view->dataArray = $data; $this->view->call = $call ; $this->view->start_date = ($this->_getParam('start_date')!='')? $this->_getParam('start_date'):$year_first_day; $this->view->end_date = ($this->_getParam('end_date')!='')? $this->_getParam('end_date'):$today; - + //$this->view->count=$paginator->getTotalItemCount(); $this->view->selcetedemp =$empid; $this->view->selected_period_hidden = ($this->_getParam('selected_period_hidden')!='')? $this->_getParam('selected_period_hidden'):''; @@ -226,7 +249,10 @@ public function getempdurationAction() } $start_date = sapp_Global::change_date($start_date,'database'); $end_date = sapp_Global::change_date($end_date,'database'); - + // if($start_date != '') + // $start_date = $start_date.' 00:00:00'; + // if($end_date != '') + // $end_date = $end_date.' 23:59:59'; $reportsmodel = new Timemanagement_Model_Reports(); $emp_id = $this->_getParam('empId'); $get_emp_proj_duration = $reportsmodel->getEmpProjDuration($emp_id,$start_date,$end_date,$projectId,$params); @@ -258,6 +284,10 @@ public function getprojecttaskdurationAction() $start_date = sapp_Global::change_date($start_date,'database'); $end_date = sapp_Global::change_date($end_date,'database'); + // if($start_date != '') + // $start_date = $start_date.' 00:00:00'; + // if($end_date != '') + // $end_date = $end_date.' 23:59:59'; $reportsmodel = new Timemanagement_Model_Reports(); $emp_id = $this->_getParam('empId'); $get_proj_task_duration = $reportsmodel->getProjTaskDuration($emp_id,$start_date,$end_date,$projectId,$params); diff --git a/application/modules/timemanagement/forms/Configuration.php b/application/modules/timemanagement/forms/Configuration.php new file mode 100644 index 000000000..dff1293cd --- /dev/null +++ b/application/modules/timemanagement/forms/Configuration.php @@ -0,0 +1,79 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ + +class Timemanagement_Form_Configuration extends Zend_Form +{ + public function init() + { + $this->setMethod('post'); + $this->setAttrib('id', 'formid'); + $this->setAttrib('name', 'configuration'); + + + $id = new Zend_Form_Element_Hidden('id'); + /*$ts_block_reminder_day = new Zend_Form_Element_Select('ts_block_reminder_day'); + $ts_block_reminder_day->setAttrib('class', 'selectoption'); + $ts_block_reminder_day->setRegisterInArrayValidator(false); + $ts_block_reminder_day->setRequired(true); + $ts_block_reminder_day->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet block reminder day.')); + + $ts_blocking_day = new Zend_Form_Element_Select('ts_blocking_day'); + $ts_blocking_day->setAttrib('class', 'selectoption'); + $ts_blocking_day->setRegisterInArrayValidator(false); + $ts_blocking_day->setRequired(true); + $ts_blocking_day->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet block day.')); + + $ts_block_start_day = new Zend_Form_Element_Select('ts_block_start_day'); + $ts_block_start_day->setAttrib('class', 'selectoption'); + $ts_block_start_day->setRegisterInArrayValidator(false); + $ts_block_start_day->setRequired(true); + $ts_block_start_day->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet block start day.')); + + $ts_block_end_day = new Zend_Form_Element_Select('ts_block_end_day'); + $ts_block_end_day->setAttrib('class', 'selectoption'); + $ts_block_end_day->setRegisterInArrayValidator(false); + $ts_block_end_day->setRequired(true); + $ts_block_end_day->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet block end day.')); */ + + $ts_weekly_reminder_day = new Zend_Form_Element_Select('ts_weekly_reminder_day'); + $ts_weekly_reminder_day->setAttrib('class', 'selectoption'); + $ts_weekly_reminder_day->setRegisterInArrayValidator(false); + $ts_weekly_reminder_day->setRequired(true); + $ts_weekly_reminder_day->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet weekly submission reminder.')); + + $ts_block_dates_range = new Zend_Form_Element_Select('ts_block_dates_range'); + $ts_block_dates_range->setAttrib('class', 'selectoption'); + $ts_block_dates_range->setRegisterInArrayValidator(false); + $ts_block_dates_range->addMultiOption('','Select Block dates range'); + $ts_block_dates_range->addMultiOption('1-31','1st - End of month'); + $ts_block_dates_range->addMultiOption('26-25','26th previous month - 25th current month'); + $ts_block_dates_range->setRequired(true); + $ts_block_dates_range->addValidator('NotEmpty', false, array('messages' => 'Please select timesheet blocking range.')); + + $submit = new Zend_Form_Element_Submit('submit'); + $submit->setAttrib('id', 'submitbutton'); + $submit->setLabel('Save'); + + // $this->addElements(array($id,$ts_block_reminder_day,$ts_blocking_day,$ts_block_start_day,$ts_block_end_day,$ts_weekly_reminder_day,$submit)); + $this->addElements(array($id,$ts_weekly_reminder_day,$ts_block_dates_range,$submit)); + $this->setElementDecorators(array('ViewHelper')); + } +} \ No newline at end of file diff --git a/application/modules/timemanagement/forms/Projects.php b/application/modules/timemanagement/forms/Projects.php index b0a48c67d..e80fadafe 100644 --- a/application/modules/timemanagement/forms/Projects.php +++ b/application/modules/timemanagement/forms/Projects.php @@ -80,7 +80,50 @@ public function init() 'exclude'=>'is_active = 1', ))); $client->getValidator('Db_RecordExists')->setMessage('Selected client is inactivated.'); - + + $currency = new Zend_Form_Element_Select('currency_id'); + $currency->addMultiOption('','Select Currency'); + $currency->setRegisterInArrayValidator(false); + $currency->setRequired(true); + $currency->addValidator('NotEmpty', false, array('messages' => 'Please select currency.')); + + $currency->addValidator(new Zend_Validate_Db_RecordExists( + array('table' => 'main_currency', + 'field' => 'id', + 'exclude'=>'isactive = 1', + ))); + $currency->getValidator('Db_RecordExists')->setMessage('Selected currency is inactivated.'); + + $project_type = new Zend_Form_Element_Radio('project_type'); + $project_type->setLabel("Type"); + $project_type->addMultiOptions(array( + 'billable' => 'Billable', + 'non_billable' => 'Non Billable', + 'revenue' => 'Revenue generation', + )); + $project_type->setSeparator(''); + $project_type->setValue('billable'); + $project_type->setRegisterInArrayValidator(false); + $project_type->setRequired(true); + $project_type->addValidator('NotEmpty', false, array('messages' => 'Please select type.')); + + $start_date = new ZendX_JQuery_Form_Element_DatePicker('start_date'); + $start_date->setOptions(array('class' => 'brdr_none')); + //$date_of_leaving->setAttrib('onchange', 'validatejoiningdate(this)'); + $start_date->setAttrib('readonly', 'true'); + $start_date->setAttrib('onfocus', 'this.blur()'); + + $end_date = new ZendX_JQuery_Form_Element_DatePicker('end_date'); + $end_date->setOptions(array('class' => 'brdr_none')); + //$date_of_leaving->setAttrib('onchange', 'validatejoiningdate(this)'); + $end_date->setAttrib('readonly', 'true'); + $end_date->setAttrib('onfocus', 'this.blur()'); + + $estimated_hrs = new Zend_Form_Element_Text("estimated_hrs"); + $estimated_hrs->setAttrib('maxLength', 5); + $estimated_hrs->addFilter(new Zend_Filter_StringTrim()); + $estimated_hrs->addValidator("regex", false, array("/^([0-9]*\:?[0-9]{1,2})$/","messages"=>"Please enter a valid hours.")); + $description = new Zend_Form_Element_Textarea('description'); $description->setAttrib('rows', 10); $description->setAttrib('cols', 50); @@ -89,7 +132,8 @@ public function init() $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $submit->setLabel('Save'); - $this->addElements(array($id,$invoice_method,$project_name,$projstatus,$base_project,$description,$client,$submit)); + + $this->addElements(array($id,$invoice_method,$project_name,$projstatus,$base_project,$description,$client,$currency,$project_type,$start_date,$end_date,$estimated_hrs,$submit)); $this->setElementDecorators(array('ViewHelper')); $this->setElementDecorators(array( 'UiWidgetElement', diff --git a/application/modules/timemanagement/models/Clients.php b/application/modules/timemanagement/models/Clients.php index 957887b5c..a69bb25a3 100644 --- a/application/modules/timemanagement/models/Clients.php +++ b/application/modules/timemanagement/models/Clients.php @@ -65,6 +65,7 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc $objName = 'clients'; + //email,phone_no,poc,address,country_id,state_id,created_by $tableFields = array( 'action'=>'Action', 'client_name' => 'Client', diff --git a/application/modules/timemanagement/models/Configuration.php b/application/modules/timemanagement/models/Configuration.php new file mode 100644 index 000000000..376c93f5c --- /dev/null +++ b/application/modules/timemanagement/models/Configuration.php @@ -0,0 +1,54 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ +/** + * + * @model Configuration Model + * @author sagarsoft + * + */ +class Timemanagement_Model_Configuration extends Zend_Db_Table_Abstract +{ + protected $_name = 'tm_configuration'; + protected $_primary = 'id'; + + public function getActiveRecord() + { + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('c'=>$this->_name),array('c.*')) + ->where('c.is_active = 1'); + return $this->fetchAll($select)->toArray(); + + } + + public function SaveorUpdateConfigurationData($data, $where) + { + if($where != ''){ + $this->update($data, $where); + return 'update'; + } else { + $this->insert($data); + $id=$this->getAdapter()->lastInsertId($this->_name); + return $id; + } + } + +} \ No newline at end of file diff --git a/application/modules/timemanagement/models/Cronjobstatus.php b/application/modules/timemanagement/models/Cronjobstatus.php new file mode 100644 index 000000000..6ab4d0c5b --- /dev/null +++ b/application/modules/timemanagement/models/Cronjobstatus.php @@ -0,0 +1,54 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ +/** + * + * @model Configuration Model + * @author sagarsoft + * + */ +class Timemanagement_Model_Cronjobstatus extends Zend_Db_Table_Abstract +{ + protected $_name = 'tm_cronjob_status'; + protected $_primary = 'id'; + + public function checkCronRunning() + { + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('c'=>$this->_name),array('c.*')) + ->where("c.cronjob_status = 'running'"); + return $this->fetchAll($select)->toArray(); + + } + + public function saveorUpdateCronjobStatusData($data, $where) + { + if($where != ''){ + $this->update($data, $where); + return 'update'; + } else { + $this->insert($data); + $id=$this->getAdapter()->lastInsertId($this->_name); + return $id; + } + } + +} \ No newline at end of file diff --git a/application/modules/timemanagement/models/Emptimesheets.php b/application/modules/timemanagement/models/Emptimesheets.php index 3082d292b..8aac48106 100644 --- a/application/modules/timemanagement/models/Emptimesheets.php +++ b/application/modules/timemanagement/models/Emptimesheets.php @@ -68,7 +68,7 @@ public function monthly_master($selmn) public function getEmployeesAsscociatedWithProject($manager_id = "",$year,$month,$search="",$clicked_status,$emp_list_flag="",$week="",$current_page){ $search=urldecode($search); - $stat_arr=array('submitted'=>'For Approval','saved'=>'Saved'); + $stat_arr=array('enabled'=>'Enabled','blocked'=>'Blocked','rejected'=>'Rejected','submitted'=>'For Approval','approved'=>'Approved','saved'=>'Saved'); $fin_arr=array(); $i=0; $where = " WHERE (ms.isactive = 1 AND pe.is_active=1 ) "; @@ -79,13 +79,20 @@ public function getEmployeesAsscociatedWithProject($manager_id = "",$year,$month $duration = "IF(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time))))is null,'00:00', time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i'))"; - $time_status = "IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', - IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved','No Entry'))"; + $time_status = "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT week_status))!=0,'Blocked', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT week_status))!=0,'Rejected', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT week_status))!=0,'Approved', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT week_status))!=0,'Enabled','No Entry'))))))"; if($emp_list_flag=="project") { - $time_status = "IF(FIND_IN_SET('submitted',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'For Approval', - IF(FIND_IN_SET('saved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Saved','No Entry' - ))"; + $time_status = "IF(FIND_IN_SET('blocked',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Blocked', +IF(FIND_IN_SET('rejected',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Rejected', +IF(FIND_IN_SET('submitted',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'For Approval', +IF(FIND_IN_SET('approved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Approved', +IF(FIND_IN_SET('saved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Saved', +IF(FIND_IN_SET('enabled',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Enabled','No Entry'))))))"; } $selectEmpTimesheetsQuery = "SELECT GROUP_CONCAT( distinct pe.project_id) proj_ids, ms.user_id AS empid, ms.userfullname AS empname, @@ -120,7 +127,7 @@ public function getEmployeesAsscociatedWithProject($manager_id = "",$year,$month $selectEmpTimesheetsQuery.=" HAVING time_status=\"".$stat_arr[$clicked_status]."\" "; } $selectEmpTimesheetsQuery .= " LIMIT ".$current_index.",".$per_page; - + //echo $selectEmpTimesheetsQuery;exit; $res = $db->query($selectEmpTimesheetsQuery); while ($row=$res->fetch()) { @@ -143,7 +150,7 @@ public function getEmployeesAsscociatedWithProject($manager_id = "",$year,$month public function getEmployeesForMonthly($manager_id = "",$year,$month,$search="",$clicked_status,$emp_list_flag="",$week="",$current_page) { $search=urldecode($search); - $stat_arr=array('submitted'=>'For Approval','saved'=>'Saved'); + $stat_arr=array('enabled'=>'Enabled','blocked'=>'Blocked','rejected'=>'Rejected','submitted'=>'For Approval','approved'=>'Approved','saved'=>'Saved'); $fin_arr=array(); $i=0; $where = " WHERE (ms.isactive = 1) "; @@ -154,8 +161,13 @@ public function getEmployeesForMonthly($manager_id = "",$year,$month,$search="", $duration = "IF(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time))))is null,'00:00', time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i'))"; - $time_status = "IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', - IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved','No Entry'))"; + $time_status = " + IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT week_status))!=0,'Blocked', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT week_status))!=0,'Rejected', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT week_status))!=0,'Approved', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT week_status))!=0,'Enabled','No Entry'))))))"; $selectEmpTimesheetsQuery = "SELECT ms.user_id AS empid, ms.userfullname AS empname, ".$duration." AS duration, @@ -194,7 +206,7 @@ public function getEmployeesForMonthly($manager_id = "",$year,$month,$search="", $selectEmpTimesheetsQuery.=" HAVING time_status=\"".$stat_arr[$clicked_status]."\" "; } $selectEmpTimesheetsQuery .= " LIMIT ".$current_index.",".$per_page; - + //echo $selectEmpTimesheetsQuery;//exit; $res = $db->query($selectEmpTimesheetsQuery); while ($row=$res->fetch()) { @@ -217,7 +229,7 @@ public function getEmployeesForMonthly($manager_id = "",$year,$month,$search="", function getEmployeeTimsheetDetails($year,$month,$week="",$user_id,$project_ids="",$emplistflag=""){ - $stat_arr=array('submitted'=>'For Approval','saved'=>'Saved'); + $stat_arr=array('enabled'=>'Enabled','blocked'=>'Blocked','rejected'=>'Rejected','submitted'=>'For Approval','approved'=>'Approved','saved'=>'Saved'); $fin_arr=array(); $i=0; $where = ""; @@ -226,13 +238,20 @@ function getEmployeeTimsheetDetails($year,$month,$week="",$user_id,$project_ids= $duration = "IF(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time))))is null,'00:00', time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i'))"; - $time_status = "IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', - IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved','No Entry'))"; + $time_status = "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT week_status))!=0,'Blocked', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT week_status))!=0,'For Approval', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT week_status))!=0,'Rejected', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT week_status))!=0,'Approved', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT week_status))!=0,'Saved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT week_status))!=0,'Enabled','No Entry'))))))"; if($emplistflag=="project") { - $time_status = " + $time_status = "IF(FIND_IN_SET('blocked',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Blocked', +IF(FIND_IN_SET('rejected',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Rejected', IF(FIND_IN_SET('submitted',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'For Approval', -IF(FIND_IN_SET('saved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Saved','No Entry'))"; +IF(FIND_IN_SET('approved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Approved', +IF(FIND_IN_SET('saved',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Saved', +IF(FIND_IN_SET('enabled',GROUP_CONCAT(sun_project_status,',',mon_project_status,',',tue_project_status,',',wed_project_status,',',thu_project_status,',',fri_project_status,',',sat_project_status))!=0,'Enabled','No Entry'))))))"; } $selectEmpTimesheetsQuery = "SELECT ms.user_id AS empid,ms.reporting_manager_name, ms.userfullname AS empname, @@ -257,7 +276,7 @@ function getEmployeeTimsheetDetails($year,$month,$week="",$user_id,$project_ids= $selectEmpTimesheetsQuery.=$where; $selectEmpTimesheetsQuery.=" GROUP BY ms.user_id"; - + //echo $selectEmpTimesheetsQuery;//exit; $res = $db->query($selectEmpTimesheetsQuery); while ($row=$res->fetch()) { @@ -282,6 +301,7 @@ public function getEachDayTsDateCron($empid,$cal_week,$startDateYear,$month="") $select = $this->select() ->setIntegrityCheck(false) ->from(array('t' => $this->_ts_status), + //array('ts_week_dates' => "concat(concat(sun_date,'#',sun_status),'$',concat(mon_date,'#',mon_status),'$',concat(tue_date,'#',tue_status),'$',concat(wed_date,'#',wed_status),'$',concat(thu_date,'#',thu_status),'$',concat(fri_date,'#',fri_status),'$',concat(sat_date,'#',sat_status))")) array('ts_week_dates' => "concat(concat(sun_date,'#',sun_status,'#','sun'),'$', concat(mon_date,'#',mon_status,'#','mon'),'$', concat(tue_date,'#',tue_status,'#','tue'),'$', @@ -291,7 +311,7 @@ public function getEachDayTsDateCron($empid,$cal_week,$startDateYear,$month="") concat(sat_date,'#',sat_status,'#','sat'))")) ->where("t.emp_id=".$empid." AND t.is_active=1 AND t.cal_week = '".$cal_week."' AND t.ts_month='".$month."' AND t.ts_year = '".$startDateYear."' ") ->group('t.emp_id'); - + //echo $select;exit(); return $this->fetchAll($select)->toArray(); } @@ -308,11 +328,410 @@ public function getEachDayTsDateCronWithProject($empid,$cal_week,$startDateYear, concat(fri_date,'#',fri_project_status,'#','fri'),'$', concat(sat_date,'#',sat_project_status,'#','sat'))")) ->where("t.emp_id=".$empid." AND t.project_id IS NOT NULL AND t.is_active=1 AND t.cal_week = '".$cal_week."' AND t.ts_month='".$month."' AND t.ts_year = '".$startDateYear."' "); - + //echo $select;exit(); return $this->fetchAll($select)->toArray(); } + + function updateEmployeeTimesheet($emp_id="",$year="",$month="",$lastday="",$calenderWeekArray="",$flag="",$rejectNote="",$emplistflag){ + + $db = Zend_Db_Table::getDefaultAdapter(); + $month_start_date = $year."-".$month."-"."01"; + $month_end_date = $year."-".$month."-".$lastday; + try{ + $db->beginTransaction(); + $monthDatesArray = sapp_Global::createDateRangeArray($month_start_date,$month_end_date); + for($i=0; $irejectEmployeeTimesheetStatus($emp_id,$calenderWeekArray[$i],$year,$monthDatesArray,$rejectNote,$month,$emplistflag); + }else{ + $this->updateEmployeeTimesheetStatus($emp_id,$calenderWeekArray[$i],$year,$flag,$monthDatesArray,$month,$emplistflag); + } + + } + // If all succeed, commit the transaction and all changes + // are committed at once. + $db->commit(); + return TRUE; + }catch(Exception $e){ + // If any of the queries failed and threw an exception, + // we want to roll back the whole transaction, reversing + // changes made in the transaction, even those that succeeded. + // Thus all changes are committed together, or none are. + $db->rollBack(); + echo $e->getMessage(); + return FALSE; + } + } + function rejectEmployeeTimesheetStatus($emp_id="", $calweek="", $year="", $datesArr="",$rejectNote="",$month="",$emplistflag){ + $resultData = array(); + $ts_filled_dates = array(); + $db = Zend_Db_Table::getDefaultAdapter(); + $isprojectManager = false; + $conditionCheck = "submitted"; + $statusUpdate = "rejected"; + $storage = new Zend_Auth_Storage_Session(); + $data = $storage->read(); + + /*$getEmpDetails = $this->getEmp_from_summary($emp_id); + if($data->id !== $getEmpDetails['reporting_manager'] ){ + $isprojectManager = true; + }*/ + + if($emplistflag == "project"){ + $isprojectManager = true; + } + + if($isprojectManager){ + // for manager + $projects = $this->getEmpProjects($data->id); + $projects = explode(',',$projects); + if(sizeof($projects) > 0){ + $resultData = $this->getEachDayTsDateCronWithProject($emp_id,$calweek,$year,$month); + if(sizeof($resultData) > 0){ + foreach ($resultData as $tmpresultData){ + $updateArray = array(); + $updateRejProjStatus = array(); + $updateStatus = array(); + $ts_week_dates = $tmpresultData['ts_week_dates']; + $project_id = $tmpresultData['project_id']; + $ts_weekArray = explode('$',$ts_week_dates); + $curDate = gmdate("Y-m-d H:i:s"); + if(count($ts_weekArray) > 0){ + foreach($ts_weekArray as $ts_day){ + $ts_day_Array = explode('#',$ts_day); + if(in_array($ts_day_Array[0],$datesArr)){ + if($ts_day_Array[1] == $conditionCheck){ + if(!empty($project_id) && $project_id != 'NULL' && in_array($project_id,$projects)){ + $updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_reject_note'] = $rejectNote; + $updateStatus[$ts_day_Array[2].'_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_status_date'] = $curDate; + } + } + } + } + } + if(!empty($project_id)){ + /*$where = array(); + $where['emp_id']=$emp_id; + $where['ts_year']=$year; + $where['cal_week']=$calweek; + $where['project_id']=$project_id; + $where['ts_month']=$month;*/ + $whereStmt = " project_id = ".(int)$project_id." AND emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + if(sizeof($updateArray) > 0){ + //print_r($updateArray); + $result = $db->update($this->_ts_status, $updateArray ,$whereStmt); + + $updateStatusArray = array(); + $getDayStatusForEmp = $this->getEmpDayStatusByProjectStatusForWeek($emp_id,$month, $calweek, $year); + foreach($getDayStatusForEmp as $key => $value){ + if(isset($updateStatus[$key])){ + $updateStatusArray[$key] = $value; + } + } + /*$statusWhere = array(); + $statusWhere['emp_id']=$emp_id; + $statusWhere['ts_year']=$year; + $statusWhere['cal_week']=$calweek; + $statusWhere['ts_month']=$month;*/ + $statusWhere = " emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + //echo $statusWhere; + + $db->update($this->_ts_status, $updateStatusArray ,$statusWhere); + + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$statusWhere); + + } + } + } + } + } + + }else{ + $updateArray = array(); + $updateRejProjStatus = array(); + $resultData = $this->getEachDayTsDateCron($emp_id,$calweek,$year,$month); + if(!empty($resultData[0])){ + $ts_week_dates = $resultData[0]['ts_week_dates']; + $ts_weekArray = explode('$',$ts_week_dates); + if(count($ts_weekArray) > 0){ + foreach($ts_weekArray as $ts_day){ + $ts_day_Array = explode('#',$ts_day); + if(in_array($ts_day_Array[0],$datesArr)){ + if($ts_day_Array[1] == $conditionCheck){ + $updateArray[$ts_day_Array[2].'_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_status_date'] = gmdate("Y-m-d H:i:s"); + $updateRejProjStatus[$ts_day_Array[2].'_reject_note'] = $rejectNote; + } + } + } + $whereStmt = "emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + if(sizeof($updateArray) > 0){ + $db->update($this->_ts_status, $updateArray ,$whereStmt); + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$whereStmt); + if(sizeof($updateRejProjStatus) > 0){ + $db->update('tm_emp_ts_notes', $updateRejProjStatus ,$whereStmt); + } + } + } + } + } + + } + + function updateEmployeeTimesheetStatus($emp_id="", $calweek="", $year="", $flag="", $datesArr="",$month="",$emplistflag){ + + $resultData = array(); + $ts_filled_dates = array(); + $conditionCheck = ""; + $statusUpdate = ""; + $db = Zend_Db_Table::getDefaultAdapter(); + $isprojectManager = false; + if($flag=="enable"){ + $conditionCheck = "blocked"; + $statusUpdate = "enabled"; + } + + if($flag=="approve"){ + $conditionCheck = "submitted"; + $statusUpdate = "approved"; + } + + $storage = new Zend_Auth_Storage_Session(); + $data = $storage->read(); + + if($emplistflag == "project"){ + $isprojectManager = true; + } + + if($isprojectManager){ + // for manager + $projects = $this->getEmpProjects($data->id); + $projects = explode(',',$projects); + if(sizeof($projects) > 0){ + $resultData = $this->getEachDayTsDateCronWithProject($emp_id,$calweek,$year,$month); + if(sizeof($resultData) > 0){ + foreach ($resultData as $tmpresultData){ + $updateArray = array(); + $updateStatus = array(); + $approvedDates = ""; + $ts_week_dates = $tmpresultData['ts_week_dates']; + $project_id = $tmpresultData['project_id']; + $ts_weekArray = explode('$',$ts_week_dates); + if(count($ts_weekArray) > 0){ + foreach($ts_weekArray as $ts_day){ + $ts_day_Array = explode('#',$ts_day); + if(in_array($ts_day_Array[0],$datesArr)){ + if($ts_day_Array[1] == $conditionCheck){ + if($project_id != 'NULL' && in_array($project_id,$projects)){ + $updateStatus[$ts_day_Array[2].'_status'] = $statusUpdate; + //$updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_status_date'] = gmdate("Y-m-d H:i:s"); + if($statusUpdate == "approved"){ + $updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $approvedDates.= $ts_day_Array[0].","; + } + } + } + } + } + } + + if(!empty($project_id) && in_array($project_id,$projects)){ + $whereStmt = " project_id = ".(int)$project_id." AND emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + if(sizeof($updateArray) > 0){ + $result = $db->update($this->_ts_status, $updateArray ,$whereStmt); + if($result > 0){ + $updateStatusArray = array(); + $getDayStatusForEmp = $this->getEmpDayStatusByProjectStatusForWeek($emp_id,$month, $calweek, $year); + foreach($getDayStatusForEmp as $key => $value){ + if(isset($updateStatus[$key])){ + $updateStatusArray[$key] = $value; + } + } + //print_r($updateStatusArray); + $statusWhere = " emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + //echo $statusWhere; + $db->update($this->_ts_status, $updateStatusArray ,$statusWhere); + + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$statusWhere); + + if($statusUpdate == "approved" && $approvedDates != ""){ + $this->saveProcessNotes($emp_id,$approvedDates,$data->id); + /*$insertProcessUpdates = array( + 'emp_id' => $emp_id, + 'ts_dates' => $approvedDates, + 'action_type' => 'approved', + 'alert' => 1, + 'action_by' => $data->id, + 'created' => gmdate("Y-m-d H:i:s") + ); + //print_r($insertProcessUpdates); + $db->insert('tm_process_updates',$insertProcessUpdates);*/ + } + } + } + } + } + } + } + }else{ + $updateArray = array(); + $approvedDates = ""; + $resultData = $this->getEachDayTsDateCron($emp_id,$calweek,$year,$month); + if(!empty($resultData[0])){ + $ts_week_dates = $resultData[0]['ts_week_dates']; + $ts_weekArray = explode('$',$ts_week_dates); + if(count($ts_weekArray) > 0){ + foreach($ts_weekArray as $ts_day){ + $ts_day_Array = explode('#',$ts_day); + if(in_array($ts_day_Array[0],$datesArr)){ + if($ts_day_Array[1] == $conditionCheck){ + $updateArray[$ts_day_Array[2].'_status'] = $statusUpdate; + //$updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $updateArray[$ts_day_Array[2].'_status_date'] = gmdate("Y-m-d H:i:s"); + if($statusUpdate == "approved"){ + $updateArray[$ts_day_Array[2].'_project_status'] = $statusUpdate; + $approvedDates.= $ts_day_Array[0].","; + } + } + } + } + $whereStmt = "emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + if(sizeof($updateArray) > 0){ + $db->update($this->_ts_status, $updateArray ,$whereStmt); + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$whereStmt); + if($approvedDates != ""){ + $this->saveProcessNotes($emp_id,$approvedDates,$data->id); + /*$insertProcessUpdates = array( + 'emp_id' => $emp_id, + 'ts_dates' => $approvedDates, + 'action_type' => 'approved', + 'alert' => 1, + 'action_by' => $data->id, + 'created' => gmdate("Y-m-d H:i:s") + ); + $db->insert('tm_process_updates',$insertProcessUpdates);*/ + } + + } + } + } + } + + } + + function getEmpDayStatusByProjectStatus($emp_id="",$month="", $calweek="", $year="",$project_status="",$day_status="",$day_date_column ="", $day_date=""){ + + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('t' => $this->_ts_status), + array("$day_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT ".$project_status."))!=0,'enabled','No Entry')))))) + ")) + ->where("emp_id=".$emp_id." AND ts_month=".$month." AND project_id IS NOT NULL + AND is_active=1 AND cal_week = '".$calweek."' AND ts_year = '".$year."' AND ".$day_date_column." = '".$day_date."'"); + $result = $this->fetchAll($select)->toArray(); + return $result[0]; + + } + + function getEmpDayStatusByProjectStatusForWeek($emp_id="",$month="", $calweek="", $year=""){ + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('t' => $this->_ts_status), + array("mon_status" => " IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT mon_project_status))!=0,'enabled','no_entry'))))))", + + "tue_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT tue_project_status))!=0,'enabled','no_entry'))))))", + + "wed_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT wed_project_status))!=0,'enabled','no_entry'))))))", + + "thu_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT thu_project_status))!=0,'enabled','no_entry'))))))", + + "fri_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT fri_project_status))!=0,'enabled','no_entry'))))))", + + "sat_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT sat_project_status))!=0,'enabled','no_entry'))))))", + + "sun_status" => "IF(FIND_IN_SET('blocked',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'blocked', + IF(FIND_IN_SET('saved',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'saved', + IF(FIND_IN_SET('rejected',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'rejected', + IF(FIND_IN_SET('submitted',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'submitted', + IF(FIND_IN_SET('approved',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'approved', + IF(FIND_IN_SET('enabled',GROUP_CONCAT(DISTINCT sun_project_status))!=0,'enabled','no_entry'))))))" + ) + ) + ->where("emp_id=".$emp_id." AND ts_month=".$month." AND project_id IS NOT NULL + AND is_active=1 AND cal_week = '".$calweek."' AND ts_year =".$year); + $result = $this->fetchAll($select)->toArray(); + return $result[0]; + } + + + function getEmpWeekStatus($emp_id="", $calweek="", $year="", $month=""){ + + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('t' => $this->_ts_status), + array('week_status' => "IF(FIND_IN_SET('blocked',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'blocked', + IF(FIND_IN_SET('submitted',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'submitted', + IF(FIND_IN_SET('rejected',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'rejected', + IF(FIND_IN_SET('saved',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'saved', + IF(FIND_IN_SET('approved',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'approved', + IF(FIND_IN_SET('enabled',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'enabled','no_entry')))))) + ")) + ->where("emp_id=".$emp_id." AND is_active=1 AND ts_month=".$month." AND cal_week = '".$calweek."' AND ts_year = '".$year."' ") + ->group('emp_id'); + //echo $select; + $result = $this->fetchAll($select)->toArray(); + return $result[0]; + + } public function getEmp_from_summary($userid) { @@ -327,7 +746,7 @@ public function getEmpProjects($userid) $db = Zend_Db_Table::getDefaultAdapter(); $qry = "select GROUP_CONCAT(project_id) as projects from tm_project_employees where is_active = 1 AND emp_id = ".$userid." "; $res = $db->query($qry)->fetch(); - + //print_r($res); return $res['projects']; } @@ -341,13 +760,153 @@ public function getEmpProjectByDate($userid,$calweek,$month,$year,$day,$date) return $res['projects']; } - + public function updateEmployeeDayTimesheet($emp_id, $calweek, $year, $month, $day, $date, $flag, $rejectNote,$emplistflag){ + + $db = Zend_Db_Table::getDefaultAdapter(); + $profiler = $db->getProfiler(); + $resultData = array(); + $ts_filled_dates = array(); + $conditionCheck = ""; + $statusUpdate = ""; + $isprojectManager = false; + try{ + $db->beginTransaction(); + + if($flag=="reject"){ + $conditionCheck = "submitted"; + $statusUpdate = "rejected"; + } + + if($flag=="approve"){ + $conditionCheck = "submitted"; + $statusUpdate = "approved"; + } + + //echo "Calender Week : $calweek"; + $storage = new Zend_Auth_Storage_Session(); + $data = $storage->read(); + + if($emplistflag == "project"){ + $isprojectManager = true; + } + + if($isprojectManager){ + // for manager + $projects = $this->getEmpProjects($data->id); + $projects = explode(',',$projects); + if(sizeof($projects) > 0){ + $weekDay = $day.'_date'; + //for employee + $project_ids = $this->getEmpProjectByDate($emp_id,$calweek,$month,$year,$weekDay,$date); + $project_ids = explode(',',$project_ids); + if(sizeof($project_ids)> 0){ + for($i=0; $i 0){ + $result = $db->update($this->_ts_status, $updateArray ,$whereStmt); + $day_status = $this->getEmpDayStatusByProjectStatus($emp_id,$month,$calweek,$year,$day.'_project_status',$day.'_status',$day.'_date', $date); + $update_day_status_Array = array( + $day.'_status' =>$day_status[$day.'_status'] + ); + $where_day_status = " emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek AND ".$day."_date = '".$date."'"; + //print_r($update_day_status_Array); + //echo $where_day_status; + $db->update($this->_ts_status, $update_day_status_Array ,$where_day_status); + + $where_week_status_Array = " emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek"; + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$where_week_status_Array); + + if($flag=="approve"){ + + $this->saveProcessNotes($emp_id,$date,$data->id); + /*$insertProcessUpdates = array( + 'emp_id' => $emp_id, + 'ts_dates' => $date, + 'action_type' => 'approved', + 'alert' => 1, + 'action_by' => $data->id, + 'created' => gmdate("Y-m-d H:i:s") + ); + $db->insert('tm_process_updates',$insertProcessUpdates);*/ + } + } + + } + } + } + } + }else{ + $updateArray = array(); + $updateRejProjStatus = array(); + $updateArray[$day.'_status'] = $statusUpdate; + $updateArray[$day.'_project_status'] = $statusUpdate; + $updateArray[$day.'_status_date'] = gmdate("Y-m-d H:i:s"); + if($flag=="reject"){ + $updateRejProjStatus[$day.'_reject_note'] = $rejectNote; + } + $whereStmt = "emp_id = $emp_id AND ts_year = $year AND ts_month =".(int)$month." AND cal_week = $calweek AND ".$day."_date = '".$date."'"; + if(sizeof($updateArray) > 0){ + $db->update($this->_ts_status, $updateArray ,$whereStmt); + $weekStatus = $this->getEmpWeekStatus($emp_id,$calweek,$year,$month); + $week_status = $weekStatus['week_status']; + $db->update($this->_ts_status, array('week_status' => $week_status) ,$whereStmt); + } + if($flag=="approve"){ + + $this->saveProcessNotes($emp_id,$date,$data->id); + /*$insertProcessUpdates = array( + 'emp_id' => $emp_id, + 'ts_dates' => $date, + 'action_type' => 'approved', + 'alert' => 1, + 'action_by' => $data->id, + 'created' => gmdate("Y-m-d H:i:s") + ); + $db->insert('tm_process_updates',$insertProcessUpdates);*/ + } + if(sizeof($updateRejProjStatus) > 0){ + $db->update('tm_emp_ts_notes', $updateRejProjStatus ,$whereStmt); + } + } + + // If all succeed, commit the transaction and all changes + // are committed at once. + $db->commit(); + return TRUE; + }catch(Exception $e){ + // If any of the queries failed and threw an exception, + // we want to roll back the whole transaction, reversing + // changes made in the transaction, even those that succeeded. + // Thus all changes are committed together, or none are. + $db->rollBack(); + echo $e->getMessage(); + return FALSE; + } + + } public function getMonthTimesheetData($empId,$year,$month,$project_ids="",$emplistflag='') { $status = '_status'; if($emplistflag == "project"){ $status = '_project_status'; } + + $select_list = ",CONCAT(IFNULL(ts.sun_reject_note,''),IFNULL(en.sun_reject_note,'')) as sun_reject_note ,CONCAT(IFNULL(ts.mon_reject_note,''),IFNULL(en.mon_reject_note,'')) as mon_reject_note,CONCAT(IFNULL(ts.tue_reject_note,''),IFNULL(en.tue_reject_note,'')) as tue_reject_note ,CONCAT(IFNULL(ts.wed_reject_note,''),IFNULL(en.wed_reject_note,'')) as wed_reject_note,CONCAT(IFNULL(ts.thu_reject_note,''),IFNULL(en.thu_reject_note,'')) as thu_reject_note,CONCAT(IFNULL(ts.fri_reject_note,''),IFNULL(en.fri_reject_note,'')) as fri_reject_note,CONCAT(IFNULL(ts.sat_reject_note,''),IFNULL(en.sat_reject_note,'')) as sat_reject_note"; + $select = $this->select() ->setIntegrityCheck(false) ->from(array('et'=>$this->_name),array( @@ -359,17 +918,18 @@ public function getMonthTimesheetData($empId,$year,$month,$project_ids="",$empli if(et.thu_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.thu_duration as time)))),"%H:%i"))thu_duration,ifnull(ts.thu'.$status.',"no_entry")thu_status, if(et.fri_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.fri_duration as time)))),"%H:%i"))fri_duration,ifnull(ts.fri'.$status.',"no_entry")fri_status, if(et.sat_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.sat_duration as time)))),"%H:%i"))sat_duration,ifnull(ts.sat'.$status.',"no_entry")sat_status, - if(et.week_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),"%H:%i"))week_duration' + if(et.week_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),"%H:%i"))week_duration'.$select_list )); if($project_ids != ""){ $select->joinInner(array('ts'=> $this->_ts_status),'ts.emp_id = et.emp_id and et.ts_year= ts.ts_year and et.ts_month= ts.ts_month and et.ts_week = ts.ts_week and et.project_id = ts.project_id and et.project_id IN ('.$project_ids.')',array()); }else{ + // $select->joinInner(array('ts'=> $this->_ts_status),'ts.emp_id = et.emp_id and et.ts_year= ts.ts_year and et.ts_month= ts.ts_month and et.ts_week = ts.ts_week and et.project_id = ts.project_id',array()); $select->joinInner(array('ts'=> $this->_ts_status),'ts.emp_id = et.emp_id and et.ts_year= ts.ts_year and et.ts_month= ts.ts_month and et.ts_week = ts.ts_week and (et.project_id = ts.project_id OR ts.project_id IS NULL)',array()); } $select->joinInner(array('en'=> 'tm_emp_ts_notes'),'en.emp_id = et.emp_id and et.ts_year= en.ts_year and et.ts_month= en.ts_month and et.ts_week = en.ts_week ',array()); $select->where("et.is_active=1 and ts.is_active=1 and et.ts_year = $year and et.ts_month = $month and et.emp_id = $empId"); $select->group('ts.ts_week'); - + // echo $select;//exit; return $this->fetchAll($select)->toArray(); } @@ -388,7 +948,7 @@ public function getWeeklyTimesheetData($empId,$year,$month,$week,$project_ids="" $select->where("p.id IN (".$project_ids.")"); } $select->order('p.project_name'); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } diff --git a/application/modules/timemanagement/models/MyTimesheet.php b/application/modules/timemanagement/models/MyTimesheet.php index a8b4e80b2..6996b6888 100644 --- a/application/modules/timemanagement/models/MyTimesheet.php +++ b/application/modules/timemanagement/models/MyTimesheet.php @@ -29,11 +29,19 @@ public function SaveOrUpdateTimesheet($arrayData) $query = 'INSERT INTO '. $this->_name.'('.implode(',',array_keys($arrayData)).') VALUES ('. implode(',',array_fill(1, count($arrayData), '?')).') ON DUPLICATE KEY UPDATE '.implode(' = ?,', array_keys($arrayDataForUpdate)).' = ?'; - + // echo $query; exit; $result = $db->query($query,array_merge(array_values($arrayData),array_values($arrayDataForUpdate))); return $result; +// if($where != ''){ +// $this->update($data, $where); +// return 'update'; +// } else { +// $this->insert($data); +// $id=$this->getAdapter()->lastInsertId($this->_name); +// return $id; +// } } public function updateTimesheetRecord($data, $where) { @@ -45,7 +53,7 @@ public function updateStatusRecord($data, $where) { $db = Zend_Db_Table::getDefaultAdapter(); $query = 'UPDATE tm_ts_status SET '.implode(' = ?,',array_keys($data)).' = ?'. ' where '.$where; - + //echo $query; exit; $result = $db->query($query,array_values($data)); } @@ -56,7 +64,7 @@ public function getProjNullRecordCountInTimeSheet($empId,$year,$month,$week){ ->from(array('t' => 'tm_emp_timesheets'), array('count(*) rec_count')) ->where(" project_id is null and t.emp_id =".$empId." and t.ts_year = '".$year."' and t.ts_month='".$month."' and t.ts_week = '".$week."'"); - + //echo $select;exit; $result = $this->fetchAll($select)->toArray(); return $result[0]['rec_count']; @@ -68,7 +76,7 @@ public function getProjNullRecordCountInStatus($empId,$year,$month,$week){ ->from(array('s' => 'tm_ts_status'), array('count(*) rec_count')) ->where(" project_id is null and s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month='".$month."' and s.ts_week = '".$week."'"); - + //echo $select;exit; $result = $this->fetchAll($select)->toArray(); return $result[0]['rec_count']; @@ -78,7 +86,7 @@ public function deleteTimesheetTask($empId,$arrayData,$projTaskId,$year,$month,$ $db = Zend_Db_Table::getDefaultAdapter(); $query = 'UPDATE '. $this->_name.' SET '.implode(' = ?,',array_keys($arrayData)).' = ?'. ' where project_task_id = '. $projTaskId.' and ts_year = '.$year.' and ts_month = '.$month .' and ts_week = '.$week.' and emp_id ='. $empId; - + //echo $query; exit; $result = $db->query($query,array_values($arrayData)); return $result; @@ -88,7 +96,7 @@ public function deleteWeekProjectStatus($empId,$arrayData,$projId,$year,$month,$ $db = Zend_Db_Table::getDefaultAdapter(); $query = 'UPDATE tm_ts_status SET '.implode(' = ?,',array_keys($arrayData)).' = ?'. ' where project_id = '. $projId.' and ts_year = '.$year.' and ts_month = '.$month .' and ts_week = '.$week.' and emp_id ='. $empId; - + //echo $query; exit; $result = $db->query($query,array_values($arrayData)); return $result; @@ -172,6 +180,9 @@ public function SaveOrUpdateTimesheetStatus($arrayData) $query = 'INSERT INTO tm_ts_status ('.implode(',',array_keys($arrayData)).') VALUES ('. implode(',',array_fill(1, count($arrayData), '?')).') ON DUPLICATE KEY UPDATE '.implode(' = ?,', array_keys($arrayDataForUpdate)).' = ?'; + //echo $query; //exit; + + // return $db->query($query,array_merge(array_values($arrayData),array_values($arrayDataForUpdate)))->fetch(); $result = $db->query($query,array_merge(array_values($arrayData),array_values($arrayDataForUpdate))); return $result; @@ -191,7 +202,7 @@ public function SaveOrUpdateTimesheetNotes($arrayData) $query = 'INSERT INTO tm_emp_ts_notes ('.implode(',',array_keys($arrayData)).') VALUES ('. implode(',',array_fill(1, count($arrayData), '?')).') ON DUPLICATE KEY UPDATE '.implode(' = ?,', array_keys($arrayDataForUpdate)).' = ?'; - + //// echo $query; exit; $result = $db->query($query,array_merge(array_values($arrayData),array_values($arrayDataForUpdate))); return $result; @@ -222,21 +233,32 @@ public function empployeeDeletedTasks($empId,$year,$mon,$week,$calWeek,$projTask $db = Zend_Db_Table::getDefaultAdapter(); $taskIds = "".implode(',',array_values($projTasks)); - + //echo " tasks --> ".implode(',',array_values($projTasks)); exit; $query = 'SELECT project_task_id FROM tm_emp_timesheets WHERE is_active = 1 and emp_id ='.$empId.' AND ts_year='.$year.' AND ts_month="'.$mon. '" AND ts_week ='.$week.' AND cal_week ='.$calWeek.' AND project_task_id NOT IN ('.$taskIds.')'; - + //echo " SQL ".$query; exit; $result =$db->query($query)->fetch(); return $result; } +// public function getEmployeeWeekTasks($empId,$year,$mon,$week) { +// +// $db = Zend_Db_Table::getDefaultAdapter(); +// $taskIds = "".implode(',',array_values($projTasks)); +// //echo " tasks --> ".implode(',',array_values($projTasks)); exit; +// $query = 'SELECT project_task_id FROM tm_emp_timesheets WHERE is_active = 1 and emp_id ='.$empId.' AND ts_year='.$year.' AND ts_month="'.$mon. +// '" AND ts_week ='.$week.')'; +// //echo " SQL ".$query; exit; +// $result =$db->query($query)->fetch(); +// return $result; +// } public function empployeeDeletedProjects($empId,$year,$mon,$week,$calWeek,$projectIds) { $db = Zend_Db_Table::getDefaultAdapter(); $projIds = "".implode(',',array_values($projectIds)); - + //echo " tasks --> ".implode(',',array_values($projTasks)); exit; $query = 'SELECT project_id FROM tm_ts_status WHERE is_active = 1 and emp_id ='.$empId.' AND ts_year='.$year.' AND ts_month="'.$mon. '" AND ts_week ='.$week.' AND cal_week ='.$calWeek.' AND project_id NOT IN ('.$projIds.')'; - + //echo " SQL ".$query; exit; $result =$db->query($query)->fetch(); return $result; } @@ -248,7 +270,7 @@ public function getWeekDaysDailyStatus($empId,$year,$mon,$week) { 's.fri_status','s.sat_status')) ->where("s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month = '".$mon."' and s.ts_week = '".$week."' ") ->group('s.emp_id'); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } @@ -260,7 +282,7 @@ public function getWeekDaysProjStatus($empId,$year,$mon,$week) { 's.fri_project_status','s.sat_project_status')) ->where("s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month = '".$mon."' and s.ts_week = '".$week."' and s.is_active = 1 "); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } @@ -272,13 +294,13 @@ public function getWeekDaysProjStatusForProject($empId,$year,$mon,$week,$projId) 's.fri_project_status','s.sat_project_status')) ->where("s.project_id =".$projId." and s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month = '".$mon."' and s.ts_week = '".$week."' "); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } - public function getMonthTimesheetData($empId,$year,$month) { - + public function getMonthTimesheetData($empId,$year,$month) { //,$project_ids="" + //echo $project_ids; $select = $this->select() ->setIntegrityCheck(false) ->from(array('et'=>$this->_name),array( @@ -290,44 +312,57 @@ public function getMonthTimesheetData($empId,$year,$month) { if(et.thu_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.thu_duration as time)))),"%H:%i"))thu_duration,ifnull(ts.thu_status,"no_entry")thu_status, if(et.fri_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.fri_duration as time)))),"%H:%i"))fri_duration,ifnull(ts.fri_status,"no_entry")fri_status, if(et.sat_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.sat_duration as time)))),"%H:%i"))sat_duration,ifnull(ts.sat_status,"no_entry")sat_status, - if(et.week_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),"%H:%i"))week_duration' + if(et.week_duration is null,"00:00",time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),"%H:%i"))week_duration, + GROUP_CONCAT(distinct ifnull(tn.sun_reject_note,""), if(ts.sun_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.sun_reject_note,"")),"")) sun_reject_note, + GROUP_CONCAT(distinct ifnull(tn.mon_reject_note,""), if(ts.mon_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.mon_reject_note,"")),"")) mon_reject_note, + GROUP_CONCAT(distinct ifnull(tn.tue_reject_note,""), if(ts.tue_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.tue_reject_note,"")),"")) tue_reject_note, + GROUP_CONCAT(distinct ifnull(tn.wed_reject_note,""), if(ts.wed_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.wed_reject_note,"")),"")) wed_reject_note, + GROUP_CONCAT(distinct ifnull(tn.thu_reject_note,""), if(ts.thu_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.thu_reject_note,"")),"")) thu_reject_note, + GROUP_CONCAT(distinct ifnull(tn.fri_reject_note,""), if(ts.fri_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.fri_reject_note,"")),"")) fri_reject_note, + GROUP_CONCAT(distinct ifnull(tn.sat_reject_note,""), if(ts.sat_reject_note != "", CONCAT(p.project_name,":",ifnull(ts.sat_reject_note,"")),"")) sat_reject_note' )); - + // ->joinInner(array('ts'=>'tm_ts_status'),'ts.emp_id = et.emp_id and ts.project_id = et.project_id',array()) +// if($project_ids != ""){ +// $select->joinInner(array('ts'=>'tm_ts_status'),'ts.emp_id = et.emp_id and et.ts_year= ts.ts_year and et.ts_month= ts.ts_month and et.ts_week = ts.ts_week and et.project_id = ts.project_id and et.project_id IN ('.$project_ids.')',array()); +// }else{ $select->joinInner(array('ts'=>'tm_ts_status'),'ts.emp_id = et.emp_id and et.ts_year= ts.ts_year and et.ts_month= ts.ts_month and et.ts_week = ts.ts_week and (et.project_id = ts.project_id OR ts.project_id IS NULL)',array()); $select->joinInner(array('tn'=>'tm_emp_ts_notes'),'tn.emp_id = ts.emp_id and tn.ts_year= ts.ts_year and tn.ts_month= ts.ts_month and tn.ts_week = ts.ts_week',array()); $select->joinLeft(array('p'=>'tm_projects'),'p.id = ts.project_id and p.id = et.project_id',array()); - + // } $select->where("et.is_active=1 and ts.is_active=1 and et.ts_year = $year and et.ts_month = $month and et.emp_id = $empId"); $select->group('ts.ts_week'); - + //echo $select; exit; return $this->fetchAll($select)->toArray(); } //public function getWeeklyTimesheetData($empId,$year,$calWeek,$week) { - public function getWeeklyTimesheetData($empId,$year,$month,$week,$flag='') { - + public function getWeeklyTimesheetData($empId,$year,$month,$week,$flag='') { //,$project_ids="" + //$calWeek = 26; $where = ''; if($flag != 'view'){ - $where .= " and p.project_status NOT IN ('draft','hold','completed')"; + $where .= " and p.project_status NOT IN ('draft')"; } $select = $this->select() ->setIntegrityCheck(false) ->from(array('pte'=>'tm_project_task_employees'),array( - 'pte.project_id','p.project_name','pte.project_task_id','t.task','sun_duration'=>'ifnull(et.sun_duration,0)','mon_duration'=>'ifnull(et.mon_duration,0)', + 'pte.project_id','p.project_name','p.project_status','pte.project_task_id','t.task','sun_duration'=>'ifnull(et.sun_duration,0)','mon_duration'=>'ifnull(et.mon_duration,0)', 'tue_duration'=>'ifnull(et.tue_duration,0)','wed_duration'=>'ifnull(et.wed_duration,0)','thu_duration'=>'ifnull(et.thu_duration,0)','fri_duration'=>'ifnull(et.fri_duration,0)','sat_duration'=>'ifnull(et.sat_duration,0)','week_duration'=>'ifnull(et.week_duration,0)')) ->joinInner(array('pt'=>'tm_project_tasks'),'pt.id = pte.project_task_id',array()) ->joinInner(array('p'=>'tm_projects'),'p.id = pt.project_id and p.id = pte.project_id',array()) ->joinInner(array('t'=>'tm_tasks'),'t.id = pt.task_id',array()); - + // ->joinLeft(array('et'=>'tm_emp_timesheets'),'et.project_task_id = pte.project_task_id and ts_year='.$year.' and et.ts_month='.$month.' and et.ts_week = '.$week.' and et.emp_id= '.$empId,array()); if($flag == 'view') $select->joinInner(array('et'=>'tm_emp_timesheets'),'et.project_task_id = pte.project_task_id and et.ts_year='.$year.' and et.ts_month='.$month.' and et.ts_week = '.$week.' and et.emp_id= '.$empId,array()); else $select->joinLeft(array('et'=>'tm_emp_timesheets'),'et.project_task_id = pte.project_task_id and ts_year='.$year.' and et.ts_month='.$month.' and et.ts_week = '.$week.' and et.emp_id= '.$empId,array()); $select->where("pte.emp_id =".$empId." and pte.is_active = 1 and p.is_active = 1 $where "); - - $select->order('p.project_name'); +// if($project_ids != ""){ +// $select->where("p.id IN (".$project_ids.")"); +// } + $select->order('p.project_name'); + //echo $select;exit; return $this->fetchAll($select)->toArray(); } public function getWeekNotes($empId,$year,$month,$week){ @@ -336,9 +371,9 @@ public function getWeekNotes($empId,$year,$month,$week){ ->setIntegrityCheck(false) ->from(array('n' => 'tm_emp_ts_notes'),array('n.sun_note','n.mon_note','n.tue_note','n.wed_note','n.thu_note', 'n.fri_note','n.sat_note','n.week_note')) - + // ->where("n.emp_id =".$empId." and n.ts_year = '".$year."' and n.cal_week = '".$calWeek."' "); ->where("n.emp_id =".$empId." and n.ts_year = '".$year."' and n.ts_month='".$month."' and n.ts_week = '".$week."'"); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } // public function getWeekDaysStatus($empId,$year,$calWeek){ @@ -352,10 +387,18 @@ public function getWeekDaysStatus($empId,$year,$month,$week,$emplistflag='',$pro $where = " AND s.project_id IN (".$project_ids.")"; } } + $sun_reject_note = 'CONCAT(IFNULL(s.sun_reject_note,""),IFNULL(en.sun_reject_note,""))'; + $mon_reject_note = 'CONCAT(IFNULL(s.mon_reject_note,""),IFNULL(en.mon_reject_note,""))'; + $tue_reject_note = 'CONCAT(IFNULL(s.tue_reject_note,""),IFNULL(en.tue_reject_note,""))'; + $wed_reject_note = 'CONCAT(IFNULL(s.wed_reject_note,""),IFNULL(en.wed_reject_note,""))'; + $thu_reject_note = 'CONCAT(IFNULL(s.thu_reject_note,""),IFNULL(en.thu_reject_note,""))'; + $fri_reject_note = 'CONCAT(IFNULL(s.fri_reject_note,""),IFNULL(en.fri_reject_note,""))'; + $sat_reject_note = 'CONCAT(IFNULL(s.sat_reject_note,""),IFNULL(en.sat_reject_note,""))'; + $select = $this->select() ->setIntegrityCheck(false) - ->from(array('s' => 'tm_ts_status'),array( + ->from(array('s' => 'tm_ts_status'),array('sun_reject_note'=>$sun_reject_note,'mon_reject_note'=>$mon_reject_note,'tue_reject_note'=>$tue_reject_note,'wed_reject_note'=>$wed_reject_note,'thu_reject_note'=>$thu_reject_note,'fri_reject_note'=>$fri_reject_note,'sat_reject_note'=>$sat_reject_note, 'sun_status'=>'case when s.sun'.$status.' ="submitted" then "For Approval" when s.sun'.$status.' ="saved" then "Yet to submit" when s.sun'.$status.' ="no_entry" then "No Entry" else CONCAT(UCASE(LEFT(s.sun'.$status.', 1)),SUBSTRING(s.sun'.$status.', 2)) end', @@ -389,9 +432,11 @@ public function getWeekDaysStatus($empId,$year,$month,$week,$emplistflag='',$pro ->joinInner(array('en'=> 'tm_emp_ts_notes'),'en.emp_id = s.emp_id and s.ts_year= en.ts_year and s.ts_month= en.ts_month and s.ts_week = en.ts_week ',array()) - + // ->where("s.emp_id =".$empId." and s.ts_year = '".$year."' and s.cal_week = '".$calWeek."' "); ->where("s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month='".$month."' and s.ts_week = '".$week."' ".$where) - ->group('s.emp_id'); + ->group('s.emp_id'); + + //echo $select;//exit; return $this->fetchAll($select)->toArray(); } public function updateDayStatus($empId,$year,$month,$week){ @@ -399,27 +444,55 @@ public function updateDayStatus($empId,$year,$month,$week){ $select = $this->select() ->setIntegrityCheck(false) ->from(array('s' => 'tm_ts_status'),array( - 'sun_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"submitted","no_entry"))', - 'mon_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"submitted", "no_entry"))', - 'tue_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"submitted","no_entry"))', - 'wed_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"submitted","no_entry"))', - 'thu_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"submitted","no_entry"))', - 'fri_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"submitted","no_entry"))', - 'sat_status' => 'IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"saved", - IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"submitted","no_entry"))' + 'sun_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.sun_project_status))!=0,"enabled","no_entry"))))))', + 'mon_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.mon_project_status))!=0,"enabled","no_entry"))))))', + 'tue_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.tue_project_status))!=0,"enabled","no_entry"))))))', + 'wed_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.wed_project_status))!=0,"enabled","no_entry"))))))', + 'thu_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.thu_project_status))!=0,"enabled","no_entry"))))))', + 'fri_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.fri_project_status))!=0,"enabled","no_entry"))))))', + 'sat_status' => 'IF(FIND_IN_SET("blocked",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"blocked", + IF(FIND_IN_SET("saved",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"saved", + IF(FIND_IN_SET("rejected",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"rejected", + IF(FIND_IN_SET("submitted",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"submitted", + IF(FIND_IN_SET("approved",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"approved", + IF(FIND_IN_SET("enabled",GROUP_CONCAT(DISTINCT s.sat_project_status))!=0,"enabled","no_entry"))))))' )) ->where(" s.project_id is not null and s.is_active = 1 and s.emp_id =".$empId." and s.ts_year = '".$year."' and s.ts_month = '".$month."' and s.ts_week = '".$week."' ") ->group('s.emp_id'); $result = $this->fetchAll($select)->toArray(); $db = Zend_Db_Table::getDefaultAdapter(); - + //print_r($result); $where = " emp_id =".$empId." and ts_year = '".$year."' and ts_month = '".$month."' and ts_week = '".$week."' "; $db->update('tm_ts_status',$result[0], $where); } @@ -428,29 +501,33 @@ public function updateWeekStatus($empId,$year,$month,$week){ $select = $this->select() ->setIntegrityCheck(false) ->from(array('t' => 'tm_ts_status'), - array('week_status' => - "IF(FIND_IN_SET('submitted',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'submitted', - IF(FIND_IN_SET('saved',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'saved', 'no_entry'))")) + array('week_status' => "IF(FIND_IN_SET('blocked',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'blocked', + IF(FIND_IN_SET('submitted',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'submitted', + IF(FIND_IN_SET('rejected',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'rejected', + IF(FIND_IN_SET('approved',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'approved', + IF(FIND_IN_SET('saved',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'saved', + IF(FIND_IN_SET('enabled',CONCAT(sun_status,',',mon_status,',',tue_status,',',wed_status,',',thu_status,',',fri_status,',',sat_status))!=0,'enabled','no_entry')))))) + ")) ->where("emp_id=".$empId." and is_active=1 and ts_week = '".$week."' and ts_year = '".$year."' and ts_month = '".$month."' ") ->group('emp_id'); - + // echo $select; $result = $this->fetchAll($select)->toArray(); $db = Zend_Db_Table::getDefaultAdapter(); - + //print_r($result); $where = " emp_id =".$empId." and ts_year = '".$year."' and ts_month = '".$month."' and ts_week = '".$week."' "; $db->update('tm_ts_status',$result[0], $where); } public function updateSubmitStatus($empId,$year,$month,$week,$dataArray) { $db = Zend_Db_Table::getDefaultAdapter(); - + //print_r($result); $where = " emp_id =".$empId." and ts_year = '".$year."' and ts_month = '".$month."' and ts_week = '".$week."' "; $db->update('tm_ts_status',$dataArray, $where); } public function updateProjectSubmitStatus($empId,$year,$month,$week,$dataArray,$projId) { $db = Zend_Db_Table::getDefaultAdapter(); - + //print_r($result); $where = " is_active = 1 and emp_id =".$empId." and ts_year = '".$year."' and ts_month = '".$month."' and ts_week = '".$week."' and project_id = ".$projId; $db->update('tm_ts_status',$dataArray, $where); } @@ -491,6 +568,15 @@ public function updateWeekDuration($empId,$year,$month,$week) { $stmt->execute(); } - + public function getCronDetailsForMonth($year,$month) { + + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('c' => 'tm_mailing_list'),array('ts_start_date','ts_end_date')) + ->where("mail_type = 'block' and YEAR(ts_end_date) = '".$year."' and MONTH(ts_end_date) = '".$month."'"); + + //echo $select;exit; + return $this->fetchAll($select)->toArray(); + } } diff --git a/application/modules/timemanagement/models/Notifications.php b/application/modules/timemanagement/models/Notifications.php new file mode 100644 index 000000000..a4d5ff7ae --- /dev/null +++ b/application/modules/timemanagement/models/Notifications.php @@ -0,0 +1,215 @@ += year(es.date_of_joining) and cal_week >= week(es.date_of_joining)) + and (ts.ts_year <= year(now()) and cal_week <= week('".$weekend."')) + and week_status != 'approved' + group by ts.ts_year,ts.cal_week";*/ + $query = "select ts_year, + concat(if(sun_status not in('submitted','approved'),concat(sun_date,'#',if(sun_status!='',sun_status,'no_entry')),''),'$', + if(mon_status not in('submitted','approved'),concat(mon_date,'#',if(mon_status!='',mon_status,'no_entry')),''),'$', + if(tue_status not in('submitted','approved'),concat(tue_date,'#',if(tue_status!='',tue_status,'no_entry')),''),'$', + if(wed_status not in('submitted','approved'),concat(wed_date,'#',if(wed_status!='',wed_status,'no_entry')),''),'$', + if(thu_status not in('submitted','approved'),concat(thu_date,'#',if(thu_status!='',thu_status,'no_entry')),''),'$', + if(fri_status not in('submitted','approved'),concat(fri_date,'#',if(fri_status!='',fri_status,'no_entry')),''),'$', + if(sat_status not in('submitted','approved'),concat(sat_date,'#',if(sat_status!='',sat_status,'no_entry')),'')) ts_week_dates + from ( + select ts.ts_year,ts.ts_month,ts.cal_week, sun_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(sun_status = 'no_entry','',sun_status))) sun_status, + mon_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(mon_status = 'no_entry','',mon_status))) mon_status, + tue_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(tue_status = 'no_entry','',tue_status))) tue_status, + wed_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(wed_status = 'no_entry','',wed_status))) wed_status, + thu_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(thu_status = 'no_entry','',thu_status))) thu_status, + fri_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(fri_status = 'no_entry','',fri_status))) fri_status, + sat_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(sat_status = 'no_entry','',sat_status))) sat_status + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$loginId." AND ts.ts_year >= year(es.date_of_joining) + and cal_week <= week('".$weekend."') and week_status != 'approved' + group by ts.ts_year,ts.cal_week + )k"; + + $result = $db->query($query)->fetchAll(); + return $result; + } + public function getSubmittedNotifications($loginId,$weekend) + { + $db = Zend_Db_Table::getDefaultAdapter(); + /*$query = "select ts.ts_year,ts.cal_week, + concat(if(sun_status in('submitted','approved'),concat(sun_date,'#',sun_status),''),'$', + if(mon_status in('submitted','approved'),concat(mon_date,'#',mon_status),''),'$', + if(tue_status in('submitted','approved'),concat(tue_date,'#',tue_status),''),'$', + if(wed_status in('submitted','approved'),concat(wed_date,'#',wed_status),''),'$', + if(thu_status in('submitted','approved'),concat(thu_date,'#',thu_status),''),'$', + if(fri_status in('submitted','approved'),concat(fri_date,'#',fri_status),''),'$', + if(sat_status in('submitted','approved'),concat(sat_date,'#',sat_status),'')) ts_week_dates + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$loginId." and (ts.ts_year >= year(es.date_of_joining) and cal_week >= week(es.date_of_joining)) + and (ts.ts_year <= year(now()) and cal_week <= week('".$weekend."')) + and week_status != 'approved' + group by ts.ts_year,ts.cal_week";*/ + + $query = "select ts_year, + concat(if(sun_status in('submitted','approved'),concat(sun_date,'#',if(sun_status!='',sun_status,'no_entry')),''),'$', + if(mon_status in('submitted','approved'),concat(mon_date,'#',if(mon_status!='',mon_status,'no_entry')),''),'$', + if(tue_status in('submitted','approved'),concat(tue_date,'#',if(tue_status!='',tue_status,'no_entry')),''),'$', + if(wed_status in('submitted','approved'),concat(wed_date,'#',if(wed_status!='',wed_status,'no_entry')),''),'$', + if(thu_status in('submitted','approved'),concat(thu_date,'#',if(thu_status!='',thu_status,'no_entry')),''),'$', + if(fri_status in('submitted','approved'),concat(fri_date,'#',if(fri_status!='',fri_status,'no_entry')),''),'$', + if(sat_status in('submitted','approved'),concat(sat_date,'#',if(sat_status!='',sat_status,'no_entry')),'')) ts_week_dates + from ( + select ts.ts_year,ts.ts_month,ts.cal_week, sun_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(sun_status = 'no_entry','',sun_status))) sun_status, + mon_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(mon_status = 'no_entry','',mon_status))) mon_status, + tue_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(tue_status = 'no_entry','',tue_status))) tue_status, + wed_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(wed_status = 'no_entry','',wed_status))) wed_status, + thu_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(thu_status = 'no_entry','',thu_status))) thu_status, + fri_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(fri_status = 'no_entry','',fri_status))) fri_status, + sat_date,TRIM( BOTH ',' FROM GROUP_CONCAT(DISTINCT if(sat_status = 'no_entry','',sat_status))) sat_status + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$loginId." AND ts.ts_year >= year(es.date_of_joining) + and cal_week <= week('".$weekend."') + group by ts.ts_year,ts.cal_week + )k"; + $result = $db->query($query)->fetchAll(); + return $result; + } + //get time sheet status for employee in between days + public function getTimesheetStatus($emp_id,$weekend) + { + $mnth = date('m'); + //and (ts.ts_year = year(now()) and ts.ts_month = month(now()) and cal_week <= week('".$weekend."')) + $db = Zend_Db_Table::getDefaultAdapter(); + $query = "select ts.ts_year,ts.cal_week, + concat(if(sun_status not in('no_entry','saved'),if(month(sun_date)='".$mnth."',concat(sun_date,'#',sun_status),''),''),'$', + if(mon_status not in('no_entry','saved'),if(month(mon_date)='".$mnth."',concat(mon_date,'#',mon_status),''),''),'$', + if(tue_status not in('no_entry','saved'),if(month(tue_date)='".$mnth."',concat(tue_date,'#',tue_status),''),''),'$', + if(wed_status not in('no_entry','saved'),if(month(wed_date)='".$mnth."',concat(wed_date,'#',wed_status),''),''),'$', + if(thu_status not in('no_entry','saved'),if(month(thu_date)='".$mnth."',concat(thu_date,'#',thu_status),''),''),'$', + if(fri_status not in('no_entry','saved'),if(month(fri_date)='".$mnth."',concat(fri_date,'#',fri_status),''),''),'$', + if(sat_status not in('no_entry','saved'),if(month(sat_date)='".$mnth."',concat(sat_date,'#',sat_status),''),'')) ts_week_dates + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$emp_id." and (ts.ts_year >= year(es.date_of_joining)) + and (ts.ts_year = year(now()) and ts.ts_month = month(now()) and cal_week = week('".$weekend."')) + group by ts.ts_year,ts.ts_month,ts.cal_week"; + $result = $db->query($query)->fetchAll(); + return $result; + } + //get saved time sheets + public function getSavedTimesheets($emp_id,$weekend) + { + $mnth = date('m'); + $db = Zend_Db_Table::getDefaultAdapter(); + $query = "select ts.ts_year,ts.cal_week, + concat(if(sun_status in('no_entry','saved'),if(month(sun_date)='".$mnth."',concat(sun_date,'#',sun_status),''),''),'$', + if(mon_status in('no_entry','saved'),if(month(mon_date)='".$mnth."',concat(mon_date,'#',mon_status),''),''),'$', + if(tue_status in('no_entry','saved'),if(month(tue_date)='".$mnth."',concat(tue_date,'#',tue_status),''),''),'$', + if(wed_status in('no_entry','saved'),if(month(wed_date)='".$mnth."',concat(wed_date,'#',wed_status),''),''),'$', + if(thu_status in('no_entry','saved'),if(month(thu_date)='".$mnth."',concat(thu_date,'#',thu_status),''),''),'$', + if(fri_status in('no_entry','saved'),if(month(fri_date)='".$mnth."',concat(fri_date,'#',fri_status),''),''),'$', + if(sat_status in('no_entry','saved'),if(month(sat_date)='".$mnth."',concat(sat_date,'#',sat_status),''),'')) ts_week_dates + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$emp_id." and (ts.ts_year >= year(es.date_of_joining)) + and (ts.ts_year = year(now()) and ts.ts_month = month(now()) and cal_week = week('".$weekend."')) + group by ts.ts_year,ts.ts_month,ts.cal_week"; + $result = $db->query($query)->fetchAll(); + return $result; + } + + //function to get employees under reporting manager + public function getManagerEmployees($managerId) + { + $db = Zend_Db_Table::getDefaultAdapter(); + $query = "select es.user_id,es.userfullname from main_employees_summary es where es.isactive=1 and es.reporting_manager = ".$managerId; + $result = $db->query($query)->fetchAll(); + return $result; + + } + //function to get previous days time sheet status less than current week + public function getpreviousTimesheetStatus($loginId,$weekend,$mnth,$year) + { + $db = Zend_Db_Table::getDefaultAdapter(); + $query = "select ts.ts_year,ts.cal_week, + concat(if(sun_status not in('rejected','blocked'), if(month(sun_date)='".$mnth."',concat(sun_date,'#',sun_status),''),''),'$', + if(mon_status not in('rejected','blocked'),if(month(mon_date)='".$mnth."',concat(mon_date,'#',mon_status),''),''),'$', + if(tue_status not in('rejected','blocked'),if(month(tue_date)='".$mnth."',concat(tue_date,'#',tue_status),''),''),'$', + if(wed_status not in('rejected','blocked'),if(month(wed_date)='".$mnth."',concat(wed_date,'#',wed_status),''),''),'$', + if(thu_status not in('rejected','blocked'),if(month(thu_date)='".$mnth."',concat(thu_date,'#',thu_status),''),''),'$', + if(fri_status not in('rejected','blocked'),if(month(fri_date)='".$mnth."',concat(fri_date,'#',fri_status),''),''),'$', + if(sat_status not in('rejected','blocked'),if(month(sat_date)='".$mnth."',concat(sat_date,'#',sat_status),''),'')) ts_week_dates + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$loginId." and (ts.ts_year >= year(es.date_of_joining)) + and (ts.ts_year <= '".$year."' and ts.ts_month = '".$mnth."' and cal_week = week('".$weekend."')) + group by ts.ts_year,ts.cal_week"; + $result = $db->query($query)->fetchAll(); + return $result; + } + //get time sheet status for employee in between days + public function getpreviousSavedTimesheets($emp_id,$weekend,$mnth,$year) + { + //and (ts.ts_year = year(now()) and ts.ts_month = month(now()) and cal_week <= week('".$weekend."')) + $db = Zend_Db_Table::getDefaultAdapter(); + $query = "select ts.ts_year,ts.cal_week, + concat(if(sun_status in('rejected','blocked'), if(month(sun_date)='".$mnth."',concat(sun_date,'#',sun_status),''),''),'$', + if(mon_status in('rejected','blocked'),if(month(mon_date)='".$mnth."',concat(mon_date,'#',mon_status),''),''),'$', + if(tue_status in('rejected','blocked'),if(month(tue_date)='".$mnth."',concat(tue_date,'#',tue_status),''),''),'$', + if(wed_status in('rejected','blocked'),if(month(wed_date)='".$mnth."',concat(wed_date,'#',wed_status),''),''),'$', + if(thu_status in('rejected','blocked'),if(month(thu_date)='".$mnth."',concat(thu_date,'#',thu_status),''),''),'$', + if(fri_status in('rejected','blocked'),if(month(fri_date)='".$mnth."',concat(fri_date,'#',fri_status),''),''),'$', + if(sat_status in('rejected','blocked'),if(month(sat_date)='".$mnth."',concat(sat_date,'#',sat_status),''),'')) ts_week_dates + from tm_ts_status ts + inner join main_employees_summary es on es.user_id = ts.emp_id + where ts.emp_id=".$emp_id." and (ts.ts_year >= year(es.date_of_joining)) + and (ts.ts_year = '".$year."' and ts.ts_month = '".$mnth."' and cal_week = week('".$weekend."')) + group by ts.ts_year,ts.ts_month,ts.cal_week"; + $result = $db->query($query)->fetchAll(); + //echo $query.'
    '; + return $result; + } + //get number of weeks in current given month + function weeks_in_month($year, $month, $start_day_of_week) + { + // Total number of days in the given month. + $num_of_days = date("t", mktime(0,0,0,$month,1,$year)); + + // Count the number of times it hits $start_day_of_week. + $num_of_weeks = 0; + for($i=1; $i<=$num_of_days; $i++) + { + $day_of_week = date('w', mktime(0,0,0,$month,$i,$year)); + if($day_of_week==$start_day_of_week) + $num_of_weeks++; + } + + return $num_of_weeks; + } + +} diff --git a/application/modules/timemanagement/models/Projectresources.php b/application/modules/timemanagement/models/Projectresources.php index c0f7952b9..dfd2904dd 100644 --- a/application/modules/timemanagement/models/Projectresources.php +++ b/application/modules/timemanagement/models/Projectresources.php @@ -42,7 +42,8 @@ public function getProjectResourcesData($projectId){ ->joinInner(array('r'=>'main_roles'),"r.id = e.emprole",array()) ->joinInner(array('g'=>'main_groups'),"g.id = r.group_id",array()) ->where('pr.is_active = 1 AND e.isactive = 1 AND pr.project_id = '.$projectId.'') - ->order("pr.modified DESC"); + ->order("pr.modified DESC");; + //echo $select;exit; $res = $this->fetchAll($select)->toArray(); if (isset($res) && !empty($res)) { @@ -98,7 +99,9 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc $projectModel = new Timemanagement_Model_Projects(); $projectData = $projectModel->getSingleProjectData($a); - $tableFields = array('empname' => 'Name','tm_role' => 'Role','viewtasks' => ''); + $currencyCode = (isset($projectData[0]['currencycode']))?$projectData[0]['currencycode']:''; + + $tableFields = array('empname' => 'Name','tm_role' => 'Role','billable_rate' => 'Billable Rate ('.$currencyCode.')','cost_rate'=>'Cost Rate ('.$currencyCode.')','viewtasks' => ''); $tablecontent = $this->getProjectResourcesGridData($sort, $by, $pageNo, $perPage,$searchQuery,$a,$loginUserId,$having); @@ -124,6 +127,10 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc ), ) ); + + /* if($tm_role == 'Lead'){ + $dataTmp['otheraction'] = 'leadresourcegrid'; + }*/ return $dataTmp; } public function getProjectResourcesGridData($sort, $by, $pageNo, $perPage,$searchQuery,$project_id,$loginUserId,$having = '') @@ -147,10 +154,11 @@ public function getProjectResourcesGridData($sort, $by, $pageNo, $perPage,$searc if($having != ''){ $select->having("$having") ->order("$by $sort"); + //->limitPage($pageNo, $perPage); }else{ $select->order("$by $sort") ->limitPage($pageNo, $perPage); - } + }//echo $select;exit; return $select; } @@ -199,6 +207,7 @@ public function getProjectNotAddedResource($projectId,$added_empIdStrind,$empTyp ->where("1=1 AND u.date_of_joining <= CURDATE() AND u.isactive = 1 ".$orWhere."") ->group("u.user_id") ->having("tm_role = '".$empType."'"); + //echo $select;exit; $res = $this->fetchAll($select)->toArray(); if (isset($res) && !empty($res)) { @@ -237,7 +246,8 @@ public function getOtherEmployees($projectId,$added_empIdStrind,$empType,$addedM ->joinLeft(array('j'=>'main_jobtitles'),"u.jobtitle_id = j.id",array()) ->where("1=1 AND u.isactive =1 AND u.date_of_joining <= CURDATE() ".$orWhere."") ->group("u.user_id") - ->having("tm_role = '".$empType."'"); + ->having("tm_role = '".$empType."'");; + //echo $select;exit; $res = $this->fetchAll($select)->toArray(); if (isset($res) && !empty($res)) { @@ -286,10 +296,11 @@ public function getEmpTasks($project_id,$resource_id) ->setIntegrityCheck(false) ->from(array('pr'=>'tm_project_task_employees'),array('pr.*')) ->joinInner(array('tt'=>'tm_tasks'),"tt.id = pr.task_id",array('tt.task')) - ->joinInner(array('ept'=>'tm_project_tasks'),"ept.task_id = pr.task_id AND ept.project_id = pr.project_id",array('actual_hrs'=>new Zend_Db_Expr("IF(et.week_duration is null,'',time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i' ))"))) + ->joinInner(array('ept'=>'tm_project_tasks'),"ept.task_id = pr.task_id AND ept.project_id = pr.project_id",array('ept.estimated_hrs','actual_hrs'=>new Zend_Db_Expr("IF(et.week_duration is null,'',time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i' ))"))) ->joinLeft(array('et'=>'tm_emp_timesheets'),'et.project_task_id = ept.id and pr.emp_id = et.emp_id AND et.is_active = 1',array()) ->where('pr.emp_id='.$resource_id.' AND pr.project_id = '.$project_id.' AND pr.is_active = 1 AND ept.is_active=1') ->group(array('ept.id')); + //echo $select; return $this->fetchAll($select)->toArray(); } //FUNCTION TO GET EMPLOYEE DETAILS @@ -322,7 +333,7 @@ public function getAllTasks($projectId,$task_ids='') $db = Zend_Db_Table::getDefaultAdapter(); $select = $this->select() ->setIntegrityCheck(false) - ->from(array('pt'=>'tm_project_tasks')) + ->from(array('pt'=>'tm_project_tasks'),array('pt.task_id','pt.estimated_hrs','pt.id')) ->joinInner(array('t'=>'tm_tasks'),"t.id = pt.task_id ",array('t.task')) ->where('pt.is_active = 1 AND pt.project_id = '.$projectId.$cond.''); return $this->fetchAll($select)->toArray(); @@ -331,9 +342,9 @@ public function getAllTasks($projectId,$task_ids='') public function getassignedTasks($project_id,$employee_id) { $db = Zend_Db_Table::getDefaultAdapter(); - $select = $this->select() + $select = $this->select() ->setIntegrityCheck(false) - ->from(array('pt'=>'tm_project_tasks'),array('pt.task_id')) + ->from(array('pt'=>'tm_project_tasks'),array('pt.task_id','pt.estimated_hrs')) ->joinInner(array('pte'=>'tm_project_task_employees'),"pt.task_id = pte.task_id and pte.project_id = ".$project_id." ",array('pte.id','pte.project_task_id','projectTaskCount'=>'(SELECT count(*) FROM tm_emp_timesheets et WHERE et.project_task_id = pte.project_task_id AND et.is_active = 1 AND et.emp_id ='. $employee_id.')')) ->joinInner(array('t'=>'tm_tasks'),"t.id = pt.task_id ",array('t.task')) ->where('pt.is_active = 1 AND pt.project_id = '.$project_id.' and pte.is_active = 1 and pte.emp_id = '.$employee_id); diff --git a/application/modules/timemanagement/models/Projects.php b/application/modules/timemanagement/models/Projects.php index 87d7242d2..a2f4e8874 100644 --- a/application/modules/timemanagement/models/Projects.php +++ b/application/modules/timemanagement/models/Projects.php @@ -60,15 +60,18 @@ public function getProjectsData($sort, $by, $pageNo, $perPage,$searchQuery) $projectsData = $this->select()->distinct() ->setIntegrityCheck(false) - ->from(array('p' => $this->_name),array('id'=>'p.id','project_name'=>'p.project_name','project_status'=>'if(p.project_status = "initiated", "Initiated",if(p.project_status = "draft" , "Draft",if (p.project_status = "in-progress","In Progress",if(p.project_status = "hold","Hold",if(p.project_status = "completed","Completed","")))))','parent_project'=>'p2.project_name')) + ->from(array('p' => $this->_name),array('id'=>'p.id','project_name'=>'p.project_name','project_status'=>'if(p.project_status = "initiated", "Initiated",if(p.project_status = "draft" , "Draft",if (p.project_status = "in-progress","In Progress",if(p.project_status = "hold","Hold",if(p.project_status = "completed","Completed","")))))','start_date'=>'p.start_date','end_date'=>'p.end_date','parent_project'=>'p2.project_name','project_type'=>'IF(p.project_type="billable","Billable",IF(p.project_type="non_billable","Non billable","Revenue generation"))')) ->joinLeft(array('p2' => $this->_name),'p.base_project = p2.id',array()) - ->joinLeft(array('c'=>'tm_clients'),'p.client_id=c.id',array('client_name'=>'c.client_name')); + ->joinLeft(array('c'=>'tm_clients'),'p.client_id=c.id',array('client_name'=>'c.client_name')) + ->joinLeft(array('cur'=>'main_currency'),'p.currency_id = cur.id',array('currencyname'=>'cur.currencyname')); if(Zend_Registry::get( 'tm_role' ) == 'Manager'){ $projectsData->joinLeft(array('pe'=>'tm_project_employees'),'pe.project_id = p.id',array()); } $projectsData->where($where) ->order("$by $sort") ->limitPage($pageNo, $perPage); + //echo $projectsData;exit; + return $projectsData; } @@ -97,10 +100,13 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc foreach($searchValues as $key => $val) { if($key == 'client') $key = 'client_id'; + if($key == 'currency') $key = 'currency_id'; if($key == 'parent_project'){ $searchQuery .= " p.base_project = '".$val."' AND "; }else if($key == 'client_name'){ $searchQuery .= " c.id = '".$val."' AND "; + }else if($key == 'currencyname'){ + $searchQuery .= " cur.id = '".$val."' AND "; }else{ $searchQuery .= " p.".$key." like '%".$val."%' AND "; } @@ -111,7 +117,7 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc $objName = 'projects'; - $tableFields = array('action'=>'Action','project_name' => 'Project','project_status'=>'Status','parent_project'=>'Base Project','client_name' => 'Client'); + $tableFields = array('action'=>'Action','project_name' => 'Project','project_status'=>'Status','parent_project'=>'Base Project','client_name' => 'Client','currencyname'=>'Currency','project_type'=>'Project Type'); $tablecontent = $this->getProjectsData($sort, $by, $pageNo, $perPage,$searchQuery); @@ -135,6 +141,16 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc } } + $currencyModel = new Default_Model_Currency(); + $currencyData = $currencyModel->getCurrencyList(); + $currencyArray = array(''=>'All'); + if(sizeof($currencyData) > 0) + { + foreach ($currencyData as $currency){ + $currencyArray[$currency['id']] = $currency['currency']; + } + } + $dataTmp = array( 'sort' => $sort, 'by' => $by, @@ -155,15 +171,27 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc 'type' => 'select', 'filter_data' => $clientArray, ), - 'parent_project' => array( + 'currencyname' => array( + 'type' => 'select', + 'filter_data' => $currencyArray, + ), + 'parent_project' => array( 'type' => 'select', 'filter_data' => $base_projectArray, ), - 'project_status' => array( + 'category' => array( + 'type' => 'select', + 'filter_data' => array(''=>'All','billable' => 'Billable','non_billable' => 'Non Billable','revenue' => 'Revenue generation'), + ), + 'project_status' => array( 'type' => 'select', 'filter_data' => array(''=>'All','initiated' => 'Initiated','draft' => 'Draft','in-progress' => 'In Progress','hold'=>'Hold','completed'=>'Completed'), ), - + 'project_type' => array('type' => 'select', + 'filter_data' => array(''=>'All','billable' => 'Billable','non_billable' => 'Non Billable','revenue' => 'Revenue generation'), + ), + //'start_date'=>array('type'=>'datepicker'), + // 'end_date'=>array('type'=>'datepicker') ), ); return $dataTmp; @@ -174,6 +202,7 @@ public function getSingleProjectData($id){ ->setIntegrityCheck(false) ->from(array('p'=>$this->_name),array('p.*')) ->joinLeft(array('c'=>'tm_clients'),'p.client_id=c.id',array('client_name'=>'c.client_name')) + ->joinLeft(array('cur'=>'main_currency'),'p.currency_id=cur.id',array('currencyname'=>'cur.currencyname','currencycode'=>'cur.currencycode')) ->where('p.is_active = 1 AND p.id='.$id.' '); $res = $this->fetchAll($select)->toArray(); if (isset($res) && !empty($res)) @@ -245,7 +274,12 @@ public function getEmpGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboa foreach($searchValues as $key => $val) { if($key == 'client') $key = 'client_id'; - else{ + if($key == 'currency') $key = 'currency_id'; + if($key == 'start_date'){ + $searchQuery .= " ".$key." like '%". sapp_Global::change_date($val,'database')."%' AND "; + }else if($key == 'end_date'){ + $searchQuery .= " ".$key." like '%". sapp_Global::change_date($val,'database')."%' AND "; + }else{ $searchQuery .= " ".$key." like '%".$val."%' AND "; } $searchArray[$key] = $val; @@ -258,7 +292,7 @@ public function getEmpGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboa $objName = 'leadprojects'; } - $tableFields = array('action'=>'Action','project_name' => 'Project','client_name' => 'Client'); + $tableFields = array('action'=>'Action','project_name' => 'Project','start_date' => 'Start Date','end_date' => 'End Date','client_name' => 'Client'); $tablecontent = $this->getEmpProjectsData($sort, $by, $pageNo, $perPage,$searchQuery,$employee_id); @@ -282,6 +316,16 @@ public function getEmpGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboa } } + $currencyModel = new Default_Model_Currency(); + $currencyData = $currencyModel->getCurrencyList(); + $currencyArray = array(''=>'All'); + if(sizeof($currencyData) > 0) + { + foreach ($currencyData as $currency){ + $currencyArray[$currency['currency']] = $currency['currency']; + } + } + $dataTmp = array( 'sort' => $sort, 'by' => $by, @@ -301,18 +345,26 @@ public function getEmpGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboa 'client_name' => array( 'type' => 'select', 'filter_data' => $clientArray, + ), + 'currencyname' => array( + 'type' => 'select', + 'filter_data' => $currencyArray, ), 'base_project' => array( 'type' => 'select', 'filter_data' => $base_projectArray, ), - + 'category' => array( + 'type' => 'select', + 'filter_data' => array(''=>'All','billable' => 'Billable','non_billable' => 'Non Billable','revenue' => 'Revenue generation'), + ), 'project_status' => array( 'type' => 'select', 'filter_data' => array(''=>'All','initiated' => 'Initiated','draft' => 'Draft','in-progress' => 'In Progress','hold'=>'Hold','completed'=>'Completed'), - ) - - ) + ), + 'start_date'=>array('type'=>'datepicker'), + 'end_date'=>array('type'=>'datepicker') + ), ); return $dataTmp; } @@ -327,11 +379,13 @@ public function getEmpProjectsData($sort, $by, $pageNo, $perPage,$searchQuery,$e $projectsData = $this->select() ->setIntegrityCheck(false) ->from(array('tpe' => 'tm_project_employees'),array('tpe.*')) - ->joinLeft(array('p' => $this->_name),'tpe.project_id=p.id',array('id'=>'p.id','project_name'=>'p.project_name','project_status'=>'p.project_status','base_project'=>'p.base_project')) + ->joinLeft(array('p' => $this->_name),'tpe.project_id=p.id',array('id'=>'p.id','project_name'=>'p.project_name','project_status'=>'p.project_status','start_date'=>'p.start_date','end_date'=>'p.end_date','base_project'=>'p.base_project','project_type'=>'IF(p.project_type="billable","Billable",IF(p.project_type="non_billable","Non billable","Revenue generation"))')) ->joinLeft(array('c'=>'tm_clients'),'p.client_id=c.id',array('client_name'=>'c.client_name')) + ->joinLeft(array('cur'=>'main_currency'),'p.currency_id = cur.id',array('currencyname'=>'cur.currencyname')) ->where($where) ->order("$by $sort") ->limitPage($pageNo, $perPage); + // echo $projectsData; //exit; return $projectsData; } @@ -418,8 +472,446 @@ public function getprevmonthweeks($selmn,$day) return $this->getprevmonthweeks($new_selmn, $lsday_new); } } + //previous weeks submit status. + public function prev_weeksubmit_status($prevweeks,$emp_id,$emp_details) + { + $fin_str=array(); + $month_name=''; + $prev_str=''; + if(sizeof($prevweeks) >0) + { + //To get dates of timesheet filled by user of the given duration + + $notificationModel = new Timemanagement_Model_Notifications(); + $weekend_date = date('Y-m-d', strtotime('last saturday')); + + for($i=1;$i<=count($prevweeks);$i++) + { + $timesheet_date_array = array(); + $weekno=$i; + $hidstartweek_date=min($prevweeks[$i]); + $for_month=new DateTime($hidstartweek_date); + $yr_mnth=$for_month->format('Y-m'); + $month_name=$for_month->format('F'); + $hidendweek_date=max($prevweeks[$i]); + $hidemp=$emp_id; + $emp_dept_id = $emp_details['department_id']; + $join_date=new DateTime($emp_details['date_of_joining']); + $join_date=$join_date->format('Y-m-d'); + + $resultData = array(); + $savedTimeSheets = array(); + $resultData = $notificationModel->getTimesheetStatus($emp_id,$hidendweek_date); + $savedTimeSheets = $notificationModel->getSavedTimesheets($emp_id,$hidendweek_date); + + //End + if(count($resultData)>0) + { + $timesheet_dates_with_status = ''; + foreach($resultData as $array) + { + $timesheet_dates_with_status.= $array['ts_week_dates']; + $timesheet_dates_with_status.='$'; + } + $ts_date_array = array(); + $ts_date_array = array_filter(explode('$',$timesheet_dates_with_status)); + $timesheetEnteredDates = implode('#',$ts_date_array); + //echo $timesheetEnteredDates; + $timesheetEnteredDatesArray = explode('#',$timesheetEnteredDates); + $statusArray = array('saved','enabled','rejected','blocked','no_entry','submitted','approved'); + $enteredDateStatusArr = array(); + $timesheet_date_arr=array(); + if(count($timesheetEnteredDatesArray)>0) + { + foreach($timesheetEnteredDatesArray as $date) + { + if(!in_array($date,$statusArray)) + { + $timesheet_date_arr[] = $date; + } + else + { + $enteredDateStatusArr[] = $date; + } + } + } + foreach($timesheet_date_arr as $key => $ts_date) + { + //echo 'date'.$ts_date.'-----'.$enteredDateStatusArr[$key].'
    '; + if($ts_date>=date('Y-m-01') && $ts_date<=date('Y-m-t') && isset($enteredDateStatusArr[$key]) && ($enteredDateStatusArr[$key]=='approved' || $enteredDateStatusArr[$key]=='submitted')) + { + $timesheet_date_array[] = $ts_date; + } + } + } + $saved_timesheet_date_array = array(); + $timesheet_date_arry=array(); + $enteredDateStatusArray = array(); + if(count($savedTimeSheets)>0) + { + $saved_timesheet_dates = ''; + foreach($savedTimeSheets as $arrayy) + { + $saved_timesheet_dates.= $arrayy['ts_week_dates']; + $saved_timesheet_dates.='$'; + } + $saved_ts_date_arra = array(); + $saved_ts_date_arra = array_filter(explode('$',$saved_timesheet_dates)); + $timesheetEnteredDatesArr = array(); + $timesheetEnteredDate=''; + $timesheetEnteredDate = implode('#',$saved_ts_date_arra); + //echo $timesheetEnteredDates; + $timesheetEnteredDatesArr = explode('#',$timesheetEnteredDate); + $statusArray = array('saved','enabled','rejected','blocked','no_entry','submitted','approved'); + $timesheet_date_arry=array(); + $enteredDateStatusArray = array(); + if(count($timesheetEnteredDatesArr)>0) + { + foreach($timesheetEnteredDatesArr as $dates) + { + if(!in_array($dates,$statusArray)) + { + $timesheet_date_arry[] = $dates; + } + else + { + $enteredDateStatusArray[] = $dates; + } + } + } + foreach($timesheet_date_arry as $key => $saved_date) + { + if($saved_date>=date('Y-m-01') && $saved_date<=date('Y-m-t') && isset($enteredDateStatusArray[$key]) && ($enteredDateStatusArray[$key]=='approved' || $enteredDateStatusArray[$key]=='submitted')) + if($saved_date>=date('Y-m-01') && $saved_date<=date('Y-m-t') && isset($enteredDateStatusArray[$key]) && ($enteredDateStatusArray[$key]=='approved' || $enteredDateStatusArray[$key]=='submitted')) + { + $saved_timesheet_date_array[] = $saved_date; + } + } + } + $weekDatesArray = array(); + //To get day in the week + $weekDatesArray = sapp_Global::createDateRangeArray($hidstartweek_date,$hidendweek_date); + //End + + + //To get Holidays for the given duration + + $holidays = array(); + $holidayDateslistArr = array(); + $loginUserGroupId = $emp_details['holiday_group']; + if( isset($hidemp) && $hidemp !=''){ + $holidaydatesmodel = new Default_Model_Holidaydates(); + if($loginUserGroupId>0) + { + $holidayDateslistArr = $holidaydatesmodel->getHolidayDatesListForGroup($loginUserGroupId); + } + if(!empty($holidayDateslistArr)) + { + for($j=0;$jgetEmpLeaves($hidemp,$hidstartweek_date,$hidendweek_date); + $emp_leave_days = array(); + foreach($employeeLeaves as $empleave) + { + $emplev_start_date = $empleave['from_date']; + $emplev_endt_date = $empleave['to_date']; + $emp_leave_days[] = sapp_Global::createDateRangeArray($emplev_start_date,$emplev_endt_date); + } + $employee_leave_days = array(); + foreach($emp_leave_days as $lev_days) + { + foreach($lev_days as $days) + { + $employee_leave_days[] = $days; + } + } + //End + $empWeekends = array(); + //To get default not working days(saturday and sunday) + $empWeekends = $usersModel->getWeekend($hidstartweek_date,$hidendweek_date,$emp_dept_id); + //End + + //combine all holidays , leaves, weekends + $hol_leav_weknd = array(); + $hol_leav_weknd = array_merge($holidays,$employee_leave_days,$empWeekends); + + $no_entry_weekennds = array(); + if(count($timesheet_date_arry)>0) + { + //if employee work on holiday , weekend + foreach($timesheet_date_arry as $key =>$val) + { + if(in_array($val,$hol_leav_weknd) && $enteredDateStatusArray[$key]=='no_entry') + { + $no_entry_weekennds[] = $val; + } + } + } + //remove holidays,weekend,leaves from between days + $working_days = array(); + $working_days = array_diff($weekDatesArray, $hol_leav_weknd); + $emptyDataDatesArry=array(); + $emptyDataDatesArray = array(); + $holiday_timesheets = array(); + $holiday_timesheets = array_diff($working_days,$timesheet_date_array); + $emptyDataDatesArry = array_merge($holiday_timesheets,$saved_timesheet_date_array); + $emptyDataDatesArray = array_diff($emptyDataDatesArry,$no_entry_weekennds); + if(count($emptyDataDatesArray)>0) + { + $newemptyDataDatesArray=array(); + foreach($emptyDataDatesArray as $edate) + { + if($edate>=$join_date) + $newemptyDataDatesArray[]=$edate; + } + $emptyDataDatesArray=$newemptyDataDatesArray; + } + if(count($emptyDataDatesArray) >0) + { + $fin_str[]= $weekno; + } + } + } + if(count($fin_str)>0) + { + $prev_str= " Week- ".implode(',', $fin_str).' timesheet(s) of '.$month_name."@@@".$yr_mnth; + } + return $prev_str; + } + //function to get previous pending submissions + public function getPreviousDaysTSStatus($prevweeks,$emp_id,$emp_details) + { + $fin_str=array(); + $month_name=''; + $prev_str=''; + $final_display_array = array(); + + if(sizeof($prevweeks) >0) + { + //To get dates of timesheet filled by user of the given duration + $resultData = array(); + $timesheet_date_array = array(); + $enteredDateStatusArr = array(); + $notificationModel = new Timemanagement_Model_Notifications(); + $weekend_date = date('Y-m-d', strtotime('last saturday')); + for($i=1;$i<=count($prevweeks);$i++) + { + + $savedTimeSheetArray = array(); + $savedTimeSheetblckedArray = array(); + $weekno=$i; + $hidstartweek_date=min($prevweeks[$i]); + $for_month=new DateTime($hidstartweek_date); + $yr_mnth=$for_month->format('Y-m'); + $month_name=$for_month->format('F'); + $hidendweek_date=max($prevweeks[$i]); + $mnth = date('m',strtotime($hidendweek_date)); + $year = date('Y',strtotime($hidendweek_date)); + $hidemp=$emp_id; + $emp_dept_id = $emp_details['department_id']; + $join_date=new DateTime($emp_details['date_of_joining']); + $join_date=$join_date->format('Y-m-d'); + $resultData = $notificationModel->getpreviousTimesheetStatus($emp_id,$hidendweek_date,$mnth,$year); + $savedTimeSheets = $notificationModel->getpreviousSavedTimesheets($emp_id,$hidendweek_date,$mnth,$year); + //End + if(count($resultData)>0) + { + $timesheet_dates_with_status = ''; + foreach($resultData as $array) + { + $timesheet_dates_with_status.= $array['ts_week_dates']; + $timesheet_dates_with_status.='$'; + } + $timesheet_date_with_status_array = array_filter(explode('$',$timesheet_dates_with_status)); + $timesheetEnteredDatesArray = array(); + if(count($timesheet_date_with_status_array)>0) + { + $timesheetEnteredDates = implode('#',$timesheet_date_with_status_array); + $timesheetEnteredDatesArray = explode('#',$timesheetEnteredDates); + } + $enteredDatesArray = array(); + $statusArray = array('saved','enabled','rejected','blocked','no_entry','submitted','approved'); + $enteredDateStatusArr = array(); + $timesheet_date_array = array(); + if(count($timesheetEnteredDatesArray)>0) + { + foreach($timesheetEnteredDatesArray as $date) + { + if(!in_array($date,$statusArray)) + { + $timesheet_date_array[] = $date; + } + else + { + $enteredDateStatusArr[] = $date; + } + } + } + + } + if(count($timesheet_date_array) > 0 && (count($timesheet_date_array) == count($enteredDateStatusArr))) + { + foreach($timesheet_date_array as $key=>$value) + { + $status = 'No Entry'; + if(isset($key)) + { + $status = $key; + } + $savedTimeSheetArray[$value] = ($enteredDateStatusArr[$status]=='no_entry')?'No Entry':$enteredDateStatusArr[$status]; + } + } + $saved_timesheet_date_array = array(); + if(count($savedTimeSheets)>0) + { + $saved_timesheet_dates = ''; + foreach($savedTimeSheets as $arrayy) + { + $saved_timesheet_dates.= $arrayy['ts_week_dates']; + $saved_timesheet_dates.='$'; + } + $timesheet_date_with_status_array = array_filter(explode('$',$saved_timesheet_dates)); + $timesheetEnteredDatesArr = array(); + if(count($timesheet_date_with_status_array)>0) + { + $timesheetSavedEnteredDates = implode('#',$timesheet_date_with_status_array); + $timesheetEnteredDatesArr = explode('#',$timesheetSavedEnteredDates); + } + $enteredDatesArray = array(); + $statusArr = array('saved','enabled','rejected','blocked','no_entry','submitted','approved'); + $enteredDateStatusArry = array(); + foreach($timesheetEnteredDatesArr as $dates) + { + if(!in_array($dates,$statusArr)) + { + $saved_timesheet_date_array[] = $dates; + } + else + { + $enteredDateStatusArry[] = $dates; + } + } + } + if(count($saved_timesheet_date_array)>0 && count($enteredDateStatusArry)>0) + { + foreach($saved_timesheet_date_array as $keyy=>$valuee) + { + $savedTimeSheetblckedArray[$valuee] = $enteredDateStatusArry[$keyy]; + } + } + //To get day in the week + $weekDatesArray = sapp_Global::createDateRangeArray($hidstartweek_date,$hidendweek_date); + //End + //To get Holidays for the given duration + + $holidays = array(); + $holidayDateslistArr = array(); + $loginUserGroupId = $emp_details['holiday_group']; + if( isset($hidemp) && $hidemp !=''){ + $holidaydatesmodel = new Default_Model_Holidaydates(); + if($loginUserGroupId>0) + { + $holidayDateslistArr = $holidaydatesmodel->getHolidayDatesListForGroup($loginUserGroupId); + } + if(!empty($holidayDateslistArr)) + { + for($j=0;$j0) + { + foreach($holidays as $holidayDate){ + //if(!in_array($holidayDate,$timesheet_date_array) && !in_array($holidayDate,$saved_timesheet_date_array) && ($holidayDate>=$hidstartweek_date && $holidayDate<=$hidendweek_date)) + if(!(isset($savedTimeSheetArray[$holidayDate]) && $savedTimeSheetArray[$holidayDate]!='No Entry') && !(isset($savedTimeSheetblckedArray[$holidayDate]) && $savedTimeSheetblckedArray[$holidayDate]!='No Entry') && ($holidayDate>=$hidstartweek_date && $holidayDate<=$hidendweek_date)) + { + $holidaysStatusArray[$holidayDate] = 'Holiday'; + } + } + } + //End + + //To get Leaves applied by user for the given duration + + $employeeLeaves = array(); + $usersModel = new Timemanagement_Model_Users(); + $employeeLeaves = $usersModel->getEmpLeaves($hidemp,$hidstartweek_date,$hidendweek_date); + $emp_leave_days = array(); + foreach($employeeLeaves as $empleave) + { + $emplev_start_date = $empleave['from_date']; + $emplev_endt_date = $empleave['to_date']; + $emp_leave_days[] = sapp_Global::createDateRangeArray($emplev_start_date,$emplev_endt_date); + } + $employee_leave_days = array(); + $employee_leave_ts_array = array(); + foreach($emp_leave_days as $lev_days) + { + foreach($lev_days as $days) + { + $employee_leave_days[] = $days; + $employee_leave_ts_array[$days]='Leave'; + } + } + //End + //To get default not working days(saturday and sunday) + $empWeekends = $usersModel->getWeekend($hidstartweek_date,$hidendweek_date,$emp_dept_id); + //End + $weekend_array = array(); + foreach($empWeekends as $weekend) + { + if(!(isset($savedTimeSheetArray[$weekend]) && $savedTimeSheetArray[$weekend]!='No Entry') && !in_array($weekend,$saved_timesheet_date_array)) + { + $weekend_array[$weekend] = 'Weekend'; + } + } + + //combine all holidays , leaves, weekends + $hol_leav_weknd = array(); + $hol_leav_weknd = array_merge($holidays,$employee_leave_days,$empWeekends); + + //remove holidays,weekend,leaves from between days + $working_days = array_diff($weekDatesArray, $hol_leav_weknd); + $emptyDataDatesArray = array(); + $holiday_timesheets = array_diff($working_days,$timesheet_date_array); + $emptyDataDatesArray = array_merge($holiday_timesheets,$saved_timesheet_date_array); + $holiday_ts_array = array(); + foreach($holiday_timesheets as $holidayts) + { + $holiday_ts_array[$holidayts] = 'No Entry'; + } + $final_array = array_merge($savedTimeSheetArray,$holiday_ts_array,$savedTimeSheetblckedArray,$holidaysStatusArray,$employee_leave_ts_array,$weekend_array); + + + $final_holadys_removed_array = array(); + foreach($final_array as $finalkey => $finalstatus) + { + if(!(in_array($finalkey,$hol_leav_weknd) && $final_array[$finalkey] == 'No Entry')) + { + $final_holadys_removed_array[$finalkey] = $finalstatus; + } + } + $final_display_array[$weekno] = $final_holadys_removed_array; + } + } + return $final_display_array; + } + /** * This method returns all projects under client * diff --git a/application/modules/timemanagement/models/Projecttasks.php b/application/modules/timemanagement/models/Projecttasks.php index ec56ce132..32e04f9c9 100644 --- a/application/modules/timemanagement/models/Projecttasks.php +++ b/application/modules/timemanagement/models/Projecttasks.php @@ -41,6 +41,7 @@ public function getProjectTasksData($projectId){ ->joinLeft(array('et'=>'tm_emp_timesheets'),'et.project_task_id = pt.id AND et.is_active = 1',array()) ->where('pt.is_active = 1 AND pt.project_id = '.$projectId.'') ->order("pt.modified DESC"); + //echo $select; //exit; $res = $this->fetchAll($select)->toArray(); if (isset($res) && !empty($res)) { @@ -88,10 +89,15 @@ public function getGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$dashboardc } $objName = 'projecttasks'; - $projectModel = new Timemanagement_Model_Projects(); + + $projectModel = new Timemanagement_Model_Projects(); $projectData = $projectModel->getSingleProjectData($a); - $tableFields = array('task' => 'Name','actual_hrs' => 'Actual Hours','viewresources'=>''); + $currencyCode = (isset($projectData[0]['currencycode']))?$projectData[0]['currencycode']:''; + + $tableFields = array('task' => 'Name','estimated_hrs' => 'Estimated Hours','billable_rate' => 'Billable Rate ('.$currencyCode.')','actual_hrs' => 'Actual Hours','viewresources'=>''); + $tablecontent = $this->getProjectTaskData($sort, $by, $pageNo, $perPage,$searchQuery,$a,$having); + $dataTmp = array( 'sort' => $sort, 'by' => $by, @@ -128,7 +134,7 @@ public function getProjectTaskData($sort, $by, $pageNo, $perPage,$searchQuery,$a ->where($where) ->order("$by $sort") ->limitPage($pageNo, $perPage) - ->group(array('tpt.id')); + ->group(array('tpt.id')); //echo $projectTaskData;exit; if($having != ''){ $projectTaskData->having("$having"); @@ -154,9 +160,9 @@ public function getTasks($projectId,$projectTaskId) $db = Zend_Db_Table::getDefaultAdapter(); $select = $this->select() ->setIntegrityCheck(false) - ->from(array('tpte'=>'tm_project_tasks')) + ->from(array('tpte'=>'tm_project_tasks'),array('tpte.is_billable','tpte.estimated_hrs')) ->joinInner(array('tt'=>'tm_tasks'),"tt.id = tpte.task_id",array('tt.task')) - ->where( 'tpte.project_id='.$projectId.' and tpte.task_id='.$projectTaskId.''); + ->where('tpte.is_active=1 and tpte.project_id='.$projectId.' and tpte.task_id='.$projectTaskId.''); return $this->fetchAll($select)->toArray(); } //function to get tasks resources @@ -255,6 +261,8 @@ public function getEmpTaskGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$das { if($key == 'task'){ $searchQuery .= " tt.".$key." like '%".$val."%' AND "; + }else if($key == 'estimated_hrs'){ + $searchQuery .= " tpt.".$key." like '%".$val."%' AND "; }else if($key == 'actual_hrs'){ $having = " ".$key." like '%".$val."%' "; }else{ @@ -270,8 +278,10 @@ public function getEmpTaskGrid($sort,$by,$perPage,$pageNo,$searchData,$call,$das $objName = 'leadprojects'; } - $tableFields = array('task' => 'Name','actual_hrs' => 'Actual Hours'); + $tableFields = array('task' => 'Name','estimated_hrs' => 'Estimated Hours','actual_hrs' => 'Actual Hours'); + $tablecontent = $this->getProjectEmpTaskData($sort, $by, $pageNo, $perPage,$searchQuery,$a,$loginUserId,$having); + $dataTmp = array( 'sort' => $sort, 'by' => $by, @@ -298,9 +308,10 @@ public function getProjectEmpTaskData($sort, $by, $pageNo, $perPage,$searchQuery if($searchQuery) $where .= " AND ".$searchQuery; $db = Zend_Db_Table::getDefaultAdapter(); + $empTaskData = $this->select() ->setIntegrityCheck(false) - ->from(array('tpe'=>'tm_project_task_employees'),array('tt.task','actual_hrs'=>new Zend_Db_Expr("IF(et.week_duration is null,'',time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i' ))"))) + ->from(array('tpe'=>'tm_project_task_employees'),array('tt.task','tpt.estimated_hrs','actual_hrs'=>new Zend_Db_Expr("IF(et.week_duration is null,'',time_format(SEC_TO_TIME(sum(TIME_TO_SEC(cast(et.week_duration as time)))),'%H:%i' ))"))) ->joinINNER(array('tt'=>'tm_tasks'),'tpe.task_id=tt.id',array()) ->joinINNER(array('tpt'=>'tm_project_tasks'),'tpe.project_task_id = tpt.id',array()) ->joinLeft(array('et'=>'tm_emp_timesheets'),'et.project_task_id = tpt.id AND et.is_active = 1',array()) @@ -312,6 +323,7 @@ public function getProjectEmpTaskData($sort, $by, $pageNo, $perPage,$searchQuery if($having != ''){ $empTaskData->having("$having"); } + //echo $empTaskData;exit; return $empTaskData; } diff --git a/application/modules/timemanagement/models/Reports.php b/application/modules/timemanagement/models/Reports.php index f53075a41..d0b5b3bc5 100644 --- a/application/modules/timemanagement/models/Reports.php +++ b/application/modules/timemanagement/models/Reports.php @@ -93,11 +93,11 @@ public function getEmployeeReportsbyProjectId($sort, $by, $perPage, $pageNo, $se $objName = 'reports'; - + //email,phone_no,poc,address,country_id,state_id,created_by $tableFields = array( - + //'action'=>'Action', 'userfullname' => 'Employee', - + //'project_type' => 'Project Type', 'duration' => 'Hours', ); @@ -145,7 +145,7 @@ public function getEmployeeReportsData($sort, $by, $pageNo, $perPage, $searchQue { if($end_date == "") { - + //$end_date = date('%Y-%m-%d %H:%i:%s'); $end_date = date('%Y-%m-%d'); } $start_dates=strtotime($start_date); @@ -221,7 +221,11 @@ public function getEmployeeReportsData($sort, $by, $pageNo, $perPage, $searchQue $duration_sort = "SUM(TIME_TO_SEC(et.week_duration))"; } - + // if($param!="" && $param!="undefined" && $param!="Today" && $param!="Last 7 days") + // { + // $andwhere = " AND et.ts_year = ".$sd_year." AND et.ts_month >= ".$sd_month." AND et.ts_month <= ".$sd_month; + // } + // $andwhere = " AND et.created BETWEEN STR_TO_DATE('".$start_date."','%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('".$end_date."','%Y-%m-%d %H:%i:%s')"; } if($searchQuery){ @@ -235,7 +239,7 @@ public function getEmployeeReportsData($sort, $by, $pageNo, $perPage, $searchQue $db = Zend_Db_Table::getDefaultAdapter(); $select = $this->select() ->setIntegrityCheck(false) - ->from(array('et' => 'tm_emp_timesheets'),array('e.userfullname','userId'=>'et.emp_id', + ->from(array('et' => 'tm_emp_timesheets'),array('e.userfullname','p.project_type','userId'=>'et.emp_id', 'duration'=>$duration,'duration_sort'=>$duration_sort)) ->joinInner(array('pt'=>'tm_project_tasks'), 'pt.id = et.project_task_id',array()) ->joinInner(array('p'=>'tm_projects'), 'p.id = pt.project_id',array()) @@ -244,7 +248,7 @@ public function getEmployeeReportsData($sort, $by, $pageNo, $perPage, $searchQue ->order("$by $sort") ->group('et.emp_id') ->limitPage($pageNo, $perPage); - + //echo $select; return $select; } @@ -268,10 +272,11 @@ function getProjectReportsbyEmployeeId($sort, $by, $perPage, $pageNo, $searchDat $objName = 'reports'; - + //email,phone_no,poc,address,country_id,state_id,created_by $tableFields = array( - + //'action'=>'Action', 'project_name' => 'Project', + 'project_type' => 'Project Type', 'duration' => 'Hours', ); @@ -308,7 +313,7 @@ function getProjectReportsData($sort, $by, $pageNo, $perPage, $searchQuery, $sta { if($end_date == "") { - + //$end_date = date('%Y-%m-%d %H:%i:%s'); $end_date = date('%Y-%m-%d'); } $start_dates=strtotime($start_date); @@ -322,7 +327,7 @@ function getProjectReportsData($sort, $by, $pageNo, $perPage, $searchQuery, $sta $duration=""; $duration_sort =""; - + //$andwhere = " AND et.created BETWEEN STR_TO_DATE('".$start_date."','%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('".$end_date."','%Y-%m-%d %H:%i:%s')"; if($param=="" || $param=="undefined" || $param=="Last 7 days") { $duration = "CONCAT(FLOOR(SUM( TIME_TO_SEC( IF(sun_date BETWEEN '".$start_date."' AND '".$end_date."',sun_duration,'00:00')) + @@ -394,22 +399,24 @@ function getProjectReportsData($sort, $by, $pageNo, $perPage, $searchQuery, $sta { $andwhere .= ' AND et.emp_id = '.$empid; } - - + //'duration'=>'concat(floor(SUM( TIME_TO_SEC( et.week_duration ))/3600),":",lpad(floor(SUM( TIME_TO_SEC( et.week_duration ))/60)%60,2,"0"))' + //'SUM(TIME_TO_SEC(et.week_duration))' $select = $this->select() ->setIntegrityCheck(false) - ->from(array('et' => 'tm_emp_timesheets'),array('p.project_name','p.id', + ->from(array('et' => 'tm_emp_timesheets'),array('p.project_name','proj_category'=>'p.project_type','p.id','project_type'=>'IF(p.project_type="billable","Billable",IF(p.project_type="non_billable","Non billable","Revenue generation"))', 'duration'=>$duration,'duration_sort'=>$duration_sort)) ->joinInner(array('pt'=>'tm_project_tasks'), 'pt.id = et.project_task_id',array()) ->joinInner(array('p'=>'tm_projects'), 'p.id = pt.project_id and p.id = et.project_id',array()) ->joinInner(array('e'=>'main_employees_summary'), 'e.user_id = et.emp_id',array()) ->joinLeft(array('pm'=>'tm_project_employees'), 'p.id = pm.project_id and pm.emp_id = et.emp_id ',array()) - + //->joinLeft(array('pm'=>new Zend_Db_Expr('(SELECT project_id,GROUP_CONCAT(emp_id) as manager_ids FROM tm_project_employees + //WHERE is_active=1 and emp_type = \'manager\' GROUP BY project_id)')), 'pm.project_id = pt.project_id',array()) ->where('et.is_active=1 '.$andwhere) ->order("$by $sort") ->group('p.id') ->limitPage($pageNo, $perPage); + //echo $select;//exit; return $select; } public function getEmpProjDuration($empId,$start_date,$end_date,$project_id,$param) @@ -419,7 +426,7 @@ public function getEmpProjDuration($empId,$start_date,$end_date,$project_id,$par { if($end_date == "") { - + //$end_date = date('%Y-%m-%d %H:%i:%s'); $end_date = date('%Y-%m-%d'); } $start_dates=strtotime($start_date); @@ -432,7 +439,7 @@ public function getEmpProjDuration($empId,$start_date,$end_date,$project_id,$par $duration=""; $andwhere = " AND et.ts_year >= ".$sd_year." AND et.ts_year <=".$ed_year." AND et.ts_month >= ".$sd_month." AND et.ts_month <= ".$ed_month; - + //$andwhere = " AND et.created BETWEEN STR_TO_DATE('".$start_date."','%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('".$end_date."','%Y-%m-%d %H:%i:%s')"; if($param=="" || $param=="undefined" || $param=="Last 7 days") { @@ -492,7 +499,7 @@ public function getEmpProjDuration($empId,$start_date,$end_date,$project_id,$par ->joinInner(array('p'=>'tm_projects'), 'p.id = et.project_id',array()) ->where('et.is_active=1 and p.is_active = 1 '.$andwhere.' and et.emp_id = '.$empId) ->group('et.project_id'); - + // echo $select; return $this->fetchAll($select)->toArray(); } public function getProjTaskDuration($empId,$start_date,$end_date,$project_id,$param) @@ -502,7 +509,7 @@ public function getProjTaskDuration($empId,$start_date,$end_date,$project_id,$pa { if($end_date == "") { - + //$end_date = date('%Y-%m-%d %H:%i:%s'); $end_date = date('%Y-%m-%d'); } $start_dates=strtotime($start_date); @@ -515,7 +522,7 @@ public function getProjTaskDuration($empId,$start_date,$end_date,$project_id,$pa $andwhere = " AND et.ts_year >= ".$sd_year." AND et.ts_year <=".$ed_year." AND et.ts_month >= ".$sd_month." AND et.ts_month <= ".$ed_month; - + //$andwhere = " AND et.created BETWEEN STR_TO_DATE('".$start_date."','%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('".$end_date."','%Y-%m-%d %H:%i:%s')"; $duration=""; if($param=="" || $param=="undefined" || $param=="Last 7 days") { @@ -584,7 +591,7 @@ public function getProjTaskDuration($empId,$start_date,$end_date,$project_id,$pa ->joinLeft(array('pm'=>'tm_project_employees'), 'p.id = pm.project_id and pm.emp_id = et.emp_id ',array()) ->where('et.is_active=1 and p.id='.$project_id.' '.$andwhere) ->group('t.id'); - + //echo $select;//exit; return $this->fetchAll($select)->toArray(); } } \ No newline at end of file diff --git a/application/modules/timemanagement/models/Timesheetstatus.php b/application/modules/timemanagement/models/Timesheetstatus.php index 5204885d1..c0dd01bb9 100644 --- a/application/modules/timemanagement/models/Timesheetstatus.php +++ b/application/modules/timemanagement/models/Timesheetstatus.php @@ -31,11 +31,11 @@ public function getEachDayTsDateCron($empid,$cal_weekArray,$yearArray) } $select = $this->select() ->setIntegrityCheck(false) - ->from(array('t' => 'tm_ts_status'), array('ts_week_dates'=>"concat(concat(sun_date,'#',IFNULL(sun_status,'NULL')),'$',concat(mon_date,'#',IFNULL(mon_status,'NULL')),'$',concat(tue_date,'#',IFNULL(tue_status,'NULL')),'$',concat(wed_date,'#',IFNULL(wed_status,'NULL')),'$',concat(thu_date,'#',IFNULL(thu_status,'NULL')),'$',concat(fri_date,'#',IFNULL(fri_status,'NULL')),'$',concat(sat_date,'#',IFNULL(sat_status,'NULL')))")) + ->from(array('t' => 'tm_ts_status'), array('ts_week_dates'=>"group_concat(concat(sun_date,'#',IFNULL(sun_status,'NULL')),'$',concat(mon_date,'#',IFNULL(mon_status,'NULL')),'$',concat(tue_date,'#',IFNULL(tue_status,'NULL')),'$',concat(wed_date,'#',IFNULL(wed_status,'NULL')),'$',concat(thu_date,'#',IFNULL(thu_status,'NULL')),'$',concat(fri_date,'#',IFNULL(fri_status,'NULL')),'$',concat(sat_date,'#',IFNULL(sat_status,'NULL')))")) ->where("t.emp_id=".$empid." AND t.is_active=1 AND (".$where.")") ->group('t.ts_month'); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } @@ -47,7 +47,7 @@ public function getTsRecordExists($empid,$ts_year,$ts_month,$ts_week,$cal_week) ->where("t.emp_id=".$empid." AND t.is_active=1 AND t.ts_year=".$ts_year." AND t.ts_month=".$ts_month." AND t.ts_week=".$ts_week." AND t.cal_week=".$cal_week." ") ->group('t.emp_id'); - + //echo $select;exit; return $this->fetchAll($select)->toArray(); } diff --git a/application/modules/timemanagement/models/Users.php b/application/modules/timemanagement/models/Users.php index f5e7d2e9c..13344a0cb 100644 --- a/application/modules/timemanagement/models/Users.php +++ b/application/modules/timemanagement/models/Users.php @@ -33,13 +33,8 @@ public function getUserTimemanagementRole($userId){ }else{ $tmRole[0]['tm_role'] = 'Admin'; } - if(isset($tmRole)) - { - return $tmRole[0]['tm_role']; - }else{ - return array(); - } - + + return $tmRole[0]['tm_role']; } public function getEmployees($empType) { @@ -50,7 +45,7 @@ public function getEmployees($empType) { ->joinInner(array('p'=>'main_privileges'),"p.role = u.emprole",array()) ->joinInner(array('m'=>'main_menu'),"m.id = p.object",array()) ->where(" m.menuName = '".$empType."' and m.parent=(select id from main_menu where menuName ='Time Management' and isactive = 1)"); - + //echo $select;exit; $employees = $this->fetchAll($select)->toArray(); return $employees; @@ -75,7 +70,7 @@ public function getEmployeeHolidaysNWeekends($empId,$year,$month,$calWeek="") { ->from(array('s'=>'main_employees_summary'), array('date_of_joining','m.weekend_startday','m.weekend_endday','holiday_names'=>'GROUP_CONCAT(h.holidayname)' , 'holiday_dates'=>'GROUP_CONCAT(h.holidaydate)')) - ->joinInner(array('m'=>'main_leavemanagement'),"m.department_id = s.department_id",array()) + ->joinInner(array('m'=>'main_leavemanagement'),"m.department_id = s.department_id and m.isactive=1",array()) ->joinLeft(array('h'=>'main_holidaydates'),"h.groupid = s.holiday_group and h.isactive=1 and YEAR(holidaydate) = '".$year."' ".$where." ",array()) ->where(" s.user_id = '".$empId."'"); //echo $select; @@ -84,6 +79,22 @@ public function getEmployeeHolidaysNWeekends($empId,$year,$month,$calWeek="") { return $result; } + //function to get approval details + public function getEmpApprovalStatusDteails($emp_id) + { + $select = $this->select() + ->setIntegrityCheck(false) + ->from(array('t' => 'tm_process_updates'),array('ts_date'=>'t.ts_dates','approved_date'=>'date_format(t.created,"%Y-%m-%d")')) + ->where("t.action_type = 'approved' AND t.alert = 'open' AND t.emp_id = '".$emp_id."' ") + ->order("t.ts_dates DESC"); + return $this->fetchAll($select)->toArray(); + } + //function to update notification alert as closed + public function addOrUpdateTstatusData($employee_id) + { + $db = Zend_Db_Table::getDefaultAdapter(); + $db->query("UPDATE tm_process_updates SET alert='closed' , modified=NOW() WHERE action_type='approved' AND emp_id = ".$employee_id); + } //function to fetch all employees who reports @@ -99,8 +110,9 @@ public function getEmployeesReportingTo($reportingToId,$cron_run_day) { ->joinInner(array('g'=>'main_groups'),"g.id = r.group_id",array()) ->joinInner(array('d'=>'main_departments'),"d.id = u.department_id",array()) ->joinInner(array('tz'=>'main_timezone'),"tz.id = d.timezone",array()) - ->where("u.reporting_manager = '".$reportingToId."'"); - + ->where("u.isactive=1 and u.reporting_manager = '".$reportingToId."'"); + //->having('emp_cur_day = "'.$cron_run_day.'"'); + //echo $select;exit; $employeesReported = $this->fetchAll($select)->toArray(); return $employeesReported; @@ -115,7 +127,7 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem if($hidemp != '' && $hidstartweek_date != '' && $hidendweek_date != '') { //To get days in the week/month - $weekDatesArray = sapp_Global::createDateRangeArray($hidstartweek_date,$hidendweek_date); //echo + $weekDatesArray = sapp_Global::createDateRangeArray($hidstartweek_date,$hidendweek_date); //echo '
    ';print_r($weekDatesArray);
     			//End
     
     			$submittedtsdates = $holDates = $weekendDates = $leaveDates = array();
    @@ -139,14 +151,14 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem
     				}
     				$loopDate = date ("Y-m-d", strtotime("+1 day", strtotime($loopDate)));
     			}
    -			
    +			//$cal_week = strftime('%U',strtotime($hidstartweek_date));
     
     			$startDateYear = $startdateObj->format("Y");
     
     			/*submitted and approved status dates in a date range*/
     			//To get dates of timesheet filled by user of the given duration
     			$tsStatus_model = new Timemanagement_Model_Timesheetstatus();
    -			$resultData = $tsStatus_model->getEachDayTsDateCron($hidemp,$cal_weekArray,$yearCalWeekArray); 
    +			$resultData = $tsStatus_model->getEachDayTsDateCron($hidemp,$cal_weekArray,$yearCalWeekArray); //echo '
    '; print_r($resultData);exit;
     			$ts_filled_dates = array();
     			if(!empty($resultData)){
     				foreach($resultData as $resData){
    @@ -157,9 +169,13 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem
     							$ts_day_Array = explode('#',$ts_day);
     							if(in_array($ts_day_Array[0],$weekDatesArray)){
     								if($ts_day_Array[1] == 'submitted' || $ts_day_Array[1] == 'approved'){
    -									
    +									/*if(!empty($submittedtsdates)){
    +										if(in_array($ts_day_Array[0],$submittedtsdates)){
    +											continue;
    +										}
    +									}else{*/
     										$submittedtsdates[] = $ts_day_Array[0]; //$ts_day_Array[0] is ts status date
    -									
    +									//}
     								}
     							}
     						}
    @@ -183,7 +199,7 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem
     				}
     			}
     			//End
    -			
    +			//echo '$emp_dept_id---'.$emp_dept_id.'
    '; //To get Leaves applied by user for the given duration $empLeaves = $this->getEmpLeaves($hidemp,$hidstartweek_date,$hidendweek_date); if(!empty($empLeaves)){ @@ -201,7 +217,7 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem if($emp_dept_id !='' && $emp_dept_id != NULL){ $weekendDetailsArr = $this->getWeekend($hidstartweek_date, $hidendweek_date, $emp_dept_id); } - + //print_r($weekendDetailsArr);exit; //End @@ -235,11 +251,11 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem $totalDaysArray = array(); $totalDaysArray = array_merge($submittedtsdates,$holDates,$leaveDates,$weekendDates); - + //print_r($totalDaysArray); $emptyDataDatesArray = array(); $emptyDataDatesArray = array_diff($weekDatesArray,$totalDaysArray); - + //echo '
    ';print_r($emptyDataDatesArray);exit;
     			if(count($emptyDataDatesArray)>0)
     			{
     				$newemptyDataDatesArray=array();
    @@ -247,12 +263,12 @@ public function checkweekdaysdatacron($hidstartweek_date,$hidendweek_date,$hidem
     				{
     					if($edate>=$empJoiningDate)
     					$newemptyDataDatesArray[]=$edate;
    -				} 
    +				} //print_r($newemptyDataDatesArray);exit;
     				return $newemptyDataDatesArray;
     			}
     			else
     			return array();
    -			
    +			// echo "
    ";print_r($emptyDataDatesArray);exit;
     		}
     	}
     
    @@ -288,9 +304,9 @@ public function getEmpLeaves($empid,$startday,$endday,$flag='')
     		->setIntegrityCheck(false)
     		->from(array('el' => 'main_leaverequest'),
     		array('from_date'=>'date_format(el.from_date,"%Y-%m-%d")','to_date'=>'date_format(el.to_date,"%Y-%m-%d")','leavetypeid'=>'el.leavetypeid','leavestatus'=>'el.leavestatus','leaveday'=>'el.leaveday','leave_req_id'=>'el.id'))
    -	
    +	//	->where("el.isactive=1 AND el.user_id=".$empid." AND el.leavestatus IN ('Approved','Pending for approval') AND  ((el.from_date >= '".$startday."' AND el.from_date <= '".$endday."') OR (el.to_date >= '".$startday."' AND el.to_date <= '".$endday."')) ");
     		->where("$where  el.isactive=1 AND el.user_id=".$empid." AND el.leavestatus IN ('Approved','Pending for approval') AND  ((el.from_date >= '".$startday."' AND el.from_date <= '".$endday."') OR (el.to_date >= '".$startday."' AND el.to_date <= '".$endday."')) ");
    -	
    +		//echo $select;	
     		return $this->fetchAll($select)->toArray();
     	}
     
    @@ -305,13 +321,28 @@ public function getManagers()
           ELSE 'Employee' END END)"),'u.userfullname','u.emailaddress','u.employeeId'))
     		->joinInner(array('r'=>'main_roles'),"r.id = u.emprole",array())
     		->joinInner(array('g'=>'main_groups'),"g.id = r.group_id",array())
    +		->where("u.isactive=1")
     		->group("u.user_id")
     		->having("tm_role = 'Manager'");;
     
     		return $this->fetchAll($select)->toArray();
     	}
     
    -	
    +	/*public function checkTmEnable()
    +	{
    +		$select = $this->select()
    +		->setIntegrityCheck(false)
    +		->from(array('m' => 'main_menu'),array())
    +		->where("m.isactive=1 AND m.url='/timemanagement'");
    +
    +		$result = $this->fetchAll($select)->toArray();
    +
    +		if(count($result) > 0){
    +			return true;
    +		}else{
    +			return false;
    +		}
    +	}*/
     	public function checkTmEnable()
     	{
     		$select = "select * from main_menu where isactive=1 AND url='/timemanagement'";
    diff --git a/application/modules/timemanagement/views/scripts/configuration/add.phtml b/application/modules/timemanagement/views/scripts/configuration/add.phtml
    new file mode 100644
    index 000000000..9dc0d0a83
    --- /dev/null
    +++ b/application/modules/timemanagement/views/scripts/configuration/add.phtml
    @@ -0,0 +1,137 @@
    +.
    + *
    + *  Sentrifugo Support 
    + ********************************************************************************/
    +?>
    +
    +nodata != '')
    +{
    +?>
    +
    +
    + Configuration already configured. +
    +form);?> + + +
    + form->id; ?> +
    + +
    + +
    form->timeformatid; ?> + + + msgarray['ts_weekly_reminder_day'])){?> + msgarray['ts_weekly_reminder_day'];?> + +
    +
    + +
    + +
    form->ts_block_dates_range; ?> + msgarray['ts_block_dates_range'])){?> + msgarray['ts_block_dates_range'];?> + +
    +
    + +
    +
    Weekly Submission Reminder: Set a day in a week for mailing weekly reminders to notify your employees about sending their timesheets for approval.
    +
    Timesheet Blocking Range: Set monthly timesheet blocking range

    + +1st - End of month +
      +
    1. By the end of every month, all employees must submit their timesheets
    2. +
    3. Two days of grace period i.e. 1st and 2nd of the next month, is provided to the employees to submit their timesheets. On 2nd of every month, a notification will be sent as a reminder about blocking the timesheet.
    4. +
    5. On 3rd of every month, if the employees have not submitted their timesheets, their previous month's timesheet will be blocked.
    6. +
    +26th previous month - 25th next month +
      +
    1. By 25th of every month, all employees must submit their timesheets.
    2. +
    3. Two days of grace period i.e. 27th and 28th of the next month, is provided to the employees to submit their timesheets. On 27th of every month, a notification will be sent as a reminder about blocking the timesheet.
    4. +
    5. On 28th of every month, if the employees have not submitted their timesheets, their previous month's timesheet will be blocked.
    6. +
    +
    +
    + +
    + form->submit; ?> + +
    +
    + + + +
    + diff --git a/application/modules/timemanagement/views/scripts/configuration/index.phtml b/application/modules/timemanagement/views/scripts/configuration/index.phtml new file mode 100644 index 000000000..d4a2a9ed9 --- /dev/null +++ b/application/modules/timemanagement/views/scripts/configuration/index.phtml @@ -0,0 +1,113 @@ +. + * + * Sentrifugo Support + ********************************************************************************/ +?> + +sess_values; + +if (count($this->messages)) {?> +
    +messages as $message) + { + $flag = array(); + $flag = array_keys($message); + echo "
    "; + echo $message[$flag[0]]; + echo "
    "; + } +?> +
    + + + +dataArray)){?> + +
    +
    +
    Configuration is not yet set. + Click here to add the Configuration +
    + + +
    +admin == 'Yes') +{ + $weekArray = array('sun'=>'Sunday','mon'=>'Monday','tue'=>'Tuesday','wed'=>'Wednesday','thu'=>'Thursday','fri'=>'Friday','sat'=>'Saturday'); +?> + +
    Configuration +
    + + + +
    +
    + +
    + + + + + + + + + + + +
    Weekly Submission ReminderdataArray[0]['ts_weekly_reminder_day'])]; ?>
    Timesheet Blocking RangedataArray[0]['ts_block_dates_range']) == '26-25')?'26th previous month - 25th next month':'1st - End of month'; ?>
    +
    +
    +
    Weekly Submission Reminder: Set a day in a week for mailing weekly reminders to notify your employees about sending their timesheets for approval.
    +
    Timesheet Blocking Range: Set monthly timesheet blocking range

    + 1st - End of month +
      +
    1. By the end of every month, all employees must submit their timesheets
    2. +
    3. Two days of grace period i.e. 1st and 2nd of the next month, is provided to the employees to submit their + timesheets. On 2nd of every month, a notification will be sent as a reminder about blocking the timesheet.
    4. +
    5. On 3rd of every month, if the employees have not submitted their timesheets, their previous month's timesheet will be blocked.
    6. +
    + 26th previous month - 25th next month +
      +
    1. By 25th of every month, all employees must submit their timesheets.
    2. +
    3. Two days of grace period i.e. 27th and 28th of the next month, is provided to the employees to submit their timesheets. On 27th of every month, a notification will be sent as a reminder about blocking the timesheet.
    4. +
    5. On 28th of every month, if the employees have not submitted their timesheets, their previous month's timesheet will be blocked.
    6. +
    +
    +
    +
    + +
    + \ No newline at end of file diff --git a/application/modules/timemanagement/views/scripts/employeeprojects/view.phtml b/application/modules/timemanagement/views/scripts/employeeprojects/view.phtml index e93a3d421..f78de2485 100644 --- a/application/modules/timemanagement/views/scripts/employeeprojects/view.phtml +++ b/application/modules/timemanagement/views/scripts/employeeprojects/view.phtml @@ -35,14 +35,19 @@ else { $data = $this->data; $projectStatusArray = array('initiated'=>'Initiated','draft'=>'Draft','in-progress'=>'In Progress','hold'=>'Hold','completed'=>'Completed'); -?> + + ?> + +
    +
    Project Details
    -
    +
    +
    @@ -56,9 +61,21 @@ $projectStatusArray = array('initiated'=>'Initiated','draft'=>'Draft','in-progre - + + + + + + + + + + + + +
    Description Project statusProject status
    Start DateEnd Date
    Estimated Hours
    diff --git a/application/modules/timemanagement/views/scripts/emptimesheets/accordion.ajax.phtml b/application/modules/timemanagement/views/scripts/emptimesheets/accordion.ajax.phtml index 9ecf8f471..9c64b60f7 100644 --- a/application/modules/timemanagement/views/scripts/emptimesheets/accordion.ajax.phtml +++ b/application/modules/timemanagement/views/scripts/emptimesheets/accordion.ajax.phtml @@ -36,6 +36,7 @@ if('page;?>'==1 && '' == '0') $('#idhidweek_ac').val(''); }); +
    @@ -43,13 +44,10 @@ if('page;?>'==1 && '' == '0')
    - for_approvalyet_to_submitno_entry"> + for_approvalrejectedapprovedblockedyet_to_submitno_entry"> @@ -67,11 +65,24 @@ if('page;?>'==1 && '' == '0')
    +
    diff --git a/application/modules/timemanagement/views/scripts/emptimesheets/displayweeks.ajax.phtml b/application/modules/timemanagement/views/scripts/emptimesheets/displayweeks.ajax.phtml index 5478e8535..659d0b68d 100644 --- a/application/modules/timemanagement/views/scripts/emptimesheets/displayweeks.ajax.phtml +++ b/application/modules/timemanagement/views/scripts/emptimesheets/displayweeks.ajax.phtml @@ -19,17 +19,19 @@ $(document).ready(function(){ selWeek; - + //$nextMonth = $selectedYrMon[1]+1; if($selectedYrMon[1] < 12) $nextMonth = $selectedYrMon[1]+1; else @@ -38,6 +40,9 @@ $(document).ready(function(){ DateInterval::createFromDateString('next sunday'),new DateTime("first day of $selectedYrMon[0]-$nextMonth"))); +// foreach($datesArray as $sunday) { +// //echo $sunday->format("Y-m-d\n"); +// } $firstDay = DateTime::createFromFormat('Y-m-d', "$currentMonth".'-1'); $firstDayName = $firstDay->format('D'); @@ -46,7 +51,7 @@ $(document).ready(function(){ if($hidweek == 1) { $startDate = $currentMonth."-1"; - + //$weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate))); $startDateName = date('D', strtotime($startDate)); if($startDateName != "Sun") { $weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate))); @@ -74,7 +79,7 @@ $(document).ready(function(){ 1) { ?>
    diff --git a/application/modules/timemanagement/views/scripts/emptimesheets/empdisplayweeks.ajax.phtml b/application/modules/timemanagement/views/scripts/emptimesheets/empdisplayweeks.ajax.phtml index 4501cb27d..589eafbc9 100644 --- a/application/modules/timemanagement/views/scripts/emptimesheets/empdisplayweeks.ajax.phtml +++ b/application/modules/timemanagement/views/scripts/emptimesheets/empdisplayweeks.ajax.phtml @@ -31,14 +31,14 @@ $(document).ready(function(){ $selectedYrMon = explode('-', $currentMonth); - + //$selMonName = date('F', mktime(0, 0, 0, $selectedYrMon[1], 10)); $firstday = date("w", mktime(0, 0, 0, $selectedYrMon[1], 1, $selectedYrMon[0])); $lastday = date("t", mktime(0, 0, 0, $selectedYrMon[1], 1, $selectedYrMon[0])); $noOfweeks = 1 + ceil(($lastday-7+$firstday)/7); $selWeek = $this->selWeek; - + //$nextMonth = $selectedYrMon[1]+1; if($selectedYrMon[1] < 12) $nextMonth = $selectedYrMon[1]+1; else @@ -46,7 +46,13 @@ $selectedYrMon = explode('-', $currentMonth); $datesArray = iterator_to_array(new DatePeriod(new DateTime("first sunday of $currentMonth"), DateInterval::createFromDateString('next sunday'),new DateTime("first day of $selectedYrMon[0]-$nextMonth"))); - + //$datesArray = iterator_to_array(new DatePeriod(new DateTime("first sunday of $currentMonth"), + //DateInterval::createFromDateString('next sunday'),new DateTime("last day of $currentMonth"))); + +// foreach($datesArray as $sunday) { +// //echo $sunday->format("Y-m-d\n"); +// } + $firstDay = DateTime::createFromFormat('Y-m-d', "$currentMonth".'-1'); $firstDayName = $firstDay->format('D'); $wCounter = 1; @@ -54,7 +60,7 @@ $selectedYrMon = explode('-', $currentMonth); if($hidweek == 1) { $startDate = $currentMonth."-1"; - + //$weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate))); $startDateName = date('D', strtotime($startDate)); if($startDateName != "Sun") { $weekStartDay = date('F d, Y', strtotime('last sunday', strtotime($startDate))); @@ -85,7 +91,7 @@ $selectedYrMon = explode('-', $currentMonth); 1) { ?> diff --git a/application/modules/timemanagement/views/scripts/emptimesheets/employeetimesheet.phtml b/application/modules/timemanagement/views/scripts/emptimesheets/employeetimesheet.phtml index fd1d43fdd..dfbb5ffc9 100644 --- a/application/modules/timemanagement/views/scripts/emptimesheets/employeetimesheet.phtml +++ b/application/modules/timemanagement/views/scripts/emptimesheets/employeetimesheet.phtml @@ -72,10 +72,13 @@ $(document).ready(function(){
    - +
    - +
    @@ -92,8 +95,8 @@ $(document).ready(function(){
    @@ -185,7 +211,7 @@ $(function() {
    \ No newline at end of file diff --git a/application/modules/timemanagement/views/scripts/index/index.phtml b/application/modules/timemanagement/views/scripts/index/index.phtml index 1e5674ab3..3b62acde6 100644 --- a/application/modules/timemanagement/views/scripts/index/index.phtml +++ b/application/modules/timemanagement/views/scripts/index/index.phtml @@ -21,9 +21,11 @@ ?> format('Y-m-d'); - + //$currentMonth = $now->format('Y-m'); + //echo " DOJ ".$this->empDoj; $empDoj = $this->empDoj; $dateEmpDoj = date('Y-m',strtotime($empDoj)); $empDojDay = intval(date('d',strtotime($empDoj))); @@ -31,6 +33,7 @@ $selYrMon = $this->selYrMon; $currentMonth = $selYrMon; + $approvedAlert = $this->approvedAlert; $cronStartDay = $this->cronStartDay; $cronEndDay = $this->cronEndDay; @@ -44,16 +47,21 @@ var currMonth = ""; var empId = ""; - + // console.log(" currMonth "+currMonth); + //console.log($("#calSelYrMonth").val()); $(document).ready(function () { - $('.breadcrumbs').append("Time Sheet"); + $('.breadcrumbs').append("Timesheet"); $('.hol_leave').powerTip({ placement: 'e', mouseOnToPopup: true, smartPlacement: true }); - + $('.rejected_note').powerTip({ + placement: 'e', + mouseOnToPopup: true, + smartPlacement: true + }); $("#calSelYrMonth").val(currMonth); var empDoj = $('#empDoj').val(); @@ -65,9 +73,9 @@ function contextMenuItems(dayStatus,inactiveClass,weekendClass,leaveDataId) { var menUItems = { - "submit": {name: "Submit Time Sheet"}, - "new": {name: "New Time Sheet"}, - "edit": {name: "Edit Time Sheet"}, + "submit": {name: "Submit Timesheet"}, + "new": {name: "New Timesheet"}, + "edit": {name: "Edit Timesheet"}, "leave": {name: "Mark as Leave"}, "cancelleave": {name: "Cancel Leave"}, }; @@ -86,7 +94,12 @@ } } - + if(dayStatus == 'Rejected' || dayStatus == 'Enabled' ) { + delete menUItems["submit"]; + delete menUItems["new"]; + delete menUItems["leave"]; + delete menUItems["cancelleave"]; + } if(dayStatus == 'Yet to submit') { delete menUItems["new"]; @@ -99,7 +112,11 @@ delete menUItems["cancelleave"]; } } - +// if(dayStatus == 'For Approval') { +// delete menUItems["submit"]; +// delete menUItems["new"]; +// delete menUItems["edit"]; +// } if(inactiveClass){ delete menUItems["submit"]; delete menUItems["edit"]; @@ -138,7 +155,7 @@ if(td_id != undefined){ var day = $(this).children('.date').text(); - if(dayStatus != "Approved" && dayStatus != "Submitted" && dayStatus != "Not Submitted" ) { + if(dayStatus != "Approved" && dayStatus != "For Approval" && dayStatus != "Not Submitted" ) { if(inativeClass && leaveDataId == 'L'){ freezedClass = true; @@ -173,7 +190,36 @@ } }); - + //var mainDivHeight = $(".reports-block-area").height(); + //$('.right_container').height(eval(mainDivHeight-51)); + + /* $(".responsive-calendar").responsiveCalendar({ + time: currMonth, + startFromSunday: true, + allRows: false, + events: { + "":{} + }, + onInit: function() { + + var currYrMon = (this.currentYear)+'-'+(this.currentMonth+1); + $("#calSelYrMonth").val(currYrMon); + }, + onMonthChange: function() { + + var selYrMon = (this.currentYear)+'-'+(this.currentMonth+1); + $("#calSelYrMonth").val(selYrMon); + var selYrMonArray = selYrMon.split("-"); + + var currDt = new Date(); + var currMon = currDt.getMonth(); + if(selYrMonArray[1]< empDojMon+1 || selYrMonArray[1] > currMon+1 ) { + $("#res_div_link").hide(); + } else { + $("#res_div_link").show(); + } + } + }); */ }); @@ -196,31 +242,118 @@
    - +YrMonths; + //$this->empDoj; +?>
    - - + + + + + 0){ + ?> + + +
    Your timesheet has been approved. View Details
    + + + prev_str!=''){ + $prev_str_split=preg_split('/@@@/',$this->prev_str); + ?> + +
    has not been submitted.
    + +
    - + +
      - + empDoj)); + //$empDojMonth = date('m',strtotime($this->empDoj)); + + //$YrMonths = $this->YrMonths; + // $startYrMon = date_create($YrMonths[0].' last month')->format('Y-m'); + // $endYrMon = date_create($YrMonths[3].' next month')->format('Y-m'); + + //echo " selYrMon ".$selYrMon." dateEmpDoj ".$dateEmpDoj; + //if($selYrMon > $dateEmpDoj) { + ?> + + + + + + $now->format('Y-m') ||$val < $dateEmpDoj ) { + ?> + + + + format('Y-m')) { + ?> + + + +
    - + 'no_entry','saved'=>'yet_to_submit', - 'submitted'=>'for_approval'); - $statusText = array('no_entry'=>'No Entry','saved'=>'Yet to submit', - 'submitted'=>'Submitted'); + $statusClasses = array('no_entry'=>'no_entry','saved'=>'yet_to_submit','approved'=>'approved', + 'submitted'=>'for_approval','enabled'=>'enabled','rejected'=>'rejected','blocked'=>'blocked'); + $statusText = array('no_entry'=>'No Entry','saved'=>'Yet to submit','approved'=>'Approved', + 'submitted'=>'For Approval','enabled'=>'Enabled','rejected'=>'Rejected','blocked'=>'Blocked'); $dayCounter = 1; @@ -380,6 +513,7 @@ $currentDayClass = ""; $inactiveDayClass = ""; $blockedDayClass = ""; + $rejectNoteClass = ""; $holName = ""; $holLeaveClass = ""; $curDate = date('Y-m-d',strtotime($cDate)); @@ -397,7 +531,8 @@ if($dayName == $day) { $duration = ($weekData != "")?$weekData[strtolower($dayName).'_duration']:"00:00"; - $status = ($weekData != "")?$weekData[strtolower($dayName).'_status']:'no_entry'; + $status = ($weekData != "")?$weekData[strtolower($dayName).'_status']:'no_entry'; + $rejectNote = ($weekData != "")?$weekData[strtolower($dayName).'_reject_note']:""; $calDate = $selectedYrMon[0].'-'.$selectedYrMon[1].'-'.$dayCounter; //$holiday = (in_array($calDate,$holidayDates))?"H":""; $holiday = (in_array($dayCounter,$holidayDates))?"H":""; @@ -503,10 +638,16 @@
    -
    +
    leaveData = "leave_">
    @@ -529,7 +670,33 @@
    - +
    @@ -820,31 +987,24 @@ $(document).ready(function(){ function markasleave(day){ var selYyrMon = ""; var selYYrMonArray = selYyrMon.split("-"); - if(day.length == 1){ + + if(day.length == 1){ day = '0'+day; } - var selectedStartDates = day+"-"+selYYrMonArray[1]+"-"+selYYrMonArray[0]; - - //changed to convert date as gloabal + + //changed to convert date as gloabal $.ajax({ - type:"post", - data:"day="+day+"&yearmonth="+selectedStartDates, - url:base_url+"/timemanagement/index/converdate/format/json", - dataType:'json', - success: function(response) - { + type:"post", + data:"day="+day+"&yearmonth="+selectedStartDates, + url:base_url+"/timemanagement/index/converdate/format/json", + dataType:'json', + success: function(response) + { validatefullcalenderdate(response.conerteddate,response.conerteddate); - } + } }); - - - - - - - } function validate_todate() diff --git a/application/modules/timemanagement/views/scripts/index/week.phtml b/application/modules/timemanagement/views/scripts/index/week.phtml index aa86671cb..a3942248f 100644 --- a/application/modules/timemanagement/views/scripts/index/week.phtml +++ b/application/modules/timemanagement/views/scripts/index/week.phtml @@ -23,6 +23,7 @@ read(); + $now = new DateTime(); $today = $now->format('Y-m-d'); $empDoj = $this->empDoj; @@ -162,8 +163,8 @@ var menUItems = { // "submit": {name: "Submit Time Sheet"}, - "new": {name: "New Time Sheet"}, - "edit": {name: "Edit Time Sheet"}, + "new": {name: "New Timesheet"}, + "edit": {name: "Edit Timesheet"}, "leave": {name: "Mark as Leave"}, "cancelleave": {name: "Cancel Leave"}, }; @@ -183,7 +184,13 @@ } } - + if(dayStatus == 'Rejected' || dayStatus == 'Enabled' ) { + // delete menUItems["submit"]; + delete menUItems["new"]; + delete menUItems["leave"]; + delete menUItems["cancelleave"]; + + } if(dayStatus == 'Yet to submit') { delete menUItems["new"]; @@ -196,7 +203,10 @@ delete menUItems["cancelleave"]; } } - +// if(dayStatus == 'For Approval') { +// delete menUItems["new"]; +// delete menUItems["edit"]; +// } if(weekendClass) { delete menUItems["leave"]; } @@ -356,7 +366,47 @@ } } }) ; - + + // console.log(" opened "+opened); + // $weekview.find("tr").not('.accordion').hide(); + // $weekview.find("tr").eq(0).show(); + +// $weekview.find(".accordion").click(function(id){ +// $(id).not(this).siblings().fadeOut(1000); +// $(this).siblings().fadeToggle(1000); +// }); + + + //var mainDivHeight = $(".reports-block-area").height(); + // $('.right_container').height(eval(mainDivHeight-51)); + + /* $(".responsive-calendar").responsiveCalendar({ + time: currMonth, + startFromSunday: true, + allRows: false, + events: { + "": {} + }, + onInit: function() { + + var currYrMon = (this.currentYear)+'-'+(this.currentMonth+1); + $("#calSelYrMonth").val(currYrMon); + }, + onMonthChange: function() { + + var selYrMon = (this.currentYear)+'-'+(this.currentMonth+1); + $("#calSelYrMonth").val(selYrMon); + var selYrMonArray = selYrMon.split("-"); + + var currDt = new Date(); + var currMon = currDt.getMonth(); + if(selYrMonArray[1]< empDojMon+1 || selYrMonArray[1] > currMon+1 ) { + $("#res_div_link").hide(); + } else { + $("#res_div_link").show(); + } + } + }); */ }); @@ -366,6 +416,8 @@
    format("Y-m-d\n"); +// } $firstDay = DateTime::createFromFormat('Y-m-d', "$currentMonth".'-1'); $firstDayName = $firstDay->format('D'); @@ -407,9 +461,22 @@ $calWeekNo = strftime('%U',strtotime($weekStartDay)); $weekDaysStatus = $this->weekDaysStatus; - $statusClasses = array('No Entry'=>'no_entry','Yet to submit'=>'yet_to_submit', - 'For Approval'=>'for_approval'); - + $statusClasses = array('No Entry'=>'no_entry','Yet to submit'=>'yet_to_submit','Approved'=>'approved', + 'For Approval'=>'for_approval','Enabled'=>'enabled','Rejected'=>'rejected','Blocked'=>'blocked'); + +// $weekStartDay = $weekendDay + 1; +// $dayName = date('D',mktime(0, 0, 0, $selectedYrMon[1], $weekStartDay)); +// $key = array_keys($weekdays, $dayName); +// if($selWeek == $noOfweeks) { +// +// $dayName = date('D',mktime(0, 0, 0, $selectedYrMon[1], $lastday)); +// $key = array_keys($weekdays, $dayName); +// $weekCounter = $key[0]; +// } else { +// $weekCounter = 7 - ($key[0]+ 1); +// } +// $weekendDay = $weekStartDay + $weekCounter; +// echo " week start : ".$weekStartDay." week end : ".$weekendDay; ?>
    -
    + + + + + + + +
    @@ -514,7 +634,14 @@ $thuDate = date('Y-m-d', strtotime("$weekStartDay +4 day")); $friDate = date('Y-m-d', strtotime("$weekStartDay +5 day")); $satDate = date('Y-m-d', strtotime("$weekStartDay +6 day")); - + +// $sunDisClass = ($selYrMon != date('Y-m',strtotime($sunDay)))? 'dis_pre_mon':""; +// $monDisClass = ($selYrMon != date('Y-m',strtotime($monDay)))? 'dis_pre_mon':""; +// $tueDisClass = ($selYrMon != date('Y-m',strtotime($tueDay)))? 'dis_pre_mon':""; +// $wedDisClass = ($selYrMon != date('Y-m',strtotime($wedDay)))? 'dis_pre_mon':""; +// $thuDisClass = ($selYrMon != date('Y-m',strtotime($thuDay)))? 'dis_pre_mon':""; +// $friDisClass = ($selYrMon != date('Y-m',strtotime($friDay)))? 'dis_pre_mon':""; +// $satDisClass = ($selYrMon != date('Y-m',strtotime($satDay)))? 'dis_pre_mon':""; $sunDisClass = ($selMon != date('m',strtotime($sunDate)))? 'dis_pre_mon':""; $monDisClass = ($selMon != date('m',strtotime($monDate)))? 'dis_pre_mon':""; @@ -658,7 +785,25 @@ $satFreezedClass = "freezed"; } } - + //print_r($leavesArray); +// $weekendDay = 0; + // $weekdays = array( 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); + // for($i = 1; $i <= $noOfweeks; $i++) { + +// $weekStartDay = $weekendDay + 1; +// $dayName = date('D',mktime(0, 0, 0, $selectedYrMon[1], $weekStartDay)); +// $key = array_keys($weekdays, $dayName); +// if($i == $noOfweeks) { +// +// $dayName = date('D',mktime(0, 0, 0, $selectedYrMon[1], $lastday)); +// $key = array_keys($weekdays, $dayName); +// $weekCounter = $key[0]; +// } else { +// $weekCounter = 7 - ($key[0]+ 1); +// } +// $weekendDay = $weekStartDay + $weekCounter; +// echo " week start : ".$weekStartDay." week end : ".$weekendDay; + //$selWeekClass = ($i == $selWeek)? "class='active'":""; ?> @@ -1094,7 +1239,19 @@ Hours - + ".(isset($sun_reject_note) && $sun_reject_note!='')?$sun_reject_note:''.""; + $sun_tdata='data-powertip="'.$sun_span.'"'; + } + $is_mon_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['mon_status']:"No Entry"; + $mon_rej_note=''; + $mon_reject_note=''; + $mon_span=''; + $mon_tdata=''; + if($is_mon_rej=='Rejected') + { + $mon_reject_note = $weekDaysStatus[0]['mon_reject_note']; + $mon_rej_note = 'rejected_note'; + $mon_span = "".(isset($mon_reject_note) && $mon_reject_note!='')?$mon_reject_note:''.""; + $mon_tdata='data-powertip="'.$mon_span.'"'; + } $is_tue_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['tue_status']:"No Entry"; - + $tue_rej_note=''; + $tue_reject_note=''; + $tue_span=''; + $tue_tdata=''; + if($is_tue_rej=='Rejected') + { + $tue_reject_note = $weekDaysStatus[0]['tue_reject_note']; + $tue_rej_note = 'rejected_note'; + $tue_span = "".(isset($tue_reject_note) && $tue_reject_note!='')?$tue_reject_note:''.""; + $tue_tdata='data-powertip="'.$tue_span.'"'; + } $is_wed_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['wed_status']:"No Entry"; - + $wed_rej_note=''; + $wed_reject_note=''; + $wed_span=''; + $wed_tdata=''; + if($is_wed_rej=='Rejected') + { + $wed_reject_note = $weekDaysStatus[0]['wed_reject_note']; + $wed_rej_note = 'rejected_note'; + $wed_span = "".(isset($wed_reject_note) && $wed_reject_note!='')?$wed_reject_note:''.""; + $wed_tdata='data-powertip="'.$wed_span.'"'; + } $is_thu_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['thu_status']:"No Entry"; - + $thu_rej_note=''; + $thu_reject_note=''; + $thu_span=''; + $thu_tdata=''; + if($is_thu_rej=='Rejected') + { + $thu_reject_note = $weekDaysStatus[0]['thu_reject_note']; + $thu_rej_note = 'rejected_note'; + $thu_span = "".(isset($thu_reject_note) && $thu_reject_note!='')?$thu_reject_note:''.""; + $thu_tdata='data-powertip="'.$thu_span.'"'; + } $is_fri_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['fri_status']:"No Entry"; - + $fri_rej_note=''; + $fri_reject_note=''; + $fri_span=''; + $fri_tdata=''; + if($is_fri_rej=='Rejected') + { + $fri_reject_note = $weekDaysStatus[0]['fri_reject_note']; + $fri_rej_note = 'rejected_note'; + $fri_span = "".(isset($fri_reject_note) && $fri_reject_note!='')?$fri_reject_note:''.""; + $fri_tdata='data-powertip="'.$fri_span.'"'; + } $is_sat_rej = (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['sat_status']:"No Entry"; - + $sat_rej_note=''; + $sat_reject_note=''; + $sat_span=''; + $sat_tdata=''; + if($is_sat_rej=='Rejected') + { + $sat_reject_note = $weekDaysStatus[0]['sat_reject_note']; + $sat_rej_note = 'rejected_note'; + $sat_span = "".(isset($sat_reject_note) && $sat_reject_note!='')?$sat_reject_note:''.""; + $sat_tdata='data-powertip="'.$sat_span.'"'; + } ?> - " > + " > = $empDojDate ) echo ($sunStatus == "Blocked")?"Not Submitted": $sunStatus; // echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['sun_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($monStatus == "Blocked")?"Not Submitted": $monStatus; // echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['mon_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($tueStatus == "Blocked")?"Not Submitted": $tueStatus; //echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['tue_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($wedStatus == "Blocked")?"Not Submitted": $wedStatus; // echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['wed_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($thuStatus == "Blocked")?"Not Submitted": $thuStatus; //echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['thu_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($friStatus == "Blocked")?"Not Submitted": $friStatus; // echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['fri_status']:"No Entry"; ?> - " > + " > = $empDojDate ) echo ($satStatus == "Blocked")?"Not Submitted": $satStatus; // echo (sizeof($weekDaysStatus) != 0)?$weekDaysStatus[0]['sat_status']:"No Entry"; @@ -1479,7 +1685,7 @@ : Nothing entered - + - );"> - + - + - +