Ejemplo n.º 1
0
 public function oldmyAttendanceAction()
 {
     $usersNs = new Zend_Session_Namespace("members");
     $userId = $usersNs->userId;
     $model1 = new Application_Model_User();
     $model = $model1->find($userId);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/employees'));
     }
     $this->view->user = $model;
     $request = $this->getRequest();
     $form = new Application_Form_Attendance();
     $form->removeElement("attendanceSheet");
     $form->clearDecorators();
     $elements = $form->getElements();
     foreach ($elements as $element) {
         $element->setAttrib("style", "width:100px");
         $element->removeDecorator('label');
     }
     $form->getElement("month")->setAttrib("class", "");
     $form->getElement("year")->setAttrib("class", "");
     if ($request->isPost()) {
         $options = $request->getPost();
         if ($form->isValid($options)) {
             $date = $options["year"] . "-" . $options['month'];
             $attendance = new Application_Model_Attendance();
             $this->view->attendance = $attendance->fetchAll("user_id='{$userId}' and DATE_FORMAT(attendance_date, '%Y-%m')='{$date}'");
         } else {
             $form->reset();
             $form->populate($options);
         }
     } else {
         $options['month'] = date("m");
         $options['year'] = date("Y");
         $form->populate($options);
         $date = date("Y-m");
         $attendance = new Application_Model_Attendance();
         $this->view->attendance = $attendance->fetchAll("user_id='{$userId}' and DATE_FORMAT(attendance_date, '%Y-%m')='{$date}'");
     }
     $this->view->form = $form;
 }
Ejemplo n.º 2
0
 public function importAttendance($options, $targetPath)
 {
     include_once LIBRARY_PATH . "/Base/Excel/PHPExcel.php";
     $objPHPExcel = new PHPExcel();
     $objPHPExcel = PHPExcel_IOFactory::load($targetPath);
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         if ($worksheet->getTitle() == "Sheet1") {
             $rowctr = 0;
             foreach ($worksheet->getRowIterator() as $row) {
                 if ($row->getRowIndex() == 1) {
                     $cellIterator = $row->getCellIterator();
                     $cellIterator->setIterateOnlyExistingCells(false);
                     // Loop all cells, even if it is not set
                     foreach ($cellIterator as $cell) {
                         if (!is_null($cell)) {
                             if ($cell->getCoordinate() == "A1") {
                                 $columns[] = $cell->getCalculatedValue();
                             } else {
                                 $columns[] = $options['year'] . "-" . $options['month'] . "-" . $cell->getCalculatedValue();
                             }
                         }
                     }
                 } else {
                     $cellIterator = $row->getCellIterator();
                     $cellIterator->setIterateOnlyExistingCells(false);
                     // Loop all cells, even if it is not set
                     $cellctr = 0;
                     foreach ($cellIterator as $cell) {
                         if (!is_null($cell)) {
                             if ($cellctr == 0) {
                                 $empCode = $cell->getCalculatedValue();
                             } else {
                                 $user = new Application_Model_User();
                                 $user = $user->fetchRow("employee_code='{$empCode}'");
                                 if (false !== $user) {
                                     $attendance = new Application_Model_Attendance();
                                     $attendance = $attendance->fetchRow("user_id='" . $user->getId() . "' and attendance_date='" . $columns[$cellctr] . "'");
                                     if (false === $attendance) {
                                         //do insert
                                         if (trim($cell->getCalculatedValue()) != "") {
                                             $attendance = new Application_Model_Attendance();
                                             $attendance->setEmpCode($empCode);
                                             $attendance->setAttendance($cell->getCalculatedValue());
                                             $attendance->setAttendanceDate($columns[$cellctr]);
                                             $attendance->setUserId($user->getId());
                                             $attendance->save();
                                         }
                                     } else {
                                         //do update
                                         if (trim($cell->getCalculatedValue()) != "") {
                                             $attendance->setEmpCode($empCode);
                                             $attendance->setAttendance($cell->getCalculatedValue());
                                             $attendance->setAttendanceDate($columns[$cellctr]);
                                             $attendance->setUserId($user->getId());
                                             $attendance->save();
                                         }
                                     }
                                 }
                             }
                         }
                         $cellctr++;
                     }
                     // end of cellIterator foreach
                     $rowctr++;
                 }
             }
             //end of row iterator foreach
         }
         // If worksheet = Sheet1
     }
     // end of worksheet iterator foreach
     return $rowctr;
 }