public function updateStageAction() { $project_id = $this->_getParam('id'); $data = Zend_Json::decode($this->_getParam('data')); $to_stage_override = $data['edit_hold_stage_override']; $to_stage = $this->_getParam('to_stage'); $from_stage = $this->_getParam('from_stage'); $result = array('status' => 0); $projectinfo_orig = Application_Model_Projects::GetProjectInfo($project_id); //for the 'release from hold' operation, the user can override the to_stage with their own selection. if (is_numeric($to_stage_override)) { $to_stage = $to_stage_override; } $data['to_stage'] = $to_stage; $data = ProNav_Utils::stripTagsAndTrim($data); if (!is_numeric($to_stage) || !is_numeric($from_stage)) { echo Zend_Json::encode(array('errors' => array('Unrecognized Action. Please Try Again.'))); return; } if ($to_stage == $from_stage && $to_stage != ProNav_Utils::STAGE_PROPOSED) { echo Zend_Json::encode(array('errors' => array('Cannot update a project into the same stage.'))); return; } if ($data['comment'] == '' && ($data['to_stage'] == ProNav_Utils::STAGE_HOLD || $data['to_stage'] == ProNav_Utils::STAGE_CANCELLED)) { echo Zend_Json::encode(array('errors' => array('A Comment is Required.'))); return; } if (!ProNav_Auth::isEmployee() && $to_stage == ProNav_Utils::STAGE_AUTHORIZED && !$data['authorization_type']) { echo Zend_Json::encode(array('errors' => array('An Authorization Selection Is Required'))); return; } if ($to_stage == ProNav_Utils::STAGE_PROPOSED) { if (!is_numeric($data['bill_type']) || is_numeric($data['bill_type']) && $data['bill_type'] < 1) { echo Zend_Json::encode(array('errors' => array('A Propsal Type Selection is Required.'))); return; } } if ($to_stage == ProNav_Utils::STAGE_CLOSED || $to_stage == ProNav_Utils::STAGE_CANCELLED) { $closeChecks = Application_Model_Projects::getCloseDetails($project_id); $errors = array(); if ($to_stage == ProNav_Utils::STAGE_CLOSED) { if ($closeChecks->current_status_percent != Application_Model_ProgressOption::STATUS_TASK_COMPLETE) { $errors[] = "The project's overall status must be set to 100% before it can be closed."; } } if ($closeChecks->invalid_cor_state) { $errors[] = "Project cannot be closed with outstanding Change Order Requests."; } /* Doesn't exist in close checks? if($closeChecks->unapproved_co) { $errors[] = "All Change Orders must be executed first."; } */ if (count($errors) > 0) { echo Zend_Json::encode(array('errors' => $errors)); return; } } //set the project manager to null if it exists and it is not a number. if ($to_stage == ProNav_Utils::STAGE_OPEN && array_key_exists('acct_project_manager', $data) && !is_numeric($data['acct_project_manager'])) { $data['acct_project_manager'] = null; } if (isset($data['done_for_corporation']) && $data['done_for_corporation'] != $projectinfo_orig->done_for_corporation) { //Get limited billing information from the corporation (most was set in dialog). $billing = Application_Model_Corporations::getBillingInfo($data['done_for_corporation']); $data['acct_billing_contact'] = $billing['billing_contact']; $data['acct_billing_phone'] = $billing['billing_phone']; } Application_Model_Projects::UpdateStage($project_id, $data); $projectinfo = Application_Model_Projects::GetProjectInfo($project_id); if (isset($data['acct_billing_address1']) && ProNav_Auth::hasPerm(ProNav_Auth::PERM_CORPORATIONS_ADD_EDIT)) { //Determine if you should prompt the user to update the corp billing info. $fields_to_update = $this->getEligibleBillingFieldsForCorpUpdate($data, $projectinfo_orig, $projectinfo); if (count($fields_to_update) > 0) { $result['offer_save_billing'] = $fields_to_update; } } $result['status'] = 1; $this->getResponse()->setBody(Zend_Json::encode($result)); }