public function saveAction() { $tasksHrsData = $this->_getParam('data'); $calWeek = $this->_getParam('calWeek'); $week = $this->_getParam('week'); $weekStartDate = $this->_getParam('weekStart'); $weekEndDate = $this->_getParam('weekEnd'); $selYrMon = $this->_getParam('selYrMon'); $tasksData = explode(',', $tasksHrsData); $callval = $this->getRequest()->getParam('call'); $sunNote = $this->_getParam('sun_note'); $monNote = $this->_getParam('mon_note'); $tueNote = $this->_getParam('tue_note'); $wedNote = $this->_getParam('wed_note'); $thuNote = $this->_getParam('thu_note'); $friNote = $this->_getParam('fri_note'); $satNote = $this->_getParam('sat_note'); $weekNote = $this->_getParam('week_note'); $storage = new Zend_Auth_Storage_Session(); $sessionData = $storage->read(); $selYrMonArray = explode('-', $selYrMon); $myTsModel = new Timemanagement_Model_MyTimesheet(); $projTasksArray = array(); $projsArray = array(); $date = new Zend_Date(); $projectId = ''; if ($this->getRequest()->getPost() && $tasksHrsData != '') { foreach ($tasksData as $data) { $taskDataArray = explode('#', $data); $sun_hrs = $taskDataArray[2] != null ? $taskDataArray[2] : 0; $sun_tot = 0; if (!empty($sun_hrs)) { $sun_dur = explode(':', $sun_hrs); $sun_tot += $sun_dur[0] * 60; $sun_tot += $sun_dur[1]; } $mon_hrs = $taskDataArray[3] != null ? $taskDataArray[3] : 0; $mon_tot = 0; if (!empty($mon_hrs)) { $mon_dur = explode(':', $mon_hrs); $mon_tot += $mon_dur[0] * 60; $mon_tot += $mon_dur[1]; } $tue_hrs = $taskDataArray[4] != null ? $taskDataArray[4] : 0; $tue_tot = 0; if (!empty($tue_hrs)) { $tue_dur = explode(':', $tue_hrs); $tue_tot += $tue_dur[0] * 60; $tue_tot += $tue_dur[1]; } $wed_hrs = $taskDataArray[5] != null ? $taskDataArray[5] : 0; $wed_tot = 0; if (!empty($wed_hrs)) { $wed_dur = explode(':', $wed_hrs); $wed_tot += $wed_dur[0] * 60; $wed_tot += $wed_dur[1]; } $thu_hrs = $taskDataArray[6] != null ? $taskDataArray[6] : 0; $thu_tot = 0; if (!empty($thu_hrs)) { $thu_dur = explode(':', $thu_hrs); $thu_tot += $thu_dur[0] * 60; $thu_tot += $thu_dur[1]; } $fri_hrs = $taskDataArray[7] != null ? $taskDataArray[7] : 0; $fri_tot = 0; if (!empty($fri_hrs)) { $fri_dur = explode(':', $fri_hrs); $fri_tot += $fri_dur[0] * 60; $fri_tot += $fri_dur[1]; } $sat_hrs = $taskDataArray[8] != null ? $taskDataArray[8] : 0; $sat_tot = 0; if (!empty($sat_hrs)) { $sat_dur = explode(':', $sat_hrs); $sat_tot += $sat_dur[0] * 60; $sat_tot += $sat_dur[1]; } $week_tot_time = intval($sun_tot) + intval($mon_tot) + intval($tue_tot) + intval($wed_tot) + intval($thu_tot) + intval($fri_tot) + intval($sat_tot); $wkHrsPart = floor($week_tot_time / 60); $wkMinsPart = $week_tot_time % 60; if (strlen($wkHrsPart . '') == 1) { $wkHrsPart = '0' . $wkHrsPart; } if (strlen($wkMinsPart . '') == 1) { $wkMinsPart = '0' . $wkMinsPart; } $week_tot = $wkHrsPart . ':' . $wkMinsPart; array_push($projTasksArray, $taskDataArray[0]); $data = array('emp_id' => $sessionData->id, 'project_task_id' => $taskDataArray[0], 'project_id' => $taskDataArray[1], 'ts_year' => $selYrMonArray[0], 'ts_month' => $selYrMonArray[1], 'ts_week' => $week, 'cal_week' => $calWeek, 'sun_date' => date('Y-m-d', strtotime($weekStartDate)), 'sun_duration' => $taskDataArray[2] != null ? $taskDataArray[2] : '00:00', 'mon_date' => date('Y-m-d', strtotime('+1 day', strtotime($weekStartDate))), 'mon_duration' => $taskDataArray[3] != null ? $taskDataArray[3] : '00:00', 'tue_date' => date('Y-m-d', strtotime('+2 day', strtotime($weekStartDate))), 'tue_duration' => $taskDataArray[4] != null ? $taskDataArray[4] : '00:00', 'wed_date' => date('Y-m-d', strtotime('+3 day', strtotime($weekStartDate))), 'wed_duration' => $taskDataArray[5] != null ? $taskDataArray[5] : '00:00', 'thu_date' => date('Y-m-d', strtotime('+4 day', strtotime($weekStartDate))), 'thu_duration' => $taskDataArray[6] != null ? $taskDataArray[6] : '00:00', 'fri_date' => date('Y-m-d', strtotime('+5 day', strtotime($weekStartDate))), 'fri_duration' => $taskDataArray[7] != null ? $taskDataArray[7] : '00:00', 'sat_date' => date('Y-m-d', strtotime('+6 day', strtotime($weekStartDate))), 'sat_duration' => $taskDataArray[8] != null ? $taskDataArray[8] : '00:00', 'week_duration' => $week_tot, 'created_by' => $sessionData->id, 'is_active' => 1, 'created' => Zend_Registry::get('currentdate')); $checkProjNull = $myTsModel->getProjNullRecordCountInTimeSheet($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week); if ($checkProjNull != 0) { $where = " ts_year = " . $selYrMonArray[0] . " and ts_month = " . $selYrMonArray[1] . " and ts_week = " . $week . " and emp_id = " . $sessionData->id . " and project_id is null"; unset($data['created']); $data['modified'] = Zend_Registry::get('currentdate'); $myTsModel->updateTimesheetRecord($data, $where); } else { $myTsModel->SaveOrUpdateTimesheet($data); } if ($projectId != $taskDataArray[1]) { $projectId = $taskDataArray[1]; array_push($projsArray, $taskDataArray[1]); } } foreach ($projsArray as $proj) { $projHrsData = $myTsModel->getWeekProjectHrs($sessionData->id, $proj, $selYrMonArray[0], $selYrMonArray[1], $week); $statusData = array('emp_id' => $sessionData->id, 'project_id' => $proj, 'ts_year' => $selYrMonArray[0], 'ts_month' => $selYrMonArray[1], 'ts_week' => $week, 'cal_week' => $calWeek, 'sun_date' => date('Y-m-d', strtotime($weekStartDate)), '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'), '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'), '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'), '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'), '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'), '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'), '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'), 'week_status' => $projHrsData[0]['week_duration'] != '00:00' ? 'saved' : 'no_entry', 'created_by' => $sessionData->id, 'is_active' => 1, 'created' => Zend_Registry::get('currentdate')); $checkProjNull = $myTsModel->getProjNullRecordCountInStatus($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week); if ($checkProjNull != 0) { $where = " ts_year = " . $selYrMonArray[0] . " and ts_month = " . $selYrMonArray[1] . " and ts_week = " . $week . " and emp_id = " . $sessionData->id . " and project_id is null"; unset($statusData['created']); $statusData['modified'] = Zend_Registry::get('currentdate'); $myTsModel->updateStatusRecord($statusData, $where); } else { $myTsModel->SaveOrUpdateTimesheetStatus($statusData); } } $notesData = array('emp_id' => $sessionData->id, 'ts_year' => $selYrMonArray[0], 'ts_month' => $selYrMonArray[1], 'ts_week' => $week, 'cal_week' => $calWeek, 'sun_date' => date('Y-m-d', strtotime($weekStartDate)), 'sun_note' => $sunNote, 'mon_date' => date('Y-m-d', strtotime('+1 day', strtotime($weekStartDate))), 'mon_note' => $monNote, 'tue_date' => date('Y-m-d', strtotime('+2 day', strtotime($weekStartDate))), 'tue_note' => $tueNote, 'wed_date' => date('Y-m-d', strtotime('+3 day', strtotime($weekStartDate))), 'wed_note' => $wedNote, 'thu_date' => date('Y-m-d', strtotime('+4 day', strtotime($weekStartDate))), 'thu_note' => $thuNote, 'fri_date' => date('Y-m-d', strtotime('+5 day', strtotime($weekStartDate))), 'fri_note' => $friNote, 'sat_date' => date('Y-m-d', strtotime('+6 day', strtotime($weekStartDate))), 'sat_note' => $satNote, 'week_note' => $weekNote, 'created_by' => $sessionData->id, 'is_active' => 1, 'created' => Zend_Registry::get('currentdate')); $myTsModel->SaveOrUpdateTimesheetNotes($notesData); } $empDeletedTasks = $myTsModel->empployeeDeletedTasks($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week, $calWeek, $projTasksArray); if (is_array($empDeletedTasks)) { foreach ($empDeletedTasks as $taskId) { $deleteTasksData = array('emp_id' => $sessionData->id, 'project_task_id' => $taskId, 'ts_year' => $selYrMonArray[0], 'ts_month' => $selYrMonArray[1], 'ts_week' => $week, 'cal_week' => $calWeek, 'sun_duration' => '00:00', 'mon_duration' => '00:00', 'tue_duration' => '00:00', 'wed_duration' => '00:00', 'thu_duration' => '00:00', 'fri_duration' => '00:00', 'sat_duration' => '00:00', 'week_duration' => '00:00', 'is_active' => 0, 'modified_by' => $sessionData->id, 'modified' => Zend_Registry::get('currentdate')); $myTsModel->deleteTimesheetTask($sessionData->id, $deleteTasksData, $taskId, $selYrMonArray[0], $selYrMonArray[1], $week); } } $empDeletedProjects = $myTsModel->empployeeDeletedProjects($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week, $calWeek, $projsArray); if (is_array($empDeletedProjects)) { foreach ($empDeletedProjects as $projId) { $deleteProjectsData = array('emp_id' => $sessionData->id, 'project_id' => $taskId, 'ts_year' => $selYrMonArray[0], 'ts_month' => $selYrMonArray[1], 'ts_week' => $week, 'cal_week' => $calWeek, 'sun_project_status' => 'no_entry', 'mon_project_status' => 'no_entry', 'tue_project_status' => 'no_entry', 'wed_project_status' => 'no_entry', 'thu_project_status' => 'no_entry', 'fri_project_status' => 'no_entry', 'sat_project_status' => 'no_entry', 'is_active' => 0, 'modified_by' => $sessionData->id, 'modified' => Zend_Registry::get('currentdate')); $myTsModel->deleteWeekProjectStatus($sessionData->id, $deleteProjectsData, $projId, $selYrMonArray[0], $selYrMonArray[1], $week); } } $myTsModel->updateDayStatus($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week); $myTsModel->updateWeekStatus($sessionData->id, $selYrMonArray[0], $selYrMonArray[1], $week); if ($callval == 'ajaxcall') { $this->_helper->layout->disableLayout(); } $this->view->status = 'success'; $this->view->message = 'Time sheet saved successfully.'; }