function insertComapnyFinancialData() { define("YEAR_INDEX", 1); define("SEASON_INDEX", 2); define("VALUE_AT_RISK_INDEX", 3); $insert_value = $_GET['selectedInsertItem']; $company_id = $insert_value[COMPANY_ID_INDEX]; $season = $insert_value[YEAR_INDEX] . $insert_value[SEASON_INDEX]; // 檢查id是否存在於資料庫, 若不存在則跳出 if (checkCompany($GLOBALS['tableName'], $company_id)) { // 檢查idxsason財務資料是否存在於資料庫, 若存在則跳出 if (!checkFinancialInfo($GLOBALS['tableName'], $company_id, $season)) { $value_at_risk = $insert_value[VALUE_AT_RISK_INDEX]; // 組成新增字串 switch ($GLOBALS['tableName']) { case CFINANCIAL_INFO: $table_name = "company_financial_information"; $insert_value_str = '(`company_id`, `season`, `value_at_risk`, `stock`, `cashflow_operating`, `cashflow_investment`, `proceed_fm_newIssue`) VALUES ("' . $company_id . '","' . $season . '", ' . $value_at_risk . ', null, null, null, null)'; break; case CHINA_CFINANCIAL_INFO: $table_name = "china_company_financial_information"; $insert_value_str = '(`company_id`, `season`, `value_at_risk`, `cashflow_operating`, `cashflow_investment`, `proceed_fm_newIssue`) VALUES ("' . $company_id . '","' . $season . '",' . $value_at_risk . ', null, null, null)'; break; } // 新增單筆公司財務資料 $GLOBALS['dbc_object']->insertData($table_name, $insert_value_str); // showInsertMessage(INSERT_SUCCESS); } else { showInsertMessage(EXISTED_VALUE_AT_RISK_DATA); // 該筆財務資料已存在於資料庫中 } } else { // NO_COMPANY_DATA showInsertMessage(NO_COMPANY_DATA); // 該公司代號的公司不存在 } }
function uploadStockorCashflow($c, $class, $file) { // fp : 讀取好的檔案 $fp = loadCsvFile($file); // line 1 : tile列 公司ID 公司名稱 季別 資料欄位 // 股價 : 1欄 // 現金流量 : 3欄 // line 2 start : data列 公司ID 公司名稱 季別 該季資料 // step 1 : checkFinancialInfo(c, cid, season) ? 修改該id x season資料資料欄位 : 不做任何事 // 日期轉換 20140630 -> 2014Q2 // loop step 1 until row over // stock : checkStockDate(season) if ($fp) { if ($c === TAIWAN) { $tablename = 'company_financial_information'; } else { if ($c === CHINA) { $tablename = 'china_company_financial_information'; } } $ROW = fgetcsv($fp); // title列(跳過) // 計算現金流量的index if ($class === CASHFLOW) { $cashflowColNameIndexArray = getCashflowIndexArray($ROW); } while ($ROW = fgetcsv($fp)) { $cid = trim($ROW[FIRSTCOLUMN]); if (is_numeric($cid)) { $date = $ROW[THIRDCOLUMN]; // 將日期轉成季別格式 $season = convertDate2Season($date); // 檢查季別是否與使用者輸入的季別相同 // 若相同則繼續上傳動作 if (checkUploadSeason($season)) { if (checkFinancialInfo($c, $cid, $season)) { // 檢查資料庫中是否已有該筆idxseason資料 $condition = '`company_id`="' . $cid . '" AND `season`="' . $season . '"'; if ($class === STOCK) { // 修改資料庫中該筆idxseason資料的股價欄位 $stock = checkNull($ROW[FOURTHCOLUMN]); $GLOBALS['dbc_object']->updateData($tablename, STOCK, $stock, $condition); } else { if ($class = CASHFLOW) { // 修改資料庫中該筆idxseason資料的現金流量欄位 for ($i = 0; $i < count($cashflowColNameIndexArray); $i++) { $cashflow = checkNull($ROW[$cashflowColNameIndexArray[1][$i]]); $GLOBALS['dbc_object']->updateData($tablename, $cashflowColNameIndexArray[0][$i], $cashflow, $condition); } } else { printError('處理資料出現問題!'); } } } } else { printError('檔案內的季別與輸入的上傳季別不一致 取消上傳動作'); } } } if ($class === STOCK) { // 上傳股價日期對應季別的資料 updateStockDate($date); } } }