grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 */ if (!defined('sugarEntry') || !sugarEntry) { die('Not A Valid Entry Point'); } class ProjectController extends SugarController { //Loads the gantt view public function action_view_GanttChart() { $this->view = 'GanttChart'; } public function action_generate_chart() { $db = DBManagerFactory::getInstance(); include_once('modules/Project/gantt.php'); include_once('modules/Project/project_table.php'); $project = new Project(); $project->retrieve($_POST["pid"]); //Get project tasks $Task = BeanFactory::getBean('ProjectTask'); $tasks = $Task->get_full_list("order_number", "project_task.project_id = '".$project->id."'"); //Get the start and end date of the project in database format $query = "SELECT min(date_start) FROM project_task WHERE project_id = '{$project->id}'"; $start_date = $db->getOne($query); $query = "SELECT max(date_finish) FROM project_task WHERE project_id = '{$project->id}'"; $end_date = $db->getOne($query); $duration = $this->count_days($start_date, $end_date); if ($duration < 30) { $query = "SELECT max(date_finish) + INTERVAL " . (30 - $duration) . " DAY FROM project_task WHERE project_id = '{$project->id}'"; $end_date = $db->getOne($query); } ?>
getPreference('datef'); $startdate = DateTime::createFromFormat($dateformat, $_POST['start']); $start = $startdate->format('Y-m-d'); //Take 1 off duration so that task displays in correct number of table cells in gantt chart. $duration = $_POST['duration'] -1; $duration_unit = $_POST['unit']; //Compensate for resulting negative number when a 0 duration is passed in above if ($duration < 0) { $duration = 0; } //------ build business hours array $days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); $businessHours = BeanFactory::getBean("AOBH_BusinessHours"); $bhours = array(); foreach ($days as $day) { $bh = $businessHours->getBusinessHoursForDay($day); if ($bh) { $bh = $bh[0]; if ($bh->open) { $open_h = $bh ? $bh->opening_hours : 9; $close_h = $bh ? $bh->closing_hours : 17; $start_time = DateTime::createFromFormat($dateformat, $_POST['start']); $start_time = $start_time->modify('+'.$open_h.' Hours'); $end_time = DateTime::createFromFormat($dateformat, $_POST['start']); $end_time = $end_time->modify('+'.$close_h.' Hours'); $hours = ($end_time->getTimestamp() - $start_time->getTimestamp())/(60*60); if ($hours < 0) { $hours = 0 - $hours ; } //$hours = $bh->diffBusinessHours($start_time, $end_time); $bhours[$day] = $hours; } else { $bhours[$day] = 0; } } } //----------------------------------- //default business hours array if ($override_business_hours != 1 || empty($bhours)) { $bhours = array('Monday' => 8,'Tuesday' => 8,'Wednesday' => 8, 'Thursday' => 8, 'Friday' => 8, 'Saturday' => 0, 'Sunday' => 0); } //--------------------------- // //code block to calculate end date based on user's business hours // $enddate = $startdate; $h = 0; $d = 0; if ($duration_unit == 'Hours') { while ($duration > $h) { $day = $enddate->format('l'); $h += $bhours[$day]; $enddate = $enddate->modify('+1 Days'); } $enddate = $enddate->format('Y-m-d'); } else { while ($duration >= $d) { $day = $enddate->format('l'); if ($bhours[$day] != 0) { $d += 1; } $enddate = $enddate->modify('+1 Days'); } $enddate = $enddate->modify('-1 Days');//readjust it back to remove 1 additional day added $enddate = $enddate->format('Y-m-d'); } //---------------------------------- if ($percent > 0) { $status = 'In Progress'; } else { $status = 'Not Started'; } //count tasks $query = "SELECT COUNT(*) FROM project_task WHERE project_id = '{$project_id}' AND deleted = '0'"; $count = $db->getOne($query); $tid = $count+1; if ($this->IsNullOrEmptyString($task_id)) { $this->create_task($task_name, $start, $enddate, $project_id, $milestone_flag, $status, $tid, $predecessor, $rel_type, $duration, $duration_unit, $resource, $percent, $note, $actual_duration, $tid); } else { $this->update_task($task_id, $task_name, $start, $enddate, $project_id, $milestone_flag, $status, $predecessor, $rel_type, $duration, $duration_unit, $resource, $percent, $note, $actual_duration); } } //mark project task as deleted public function action_delete_task() { $id = $_POST['task_id']; $task = new ProjectTask(); $task->retrieve($id); $task->deleted = '1'; $task->save(); } //Returns new task start date including any lag via ajax call public function action_get_end_date() { global $timeDate; $db = DBManagerFactory::getInstance(); $timeDate = new TimeDate(); $id = $_POST['task_id']; $lag = $_POST['lag']; //Get the end date of the projectTask in raw database format $query = "SELECT date_finish FROM project_task WHERE id = '{$id}'"; $end_date = $db->getOne($query); //Add 1 day onto end date for first day of new task $start_date = date('Y-m-d', strtotime($end_date. ' + 1 days')); //Add lag onto start date $start_date = date('Y-m-d', strtotime($start_date. ' + '.$lag.' days')); echo $timeDate->to_display_date($start_date, true); die(); } //updates the order of the tasks public function action_update_order() { //convert quotes in json string back to normal $jArray = htmlspecialchars_decode($_POST['orderArray']); //create object/array from json data $orderArray = json_decode($jArray, true); foreach ($orderArray as $id => $order_number) { $task = new ProjectTask(); $task->retrieve($id); $task->order_number = $order_number; $task->save(); } } //returns tasks for predecessor in the add task pop-up form public function action_get_predecessors() { global $mod_strings; $project = new Project(); $project->retrieve($_REQUEST["project_id"]); //Get project tasks $Task = BeanFactory::getBean('ProjectTask'); $tasks = $Task->get_full_list("order_number", "project_task.project_id = '".$project->id."'"); echo ''; foreach ($tasks as $task) { echo '