Beispiel #1
0
 /**
  * 审批
  *
  * @param $data
  */
 public function onReview(Tudu_Model_Tudu_Entity_Tudu $tudu, Tudu_Model_Tudu_Entity_Extension_Abstract $data)
 {
     // 完成
     if ($tudu->stepId == '^end') {
         // 补签申请的另外处理
         if ($data->getAttribute('categoryid') == '^checkin') {
             return $this->updateCheckinApply($tudu, $data);
         }
         $data = $data->getAttributes();
         /* @var $daoApply Dao_App_Attend_Apply */
         $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
         $daoApply->updateApply($data['applyid'], array('status' => 2));
         $daoApply->updateReviewer($data['applyid'], $tudu->uniqueId, array('status' => 1));
         $startTime = $data['starttime'];
         $endTime = $data['endtime'];
         // 更新考勤信息备注
         /* @var $daoDate Dao_App_Attend_Date */
         $daoDate = Tudu_Dao_Manager::getDao('Dao_App_Attend_Date', Tudu_Dao_Manager::DB_APP);
         /* @var $daoMonth Dao_App_Attend_Month */
         $daoMonth = Tudu_Dao_Manager::getDao('Dao_App_Attend_Month', Tudu_Dao_Manager::DB_APP);
         /* @var $daoTotal Dao_App_Attend_Total */
         $daoTotal = Tudu_Dao_Manager::getDao('Dao_App_Attend_Total', Tudu_Dao_Manager::DB_APP);
         $start = strtotime(date('Y-m-d', $startTime));
         $end = strtotime(date('Y-m-d', $endTime));
         $days = floor(($end - $start) / 86400);
         $period = round($data['period'], 1);
         $memo = array($data['categoryname'], $data['starttime'], $data['endtime'], $period);
         for ($i = 0; $i < $days + 1; $i++) {
             $date = $start + $i * 86400;
             $daoDate->addApply(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $date, 'categoryid' => $data['categoryid'], 'memo' => implode('|', $memo)));
             if ($date <= strtotime('today')) {
                 if (!$daoDate->existsRecord($data['uniqueid'], $date)) {
                     $daoDate->create(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'date' => $date));
                 }
                 $daoDate->update($data['uniqueid'], $date, array('iswork' => 0, 'islate' => 0, 'isleave' => 0, 'checkinstatus' => 0));
             }
         }
         $months = array();
         $months[date('Ym', $start)] = array('year' => date('Y', $start), 'month' => date('m', $start));
         $months[date('Ym', $end)] = array('year' => date('Y', $end), 'month' => date('m', $end));
         foreach ($months as $month => $val) {
             // 判断月统计表是否已有当月的统计记录
             $sum = $daoDate->dateSum(array('uniqueid' => $data['uniqueid'], 'startdate' => mktime(0, 0, 0, $val['month'], 1, $val['year']), 'enddate' => mktime(0, 0, 0, $val['month'] + 1, 1, $val['year'])));
             $monthParams = array();
             if (!empty($sum)) {
                 $monthParams['updatetime'] = time();
                 $monthParams['late'] = (int) $sum['late'];
                 $monthParams['leave'] = (int) $sum['leave'];
                 $monthParams['unwork'] = (int) $sum['unwork'];
                 if (!$daoMonth->existsRecord($data['uniqueid'], $month)) {
                     $monthParams['orgid'] = $data['orgid'];
                     $monthParams['uniqueid'] = $data['uniqueid'];
                     $monthParams['date'] = $month;
                     $daoMonth->create($monthParams);
                 } else {
                     $daoMonth->update($data['uniqueid'], $month, $monthParams);
                 }
             }
             // 统计考勤类型次数等
             if (!$daoTotal->existsRecord($data['categoryid'], $data['uniqueid'], $month)) {
                 $daoTotal->create(array('orgid' => $data['orgid'], 'uniqueid' => $data['uniqueid'], 'categoryid' => $data['categoryid'], 'date' => $month, 'total' => $period, 'updatetime' => time()));
             } else {
                 $daoTotal->updateTotal($data['categoryid'], $data['uniqueid'], $month, $period);
             }
         }
         $manager = Tudu_Tudu_Manager::getInstance();
         $manager->doneTudu($tudu->tuduId, 1, 0);
         // 没有的
     } else {
         /* @var $daoApply Dao_App_Attend_Apply */
         $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
         $apply = $daoApply->getApply(array('tuduid' => $tudu->tuduId));
         // 不同意
         if (!$tudu->isAgree) {
             $daoApply->updateApply($apply->applyId, array('status' => 3));
             //$manager = Tudu_Tudu_Manager::getInstance();
             //$manager->doneTudu($tudu->tuduId, 1, 0);
         } else {
             $daoApply->updateApply($apply->applyId, array('status' => 1));
         }
         if (null !== $apply) {
             $daoApply->updateReviewer($apply->applyId, $tudu->uniqueId, array('status' => $tudu->isAgree ? 1 : 2));
             if ($tudu->recipient) {
                 $recipients = $tudu->recipient;
                 foreach ($recipients as $rec) {
                     if (!empty($rec['isreview'])) {
                         $daoApply->addReviewer($apply->applyId, $rec['uniqueid'], 0);
                     }
                 }
             }
         }
     }
 }