/** * 業績報表(個人) */ public function actionRpt01() { $empno = ''; if (isset($_GET['empno'])) { Yii::app()->session['empno'] = $_GET['empno']; $this->redirect(array('rpt01')); //跳轉回rpt01頁面 } else { if (Yii::app()->session['empno'] != '') { $empno = Yii::app()->session['empno']; //沒使用到清空 // unset(Yii::app()->session['empno']); } else { // 取得員工編號 $empno = Yii::app()->user->id; } } // 查詢員工資料 $user = User::model()->findByPk($empno); //得到達成率的年月 $achYM = isset($_POST['achYm']) ? $_POST['achYm'] : date('Ym'); // 預設月初至今天 $qryStart = date("Ym01"); $qryEnd = date("Ymd"); if (isset($_POST["qryDates"])) { if (isset($_POST['qryStart'])) { $qryStart = $_POST['qryStart']; } if (isset($_POST['qryEnd'])) { $qryEnd = $_POST['qryEnd']; } } if ($qryEnd < $qryStart) { Yii::app()->user->setFlash('error', '結束日期不可小於起始日期!'); } //切割出年份 $tmp_year = substr($achYM, 0, 4); //切割出月份 $tmp_mon = substr($achYM, 4, 2); if (isset($_POST['achieveqry'])) { $qryStart = date("Ymd", mktime(24, 0, 0, $tmp_mon, 0, $tmp_year)); $qryEnd = date("Ymd", mktime(0, 0, 0, $tmp_mon + 1, 0, $tmp_year)); } $aStart = date("Ymd", mktime(24, 0, 0, $tmp_mon, 0, $tmp_year)); $aEnd = date("Ymd", mktime(0, 0, 0, $tmp_mon + 1, 0, $tmp_year)); // 先利用GROUP算出此員工在此日期區間內各項業績總和. 用來產生欄位數, 並取得中文名稱 $sql = "SELECT a.serviceno, b.showname, a.num \n FROM (\n ( SELECT serviceno, SUM( num ) AS num FROM tbp_perform_emp_log \n WHERE empno = '{$empno}' AND pdate BETWEEN '{$aStart}' AND '{$aEnd}' GROUP BY serviceno ) a\n LEFT JOIN tbs_service b\n ON a.serviceno = b.serviceno\n )\n ORDER BY a.serviceno "; $result = Yii::app()->db->createCommand($sql)->queryAll(); // 門市. 門市ID $storeAry = array(); $storeAreaId = array(); $TbsStores = TbsStore::model()->findAllByAttributes(array('opt1' => 1)); foreach ($TbsStores as $store) { $storeAry[$store->storecode] = $store->storename; $storeAreaId[$store->storecode] = $store->area_id; } unset($TbsStores); // 區域 $areaAry = array(); $TbsAreas = TbsArea::model()->findAllByAttributes(array('opt1' => 1)); foreach ($TbsAreas as $area) { $areaAry[$area->id] = $area->areaname; } unset($TbsAreas); // 職位 $positionAry = array(); $TbsPositions = TbsPosition::model()->findAllByAttributes(array('opt1' => 1)); foreach ($TbsPositions as $pos) { $positionAry[$pos->id] = $pos->pcname; } unset($TbsPositions); // 薪資, 責任額 $salaryAry = array(); $dutyAry = array(); $TbsBaseSalary = TbsBasesalary::model()->findAllByAttributes(array('opt1' => 1)); foreach ($TbsBaseSalary as $salary) { $salaryAry[$salary->id] = $salary->salary; $dutyAry[$salary->id] = $salary->duty; } unset($TbsBaseSalary); $acol = $this->getRpt01Col(); $atitle = $this->getRpt01Title($acol); $colAry = array(); $col = $this->getRpt01Col2(); // 欄位ID $title = $this->getRpt01Title2($col); // 抬頭 // 合計 $sum = array('col1' => 0, 'col2' => 0, 'col3' => 0, 'col4' => 0, 'col5' => 0, 'col6' => 0, 'col9' => 0, 'col10' => 0, 'col11' => 0, 'col12' => 0, 'col13' => 0, 'col14' => 0, 'col15' => 0, 'col16' => 0, 'col17' => 0); $logArray = array(); // 個人業績紀錄 // 利用 col 把每一個ARRAY的值丟進入 // col[0]='A01', col[1]='B01' // title['A01']='剪髮, title['B01']='燙髮' // sum['A01]=剪髮合計, sum['B01]=燙髮合計 $empMonth = TbsEmpMonth::model()->findByDayMonth($empno, $achYM); if ($empMonth != NULL) { if ($result != NULL) { Yii::app()->user->setFlash('success', $tmp_year . '年' . $tmp_mon . '月' . '業績查詢成功!染髮顆數包含燙髮,洗髮(促)為洗髮不加十元顆數!'); } else { Yii::app()->user->setFlash('error', $tmp_year . '年' . $tmp_mon . '月' . '查無業績!'); } $row = array(); // 年月 $row['ym'] = $achYM; // 營業區 $row['area'] = $areaAry[$empMonth->area]; // 門市 $row['store'] = $storeAry[$empMonth->storecode]; // 職稱 $row['position'] = $positionAry[$empMonth->position1]; // 員編 $row['empno'] = $empno; // 姓名 $row['name'] = $user->emp ? $user->emp->empname : ''; // 到職日 $row['arrivedate'] = Yii::app()->dateFormatter->format("yyyy-MM-dd", $empMonth->arrivedate, "yyyy-MM-dd"); // 狀態 $row['status'] = TbsEmp::model()->getHireType($empMonth->hiretype); // 保底 $row['salary'] = $salaryAry[$empMonth->salary]; // 責任業績, 區店長需動態算, opt2欄位設成管理門市數 // 103/7/1 區店長責任額修正 // if($empMonth->position1 == 9){ // $areaduty = TbsAreaduty::model()->findByAttributes(array('storenum'=>$empMonth->opt2)); // if(isset($areaduty)) // $row['duty'] = $areaduty->duty; // }else $row['duty'] = $dutyAry[$empMonth->salary]; $asum = array(); for ($i = 0; $i < count($result); $i++) { $asum[$result[$i]['serviceno']] = $result[$i]['num']; } // 設定各欄位業績及洗助算法 $row = $this->setRpt01RowData($row, $asum); // 達成率 $rate = $row['duty'] == 0 ? 0 : round($row['perform'] / $row['duty'], 4); $row['rate'] = $rate * 100 . "%"; // //洗髮+10 // $row['col10'] = isset($empData['col10'])?$empData['col10']:0; // // //洗髮不加10 //// $row['col11'] = 0; // $row['col11'] = isset($empData['col11'])?$empData['col11']:0; // 是否達成 $row['achi'] = $rate >= 1 ? '達成' : '未達成'; if ($row['perform'] + $row['assist'] > 0) { array_push($colAry, $row); } // ================== 以下為業績區間 ====================================== // 查詢業績區間 for ($i = 0; $i <= $qryEnd - $qryStart; $i++) { $pdate = $qryEnd - $i; // 利用員編+日期查詢 $emplog = TbpPerformEmpLog::model()->findAllByAttributes(array('empno' => $empno, 'pdate' => $pdate)); $count = count($emplog); if ($count > 0) { $ary = array('col1' => 0, 'col2' => 0, 'col3' => 0, 'col4' => 0, 'col5' => 0, 'col6' => 0, 'col9' => 0, 'col10' => 0, 'col11' => 0, 'col12' => 0, 'col13' => 0, 'col14' => 0, 'col15' => 0, 'col16' => 0, 'col17' => 0); // 門市 $pstore = $emplog[0]->storecode; // 如果同一天有2間門市以上之業績時, 會有多筆 for ($logi = 0; $logi < $count; $logi++) { // 需要PUSH多筆 if ($pstore != $emplog[$logi]->storecode) { $sum['store'] = '合計'; $sum['col1'] = $sum['col1'] + $ary['col1']; $sum['col2'] = $sum['col2'] + $ary['col2']; $sum['col3'] = $sum['col3'] + $ary['col3']; $sum['col5'] = $sum['col5'] + $ary['col5']; $sum['col6'] = $sum['col6'] + $ary['col6']; // $sum['col7'] = $sum['col7'] + $ary['col7']; // $sum['col8'] = $sum['col8'] + $ary['col8']; $sum['col9'] = $sum['col9'] + $ary['col9']; $sum['col10'] = $sum['col10'] + $ary['col10']; $sum['col11'] = $sum['col11'] + $ary['col11']; $sum['col12'] = $sum['col12'] + $ary['col12']; $sum['col13'] = $sum['col13'] + $ary['col13']; $sum['col14'] = $sum['col14'] + $ary['col14']; $sum['col15'] = $sum['col15'] + $ary['col15']; $sum['col16'] = $sum['col16'] + $ary['col16']; $sum['col17'] = $sum['col17'] + $ary['col17']; array_push($logArray, $ary); $pstore = $emplog[$logi]->storecode; $ary = array('col1' => 0, 'col2' => 0, 'col3' => 0, 'col4' => 0, 'col5' => 0, 'col6' => 0, 'col9' => 0, 'col10' => 0, 'col11' => 0, 'col12' => 0, 'col13' => 0, 'col14' => 0, 'col15' => 0, 'col16' => 0, 'col17' => 0); } // 日期 $ary['pdate'] = $emplog[$logi]->pdate; // 門市 $ary['store'] = $emplog[$logi]->storename; // 剪 if ($emplog[$logi]->serviceno == 'A01') { $ary['col1'] = $ary['col1'] + $emplog[$logi]->num; } if ($emplog[$logi]->serviceno == 'S01') { $ary['col1'] = $ary['col1'] + $emplog[$logi]->num; } if ($emplog[$logi]->serviceno == 'S05') { $ary['col1'] = $ary['col1'] + $emplog[$logi]->num; } //染 if ($emplog[$logi]->serviceno == 'B01') { $ary['col2'] = $ary['col2'] + $emplog[$logi]->num; } //助染 if ($emplog[$logi]->serviceno == 'B02') { $ary['col3'] = $ary['col3'] + $emplog[$logi]->num; } //優染 if ($emplog[$logi]->serviceno == 'S03') { $ary['col5'] = $ary['col5'] + $emplog[$logi]->num; } //優助染 if ($emplog[$logi]->serviceno == 'S04') { $ary['col6'] = $ary['col6'] + $emplog[$logi]->num; } //舒活SPA // if($emplog[$logi]->serviceno == 'E01') $ary['col7'] = $ary['col7'] +$emplog[$logi]->num; //養護SPA // if($emplog[$logi]->serviceno == 'E02') $ary['col8'] = $ary['col8'] + $emplog[$logi]->num; //洗髮精 if ($emplog[$logi]->serviceno == 'N041') { $ary['col9'] = $ary['col9'] + $emplog[$logi]->num; } if ($emplog[$logi]->serviceno == 'N042') { $ary['col12'] = $ary['col12'] + $emplog[$logi]->num; } if ($emplog[$logi]->serviceno == 'N043') { $ary['col13'] = $ary['col13'] + $emplog[$logi]->num; } //洗髮+10 if ($emplog[$logi]->serviceno == 'D01') { $ary['col10'] = $ary['col10'] + $emplog[$logi]->num; } //洗髮不+10 if ($emplog[$logi]->serviceno == 'S02') { $ary['col11'] = $ary['col11'] + $emplog[$logi]->num; } if ($emplog[$logi]->serviceno == 'S06') { $ary['col11'] = $ary['col11'] + $emplog[$logi]->num; } //髮油 if ($emplog[$logi]->serviceno == 'N051') { $ary['col14'] = $ary['col14'] + $emplog[$logi]->num; } //瞬護 if ($emplog[$logi]->serviceno == 'F07') { $ary['col15'] = $ary['col15'] + $emplog[$logi]->num; } //隔離 if ($emplog[$logi]->serviceno == 'F08') { $ary['col16'] = $ary['col16'] + $emplog[$logi]->num; } //髮雕 if ($emplog[$logi]->serviceno == 'N052') { $ary['col17'] = $ary['col17'] + $emplog[$logi]->num; } } $sum['store'] = '合計'; $sum['col1'] = $sum['col1'] + $ary['col1']; $sum['col2'] = $sum['col2'] + $ary['col2']; $sum['col3'] = $sum['col3'] + $ary['col3']; $sum['col5'] = $sum['col5'] + $ary['col5']; $sum['col6'] = $sum['col6'] + $ary['col6']; // $sum['col7'] = $sum['col7'] + $ary['col7']; // $sum['col8'] = $sum['col8'] + $ary['col8']; $sum['col9'] = $sum['col9'] + $ary['col9']; $sum['col10'] = $sum['col10'] + $ary['col10']; $sum['col11'] = $sum['col11'] + $ary['col11']; $sum['col12'] = $sum['col12'] + $ary['col12']; $sum['col13'] = $sum['col13'] + $ary['col13']; $sum['col14'] = $sum['col14'] + $ary['col14']; $sum['col15'] = $sum['col15'] + $ary['col15']; $sum['col16'] = $sum['col16'] + $ary['col16']; $sum['col17'] = $sum['col17'] + $ary['col17']; array_push($logArray, $ary); } } array_push($logArray, $sum); } $com = new ComFunction(); $attendance = $com->getAbsenceByEmp($achYM, $empno, TRUE); //呼叫差勤結果 $weight = $com->getWeightByEmp($achYM, $empno); //呼叫差勤結果 $this->render('rpt01', array('user' => $user, 'achYM' => $achYM, 'qryStart' => $qryStart, 'qryEnd' => $qryEnd, 'acol' => $acol, 'atitle' => $atitle, 'col' => $col, 'title' => $title, 'sum' => $sum, 'logArray' => $logArray, 'colAry' => $colAry, 'attendance' => $attendance, 'weight' => $weight)); }
public function actionAudit() { //得到起始 結束的年月日 $qry_dateS = date("Ymd", strtotime('-1 month')); //找尋前1個月 $qry_dateE = date('Ymd'); //得到所選日期區間 if (isset($_POST['qry_dateS'])) { $qry_dateS = $_POST['qry_dateS']; } if (isset($_POST['qry_dateE'])) { $qry_dateE = $_POST['qry_dateE']; } // 篩選 logtype != 2 、 opt2 != 1, 獎懲, 遲到早退開小差, 代理 及其他都不計 $sql = "SELECT logday,empno ,logname, num ,opt2 FROM tba_log\n WHERE logtype != 2 AND opt2 != 1 AND logitem !=16 AND logitem !=29 AND logday BETWEEN '{$qry_dateS}' AND '{$qry_dateE}' \n ORDER BY logday DESC "; $result = Yii::app()->db->createCommand($sql)->queryAll(); // output array $_array = array(); if (count(count($result) > 0)) { // 用來比較的日期 if (isset($result[0]['logday'])) { $day = $result[0]['logday']; } // 用來比較的員編 if (isset($result[0]['empno'])) { $no = $result[0]['empno']; } //預設的array $logAry = array('logday' => '', 'empno' => '', 'logname' => '', 'num' => 0); for ($i = 0; $i < count($result); $i++) { if ($result[$i]['logday'] == $day && $result[$i]['empno'] == $no) { //日期與員編相同 $logAry['logday'] = $result[$i]['logday']; $logAry['empno'] = $result[$i]['empno']; $logAry['logname'] = $logAry['logname'] . ' ' . $this->auditByEmpFormat($result[$i]); //回傳字串相加 $logAry['num'] = $logAry['num'] + $result[$i]['num']; //num相加 } else { array_push($_array, $logAry); $day = $result[$i]['logday']; //day設成進來的日期 $no = $result[$i]['empno']; //day設成進來的員編 $logAry = array(); //清空 $logAry['logday'] = $result[$i]['logday']; $logAry['empno'] = $result[$i]['empno']; $logAry['logname'] = $this->auditByEmpFormat($result[$i]); $logAry['num'] = $result[$i]['num']; } } array_push($_array, $logAry); } $final_result = array(); if (count($_array) > 0) { for ($i = 0; $i < count($_array); $i++) { if ($_array[$i]['num'] >= 1) { //給sql查詢條件 $logday = $_array[$i]['logday']; $empno = $_array[$i]['empno']; $isExist = TbpPerformEmpLog::model()->findByAttributes(array(), $conditon = " pdate = '{$logday}' and empno = {$empno} ORDER BY pdate DESC "); if (isset($isExist)) { $temp = array('logdate' => $logday, 'storename' => $isExist->storename, 'empno' => $isExist->empno, 'empname' => $isExist->empname, 'perform' => '有', 'logname' => $_array[$i]['logname']); array_push($final_result, $temp); } } } } $this->render('audit', array('qry_dateS' => $qry_dateS, 'qry_dateE' => $qry_dateE, 'final_result' => $final_result)); }