Exemple #1
0
 /**
  * saveTransactionDB saves data to Transactions table in db
  * @return bool db Success or Failure 
  */
 protected function saveTransactionsDB($TRX = FALSE)
 {
     $tbl = new Application_Model_DbTable_Transactions(Np_Db::master());
     if ($TRX != FALSE) {
         $trxNo = $TRX;
     } else {
         $trxNo = $this->request->getHeaderField("TRX_NO");
     }
     $msgType = $this->request->getHeaderField("MSG_TYPE");
     $portTime = $this->request->getBodyField('PORT_TIME');
     $rejectReasonCode = $this->request->getRejectReasonCode();
     $reqId = $this->request->getHeaderField('REQUEST_ID');
     if ($trxNo) {
         $data = array('trx_no' => $trxNo, 'request_id' => $reqId, 'message_type' => $msgType, 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO"));
         if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") {
             // do nothing
         } else {
             $data['reject_reason_code'] = $rejectReasonCode;
         }
         if ($msgType == "Update" || $msgType == "Request") {
             $data['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime);
         }
         if ($msgType == "Publish") {
             $data['donor'] = Application_Model_General::getDonorByReqId($reqId);
         }
         $res = $tbl->insert($data);
         return $res;
     } else {
         //this request if from internal - have to add trx_no
         //save to Transactions table trx_no  has to be consisten to id of the table
         $adapter = $tbl->getAdapter();
         $adapter->beginTransaction();
         try {
             $temp_trx_no = Application_Model_General::createRandKey(14);
             if (isset($this->data['request_id'])) {
                 $reqId = $this->data['request_id'];
             }
             $row_insert = array('trx_no' => $temp_trx_no, 'request_id' => $reqId, 'message_type' => $this->request->getHeaderField("MSG_TYPE"), 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO"));
             if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") {
                 // do nothing
             } else {
                 $row_insert['reject_reason_code'] = $rejectReasonCode;
             }
             if ($msgType == "Update" || $msgType == "Request" || $msgType == "Check" && Application_Model_General::isAutoCheck($reqId)) {
                 $row_insert['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime);
             }
             if ($msgType == "Publish") {
                 $row_insert['donor'] = Application_Model_General::getDonorByReqId($reqId);
             }
             $_id = $tbl->insert($row_insert);
             $id = substr("00000000000" . $_id, -12, 12);
             $trx_no = Application_Model_General::getSettings('InternalProvider') . $id;
             $ret = $tbl->update(array('trx_no' => $trx_no), "id = " . $_id);
             $this->request->setTrxNo($trx_no);
             $adapter->commit();
             return true;
         } catch (Exception $e) {
             error_log("Error on create record in transactions table: " . $e->getMessage());
             $adapter->rollBack();
             return false;
         }
     }
 }