Example #1
0
 /**
  * Adds new owner to ebls_owner table
  *
  */
 function add()
 {
     if ($this->m_dbLink) {
         if (($error_num = $this->validateData()) > 0) {
             ebpls_start_transaction($this->m_dbLink);
             $this->data_elems[OWNER_REG_DATE] = date("Y-d-m H:i:s");
             $this->data_elems[OWNER_LASTUPDATED] = date("Y-d-m H:i:s");
             $strValues = $this->data_elems;
             $this->debug("DATE : " . $this->data_elems[OWNER_REG_DATE]);
             $ret = ebpls_insert_data($this->m_dbLink, EBPLS_OWNER_TABLE, $strValues);
             if ($ret < 0) {
                 $this->debug("CREATE OWNER FAILED [error:{$ret},msg=" . get_db_error() . "]");
                 $this->setError($ret, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
                 return $ret;
             } else {
                 $this->debug("CREATE OWNER SUCCESSFULL [{$ret}]");
                 $this->data_elems[OWNER_ID] = $ret;
                 ebpls_commit_transaction($this->m_dbLink);
                 return $ret;
             }
         } else {
             $this->debug("CREATE OWNER FAILED [error:{$ret},msg=" . get_db_error() . "]");
             return $error_num;
         }
     } else {
         $this->debug("CREATE OWNER FAILED INVALID DB LINK {$this->m_dbLink}");
         $this->setError($ret, "Invalid Db link {$this->m_dbLink}");
         return -1;
     }
 }
 function setTransactionStatus($trans_id, $status, $creator, $user_level)
 {
     switch ($status) {
         case TRANS_STATUS_ASSESSMENT:
             if ($user_level != TRANS_LEVEL_APPLICATION_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("setTransactionStatus Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "setTransactionStatus Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("setTransactionStatus Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "setTransactionStatus Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_APPLICATION) {
                 $this->debug("setTransactionStatus Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "setTransactionStatus Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // NOTE : additional checking should be done here if all requirements have been submitted
             $pen_req_list = $this->getRequirementList(REQUIREMENT_STATUS_PENDING);
             //print_r($pen_req_list);
             if ($pen_req_list != -1 && count($pen_req_list) > 0) {
                 $this->debug("setTransactionStatus Failed, pending requirements not yet submitted.");
                 $this->setError(-1, "setTransactionStatus Failed, pending requirements not yet submitted.");
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $ass_code = get_next_system_code($this->m_dbLink, CODES_ASS_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_ASSESSMENT;
             $strValue[TRANS_ASSESSMENT_CODE] = $ass_code;
             $strValue[TRANS_ASSESSMENT_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_APPLICATION_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_ASS_COL, $ass_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_PAYMENT:
             if ($user_level != TRANS_LEVEL_ASSESSMENT_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("assessTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "assessTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("assessTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "assessTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_ASSESSMENT) {
                 $this->debug("assessTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "assessTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // NOTE : check if payment mode have beens set
             if (!$this->isPaymentModeSet()) {
                 $this->setError(-1, "Payment not yet set, please set payment mode before setting transaction for payment status.");
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $pay_code = get_next_system_code($this->m_dbLink, CODES_PAY_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_PAYMENT;
             $strValue[TRANS_PAYMENT_CODE] = $pay_code;
             $strValue[TRANS_PAYMENT_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_ASSESSMENT_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_PAY_COL, $pay_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_APPROVAL:
             if ($user_level != TRANS_LEVEL_PAYMENT_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("paymentTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "paymentTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("paymentTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "paymentTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_PAYMENT) {
                 $this->debug("paymentTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "paymentTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             //
             ebpls_start_transaction($this->m_dbLink);
             $apr_code = get_next_system_code($this->m_dbLink, CODES_APR_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_APPROVAL;
             $strValue[TRANS_APPROVAL_CODE] = $apr_code;
             $strValue[TRANS_APPROVAL_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_PAYMENT_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_APR_COL, $apr_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_RELEASING:
             if ($user_level != TRANS_LEVEL_APPROVAL_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("approveTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "approveTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("approveTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "approveTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_APPROVAL) {
                 $this->debug("setStatusForReleasing Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "setStatusForReleasing Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $rel_code = get_next_system_code($this->m_dbLink, CODES_REL_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_RELEASING;
             $strValue[TRANS_RELEASE_CODE] = $rel_code;
             $strValue[TRANS_RELEASE_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_APPROVAL_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_REL_COL, $rel_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_RELEASED:
         case TRANS_STATUS_REJECTED:
             if ($user_level != TRANS_LEVEL_RELEASING_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("releaseTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "releaseTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("releaseTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "releaseTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_RELEASING) {
                 $this->debug("releaseTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "releaseTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // get permit no
             $permit_type = $this->getPermitType();
             $permit_id = $this->getPermitId();
             switch ($permit_type) {
                 case PERMIT_TYPE_BUSINESS:
                     $key = CODES_PERMIT_BUS_COL;
                     break;
                 case PERMIT_TYPE_OCCUPATIONAL:
                     $key = CODES_PERMIT_OCCUPATIONAL_COL;
                     break;
                 case PERMIT_TYPE_PEDDLER:
                     $key = CODES_PERMIT_PEDDLER_COL;
                     break;
                 case PERMIT_TYPE_FRANCHISE:
                     $key = CODES_PERMIT_FRANCHISE_BUS_COL;
                     break;
                 case PERMIT_TYPE_MOTORIZED:
                     $key = CODES_PERMIT_MOTORIZED_COL;
                     break;
                 case PERMIT_TYPE_FISHERY:
                     $key = CODES_PERMIT_FISHERY_COL;
                     break;
                 default:
                     $this->debug("Invalid Transaction permit type {$permit_type}, can't process release of transaction.");
                     return -1;
                     break;
             }
             ebpls_start_transaction($this->m_dbLink);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = $status;
             $strValue[TRANS_RELEASE_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             if ($status == TRANS_STATUS_RELEASED && ($this->getData(TRANS_TYPE) == TRANS_TYPE_NEW || $this->getData(TRANS_TYPE) == TRANS_TYPE_RENEW)) {
                 $permit_code = get_next_system_code($this->m_dbLink, $key);
                 $strValue[TRANS_PERMIT_CODE] = $permit_code;
             }
             // use ebplsPermit as a factory class to retrieve proper class reference with the right type
             // of EBPLSPermit subclass
             $clsPermit = new EBPLSPermit($this->m_dbLink, false);
             $clsPermitToUpdate = $clsPermit->createPermit($this->m_dbLink, $permit_id, $permit_type, false);
             if ($clsPermitToUpdate != null) {
                 // update transaction with permit code of permit
                 $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
                 if ($ret < 0) {
                     $this->debug("Promotion of transaction to {$status} stage failed.");
                     $this->setError(-1, get_db_error());
                     ebpls_rollback_transaction($this->m_dbLink);
                 } else {
                     // update permit of table
                     $clsPermitToUpdate->assignPermitCode($permit_code);
                     if ($status == TRANS_STATUS_RELEASED && ($this->getData(TRANS_TYPE) == TRANS_TYPE_NEW || $this->getData(TRANS_TYPE) == TRANS_TYPE_RENEW)) {
                         $ret_app_code = update_system_code($this->m_dbLink, $key, $permit_code);
                     }
                     $this->debug("Promotion of transaction to {$status} stage ok.");
                 }
                 // set permit status
                 if ($permit_type == PERMIT_TYPE_BUSINESS) {
                     $clsBus = new EBPLSEnterprise($this->m_dbLink);
                     $clsBus->_updateBusinessNatureApplication($nature_code, NULL, NULL, NULL, "PROCESSED");
                 }
                 ebpls_commit_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to {$status} stage failed, unable to create class permit to assigne permit code.");
                 ebpls_rollback_transaction($this->m_dbLink);
             }
             break;
         default:
             $this->debug("Unrecognized status {$status} value passed.");
             break;
     }
     $this->data_elem[TRANS_TRANSACTION_STATUS] = $status;
     return $ret;
 }