function insertLOBuyingOrderForHN($AccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $StockExchangeID, $IsGotPaper, $CreatedBy) { $function_name = 'insertLOBuyingOrderForHN'; $struct = '{urn:' . $this->class_name . '}' . $function_name . 'Struct'; if (authenUser(func_get_args(), $this, $function_name) > 0) { return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } // checking account is active / not if (!$this->checkAccountIsActive($AccountNo)) { $this->_ERROR_CODE = 30275; return returnXML(func_get_args(), $this->class_name, $function_name, 30275, $this->items, $this); } if (!required($AccountNo) || !required($OrderDate) || !required($StockID) || !required($OrderQuantity) || !required($OrderPrice) || !required($Session) || !unsigned($OrderQuantity) || !unsigned($StockID) || $Session > MAX_SESSION_HN) { if (!required($AccountNo)) { $this->_ERROR_CODE = 30300; } if (!required($OrderDate)) { $this->_ERROR_CODE = 30301; } if (!required($StockID) || !unsigned($StockID)) { $this->_ERROR_CODE = 30302; } if (!required($OrderQuantity) || !unsigned($OrderQuantity)) { $this->_ERROR_CODE = 30303; } if (!required($Session) || !unsigned($Session) || $Session > MAX_SESSION_HN) { $this->_ERROR_CODE = 30304; } if (!required($OrderPrice)) { $this->_ERROR_CODE = 30305; } } else { $vip = checkVIPAccount($AccountNo); // 1: exist 0: not exist if ($vip == 1 && $FromTypeID == 5) { // web $this->_ERROR_CODE = 30602; return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } if (strpos(EOT_PROHIBITION_ACCOUNT, $AccountNo) !== false && $FromTypeID == 5) { $this->_ERROR_CODE = 30602; return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } $CheckSession = $this->checkSessionForHN($OrderDate); if ($CheckSession == ORDER_EXPIRED || $CheckSession == ORDER_DENIED) { $this->_ERROR_CODE = 30306; return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } // else {$CheckSession = ORDER_APPROVED;} if (!$this->checkStockPrice($StockID, $OrderPrice, $StockExchangeID, $OrderDate)) { $this->_ERROR_CODE = 30307; } $isQuotaAccount = CheckIsQuotaAccount($AccountNo); if ($this->_ERROR_CODE == 0) { if ($CheckSession == ORDER_APPROVED) { $query = sprintf("CALL sp_insertLOBuyingOrderForHN('%s', %u, %u, %u, %u, %u, '%s', '%s', '%u', '%u', '%s')", $AccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $IsGotPaper, $CreatedBy); } $rs = $this->_MDB2_WRITE->extended->getRow($query); $this->_MDB2_WRITE->disconnect(); if (empty($rs)) { $this->_ERROR_CODE = 30308; } else { $result = $rs['varerror']; if ($result < 0) { switch ($result) { case '-1': $this->_ERROR_CODE = 30309; break; case '-2': $this->_ERROR_CODE = 30310; break; case '-3': $this->_ERROR_CODE = 30311; break; case '-4': $this->_ERROR_CODE = 30312; break; case '-5': $this->_ERROR_CODE = 30313; break; case '-6': $this->_ERROR_CODE = 30314; break; case '-7': $this->_ERROR_CODE = 30315; break; case '-8': $this->_ERROR_CODE = 30615; break; default: $this->_ERROR_CODE = 666; } } else { $this->items[0] = new SOAP_Value('item', $struct, array("ID" => new SOAP_Value("ID", "string", $result))); //block money in bank $query = sprintf("SELECT * FROM vw_ListAccountBank_Detail WHERE AccountNo='%s' ORDER BY Priority ", $AccountNo); $bank_rs = $this->_MDB2->extended->getAll($query); if (strpos(PAGODA_ACCOUNT, $AccountNo) === false && $vip == 0) { $dab_rs = 999; if ($isQuotaAccount != 0) { // Neu khach hang su dung dich vu T2 thi chi giao dich voi bank NHHM $BankID = NHHM; $mdb = initWriteDB(); $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, NHHM, $result, $rs['varordervalue'], $OrderDate, $CreatedBy); $off_rs = $mdb->extended->getRow($query); $mdb->disconnect(); $dab_rs = $off_rs['varerror']; } else { for ($i = 0; $i < count($bank_rs); $i++) { switch ($bank_rs[$i]['bankid']) { case DAB_ID: $dab =& new CDAB(); $dab_rs = $dab->blockMoney($bank_rs[$i]['bankaccount'], $bank_rs[$i]['cardno'], $AccountNo, $result, $rs['varordervalue'], $OrderDate); break; case VCB_ID: $dab =& new CVCB(); $OrderID = $result . $rs['varunitcode']; if (!$this->killStupidBank()) { // VCB is stupid $dab_rs = $dab->blockMoney($AccountNo, $OrderID, $rs['varordervalue']); } else { $dab_rs = 30999; } break; case ANZ_ID: $OrderID = $result; $query = sprintf("CALL sp_anz_money_request_lock( %u, '%s', '%s', '%s' )", $OrderID, $AccountNo, $rs['varordervalue'], $CreatedBy); $this->_MDB2_WRITE->connect(); $rs1 = $this->_MDB2_WRITE->extended->getRow($query); $this->_MDB2_WRITE->disconnect(); switch ($rs1['varerror']) { case -1: $dab_rs = 34511; //database error break; case -2: $dab_rs = 34512; //not enough money to unlock break; case -3: $dab_rs = 34513; //account does not exist break; default: $dab_rs = $rs1['varerror']; } break; case NVB_ID: $dab =& new CNVB(); $dab_rs = $dab->blockMoney(substr($result . date("His"), 3), $bank_rs[$i]['bankaccount'], $rs['varordervalue'], $result); break; case OFFLINE: $mdb = initWriteDB(); $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, OFFLINE, $result, $rs['varordervalue'], $OrderDate, $CreatedBy); $off_rs = $mdb->extended->getRow($query); $mdb->disconnect(); $dab_rs = $off_rs['varerror']; break; } //switch if ($dab_rs == '0') { $BankID = $bank_rs[$i]['bankid']; break; } } } } else { $dab_rs = 0; $BankID = EXI_ID; } if ($dab_rs == '0') { //Successfully $mdb = initWriteDB(); $query = sprintf("CALL sp_updateBuyingOrderFromPendingToApproved(%u, %u) ", $result, $BankID); $status_rs = $mdb->extended->getRow($query); $mdb->disconnect(); if (empty($status_rs)) { $this->_ERROR_CODE = 30316; } else { $result = $status_rs['varerror']; if ($result < 0) { //update Order Status fail switch ($result) { case '-1': $this->_ERROR_CODE = 30317; break; case '-2': $this->_ERROR_CODE = 30318; break; } //switch } // if } // if WS } else { // bank fail if ($isQuotaAccount != 0) { switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 30660; break; case '-2': $this->_ERROR_CODE = 30661; break; case '-3': $this->_ERROR_CODE = 30662; break; case '-4': $this->_ERROR_CODE = 30663; break; default: $this->_ERROR_CODE = $dab_rs; } } else { $i = $i - 1; switch ($bank_rs[$i]['bankid']) { case DAB_ID: switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 41020; break; case '-2': $this->_ERROR_CODE = 41021; break; case '-3': $this->_ERROR_CODE = 41022; break; case '-4': $this->_ERROR_CODE = 41023; break; case '-5': $this->_ERROR_CODE = 41024; break; case '1': $this->_ERROR_CODE = 41025; break; case '2': $this->_ERROR_CODE = 41026; break; case '3': $this->_ERROR_CODE = 41027; break; case '4': $this->_ERROR_CODE = 41028; break; case '5': $this->_ERROR_CODE = 41030; break; case '99': $this->_ERROR_CODE = 41029; break; default: $this->_ERROR_CODE = $dab_rs; } break; case VCB_ID: $this->_ERROR_CODE = $dab_rs; break; case NVB_ID: $this->_ERROR_CODE = $dab_rs; break; case OFFLINE: switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 30660; break; case '-2': $this->_ERROR_CODE = 30661; break; case '-3': $this->_ERROR_CODE = 30662; break; case '-4': $this->_ERROR_CODE = 30663; break; default: $this->_ERROR_CODE = $dab_rs; } break; } //switch } //$mdb->connect(); $mdb = initWriteDB(); $query = sprintf("CALL sp_updateBuyingOrderFromPendingToDenied(%u, '%s') ", $result, $dab_rs); $status_rs = $mdb->extended->getRow($query); $mdb->disconnect(); if (empty($status_rs)) { $this->_ERROR_CODE = 30297; } else { $result = $status_rs['varerror']; if ($result < 0) { //update Order Status fail switch ($result) { case '-1': $this->_ERROR_CODE = 30298; break; case '-2': $this->_ERROR_CODE = 30299; break; } //switch } // if } // if WS } // bank } // WS Insert Result } //WS Insert } } return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); }
/** Function: insertBuyingOrderForTransactionExecuteWithReservingMoney */ function insertBuyingOrderForTransactionExecuteWithReservingMoney($OrderNumber, $AccountNo, $Symbol, $OrderQuantity, $OrderPrice, $Session, $OrderStyleID, $Note, $StockExchangeID, $OrderDate, $CreatedBy) { $function_name = 'insertBuyingOrderForTransactionExecuteWithReservingMoney'; $struct = '{urn:' . $this->class_name . '}' . $function_name . 'Struct'; if (authenUser(func_get_args(), $this, $function_name) > 0) { return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } if (!required($OrderNumber) || !required($AccountNo) || !required($Symbol) || !required($OrderDate) || !required($OrderQuantity) || !unsigned($OrderQuantity) || !required($OrderPrice) || !required($Session) || !unsigned($Session) || !required($OrderStyleID) || !unsigned($OrderStyleID) || !required($StockExchangeID) || !unsigned($StockExchangeID)) { if (!required($OrderNumber)) { $this->_ERROR_CODE = 34410; } if (!required($AccountNo)) { $this->_ERROR_CODE = 34411; } if (!required($Symbol)) { $this->_ERROR_CODE = 34412; } if (!required($OrderQuantity) || !unsigned($OrderQuantity)) { $this->_ERROR_CODE = 34413; } if (!required($OrderPrice)) { $this->_ERROR_CODE = 34414; } if (!required($Session) || !unsigned($Session)) { $this->_ERROR_CODE = 34415; } if (!required($OrderDate)) { $this->_ERROR_CODE = 34416; } if (!required($OrderStyleID) || !unsigned($OrderStyleID)) { $this->_ERROR_CODE = 34417; } if (!required($StockExchangeID) || !unsigned($StockExchangeID)) { $this->_ERROR_CODE = 34418; } } else { $query = sprintf("CALL sp_insertBuyingOrderForTransactionExecute('%s', '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', '%s')", $OrderNumber, $AccountNo, $Symbol, $OrderQuantity, $OrderPrice, $Session, $OrderStyleID, $Note, $StockExchangeID, $OrderDate, $CreatedBy); $rs = $this->_MDB2_WRITE->extended->getRow($query); $this->_MDB2_WRITE->disconnect(); if (empty($rs)) { $this->_ERROR_CODE = 34419; } else { $result = $rs['varerror']; if ($result < 0) { switch ($result) { case '-1': $this->_ERROR_CODE = 34420; break; case '-2': $this->_ERROR_CODE = 34421; break; case '-3': $this->_ERROR_CODE = 34422; break; case '-4': $this->_ERROR_CODE = 34423; break; } } else { //block money in bank $query = sprintf("SELECT * FROM vw_ListAccountBank_Detail WHERE AccountNo='%s' ORDER BY Priority ", $AccountNo); $bank_rs = $this->_MDB2->extended->getAll($query); if (strpos(PAGODA_ACCOUNT, $AccountNo) === false) { $dab_rs = 999; $isQuotaAccount = CheckIsQuotaAccount($AccountNo); if ($isQuotaAccount != 0) { // Neu khach hang su dung dich vu T2 thi chi giao dich voi bank NHHM $BankID = NHHM; $mdb = initWriteDB(); $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, NHHM, $result, $rs['varordervalue'], $OrderDate, $CreatedBy); $off_rs = $mdb->extended->getRow($query); $mdb->disconnect(); $dab_rs = $off_rs['varerror']; } else { for ($i = 0; $i < count($bank_rs); $i++) { switch ($bank_rs[$i]['bankid']) { case DAB_ID: $dab =& new CDAB(); $dab_rs = $dab->blockMoney($bank_rs[$i]['bankaccount'], $bank_rs[$i]['cardno'], $AccountNo, $result, 1, $OrderDate); break; case VCB_ID: $dab =& new CVCB(); $OrderID = $result . $rs['varunitcode']; $dab_rs = $dab->blockMoney($AccountNo, $OrderID, 1); break; case NVB_ID: $dab =& new CNVB(); $dab_rs = $dab->blockMoney(substr($result . date("His"), 3), $bank_rs[$i]['bankaccount'], 1, $result); break; case OFFLINE: $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, OFFLINE, $result, 1, $OrderDate, $CreatedBy); $this->_MDB2_WRITE->connect(); $off_rs = $this->_MDB2_WRITE->extended->getRow($query); $this->_MDB2_WRITE->disconnect(); $dab_rs = $off_rs['varerror']; break; } if ($dab_rs == 0) { $BankID = $bank_rs[$i]['bankid']; break; } } } } else { $dab_rs = 0; $BankID = EXI_ID; } if ($dab_rs != 0) { //fail if ($isQuotaAccount != 0) { // ==> BankID = NHHM switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 30650; break; case '-2': $this->_ERROR_CODE = 30651; break; case '-3': $this->_ERROR_CODE = 30652; break; case '-4': $this->_ERROR_CODE = 30653; break; default: $this->_ERROR_CODE = $dab_rs; } } else { $i = $i - 1; switch ($bank_rs[$i]['bankid']) { case DAB_ID: switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 41020; break; case '-2': $this->_ERROR_CODE = 41021; break; case '-3': $this->_ERROR_CODE = 41022; break; case '-4': $this->_ERROR_CODE = 41023; break; case '-5': $this->_ERROR_CODE = 41024; break; case '1': $this->_ERROR_CODE = 41025; break; case '2': $this->_ERROR_CODE = 41026; break; case '3': $this->_ERROR_CODE = 41027; break; case '4': $this->_ERROR_CODE = 41028; break; case '5': $this->_ERROR_CODE = 41030; break; case '99': $this->_ERROR_CODE = 41029; break; default: $this->_ERROR_CODE = $dab_rs; } break; case VCB_ID: $this->_ERROR_CODE = $dab_rs; break; case NVB_ID: $this->_ERROR_CODE = $dab_rs; break; case NHHM: case OFFLINE: switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 30650; break; case '-2': $this->_ERROR_CODE = 30651; break; case '-3': $this->_ERROR_CODE = 30652; break; case '-4': $this->_ERROR_CODE = 30653; break; default: $this->_ERROR_CODE = $dab_rs; } break; } //switch } $this->_MDB2_WRITE->connect(); $query = sprintf("DELETE FROM %s WHERE ID=%u ", TBL_ORDER, $result); $delete_rs = $this->_MDB2_WRITE->extended->getRow($query); } else { // bank $this->items[0] = new SOAP_Value('item', $struct, array("ID" => new SOAP_Value("ID", "string", $result))); $this->_MDB2_WRITE->connect(); $query = sprintf("CALL sp_updateBankIDWhenInsertWarningOrder( %u, %u ) ", $result, $BankID); $status_rs = $this->_MDB2_WRITE->extended->getRow($query); if (empty($status_rs)) { $this->_ERROR_CODE = 34145; } } } } } return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); }
function insertCoSellOrder($CoAccountNo, $AccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $IsGotPaper, $CreatedBy, $AccountNoContra, $CompanyNameContra) { $function_name = 'insertCoSellOrder'; $struct = '{urn:' . $this->class_name . '}' . $function_name . 'Struct'; $log[] = sprintf('insertCoSellOrder - CoAccountNo:%s;AccountNo:%s;StockID:%s;OrderQuantity:%s;OrderPrice:%s;Session:%s;FromTypeID:%s;Note:%s;OrderDate:%s;IsAssigner:%s;IsGotPaper:%s;CreatedBy:%s;AccountNoContra:%s;CompanyNameContra:%s;ExecutedTime:%s', $CoAccountNo, $AccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $IsGotPaper, $CreatedBy, $AccountNoContra, $CompanyNameContra, date('Y-m-d h:i:s')); if (authenUser(func_get_args(), $this, $function_name) > 0) { $log[] = sprintf('authenUser: ERROR_CODE: %s', $this->_ERROR_CODE); write_my_log_path("insertCoSellOrder", implode("\n --> ", $log), '/home/vhosts/eSMS/htdocs/logs/otc/'); return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } $log[] = sprintf('authenUser: ERROR_CODE: %s', $this->_ERROR_CODE); // checking account is active / not if (!checkAccountIsActive($AccountNo) || !checkAccountIsActive($CoAccountNo)) { $this->_ERROR_CODE = 30275; $log[] = sprintf('checkAccountIsActive: ERROR_CODE: %s; AccountNo:%s,%s;CoAccountNo: %s,%s', $this->_ERROR_CODE, $AccountNo, checkAccountIsActive($AccountNo) ? 'TRUE' : 'FALSE', $CoAccountNo, checkAccountIsActive($CoAccountNo) ? 'TRUE' : 'FALSE'); write_my_log_path("insertCoSellOrder", implode("\n --> ", $log), '/home/vhosts/eSMS/htdocs/logs/otc/'); return returnXML(func_get_args(), $this->class_name, $function_name, 30275, $this->items, $this); } $log[] = sprintf('checkAccountIsActive: ERROR_CODE: %s; AccountNo:%s,%s;CoAccountNo: %s,%s', $this->_ERROR_CODE, $AccountNo, checkAccountIsActive($AccountNo) ? 'TRUE' : 'FALSE', $CoAccountNo, checkAccountIsActive($CoAccountNo) ? 'TRUE' : 'FALSE'); if (!required($CoAccountNo) || !required($AccountNo) || !required($OrderDate) || !required($StockID) || !required($OrderQuantity) || !required($OrderPrice) || !required($Session) || !unsigned($OrderQuantity) || !unsigned($StockID)) { if (!required($AccountNo) || !required($CoAccountNo)) { $this->_ERROR_CODE = 30051; } if (!required($OrderDate)) { $this->_ERROR_CODE = 30052; } if (!required($StockID) || !unsigned($StockID)) { $this->_ERROR_CODE = 30053; } if (!required($OrderQuantity) || !unsigned($OrderQuantity)) { $this->_ERROR_CODE = 30054; } if (!required($Session)) { $this->_ERROR_CODE = 30055; } if (!required($OrderPrice)) { $this->_ERROR_CODE = 30056; } $log[] = sprintf('check require: ERROR_CODE: %s', $this->_ERROR_CODE); } else { $vip = checkVIPAccount($AccountNo); // 1: exist 0: not exist $vipCo = checkVIPAccount($CoAccountNo); // 1: exist 0: not exist if (($vip == 1 || $vipCo == 1) && $FromTypeID == 5) { // web $this->_ERROR_CODE = 30602; $log[] = sprintf('Vip on web: Fail; AccountNo: %s;CoAccountNo: %s', $vip == 0 ? 'not vip' : 'vip', $vipCo == 0 ? 'not vip' : 'vip'); write_my_log_path("insertCoSellOrder", implode("\n --> ", $log), '/home/vhosts/eSMS/htdocs/logs/otc/'); return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } if ((strpos(EOT_PROHIBITION_ACCOUNT, $AccountNo) !== false || strpos(EOT_PROHIBITION_ACCOUNT, $CoAccountNo) !== false) && $FromTypeID == 5) { $this->_ERROR_CODE = 30602; $log[] = sprintf('check EOT_PROHIBITION_ACCOUNT: ERROR_CODE: %s;AccountNo:%s,%s;CoAccountNo:%s,%s', $this->_ERROR_CODE, $AccountNo, strpos(EOT_PROHIBITION_ACCOUNT, $AccountNo), $CoAccountNo, strpos(EOT_PROHIBITION_ACCOUNT, $CoAccountNo)); write_my_log_path("insertCoSellOrder", implode("\n --> ", $log), '/home/vhosts/eSMS/htdocs/logs/otc/'); return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); } if (!checkStockPrice($StockID, $OrderPrice, $OrderDate)) { $this->_ERROR_CODE = 30057; } $log[] = sprintf('checkStockPrice: ERROR_CODE: %s', $this->_ERROR_CODE); $sellingOrderID = ''; $buyingOrderID = ''; try { if ($this->_ERROR_CODE == 0) { // -------------------------------------------------------------------------------------- // // Insert sell order for $CoAccountNo // -------------------------------------------------------------------------------------- // $query = sprintf("CALL sp_upcom_insertSellingOrder('%s', %u, %u, %u, %u, '%u', '%s', '%s', '%u', '%u', '%s', '%s', '%s')", $CoAccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $IsGotPaper, $CreatedBy, $AccountNoContra, $CompanyNameContra); $log[] = sprintf('%s', $query); $mdb = initWriteDB(); $rs = $mdb->extended->getRow($query); $mdb->disconnect(); if (empty($rs)) { $this->_ERROR_CODE = 30060; } else { $result = $rs['varerror']; if ($result < 0) { switch ($result) { case '-1': $this->_ERROR_CODE = 19010; break; case '-2': $this->_ERROR_CODE = 19011; break; case '-3': $this->_ERROR_CODE = 19012; break; case '-4': $this->_ERROR_CODE = 19013; break; case '-5': $this->_ERROR_CODE = 19014; break; case '-6': $this->_ERROR_CODE = 19015; break; default: $this->_ERROR_CODE = $result; } } else { $sellingOrderID = $result; } } $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); $log[] = sprintf('SellingOrderID: %s', $sellingOrderID); } if ($this->_ERROR_CODE == 0) { // -------------------------------------------------------------------------------------- // // Insert buy order for $AccountNo // -------------------------------------------------------------------------------------- // $query = sprintf("CALL sp_upcom_insertBuyingOrder('%s', %u, %u, %u, %u, %u, '%s', '%s', '%u', '%u', '%s', '%s', '%s')", $AccountNo, $StockID, $OrderQuantity, $OrderPrice, $Session, $FromTypeID, $Note, $OrderDate, $IsAssigner, $IsGotPaper, $CreatedBy, $AccountNoContra, $CompanyNameContra); $log[] = sprintf('%s', $query); $rs = $this->_MDB2_WRITE->extended->getRow($query); if (empty($rs)) { $this->_ERROR_CODE = 30015; $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); } else { $result = $rs['varerror']; if ($result < 0) { switch ($result) { case '-1': $this->_ERROR_CODE = 19001; break; case '-2': $this->_ERROR_CODE = 19002; break; case '-3': $this->_ERROR_CODE = 19003; break; case '-4': $this->_ERROR_CODE = 19004; break; case '-5': $this->_ERROR_CODE = 19005; break; default: $this->_ERROR_CODE = $result; } $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); } else { $isQuotaAccount = CheckIsQuotaAccount($AccountNo); $vip = checkVIPAccount($AccountNo); // 1: exist 0: not exist $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); $log[] = sprintf('BuyingOrderID: %s', $result); $buyingOrderID = $result; //block money in bank $query = sprintf("SELECT * FROM vw_ListAccountBank_Detail WHERE AccountNo='%s' ORDER BY Priority ", $AccountNo); $log[] = sprintf('%s', $query); $mdb = initWriteDB(); $bank_rs = $mdb->extended->getAll($query); $log[] = sprintf('PAGODA_ACCOUNT: %s', strpos(PAGODA_ACCOUNT, $AccountNo) === false ? 'FALSE' : 'TRUE'); $log[] = sprintf('VIP_ACCOUNT: %s', $vip == 0 ? 'FALSE' : 'TRUE'); if (strpos(PAGODA_ACCOUNT, $AccountNo) === false && $vip == 0) { $dab_rs = 999; if ($isQuotaAccount != 0) { $BankID = NHHM; $mdb = initWriteDB(); $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, NHHM, $result, $rs['varordervalue'], $OrderDate, $CreatedBy); $off_rs = $mdb->extended->getRow($query); $mdb->disconnect(); $dab_rs = $off_rs['varerror']; $log[] = sprintf('block_money: bankid:NHHM;result:%s', $dab_rs); } else { for ($i = 0; $i < count($bank_rs); $i++) { switch ($bank_rs[$i]['bankid']) { case DAB_ID: $dab =& new CDAB(); $dab_rs = $dab->blockMoney($bank_rs[$i]['bankaccount'], $bank_rs[$i]['cardno'], $AccountNo, $result, $rs['varordervalue'], $OrderDate); $log[] = sprintf('block_money: bankid:DAB_ID;result:%s', $dab_rs); break; case VCB_ID: $dab =& new CVCB(); $OrderID = $result . $rs['varunitcode']; if (!killStupidBank()) { // VCB is stupid $dab_rs = $dab->blockMoney($AccountNo, $OrderID, $rs['varordervalue']); } else { $dab_rs = 30999; } $log[] = sprintf('block_money: bankid:VCB_ID;result:%s', $dab_rs); break; case ANZ_ID: $OrderID = $result; $query = sprintf("CALL sp_anz_money_request_lock( %u, '%s', '%s', '%s' )", $OrderID, $AccountNo, $rs['varordervalue'], $CreatedBy); $this->_MDB2_WRITE->connect(); $rs1 = $this->_MDB2_WRITE->extended->getRow($query); $this->_MDB2_WRITE->disconnect(); switch ($rs1['varerror']) { case -1: $dab_rs = 34511; //database error break; case -2: $dab_rs = 34512; //not enough money to unlock break; case -3: $dab_rs = 34513; //account does not exist break; default: $dab_rs = $rs1['varerror']; } $log[] = sprintf('block_money: bankid:ANZ_ID;result:%s', $dab_rs); // added by Quang, 20100407 ------------------------------------ break; case OFFLINE: //inAccountNo varchar(20),inBankID int,inOrderID bigint,inOrderAmount double,inOrderDate date,inCreatedBy $mdb = initWriteDB(); $query = sprintf("CALL sp_VirtualBank_Lock('%s', %u, %u, %f, '%s', '%s')", $AccountNo, OFFLINE, $result, $rs['varordervalue'], $OrderDate, $CreatedBy); $off_rs = $mdb->extended->getRow($query); $mdb->disconnect(); $dab_rs = $off_rs['varerror']; $log[] = sprintf('block_money: bankid:OFFLINE;result:%s', $dab_rs); break; // end add ----------------------------------------------------- } if ($dab_rs == 0) { $BankID = $bank_rs[$i]['bankid']; break; } } } } else { $dab_rs = 0; } if ($dab_rs == 0) { //Successfully $log[] = sprintf('successded_block_money'); $mdb = initWriteDB(); if ($Session <= 3) { $query = sprintf("CALL sp_updateBuyingOrderFromPendingToApproved(%u, %u) ", $result, $BankID); } else { $query = sprintf("CALL sp_updateBuyingOrderFromPendingToTransfered(%u, %u) ", $result, $BankID); } $log[] = sprintf('%s', $query); $status_rs = $mdb->extended->getRow($query); $mdb->disconnect(); if (empty($status_rs)) { $this->_ERROR_CODE = 30143; } else { $result = $status_rs['varerror']; if ($result < 0) { //update Order Status fail switch ($result) { case '-1': $this->_ERROR_CODE = 30141; break; case '-2': $this->_ERROR_CODE = 30142; break; } //switch } // if } // if WS $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); } else { // bank fail $log[] = sprintf('failed_block_money'); switch ($dab_rs) { case '-1': $this->_ERROR_CODE = 41020; break; case '-2': $this->_ERROR_CODE = 41021; break; case '-3': $this->_ERROR_CODE = 41022; break; case '-4': $this->_ERROR_CODE = 41023; break; case '-5': $this->_ERROR_CODE = 41024; break; case '1': $this->_ERROR_CODE = 41025; break; case '2': $this->_ERROR_CODE = 41026; break; case '3': $this->_ERROR_CODE = 41027; break; case '4': $this->_ERROR_CODE = 41028; break; case '5': $this->_ERROR_CODE = 41030; break; case '99': $this->_ERROR_CODE = 41029; break; default: $this->_ERROR_CODE = $dab_rs; } $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); $mdb = initWriteDB(); $query = sprintf("CALL sp_updateBuyingOrderFromPendingToDenied(%u, '%s') ", $result, $dab_rs); $log[] = sprintf('%s', $query); $status_rs = $mdb->extended->getRow($query); $mdb->disconnect(); if (empty($status_rs)) { $this->_ERROR_CODE = 30144; } else { $result = $status_rs['varerror']; if ($result < 0) { //update Order Status fail switch ($result) { case '-1': $this->_ERROR_CODE = 30145; break; case '-2': $this->_ERROR_CODE = 30146; break; } //switch } // if } // if WS $log[] = sprintf('ERROR_CODE: %s', $this->_ERROR_CODE); } } } // -------------------------------------------------------------------------------------- // // End Insert buy order for $AccountNo // -------------------------------------------------------------------------------------- // } $this->items[0] = new SOAP_Value('item', $struct, array("BuyingOrderID" => new SOAP_Value("BuyingOrderID", "string", $buyingOrderID), "SellingOrderID" => new SOAP_Value("SellingOrderID", "string", $sellingOrderID))); } catch (Exception $e) { $log[] = sprintf('Exception: %s', $e->getMessage()); $this->_ERROR_CODE = 30060; } } write_my_log_path("insertCoSellOrder", implode("\n --> ", $log), '/home/vhosts/eSMS/htdocs/logs/otc/'); return returnXML(func_get_args(), $this->class_name, $function_name, $this->_ERROR_CODE, $this->items, $this); }