コード例 #1
0
ファイル: Projects.php プロジェクト: rahullambaindia/pronav
 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 commitScheduleAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     $project_id = $data["project_id"];
     //convert the dates to valid mysql formats (they come in like "Tue 10/27/2010")
     foreach ($data as $key => $value) {
         if ($key == "project_id" || $value == "") {
             continue;
         }
         $data[$key] = ProNav_Utils::toMySQLDate($value);
     }
     $data["schedule_modified_by"] = ProNav_Auth::getUserID();
     $data["schedule_modified"] = new Zend_Db_Expr('NOW()');
     ProNav_Utils::scrubArray($data, true);
     if (Application_Model_Projects::updateProject($data)) {
         $projectinfo = Application_Model_Projects::GetProjectInfo($project_id);
         echo $this->view->partial('project/schedule.phtml', array('projectinfo' => $projectinfo));
     }
 }