stickler
This commit is contained in:
parent
6d77f5e12f
commit
d423e47d3b
@ -8751,22 +8751,21 @@ class Form
|
|||||||
* @param int $option_only Return only html options lines without the select tag
|
* @param int $option_only Return only html options lines without the select tag
|
||||||
* @param string $show_empty Add an empty line ('1' or string to show for empty line)
|
* @param string $show_empty Add an empty line ('1' or string to show for empty line)
|
||||||
* @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
|
* @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
|
||||||
* @param int $forcefocus Force focus on field (works with javascript only)
|
* @param int $forcefocus Force focus on field (works with javascript only)
|
||||||
* @param int $disabled Disabled
|
* @param int $disabled Disabled
|
||||||
* @param string $morecss More css added to the select component
|
* @param string $morecss More css added to the select component
|
||||||
* @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids.
|
* @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids.
|
||||||
* @param string $showproject 'all' = Show project info, ''=Hide project info
|
* @param string $showproject 'all' = Show project info, ''=Hide project info
|
||||||
* @param User $usertofilter User object to use for filtering
|
* @param User $usertofilter User object to use for filtering
|
||||||
* @return int Nbr of project if OK, <0 if KO
|
* @return int Nbr of project if OK, <0 if KO
|
||||||
*/
|
*/
|
||||||
public function selectIntervention($socid = -1, $selected = '', $htmlname = 'interid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null)
|
public function selectIntervention($socid = -1, $selected = '', $htmlname = 'interid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null)
|
||||||
{
|
{
|
||||||
global $user, $conf, $langs;
|
global $user, $conf, $langs;
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||||
|
|
||||||
if (is_null($usertofilter))
|
if (is_null($usertofilter)) {
|
||||||
{
|
|
||||||
$usertofilter = $user;
|
$usertofilter = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8775,17 +8774,15 @@ class Form
|
|||||||
$hideunselectables = false;
|
$hideunselectables = false;
|
||||||
if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
|
if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
|
||||||
|
|
||||||
if (empty($projectsListId))
|
if (empty($projectsListId)) {
|
||||||
{
|
if (empty($usertofilter->rights->projet->all->lire)) {
|
||||||
if (empty($usertofilter->rights->projet->all->lire))
|
|
||||||
{
|
|
||||||
$projectstatic = new Project($this->db);
|
$projectstatic = new Project($this->db);
|
||||||
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
|
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search all projects
|
// Search all projects
|
||||||
$sql = 'SELECT i.rowid, i.ref as ref, p.fk_soc, p.fk_statut, p.public,';
|
$sql = 'SELECT i.rowid, i.ref as ref, p.fk_soc, p.fk_statut, p.public,';
|
||||||
$sql .= ' s.nom as name';
|
$sql .= ' s.nom as name';
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
|
||||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
|
||||||
@ -8798,11 +8795,9 @@ class Form
|
|||||||
$sql .= " GROUP BY i.ref ORDER BY p.ref, i.ref ASC";
|
$sql .= " GROUP BY i.ref ORDER BY p.ref, i.ref ASC";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
// Use select2 selector
|
// Use select2 selector
|
||||||
if (!empty($conf->use_javascript_ajax))
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
{
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
|
||||||
$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
|
$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
|
||||||
$out .= $comboenhancement;
|
$out .= $comboenhancement;
|
||||||
@ -8820,63 +8815,45 @@ class Form
|
|||||||
}
|
}
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if ($num)
|
if ($num) {
|
||||||
{
|
while ($i < $num) {
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
|
// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
|
||||||
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire))
|
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) {
|
||||||
{
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
} else {
|
||||||
else
|
if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
|
||||||
{
|
|
||||||
if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED)
|
|
||||||
{
|
|
||||||
$i++;
|
$i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$labeltoshow = '';
|
$labeltoshow = '';
|
||||||
|
|
||||||
if ($showproject == 'all')
|
if ($showproject == 'all') {
|
||||||
{
|
|
||||||
$labeltoshow .= dol_trunc($obj->ref, 18); // Intervention ref
|
$labeltoshow .= dol_trunc($obj->ref, 18); // Intervention ref
|
||||||
if ($obj->name) $labeltoshow .= ' - '.$obj->name; // Soc name
|
if ($obj->name) $labeltoshow .= ' - '.$obj->name; // Soc name
|
||||||
|
|
||||||
$disabled = 0;
|
$disabled = 0;
|
||||||
if ($obj->fk_statut == Project::STATUS_DRAFT)
|
if ($obj->fk_statut == Project::STATUS_DRAFT) {
|
||||||
{
|
|
||||||
$disabled = 1;
|
$disabled = 1;
|
||||||
$labeltoshow .= ' - '.$langs->trans("Draft");
|
$labeltoshow .= ' - '.$langs->trans("Draft");
|
||||||
}
|
} elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
|
||||||
elseif ($obj->fk_statut == Project::STATUS_CLOSED)
|
|
||||||
{
|
|
||||||
if ($discard_closed == 2) $disabled = 1;
|
if ($discard_closed == 2) $disabled = 1;
|
||||||
$labeltoshow .= ' - '.$langs->trans("Closed");
|
$labeltoshow .= ' - '.$langs->trans("Closed");
|
||||||
}
|
} elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
|
||||||
elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
|
|
||||||
{
|
|
||||||
$disabled = 1;
|
$disabled = 1;
|
||||||
$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
|
$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($selected) && $selected == $obj->rowid)
|
if (!empty($selected) && $selected == $obj->rowid) {
|
||||||
{
|
|
||||||
$out .= '<option value="'.$obj->rowid.'" selected';
|
$out .= '<option value="'.$obj->rowid.'" selected';
|
||||||
//if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
|
//if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
|
||||||
$out .= '>'.$labeltoshow.'</option>';
|
$out .= '>'.$labeltoshow.'</option>';
|
||||||
}
|
} else {
|
||||||
else
|
if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
|
||||||
{
|
|
||||||
if ($hideunselectables && $disabled && ($selected != $obj->rowid))
|
|
||||||
{
|
|
||||||
$resultat = '';
|
$resultat = '';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$resultat = '<option value="'.$obj->rowid.'"';
|
$resultat = '<option value="'.$obj->rowid.'"';
|
||||||
if ($disabled) $resultat .= ' disabled';
|
if ($disabled) $resultat .= ' disabled';
|
||||||
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
|
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
|
||||||
@ -8899,9 +8876,7 @@ class Form
|
|||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
return $num;
|
return $num;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($this->db);
|
dol_print_error($this->db);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -536,8 +536,7 @@ if ($action == 'confirm_generateinvoice') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'confirm_generateinter')
|
if ($action == 'confirm_generateinter') {
|
||||||
{
|
|
||||||
$langs->load('interventions');
|
$langs->load('interventions');
|
||||||
|
|
||||||
if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
|
if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
|
||||||
@ -556,7 +555,7 @@ if ($action == 'confirm_generateinter')
|
|||||||
$fuser = new User($db);
|
$fuser = new User($db);
|
||||||
|
|
||||||
$db->begin();
|
$db->begin();
|
||||||
$interToUse = GETPOST('interid', 'int');
|
$interToUse = GETPOST('interid', 'int');
|
||||||
|
|
||||||
|
|
||||||
$tmpinter->socid = $projectstatic->thirdparty->id;
|
$tmpinter->socid = $projectstatic->thirdparty->id;
|
||||||
@ -564,23 +563,21 @@ if ($action == 'confirm_generateinter')
|
|||||||
$tmpinter->fk_project = $projectstatic->id;
|
$tmpinter->fk_project = $projectstatic->id;
|
||||||
$tmpinter->description = $projectstatic->title . ( ! empty($projectstatic->description) ? '-' . $projectstatic->label : '' );
|
$tmpinter->description = $projectstatic->title . ( ! empty($projectstatic->description) ? '-' . $projectstatic->label : '' );
|
||||||
|
|
||||||
if ($interToUse) {
|
if ($interToUse) {
|
||||||
$tmpinter->fetch($interToUse);
|
$tmpinter->fetch($interToUse);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$result = $tmpinter->create($user);
|
$result = $tmpinter->create($user);
|
||||||
if ($result <= 0)
|
if ($result <= 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($tmpinter->error, $tmpinter->errors, 'errors');
|
setEventMessages($tmpinter->error, $tmpinter->errors, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$arrayoftasks = array();
|
$arrayoftasks = array();
|
||||||
foreach ($toselect as $key => $value)
|
foreach ($toselect as $key => $value) {
|
||||||
{
|
|
||||||
// Get userid, timepent
|
// Get userid, timepent
|
||||||
$object->fetchTimeSpent($value);
|
$object->fetchTimeSpent($value);
|
||||||
// $object->id is the task id
|
// $object->id is the task id
|
||||||
@ -590,8 +587,7 @@ if ($action == 'confirm_generateinter')
|
|||||||
$arrayoftasks[$object->timespent_id]['date'] = date('Y-m-d H:i:s', $object->timespent_datehour);
|
$arrayoftasks[$object->timespent_id]['date'] = date('Y-m-d H:i:s', $object->timespent_datehour);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($arrayoftasks as $timespent_id => $value)
|
foreach ($arrayoftasks as $timespent_id => $value) {
|
||||||
{
|
|
||||||
$ftask = new Task($db);
|
$ftask = new Task($db);
|
||||||
$ftask->fetch($object->id);
|
$ftask->fetch($object->id);
|
||||||
// Define qty per hour
|
// Define qty per hour
|
||||||
@ -603,8 +599,7 @@ if ($action == 'confirm_generateinter')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$urltointer = $tmpinter->getNomUrl(0);
|
$urltointer = $tmpinter->getNomUrl(0);
|
||||||
$mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
|
$mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
|
||||||
$mesg = str_replace('{s1}', $urltointer, $mesg);
|
$mesg = str_replace('{s1}', $urltointer, $mesg);
|
||||||
@ -613,9 +608,7 @@ if ($action == 'confirm_generateinter')
|
|||||||
//var_dump($tmpinvoice);
|
//var_dump($tmpinvoice);
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1117,7 +1110,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) {
|
|||||||
$massaction = '';
|
$massaction = '';
|
||||||
}
|
}
|
||||||
} elseif ($massaction == 'generateinter') {
|
} elseif ($massaction == 'generateinter') {
|
||||||
// Form to convert time spent into invoice
|
// Form to convert time spent into invoice
|
||||||
print '<input type="hidden" name="massaction" value="confirm_createinter">';
|
print '<input type="hidden" name="massaction" value="confirm_createinter">';
|
||||||
|
|
||||||
if ($projectstatic->thirdparty->id > 0) {
|
if ($projectstatic->thirdparty->id > 0) {
|
||||||
@ -1127,7 +1120,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) {
|
|||||||
print $langs->trans('InterToUse');
|
print $langs->trans('InterToUse');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$form->selectIntervention($projectstatic->thirdparty->id, '', 'interid', 24, 0, $langs->trans('NewInter'),
|
$form->selectIntervention($projectstatic->thirdparty->id, '', 'interid', 24, 0, $langs->trans('NewInter'),
|
||||||
1, 0, 0, 'maxwidth500', '', 'all');
|
1, 0, 0, 'maxwidth500', '', 'all');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user