Exemple #1
0
 public static function CreateProject($data)
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     $current_user = ProNav_Auth::getUserID();
     //get corporation level detail to copy over.
     $corp = Application_Model_Corporations::GetCorporationRow($data['done_for_corporation']);
     $data['acct_tax_exempt'] = $corp->tax_exempt;
     $project = array('done_for_corporation' => $data['done_for_corporation'], 'done_for_workgroup' => $data['done_for_workgroup'], 'done_at_location' => $data['done_at_location'], 'title' => $data['title'], 'scope' => $data['scope'], 'done_by_workgroup' => $data['done_by_workgroup'], 'stage_id' => $data['stage_id'], 'bill_type' => $data['bill_type'] ? $data['bill_type'] : new Zend_Db_Expr("NULL"), 'status' => 0, 'po_number' => $data['po_number'] ? $data['po_number'] : new Zend_Db_Expr("NULL"), 'po_date' => ProNav_Utils::toMySQLDate($data['po_date']), 'po_amount' => $data['po_amount'] ? $data['po_amount'] : new Zend_Db_Expr("NULL"), 'ref_no' => $data['ref_no'] ? $data['ref_no'] : new Zend_Db_Expr("NULL"), 'schedule_estimated_start' => ProNav_Utils::toMySQLDate($data['schedule_estimated_start']), 'schedule_estimated_end' => ProNav_Utils::toMySQLDate($data['schedule_estimated_end']), 'schedule_modified_by' => $data['schedule_not_before'] || $data['schedule_required_by'] ? $current_user : new Zend_Db_Expr("NULL"), 'schedule_modified' => $data['schedule_not_before'] || $data['schedule_required_by'] ? new Zend_Db_Expr("NOW()") : new Zend_Db_Expr("NULL"), 'work_type' => $data['work_type'] ? $data['work_type'] : new Zend_Db_Expr("NULL"), 'point_of_contact' => $data['point_of_contact'] ? $data['point_of_contact'] : new Zend_Db_Expr("NULL"), 'acct_tax_exempt' => $data['acct_tax_exempt'], 'requested_by' => $data['requested_by'] ? $data['requested_by'] : new Zend_Db_Expr("NULL"), 'acq_sales_person' => $data['acq_sales_person'] ? $data['acq_sales_person'] : new Zend_Db_Expr('NULL'), 'acq_probability' => $data['acq_probability'] == -1 ? new Zend_Db_Expr('NULL') : $data['acq_probability'], 'acq_booking_month' => $data['acq_booking_month'] == -1 ? new Zend_Db_Expr('NULL') : $data['acq_booking_month'], 'acq_booking_year' => $data['acq_booking_year'] == -1 ? new Zend_Db_Expr('NULL') : $data['acq_booking_year'], 'acq_estimator' => $data['acq_estimator'] ? $data['acq_estimator'] : new Zend_Db_Expr('NULL'), 'acq_pre_bid_mandatory' => $data['acq_pre_bid_mandatory'] == '1' ? '1' : ($data['acq_pre_bid_mandatory'] == '0' ? 0 : new Zend_Db_Expr('NULL')), 'acq_pre_bid_date' => ProNav_Utils::toMySQLDate($data['acq_pre_bid_date']), 'acq_bid_date' => ProNav_Utils::toMySQLDate($data['acq_bid_date']), 'acq_bid_review_meeting' => ProNav_Utils::toMySQLDate($data['acq_bid_review_meeting']), 'acq_estimating_hours' => is_numeric($data['acq_estimating_hours']) ? $data['acq_estimating_hours'] : new Zend_Db_Expr('NULL'), 'acct_billing_address1' => $corp->billing_address1, 'acct_billing_address2' => $corp->billing_address2, 'acct_billing_city' => $corp->billing_city, 'acct_billing_state' => $corp->billing_state, 'acct_billing_state' => $corp->billing_state, 'acct_billing_zip' => $corp->billing_zip, 'acct_billing_phone' => $corp->billing_phone, 'acct_billing_contact' => $corp->billing_contact, 'acct_billing_notes' => $corp->billing_notes, 'created_by' => $current_user, 'created_date' => new Zend_Db_Expr("NOW()"));
     $db->insert('projects', $project);
     $new_project_id = $db->lastInsertId();
     if ($data['stage_id'] == ProNav_Utils::STAGE_OPEN) {
         $overall_status = Application_Model_ProjectTask::get_overall_task($new_project_id);
         $overall_status->add_new_status(Application_Model_ProgressOption::STATUS_TASK_STARTED);
     }
     //insert into the stage audit table
     $stage = array('project_id' => $new_project_id, 'stage_id' => $data['stage_id'], 'comment' => $data['comment'], 'entered_by' => $current_user, 'entered_date' => new Zend_Db_Expr("NOW()"));
     $db->insert('project_stage_audit', $stage);
     //If user is not an employee we need to append employees to the project watch list.
     //Per their subscriptions -- This cannot be modified by the client at project creation.
     if (!ProNav_Auth::isEmployee()) {
         $queue = new stdClass();
         $queue->project_id = -1;
         $queue->event_type = ProNav_Notification::EVENT_PROJECT_CREATED;
         $queue->only_action = ProNav_NotificationProject::ACTION_ADD_TO_TEAM;
         $queue->done_for_corporation = $data['done_for_corporation'];
         $queue->done_for_workgroup = $data['done_for_workgroup'];
         $queue->done_by_workgroup = $data['done_by_workgroup'];
         $queue->done_at_location = $data['done_at_location'];
         $queue->location_owner = $data['location_owner'];
         $oNotifyQ = new ProNav_NotificationProject($queue);
         $subscribers = $oNotifyQ->getSubscribers();
         foreach ($subscribers as $user) {
             if ($user->corporation_id == ProNav_Utils::TriMId) {
                 $data['team'][] = $user->user_id;
             }
         }
     }
     //insert to the project team table
     foreach ($data['team'] as $user_id) {
         $db->query("CALL add_user_to_team(?, ?, ?)", array($user_id, $new_project_id, $current_user))->execute();
     }
     ProNav_Utils::registerEvent($new_project_id, ProNav_Notification::EVENT_PROJECT_CREATED, $data['stage_id'], $current_user, new Zend_Db_Expr('Now()'));
     return $new_project_id;
 }