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;
 }
 /** Project Team **/
 public function getInitialProjectTeamMembersAction()
 {
     //preempt the notification_queue to get the project teams right away
     $dfc = $this->_getParam('done_for_corporation', -1);
     $dfw = $this->_getParam('done_for_workgroup', -1);
     $dbw = $this->_getParam('done_by_workgroup', -1);
     $dal = $this->_getParam('done_at_location', -1);
     $dlo = $this->_getParam('location_owner', -1);
     $stage = $this->_getParam('stage_id', -1);
     $authorization = $this->_getParam('authorization', -1);
     //set values for clients
     if (!ProNav_Auth::isEmployee()) {
         $dfc = ProNav_Auth::getCorporationID();
         $dlo = ProNav_Auth::getCorporationID();
         $depts = ProNav_Auth::getDepartments();
         if (count($depts) < 1) {
             echo 'No User Workgroups';
             die;
         }
         if (!in_array($dfw, $depts)) {
             $dfw = $depts[0];
         }
     }
     $errs = array();
     //check values.
     if (!is_numeric($dfc) || $dfc < 1) {
         $errs[] = 'Please Select a Customer.';
     }
     if (!is_numeric($dfw) || $dfw < 1) {
         $errs[] = 'Please Select a Workgroup.';
     }
     if (!is_numeric($dlo) || $dlo < 1) {
         $errs[] = 'Please Select a Location Owner.';
     }
     if (!is_numeric($dal) || $dal < 1) {
         $errs[] = 'Please Select a Location.';
     } else {
         if (!Application_Model_Corporations::hasLocation($dal, $dlo)) {
             $errs[] = 'Unknown Location Selected.';
         }
     }
     if (!is_numeric($dbw) || $dbw < 1) {
         $errs[] = 'Please Select a Business Unit.';
     }
     if (!ProNav_Auth::isEmployee() && ($authorization != ProNav_Utils::STAGE_AUTHORIZED && $authorization != ProNav_Utils::STAGE_RFP)) {
         $errs[] = 'Please specify whether you are authorizing a time & material project or requesting a proposal.';
     } else {
         if (!is_numeric($stage) || $stage < 1) {
             $errs[] = 'Please Select A Project Stage.';
         }
     }
     if (count($errs) > 0) {
         echo Zend_Json::encode(array('state' => 0, 'msgs' => $errs));
         die;
     }
     //get the list of all users for the given corporation (we will remove some later).
     //put them in the format expected by the ajax call.
     $offUsers = Application_Model_Projects::getProjectTeamAvailable(-1, $dfc, $dfw);
     $offUsers_2 = array();
     foreach ($offUsers as $user) {
         $offUsers_2[$user->user_id] = array("user_id" => $user->user_id, "name" => $user->getFormattedName(Application_Model_User::LFMI), "corporation_id" => $user->Corporation->corporation_id, "corporation" => $user->Corporation->name, "assigned" => 0, "pronav_access" => $user->pronav_access);
     }
     //dip into the notification queue for the list of subscribers.
     //This code here was a refactoring - which is why we are dipping into the notificaton queue.
     $np = new ProNav_NotificationProject();
     $queue = new stdClass();
     $queue->event_type = ProNav_Notification::EVENT_PROJECT_CREATED;
     $queue->event_value = $stage;
     $queue->only_action = ProNav_NotificationProject::ACTION_ADD_TO_TEAM;
     $queue->done_for_corporation = $dfc;
     $queue->done_for_workgroup = $dfw;
     $queue->done_by_workgroup = $dbw;
     $queue->done_at_location = $dal;
     $queue->location_owner = $dlo;
     $np->setQueue($queue);
     $onUsers = $np->getSubscribers(true);
     $onUsers_2 = array();
     foreach ($onUsers as $user) {
         if (!ProNav_Auth::isEmployee() && $user->corporation_id == ProNav_Utils::TriMId) {
             continue;
         }
         $onUsers_2[$user->user_id] = array("user_id" => $user->user_id, "name" => $user->lastname . ', ' . $user->firstname, "corporation_id" => $user->corporation_id, "corporation" => $user->name, "assigned" => 1, "pronav_access" => $user->pronav_access);
         //remove the user from the offUsers list, if they are found in the subscribers list.
         unset($offUsers_2[$user->user_id]);
     }
     //add the current user to the onUsers list.
     $currentUser = Application_Model_Users::getUser(ProNav_Auth::getUserID());
     $onUsers_2[] = array('user_id' => $currentUser->user_id, 'name' => $currentUser->getFormattedName(Application_Model_User::LFMI), 'corporation_id' => $currentUser->corporation_id, 'corporation' => $currentUser->corporation_name, 'assigned' => 1, 'pronav_access' => $currentUser->pronav_access);
     echo Zend_Json::encode(array('state' => 1, 'users' => array_merge($onUsers_2, $offUsers_2)));
 }