$form = $this->beginWidget('CActiveForm', array('id' => 'tba-weight-form', 'enableAjaxValidation' => false)); ?> <p class="note">欄位 <span class="required">*</span>是必填.</p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'logitem'); ?> <?php echo $form->dropDownList($model, 'logitem', CHtml::listData(TbaLogItem::model()->findAll(array('order' => 'logtype ASC,seqno ASC', 'condition' => 'weight=1 AND opt1=1')), 'id', 'logname'), array('empty' => '選擇項目')); ?> <?php echo $form->error($model, 'logitem'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'nweight'); ?> <?php echo $form->textField($model, 'nweight', array('size' => 3, 'maxlength' => 3)); ?> <?php
?> <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'logday', 'options' => array('showAnim' => 'slideDown', 'changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'yymmdd'), 'htmlOptions' => array('style' => 'width:100px;'))); ?> <?php echo $form->error($model, 'logday'); ?> </td> <td> <?php echo $form->labelEx($model, 'logitem'); ?> <?php echo $form->dropDownList($model, 'logitem', CHtml::listData(TbaLogItem::model()->findAll(array('order' => 'seqno', 'condition' => "logtype='2' AND optshow='1' ")), 'id', 'logname')); ?> <?php echo $form->error($model, 'logitem'); ?> </td> <td> <?php echo $form->labelEx($model, 'num'); ?> <?php echo $form->textField($model, 'num', array('size' => 4, 'maxlength' => 4)); ?> <?php
/** * 動態取得差勤項目連動 * * 判斷條件為 logtype(差勤類別) 及 optshow(是否顯示) 預設為 1 * * 可接受二種型態 ( 二種型態只能擇一) * 1. 一般查詢欄位 ( 比如: qry_area ) * url'=>CController::createUrl('tbsCom/dynamicstores',array('update'=>'qry_area')), * 2. MODEL欄位 ( 比如: TbaLog 的model, 欄位是 storecode ) * 'url'=>CController::createUrl('tbsCom/dynamicstores',array('model'=>'TbaLog','column'=>'storecode','empty'=>FALSE)), //url to call. * 3. 若結果第一列不想為空, 再傳入empty變數, 範例如下 * 'url'=>CController::createUrl('tbsCom/dynamicstores',array('empty'=>FALSE)) */ public function actionDynamiclogitems() { // 第一列預設為空 $empty = TRUE; // 第一列是否為空 if (isset($_GET['empty'])) { $empty = $_GET['empty']; } // 由異動欄位來的值 $logtype = ''; if (isset($_GET['model']) && isset($_GET['column'])) { $logtype = $_POST[$_GET['model']][$_GET['column']]; } elseif (isset($_GET['update'])) { $logtype = $_POST[$_GET['update']]; } // 依傳入之areaid來查詢對應門市, 並且要已啟用 $items = TbaLogItem::model()->findAllByAttributes(array(), $condition = "logtype = :id and optshow = '1' order by seqno ", $params = array(':id' => (int) $logtype)); // 取出店編號對應店名 $data = CHtml::listData($items, 'id', 'logname'); // 回傳至畫面 // 連動結果第一筆為空 if ($empty) { echo CHtml::tag('option', array('value' => ''), '選擇項目', true); } foreach ($data as $value => $name) { echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true); } }
?> <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'logday', 'attribute' => 'logday', 'value' => "{$logday}", 'options' => array('showAnim' => 'slideDown', 'changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'yymmdd'), 'htmlOptions' => array('style' => 'width:100px;'))); ?> <?php echo $form->error($model, 'logday'); ?> </td> <td> <?php echo $form->labelEx($model, 'logitem'); ?> <?php echo CHtml::dropDownList('logitem', $logitem, CHtml::listData(TbaLogItem::model()->findAll(array('order' => 'seqno ASC', 'condition' => 'opt2=1')), 'id', 'logname')); ?> <?php echo $form->error($model, 'logitem'); ?> </td> </tr> </table> <br> <div id="TbaLog_empno"> </div> <br> <table> <tr>
/** * */ public function actionSettle() { //年月, 預設上個月 $tmp = strtotime("-1 month", time()); $qry_YM = date('Ym', $tmp); $qry_YM = '201405'; $com = new ComFunction(); //員編 $qry_empno = ''; //員工姓名 $qry_empname = ''; if (isset($_POST['qry_YM'])) { $qry_YM = $_POST['qry_YM']; } if (isset($_POST['qry_empno'])) { $qry_empno = $_POST['qry_empno']; } if (isset($_POST['qry_empname'])) { $qry_empname = $_POST['qry_empname']; } // 標題列 $title = array(); // 欄位順序 $col = array(); // 畫面輸出陣列 $output = array(); // 顯示差勤細項紀錄 $showTotal = TRUE; if ($_POST) { // 若員工編號或姓名不為空 if ($qry_empno != '') { $user = User::model()->findByPk($qry_empno); if (isset($user->emp)) { $qry_empname = $user->emp->empname; } } elseif ($qry_empname != '') { $emp = TbsEmp::model()->findByAttributes(array('empname' => $qry_empname)); if (isset($emp)) { $qry_empno = $emp->empno; } } // 勾選顯示差勤 // if(isset($_POST['showTotal']) && $_POST['showTotal'] == 1 ) // $showTotal = TRUE; // 差勤結算 // if(isset($_POST['settle'])) $showTotal = TRUE; // 取得此月份的國定假日 $holidays = $com->getHolidayByYearMonth($qry_YM); // 取得所有的差勤項目 $logitems = TbaLogItem::model()->findAllByAttributes(array('optshow' => 1)); $items = array(); // 所有差勤項目 $itemsettle = array(); // 差勤結算項目 $itemname = array(); // 差勤名稱 $itemdays = array(); // 以天計差勤項目 (公.婚.事.病.假.曠..) $itemmins = array(); // 以分計差勤項目 ( 遲到早退開小差 ) $itemeach = array(); // 以支計差勤項目 ( 小過, 大過 ) // 將資料分類 foreach ($logitems as $item) { array_push($items, $item->id); $itemname[$item->id] = $item->logname; if ($item->weight == 1) { if ($item->logtype == 1) { if ($item->opt2 == 0) { array_push($itemdays, $item->id); } else { array_push($itemmins, $item->id); } } else { array_push($itemeach, $item->id); } } if ($item->salaryitem != '') { $itemsettle[$item->id] = $item->salaryitem; } } // 輸出的表頭 $title = $this->getWeightTitle($showTotal, $items, $itemdays, $itemmins, $itemeach, $itemname); // 欄位順序 $col = array_keys($title); // 取得差勤權重 $logweights = TbaWeight::model()->findAllByAttributes(array('opt1' => 1)); $nweight = array(); // 平日權重 $hweight = array(); // 假日權重 // foreach ($logweights as $weight) { $nweight[$weight->logitem] = $weight->nweight; $hweight[$weight->logitem] = $weight->hweight; if ($weight->opt2 == 1) { $nweight['opt2'] = $weight->nweight; } } // 計算權重 // 查出目前所有的差勤紀錄 // 每一天都丟進 $holidays 來判斷是否為假日 // 再逐項去判斷是否有權重. 若有則再做計算. // 而權重要判斷成是以天計, 以分計, 還是以支計 $aStart = $com->getTheFirstDayByYearMonth($qry_YM, "Ymd"); $aEnd = $com->getTheLastDayByYearMonth($qry_YM, "Ymd"); // 查出區間內之差勤紀錄, 依員編. 差勤項目. 排序 $sql = "SELECT * \n FROM `tba_log` \n WHERE logday \n BETWEEN '{$aStart}'\n AND '{$aEnd}' "; if ($qry_empno != '') { $sql = $sql . "AND empno = '{$qry_empno}' "; } $sql = $sql . "ORDER BY empno, logitem, opt2"; $logs = TbaLog::model()->findAllBySql($sql); // 針對每一筆. 先判斷是否有權重. 再判斷是那一種 // logtype=1 => 天 => 再判斷平日.假日 // logtype=1 => => opt2 = 1 ==> 分 , 該月累積超過30分, 則有權重 // 支 => 每一筆皆有 $emp = $logs[0]->empno; $empAry = array(); $empAry['empname'] = $logs[0]->empname; for ($i = 0; $i < count($logs); $i++) { // 若符合要計算權重的項目才進行判斷 if (in_array($logs[$i]->logitem, $items)) { // 同一個人一個 array if ($logs[$i]->empno == $emp) { if (isset($empAry[$logs[$i]->logitem])) { $empAry[$logs[$i]->logitem] = $empAry[$logs[$i]->logitem] + $logs[$i]->num; } else { $empAry[$logs[$i]->logitem] = $logs[$i]->num; } $empAry = $this->setWeightValue($empAry, $logs[$i], $holidays, $nweight, $hweight); } else { // 寫入前, 把遲到分鐘數, 換算成權重 if (isset($empAry['opt2']) && isset($nweight['opt2'])) { $empAry['opt2'] = $this->setLateWeight($empAry['opt2'], $nweight['opt2']); } else { $empAry['opt2'] = 0; } $empAry['sum'] = $this->setSumWeight($col, $empAry); $output[$emp] = $empAry; $emp = $logs[$i]->empno; $empAry = array(); $empAry['empname'] = $logs[$i]->empname; if (isset($empAry[$logs[$i]->logitem])) { $empAry[$logs[$i]->logitem] = $empAry[$logs[$i]->logitem] + $logs[$i]->num; } else { $empAry[$logs[$i]->logitem] = $logs[$i]->num; } $empAry = $this->setWeightValue($empAry, $logs[$i], $holidays, $nweight, $hweight); } } // if(in_array($logs[$i]->logitem, $items)) } // for ($i = 0; $i < count($logs); $i++) if (isset($empAry['opt2']) && isset($nweight['opt2'])) { $empAry['opt2'] = $this->setLateWeight($empAry['opt2'], $nweight['opt2']); } else { $empAry['opt2'] = 0; } $empAry['sum'] = $this->setSumWeight($col, $empAry); $output[$emp] = $empAry; // 如果是結算, 則將結果寫入資料庫 if (isset($_POST['settle'])) { // 先刪除該年月之資料 $deleteAry = array(); $param = TbmParam::model()->findByAttributes(array('param' => 'attend_settle')); if ($param != NULL) { $deleteAry = explode(",", $param->pvalue); } // 先刪除此年月之資料 if ($qry_empno != '' or $qry_empname != '') { TbmEmpItem::model()->deleteAllByAttributes(array('daymonth' => $qry_YM, 'empno' => $qry_empno, 'itemno' => $deleteAry)); } else { TbmEmpItem::model()->deleteAllByAttributes(array('daymonth' => $qry_YM, 'itemno' => $deleteAry)); } $result = $this->createSettleItems($qry_YM, $itemsettle, $output); if (isset($result)) { $check = isset($result[0]) ? $result[0] : FALSE; $errmsg = isset($result[1]) ? $result[1] : "差勤結算失敗!"; if ($check) { Yii::app()->user->setFlash('success', "[差勤結算]成功!{$qry_YM} 共計有 " . count($output) . "筆 員工有差勤紀錄!"); } else { Yii::app()->user->setFlash('error', "[差勤結算]失敗!{$errmsg!}"); } } } else { Yii::app()->user->setFlash('success', "[畫面輸出]查詢成功!{$qry_YM} 共計有 " . count($output) . "筆 員工有差勤紀錄!"); } } else { Yii::app()->user->setFlash('notice', "[畫面輸出]可以只查看此年月之差勤權重, 不會結算至薪資。[差勤結算]會將此年月之差勤結果寫入薪資項目,供薪資計算用。"); } $this->render('settle', array('qry_YM' => $qry_YM, 'qry_empno' => $qry_empno, 'qry_empname' => $qry_empname, 'title' => $title, 'col' => $col, 'colAry' => $output)); }
/** * 設定差勤項目遲到 - opt2 * @param type $logitem - logitem id - 差勤項目ID * @return type opt2 - 項目名稱 */ private function setLogItem($model) { $logitem = TbaLogItem::model()->findByPk($model->logitem); if (isset($logitem)) { $model->logname = $logitem->logname; $model->opt2 = $logitem->opt2; $model->opt3 = $logitem->opt3; } return $model; }
/** * 依員工查詢權重 * @param String $daymonth - 年月 ( 2014-01-01 ) * @param String $empno - 員工編號 ( 02010001) * @return int */ public function getWeightByEmp($daymonth, $empno) { $result = 0; // 員工出缺勤 $absence = $this->getAbsenceByEmp($daymonth, $empno, FALSE); // 取得國定假日 $dates = array(); foreach ($absence as $key => $abs) { array_push($dates, $key); } $holidays = $this->getHolidayByDates($dates); // 取得有權重的差勤項目 $logitems = TbaLogItem::model()->findAllByAttributes(array('weight' => 1, 'opt1' => 1)); $itemdays = array(); // 以天計 $itemmins = array(); // 以分計 ( 遲到早退開小差 ) $itemeach = array(); // 以支計 ( 小過, 大過 ) foreach ($logitems as $item) { if ($item->logtype == 1) { if ($item->opt2 == 0) { array_push($itemdays, $item->id); } else { array_push($itemmins, $item->id); } } else { array_push($itemeach, $item->id); } } // 取得差勤權重 $logweights = TbaWeight::model()->findAllByAttributes(array('opt1' => 1)); $nweight = array(); // 平日權重 $hweight = array(); // 假日權重 foreach ($logweights as $weight) { $nweight[$weight->logitem] = $weight->nweight; $hweight[$weight->logitem] = $weight->hweight; } // 計算權重 // 以 員工出缺勤 $absence 來 loop // 每一天都丟進 $holidays 來判斷是否為假日 // 再逐項去判斷是否有權重. 若有則再做計算. // 而權重要判斷成是以天計, 以分計, 還是以支計 foreach ($absence as $date => $abs) { } return $hweight; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return TbaLogItem the loaded model * @throws CHttpException */ public function loadModel($id) { $model = TbaLogItem::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }