NEW Dolibarr#22848 Add order tags

This commit is contained in:
Florent Poinsaut
2025-02-14 14:29:49 +01:00
parent d7205f3404
commit bfed762fe9
7 changed files with 365 additions and 90 deletions

View File

@@ -11279,6 +11279,109 @@ class Form
}
}
/**
* Output a combo list with orders qualified for a third party
*
* @param int $selected Id order preselected
* @param string $htmlname Name of HTML select
* @param int $maxlength Maximum length of label
* @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 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 $disabled Disabled
* @param string $morecss More css added to the select component
* @return int Nbr of project if OK, <0 if KO
*/
public function selectOrder($selected = '', $htmlname = 'orderid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500')
{
global $user, $conf, $langs;
$out = '';
$hideunselectables = false;
if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
$hideunselectables = true;
}
// Search all orders
$sql = "SELECT c.rowid, c.ref";
$sql .= ' FROM '.$this->db->prefix().'commande as c';
$sql .= " ORDER BY c.ref ASC";
$resql = $this->db->query($sql);
if ($resql) {
// Use select2 selector
if (!empty($conf->use_javascript_ajax)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
$out .= $comboenhancement;
$morecss = 'minwidth200imp maxwidth500';
}
if (empty($option_only)) {
$out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">';
}
if (!empty($show_empty)) {
$out .= '<option value="0" class="optiongrey">';
if (!is_numeric($show_empty)) {
$out .= $show_empty;
} else {
$out .= '&nbsp;';
}
$out .= '</option>';
}
$num = $this->db->num_rows($resql);
$i = 0;
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
$i++;
continue;
}
$labeltoshow = dol_trunc($obj->ref, 18); // Order ref
if (!empty($selected) && $selected == $obj->rowid) {
$out .= '<option value="'.$obj->rowid.'" selected';
//if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
$out .= '>'.$labeltoshow.'</option>';
} else {
if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
$resultat = '';
} else {
$resultat = '<option value="'.$obj->rowid.'"';
if ($disabled) {
$resultat .= ' disabled';
}
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
//else $labeltoshow.=' ('.$langs->trans("Private").')';
$resultat .= '>';
$resultat .= $labeltoshow;
$resultat .= '</option>';
}
$out .= $resultat;
}
$i++;
}
}
if (empty($option_only)) {
$out .= '</select>';
}
print $out;
$this->db->free($resql);
return $num;
} else {
dol_print_error($this->db);
return -1;
}
}
/**
* Output the component to make advanced search criteries
*