Skip to content

Commit

Permalink
CLOSE Dolibarr#23331 Add support for parent projects (Dolibarr#24856)
Browse files Browse the repository at this point in the history
  • Loading branch information
mc2contributor authored Oct 20, 2023
1 parent 9361b12 commit 60fa585
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
62 changes: 62 additions & 0 deletions htdocs/projet/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
$date_start_event = dol_mktime(GETPOST('date_start_eventhour', 'int'), GETPOST('date_start_eventmin', 'int'), GETPOST('date_start_eventsec', 'int'), GETPOST('date_start_eventmonth', 'int'), GETPOST('date_start_eventday', 'int'), GETPOST('date_start_eventyear', 'int'));
$date_end_event = dol_mktime(GETPOST('date_end_eventhour', 'int'), GETPOST('date_end_eventmin', 'int'), GETPOST('date_end_eventsec', 'int'), GETPOST('date_end_eventmonth', 'int'), GETPOST('date_end_eventday', 'int'), GETPOST('date_end_eventyear', 'int'));
$location = GETPOST('location', 'alphanohtml');
$fk_project = GETPOST('fk_project', 'int');


$mine = GETPOST('mode') == 'mine' ? 1 : 0;
Expand Down Expand Up @@ -205,6 +206,7 @@
$db->begin();

$object->ref = GETPOST('ref', 'alphanohtml');
$object->fk_project = GETPOST('fk_project', 'int');
$object->title = GETPOST('title', 'alphanohtml');
$object->socid = GETPOST('socid', 'int');
$object->description = GETPOST('description', 'restricthtml'); // Do not use 'alpha' here, we want field as it is
Expand Down Expand Up @@ -304,6 +306,7 @@
$old_start_date = $object->date_start;

$object->ref = GETPOST('ref', 'alpha');
$object->fk_project = GETPOST('fk_project', 'int');
$object->title = GETPOST('title', 'alphanohtml'); // Do not use 'alpha' here, we want field as it is
$object->statut = GETPOST('status', 'int');
$object->socid = GETPOST('socid', 'int');
Expand Down Expand Up @@ -603,6 +606,14 @@
// Label
print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td><td><input class="width500 maxwidth150onsmartphone" type="text" name="title" value="'.dol_escape_htmltag(GETPOST("title", 'alphanohtml')).'" autofocus></td></tr>';

// Parent
if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
print '<tr><td>'.$langs->trans("Parent").'</td><td class="maxwidthonsmartphone">';
print img_picto('', 'project', 'class="pictofixedwidth"');
$formproject->select_projects(-1, '', 'fk_project', 64, 0, 1, 1, 0, 0, 0, '', 0, 0, '', '', '');
print '</td></tr>';
}

// Usage (opp, task, bill time, ...)
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
print '<tr><td class="tdtop">';
Expand Down Expand Up @@ -970,6 +981,14 @@ function change_percent()
print ajax_combobox('status');
print '</td></tr>';

// Parent
if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
print '<tr><td>'.$langs->trans("Parent").'</td><td class="maxwidthonsmartphone">';
print img_picto('', 'project', 'class="pictofixedwidth"');
$formproject->select_projects(-1, $object->fk_project, 'fk_project', 64, 0, 1, 1, 0, 0, 0, '', 0, 0, '', '', '');
print '</td></tr>';
}

// Usage
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
print '<tr><td class="tdtop">';
Expand Down Expand Up @@ -1246,6 +1265,14 @@ function set_usage_event() {
if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
$morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
}
// Parent
if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
if (!empty($object->fk_project) && $object->fk_project) {
$parent = new Project($db);
$parent->fetch($object->fk_project);
$morehtmlref .= $langs->trans("Child of").' '.$parent->getNomUrl(1, 'project').' '.$parent->title;
}
}
$morehtmlref .= '</div>';

// Define a complementary filter for search of next/prev ref.
Expand Down Expand Up @@ -1618,6 +1645,41 @@ function change_percent()
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre

if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
/*
* Sub-projects (children)
*/
$children = $object->getChildren();
if ($children) {
print '<table class="centpercent notopnoleftnoright table-fiche-title">';
print '<tr class="titre"><td class="nobordernopadding valignmiddle col-title">';
print '<div class="titre inline-block">'.$langs->trans('Sub-projects').'</div>';
print '</td></tr></table>';

print '<div class="div-table-responsive-no-min">';
print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
print '<tr class="liste_titre">';
print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
print getTitleFieldOfList('Status', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
print '</tr>';
print "\n";

$subproject = new Project($db);
foreach ($children as $child) {
$subproject->fetch($child->rowid);
print '<tr class="oddeven">';
print '<td class="nowraponall">'.$subproject->getNomUrl(1, 'project').'</td>';
print '<td class="nowraponall tdoverflowmax125">'.$child->title.'</td>';
print '<td class="nowraponall">'.$subproject->getLibStatut(5).'</td>';
print '</tr>';
}

print '</table>';
print '</div>';
}
}

/*
* Generated documents
*/
Expand Down
39 changes: 38 additions & 1 deletion htdocs/projet/class/project.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class Project extends CommonObject
*/
protected $table_ref_field = 'ref';

/**
* @var int parent project
*/
public $fk_project;

/**
* @var string description
*/
Expand Down Expand Up @@ -291,6 +296,7 @@ class Project extends CommonObject
*/
public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
'fk_project' =>array('type'=>'integer', 'label'=>'Parent', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>12),
'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>15, 'searchall'=>1),
'title' =>array('type'=>'varchar(255)', 'label'=>'ProjectLabel', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>17, 'showoncombobox'=>2, 'searchall'=>1),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>19),
Expand Down Expand Up @@ -426,6 +432,7 @@ public function create($user, $notrigger = 0)

$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (";
$sql .= "ref";
$sql .= ", fk_project";
$sql .= ", title";
$sql .= ", description";
$sql .= ", fk_soc";
Expand Down Expand Up @@ -458,6 +465,7 @@ public function create($user, $notrigger = 0)
$sql .= ", ip";
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($this->ref)."'";
$sql .= ", ".($this->fk_project ? ((int) $this->fk_project) : "null");
$sql .= ", '".$this->db->escape($this->title)."'";
$sql .= ", '".$this->db->escape($this->description)."'";
$sql .= ", ".($this->socid > 0 ? $this->socid : "null");
Expand Down Expand Up @@ -570,6 +578,7 @@ public function update($user, $notrigger = 0)

$sql = "UPDATE ".MAIN_DB_PREFIX."projet SET";
$sql .= " ref='".$this->db->escape($this->ref)."'";
$sql .= ", fk_project=".($this->fk_project ? ((int) $this->fk_project) : "null");
$sql .= ", title = '".$this->db->escape($this->title)."'";
$sql .= ", description = '".$this->db->escape($this->description)."'";
$sql .= ", fk_soc = ".($this->socid > 0 ? $this->socid : "null");
Expand Down Expand Up @@ -680,7 +689,7 @@ public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '')
return -1;
}

$sql = "SELECT rowid, entity, ref, title, description, public, datec, opp_amount, budget_amount,";
$sql = "SELECT rowid, entity, fk_project, ref, title, description, public, datec, opp_amount, budget_amount,";
$sql .= " tms, dateo as date_start, datee as date_end, date_close, fk_soc, fk_user_creat, fk_user_modif, fk_user_close, fk_statut as status, fk_opp_status, opp_percent,";
$sql .= " note_private, note_public, model_pdf, usage_opportunity, usage_task, usage_bill_time, usage_organize_event, email_msgid,";
$sql .= " accept_conference_suggestions, accept_booth_suggestions, price_registration, price_booth, max_attendees, date_start_event, date_end_event, location, extraparams";
Expand Down Expand Up @@ -709,6 +718,7 @@ public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '')
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->ref = $obj->ref;
$this->fk_project = $obj->fk_project;
$this->title = $obj->title;
$this->description = $obj->description;
$this->date_c = $this->db->jdate($obj->datec);
Expand Down Expand Up @@ -2480,4 +2490,31 @@ public function getKanbanView($option = '', $arraydata = null)
$return .= '</div>';
return $return;
}

/**
* Return array of sub-projects of the current project
*
* @return array Children of this project as objects with rowid & title as members
*/
public function getChildren()
{
$children = [];
$sql = 'SELECT rowid,title';
$sql .= ' FROM '.MAIN_DB_PREFIX.'projet';
$sql .= ' WHERE fk_project = '.((int) $this->id);
$sql .= ' ORDER BY title';
$result = $this->db->query($sql);
if ($result) {
$n = $this->db->num_rows($result);
while ($n) {
$children[] = $this->db->fetch_object($result);
$n--;
}
$this->db->free($result);
} else {
dol_print_error($this->db);
}

return $children;
}
}

0 comments on commit 60fa585

Please sign in to comment.