예제 #1
0
 public static function UpdateStage($project_id, $data)
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     $current_user = ProNav_Auth::getUserID();
     $orig = self::getPrevStageInfo($project_id);
     $from_stage = $orig->stage_id;
     $stage_before_from_stage = $orig->prev_stage_id ? $orig->prev_stage_id : ProNav_Utils::STAGE_OPEN;
     $update_data = array();
     $update_data['stage_id'] = $data['to_stage'] == -1 ? $stage_before_from_stage : $data['to_stage'];
     //-1 is release from hold
     //All the fields that could be in the data array.
     //Only operates on them if the key exists in the $data array.
     //As not all fields are always present and we do not want to clear existing fields that are not present.
     //key, type, default value.
     $possible_flds = array(array('done_for_corporation', 1), array('done_for_workgroup', 1), array('point_of_contact', 1), array('po_number', 0), array('po_amount', 2), array('po_date', 3), array('bill_type', 1), array('schedule_estimated_start', 3), array('schedule_estimated_end', 3), array('acct_estimated_cost', 2), array('acct_retainage', 0), array('acct_prevailing_wage', 4), array('acct_tax_exempt', 4), array('acct_billing_address1', 0), array('acct_billing_address2', 0), array('acct_billing_city', 0), array('acct_billing_state', 1), array('acct_billing_zip', 0), array('acct_billing_notes', 0), array('acct_billing_contact', 0), array('acct_billing_phone', 0), array('acct_invoice_type', 1), array('acct_billing_date', 1), array('acct_cert_of_ins_req', 4), array('acct_ocip', 4), array('acct_performance_bond_req', 4), array('acct_permit_req', 4), array('acct_project_type', 1), array('acct_project_value', 2), array('acct_project_manager', 1), array('job_no', 0));
     foreach ($possible_flds as $fld) {
         $key = $fld[0];
         $type = $fld[1];
         $default_val = count($fld) == 3 ? $fld[2] : new Zend_Db_Expr('NULL');
         if (array_key_exists($key, $data)) {
             $val = $data[$key];
             switch ($type) {
                 case 1:
                     //Numbers
                     if (is_numeric($val) && $val > 0) {
                         $update_data[$key] = $val;
                     } else {
                         $update_data[$key] = $default_val;
                     }
                     break;
                 case 2:
                     //Formatted Numbers
                     $val = ProNav_Utils::stripFormattedNumbers($val);
                     if (is_numeric($val)) {
                         $update_data[$key] = $val;
                     } else {
                         $update_data[$key] = $default_val;
                     }
                     break;
                 case 3:
                     //Dates
                     if ($val) {
                         $update_data[$key] = ProNav_Utils::toMySQLDate($val, true);
                     } else {
                         $update_data[$key] = $default_val;
                     }
                     break;
                 case 4:
                     //Boolean
                     $update_data[$key] = $val == '1' ? 1 : 0;
                     break;
                 default:
                     //Text
                     $val = trim($val);
                     if ($val) {
                         $update_data[$key] = $val;
                     } else {
                         $update_data[$key] = $default_val;
                     }
                     break;
             }
         }
     }
     $comment = $data['comment'];
     $db->update('projects', $update_data, $db->quoteInto('project_id = ?', $project_id));
     //if this is the first time you are going into the open stage, then set the status percent to 'started'.
     if ($data['stage_id'] == ProNav_Utils::STAGE_OPEN && !Application_Model_Projects::hasBeenInStage($project_id, ProNav_Utils::STAGE_OPEN)) {
         $overall = Application_Model_ProjectTask::get_overall_task($project_id);
         $overall->add_new_status(Application_Model_ProgressOption::STATUS_TASK_STARTED, 'Project Opened');
     }
     $resubmit = $data['resubmit'] ? 1 : 0;
     //stage audit
     if ($orig->stage_id != $update_data['stage_id'] || $resubmit == 1) {
         $stage = array('project_id' => $project_id, 'stage_id' => $update_data['stage_id'], 'comment' => $comment, 'entered_by' => $current_user, 'entered_date' => new Zend_Db_Expr("NOW()"));
         $db->insert('project_stage_audit', $stage);
         if ($orig->stage_id == ProNav_Utils::STAGE_POTENTIAL) {
             if ($update_data['stage_id'] != ProNav_Utils::STAGE_CANCELLED) {
                 ProNav_Utils::registerEvent($project_id, 1, $update_data['stage_id'], $current_user, new Zend_Db_Expr('Now()'));
             }
         } else {
             ProNav_Utils::registerEvent($project_id, 2, $update_data['stage_id'], $current_user, new Zend_Db_Expr('Now()'));
         }
     }
 }
예제 #2
0
 public function commitAccountingAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     $project_id = Zend_Filter_Digits::filter($data["project_id"]);
     //Used to determine if billing items changed, prompted later below.
     $projectinfo_orig = Application_Model_Projects::GetProjectInfo($project_id);
     $data["project_id"] = $project_id;
     ProNav_Utils::WhiteListArray($data, array('project_id', 'bill_type', 'po_amount', 'po_date', 'schedule_estimated_start', 'schedule_estimated_end', 'acct_project_value', 'acct_invoice_type', 'acct_ocip', 'id', 'acct_retainage', 'acct_prevailing_wage', 'acct_tax_exempt', 'acct_cert_of_ins_req', 'acct_performance_bond_req', 'acct_permit_req', 'acct_project_type', 'acct_billed_to_date', 'acct_estimated_cost', 'acct_comment', 'po_number', 'job_no', 'acct_project_manager', 'acct_project_engineer', 'acct_field_staff_leader', 'acct_billing_date', 'acct_billing_address1', 'acct_billing_address2', 'acct_billing_city', 'acct_billing_state', 'acct_billing_zip', 'acct_billing_contact', 'acct_billing_phone', 'acct_billing_notes'));
     $data = ProNav_Utils::stripTagsAndTrim($data);
     $data["bill_type"] = is_numeric($data["bill_type"]) ? $data["bill_type"] : -1;
     $data["po_amount"] = ProNav_Utils::stripFormattedNumbers($data["po_amount"]);
     $data["po_date"] = ProNav_Utils::toMySQLDate($data["po_date"]);
     $data["acct_project_value"] = ProNav_Utils::stripFormattedNumbers($data["acct_project_value"]);
     $data["acct_invoice_type"] = is_numeric($data["acct_invoice_type"]) ? $data["acct_invoice_type"] : -1;
     $data["acct_prevailing_wage"] = $data["acct_prevailing_wage"] == 1 ? 1 : 0;
     $data["acct_tax_exempt"] = $data["acct_tax_exempt"] == 1 ? 1 : 0;
     $data["acct_ocip"] = $data["acct_ocip"] == 1 ? 1 : 0;
     $data["acct_cert_of_ins_req"] = $data["acct_cert_of_ins_req"] == 1 ? 1 : 0;
     $data["acct_performance_bond_req"] = $data["acct_performance_bond_req"] == 1 ? 1 : 0;
     $data["acct_permit_req"] = $data["acct_permit_req"] == 1 ? 1 : 0;
     $data["acct_project_type"] = is_numeric($data["acct_project_type"]) ? $data["acct_project_type"] : 1;
     $data["acct_billed_to_date"] = ProNav_Utils::stripFormattedNumbers($data["acct_billed_to_date"]);
     $data["acct_estimated_cost"] = ProNav_Utils::stripFormattedNumbers($data["acct_estimated_cost"]);
     $data["acct_project_manager"] = is_numeric($data["acct_project_manager"]) ? $data["acct_project_manager"] : null;
     $data["acct_project_engineer"] = is_numeric($data["acct_project_engineer"]) ? $data["acct_project_engineer"] : null;
     $data["acct_field_staff_leader"] = is_numeric($data["acct_field_staff_leader"]) ? $data["acct_field_staff_leader"] : null;
     $data['acct_billing_date'] = $data['acct_billing_date'] && is_numeric($data['acct_billing_date']) ? $data['acct_billing_date'] : null;
     $data["acct_billing_state"] = is_numeric($data["acct_billing_state"]) ? $data["acct_billing_state"] : null;
     $data['schedule_estimated_start'] = ProNav_Utils::toMySQLDate($data['schedule_estimated_start'], false);
     $data['schedule_estimated_end'] = ProNav_Utils::toMySQLDate($data['schedule_estimated_end'], false);
     ProNav_Utils::scrubArray($data, true, false);
     $data["acct_modified_by"] = ProNav_Auth::getUserID();
     $data["acct_modified_date"] = new Zend_Db_Expr("NOW()");
     $result = Application_Model_Projects::updateProject($data);
     //The updated project data.
     $projectinfo = Application_Model_Projects::GetProjectInfo($project_id);
     $cors = Application_Model_ChangeOrders::getRequestsForProject($project_id, true, true);
     $executed_cors = array();
     foreach ($cors as $cor) {
         if ($cor->accounting_stage_id == Application_Model_ChangeOrderRequest::ACCT_EXECUTED) {
             $executed_cors[] = $cor;
         }
     }
     $jOut = array();
     if (!$result) {
         $jOut['status'] = 0;
     } else {
         $jOut['status'] = 1;
         $jOut['accounting'] = $this->view->partial('project/accounting.phtml', array('projectinfo' => $projectinfo));
         $jOut['general'] = $this->view->partial('project/partial-general-info.phtml', array('projectinfo' => $projectinfo, 'open_projects' => Application_Model_Projects::OpenProjectsCountAtLocation($projectinfo->done_at_location, $project_id), 'active_projects' => Application_Model_Projects::ActiveProjectsCountAtLocation($projectinfo->done_at_location, $project_id)));
         $jOut['value'] = $this->view->partial('project/partial-project-value.phtml', array('base_project' => $projectinfo, 'original_contract_value' => $projectinfo->getProjectValue(), 'has_executed_cos' => count($executed_cors), 'executed_cos_value' => Application_Model_ChangeOrders::sumProjectValue($executed_cors), 'total_contract_value' => Application_Model_ChangeOrders::sumProjectValue($executed_cors, $projectinfo)));
         //Determine if you should prompt the user to update the corp billing info.
         if (ProNav_Auth::hasPerm(ProNav_Auth::PERM_CORPORATIONS_ADD_EDIT)) {
             $fields_to_update = $this->getEligibleBillingFieldsForCorpUpdate($data, $projectinfo_orig, $projectinfo);
             if (count($fields_to_update) > 0) {
                 $jOut['offer_save_billing'] = Zend_Json::encode($fields_to_update);
             }
         }
     }
     echo Zend_Json_Encoder::encode($jOut);
 }