コード例 #1
0
ファイル: FormulaHelpers.php プロジェクト: hunglmtb/eb
function contract_attr($formulaId, $code, $year = '')
{
    global $contractIdGlobal;
    global $yearGlobal;
    if ($year != '') {
        $year = $yearGlobal - 1;
        $sSQL = " SELECT a.FORMULA_VALUE FROM pd_contract_year a ,pd_contract_calculation b WHERE b.ID = a.CALCULATION_ID AND" . "  a.CONTRACT_ID =  " . $contractIdGlobal . " AND  a.YEAR =  '" . $year . "'" . " AND  b.FORMULA_ID =  '" . $formulaId . "'";
        $pdContractYear = PdContractYear::getTableName();
        $pdContractCalculation = PdContractCalculation::getTableName();
        $contractYear = PdContractYear::join($pdContractCalculation, "{$pdContractYear}.CALCULATION_ID", '=', "{$pdContractCalculation}.ID")->where("{$pdContractYear}.CONTRACT_ID", '=', $contractIdGlobal)->where("{$pdContractYear}.YEAR", '=', $year)->where("{$pdContractCalculation}.FORMULA_ID", '=', $formulaId)->select("{$pdContractYear}.FORMULA_VALUE as ATTRIBUTE_VALUE")->first();
    } else {
        $sSQL = " SELECT ATTRIBUTE_VALUE \n\t\t\t\tFROM pd_code_contract_attribute a\n\t\t\t\t,pd_contract_data b\n\t\t\t\tWHERE b.ATTRIBUTE_ID = a.ID AND" . "  b.CONTRACT_ID =  " . $contractIdGlobal . " \n\t\t\t\t\t\tAND  a.CODE =  '" . $code . "'";
        $pdContractData = PdContractData::getTableName();
        $pdCodeContractAttribute = PdCodeContractAttribute::getTableName();
        $contractYear = PdCodeContractAttribute::join($pdContractData, "{$pdContractData}.ATTRIBUTE_ID", '=', "{$pdCodeContractAttribute}.ID")->where("{$pdCodeContractAttribute}.CODE", '=', $code)->where("{$pdContractData}.CONTRACT_ID", '=', $contractIdGlobal)->select("ATTRIBUTE_VALUE")->first();
    }
    /* $result=mysql_query($sSQL) or die("fail: ".$sSQL."-> error:".mysql_error());
    	while($row=mysql_fetch_array($result)) {
    		return $row['ATTRIBUTE_VALUE'];
    	} */
    if ($contractYear) {
        return $contractYear->ATTRIBUTE_VALUE;
    }
    return 0;
}