/**
  * 
  * @param type $emplog
  * @return array
  */
 private function getSumData($emplog, $stores, $empname, $qry_dateS, $qry_dateE)
 {
     //畫面上的陣列
     $colAry = array();
     //年月
     $pdate = substr($qry_dateS, 0, 6);
     //每一行的陣列
     $row = array();
     //合計陣列
     $sum = TbpPerformParamRpt08::model()->getRptTitle();
     if (isset($sum)) {
         foreach ($sum as $key => $value) {
             $sum[$key] = 0;
         }
     }
     //全域變數
     $store = '';
     //如果撈出的結果>0,就先把第一筆資料先放進去
     if (count($emplog > 0)) {
         //讓全域變數等於第一筆資料的門市
         $store = $emplog[0]['storecode'];
         $row['storename'] = $emplog[0]['storename'];
         $row['storecode'] = $emplog[0]['storecode'];
         $row['empname'] = $empname;
         $row['pdate'] = $pdate;
     }
     //開始對每一筆資料跑loop
     for ($i = 0; $i < count($emplog); $i++) {
         //如果門市=第一筆資料的門市,就把num填入服務項目的欄位
         if ($emplog[$i]['storecode'] == $store) {
             $row['area'] = $stores[$emplog[$i]['storecode']];
             $row[$emplog[$i]['serviceno']] = $emplog[$i]['num'];
             $row['empname'] = $empname;
         } else {
             //跑完一天之後push進畫面
             array_push($colAry, $row);
             //把row清空,再把全域變數換成下一間門市
             $row = array();
             $store = $emplog[$i]['storecode'];
             $row['area'] = $stores[$emplog[$i]['storecode']];
             $row['storecode'] = $emplog[$i]['storecode'];
             $row['storename'] = $emplog[$i]['storename'];
             $row['pdate'] = $pdate;
             $row[$emplog[$i]['serviceno']] = $emplog[$i]['num'];
         }
         //合計
         if (!isset($sum[$emplog[$i]['serviceno']])) {
             $sum[$emplog[$i]['serviceno']] = 0;
         }
     }
     //最後一天push進畫面
     array_push($colAry, $row);
     $peform_service = TbsService::model()->findAllByAttributes(array('type1' => '1'));
     $assist_service = TbsService::model()->findAllByAttributes(array('type1' => '2'));
     // 利用 col 把每一個ARRAY的值丟進入
     //'A01'->'10','B01'->0...
     for ($j = 0; $j < count($colAry); $j++) {
         $colAry[$j] = $this->setRpt08RowData($colAry[$j], $colAry[$j], $peform_service, $assist_service);
         //合計
         foreach ($sum as $key => $value) {
             if (isset($colAry[$j][$key])) {
                 $sum[$key] = $sum[$key] + $colAry[$j][$key];
             }
         }
     }
     $tbpPerforms = TbpPerform::model()->findAllByAttributes(array(), $condition = "pdate between '{$qry_dateS}' and '{$qry_dateE}' ");
     // 建立storecode->remit的array
     $totalAry = array();
     $outputAry = array();
     $remitAry = array();
     $realRemitAry = array();
     //            $realTypeAry = array();
     $realMemoAry = array();
     $sumTotal = array();
     $sumOutput = array();
     $sumRemit = array();
     $sumRealRemit = array();
     //            $sumRealType = array();
     $sumRealMemo = array();
     foreach ($tbpPerforms as $perform) {
         if (isset($sumTotal[$perform->storecode])) {
             $sumTotal[$perform->storecode] = $sumTotal[$perform->storecode] + $perform->total;
         } else {
             $sumTotal[$perform->storecode] = $perform->total;
         }
         if (isset($sumOutput[$perform->storecode])) {
             $sumOutput[$perform->storecode] = $sumOutput[$perform->storecode] + $perform->output;
         } else {
             $sumOutput[$perform->storecode] = $perform->output;
         }
         if (isset($sumRemit[$perform->storecode])) {
             $sumRemit[$perform->storecode] = $sumRemit[$perform->storecode] + $perform->remit;
         } else {
             $sumRemit[$perform->storecode] = $perform->remit;
         }
         if (isset($sumRealRemit[$perform->storecode])) {
             $sumRealRemit[$perform->storecode] = $sumRealRemit[$perform->storecode] + $perform->realremit;
         } else {
             $sumRealRemit[$perform->storecode] = $perform->realremit;
         }
         // 備註
         if (isset($sumRealMemo[$perform->storecode])) {
             $str = $sumRealMemo[$perform->storecode];
             if ($str != '' && $perform->realmemo != '') {
                 $str = $str . ', ' . '[' . $perform->pdate . ']' . $perform->realmemo;
             } elseif ($str == '' && $perform->realmemo != '') {
                 $str = '[' . $perform->pdate . ']' . $perform->realmemo;
             }
             $sumRealMemo[$perform->storecode] = $str;
         } else {
             if ($perform->realmemo == '') {
                 $sumRealMemo[$perform->storecode] = $perform->realmemo;
             } else {
                 $sumRealMemo[$perform->storecode] = '[' . $perform->pdate . ']' . $perform->realmemo;
             }
         }
         $totalAry[$pdate . $perform->storecode] = $sumTotal[$perform->storecode];
         $outputAry[$pdate . $perform->storecode] = $sumOutput[$perform->storecode];
         $remitAry[$pdate . $perform->storecode] = $sumRemit[$perform->storecode];
         $realRemitAry[$pdate . $perform->storecode] = $sumRealRemit[$perform->storecode];
         $realMemoAry[$pdate . $perform->storecode] = $sumRealMemo[$perform->storecode];
     }
     // 放匯款金額進 $colAry
     for ($j = 0; $j < count($colAry); $j++) {
         $key = $colAry[$j]['pdate'] . $colAry[$j]['storecode'];
         // 取得
         $total = $totalAry[$key];
         $output = $outputAry[$key];
         $remit = $remitAry[$key];
         $realremit = $realRemitAry[$key];
         //                $realtype = $realTypeAry[$key];
         $realmemo = $realMemoAry[$key];
         // 填入
         $colAry[$j]['total'] = $total;
         $colAry[$j]['output'] = $output;
         $colAry[$j]['remit'] = $remit;
         $colAry[$j]['realremit'] = $realremit;
         //                $colAry[$j]['realtype'] = $realtype;
         $colAry[$j]['realmemo'] = $realmemo;
         // 合計
         if (isset($sum['total'])) {
             $sum['total'] = $sum['total'] + $total;
         } else {
             $sum['total'] = $total;
         }
         if (isset($sum['output'])) {
             $sum['output'] = $sum['output'] + $output;
         } else {
             $sum['output'] = $output;
         }
         if (isset($sum['remit'])) {
             $sum['remit'] = $sum['remit'] + $remit;
         } else {
             $sum['remit'] = $remit;
         }
         if (isset($sum['realremit'])) {
             $sum['realremit'] = $sum['realremit'] + $realremit;
         } else {
             $sum['realremit'] = $realremit;
         }
         if (isset($sum['realmemo'])) {
             $str = $sum['realmemo'];
             if ($str != '' && $realmemo != '') {
                 $str = $str . ', ' . $realmemo;
             } elseif ($str == '' && $realmemo != '') {
                 $str = $realmemo;
             }
             $sum['realmemo'] = $str;
         } else {
             $sum['realmemo'] = $realmemo;
         }
     }
     array_push($colAry, $sum);
     return $colAry;
 }
示例#2
0
<?php 
echo CHtml::endForm();
?>
</div><!-- form -->
</div>

<?php 
foreach (Yii::app()->user->getFlashes() as $key => $message) {
    echo "<div class='flash-{$key}'>" . $message . "</div>\n";
}
?>
 


<?php 
$model = new TbpPerform();
if (isset($fileName) && $fileName != '') {
    ?>
<div align="center">
        <a href="<?php 
    echo Yii::app()->request->baseUrl;
    ?>
/protected/tmp/<?php 
    echo $fileName;
    ?>
">
            <img src="<?php 
    echo Yii::app()->request->baseUrl;
    ?>
/images/download01.jpg">
        </a>;
 public function actionExport()
 {
     // 用以計算開始/結束時間之變數
     $time_start = microtime(true);
     //ini_set('memory_limit', '256M');
     //ini_set('max_execution_time', '300');
     // Sleep for a while
     usleep(100);
     //得到起始 結束的年月日
     $qry_dateS = date('Ymd');
     $qry_dateE = date('Ymd');
     $qry_area = "";
     //區域
     $qry_store = "";
     // 門市
     $qry_serviceno = array();
     //服務項目
     $serviceno_seq = array();
     //服務項目順序
     //預設取消匯出初始值
     $cancel_export = false;
     //預設查詢異動初始值
     $qry_move = false;
     if (isset($_POST['qry_dateS'])) {
         $qry_dateS = $_POST['qry_dateS'];
     }
     if (isset($_POST['qry_dateE'])) {
         $qry_dateE = $_POST['qry_dateE'];
     }
     if (isset($_POST['qry_area'])) {
         $qry_area = $_POST['qry_area'];
     }
     if (isset($_POST['qry_store'])) {
         $qry_store = $_POST['qry_store'];
     }
     if (isset($_POST['cancel_export'])) {
         $cancel_export = $_POST['cancel_export'];
     }
     if (isset($_POST['qry_move'])) {
         $qry_move = $_POST['qry_move'];
     }
     // 篩選條件初始的預設值
     $default_serviceno = array();
     $tbpParam = TbpPerformOut01::model()->findByAttributes(array('name' => 'ching_hang'));
     if ($tbpParam != NULL) {
         $default_serviceno = explode(",", $tbpParam->item);
         $serviceno_seq = explode(",", $tbpParam->sequence);
     }
     //  篩選條件初始的預設值
     $qry_serviceno = $default_serviceno;
     unset($default_serviceno);
     // 畫面呈現的表格欄位, col是欄位名稱, title是欄位顯示的中文字
     $col = array();
     $title = array();
     //            $col = $qry_serviceno;
     //
     //            // 取得預設報表抬頭
     //            $title = TbpPerformOut01::model()->getRptTitle($col);
     //
     //            // 設定報表抬頭
     //            foreach ($serviceno as $row) {
     //                $title[$row->serviceno] = $row->cname;
     //            }
     //正航匯入title
     if (count($serviceno_seq) != 0) {
         // 將指定的順序放進去, 再重新排序
         $col = array_combine($serviceno_seq, $qry_serviceno);
         ksort($col);
     } else {
         //models預設好的col
         $col = TbpPerformOut01::model()->getRemitCol();
     }
     unset($serviceno_seq);
     unset($qry_serviceno);
     // 取得預設報表抬頭
     $title = TbpPerformOut01::model()->getRemittitle();
     // 輸出在畫面上的陣列
     $colAry = array();
     //店編對應區域名稱的陣列
     $stores = array();
     //儲存篩選出來的門市
     $tbsStroes = array();
     //儲存塞選出的門市的店編
     $sqlStroe = array();
     //如果有選門市,就只選出那一家門市
     if ($qry_store != '') {
         $tbsStroes = TbsStore::model()->findAllByAttributes(array('storecode' => $qry_store));
     } elseif ($qry_area != '') {
         $tbsStroes = TbsStore::model()->findAllByAttributes(array('area_id' => $qry_area));
     } else {
         $tbsStroes = TbsStore::model()->findAll();
     }
     foreach ($tbsStroes as $store) {
         //找出篩選出的門市的區域代碼
         $area = TbsArea::model()->findByPK($store->area_id);
         if ($area != NULL) {
             //push店編
             array_push($sqlStroe, $store->storecode);
             //店編對應區域名稱
             $stores[$store->storecode] = $area->areaname;
         }
     }
     // 查詢用的SQL
     $qryStr = '';
     //如果有選門市或區域就需要sql=AND storecode in('007001',007002')
     if ($qry_store != '' or $qry_area != '') {
         //sql=sql.in('007001')因為只有一筆的時候沒有' , '  所以直接把店編放進去
         if (count($sqlStroe) > 0) {
             $qryStr = " AND storecode in ('{$sqlStroe['0']}'";
             //如果門市>1,就需要' , '
             if (count($sqlStroe) > 1) {
                 for ($i = 1; $i < count($sqlStroe); $i++) {
                     $qryStr = $qryStr . ",'{$sqlStroe[$i]}'";
                 }
             }
             $qryStr = $qryStr . ")";
         }
     }
     $fileName = '';
     //按下查詢
     if (isset($_POST['qry']) or isset($_POST['export'])) {
         $sql = "( SELECT pdate, storecode, storename, serviceno, sum(num) as num FROM tbp_perform_emp_log " . "WHERE pdate BETWEEN '{$qry_dateS}' AND '{$qry_dateE}' {$qryStr} AND num !=0 " . "GROUP BY pdate, storecode, storename, serviceno ORDER BY pdate, storecode ,serviceno) ";
         $sql2 = "( SELECT pdate, storecode, storename, serviceno, sum(num) as num FROM tbp_perform_log " . "WHERE pdate BETWEEN '{$qry_dateS}' AND '{$qry_dateE}' {$qryStr} AND num !=0 " . "GROUP BY pdate, storecode, storename, serviceno ORDER BY pdate, storecode ,serviceno) ";
         $sql = $sql . "UNION" . $sql2;
         //合併
         $sql = $sql . "order by pdate, storecode, serviceno";
         //一定要照pdate排序,因為loop要照日期去跑
         $emplog = Yii::app()->db->createCommand($sql)->queryAll();
         if ($emplog != NULL && count($emplog) > 0) {
             $colAry = $this->getDailyData($emplog);
             Yii::app()->user->setFlash('success', '以日期區間' . $qry_dateS . ' ~ ' . $qry_dateE . ' 查詢成功!合計' . count($colAry) . '筆資料');
         } else {
             Yii::app()->user->setFlash('error', '以日期區間' . $qry_dateS . ' ~ ' . $qry_dateE . ' 查無資料');
         }
         unset($emplog);
         if (isset($_POST['export'])) {
             $excelname = $qry_dateS . '-' . $qry_dateE;
             $fileName = $this->exportEXCEL($excelname, $col, $title, $colAry);
             $pdate = array();
             $storecode = array();
             //匯入成功
             if (isset($fileName)) {
                 if (count($colAry) > 0) {
                     for ($i = 0; $i < count($colAry); $i++) {
                         //給sql查詢條件
                         array_push($pdate, $colAry[$i]['pdate']);
                         array_push($storecode, $colAry[$i]['storecode']);
                     }
                     $_pdatestr = "'" . implode("','", $pdate) . "'";
                     //每個日期加入單引號為了sql in查詢使用
                     $arr1 = array_unique(explode(',', $_pdatestr));
                     //將重複日期刪除只保留一個的array
                     $_pdatestr = implode(',', $arr1);
                     //再將不重複日期轉成字串
                     $_storecodestr = "'" . implode("','", $storecode) . "'";
                     //每個店編加入單引號為了sql in查詢使用
                     $arr2 = array_unique(explode(',', $_storecodestr));
                     //將重複店編刪除只保留一個的array
                     $_storecodestr = implode(',', $arr2);
                     //再將不重複店編轉成字串
                     //不只一筆所以用findAllByAttributes
                     $isExist = TbpPerform::model()->findAllByAttributes(array(), $conditon = " pdate IN ({$_pdatestr}) and storecode IN ({$_storecodestr}) ORDER BY pdate DESC ");
                     //將匯入日期、店編符合DB條件的,則opt2設定為1
                     if (isset($isExist) and count($isExist) > 0) {
                         for ($i = 0; $i < count($isExist); $i++) {
                             $isExist[$i]->opt2 = 1;
                             $isExist[$i]->save();
                         }
                     }
                 }
             }
             unset($pdate);
             unset($storecode);
             //  CVarDumper::dump($remitAry,10,true);
             //  $col = array();
             //  $title = array();
             $colAry = array();
             // unset($colAry);
             $clickUrl = "<a href='" . Yii::app()->request->baseUrl . '/' . "protected" . '/' . "tmp" . '/' . $fileName . "'>點我下載</a>";
             Yii::app()->user->setFlash('success', "正航匯入成功!請點擊下載 " . $clickUrl);
         } else {
         }
         //Yii::app()->user->setFlash('success', "查詢成功!共計 ".count($colAry)."筆資料!");
     }
     //if(isset($_POST['qry']) OR isset($_POST['export'])
     //查詢異動array
     $qry_move_result = array();
     if (isset($_POST['qry_move']) or isset($_POST['move_export'])) {
         $qry_move = true;
         //查詢日期區間被已被匯出資料
         $isExist = TbpPerform::model()->findAllByAttributes(array(), $conditon = "  opt2=1 AND uemp IS NOT  NULL AND opt3 IS NULL ORDER BY pdate ,storecode ");
         foreach ($isExist as $value) {
             $temp = array('pdate' => $value->pdate, 'storecode' => $value->storecode, 'storename' => $value->storename, 'total' => $value->total, 'output' => $value->output, 'remit' => $value->remit, 'cemp' => $value->cemp, 'ctime' => $value->ctime, 'uemp' => $value->uemp, 'utime' => $value->utime);
             array_push($qry_move_result, $temp);
         }
         if (isset($qry_move_result) && count($qry_move_result) > 0) {
             Yii::app()->user->setFlash('success', "查出異動資料!共計 " . count($qry_move_result) . "筆資料。");
         } else {
             Yii::app()->user->setFlash('error', "沒有任何異動資料!");
         }
         // 查詢異動用的SQL
         $qrymoveStr = '';
         //為了sql 使用 in(20140506,...)
         $dateStr = '';
         //為了sql 使用 in(007002,...)
         $storecodeStr = '';
         //日期array
         $sdate = array();
         //店編array
         $sstorecode = array();
         //先把$qry_move_result的日期與店編曲出來
         if (count($qry_move_result) > 0) {
             for ($i = 0; $i < count($qry_move_result); $i++) {
                 array_push($sdate, $qry_move_result[$i]['pdate']);
                 array_push($sstorecode, $qry_move_result[$i]['storecode']);
             }
             //每個日期加入單引號為了sql in查詢使用
             if (count($sdate) > 0) {
                 $dateStr = "'" . implode("','", $sdate) . "'";
             }
             //每個店編加入單引號為了sql in查詢使用
             if (count($sstorecode) > 0) {
                 $storecodeStr = "'" . implode("','", $sstorecode) . "'";
             }
         }
         //if(count($qry_move_result)>0)
         //給sql查詢日期與店編
         $qrymoveStr = $qrymoveStr . "pdate IN ({$dateStr}) AND storecode IN ({$storecodeStr})";
         //sql字串清空
         $sql = '';
         if ($dateStr != '' and $storecodeStr != '') {
             $sql = "( SELECT pdate, storecode, storename, serviceno, sum(num) as num FROM tbp_perform_emp_log " . "WHERE {$qrymoveStr} AND num !=0 " . "GROUP BY pdate, storecode, storename, serviceno ORDER BY pdate, storecode ,serviceno) ";
             $sql2 = "( SELECT pdate, storecode, storename, serviceno, sum(num) as num FROM tbp_perform_log " . "WHERE {$qrymoveStr} AND num !=0 " . "GROUP BY pdate, storecode, storename, serviceno ORDER BY pdate, storecode ,serviceno) ";
             $sql = $sql . "UNION" . $sql2;
             //合併
             $sql = $sql . "order by pdate, storecode, serviceno";
             //一定要照pdate排序,因為loop要照日期去跑
             $emplog = Yii::app()->db->createCommand($sql)->queryAll();
             if ($emplog != NULL && count($emplog) > 0) {
                 $colAry = $this->getDailyData($emplog);
             }
         }
         unset($emplog);
         if (isset($_POST['move_export'])) {
             $excelname = "move_table";
             $fileName = $this->exportEXCEL($excelname, $col, $title, $colAry);
             //  CVarDumper::dump($remitAry,10,true);
             //  $col = array();
             // $title = array();
             $colAry = array();
             $clickUrl = "<a href='" . Yii::app()->request->baseUrl . '/' . "protected" . '/' . "tmp" . '/' . $fileName . "'>點我下載</a>";
             Yii::app()->user->setFlash('success', "異動表匯入Excel成功!請點擊下載 " . $clickUrl);
         }
     }
     // if(isset($_POST['qry_move']) OR isset($_POST['move_export']))
     //取消正航匯出array
     $cancel_result = array();
     //取消匯出正航
     if (isset($_POST['cancel_export'])) {
         $cancel_export = true;
         //查詢日期區間被已被匯出資料
         $isExist = TbpPerform::model()->findAllByAttributes(array(), $conditon = " pdate BETWEEN {$qry_dateS} AND {$qry_dateE} AND opt2=1 ORDER BY pdate ,storecode ");
         foreach ($isExist as $value) {
             $temp = array('pdate' => $value->pdate, 'storename' => $value->storename, 'total' => $value->total, 'output' => $value->output, 'remit' => $value->remit, 'realremit' => $value->realremit, 'realmemo' => $value->realmemo, 'status' => '成功');
             array_push($cancel_result, $temp);
         }
         //將日期區間DB條件的,則opt2設定為NULL
         if (isset($isExist) and count($isExist) > 0) {
             for ($i = 0; $i < count($isExist); $i++) {
                 $isExist[$i]->opt2 = NULL;
                 $isExist[$i]->save();
             }
             Yii::app()->user->setFlash('success', "取消匯出成功!共計 " . count($isExist) . "筆資料!");
         } else {
             Yii::app()->user->setFlash('error', "查無任何資料!");
         }
     }
     //if(isset($_POST['cancel_export']))
     // 用以計算開始/結束時間之變數
     $time_end = microtime(true);
     $computetime = $time_end - $time_start;
     try {
         $this->render('export', array('qry_dateS' => $qry_dateS, 'qry_dateE' => $qry_dateE, 'qry_area' => $qry_area, 'qry_store' => $qry_store, 'col' => $col, 'title' => $title, 'colAry' => $colAry, 'fileName' => $fileName, 'computetime' => $computetime, 'cancel_export' => $cancel_export, 'cancel_result' => $cancel_result, 'qry_move' => $qry_move, 'qry_move_result' => $qry_move_result));
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
     }
 }
 private function createPerformData($store, $daymonth)
 {
     // 每一列業績
     $models = array();
     //業績查詢
     if (isset($_POST['qry_perform'])) {
         $models = TbpPerform::model()->findAllByAttributes(array(), $condition = "MID(pdate,1,6) = '{$daymonth}' AND storecode= '{$store->storecode}' ");
         if (isset($models) && count($models) > 0) {
             Yii::app()->user->setFlash('success', '以下為查詢結果!');
         } else {
             Yii::app()->user->setFlash('error', '查無當月業績!');
         }
     } elseif (isset($_POST['qry_output'])) {
         //支出查詢
         $models = TbpPerform::model()->findAllByAttributes(array(), $condition = "MID(pdate,1,6) = '{$daymonth}' AND storecode= '{$store->storecode}' AND output > 0 ");
         if (isset($models) && count($models) > 0) {
             Yii::app()->user->setFlash('success', '以下為查詢結果!');
         } else {
             Yii::app()->user->setFlash('error', '當月無零用金輸出金額!');
         }
     } else {
         Yii::app()->user->setFlash('notice', '請選擇年月,以查詢業績謝謝!');
     }
     return $models;
 }
 /**
  * 新增修改 門市支出明細
  */
 public function actionCreateandupdate()
 {
     $storecode = '';
     $pdate = '';
     if (isset($_GET['storecode'])) {
         $storecode = $_GET['storecode'];
     }
     //門市編號
     if (isset($_GET['pdate'])) {
         $pdate = $_GET['pdate'];
     }
     //門市日期
     // 是否存在(合法)
     $isExist = TRUE;
     // 門市
     $store = '';
     // 門市當天業績
     $perform = '';
     // 錯誤訊息
     $errorMsg = '';
     // 畫面顯示
     $result = array();
     //如果有門市編號及日期不為空, 就查出那一家門市資料
     if ($storecode != '' && $pdate != '') {
         $store = TbsStore::model()->findByAttributes(array('storecode' => $storecode));
         if (isset($store)) {
             //取得目前IP
             $myip = $this->getMyip();
             //$myip='211.75.115.206';
             //假ip,預設高雄聯興
             //            $myip='60.249.143.210';
             // 比較登入者門市的IP,是否合法
             if (!strstr($store->storeip1, $myip)) {
                 $isExist = FALSE;
                 $errorMsg = "錯誤!所查詢之資料不屬於貴門市 [ IP: {$myip} ] ~請洽資訊組, 分機306<br>";
             }
             $perform = TbpPerform::model()->findByAttributes(array('pdate' => $pdate, 'storecode' => $storecode, 'opt1' => 1));
             if (!isset($perform)) {
                 $isExist = FALSE;
                 $errorMsg = $errorMsg . "錯誤!所查詢之門市[{$store->storename}]、日期[{$pdate}]無業績資料!";
             } elseif ($perform->output < 1) {
                 $isExist = FALSE;
                 $errorMsg = $errorMsg . "錯誤!所查詢之門市[{$store->storename}]、日期[{$pdate}]當天支出為 0 !";
             }
         } else {
             $isExist = FALSE;
             $errorMsg = "錯誤!所查詢之門市 [ {$storecode} ] 不存在~請洽資訊組, 分機306";
         }
     } else {
         $isExist = FALSE;
         $errorMsg = '錯誤!不正確的進入方式~請重新開啟EIP~若一直出現此情況,請洽資訊組, 分機306';
     }
     // 檢核日期是否合乎規範
     if ($isExist) {
         $isExist = $this->checkDate($pdate);
         if (!$isExist) {
             $errorMsg = $errorMsg . '已超過門市可修改門市支出明細時間,請聯絡會計組進行處理!!';
         }
     }
     // 預設筆數, 由公用變數取得
     $default_num = 0;
     if (isset($_POST['default_num']) && $_POST['default_num'] > 0) {
         $default_num = $_POST['default_num'];
         Yii::app()->user->setFlash('success', '修改顯示筆數成功,請依照主、次、細項點選,金額必須填入!!');
     } else {
         $tbpParam = TbpParam::model()->findByAttributes(array('param' => 'output_num'));
         if ($tbpParam != NULL) {
             $default_num = $tbpParam->pvalue;
         }
     }
     //針對F5重複刷新做解決
     //The second parameter on print_r returns the result to a variable rather than displaying it
     $RequestSignature = md5($_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'] . print_r($_POST, true));
     if (Yii::app()->session['LastRequest'] == $RequestSignature) {
         //echo $RequestSignature ;
         // 畫面顯示
         $result = TbpOutputLog::model()->findAllByAttributes(array('pdate' => $perform->pdate, 'storecode' => $perform->storecode));
     } else {
         // 若當天有業績, 且業績大於0
         if (!isset($_POST['reload']) && isset($_POST['TbpOutputLog']) && isset($perform) && $perform->output > 0) {
             $result = $this->createOutputData($result, $perform);
         } else {
             // 畫面顯示
             $result = TbpOutputLog::model()->findAllByAttributes(array('pdate' => $perform->pdate, 'storecode' => $perform->storecode));
         }
         Yii::app()->session['LastRequest'] = $RequestSignature;
     }
     $result_num = isset($result) ? count($result) : 0;
     if (isset($_POST)) {
         if ($result_num > 0) {
             Yii::app()->user->setFlash('notice', '修改細項時,仍需按照主、次、細項點選,金額必須大於0才會紀錄!!');
         } else {
             Yii::app()->user->setFlash('notice', '請按照主、次、細項點選,金額必須大於0才會紀錄!!');
         }
     }
     // 員工列數, 利用預設值產出列數
     if ($result_num < $default_num) {
         for ($i = 0; $i < $default_num - $result_num; $i++) {
             // 零用金支出表紀錄
             $model = new TbpOutputLog();
             array_push($result, $model);
         }
     }
     $this->render('createandupdate', array('pdate' => $pdate, 'store' => $store, 'perform' => $perform, 'isExist' => $isExist, 'default_num' => $default_num, 'array' => $result, 'errorMsg' => $errorMsg));
 }