68 public $errors = array();
73 public $cache_types_paiements = array();
74 public $cache_conditions_paiements = array();
75 public $cache_transport_mode = array();
76 public $cache_availability = array();
77 public $cache_demand_reason = array();
78 public $cache_types_fees = array();
79 public $cache_vatrates = array();
108 public function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata =
'string', $moreparam =
'', $fieldrequired = 0, $notabletag = 0, $paramid =
'id', $help =
'')
110 global $conf, $langs;
115 if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match(
'/^select;/', $typeofdata)) {
117 $tmp = explode(
':', $typeofdata);
118 $ret .=
'<div class="editkey_'.$tmp[0].(!empty($tmp[1]) ?
' '.$tmp[1] :
'').
'" id="'.$htmlname.
'">';
119 if ($fieldrequired) {
120 $ret .=
'<span class="fieldrequired">';
125 $ret .= $langs->trans($text);
127 if ($fieldrequired) {
130 $ret .=
'</div>'.
"\n";
132 if ($fieldrequired) {
133 $ret .=
'<span class="fieldrequired">';
138 $ret .= $langs->trans($text);
140 if ($fieldrequired) {
145 if (empty($notabletag) && $perm) {
146 $ret .=
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
148 if ($fieldrequired) {
149 $ret .=
'<span class="fieldrequired">';
154 $ret .= $langs->trans($text);
156 if ($fieldrequired) {
159 if (!empty($notabletag)) {
162 if (empty($notabletag) && $perm) {
165 if (empty($notabletag) && $perm) {
166 $ret .=
'<td class="right">';
168 if ($htmlname &&
GETPOST(
'action',
'aZ09') !=
'edit'.$htmlname && $perm) {
169 $ret .=
'<a class="editfielda reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit'.$htmlname.
'&token='.
newToken().
'&'.$paramid.
'='.$object->id.$moreparam.
'">'.
img_edit($langs->trans(
'Edit'), ($notabletag ? 0 : 1)).
'</a>';
171 if (!empty($notabletag) && $notabletag == 1) {
174 if (!empty($notabletag) && $notabletag == 3) {
177 if (empty($notabletag) && $perm) {
180 if (empty($notabletag) && $perm) {
181 $ret .=
'</tr></table>';
207 public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata =
'string', $editvalue =
'', $extObject =
null, $custommsg =
null, $moreparam =
'', $notabletag = 0, $formatfunc =
'', $paramid =
'id', $gm =
'auto')
209 global $conf, $langs;
214 if (empty($typeofdata)) {
215 return 'ErrorBadParameter typeofdata is empty';
218 if ($typeofdata ==
'datetime') {
219 $typeofdata =
'dayhour';
222 if (preg_match(
'/^(\w+)\((\d+)\)$/', $typeofdata, $reg)) {
223 if ($reg[1] ==
'varchar') {
224 $typeofdata =
'string';
225 } elseif ($reg[1] ==
'int') {
226 $typeofdata =
'numeric';
228 return 'ErrorBadParameter '.$typeofdata;
233 if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match(
'/^select;|day|datepicker|dayhour|datehourpicker/', $typeofdata)) {
234 $ret .= $this->
editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
236 $editmode = (
GETPOST(
'action',
'aZ09') ==
'edit'.$htmlname);
239 $ret .=
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].($moreparam ?
'?'.$moreparam :
'').
'">';
240 $ret .=
'<input type="hidden" name="action" value="set'.$htmlname.
'">';
241 $ret .=
'<input type="hidden" name="token" value="'.newToken().
'">';
242 $ret .=
'<input type="hidden" name="'.$paramid.
'" value="'.$object->id.
'">';
243 if (empty($notabletag)) {
244 $ret .=
'<table class="nobordernopadding centpercent">';
246 if (empty($notabletag)) {
249 if (preg_match(
'/^(string|safehtmlstring|email|url)/', $typeofdata)) {
250 $tmp = explode(
':', $typeofdata);
251 $ret .=
'<input type="text" id="'.$htmlname.
'" name="'.$htmlname.
'" value="'.($editvalue ? $editvalue : $value).
'"'.(empty($tmp[1]) ?
'' :
' size="'.$tmp[1].
'"').
' autofocus>';
252 } elseif (preg_match(
'/^(integer)/', $typeofdata)) {
253 $tmp = explode(
':', $typeofdata);
254 $valuetoshow =
price2num($editvalue ? $editvalue : $value, 0);
255 $ret .=
'<input type="text" id="'.$htmlname.
'" name="'.$htmlname.
'" value="'.$valuetoshow.
'"'.(empty($tmp[1]) ?
'' :
' size="'.$tmp[1].
'"').
' autofocus>';
256 } elseif (preg_match(
'/^(numeric|amount)/', $typeofdata)) {
257 $tmp = explode(
':', $typeofdata);
258 $valuetoshow =
price2num($editvalue ? $editvalue : $value);
259 $ret .=
'<input type="text" id="'.$htmlname.
'" name="'.$htmlname.
'" value="'.($valuetoshow !=
'' ?
price($valuetoshow) :
'').
'"'.(empty($tmp[1]) ?
'' :
' size="'.$tmp[1].
'"').
' autofocus>';
260 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
261 $tmp = explode(
':', $typeofdata);
262 $ret .=
'<input type="checkbox" id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . (empty($tmp[1]) ?
'' : $tmp[1]) .
'/>';
263 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
264 $tmp = explode(
':', $typeofdata);
265 $cols = (empty($tmp[2]) ?
'' : $tmp[2]);
267 if (preg_match(
'/%/', $cols)) {
268 $morealt =
' style="width: '.$cols.
'"';
272 $valuetoshow = ($editvalue ? $editvalue : $value);
273 $ret .=
'<textarea id="'.$htmlname.
'" name="'.$htmlname.
'" wrap="soft" rows="'.(empty($tmp[1]) ?
'20' : $tmp[1]).
'"'.($cols ?
' cols="'.$cols.
'"' :
'class="quatrevingtpercent"').$morealt.
'" autofocus>';
276 $valuetoshow = str_replace(
'&',
'&', $valuetoshow);
278 $ret .=
'</textarea>';
279 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
280 $ret .= $this->
selectDate($value, $htmlname, 0, 0, 1,
'form'.$htmlname, 1, 0, 0,
'',
'',
'',
'', 1,
'',
'', $gm);
281 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
282 $ret .= $this->
selectDate($value, $htmlname, 1, 1, 1,
'form'.$htmlname, 1, 0, 0,
'',
'',
'',
'', 1,
'',
'', $gm);
283 } elseif (preg_match(
'/^select;/', $typeofdata)) {
284 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
285 $arraylist = array();
286 foreach ($arraydata as $val) {
287 $tmp = explode(
':', $val);
288 $tmpkey = str_replace(
'|',
':', $tmp[0]);
289 $arraylist[$tmpkey] = $tmp[1];
291 $ret .= $this->
selectarray($htmlname, $arraylist, $value);
292 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
293 $tmp = explode(
':', $typeofdata);
294 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
295 $doleditor =
new DolEditor($htmlname, ($editvalue ? $editvalue : $value), (empty($tmp[2]) ?
'' : $tmp[2]), (empty($tmp[3]) ?
'100' : $tmp[3]), (empty($tmp[1]) ?
'dolibarr_notes' : $tmp[1]),
'In', (empty($tmp[5]) ? 0 : $tmp[5]), (isset($tmp[8]) ? ($tmp[8] ?
true :
false) :
true),
true, (empty($tmp[6]) ?
'20' : $tmp[6]), (empty($tmp[7]) ?
'100' : $tmp[7]));
296 $ret .= $doleditor->Create(1);
298 if (empty($notabletag)) {
303 if (empty($notabletag)) {
304 $ret .=
'<td class="left">';
307 $ret .=
'<input type="submit" class="smallpaddingimp button'.(empty($notabletag) ?
'' :
' ').
'" name="modify" value="'.$langs->trans(
"Modify").
'">';
308 if (preg_match(
'/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
311 $ret .=
'<input type="submit" class="smallpaddingimp button button-cancel'.(empty($notabletag) ?
'' :
' ').
'" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
312 if (empty($notabletag)) {
316 if (empty($notabletag)) {
317 $ret .=
'</tr></table>'.
"\n";
319 $ret .=
'</form>'.
"\n";
321 if (preg_match(
'/^(email)/', $typeofdata)) {
323 } elseif (preg_match(
'/^url/', $typeofdata)) {
325 } elseif (preg_match(
'/^(amount|numeric)/', $typeofdata)) {
326 $ret .= ($value !=
'' ?
price($value,
'', $langs, 0, -1, -1, $conf->currency) :
'');
327 } elseif (preg_match(
'/^(checkbox)/', $typeofdata)) {
328 $tmp = explode(
':', $typeofdata);
329 $ret .=
'<input type="checkbox" disabled id="' . $htmlname .
'" name="' . $htmlname .
'" value="' . $value .
'"' . ($tmp[1] ? $tmp[1] :
'') .
'/>';
330 } elseif (preg_match(
'/^text/', $typeofdata) || preg_match(
'/^note/', $typeofdata)) {
332 } elseif (preg_match(
'/^safehtmlstring/', $typeofdata)) {
334 } elseif (preg_match(
'/^restricthtml/', $typeofdata)) {
336 } elseif ($typeofdata ==
'day' || $typeofdata ==
'datepicker') {
337 $ret .=
'<span class="valuedate">'.dol_print_date($value,
'day', $gm).
'</span>';
338 } elseif ($typeofdata ==
'dayhour' || $typeofdata ==
'datehourpicker') {
339 $ret .=
'<span class="valuedate">'.dol_print_date($value,
'dayhour', $gm).
'</span>';
340 } elseif (preg_match(
'/^select;/', $typeofdata)) {
341 $arraydata = explode(
',', preg_replace(
'/^select;/',
'', $typeofdata));
342 $arraylist = array();
343 foreach ($arraydata as $val) {
344 $tmp = explode(
':', $val);
345 $arraylist[$tmp[0]] = $tmp[1];
347 $ret .= $arraylist[$value];
348 if ($htmlname ==
'fk_product_type') {
350 $ret =
img_picto($langs->trans(
"Product"),
'product',
'class="paddingleftonly paddingrightonly colorgrey"').$ret;
352 $ret =
img_picto($langs->trans(
"Service"),
'service',
'class="paddingleftonly paddingrightonly colorgrey"').$ret;
355 } elseif (preg_match(
'/^ckeditor/', $typeofdata)) {
357 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
358 $firstline = preg_replace(
'/<br>.*/',
'', $tmpcontent);
359 $firstline = preg_replace(
'/[\n\r].*/',
'', $firstline);
360 $tmpcontent = $firstline.((strlen($firstline) != strlen($tmpcontent)) ?
'...' :
'');
369 if ($formatfunc && method_exists($object, $formatfunc)) {
370 $ret = $object->$formatfunc($ret);
388 public function widgetForTranslation($fieldname, $object, $perm, $typeofdata =
'string', $check =
'', $morecss =
'')
390 global $conf, $langs, $extralanguages;
395 $arrayoflangcode = array();
396 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
397 $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
400 if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
401 if (!is_object($extralanguages)) {
402 include_once DOL_DOCUMENT_ROOT.
'/core/class/extralanguages.class.php';
405 $extralanguages->fetch_name_extralanguages(
'societe');
407 if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) {
411 $result .=
'<!-- Widget for translation -->'.
"\n";
412 $result .=
'<div class="inline-block paddingleft image-'.$object->element.
'-'.$fieldname.
'">';
413 $s =
img_picto($langs->trans(
"ShowOtherLanguages"),
'language',
'',
false, 0, 0,
'',
'fa-15 editfieldlang');
417 $result .=
'<div class="inline-block hidden field-'.$object->element.
'-'.$fieldname.
'">';
419 $resultforextrlang =
'';
420 foreach ($arrayoflangcode as $langcode) {
421 $valuetoshow =
GETPOSTISSET(
'field-'.$object->element.
"-".$fieldname.
"-".$langcode) ?
GETPOST(
'field-'.$object->element.
'-'.$fieldname.
"-".$langcode, $check) :
'';
422 if (empty($valuetoshow)) {
423 $object->fetchValuesForExtraLanguages();
425 $valuetoshow = $object->array_languages[$fieldname][$langcode];
429 $resultforextrlang .= $s;
432 if ($typeofdata ==
'textarea') {
433 $resultforextrlang .=
'<textarea name="field-'.$object->element.
"-".$fieldname.
"-".$langcode.
'" id="'.$fieldname.
"-".$langcode.
'" class="'.$morecss.
'" rows="'.ROWS_2.
'" wrap="soft">';
434 $resultforextrlang .= $valuetoshow;
435 $resultforextrlang .=
'</textarea>';
437 $resultforextrlang .=
'<input type="text" class="inputfieldforlang '.($morecss ?
' '.$morecss :
'').
'" name="field-'.$object->element.
'-'.$fieldname.
'-'.$langcode.
'" value="'.$valuetoshow.
'">';
440 $result .= $resultforextrlang;
443 $result .=
'<script>$(".image-'.$object->element.
'-'.$fieldname.
'").click(function() { console.log("Toggle lang widget"); jQuery(".field-'.$object->element.
'-'.$fieldname.
'").toggle(); });</script>';
462 protected function editInPlace($object, $value, $htmlname, $condition, $inputType =
'textarea', $editvalue =
null, $extObject =
null, $custommsg =
null)
469 if (preg_match(
'/^text/', $inputType)) {
471 } elseif (preg_match(
'/^numeric/', $inputType)) {
472 $value =
price($value);
473 } elseif ($inputType ==
'day' || $inputType ==
'datepicker') {
479 $table_element =
false;
483 $ext_element =
false;
484 $button_only =
false;
489 if (is_object($object)) {
490 $element = $object->element;
491 $table_element = $object->table_element;
492 $fk_element = $object->id;
495 if (is_object($extObject)) {
496 $ext_element = $extObject->element;
499 if (preg_match(
'/^(string|email|numeric)/', $inputType)) {
500 $tmp = explode(
':', $inputType);
501 $inputType = $tmp[0];
502 if (!empty($tmp[1])) {
503 $inputOption = $tmp[1];
505 if (!empty($tmp[2])) {
506 $savemethod = $tmp[2];
508 $out .=
'<input id="width_'.$htmlname.
'" value="'.$inputOption.
'" type="hidden"/>'.
"\n";
509 } elseif ((preg_match(
'/^day$/', $inputType)) || (preg_match(
'/^datepicker/', $inputType)) || (preg_match(
'/^datehourpicker/', $inputType))) {
510 $tmp = explode(
':', $inputType);
511 $inputType = $tmp[0];
512 if (!empty($tmp[1])) {
513 $inputOption = $tmp[1];
515 if (!empty($tmp[2])) {
516 $savemethod = $tmp[2];
519 $out .=
'<input id="timestamp" type="hidden"/>'.
"\n";
520 } elseif (preg_match(
'/^(select|autocomplete)/', $inputType)) {
521 $tmp = explode(
':', $inputType);
522 $inputType = $tmp[0];
523 $loadmethod = $tmp[1];
524 if (!empty($tmp[2])) {
525 $savemethod = $tmp[2];
527 if (!empty($tmp[3])) {
530 } elseif (preg_match(
'/^textarea/', $inputType)) {
531 $tmp = explode(
':', $inputType);
532 $inputType = $tmp[0];
533 $rows = (empty($tmp[1]) ?
'8' : $tmp[1]);
534 $cols = (empty($tmp[2]) ?
'80' : $tmp[2]);
535 } elseif (preg_match(
'/^ckeditor/', $inputType)) {
536 $tmp = explode(
':', $inputType);
537 $inputType = $tmp[0];
539 if (!empty($tmp[2])) {
542 if (!empty($tmp[3])) {
545 if (!empty($tmp[4])) {
546 $savemethod = $tmp[4];
550 $out .=
'<input id="ckeditor_toolbar" value="'.$toolbar.
'" type="hidden"/>'.
"\n";
552 $inputType =
'textarea';
556 $out .=
'<input id="element_'.$htmlname.
'" value="'.$element.
'" type="hidden"/>'.
"\n";
557 $out .=
'<input id="table_element_'.$htmlname.
'" value="'.$table_element.
'" type="hidden"/>'.
"\n";
558 $out .=
'<input id="fk_element_'.$htmlname.
'" value="'.$fk_element.
'" type="hidden"/>'.
"\n";
559 $out .=
'<input id="loadmethod_'.$htmlname.
'" value="'.$loadmethod.
'" type="hidden"/>'.
"\n";
560 if (!empty($savemethod)) {
561 $out .=
'<input id="savemethod_'.$htmlname.
'" value="'.$savemethod.
'" type="hidden"/>'.
"\n";
563 if (!empty($ext_element)) {
564 $out .=
'<input id="ext_element_'.$htmlname.
'" value="'.$ext_element.
'" type="hidden"/>'.
"\n";
566 if (!empty($custommsg)) {
567 if (is_array($custommsg)) {
568 if (!empty($custommsg[
'success'])) {
569 $out .=
'<input id="successmsg_'.$htmlname.
'" value="'.$custommsg[
'success'].
'" type="hidden"/>'.
"\n";
571 if (!empty($custommsg[
'error'])) {
572 $out .=
'<input id="errormsg_'.$htmlname.
'" value="'.$custommsg[
'error'].
'" type="hidden"/>'.
"\n";
575 $out .=
'<input id="successmsg_'.$htmlname.
'" value="'.$custommsg.
'" type="hidden"/>'.
"\n";
578 if ($inputType ==
'textarea') {
579 $out .=
'<input id="textarea_'.$htmlname.
'_rows" value="'.$rows.
'" type="hidden"/>'.
"\n";
580 $out .=
'<input id="textarea_'.$htmlname.
'_cols" value="'.$cols.
'" type="hidden"/>'.
"\n";
582 $out .=
'<span id="viewval_'.$htmlname.
'" class="viewval_'.$inputType.($button_only ?
' inactive' :
' active').
'">'.$value.
'</span>'.
"\n";
583 $out .=
'<span id="editval_'.$htmlname.
'" class="editval_'.$inputType.($button_only ?
' inactive' :
' active').
' hideobject">'.(!empty($editvalue) ? $editvalue : $value).
'</span>'.
"\n";
609 public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img =
'', $extracss =
'', $notabs = 3, $incbefore =
'', $noencodehtmltext = 0, $tooltiptrigger =
'', $forcenowrap = 0)
612 $text = $incbefore.$text;
617 $direction = (int) $direction;
627 $htmltext = str_replace(array(
"\r",
"\n"),
'', $htmltext);
630 if ($direction < 0) {
631 $extracss = ($extracss ? $extracss.
' ' :
'').($notabs != 3 ?
'inline-block' :
'');
632 $extrastyle =
'padding: 0px; padding-left: 3px;';
634 if ($direction > 0) {
635 $extracss = ($extracss ? $extracss.
' ' :
'').($notabs != 3 ?
'inline-block' :
'');
636 $extrastyle =
'padding: 0px; padding-right: 3px;';
639 $classfortooltip =
'classfortooltip';
644 if ($tooltiptrigger ==
'') {
645 $htmltext = str_replace(
'"',
'"', $htmltext);
647 $classfortooltip =
'classfortooltiponclick';
648 $textfordialog .=
'<div style="display: none;" id="idfortooltiponclick_'.$tooltiptrigger.
'" class="classfortooltiponclicktext">'.$htmltext.
'</div>';
650 if ($tooltipon == 2 || $tooltipon == 3) {
651 $paramfortooltipimg =
' class="'.$classfortooltip.($notabs != 3 ?
' inline-block' :
'').($extracss ?
' '.$extracss :
'').
'" style="padding: 0px;'.($extrastyle ?
' '.$extrastyle :
'').
'"';
652 if ($tooltiptrigger ==
'') {
653 $paramfortooltipimg .=
' title="'.($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)).
'"';
655 $paramfortooltipimg .=
' dolid="'.$tooltiptrigger.
'"';
658 $paramfortooltipimg = ($extracss ?
' class="'.$extracss.
'"' :
'').($extrastyle ?
' style="'.$extrastyle.
'"' :
'');
660 if ($tooltipon == 1 || $tooltipon == 3) {
661 $paramfortooltiptd =
' class="'.($tooltipon == 3 ?
'cursorpointer ' :
'').$classfortooltip.
' inline-block'.($extracss ?
' '.$extracss :
'').
'" style="padding: 0px;'.($extrastyle ?
' '.$extrastyle :
'').
'" ';
662 if ($tooltiptrigger ==
'') {
663 $paramfortooltiptd .=
' title="'.($noencodehtmltext ? $htmltext :
dol_escape_htmltag($htmltext, 1)).
'"';
665 $paramfortooltiptd .=
' dolid="'.$tooltiptrigger.
'"';
668 $paramfortooltiptd = ($extracss ?
' class="'.$extracss.
'"' :
'').($extrastyle ?
' style="'.$extrastyle.
'"' :
'');
670 if (empty($notabs)) {
671 $s .=
'<table class="nobordernopadding"><tr style="height: auto;">';
672 } elseif ($notabs == 2) {
673 $s .=
'<div class="inline-block'.($forcenowrap ?
' nowrap' :
'').
'">';
676 if ($direction < 0) {
677 $s .=
'<'.$tag.$paramfortooltipimg;
679 $s .=
' class="valigntop" width="14"';
681 $s .=
'>'.$textfordialog.$img.
'</'.$tag.
'>';
685 if ((
string) $text !=
'') {
686 $s .=
'<'.$tag.$paramfortooltiptd.
'>'.$text.
'</'.$tag.
'>';
689 if ($direction > 0) {
690 $s .=
'<'.$tag.$paramfortooltipimg;
692 $s .=
' class="valignmiddle" width="14"';
694 $s .=
'>'.$textfordialog.$img.
'</'.$tag.
'>';
696 if (empty($notabs)) {
697 $s .=
'</tr></table>';
698 } elseif ($notabs == 2) {
719 public function textwithpicto($text, $htmltext, $direction = 1, $type =
'help', $extracss =
'', $noencodehtmltext = 0, $notabs = 3, $tooltiptrigger =
'', $forcenowrap = 0)
721 global $conf, $langs;
726 } elseif ($type ==
'1') {
730 if (preg_match(
'/onsmartphone$/', $tooltiptrigger) && empty($conf->dol_no_mouse_hover)) {
731 $tooltiptrigger = preg_replace(
'/^.*onsmartphone$/',
'', $tooltiptrigger);
735 if ($tooltiptrigger) {
736 $alt = $langs->transnoentitiesnoconv(
"ClickToShowHelp");
740 if (empty($conf->use_javascript_ajax)) {
741 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
750 if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
751 if ($type ==
'info' || $type ==
'infoclickable' || $type ==
'help' || $type ==
'helpclickable') {
762 if ($type ==
'info') {
764 } elseif ($type ==
'help') {
765 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
766 } elseif ($type ==
'helpclickable') {
767 $img =
img_help(($tooltiptrigger !=
'' ? 2 : 1), $alt);
768 } elseif ($type ==
'superadmin') {
770 } elseif ($type ==
'admin') {
772 } elseif ($type ==
'warning') {
774 } elseif ($type !=
'none') {
778 return $this->
textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type,
'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs,
'', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
791 public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0, $name =
'massaction', $cssclass =
'checkforselect')
793 global $conf, $langs, $hookmanager;
797 $ret =
'<div class="centpercent center">';
798 $ret .=
'<select class="flat'.(empty($conf->use_javascript_ajax) ?
'' :
' hideobject').
' '.$name.
' '.$name.
'select valignmiddle alignstart" id="'.$name.
'" name="'.$name.
'"'.($disabled ?
' disabled="disabled"' :
'').
'>';
801 $parameters = array();
802 $reshook = $hookmanager->executeHooks(
'addMoreMassActions', $parameters);
804 if (count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
807 if (empty($reshook)) {
808 $ret .=
'<option value="0"'.($disabled ?
' disabled="disabled"' :
'').
'>-- '.$langs->trans(
"SelectAction").
' --</option>';
809 foreach ($arrayofaction as $code => $label) {
810 $ret .=
'<option value="'.$code.
'"'.($disabled ?
' disabled="disabled"' :
'').
' data-html="'.
dol_escape_htmltag($label).
'">'.$label.
'</option>';
813 $ret .= $hookmanager->resPrint;
817 if (empty($conf->dol_optimize_smallscreen)) {
822 $ret .=
'<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">';
823 $ret .=
'<input type="submit" disabled name="confirmmassaction"'.(empty($conf->use_javascript_ajax) ?
'' :
' style="display: none"').
' class="button smallpaddingimp'.(empty($conf->use_javascript_ajax) ?
'' :
' hideobject').
' '.$name.
' '.$name.
'confirmed" value="'.
dol_escape_htmltag($langs->trans(
"Confirm")).
'">';
826 if (!empty($conf->use_javascript_ajax)) {
827 $ret .=
'<!-- JS CODE TO ENABLE mass action select -->
829 function initCheckForSelect(mode, name, cssclass) /* mode is 0 during init of page or click all, 1 when we click on 1 checkboxi, "name" refers to the class of the massaction button, "cssclass" to the class of the checkfor select boxes */
831 atleastoneselected=0;
832 jQuery("."+cssclass).each(function( index ) {
833 /* console.log( index + ": " + $( this ).text() ); */
834 if ($(this).is(\':checked\')) atleastoneselected++;
837 console.log("initCheckForSelect mode="+mode+" name="+name+" cssclass="+cssclass+" atleastoneselected="+atleastoneselected);
839 if (atleastoneselected || '.$alwaysvisible.
')
841 jQuery("."+name).show();
842 '.($selected ?
'if (atleastoneselected) { jQuery("."+name+"select").val("'.$selected.
'").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', false); }' :
'').
'
843 '.($selected ?
'if (! atleastoneselected) { jQuery("."+name+"select").val("0").trigger(\'change\'); jQuery("."+name+"confirmed").prop(\'disabled\', true); } ' :
'').
'
847 jQuery("."+name).hide();
848 jQuery("."+name+"other").hide();
852 jQuery(document).ready(function () {
853 initCheckForSelect(0, "' . $name.
'", "'.$cssclass.
'");
854 jQuery(".' . $cssclass.
'").click(function() {
855 initCheckForSelect(1, "'.$name.
'", "'.$cssclass.
'");
857 jQuery(".' . $name.
'select").change(function() {
858 var massaction = $( this ).val();
859 var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
860 if (massaction == "builddoc")
862 urlform = urlform + "#show_files";
864 $( this ).closest("form").attr("action", urlform);
865 console.log("we select a mass action name='.$name.
' massaction="+massaction+" - "+urlform);
866 /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
867 if ($(this).val() != \'0\')
869 jQuery(".' . $name.
'confirmed").prop(\'disabled\', false);
870 jQuery(".' . $name.
'other").hide(); /* To disable if another div was open */
871 jQuery(".' . $name.
'"+massaction).show();
875 jQuery(".' . $name.
'confirmed").prop(\'disabled\', true);
876 jQuery(".' . $name.
'other").hide(); /* To disable any div open */
904 public function select_country($selected =
'', $htmlname =
'country_id', $htmloption =
'', $maxlength = 0, $morecss =
'minwidth300', $usecodeaskey =
'', $showempty = 1, $disablefavorites = 0, $addspecialentries = 0, $exclude_country_code = array(), $hideflags = 0)
907 global $conf, $langs, $mysoc;
909 $langs->load(
"dict");
912 $countryArray = array();
915 $atleastonefavorite = 0;
917 $sql =
"SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec";
918 $sql .=
" FROM ".$this->db->prefix().
"c_country";
919 $sql .=
" WHERE active > 0";
922 dol_syslog(get_class($this).
"::select_country", LOG_DEBUG);
925 $out .=
'<select id="select'.$htmlname.
'" class="flat maxwidth200onsmartphone selectcountry'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" '.$htmloption.
'>';
926 $num = $this->db->num_rows(
$resql);
930 $obj = $this->
db->fetch_object(
$resql);
932 $countryArray[$i][
'rowid'] = $obj->rowid;
933 $countryArray[$i][
'code_iso'] = $obj->code_iso;
934 $countryArray[$i][
'code_iso3'] = $obj->code_iso3;
935 $countryArray[$i][
'label'] = ($obj->code_iso && $langs->transnoentitiesnoconv(
"Country".$obj->code_iso) !=
"Country".$obj->code_iso ? $langs->transnoentitiesnoconv(
"Country".$obj->code_iso) : ($obj->label !=
'-' ? $obj->label :
''));
936 $countryArray[$i][
'favorite'] = $obj->favorite;
937 $countryArray[$i][
'eec'] = $obj->eec;
938 $favorite[$i] = $obj->favorite;
943 if (empty($disablefavorites)) {
944 $array1_sort_order = SORT_DESC;
945 $array2_sort_order = SORT_ASC;
946 array_multisort($favorite, $array1_sort_order, $label, $array2_sort_order, $countryArray);
952 if (is_numeric($showempty)) {
953 $out .=
'<option value=""> </option>'.
"\n";
955 $out .=
'<option value="">'.$langs->trans($showempty).
'</option>'.
"\n";
959 if ($addspecialentries) {
961 $out .=
'<option value="special_allnotme"'.($selected ==
'special_allnotme' ?
' selected' :
'').
'>'.$langs->trans(
"CountriesExceptMe", $langs->transnoentitiesnoconv(
"Country".$mysoc->country_code)).
'</option>';
962 $out .=
'<option value="special_eec"'.($selected ==
'special_eec' ?
' selected' :
'').
'>'.$langs->trans(
"CountriesInEEC").
'</option>';
963 if ($mysoc->isInEEC()) {
964 $out .=
'<option value="special_eecnotme"'.($selected ==
'special_eecnotme' ?
' selected' :
'').
'>'.$langs->trans(
"CountriesInEECExceptMe", $langs->transnoentitiesnoconv(
"Country".$mysoc->country_code)).
'</option>';
966 $out .=
'<option value="special_noteec"'.($selected ==
'special_noteec' ?
' selected' :
'').
'>'.$langs->trans(
"CountriesNotInEEC").
'</option>';
967 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
970 foreach ($countryArray as $row) {
972 if (empty($row[
'rowid'])) {
975 if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row[
'code_iso'], $exclude_country_code)) {
979 if (empty($disablefavorites) && $row[
'favorite'] && $row[
'code_iso']) {
980 $atleastonefavorite++;
982 if (empty($row[
'favorite']) && $atleastonefavorite) {
983 $atleastonefavorite = 0;
984 $out .=
'<option value="" disabled class="selectoptiondisabledwhite">------------</option>';
989 $labeltoshow .=
dol_trunc($row[
'label'], $maxlength,
'middle');
991 $labeltoshow .=
' ';
993 if ($row[
'code_iso']) {
994 $labeltoshow .=
' <span class="opacitymedium">('.$row[
'code_iso'].
')</span>';
995 if (empty($hideflags)) {
996 $tmpflag =
picto_from_langcode($row[
'code_iso'],
'class="saturatemedium paddingrightonly"', 1);
997 $labeltoshow = $tmpflag.
' '.$labeltoshow;
1001 if ($selected && $selected !=
'-1' && ($selected == $row[
'rowid'] || $selected == $row[
'code_iso'] || $selected == $row[
'code_iso3'] || $selected == $row[
'label'])) {
1002 $out .=
'<option value="'.($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']).
'" selected data-html="'.
dol_escape_htmltag($labeltoshow).
'" data-eec="'.((int) $row[
'eec']).
'">';
1004 $out .=
'<option value="'.($usecodeaskey ? ($usecodeaskey ==
'code2' ? $row[
'code_iso'] : $row[
'code_iso3']) : $row[
'rowid']).
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'" data-eec="'.((int) $row[
'eec']).
'">';
1006 $out .= $labeltoshow;
1007 $out .=
'</option>'.
"\n";
1010 $out .=
'</select>';
1016 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1017 $out .=
ajax_combobox(
'select'.$htmlname, array(), 0, 0,
'resolve');
1036 public function select_incoterms($selected =
'', $location_incoterms =
'', $page =
'', $htmlname =
'incoterm_id', $htmloption =
'', $forcecombo = 1, $events = array(), $disableautocomplete = 0)
1039 global $conf, $langs;
1041 $langs->load(
"dict");
1045 $incotermArray = array();
1047 $sql =
"SELECT rowid, code";
1048 $sql .=
" FROM ".$this->db->prefix().
"c_incoterms";
1049 $sql .=
" WHERE active > 0";
1050 $sql .=
" ORDER BY code ASC";
1052 dol_syslog(get_class($this).
"::select_incoterm", LOG_DEBUG);
1055 if ($conf->use_javascript_ajax && !$forcecombo) {
1056 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1060 if (!empty($page)) {
1061 $out .=
'<form method="post" action="'.$page.
'">';
1062 $out .=
'<input type="hidden" name="action" value="set_incoterms">';
1063 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1066 $out .=
'<select id="'.$htmlname.
'" class="flat selectincoterm width75" name="'.$htmlname.
'" '.$htmloption.
'>';
1067 $out .=
'<option value="0"> </option>';
1068 $num = $this->
db->num_rows(
$resql);
1072 $obj = $this->
db->fetch_object(
$resql);
1073 $incotermArray[$i][
'rowid'] = $obj->rowid;
1074 $incotermArray[$i][
'code'] = $obj->code;
1078 foreach ($incotermArray as $row) {
1079 if ($selected && ($selected == $row[
'rowid'] || $selected == $row[
'code'])) {
1080 $out .=
'<option value="'.$row[
'rowid'].
'" selected>';
1082 $out .=
'<option value="'.$row[
'rowid'].
'">';
1086 $out .= $row[
'code'];
1089 $out .=
'</option>';
1092 $out .=
'</select>';
1094 if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
1095 $out .=
ajax_multiautocompleter(
'location_incoterms',
'', DOL_URL_ROOT.
'/core/ajax/locationincoterms.php').
"\n";
1096 $moreattrib .=
' autocomplete="off"';
1098 $out .=
'<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="'.$location_incoterms.
'">'.
"\n";
1100 if (!empty($page)) {
1101 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp nomargintop nomarginbottom" value="'.$langs->trans(
"Modify").
'"></form>';
1122 public function select_type_of_lines($selected =
'', $htmlname =
'type', $showempty = 0, $hidetext = 0, $forceall = 0)
1125 global $langs, $conf;
1130 if (empty($hidetext)) {
1131 print $langs->trans(
"Type").
': ';
1133 print
'<select class="flat" id="select_'.$htmlname.
'" name="'.$htmlname.
'">';
1135 print
'<option value="-1"';
1136 if ($selected == -1) {
1139 print
'> </option>';
1142 print
'<option value="0"';
1143 if (0 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'product')) {
1146 print
'>'.$langs->trans(
"Product");
1148 print
'<option value="1"';
1149 if (1 == $selected || ($selected == -1 &&
getDolGlobalString(
'MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') ==
'service')) {
1152 print
'>'.$langs->trans(
"Service");
1159 print $langs->trans(
"Service");
1160 print
'<input type="hidden" name="'.$htmlname.
'" value="1">';
1163 print $langs->trans(
"Product");
1164 print
'<input type="hidden" name="'.$htmlname.
'" value="0">';
1166 if ($forceall < 0) {
1167 print
'<input type="hidden" name="'.$htmlname.
'" value="1">';
1182 $num = count($this->cache_types_fees);
1189 $langs->load(
"trips");
1191 $sql =
"SELECT c.code, c.label";
1192 $sql .=
" FROM ".$this->db->prefix().
"c_type_fees as c";
1193 $sql .=
" WHERE active > 0";
1197 $num = $this->
db->num_rows(
$resql);
1201 $obj = $this->
db->fetch_object(
$resql);
1204 $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
1205 $this->cache_types_fees[$obj->code] = $label;
1209 asort($this->cache_types_fees);
1230 global $user, $langs;
1232 dol_syslog(__METHOD__.
" selected=".$selected.
", htmlname=".$htmlname, LOG_DEBUG);
1236 print
'<select id="select_'.$htmlname.
'" class="flat" name="'.$htmlname.
'">';
1238 print
'<option value="-1"';
1239 if ($selected == -1) {
1242 print
'> </option>';
1245 foreach ($this->cache_types_fees as $key => $value) {
1246 print
'<option value="'.$key.
'"';
1247 if ($key == $selected) {
1257 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1284 public function select_company($selected =
'', $htmlname =
'socid', $filter =
'', $showempty =
'', $showtype = 0, $forcecombo = 0, $events = array(), $limit = 0, $morecss =
'minwidth100', $moreparam =
'', $selected_input_value =
'', $hidelabel = 1, $ajaxoptions = array(), $multiple =
false, $excludeids = array(), $showcode = 0)
1287 global $conf, $user, $langs;
1291 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && !$forcecombo) {
1292 if (is_null($ajaxoptions)) {
1293 $ajaxoptions = array();
1296 require_once DOL_DOCUMENT_ROOT .
'/core/lib/ajax.lib.php';
1300 if ($selected && empty($selected_input_value)) {
1301 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1303 $societetmp->fetch($selected);
1304 $selected_input_value = $societetmp->name;
1309 $urloption =
'htmlname='.urlencode(str_replace(
'.',
'_', $htmlname)).
'&outjson=1&filter='.urlencode($filter).(empty($excludeids) ?
'' :
'&excludeids='.join(
',', $excludeids)).($showtype ?
'&showtype='.urlencode($showtype) :
'').($showcode ?
'&showcode='.urlencode($showcode) :
'');
1311 $out .=
'<style type="text/css">.ui-autocomplete { z-index: 1003; }</style>';
1312 if (empty($hidelabel)) {
1313 print $langs->trans(
"RefOrLabel").
' : ';
1314 } elseif ($hidelabel > 1) {
1315 $placeholder = $langs->trans(
"RefOrLabel");
1316 if ($hidelabel == 2) {
1317 $out .=
img_picto($langs->trans(
"Search"),
'search');
1320 $out .=
'<input type="text" class="'.$morecss.
'" name="search_'.$htmlname.
'" id="search_'.$htmlname.
'" value="'.$selected_input_value.
'"'.($placeholder ?
' placeholder="'.dol_escape_htmltag($placeholder).
'"' :
'').
' '.(!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ?
'autofocus' :
'').
' />';
1321 if ($hidelabel == 3) {
1322 $out .=
img_picto($langs->trans(
"Search"),
'search');
1325 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
1328 $out .= $this->
select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events,
'', 0, $limit, $morecss, $moreparam, $multiple, $excludeids, $showcode);
1356 public function select_thirdparty_list($selected =
'', $htmlname =
'socid', $filter =
'', $showempty =
'', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey =
'', $outputmode = 0, $limit = 0, $morecss =
'minwidth100', $moreparam =
'', $multiple =
false, $excludeids = array(), $showcode = 0)
1359 global $conf, $user, $langs;
1360 global $hookmanager;
1364 $outarray = array();
1366 if ($selected ===
'') {
1367 $selected = array();
1368 } elseif (!is_array($selected)) {
1369 $selected = array($selected);
1373 if (function_exists(
'testSqlAndScriptInject')) {
1380 $sql =
"SELECT s.rowid, s.nom as name, s.name_alias, s.tva_intra, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
1381 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1382 $sql .=
", s.address, s.zip, s.town";
1383 $sql .=
", dictp.code as country_code";
1385 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
1386 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1387 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as dictp ON dictp.rowid = s.fk_pays";
1389 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1390 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
1392 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
1393 if (!empty($user->socid)) {
1394 $sql .=
" AND s.rowid = ".((int) $user->socid);
1397 $sql .=
" AND (".$filter.
")";
1399 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1400 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1402 if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) {
1403 $sql .=
" AND s.status <> 0";
1405 if (!empty($excludeids)) {
1406 $sql .=
" AND s.rowid NOT IN (".$this->db->sanitize(join(
',', $excludeids)).
")";
1409 $parameters = array();
1410 $reshook = $hookmanager->executeHooks(
'selectThirdpartyListWhere', $parameters);
1411 $sql .= $hookmanager->resPrint;
1413 if ($filterkey && $filterkey !=
'') {
1415 $prefix = empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
1417 $scrit = explode(
' ', $filterkey);
1419 if (count($scrit) > 1) {
1422 foreach ($scrit as $crit) {
1426 $sql .=
"(s.nom LIKE '".$this->db->escape($prefix.$crit).
"%')";
1429 if (count($scrit) > 1) {
1433 $sql .=
" OR s.barcode LIKE '".$this->db->escape($prefix.$filterkey).
"%'";
1435 $sql .=
" OR s.code_client LIKE '".$this->db->escape($prefix.$filterkey).
"%' OR s.code_fournisseur LIKE '".$this->
db->escape($prefix.$filterkey).
"%'";
1436 $sql .=
" OR s.name_alias LIKE '".$this->db->escape($prefix.$filterkey).
"%' OR s.tva_intra LIKE '".$this->
db->escape($prefix.$filterkey).
"%'";
1439 $sql .= $this->
db->order(
"nom",
"ASC");
1440 $sql .= $this->
db->plimit($limit, 0);
1443 dol_syslog(get_class($this).
"::select_thirdparty_list", LOG_DEBUG);
1447 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1452 $out .=
'<select id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'"'.($moreparam ?
' '.$moreparam :
'').
' name="'.$htmlname.($multiple ?
'[]' :
'').
'" '.($multiple ?
'multiple' :
'').
'>'.
"\n";
1454 $textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) :
'');
1455 if (!empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
1458 if ($showempty && !is_numeric($showempty)) {
1459 $textifempty = $langs->trans($showempty);
1461 $textifempty .= $langs->trans(
"All");
1465 $out .=
'<option value="-1" data-html="'.dol_escape_htmltag(
'<span class="opacitymedium">'.($textifempty ? $textifempty :
' ').
'</span>').
'">'.$textifempty.
'</option>'.
"\n";
1470 $num = $this->
db->num_rows(
$resql);
1474 $obj = $this->
db->fetch_object(
$resql);
1476 if ($showcode || !empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
1477 if (($obj->client) && (!empty($obj->code_client))) {
1478 $label = $obj->code_client.
' - ';
1480 if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
1481 $label .= $obj->code_fournisseur.
' - ';
1483 $label .=
' '.$obj->name;
1485 $label = $obj->name;
1488 if (!empty($obj->name_alias)) {
1489 $label .=
' ('.$obj->name_alias.
')';
1492 if (!empty($conf->global->SOCIETE_SHOW_VAT_IN_LIST) && !empty($obj->tva_intra)) {
1493 $label .=
' - '.$obj->tva_intra;
1496 $labelhtml = $label;
1499 $companytemp->id = $obj->rowid;
1500 $companytemp->client = $obj->client;
1501 $companytemp->fournisseur = $obj->fournisseur;
1502 $tmptype = $companytemp->getTypeUrl(1,
'', 0,
'span');
1504 $labelhtml .=
' '.$tmptype;
1507 if ($obj->client || $obj->fournisseur) {
1510 if ($obj->client == 1 || $obj->client == 3) {
1511 $label .= $langs->trans(
"Customer");
1513 if ($obj->client == 2 || $obj->client == 3) {
1514 $label .= ($obj->client == 3 ?
', ' :
'').$langs->trans(
"Prospect");
1516 if ($obj->fournisseur) {
1517 $label .= ($obj->client ?
', ' :
'').$langs->trans(
"Supplier");
1519 if ($obj->client || $obj->fournisseur) {
1524 if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
1525 $s = ($obj->address ?
' - '.$obj->address :
'').($obj->zip ?
' - '.$obj->zip :
'').($obj->town ?
' '.$obj->town :
'');
1526 if (!empty($obj->country_code)) {
1527 $s .=
', '.$langs->trans(
'Country'.$obj->country_code);
1533 if (empty($outputmode)) {
1534 if (in_array($obj->rowid, $selected)) {
1535 $out .=
'<option value="'.$obj->rowid.
'" selected data-html="'.
dol_escape_htmltag($labelhtml).
'">'.$label.
'</option>';
1537 $out .=
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labelhtml).
'">'.$label.
'</option>';
1540 array_push($outarray, array(
'key'=>$obj->rowid,
'value'=>$label,
'label'=>$label,
'labelhtml'=>$labelhtml));
1544 if (($i % 10) == 0) {
1549 $out .=
'</select>'.
"\n";
1554 $this->result = array(
'nbofthirdparties'=>$num);
1577 global $langs, $conf;
1580 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1581 $sql .=
" re.description, re.fk_facture_source";
1582 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as re";
1583 $sql .=
" WHERE re.fk_soc = ".(int) $socid;
1584 $sql .=
" AND re.entity = ".$conf->entity;
1586 $sql .=
" AND ".$filter;
1588 $sql .=
" ORDER BY re.description ASC";
1590 dol_syslog(get_class($this).
"::select_remises", LOG_DEBUG);
1593 print
'<select id="select_'.$htmlname.
'" class="flat maxwidthonsmartphone" name="'.$htmlname.
'">';
1594 $num = $this->
db->num_rows(
$resql);
1596 $qualifiedlines = $num;
1600 print
'<option value="0"> </option>';
1602 $obj = $this->
db->fetch_object(
$resql);
1603 $desc =
dol_trunc($obj->description, 40);
1604 if (preg_match(
'/\(CREDIT_NOTE\)/', $desc)) {
1605 $desc = preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $desc);
1607 if (preg_match(
'/\(DEPOSIT\)/', $desc)) {
1608 $desc = preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"Deposit"), $desc);
1610 if (preg_match(
'/\(EXCESS RECEIVED\)/', $desc)) {
1611 $desc = preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $desc);
1613 if (preg_match(
'/\(EXCESS PAID\)/', $desc)) {
1614 $desc = preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $desc);
1618 if ($selected > 0 && $selected == $obj->rowid) {
1619 $selectstring =
' selected';
1623 if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
1625 $disabled =
' disabled';
1628 if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) {
1630 if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
1631 $desc = $desc.
' - '.$tmpfac->ref;
1635 print
'<option value="'.$obj->rowid.
'"'.$selectstring.$disabled.
'>'.$desc.
' ('.
price($obj->amount_ht).
' '.$langs->trans(
"HT").
' - '.
price($obj->amount_ttc).
' '.$langs->trans(
"TTC").
')</option>';
1642 return $qualifiedlines;
1670 public function select_contacts($socid, $selected =
'', $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $showsoc = 0, $forcecombo = 0, $events = array(), $options_only =
false, $moreparam =
'', $htmlid =
'')
1673 print $this->
selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $morecss, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid);
1701 public function selectcontacts($socid, $selected =
'', $htmlname =
'contactid', $showempty = 0, $exclude =
'', $limitto =
'', $showfunction = 0, $morecss =
'', $options_only =
false, $showsoc = 0, $forcecombo = 0, $events = array(), $moreparam =
'', $htmlid =
'', $multiple =
false, $disableifempty = 0)
1703 global $conf, $langs, $hookmanager, $action;
1705 $langs->load(
'companies');
1707 if (empty($htmlid)) {
1708 $htmlid = $htmlname;
1712 if ($selected ===
'') {
1713 $selected = array();
1714 } elseif (!is_array($selected)) {
1715 $selected = array($selected);
1719 if (!is_object($hookmanager)) {
1720 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
1725 $sql =
"SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste, sp.email, sp.phone, sp.phone_perso, sp.phone_mobile, sp.town AS contact_town";
1726 if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1727 $sql .=
", s.nom as company, s.town AS company_town";
1729 $sql .=
" FROM ".$this->db->prefix().
"socpeople as sp";
1730 if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1731 $sql .=
" LEFT OUTER JOIN ".$this->db->prefix().
"societe as s ON s.rowid=sp.fk_soc";
1733 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
1734 if ($socid > 0 || $socid == -1) {
1735 $sql .=
" AND sp.fk_soc = ".((int) $socid);
1737 if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) {
1738 $sql .=
" AND sp.statut <> 0";
1741 $parameters = array();
1742 $reshook = $hookmanager->executeHooks(
'selectContactListWhere', $parameters);
1743 $sql .= $hookmanager->resPrint;
1744 $sql .=
" ORDER BY sp.lastname ASC";
1746 dol_syslog(get_class($this).
"::selectcontacts", LOG_DEBUG);
1749 $num = $this->
db->num_rows(
$resql);
1751 if ($htmlname !=
'none' && !$options_only) {
1752 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="'.$htmlid.
'" name="'.$htmlname.(($num || empty($disableifempty)) ?
'' :
' disabled').($multiple ?
'[]' :
'').
'" '.($multiple ?
'multiple' :
'').
' '.(!empty($moreparam) ? $moreparam :
'').
'>';
1755 if ($showempty && ! is_numeric($showempty)) {
1756 $textforempty = $showempty;
1757 $out .=
'<option class="optiongrey" value="-1"'.(in_array(-1, $selected) ?
' selected' :
'').
'>'.$textforempty.
'</option>';
1759 if (($showempty == 1 || ($showempty == 3 && $num > 1)) && ! $multiple) {
1760 $out .=
'<option value="0"'.(in_array(0, $selected) ?
' selected' :
'').
'> </option>';
1762 if ($showempty == 2) {
1763 $out .=
'<option value="0"'.(in_array(0, $selected) ?
' selected' :
'').
'>-- '.$langs->trans(
"Internal").
' --</option>';
1769 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1770 $contactstatic =
new Contact($this->
db);
1773 $obj = $this->
db->fetch_object(
$resql);
1776 $extendedInfos =
'';
1777 if (!empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) {
1778 $extendedInfos = array();
1779 $email = trim($obj->email);
1780 if (!empty($email)) {
1781 $extendedInfos[] = $email;
1783 $phone = trim($obj->phone);
1784 $phone_perso = trim($obj->phone_perso);
1785 $phone_mobile = trim($obj->phone_mobile);
1786 if (!empty($phone)) {
1787 $extendedInfos[] = $phone;
1789 if (!empty($phone_perso)) {
1790 $extendedInfos[] = $phone_perso;
1792 if (!empty($phone_mobile)) {
1793 $extendedInfos[] = $phone_mobile;
1796 $contact_town = trim($obj->contact_town);
1797 $company_town = trim($obj->company_town);
1798 if (!empty($contact_town)) {
1799 $extendedInfos[] = $contact_town;
1800 } elseif (!empty($company_town)) {
1801 $extendedInfos[] = $company_town;
1803 $extendedInfos = implode(
' - ', $extendedInfos);
1804 if (!empty($extendedInfos)) {
1805 $extendedInfos =
' - '.$extendedInfos;
1809 $contactstatic->id = $obj->rowid;
1810 $contactstatic->lastname = $obj->lastname;
1811 $contactstatic->firstname = $obj->firstname;
1812 if ($obj->statut == 1) {
1813 if ($htmlname !=
'none') {
1815 if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1818 if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1821 if (!empty($selected) && in_array($obj->rowid, $selected)) {
1822 $out .=
'<option value="'.$obj->rowid.
'"';
1824 $out .=
' disabled';
1826 $out .=
' selected>';
1827 $out .= $contactstatic->getFullName($langs).$extendedInfos;
1828 if ($showfunction && $obj->poste) {
1829 $out .=
' ('.$obj->poste.
')';
1831 if (($showsoc > 0) && $obj->company) {
1832 $out .=
' - ('.$obj->company.
')';
1834 $out .=
'</option>';
1836 $out .=
'<option value="'.$obj->rowid.
'"';
1838 $out .=
' disabled';
1841 $out .= $contactstatic->getFullName($langs).$extendedInfos;
1842 if ($showfunction && $obj->poste) {
1843 $out .=
' ('.$obj->poste.
')';
1845 if (($showsoc > 0) && $obj->company) {
1846 $out .=
' - ('.$obj->company.
')';
1848 $out .=
'</option>';
1851 if (in_array($obj->rowid, $selected)) {
1852 $out .= $contactstatic->getFullName($langs).$extendedInfos;
1853 if ($showfunction && $obj->poste) {
1854 $out .=
' ('.$obj->poste.
')';
1856 if (($showsoc > 0) && $obj->company) {
1857 $out .=
' - ('.$obj->company.
')';
1865 $labeltoshow = ($socid != -1) ? ($langs->trans($socid ?
"NoContactDefinedForThirdParty" :
"NoContactDefined")) : $langs->trans(
'SelectAThirdPartyFirst');
1866 $out .=
'<option class="disabled" value="-1"'.(($showempty == 2 || $multiple) ?
'' :
' selected').
' disabled="disabled">';
1867 $out .= $labeltoshow;
1868 $out .=
'</option>';
1871 $parameters = array(
1873 'htmlname'=>$htmlname,
1876 'showfunction'=>$showfunction,
1877 'showsoc'=>$showsoc,
1880 $reshook = $hookmanager->executeHooks(
'afterSelectContactOptions', $parameters, $this, $action);
1882 if ($htmlname !=
'none' && !$options_only) {
1883 $out .=
'</select>';
1886 if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
1887 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
1915 public function select_users($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0')
1918 print $this->
select_dolusers($selected, $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity);
1946 public function select_dolusers($selected =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $show_every = 0, $enableonlytext =
'', $morecss =
'', $notdisabled = 0, $outputmode = 0, $multiple =
false, $forcecombo = 0)
1949 global $conf, $user, $langs, $hookmanager;
1953 if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) {
1954 $selected = $user->id;
1957 if ($selected ===
'') {
1958 $selected = array();
1959 } elseif (!is_array($selected)) {
1960 $selected = array($selected);
1963 $excludeUsers =
null;
1964 $includeUsers =
null;
1967 if (is_array($exclude)) {
1968 $excludeUsers = implode(
",", $exclude);
1971 if (is_array($include)) {
1972 $includeUsers = implode(
",", $include);
1973 } elseif ($include ==
'hierarchy') {
1975 $includeUsers = implode(
",", $user->getAllChildIds(0));
1976 } elseif ($include ==
'hierarchyme') {
1978 $includeUsers = implode(
",", $user->getAllChildIds(1));
1982 $outarray = array();
1985 $sql =
"SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut as status, u.login, u.admin, u.entity, u.photo";
1986 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
1987 $sql .=
", e.label";
1989 $sql .=
" FROM ".$this->db->prefix().
"user as u";
1990 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
1991 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entity as e ON e.rowid = u.entity";
1992 if ($force_entity) {
1993 $sql .=
" WHERE u.entity IN (0, ".$this->db->sanitize($force_entity).
")";
1995 $sql .=
" WHERE u.entity IS NOT NULL";
1998 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1999 $sql .=
" LEFT JOIN ".$this->db->prefix().
"usergroup_user as ug";
2000 $sql .=
" ON ug.fk_user = u.rowid";
2001 $sql .=
" WHERE ug.entity = ".$conf->entity;
2003 $sql .=
" WHERE u.entity IN (0, ".$conf->entity.
")";
2006 if (!empty($user->socid)) {
2007 $sql .=
" AND u.fk_soc = ".((int) $user->socid);
2009 if (is_array($exclude) && $excludeUsers) {
2010 $sql .=
" AND u.rowid NOT IN (".$this->db->sanitize($excludeUsers).
")";
2012 if ($includeUsers) {
2013 $sql .=
" AND u.rowid IN (".$this->db->sanitize($includeUsers).
")";
2015 if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $notdisabled) {
2016 $sql .=
" AND u.statut <> 0";
2018 if (!empty($morefilter)) {
2019 $sql .=
" ".$morefilter;
2023 $reshook = $hookmanager->executeHooks(
'addSQLWhereFilterOnSelectUsers', array(), $this, $action);
2024 if (!empty($reshook)) {
2025 $sql .= $hookmanager->resPrint;
2028 if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) {
2029 $sql .=
" ORDER BY u.statut DESC, u.firstname ASC, u.lastname ASC";
2031 $sql .=
" ORDER BY u.statut DESC, u.lastname ASC, u.firstname ASC";
2034 dol_syslog(get_class($this).
"::select_dolusers", LOG_DEBUG);
2038 $num = $this->
db->num_rows(
$resql);
2042 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
' minwidth200').
'" id="'.$htmlname.
'" name="'.$htmlname.($multiple ?
'[]' :
'').
'" '.($multiple ?
'multiple' :
'').
' '.($disabled ?
' disabled' :
'').
'>';
2043 if ($show_empty && !$multiple) {
2044 $textforempty =
' ';
2045 if (!empty($conf->use_javascript_ajax)) {
2046 $textforempty =
' ';
2048 if (!is_numeric($show_empty)) {
2049 $textforempty = $show_empty;
2051 $out .=
'<option class="optiongrey" value="'.($show_empty < 0 ? $show_empty : -1).
'"'.((empty($selected) || in_array(-1, $selected)) ?
' selected' :
'').
'>'.$textforempty.
'</option>'.
"\n";
2054 $out .=
'<option value="-2"'.((in_array(-2, $selected)) ?
' selected' :
'').
'>-- '.$langs->trans(
"Everybody").
' --</option>'.
"\n";
2057 $userstatic =
new User($this->
db);
2060 $obj = $this->
db->fetch_object(
$resql);
2062 $userstatic->id = $obj->rowid;
2063 $userstatic->lastname = $obj->lastname;
2064 $userstatic->firstname = $obj->firstname;
2065 $userstatic->photo = $obj->photo;
2066 $userstatic->statut = $obj->status;
2067 $userstatic->entity = $obj->entity;
2068 $userstatic->admin = $obj->admin;
2071 if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2072 $disableline = ($enableonlytext ? $enableonlytext :
'1');
2075 $labeltoshow =
''; $labeltoshowhtml =
'';
2079 if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) {
2082 $labeltoshow .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2083 $labeltoshowhtml .= $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength);
2084 if (empty($obj->firstname) && empty($obj->lastname)) {
2085 $labeltoshow .= $obj->login;
2086 $labeltoshowhtml .= $obj->login;
2090 $moreinfo =
''; $moreinfohtml =
'';
2091 if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
2092 $moreinfo .= ($moreinfo ?
' - ' :
' (');
2093 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(');
2094 $moreinfo .= $obj->login;
2095 $moreinfohtml .= $obj->login;
2097 if ($showstatus >= 0) {
2098 if ($obj->status == 1 && $showstatus == 1) {
2099 $moreinfo .= ($moreinfo ?
' - ' :
' (').$langs->trans(
'Enabled');
2100 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').$langs->trans(
'Enabled');
2102 if ($obj->status == 0 && $showstatus == 1) {
2103 $moreinfo .= ($moreinfo ?
' - ' :
' (').$langs->trans(
'Disabled');
2104 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').$langs->trans(
'Disabled');
2107 if (
isModEnabled(
'multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
2108 if (!$obj->entity) {
2109 $moreinfo .= ($moreinfo ?
' - ' :
' (').$langs->trans(
"AllEntities");
2110 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').$langs->trans(
"AllEntities");
2112 if ($obj->entity != $conf->entity) {
2113 $moreinfo .= ($moreinfo ?
' - ' :
' (').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2114 $moreinfohtml .= ($moreinfohtml ?
' - ' :
' <span class="opacitymedium">(').($obj->label ? $obj->label : $langs->trans(
"EntityNameNotDefined"));
2118 $moreinfo .= ($moreinfo ?
')' :
'');
2119 $moreinfohtml .= ($moreinfohtml ?
')' :
'');
2120 if ($disableline && $disableline !=
'1') {
2122 $moreinfo .=
' - '.$disableline;
2123 $moreinfohtml .=
' - '.$disableline;
2125 $labeltoshow .= $moreinfo;
2126 $labeltoshowhtml .= $moreinfohtml;
2128 $out .=
'<option value="'.$obj->rowid.
'"';
2130 $out .=
' disabled';
2132 if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
2133 $out .=
' selected';
2135 $out .=
' data-html="';
2138 $outhtml .= $userstatic->getNomUrl(-3,
'', 0, 1, 24, 1,
'login',
'', 1).
' ';
2140 if ($showstatus >= 0 && $obj->status == 0) {
2141 $outhtml .=
'<strike class="opacitymediumxxx">';
2143 $outhtml .= $labeltoshowhtml;
2144 if ($showstatus >= 0 && $obj->status == 0) {
2145 $outhtml .=
'</strike>';
2149 $out .= $labeltoshow;
2150 $out .=
'</option>';
2152 $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength).$moreinfo;
2157 $out .=
'<select class="flat" id="'.$htmlname.
'" name="'.$htmlname.
'" disabled>';
2158 $out .=
'<option value="">'.$langs->trans(
"None").
'</option>';
2160 $out .=
'</select>';
2162 if ($num && !$forcecombo) {
2164 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
2202 public function select_dolusers_forevent($action =
'', $htmlname =
'userid', $show_empty = 0, $exclude =
null, $disabled = 0, $include =
'', $enableonly =
'', $force_entity =
'0', $maxlength = 0, $showstatus = 0, $morefilter =
'', $showproperties = 0, $listofuserid = array(), $listofcontactid = array(), $listofotherid = array())
2205 global $conf, $user, $langs;
2207 $userstatic =
new User($this->
db);
2211 $assignedtouser = array();
2212 if (!empty($_SESSION[
'assignedtouser'])) {
2213 $assignedtouser = json_decode($_SESSION[
'assignedtouser'],
true);
2215 $nbassignetouser = count($assignedtouser);
2218 if ($nbassignetouser) {
2219 $out .=
'<ul class="attendees">';
2223 foreach ($assignedtouser as $key => $value) {
2224 if ($value[
'id'] == $ownerid) {
2229 $userstatic->fetch($value[
'id']);
2230 $out .= $userstatic->getNomUrl(-1);
2232 $ownerid = $value[
'id'];
2233 $out .=
' ('.$langs->trans(
"Owner").
')';
2235 if ($nbassignetouser > 1 && $action !=
'view') {
2236 $out .=
' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans(
"Remove"),
'delete',
'', 0, 1).
'" value="'.$userstatic->id.
'" class="removedassigned reposition" id="removedassigned_'.$userstatic->id.
'" name="removedassigned_'.$userstatic->id.
'">';
2239 if ($showproperties) {
2240 if ($ownerid == $value[
'id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
2241 $out .=
'<div class="myavailability inline-block">';
2242 $out .=
'<span class="hideonsmartphone"> - <span class="opacitymedium">'.$langs->trans(
"Availability").
':</span> </span><input id="transparency" class="paddingrightonly" '.($action ==
'view' ?
'disabled' :
'').
' type="checkbox" name="transparency"'.($listofuserid[$ownerid][
'transparency'] ?
' checked' :
'').
'><label for="transparency">'.$langs->trans(
"Busy").
'</label>';
2252 if ($nbassignetouser) {
2257 if ($action !=
'view') {
2258 $out .=
'<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
2259 $out .=
'<script type="text/javascript">jQuery(document).ready(function () {';
2260 $out .=
'jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });';
2261 $out .=
'jQuery(".assignedtouser").change(function() { console.log(jQuery(".assignedtouser option:selected").val());';
2262 $out .=
' if (jQuery(".assignedtouser option:selected").val() > 0) { jQuery("#'.$action.
'assignedtouser").attr("disabled", false); }';
2263 $out .=
' else { jQuery("#'.$action.
'assignedtouser").attr("disabled", true); }';
2265 $out .=
'})</script>';
2266 $out .= $this->
select_dolusers(
'', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
2267 $out .=
' <input type="submit" disabled class="button valignmiddle smallpaddingimp reposition" id="'.$action.
'assignedtouser" name="'.$action.
'assignedtouser" value="'.
dol_escape_htmltag($langs->trans(
"Add")).
'">';
2303 public function select_produits($selected =
'', $htmlname =
'productid', $filtertype =
'', $limit = 0, $price_level = 0, $status = 1, $finished = 2, $selected_input_value =
'', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $selected_combinations =
null, $nooutput = 0, $status_purchase = -1)
2306 global $langs, $conf;
2311 $price_level = (!empty($price_level) ? $price_level : 0);
2312 if (is_null($ajaxoptions)) {
2313 $ajaxoptions = array();
2324 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
2327 if ($selected && empty($selected_input_value)) {
2328 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
2329 $producttmpselect =
new Product($this->
db);
2330 $producttmpselect->fetch($selected);
2331 $selected_input_value = $producttmpselect->ref;
2332 unset($producttmpselect);
2335 if ($filtertype ==
'') {
2343 $urloption =
'htmlname='.$htmlname.
'&outjson=1&price_level='.$price_level.
'&type='.$filtertype.
'&mode=1&status='.$status.
'&status_purchase='.$status_purchase.
'&finished='.$finished.
'&hidepriceinlabel='.$hidepriceinlabel.
'&warehousestatus='.$warehouseStatus;
2345 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2346 $urloption .=
'&socid='.$socid;
2348 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
2350 if (
isModEnabled(
'variants') && is_array($selected_combinations)) {
2354 <!-- script to auto show attributes select tags if a variant was selected -->
2356 // auto show attributes fields
2357 selected = '.json_encode($selected_combinations).
';
2360 jQuery(document).ready(function () {
2362 jQuery("input[name=\'prod_entry_mode\']").change(function () {
2363 if (jQuery(this).val() == \'free\') {
2364 jQuery(\'div#attributes_box\').empty();
2368 jQuery("input#'.$htmlname.
'").change(function () {
2370 if (!jQuery(this).val()) {
2371 jQuery(\'div#attributes_box\').empty();
2375 console.log("A change has started. We get variants fields to inject html select");
2377 jQuery.getJSON("'.DOL_URL_ROOT.
'/variants/ajax/getCombinations.php", {
2378 id: jQuery(this).val()
2379 }, function (data) {
2380 jQuery(\'div#attributes_box\').empty();
2382 jQuery.each(data, function (key, val) {
2384 combvalues[val.id] = val.values;
2386 var span = jQuery(document.createElement(\'div\')).css({
2387 \'display\': \'table-row\'
2391 jQuery(document.createElement(\'div\')).text(val.label).css({
2392 \'font-weight\': \'bold\',
2393 \'display\': \'table-cell\'
2397 var html = jQuery(document.createElement(\'select\')).attr(\'name\', \'combinations[\' + val.id + \']\').css({
2398 \'margin-left\': \'15px\',
2399 \'white-space\': \'pre\'
2401 jQuery(document.createElement(\'option\')).val(\'\')
2404 jQuery.each(combvalues[val.id], function (key, val) {
2405 var tag = jQuery(document.createElement(\'option\')).val(val.id).html(val.value);
2407 if (selected[val.fk_product_attribute] == val.id) {
2408 tag.attr(\'selected\', \'selected\');
2415 jQuery(\'div#attributes_box\').append(span);
2420 '.($selected ?
'jQuery("input#'.$htmlname.
'").change();' :
'').
'
2426 if (empty($hidelabel)) {
2427 $out .= $langs->trans(
"RefOrLabel").
' : ';
2428 } elseif ($hidelabel > 1) {
2429 $placeholder =
' placeholder="'.$langs->trans(
"RefOrLabel").
'"';
2430 if ($hidelabel == 2) {
2431 $out .=
img_picto($langs->trans(
"Search"),
'search');
2434 $out .=
'<input type="text" class="minwidth100'.($morecss ?
' '.$morecss :
'').
'" name="search_'.$htmlname.
'" id="search_'.$htmlname.
'" value="'.$selected_input_value.
'"'.$placeholder.
' '.(!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ?
'autofocus' :
'').
' />';
2435 if ($hidelabel == 3) {
2436 $out .=
img_picto($langs->trans(
"Search"),
'search');
2439 $out .= $this->
select_produits_list($selected, $htmlname, $filtertype, $limit, $price_level,
'', $status, $finished, 0, $socid, $showempty, $forcecombo, $morecss, $hidepriceinlabel, $warehouseStatus, $status_purchase);
2442 if (empty($nooutput)) {
2466 public function select_bom($selected =
'', $htmlname =
'bom_id', $limit = 0, $status = 1, $type = 0, $showempty =
'1', $morecss =
'', $nooutput =
'', $forcecombo = 0, $TProducts = [])
2469 global $conf, $user, $langs, $db;
2471 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
2477 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
2482 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
2484 $sql =
'SELECT b.rowid, b.ref, b.label, b.fk_product';
2485 $sql.=
' FROM '.MAIN_DB_PREFIX.
'bom_bom as b';
2486 $sql.=
' WHERE b.entity IN ('.getEntity(
'bom').
')';
2487 if (!empty($status)) $sql.=
' AND status = '. (
int) $status;
2488 if (!empty($type)) $sql.=
' AND bomtype = '. (
int) $type;
2489 if (!empty($TProducts)) $sql .=
' AND fk_product IN ('.$this->
db->sanitize(implode(
',', $TProducts)).
')';
2490 if (!empty($limit)) $sql.=
' LIMIT '. (
int) $limit;
2491 $resql = $db->query($sql);
2494 $out .=
'<option value="-1"';
2495 if (empty($selected)) $out .=
' selected';
2496 $out .=
'> </option>';
2498 while ($obj = $db->fetch_object(
$resql)) {
2500 $res = $product->fetch($obj->fk_product);
2501 $out .=
'<option value="'.$obj->rowid.
'"';
2502 if ($obj->rowid == $selected) $out .=
'selected';
2503 $out .=
'>'.$obj->ref.
' - '.$product->label .
' - '. $obj->label.
'</option>';
2509 $out .=
'</select>';
2510 if (empty($nooutput)) {
2543 public function select_produits_list($selected =
'', $htmlname =
'productid', $filtertype =
'', $limit = 20, $price_level = 0, $filterkey =
'', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty =
'1', $forcecombo = 0, $morecss =
'', $hidepriceinlabel = 0, $warehouseStatus =
'', $status_purchase = -1)
2546 global $langs, $conf;
2547 global $hookmanager;
2550 $outarray = array();
2553 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
2554 $langs->load(
'other');
2557 $warehouseStatusArray = array();
2558 if (!empty($warehouseStatus)) {
2559 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
2560 if (preg_match(
'/warehouseclosed/', $warehouseStatus)) {
2563 if (preg_match(
'/warehouseopen/', $warehouseStatus)) {
2566 if (preg_match(
'/warehouseinternal/', $warehouseStatus)) {
2571 $selectFields =
" p.rowid, p.ref, p.label, p.description, p.barcode, p.fk_country, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.duration, p.fk_price_expression";
2572 if (count($warehouseStatusArray)) {
2573 $selectFieldsGrouped =
", sum(".$this->db->ifsql(
"e.statut IS NULL",
"0",
"ps.reel").
") as stock";
2575 $selectFieldsGrouped =
", ".$this->db->ifsql(
"p.stock IS NULL", 0,
"p.stock").
" AS stock";
2579 $sql .= $selectFields.$selectFieldsGrouped;
2581 if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) {
2583 $sql .=
", (SELECT ".$this->db->prefix().
"categorie_product.fk_categorie
2584 FROM ".$this->
db->prefix().
"categorie_product
2585 WHERE ".$this->
db->prefix().
"categorie_product.fk_product=p.rowid
2587 ) AS categorie_product_id ";
2591 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2592 $sql .=
', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
2593 $sql .=
' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref';
2594 $selectFields .=
", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
2597 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
2598 $sql .=
", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
2599 $selectFields .=
', unit_long, unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units';
2604 $sql .=
", pl.label as label_translated";
2605 $sql .=
", pl.description as description_translated";
2606 $selectFields .=
", label_translated";
2607 $selectFields .=
", description_translated";
2610 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2611 $sql .=
", (SELECT pp.rowid FROM ".$this->db->prefix().
"product_price as pp WHERE pp.fk_product = p.rowid";
2612 if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2613 $sql .=
" AND price_level = ".((int) $price_level);
2615 $sql .=
" ORDER BY date_price";
2616 $sql .=
" DESC LIMIT 1) as price_rowid";
2617 $sql .=
", (SELECT pp.price_by_qty FROM ".$this->db->prefix().
"product_price as pp WHERE pp.fk_product = p.rowid";
2618 if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2619 $sql .=
" AND price_level = ".((int) $price_level);
2621 $sql .=
" ORDER BY date_price";
2622 $sql .=
" DESC LIMIT 1) as price_by_qty";
2623 $selectFields .=
", price_rowid, price_by_qty";
2625 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2626 if (count($warehouseStatusArray)) {
2627 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_stock as ps on ps.fk_product = p.rowid";
2628 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".
getEntity(
'stock').
")";
2629 $sql .=
' AND e.statut IN ('.$this->db->sanitize($this->
db->escape(implode(
',', $warehouseStatusArray))).
')';
2633 if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
2634 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
2638 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2639 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_customer_price as pcp ON pcp.fk_soc=".((int) $socid).
" AND pcp.fk_product=p.rowid";
2642 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
2643 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_units u ON u.rowid = p.fk_unit";
2647 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_lang as pl ON pl.fk_product = p.rowid ";
2648 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && !empty($socid)) {
2649 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
2651 $result = $soc->fetch($socid);
2652 if ($result > 0 && !empty($soc->default_lang)) {
2653 $sql .=
" AND pl.lang = '".$this->db->escape($soc->default_lang).
"'";
2655 $sql .=
" AND pl.lang = '".$this->db->escape($langs->getDefaultLang()).
"'";
2658 $sql .=
" AND pl.lang = '".$this->db->escape($langs->getDefaultLang()).
"'";
2662 if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
2663 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_attribute_combination pac ON pac.fk_product_child = p.rowid";
2666 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
2668 if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
2669 $sql .=
" AND pac.rowid IS NULL";
2672 if ($finished == 0) {
2673 $sql .=
" AND p.finished = ".((int) $finished);
2674 } elseif ($finished == 1) {
2675 $sql .=
" AND p.finished = ".((int) $finished);
2677 $sql .=
" AND p.tosell = ".((int) $status);
2679 } elseif ($status >= 0) {
2680 $sql .=
" AND p.tosell = ".((int) $status);
2682 if ($status_purchase >= 0) {
2683 $sql .=
" AND p.tobuy = ".((int) $status_purchase);
2686 if (strval($filtertype) !=
'') {
2687 $sql .=
" AND p.fk_product_type = ".((int) $filtertype);
2689 $sql .=
" AND p.fk_product_type = 1";
2691 $sql .=
" AND p.fk_product_type = 0";
2694 $parameters = array();
2695 $reshook = $hookmanager->executeHooks(
'selectProductsListWhere', $parameters);
2696 $sql .= $hookmanager->resPrint;
2698 if ($filterkey !=
'') {
2700 $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
2702 $scrit = explode(
' ', $filterkey);
2704 if (count($scrit) > 1) {
2707 foreach ($scrit as $crit) {
2711 $sql .=
"(p.ref LIKE '".$this->db->escape($prefix.$crit).
"%' OR p.label LIKE '".$this->
db->escape($prefix.$crit).
"%'";
2713 $sql .=
" OR pl.label LIKE '".$this->db->escape($prefix.$crit).
"%'";
2715 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
2716 $sql .=
" OR pcp.ref_customer LIKE '".$this->db->escape($prefix.$crit).
"%'";
2718 if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) {
2719 $sql .=
" OR p.description LIKE '".$this->db->escape($prefix.$crit).
"%'";
2721 $sql .=
" OR pl.description LIKE '".$this->db->escape($prefix.$crit).
"%'";
2724 if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
2725 $sql .=
" OR pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit).
"%'";
2730 if (count($scrit) > 1) {
2734 $sql .=
" OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey).
"%'";
2738 if (count($warehouseStatusArray)) {
2739 $sql .=
" GROUP BY ".$selectFields;
2743 if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) {
2744 $sql .=
" ORDER BY categorie_product_id ";
2746 ($conf->global->PRODUCT_SORT_BY_CATEGORY == 1) ? $sql .=
"ASC" : $sql .=
"DESC";
2748 $sql .= $this->
db->order(
"p.ref");
2751 $sql .= $this->
db->plimit($limit, 0);
2754 dol_syslog(get_class($this).
"::select_produits_list search products", LOG_DEBUG);
2755 $result = $this->
db->query($sql);
2757 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
2758 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2759 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
2761 $num = $this->
db->num_rows($result);
2766 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
2770 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
2775 if (!empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
2776 if ($showempty && !is_numeric($showempty)) {
2777 $textifempty = $langs->trans($showempty);
2779 $textifempty .= $langs->trans(
"All");
2782 if ($showempty && !is_numeric($showempty)) {
2783 $textifempty = $langs->trans($showempty);
2787 $out .=
'<option value="-1" selected>'.($textifempty ? $textifempty :
' ').
'</option>';
2791 while ($num && $i < $num) {
2794 $objp = $this->
db->fetch_object($result);
2796 if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) {
2797 $sql =
"SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
2798 $sql .=
" FROM ".$this->db->prefix().
"product_price_by_qty";
2799 $sql .=
" WHERE fk_product_price = ".((int) $objp->price_rowid);
2800 $sql .=
" ORDER BY quantity ASC";
2802 dol_syslog(get_class($this).
"::select_produits_list search prices by qty", LOG_DEBUG);
2803 $result2 = $this->
db->query($sql);
2805 $nb_prices = $this->
db->num_rows($result2);
2807 while ($nb_prices && $j < $nb_prices) {
2808 $objp2 = $this->
db->fetch_object($result2);
2810 $objp->price_by_qty_rowid = $objp2->rowid;
2811 $objp->price_by_qty_price_base_type = $objp2->price_base_type;
2812 $objp->price_by_qty_quantity = $objp2->quantity;
2813 $objp->price_by_qty_unitprice = $objp2->unitprice;
2814 $objp->price_by_qty_remise_percent = $objp2->remise_percent;
2816 $objp->quantity = $objp2->quantity;
2817 $objp->price = $objp2->price;
2818 $objp->unitprice = $objp2->unitprice;
2819 $objp->remise_percent = $objp2->remise_percent;
2832 array_push($outarray, $optJson);
2836 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
2837 $price_product =
new Product($this->
db);
2838 $price_product->fetch($objp->rowid,
'',
'', 1);
2840 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2842 $price_result = $priceparser->parseProduct($price_product);
2843 if ($price_result >= 0) {
2844 $objp->price = $price_result;
2845 $objp->unitprice = $price_result;
2847 $objp->price_ttc =
price2num($objp->price) * (1 + ($objp->tva_tx / 100));
2848 $objp->price_ttc =
price2num($objp->price_ttc,
'MU');
2857 array_push($outarray, $optJson);
2863 $out .=
'</select>';
2865 $this->
db->free($result);
2867 if (empty($outputmode)) {
2891 protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey =
'', $novirtualstock = 0)
2893 global $langs, $conf, $user;
2899 $outlabel_translated =
'';
2901 $outdesc_translated =
'';
2907 $outpricebasetype =
'';
2909 $outdefault_vat_code =
'';
2913 $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
2915 $label = $objp->label;
2916 if (!empty($objp->label_translated)) {
2917 $label = $objp->label_translated;
2919 if (!empty($filterkey) && $filterkey !=
'') {
2920 $label = preg_replace(
'/('.preg_quote($filterkey,
'/').
')/i',
'<strong>$1</strong>', $label, 1);
2923 $outkey = $objp->rowid;
2924 $outref = $objp->ref;
2925 $outrefcust = empty($objp->custref) ?
'' : $objp->custref;
2926 $outlabel = $objp->label;
2927 $outdesc = $objp->description;
2929 $outlabel_translated = $objp->label_translated;
2930 $outdesc_translated = $objp->description_translated;
2932 $outbarcode = $objp->barcode;
2933 $outorigin = $objp->fk_country;
2934 $outpbq = empty($objp->price_by_qty_rowid) ?
'' : $objp->price_by_qty_rowid;
2936 $outtype = $objp->fk_product_type;
2940 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
2941 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2946 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
2947 if (!empty($objp->unit_short)) {
2948 $outvalUnits .=
' - '.$objp->unit_short;
2951 if (!empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) {
2952 if (!empty($objp->weight) && $objp->weight_units !==
null) {
2954 $outvalUnits .=
' - '.$unitToShow;
2956 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
2957 $unitToShow = $objp->length.
' x '.$objp->width.
' x '.$objp->height.
' '.
measuringUnitString(0,
'size', $objp->length_units);
2958 $outvalUnits .=
' - '.$unitToShow;
2960 if (!empty($objp->surface) && $objp->surface_units !==
null) {
2962 $outvalUnits .=
' - '.$unitToShow;
2964 if (!empty($objp->volume) && $objp->volume_units !==
null) {
2966 $outvalUnits .=
' - '.$unitToShow;
2969 if ($outdurationvalue && $outdurationunit) {
2971 'h' => $langs->trans(
'Hour'),
2972 'd' => $langs->trans(
'Day'),
2973 'w' => $langs->trans(
'Week'),
2974 'm' => $langs->trans(
'Month'),
2975 'y' => $langs->trans(
'Year')
2977 if (isset($da[$outdurationunit])) {
2978 $outvalUnits .=
' - '.$outdurationvalue.
' '.$langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ?
's' :
''));
2982 $opt =
'<option value="'.$objp->rowid.
'"';
2983 $opt .= ($objp->rowid == $selected) ?
' selected' :
'';
2984 if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
2985 $opt .=
' pbq="'.$objp->price_by_qty_rowid.
'" data-pbq="'.$objp->price_by_qty_rowid.
'" data-pbqup="'.$objp->price_by_qty_unitprice.
'" data-pbqbase="'.$objp->price_by_qty_price_base_type.
'" data-pbqqty="'.$objp->price_by_qty_quantity.
'" data-pbqpercent="'.$objp->price_by_qty_remise_percent.
'"';
2988 if (!empty($user->rights->stock->lire)) {
2989 if ($objp->stock > 0) {
2990 $opt .=
' class="product_line_stock_ok"';
2991 } elseif ($objp->stock <= 0) {
2992 $opt .=
' class="product_line_stock_too_low"';
2996 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
2997 $opt .=
' data-labeltrans="'.$outlabel_translated.
'"';
2998 $opt .=
' data-desctrans="'.dol_escape_htmltag($outdesc_translated).
'"';
3002 if (!empty($objp->custref)) {
3003 $opt.=
' (' . $objp->custref .
')';
3006 $opt .=
' ('.$outbarcode.
')';
3008 $opt .=
' - '.dol_trunc($label, $maxlengtharticle);
3009 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
3010 $opt .=
' ('.getCountry($outorigin, 1).
')';
3013 $objRef = $objp->ref;
3014 if (!empty($objp->custref)) {
3015 $objRef .=
' (' . $objp->custref .
')';
3017 if (!empty($filterkey) && $filterkey !=
'') {
3018 $objRef = preg_replace(
'/('.preg_quote($filterkey,
'/').
')/i',
'<strong>$1</strong>', $objRef, 1);
3022 $outval .=
' ('.$outbarcode.
')';
3024 $outval .=
' - '.dol_trunc($label, $maxlengtharticle);
3025 if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
3026 $outval .=
' ('.getCountry($outorigin, 1).
')';
3030 $opt .= $outvalUnits;
3031 $outval .= $outvalUnits;
3037 if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
3038 $sql =
"SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
3039 $sql .=
" FROM ".$this->db->prefix().
"product_price";
3040 $sql .=
" WHERE fk_product = ".((int) $objp->rowid);
3041 $sql .=
" AND entity IN (".getEntity(
'productprice').
")";
3042 $sql .=
" AND price_level = ".((int) $price_level);
3043 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3046 dol_syslog(get_class($this).
'::constructProductListOption search price for product '.$objp->rowid.
' AND level '.$price_level.
'', LOG_DEBUG);
3047 $result2 = $this->
db->query($sql);
3049 $objp2 = $this->
db->fetch_object($result2);
3052 if ($objp2->price_base_type ==
'HT') {
3053 $opt .=
' - '.price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"HT");
3054 $outval .=
' - '.price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"HT");
3056 $opt .=
' - '.price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"TTC");
3057 $outval .=
' - '.price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"TTC");
3059 $outprice_ht =
price($objp2->price);
3060 $outprice_ttc =
price($objp2->price_ttc);
3061 $outpricebasetype = $objp2->price_base_type;
3062 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
3063 $outtva_tx = $objp2->tva_tx;
3064 $outdefault_vat_code = $objp2->default_vat_code;
3066 $outtva_tx = $objp->tva_tx;
3067 $outdefault_vat_code = $objp->default_vat_code;
3076 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
3078 $outqty = $objp->quantity;
3079 $outdiscount = $objp->remise_percent;
3080 if ($objp->quantity == 1) {
3081 $opt .=
' - '.price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency).
"/";
3082 $outval .=
' - '.price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency).
"/";
3083 $opt .= $langs->trans(
"Unit");
3084 $outval .= $langs->transnoentities(
"Unit");
3086 $opt .=
' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency).
"/".$objp->quantity;
3087 $outval .=
' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency).
"/".$objp->quantity;
3088 $opt .= $langs->trans(
"Units");
3089 $outval .= $langs->transnoentities(
"Units");
3092 $outprice_ht =
price($objp->unitprice);
3093 $outprice_ttc =
price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
3094 $outpricebasetype = $objp->price_base_type;
3095 $outtva_tx = $objp->tva_tx;
3096 $outdefault_vat_code = $objp->default_vat_code;
3098 if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
3099 $opt .=
" (".price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency).
"/".$langs->trans(
"Unit").
")";
3100 $outval .=
" (".price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency).
"/".$langs->transnoentities(
"Unit").
")";
3102 if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
3103 $opt .=
" - ".$langs->trans(
"Discount").
" : ".
vatrate($objp->remise_percent).
' %';
3104 $outval .=
" - ".$langs->transnoentities(
"Discount").
" : ".
vatrate($objp->remise_percent).
' %';
3108 if (empty($hidepriceinlabel) && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
3109 if (!empty($objp->idprodcustprice)) {
3112 if ($objp->custprice_base_type ==
'HT') {
3113 $opt .=
' - '.price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"HT");
3114 $outval .=
' - '.price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"HT");
3116 $opt .=
' - '.price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"TTC");
3117 $outval .=
' - '.price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"TTC");
3120 $outprice_ht =
price($objp->custprice);
3121 $outprice_ttc =
price($objp->custprice_ttc);
3122 $outpricebasetype = $objp->custprice_base_type;
3123 $outtva_tx = $objp->custtva_tx;
3124 $outdefault_vat_code = $objp->custdefault_vat_code;
3129 if (empty($hidepriceinlabel) && !$found) {
3130 if ($objp->price_base_type ==
'HT') {
3131 $opt .=
' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"HT");
3132 $outval .=
' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"HT");
3134 $opt .=
' - '.price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).
' '.$langs->trans(
"TTC");
3135 $outval .=
' - '.price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).
' '.$langs->transnoentities(
"TTC");
3137 $outprice_ht =
price($objp->price);
3138 $outprice_ttc =
price($objp->price_ttc);
3139 $outpricebasetype = $objp->price_base_type;
3140 $outtva_tx = $objp->tva_tx;
3141 $outdefault_vat_code = $objp->default_vat_code;
3145 if (!empty($user->rights->stock->lire)) {
3146 $opt .=
' - '.$langs->trans(
"Stock").
': '.
price(
price2num($objp->stock,
'MS'));
3148 if ($objp->stock > 0) {
3149 $outval .=
' - <span class="product_line_stock_ok">';
3150 } elseif ($objp->stock <= 0) {
3151 $outval .=
' - <span class="product_line_stock_too_low">';
3153 $outval .= $langs->transnoentities(
"Stock").
': '.
price(
price2num($objp->stock,
'MS'));
3154 $outval .=
'</span>';
3155 if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) {
3156 $langs->load(
"stocks");
3159 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3160 $tmpproduct->load_virtual_stock();
3161 $virtualstock = $tmpproduct->stock_theorique;
3163 $opt .=
' - '.$langs->trans(
"VirtualStock").
':'.$virtualstock;
3165 $outval .=
' - '.$langs->transnoentities(
"VirtualStock").
':';
3166 if ($virtualstock > 0) {
3167 $outval .=
'<span class="product_line_stock_ok">';
3168 } elseif ($virtualstock <= 0) {
3169 $outval .=
'<span class="product_line_stock_too_low">';
3171 $outval .= $virtualstock;
3172 $outval .=
'</span>';
3179 $opt .=
"</option>\n";
3184 'label2'=>$outlabel,
3191 'pricebasetype'=>$outpricebasetype,
3192 'tva_tx'=>$outtva_tx,
3193 'default_vat_code'=>$outdefault_vat_code,
3195 'discount'=>$outdiscount,
3196 'duration_value'=>$outdurationvalue,
3197 'duration_unit'=>$outdurationunit,
3199 'labeltrans'=>$outlabel_translated,
3200 'desctrans'=>$outdesc_translated,
3201 'ref_customer'=>$outrefcust
3221 public function select_produits_fournisseurs($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss =
'', $placeholder =
'')
3224 global $langs, $conf;
3225 global $price_level, $status, $finished;
3227 if (!isset($status)) {
3231 $selected_input_value =
'';
3232 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
3233 if ($selected > 0) {
3234 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3235 $producttmpselect =
new Product($this->
db);
3236 $producttmpselect->fetch($selected);
3237 $selected_input_value = $producttmpselect->ref;
3238 unset($producttmpselect);
3242 $urloption = ($socid > 0 ?
'socid='.$socid.
'&' :
'').
'htmlname='.$htmlname.
'&outjson=1&price_level='.$price_level.
'&type='.$filtertype.
'&mode=2&status='.$status.
'&finished='.$finished.
'&alsoproductwithnosupplierprice='.$alsoproductwithnosupplierprice;
3243 print
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
3244 print ($hidelabel ?
'' : $langs->trans(
"RefOrLabel").
' : ').
'<input type="text" class="minwidth300" name="search_'.$htmlname.
'" id="search_'.$htmlname.
'" value="'.$selected_input_value.
'"'.($placeholder ?
' placeholder="'.$placeholder.
'"' :
'').
'>';
3246 print $this->
select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre,
'', $status, 0, 0, $alsoproductwithnosupplierprice, $morecss, 0, $placeholder);
3269 public function select_produits_fournisseurs_list($socid, $selected =
'', $htmlname =
'productid', $filtertype =
'', $filtre =
'', $filterkey =
'', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss =
'', $showstockinlist = 0, $placeholder =
'')
3272 global $langs, $conf, $user;
3273 global $hookmanager;
3276 $outarray = array();
3278 $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
3280 $langs->load(
'stocks');
3282 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
3283 $langs->load(
'other');
3286 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock, p.tva_tx as tva_tx_sale, p.default_vat_code as default_vat_code_sale,";
3287 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
3288 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name,";
3289 $sql .=
" pfp.supplier_reputation";
3291 if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
3292 $sql .=
", pfp.desc_fourn as description";
3294 $sql .=
", p.description";
3297 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
3298 $sql .=
", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
3301 $sql .=
", pfp.barcode";
3303 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3304 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".
getEntity(
'product').
") )";
3306 $sql .=
" AND pfp.fk_soc = ".((int) $socid);
3308 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON pfp.fk_soc = s.rowid";
3310 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
3311 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_units u ON u.rowid = p.fk_unit";
3313 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
3314 if ($statut != -1) {
3315 $sql .=
" AND p.tobuy = ".((int) $statut);
3317 if (strval($filtertype) !=
'') {
3318 $sql .=
" AND p.fk_product_type = ".((int) $filtertype);
3320 if (!empty($filtre)) {
3321 $sql .=
" ".$filtre;
3324 $parameters = array();
3325 $reshook = $hookmanager->executeHooks(
'selectSuppliersProductsListWhere', $parameters);
3326 $sql .= $hookmanager->resPrint;
3328 if ($filterkey !=
'') {
3330 $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ?
'%' :
'';
3332 $scrit = explode(
' ', $filterkey);
3334 if (count($scrit) > 1) {
3337 foreach ($scrit as $crit) {
3341 $sql .=
"(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit).
"%' OR p.ref LIKE '".$this->
db->escape($prefix.$crit).
"%' OR p.label LIKE '".$this->
db->escape($prefix.$crit).
"%'";
3342 if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
3343 $sql .=
" OR pfp.desc_fourn LIKE '".$this->db->escape($prefix.$crit).
"%'";
3348 if (count($scrit) > 1) {
3352 $sql .=
" OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey).
"%'";
3353 $sql .=
" OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey).
"%'";
3357 $sql .=
" ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC";
3358 $sql .= $this->
db->plimit($limit, 0);
3362 dol_syslog(get_class($this).
"::select_produits_fournisseurs_list", LOG_DEBUG);
3363 $result = $this->
db->query($sql);
3365 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
3366 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
3368 $num = $this->
db->num_rows($result);
3371 $out .=
'<select class="flat '.($morecss ?
' '.$morecss :
'').
'" id="'.$htmlname.
'" name="'.$htmlname.
'">';
3373 $out .=
'<option value="-1" selected>'.($placeholder ? $placeholder :
' ').
'</option>';
3375 $out .=
'<option value="-1">'.($placeholder ? $placeholder :
' ').
'</option>';
3380 $objp = $this->
db->fetch_object($result);
3382 if (is_null($objp->idprodfournprice)) {
3384 $objp->tva_tx = $objp->tva_tx_sale;
3385 $objp->default_vat_code = $objp->default_vat_code_sale;
3388 $outkey = $objp->idprodfournprice;
3389 if (!$outkey && $alsoproductwithnosupplierprice) {
3390 $outkey =
'idprod_'.$objp->rowid;
3393 $outref = $objp->ref;
3394 $outbarcode = $objp->barcode;
3397 $outtype = $objp->fk_product_type;
3403 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
3404 if (!empty($objp->unit_short)) {
3405 $outvalUnits .=
' - '.$objp->unit_short;
3407 if (!empty($objp->weight) && $objp->weight_units !==
null) {
3409 $outvalUnits .=
' - '.$unitToShow;
3411 if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !==
null) {
3412 $unitToShow = $objp->length.
' x '.$objp->width.
' x '.$objp->height.
' '.
measuringUnitString(0,
'size', $objp->length_units);
3413 $outvalUnits .=
' - '.$unitToShow;
3415 if (!empty($objp->surface) && $objp->surface_units !==
null) {
3417 $outvalUnits .=
' - '.$unitToShow;
3419 if (!empty($objp->volume) && $objp->volume_units !==
null) {
3421 $outvalUnits .=
' - '.$unitToShow;
3423 if ($outdurationvalue && $outdurationunit) {
3425 'h' => $langs->trans(
'Hour'),
3426 'd' => $langs->trans(
'Day'),
3427 'w' => $langs->trans(
'Week'),
3428 'm' => $langs->trans(
'Month'),
3429 'y' => $langs->trans(
'Year')
3431 if (isset($da[$outdurationunit])) {
3432 $outvalUnits .=
' - '.$outdurationvalue.
' '.$langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ?
's' :
''));
3437 $objRef = $objp->ref;
3438 if ($filterkey && $filterkey !=
'') {
3439 $objRef = preg_replace(
'/('.preg_quote($filterkey,
'/').
')/i',
'<strong>$1</strong>', $objRef, 1);
3441 $objRefFourn = $objp->ref_fourn;
3442 if ($filterkey && $filterkey !=
'') {
3443 $objRefFourn = preg_replace(
'/('.preg_quote($filterkey,
'/').
')/i',
'<strong>$1</strong>', $objRefFourn, 1);
3445 $label = $objp->label;
3446 if ($filterkey && $filterkey !=
'') {
3447 $label = preg_replace(
'/('.preg_quote($filterkey,
'/').
')/i',
'<strong>$1</strong>', $label, 1);
3450 $optlabel = $objp->ref;
3451 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3452 $optlabel .=
' <span class="opacitymedium">('.$objp->ref_fourn.
')</span>';
3454 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
3455 $optlabel .=
' ('.$outbarcode.
')';
3457 $optlabel .=
' - '.dol_trunc($label, $maxlengtharticle);
3459 $outvallabel = $objRef;
3460 if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
3461 $outvallabel .=
' ('.$objRefFourn.
')';
3463 if (
isModEnabled(
'barcode') && !empty($objp->barcode)) {
3464 $outvallabel .=
' ('.$outbarcode.
')';
3466 $outvallabel .=
' - '.dol_trunc($label, $maxlengtharticle);
3469 $optlabel .= $outvalUnits;
3470 $outvallabel .= $outvalUnits;
3472 if (!empty($objp->idprodfournprice)) {
3473 $outqty = $objp->quantity;
3474 $outdiscount = $objp->remise_percent;
3475 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3477 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3478 $prod_supplier->id = $objp->fk_product;
3479 $prod_supplier->fourn_qty = $objp->quantity;
3480 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3481 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3483 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
3485 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3486 if ($price_result >= 0) {
3487 $objp->fprice = $price_result;
3488 if ($objp->quantity >= 1) {
3489 $objp->unitprice = $objp->fprice / $objp->quantity;
3493 if ($objp->quantity == 1) {
3494 $optlabel .=
' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency).
"/";
3495 $outvallabel .=
' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency).
"/";
3496 $optlabel .= $langs->trans(
"Unit");
3497 $outvallabel .= $langs->transnoentities(
"Unit");
3499 $optlabel .=
' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency).
"/".$objp->quantity;
3500 $outvallabel .=
' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency).
"/".$objp->quantity;
3501 $optlabel .=
' '.$langs->trans(
"Units");
3502 $outvallabel .=
' '.$langs->transnoentities(
"Units");
3505 if ($objp->quantity > 1) {
3506 $optlabel .=
" (".price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency).
"/".$langs->trans(
"Unit").
")";
3507 $outvallabel .=
" (".price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 0, $langs, 0, 0, -1, $conf->currency).
"/".$langs->transnoentities(
"Unit").
")";
3509 if ($objp->remise_percent >= 1) {
3510 $optlabel .=
" - ".$langs->trans(
"Discount").
" : ".
vatrate($objp->remise_percent).
' %';
3511 $outvallabel .=
" - ".$langs->transnoentities(
"Discount").
" : ".
vatrate($objp->remise_percent).
' %';
3513 if ($objp->duration) {
3514 $optlabel .=
" - ".$objp->duration;
3515 $outvallabel .=
" - ".$objp->duration;
3518 $optlabel .=
" - ".dol_trunc($objp->name, 8);
3519 $outvallabel .=
" - ".dol_trunc($objp->name, 8);
3521 if ($objp->supplier_reputation) {
3523 $reputations = array(
''=>$langs->trans(
'Standard'),
'FAVORITE'=>$langs->trans(
'Favorite'),
'NOTTHGOOD'=>$langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER'=>$langs->trans(
'DoNotOrderThisProductToThisSupplier'));
3525 $optlabel .=
" - ".$reputations[$objp->supplier_reputation];
3526 $outvallabel .=
" - ".$reputations[$objp->supplier_reputation];
3529 if (empty($alsoproductwithnosupplierprice)) {
3530 $optlabel .=
" - <span class='opacitymedium'>".$langs->trans(
"NoPriceDefinedForThisSupplier").
'</span>';
3531 $outvallabel .=
' - '.$langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3534 $optlabel .=
" - <span class='opacitymedium'>".$langs->trans(
"NoPriceDefinedForThisSupplier").
'</span>';
3535 $outvallabel .=
' - '.$langs->transnoentities(
"NoPriceDefinedForThisSupplier");
3539 if (
isModEnabled(
'stock') && $showstockinlist && isset($objp->stock) && ($objp->fk_product_type ==
Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) {
3540 $novirtualstock = ($showstockinlist == 2);
3542 if (!empty($user->rights->stock->lire)) {
3543 $outvallabel .=
' - '.$langs->trans(
"Stock").
': '.
price(
price2num($objp->stock,
'MS'));
3545 if ($objp->stock > 0) {
3546 $optlabel .=
' - <span class="product_line_stock_ok">';
3547 } elseif ($objp->stock <= 0) {
3548 $optlabel .=
' - <span class="product_line_stock_too_low">';
3550 $optlabel .= $langs->transnoentities(
"Stock").
':'.
price(
price2num($objp->stock,
'MS'));
3551 $optlabel .=
'</span>';
3552 if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) {
3553 $langs->load(
"stocks");
3556 $tmpproduct->fetch($objp->rowid,
'',
'',
'', 1, 1, 1);
3557 $tmpproduct->load_virtual_stock();
3558 $virtualstock = $tmpproduct->stock_theorique;
3560 $outvallabel .=
' - '.$langs->trans(
"VirtualStock").
':'.$virtualstock;
3562 $optlabel .=
' - '.$langs->transnoentities(
"VirtualStock").
':';
3563 if ($virtualstock > 0) {
3564 $optlabel .=
'<span class="product_line_stock_ok">';
3565 } elseif ($virtualstock <= 0) {
3566 $optlabel .=
'<span class="product_line_stock_too_low">';
3568 $optlabel .= $virtualstock;
3569 $optlabel .=
'</span>';
3576 $optstart =
'<option value="'.$outkey.
'"';
3577 if ($selected && $selected == $objp->idprodfournprice) {
3578 $optstart .=
' selected';
3580 if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3581 $optstart .=
' disabled';
3584 if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
3585 $optstart .=
' data-product-id="'.dol_escape_htmltag($objp->rowid).
'"';
3586 $optstart .=
' data-price-id="'.dol_escape_htmltag($objp->idprodfournprice).
'"';
3587 $optstart .=
' data-qty="'.dol_escape_htmltag($objp->quantity).
'"';
3588 $optstart .=
' data-up="'.dol_escape_htmltag(
price2num($objp->unitprice)).
'"';
3589 $optstart .=
' data-up-locale="'.dol_escape_htmltag(
price($objp->unitprice)).
'"';
3590 $optstart .=
' data-discount="'.dol_escape_htmltag($outdiscount).
'"';
3591 $optstart .=
' data-tvatx="'.dol_escape_htmltag(
price2num($objp->tva_tx)).
'"';
3592 $optstart .=
' data-tvatx-formated="'.dol_escape_htmltag(
price($objp->tva_tx, 0, $langs, 1, -1, 2)).
'"';
3593 $optstart .=
' data-default-vat-code="'.dol_escape_htmltag($objp->default_vat_code).
'"';
3595 $optstart .=
' data-description="'.dol_escape_htmltag($objp->description, 0, 1).
'"';
3597 $outarrayentry = array(
3600 'label' => $outvallabel,
3602 'price_qty_ht' =>
price2num($objp->fprice,
'MU'),
3603 'price_unit_ht' =>
price2num($objp->unitprice,
'MU'),
3604 'price_ht' =>
price2num($objp->unitprice,
'MU'),
3605 'tva_tx_formated' =>
price($objp->tva_tx, 0, $langs, 1, -1, 2),
3607 'default_vat_code' => $objp->default_vat_code,
3608 'discount' => $outdiscount,
3610 'duration_value' => $outdurationvalue,
3611 'duration_unit' => $outdurationunit,
3612 'disabled' => (empty($objp->idprodfournprice) ?
true :
false),
3613 'description' => $objp->description
3616 $parameters = array(
3618 'optstart' => &$optstart,
3619 'optlabel' => &$optlabel,
3620 'outvallabel' => &$outvallabel,
3621 'outarrayentry' => &$outarrayentry
3623 $reshook = $hookmanager->executeHooks(
'selectProduitsFournisseurListOption', $parameters, $this);
3629 $out .= $optstart .
' data-html="'.dol_escape_htmltag($optlabel).
'">' . $optlabel .
"</option>\n";;
3632 array(
'key'=>$outkey,
3634 'label'=>$outvallabel,
3636 'price_qty_ht'=>
price2num($objp->fprice,
'MU'),
3637 'price_qty_ht_locale'=>
price($objp->fprice),
3638 'price_unit_ht'=>
price2num($objp->unitprice,
'MU'),
3639 'price_unit_ht_locale'=>
price($objp->unitprice),
3640 'price_ht'=>
price2num($objp->unitprice,
'MU'),
3641 'tva_tx_formated' =>
price($objp->tva_tx),
3643 'default_vat_code'=>$objp->default_vat_code,
3644 'discount'=>$outdiscount,
3646 'duration_value'=>$outdurationvalue,
3647 'duration_unit'=>$outdurationunit,
3648 'disabled'=>(empty($objp->idprodfournprice) ?
true :
false),
3649 'description'=>$objp->description
3663 $out .=
'</select>';
3665 $this->
db->free($result);
3667 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
3673 if (empty($outputmode)) {
3691 global $langs, $conf;
3693 $langs->load(
'stocks');
3695 $sql =
"SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,";
3696 $sql .=
" pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,";
3697 $sql .=
" pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
3698 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3699 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
3700 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON pfp.fk_soc = s.rowid";
3701 $sql .=
" WHERE pfp.entity IN (".getEntity(
'productsupplierprice').
")";
3702 $sql .=
" AND p.tobuy = 1";
3703 $sql .=
" AND s.fournisseur = 1";
3704 $sql .=
" AND p.rowid = ".((int) $productid);
3705 if (empty($conf->global->PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED)) {
3706 $sql .=
" ORDER BY s.nom, pfp.ref_fourn DESC";
3708 $sql .=
" ORDER BY pfp.unitprice ASC";
3711 dol_syslog(get_class($this).
"::select_product_fourn_price", LOG_DEBUG);
3712 $result = $this->
db->query($sql);
3715 $num = $this->
db->num_rows($result);
3717 $form =
'<select class="flat" id="select_'.$htmlname.
'" name="'.$htmlname.
'">';
3720 $form .=
'<option value="0">-- '.$langs->trans(
"NoSupplierPriceDefinedForThisProduct").
' --</option>';
3722 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
3723 $form .=
'<option value="0"> </option>';
3727 $objp = $this->
db->fetch_object($result);
3729 $opt =
'<option value="'.$objp->idprodfournprice.
'"';
3731 if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier) || ($i == 0 && !empty($conf->global->PRODUCT_BEST_SUPPLIER_PRICE_PRESELECTED))) {
3732 $opt .=
' selected';
3734 $opt .=
'>'.$objp->name.
' - '.$objp->ref_fourn.
' - ';
3736 if (
isModEnabled(
'dynamicprices') && !empty($objp->fk_supplier_price_expression)) {
3738 $prod_supplier->product_fourn_price_id = $objp->idprodfournprice;
3739 $prod_supplier->id = $productid;
3740 $prod_supplier->fourn_qty = $objp->quantity;
3741 $prod_supplier->fourn_tva_tx = $objp->tva_tx;
3742 $prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
3744 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
3746 $price_result = $priceparser->parseProductSupplier($prod_supplier);
3747 if ($price_result >= 0) {
3748 $objp->fprice = $price_result;
3749 if ($objp->quantity >= 1) {
3750 $objp->unitprice = $objp->fprice / $objp->quantity;
3754 if ($objp->quantity == 1) {
3755 $opt .=
price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency).
"/";
3758 $opt .= $objp->quantity.
' ';
3760 if ($objp->quantity == 1) {
3761 $opt .= $langs->trans(
"Unit");
3763 $opt .= $langs->trans(
"Units");
3765 if ($objp->quantity > 1) {
3767 $opt .=
price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency).
"/".$langs->trans(
"Unit");
3769 if ($objp->duration) {
3770 $opt .=
" - ".$objp->duration;
3772 $opt .=
"</option>\n";
3779 $form .=
'</select>';
3780 $this->
db->free($result);
3797 public function select_address($selected, $socid, $htmlname =
'address_id', $showempty = 0)
3801 $sql =
"SELECT a.rowid, a.label";
3802 $sql .=
" FROM ".$this->db->prefix().
"societe_address as a";
3803 $sql .=
" WHERE a.fk_soc = ".((int) $socid);
3804 $sql .=
" ORDER BY a.label ASC";
3806 dol_syslog(get_class($this).
"::select_address", LOG_DEBUG);
3809 print
'<select class="flat" id="select_'.$htmlname.
'" name="'.$htmlname.
'">';
3811 print
'<option value="0"> </option>';
3813 $num = $this->
db->num_rows(
$resql);
3817 $obj = $this->
db->fetch_object(
$resql);
3819 if ($selected && $selected == $obj->rowid) {
3820 print
'<option value="'.$obj->rowid.
'" selected>'.$obj->label.
'</option>';
3822 print
'<option value="'.$obj->rowid.
'">'.$obj->label.
'</option>';
3845 $num = count($this->cache_conditions_paiements);
3852 $sql =
"SELECT rowid, code, libelle as label, deposit_percent";
3853 $sql .=
" FROM ".$this->db->prefix().
'c_payment_term';
3854 $sql .=
" WHERE entity IN (".getEntity(
'c_payment_term').
")";
3855 $sql .=
" AND active > 0";
3856 $sql .=
" ORDER BY sortorder";
3860 $num = $this->
db->num_rows(
$resql);
3863 $obj = $this->
db->fetch_object(
$resql);
3866 $label = ($langs->trans(
"PaymentConditionShort".$obj->code) != (
"PaymentConditionShort".$obj->code) ? $langs->trans(
"PaymentConditionShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
3867 $this->cache_conditions_paiements[$obj->rowid][
'code'] = $obj->code;
3868 $this->cache_conditions_paiements[$obj->rowid][
'label'] = $label;
3869 $this->cache_conditions_paiements[$obj->rowid][
'deposit_percent'] = $obj->deposit_percent;
3893 $num = count($this->cache_availability);
3900 $langs->load(
'propal');
3902 $sql =
"SELECT rowid, code, label, position";
3903 $sql .=
" FROM ".$this->db->prefix().
'c_availability';
3904 $sql .=
" WHERE active > 0";
3908 $num = $this->
db->num_rows(
$resql);
3911 $obj = $this->
db->fetch_object(
$resql);
3914 $label = ($langs->trans(
"AvailabilityType".$obj->code) != (
"AvailabilityType".$obj->code) ? $langs->trans(
"AvailabilityType".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
3915 $this->cache_availability[$obj->rowid][
'code'] = $obj->code;
3916 $this->cache_availability[$obj->rowid][
'label'] = $label;
3917 $this->cache_availability[$obj->rowid][
'position'] = $obj->position;
3921 $this->cache_availability =
dol_sort_array($this->cache_availability,
'position',
'asc', 0, 0, 1);
3942 global $langs, $user;
3946 dol_syslog(__METHOD__.
" selected=".$selected.
", htmlname=".$htmlname, LOG_DEBUG);
3948 print
'<select id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
3950 print
'<option value="0"> </option>';
3952 foreach ($this->cache_availability as $id => $arrayavailability) {
3953 if ($selected == $id) {
3954 print
'<option value="'.$id.
'" selected>';
3956 print
'<option value="'.$id.
'">';
3963 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3977 $num = count($this->cache_demand_reason);
3982 $sql =
"SELECT rowid, code, label";
3983 $sql .=
" FROM ".$this->db->prefix().
'c_input_reason';
3984 $sql .=
" WHERE active > 0";
3988 $num = $this->
db->num_rows(
$resql);
3990 $tmparray = array();
3992 $obj = $this->
db->fetch_object(
$resql);
3995 $label = ($obj->label !=
'-' ? $obj->label :
'');
3996 if ($langs->trans(
"DemandReasonType".$obj->code) != (
"DemandReasonType".$obj->code)) {
3997 $label = $langs->trans(
"DemandReasonType".$obj->code);
3999 if ($langs->trans($obj->code) != $obj->code) {
4000 $label = $langs->trans($obj->code);
4003 $tmparray[$obj->rowid][
'id'] = $obj->rowid;
4004 $tmparray[$obj->rowid][
'code'] = $obj->code;
4005 $tmparray[$obj->rowid][
'label'] = $label;
4009 $this->cache_demand_reason =
dol_sort_array($tmparray,
'label',
'asc', 0, 0, 1);
4031 public function selectInputReason($selected =
'', $htmlname =
'demandreasonid', $exclude =
'', $addempty = 0, $morecss =
'', $notooltip = 0)
4033 global $langs, $user;
4037 print
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" id="select_'.$htmlname.
'" name="'.$htmlname.
'">';
4039 print
'<option value="0"'.(empty($selected) ?
' selected' :
'').
'> </option>';
4041 foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
4042 if ($arraydemandreason[
'code'] == $exclude) {
4046 if ($selected && ($selected == $arraydemandreason[
'id'] || $selected == $arraydemandreason[
'code'])) {
4047 print
'<option value="'.$arraydemandreason[
'id'].
'" selected>';
4049 print
'<option value="'.$arraydemandreason[
'id'].
'">';
4051 $label = $arraydemandreason[
'label'];
4052 print $langs->trans($label);
4056 if ($user->admin && empty($notooltip)) {
4057 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4073 $num = count($this->cache_types_paiements);
4080 $this->cache_types_paiements = array();
4082 $sql =
"SELECT id, code, libelle as label, type, active";
4083 $sql .=
" FROM ".$this->db->prefix().
"c_paiement";
4084 $sql .=
" WHERE entity IN (".getEntity(
'c_paiement').
")";
4088 $num = $this->
db->num_rows(
$resql);
4091 $obj = $this->
db->fetch_object(
$resql);
4094 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort".$obj->code) != (
"PaymentTypeShort".$obj->code) ? $langs->transnoentitiesnoconv(
"PaymentTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4095 $this->cache_types_paiements[$obj->id][
'id'] = $obj->id;
4096 $this->cache_types_paiements[$obj->id][
'code'] = $obj->code;
4097 $this->cache_types_paiements[$obj->id][
'label'] = $label;
4098 $this->cache_types_paiements[$obj->id][
'type'] = $obj->type;
4099 $this->cache_types_paiements[$obj->id][
'active'] = $obj->active;
4103 $this->cache_types_paiements =
dol_sort_array($this->cache_types_paiements,
'label',
'asc', 0, 0, 1);
4131 public function select_conditions_paiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4154 public function getSelectConditionsPaiements($selected = 0, $htmlname =
'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss =
'', $deposit_percent = -1)
4156 global $langs, $user, $conf;
4159 dol_syslog(__METHOD__.
" selected=".$selected.
", htmlname=".$htmlname, LOG_DEBUG);
4164 if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) {
4165 $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID;
4168 $out.=
'<select id="'.$htmlname.
'" class="flat selectpaymentterms'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
4170 $out.=
'<option value="0"> </option>';
4173 $selectedDepositPercent =
null;
4175 foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
4176 if ($filtertype <= 0 && !empty($arrayconditions[
'deposit_percent'])) {
4180 if ($selected == $id) {
4181 $selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'];
4182 $out .=
'<option value="'.$id.
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'" selected>';
4184 $out .=
'<option value="'.$id.
'" data-deposit_percent="' . $arrayconditions[
'deposit_percent'] .
'">';
4186 $label = $arrayconditions[
'label'];
4188 if (!empty($arrayconditions[
'deposit_percent'])) {
4189 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions[
'deposit_percent'], $label);
4196 if ($user->admin && empty($noinfoadmin)) {
4197 $out.=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4201 if ($deposit_percent >= 0) {
4202 $out .=
' <span id="'.$htmlname.
'_deposit_percent_container"' . (empty($selectedDepositPercent) ?
' style="display: none"' :
'') .
'>';
4203 $out .= $langs->trans(
'DepositPercent') .
' : ';
4204 $out .=
'<input id="'.$htmlname.
'_deposit_percent" name="'.$htmlname.
'_deposit_percent" class="maxwidth50" value="' . strval($deposit_percent) .
'" />';
4208 $(document).ready(function () {
4209 $("#' . $htmlname .
'").change(function () {
4210 let $selected = $(this).find("option:selected");
4211 let depositPercent = $selected.attr("data-deposit_percent");
4213 if (depositPercent.length > 0) {
4214 $("#'.$htmlname.
'_deposit_percent_container").show().find("#'.$htmlname.
'_deposit_percent").val(depositPercent);
4216 $("#'.$htmlname.
'_deposit_percent_container").hide();
4246 public function select_types_paiements($selected =
'', $htmlname =
'paiementtype', $filtertype =
'', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'', $nooutput = 0)
4249 global $langs, $user, $conf;
4253 dol_syslog(__METHOD__.
" ".$selected.
", ".$htmlname.
", ".$filtertype.
", ".$format, LOG_DEBUG);
4255 $filterarray = array();
4256 if ($filtertype ==
'CRDT') {
4257 $filterarray = array(0, 2, 3);
4258 } elseif ($filtertype ==
'DBIT') {
4259 $filterarray = array(1, 2, 3);
4260 } elseif ($filtertype !=
'' && $filtertype !=
'-1') {
4261 $filterarray = explode(
',', $filtertype);
4267 if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID)) {
4268 $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
4271 $out .=
'<select id="select'.$htmlname.
'" class="flat selectpaymenttypes'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
4273 $out .=
'<option value=""> </option>';
4275 foreach ($this->cache_types_paiements as $id => $arraytypes) {
4277 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4282 if (count($filterarray) && !in_array($arraytypes[
'type'], $filterarray)) {
4287 if ($empty && empty($arraytypes[
'code'])) {
4292 $out .=
'<option value="'.$id.
'"';
4293 } elseif ($format == 1) {
4294 $out .=
'<option value="'.$arraytypes[
'code'].
'"';
4295 } elseif ($format == 2) {
4296 $out .=
'<option value="'.$arraytypes[
'code'].
'"';
4297 } elseif ($format == 3) {
4298 $out .=
'<option value="'.$id.
'"';
4301 if ($format == 1 || $format == 2) {
4302 if ($selected == $arraytypes[
'code']) {
4303 $out .=
' selected';
4306 if ($selected == $id) {
4307 $out .=
' selected';
4313 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4314 } elseif ($format == 1) {
4315 $value = $arraytypes[
'code'];
4316 } elseif ($format == 2) {
4317 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4318 } elseif ($format == 3) {
4319 $value = $arraytypes[
'code'];
4321 $out .= $value ? $value :
' ';
4322 $out .=
'</option>';
4324 $out .=
'</select>';
4325 if ($user->admin && !$noadmininfo) {
4326 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4330 if (empty($nooutput)) {
4350 $return =
'<select class="flat maxwidth100" id="select_'.$htmlname.
'" name="'.$htmlname.
'">';
4352 'HT'=>$langs->trans(
"HT"),
4353 'TTC'=>$langs->trans(
"TTC")
4355 foreach ($options as $id => $value) {
4356 if ($selected == $id) {
4357 $return .=
'<option value="'.$id.
'" selected>'.$value;
4359 $return .=
'<option value="'.$id.
'">'.$value;
4361 $return .=
'</option>';
4363 $return .=
'</select>';
4382 $num = count($this->cache_transport_mode);
4389 $this->cache_transport_mode = array();
4391 $sql =
"SELECT rowid, code, label, active";
4392 $sql .=
" FROM ".$this->db->prefix().
"c_transport_mode";
4393 $sql .=
" WHERE entity IN (".getEntity(
'c_transport_mode').
")";
4397 $num = $this->
db->num_rows(
$resql);
4400 $obj = $this->
db->fetch_object(
$resql);
4403 $label = ($langs->transnoentitiesnoconv(
"PaymentTypeShort".$obj->code) != (
"PaymentTypeShort".$obj->code) ? $langs->transnoentitiesnoconv(
"PaymentTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
4404 $this->cache_transport_mode[$obj->rowid][
'rowid'] = $obj->rowid;
4405 $this->cache_transport_mode[$obj->rowid][
'code'] = $obj->code;
4406 $this->cache_transport_mode[$obj->rowid][
'label'] = $label;
4407 $this->cache_transport_mode[$obj->rowid][
'active'] = $obj->active;
4411 $this->cache_transport_mode =
dol_sort_array($this->cache_transport_mode,
'label',
'asc', 0, 0, 1);
4433 public function selectTransportMode($selected =
'', $htmlname =
'transportmode', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss =
'')
4435 global $langs, $user;
4437 dol_syslog(__METHOD__.
" ".$selected.
", ".$htmlname.
", ".$format, LOG_DEBUG);
4441 print
'<select id="select'.$htmlname.
'" class="flat selectmodetransport'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'">';
4443 print
'<option value=""> </option>';
4445 foreach ($this->cache_transport_mode as $id => $arraytypes) {
4447 if ($active >= 0 && $arraytypes[
'active'] != $active) {
4452 if ($empty && empty($arraytypes[
'code'])) {
4457 print
'<option value="'.$id.
'"';
4458 } elseif ($format == 1) {
4459 print
'<option value="'.$arraytypes[
'code'].
'"';
4460 } elseif ($format == 2) {
4461 print
'<option value="'.$arraytypes[
'code'].
'"';
4462 } elseif ($format == 3) {
4463 print
'<option value="'.$id.
'"';
4466 if (preg_match(
'/[a-z]/i', $selected) && $selected == $arraytypes[
'code']) {
4468 } elseif ($selected == $id) {
4474 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4475 } elseif ($format == 1) {
4476 $value = $arraytypes[
'code'];
4477 } elseif ($format == 2) {
4478 $value = ($maxlength ?
dol_trunc($arraytypes[
'label'], $maxlength) : $arraytypes[
'label']);
4479 } elseif ($format == 3) {
4480 $value = $arraytypes[
'code'];
4482 print $value ? $value :
' ';
4486 if ($user->admin && !$noadmininfo) {
4487 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4503 public function selectShippingMethod($selected =
'', $htmlname =
'shipping_method_id', $filtre =
'', $useempty = 0, $moreattrib =
'', $noinfoadmin = 0, $morecss =
'')
4505 global $langs, $conf, $user;
4507 $langs->load(
"admin");
4508 $langs->load(
"deliveries");
4510 $sql =
"SELECT rowid, code, libelle as label";
4511 $sql .=
" FROM ".$this->db->prefix().
"c_shipment_mode";
4512 $sql .=
" WHERE active > 0";
4514 $sql .=
" AND ".$filtre;
4516 $sql .=
" ORDER BY libelle ASC";
4518 dol_syslog(get_class($this).
"::selectShippingMode", LOG_DEBUG);
4519 $result = $this->
db->query($sql);
4521 $num = $this->
db->num_rows($result);
4524 print
'<select id="select'.$htmlname.
'" class="flat selectshippingmethod'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'"'.($moreattrib ?
' '.$moreattrib :
'').
'>';
4525 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4526 print
'<option value="-1"> </option>';
4529 $obj = $this->
db->fetch_object($result);
4530 if ($selected == $obj->rowid) {
4531 print
'<option value="'.$obj->rowid.
'" selected>';
4533 print
'<option value="'.$obj->rowid.
'">';
4535 print ($langs->trans(
"SendingMethod".strtoupper($obj->code)) !=
"SendingMethod".strtoupper($obj->code)) ? $langs->trans(
"SendingMethod".strtoupper($obj->code)) : $obj->label;
4540 if ($user->admin && empty($noinfoadmin)) {
4541 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4546 print $langs->trans(
"NoShippingMethodDefined");
4566 $langs->load(
"deliveries");
4568 if ($htmlname !=
"none") {
4569 print
'<form method="POST" action="'.$page.
'">';
4570 print
'<input type="hidden" name="action" value="setshippingmethod">';
4571 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4573 print
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4577 $code = $langs->getLabelFromKey($this->
db, $selected,
'c_shipment_mode',
'rowid',
'code');
4578 print $langs->trans(
"SendingMethod".strtoupper($code));
4597 $langs->load(
'bills');
4599 $opt =
'<option value="" selected></option>';
4600 $sql =
"SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc";
4601 $sql .=
' FROM '.$this->db->prefix().
'facture';
4602 $sql .=
' WHERE entity IN ('.getEntity(
'invoice').
')';
4603 $sql .=
' AND situation_counter >= 1';
4604 $sql .=
' AND fk_soc = '.(int) $socid;
4605 $sql .=
' AND type <> 2';
4606 $sql .=
' ORDER by situation_cycle_ref, situation_counter desc';
4612 while ($obj = $this->
db->fetch_object(
$resql)) {
4614 if ($obj->situation_cycle_ref != $ref) {
4616 $ref = $obj->situation_cycle_ref;
4618 if ($obj->situation_final != 1) {
4620 if (substr($obj->ref, 1, 4) !=
'PROV') {
4621 if ($selected == $obj->rowid) {
4622 $opt .=
'<option value="'.$obj->rowid.
'" selected>'.$obj->ref.
'</option>';
4624 $opt .=
'<option value="'.$obj->rowid.
'">'.$obj->ref.
'</option>';
4631 dol_syslog(
"Error sql=".$sql.
", error=".$this->error, LOG_ERR);
4633 if ($opt ==
'<option value ="" selected></option>') {
4634 $opt =
'<option value ="0" selected>'.$langs->trans(
'NoSituations').
'</option>';
4648 public function selectUnits($selected =
'', $htmlname =
'units', $showempty = 0, $unit_type =
'')
4652 $langs->load(
'products');
4654 $return =
'<select class="flat" id="'.$htmlname.
'" name="'.$htmlname.
'">';
4656 $sql =
"SELECT rowid, label, code FROM ".$this->db->prefix().
"c_units";
4657 $sql .=
' WHERE active > 0';
4658 if (!empty($unit_type)) {
4659 $sql .=
" AND unit_type = '".$this->db->escape($unit_type).
"'";
4661 $sql .=
" ORDER BY sortorder";
4666 $return .=
'<option value="none"></option>';
4669 while ($res = $this->
db->fetch_object(
$resql)) {
4670 $unitLabel = $res->label;
4671 if (!empty($langs->tab_translate[
'unit'.$res->code])) {
4672 $unitLabel = $langs->trans(
'unit'.$res->code) != $res->label ? $langs->trans(
'unit'.$res->code) : $res->label;
4675 if ($selected == $res->rowid) {
4676 $return .=
'<option value="'.$res->rowid.
'" selected>'.$unitLabel.
'</option>';
4678 $return .=
'<option value="'.$res->rowid.
'">'.$unitLabel.
'</option>';
4681 $return .=
'</select>';
4701 public function select_comptes($selected =
'', $htmlname =
'accountid', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'', $showcurrency = 0, $morecss =
'', $nooutput = 0)
4704 global $langs, $conf;
4708 $langs->load(
"admin");
4711 $sql =
"SELECT rowid, label, bank, clos as status, currency_code";
4712 $sql .=
" FROM ".$this->db->prefix().
"bank_account";
4713 $sql .=
" WHERE entity IN (".getEntity(
'bank_account').
")";
4715 $sql .=
" AND clos = ".(int) $status;
4718 $sql .=
" AND ".$filtre;
4720 $sql .=
" ORDER BY label";
4722 dol_syslog(get_class($this).
"::select_comptes", LOG_DEBUG);
4723 $result = $this->
db->query($sql);
4725 $num = $this->
db->num_rows($result);
4728 $out .=
'<select id="select'.$htmlname.
'" class="flat selectbankaccount'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'"'.($moreattrib ?
' '.$moreattrib :
'').
'>';
4729 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4730 $out .=
'<option value="-1"> </option>';
4734 $obj = $this->
db->fetch_object($result);
4735 if ($selected == $obj->rowid || ($useempty == 2 && $num == 1 && empty($selected))) {
4736 $out .=
'<option value="'.$obj->rowid.
'" data-currency-code="'.$obj->currency_code.
'" selected>';
4738 $out .=
'<option value="'.$obj->rowid.
'" data-currency-code="'.$obj->currency_code.
'">';
4740 $out .= trim($obj->label);
4741 if ($showcurrency) {
4742 $out .=
' ('.$obj->currency_code.
')';
4744 if ($status == 2 && $obj->status == 1) {
4745 $out .=
' ('.$langs->trans(
"Closed").
')';
4747 $out .=
'</option>';
4750 $out .=
"</select>";
4754 $out .=
'<span class="opacitymedium">'.$langs->trans(
"NoActiveBankAccountDefined").
'</span>';
4756 $out .=
'<span class="opacitymedium">'.$langs->trans(
"NoBankAccountFound").
'</span>';
4764 if (empty($nooutput)) {
4784 public function selectEstablishments($selected =
'', $htmlname =
'entity', $status = 0, $filtre =
'', $useempty = 0, $moreattrib =
'')
4786 global $langs, $conf;
4788 $langs->load(
"admin");
4791 $sql =
"SELECT rowid, name, fk_country, status, entity";
4792 $sql .=
" FROM ".$this->db->prefix().
"establishment";
4793 $sql .=
" WHERE 1=1";
4795 $sql .=
" AND status = ".(int) $status;
4798 $sql .=
" AND ".$filtre;
4800 $sql .=
" ORDER BY name";
4802 dol_syslog(get_class($this).
"::select_establishment", LOG_DEBUG);
4803 $result = $this->
db->query($sql);
4805 $num = $this->
db->num_rows($result);
4808 print
'<select id="select'.$htmlname.
'" class="flat selectestablishment" name="'.$htmlname.
'"'.($moreattrib ?
' '.$moreattrib :
'').
'>';
4809 if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
4810 print
'<option value="-1"> </option>';
4814 $obj = $this->
db->fetch_object($result);
4815 if ($selected == $obj->rowid) {
4816 print
'<option value="'.$obj->rowid.
'" selected>';
4818 print
'<option value="'.$obj->rowid.
'">';
4820 print trim($obj->name);
4821 if ($status == 2 && $obj->status == 1) {
4822 print
' ('.$langs->trans(
"Closed").
')';
4830 print
'<span class="opacitymedium">'.$langs->trans(
"NoActiveEstablishmentDefined").
'</span>';
4832 print
'<span class="opacitymedium">'.$langs->trans(
"NoEstablishmentFound").
'</span>';
4852 if ($htmlname !=
"none") {
4853 print
'<form method="POST" action="'.$page.
'">';
4854 print
'<input type="hidden" name="action" value="setbankaccount">';
4855 print
'<input type="hidden" name="token" value="'.newToken().
'">';
4856 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
4857 $nbaccountfound = $this->
select_comptes($selected, $htmlname, 0,
'', $addempty);
4858 if ($nbaccountfound > 0) {
4859 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
4863 $langs->load(
'banks');
4866 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
4868 $result = $bankstatic->fetch($selected);
4870 print $bankstatic->getNomUrl(1);
4897 public function select_all_categories($type, $selected =
'', $htmlname =
"parent", $maxlength = 64, $markafterid = 0, $outputmode = 0, $include = 0, $morecss =
'')
4900 global $conf, $langs;
4901 $langs->load(
"categories");
4903 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4906 if (is_numeric($type)) {
4907 dol_syslog(__METHOD__.
': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
4910 if ($type === Categorie::TYPE_BANK_LINE) {
4912 $cate_arbo = array();
4913 $sql =
"SELECT c.label, c.rowid";
4914 $sql .=
" FROM ".$this->db->prefix().
"bank_categ as c";
4915 $sql .=
" WHERE entity = ".$conf->entity;
4916 $sql .=
" ORDER BY c.label";
4917 $result = $this->
db->query($sql);
4919 $num = $this->
db->num_rows($result);
4922 $objp = $this->
db->fetch_object($result);
4924 $cate_arbo[$objp->rowid] = array(
'id'=>$objp->rowid,
'fulllabel'=>$objp->label,
'color'=>
'',
'picto'=>
'category');
4928 $this->
db->free($result);
4934 $cate_arbo = $cat->get_full_arbo($type, $markafterid, $include);
4937 $outarray = array();
4939 $output =
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
4940 if (is_array($cate_arbo)) {
4941 if (!count($cate_arbo)) {
4942 $output .=
'<option value="-1" disabled>'.$langs->trans(
"NoCategoriesDefined").
'</option>';
4944 $output .=
'<option value="-1"> </option>';
4945 foreach ($cate_arbo as $key => $value) {
4946 if ($cate_arbo[$key][
'id'] == $selected || ($selected ===
'auto' && count($cate_arbo) == 1)) {
4951 $output .=
'<option '.$add.
'value="'.$cate_arbo[$key][
'id'].
'"';
4952 $output .=
' data-html="'.dol_escape_htmltag(
img_picto(
'',
'category',
'class="pictofixedwidth" style="color: #'.$cate_arbo[$key][
'color'].
'"').dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle')).
'"';
4954 $output .=
dol_trunc($cate_arbo[$key][
'fulllabel'], $maxlength,
'middle');
4955 $output .=
'</option>';
4957 $outarray[$cate_arbo[$key][
'id']] = $cate_arbo[$key][
'fulllabel'];
4961 $output .=
'</select>';
4964 if ($outputmode == 2) {
4966 } elseif ($outputmode) {
4989 public function form_confirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
"", $useajax = 0, $height = 170, $width = 500)
4992 dol_syslog(__METHOD__.
': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING);
4993 print $this->
formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
5023 public function formconfirm($page, $title, $question, $action, $formquestion =
'', $selectedchoice =
'', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0, $labelbuttonyes =
'Yes', $labelbuttonno =
'No')
5025 global $langs, $conf;
5027 $more =
'<!-- formconfirm - before call, page='.dol_escape_htmltag($page).
' -->';
5033 $newselectedchoice = empty($selectedchoice) ?
"no" : $selectedchoice;
5034 if ($conf->browser->layout ==
'phone') {
5039 if (empty($height)) {
5041 if (is_array($formquestion) && count($formquestion) > 2) {
5042 $height += ((count($formquestion) - 2) * 24);
5046 if (is_array($formquestion) && !empty($formquestion)) {
5048 foreach ($formquestion as $key => $input) {
5049 if (is_array($input) && !empty($input)) {
5050 if ($input[
'type'] ==
'hidden') {
5051 $moreattr = (!empty($input[
'moreattr']) ?
' '.$input[
'moreattr'] :
'');
5052 $morecss = (!empty($input[
'morecss']) ?
' '.$input[
'morecss'] :
'');
5054 $more .=
'<input type="hidden" id="'.dol_escape_htmltag($input[
'name']).
'" name="'.
dol_escape_htmltag($input[
'name']).
'" value="'.
dol_escape_htmltag($input[
'value']).
'" class="'.$morecss.
'"'.$moreattr.
'>'.
"\n";
5060 $moreonecolumn =
'';
5061 $more .=
'<div class="tagtable paddingtopbottomonly centpercent noborderspacing">'.
"\n";
5062 foreach ($formquestion as $key => $input) {
5063 if (is_array($input) && !empty($input)) {
5064 $size = (!empty($input[
'size']) ?
' size="'.$input[
'size'].
'"' :
'');
5065 $moreattr = (!empty($input[
'moreattr']) ?
' '.$input[
'moreattr'] :
'');
5066 $morecss = (!empty($input[
'morecss']) ?
' '.$input[
'morecss'] :
'');
5068 if ($input[
'type'] ==
'text') {
5069 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">'.$input[
'label'].
'</div><div class="tagtd"><input type="text" class="flat'.$morecss.
'" id="'.
dol_escape_htmltag($input[
'name']).
'" name="'.
dol_escape_htmltag($input[
'name']).
'"'.$size.
' value="'.(empty($input[
'value']) ?
'' : $input[
'value']).
'"'.$moreattr.
' /></div></div>'.
"\n";
5070 } elseif ($input[
'type'] ==
'password') {
5071 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">'.$input[
'label'].
'</div><div class="tagtd"><input type="password" class="flat'.$morecss.
'" id="'.
dol_escape_htmltag($input[
'name']).
'" name="'.
dol_escape_htmltag($input[
'name']).
'"'.$size.
' value="'.(empty($input[
'value']) ?
'' : $input[
'value']).
'"'.$moreattr.
' /></div></div>'.
"\n";
5072 } elseif ($input[
'type'] ==
'textarea') {
5078 $moreonecolumn .=
'<div class="margintoponly">';
5079 $moreonecolumn .= $input[
'label'].
'<br>';
5080 $moreonecolumn .=
'<textarea name="'.dol_escape_htmltag($input[
'name']).
'" id="'.
dol_escape_htmltag($input[
'name']).
'" class="'.$morecss.
'"'.$moreattr.
'>';
5081 $moreonecolumn .= $input[
'value'];
5082 $moreonecolumn .=
'</textarea>';
5083 $moreonecolumn .=
'</div>';
5084 } elseif (in_array($input[
'type'], [
'select',
'multiselect'])) {
5085 if (empty($morecss)) {
5086 $morecss =
'minwidth100';
5089 $show_empty = isset($input[
'select_show_empty']) ? $input[
'select_show_empty'] : 1;
5090 $key_in_label = isset($input[
'select_key_in_label']) ? $input[
'select_key_in_label'] : 0;
5091 $value_as_key = isset($input[
'select_value_as_key']) ? $input[
'select_value_as_key'] : 0;
5092 $translate = isset($input[
'select_translate']) ? $input[
'select_translate'] : 0;
5093 $maxlen = isset($input[
'select_maxlen']) ? $input[
'select_maxlen'] : 0;
5094 $disabled = isset($input[
'select_disabled']) ? $input[
'select_disabled'] : 0;
5095 $sort = isset($input[
'select_sort']) ? $input[
'select_sort'] :
'';
5097 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5098 if (!empty($input[
'label'])) {
5099 $more .= $input[
'label'].
'</div><div class="tagtd left">';
5101 if ($input[
'type'] ==
'select') {
5102 $more .= $this->
selectarray($input[
'name'], $input[
'values'], !empty($input[
'default']) ? $input[
'default'] :
'-1', $show_empty, $key_in_label, $value_as_key, $moreattr, $translate, $maxlen, $disabled, $sort, $morecss);
5104 $more .= $this->
multiselectarray($input[
'name'], $input[
'values'], is_array($input[
'default']) ? $input[
'default'] : [$input[
'default']], $key_in_label, $value_as_key, $morecss, $translate, $maxlen, $moreattr);
5106 $more .=
'</div></div>'.
"\n";
5107 } elseif ($input[
'type'] ==
'checkbox') {
5108 $more .=
'<div class="tagtr">';
5109 $more .=
'<div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">'.$input[
'label'].
' </div><div class="tagtd">';
5110 $more .=
'<input type="checkbox" class="flat'.($morecss ?
' '.$morecss :
'').
'" id="'.
dol_escape_htmltag($input[
'name']).
'" name="'.
dol_escape_htmltag($input[
'name']).
'"'.$moreattr;
5111 if (!is_bool($input[
'value']) && $input[
'value'] !=
'false' && $input[
'value'] !=
'0' && $input[
'value'] !=
'') {
5112 $more .=
' checked';
5114 if (is_bool($input[
'value']) && $input[
'value']) {
5115 $more .=
' checked';
5117 if (isset($input[
'disabled'])) {
5118 $more .=
' disabled';
5120 $more .=
' /></div>';
5121 $more .=
'</div>'.
"\n";
5122 } elseif ($input[
'type'] ==
'radio') {
5124 foreach ($input[
'values'] as $selkey => $selval) {
5125 $more .=
'<div class="tagtr">';
5126 if (isset($input[
'label'])) {
5128 $more .=
'<div class="tagtd'.(empty($input[
'tdclass']) ?
' tdtop' : (
' tdtop '.$input[
'tdclass'])).
'">'.$input[
'label'].
'</div>';
5130 $more .=
'<div clas="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' "'.$input[
'tdclass'])).
'"> </div>';
5133 $more .=
'<div class="tagtd'.($i == 0 ?
' tdtop' :
'').
'"><input type="radio" class="flat'.$morecss.
'" id="'.
dol_escape_htmltag($input[
'name'].$selkey).
'" name="'.
dol_escape_htmltag($input[
'name']).
'" value="'.$selkey.
'"'.$moreattr;
5134 if (!empty($input[
'disabled'])) {
5135 $more .=
' disabled';
5137 if (isset($input[
'default']) && $input[
'default'] === $selkey) {
5138 $more .=
' checked="checked"';
5141 $more .=
'<label for="'.dol_escape_htmltag($input[
'name'].$selkey).
'" class="valignmiddle">'.$selval.
'</label>';
5142 $more .=
'</div></div>'.
"\n";
5145 } elseif ($input[
'type'] ==
'date' || $input[
'type'] ==
'datetime') {
5146 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">'.$input[
'label'].
'</div>';
5147 $more .=
'<div class="tagtd">';
5148 $addnowlink = (empty($input[
'datenow']) ? 0 : 1);
5149 $more .= $this->
selectDate($input[
'value'], $input[
'name'], ($input[
'type'] ==
'datetime' ? 1 : 0), ($input[
'type'] ==
'datetime' ? 1 : 0), 0,
'', 1, $addnowlink);
5150 $more .=
'</div></div>'.
"\n";
5151 $formquestion[] = array(
'name'=>$input[
'name'].
'day');
5152 $formquestion[] = array(
'name'=>$input[
'name'].
'month');
5153 $formquestion[] = array(
'name'=>$input[
'name'].
'year');
5154 $formquestion[] = array(
'name'=>$input[
'name'].
'hour');
5155 $formquestion[] = array(
'name'=>$input[
'name'].
'min');
5156 } elseif ($input[
'type'] ==
'other') {
5157 $more .=
'<div class="tagtr"><div class="tagtd'.(empty($input[
'tdclass']) ?
'' : (
' '.$input[
'tdclass'])).
'">';
5158 if (!empty($input[
'label'])) {
5159 $more .= $input[
'label'].
'</div><div class="tagtd">';
5161 $more .= $input[
'value'];
5162 $more .=
'</div></div>'.
"\n";
5163 } elseif ($input[
'type'] ==
'onecolumn') {
5164 $moreonecolumn .=
'<div class="margintoponly">';
5165 $moreonecolumn .= $input[
'value'];
5166 $moreonecolumn .=
'</div>'.
"\n";
5167 } elseif ($input[
'type'] ==
'hidden') {
5169 } elseif ($input[
'type'] ==
'separator') {
5172 $more .=
'Error type '.$input[
'type'].
' for the confirm box is not a supported type';
5176 $more .=
'</div>'.
"\n";
5177 $more .= $moreonecolumn;
5183 if (!empty($conf->dol_use_jmobile)) {
5186 if (empty($conf->use_javascript_ajax)) {
5192 $dialogconfirm =
'dialog-confirm';
5194 if (!is_numeric($useajax)) {
5198 $dialogconfirm .=
'-'.$button;
5200 $pageyes = $page.(preg_match(
'/\?/', $page) ?
'&' :
'?').
'action='.urlencode($action).
'&confirm=yes';
5201 $pageno = ($useajax == 2 ? $page.(preg_match(
'/\?/', $page) ?
'&' :
'?').
'action='.urlencode($action).
'&confirm=no' :
'');
5204 if (is_array($formquestion)) {
5205 foreach ($formquestion as $key => $input) {
5208 if (is_array($input) && isset($input[
'name'])) {
5209 if (strpos($input[
'name'],
',') > 0) {
5210 $inputok = array_merge($inputok, explode(
',', $input[
'name']));
5212 array_push($inputok, $input[
'name']);
5216 if (isset($input[
'inputko']) && $input[
'inputko'] == 1) {
5217 array_push($inputko, $input[
'name']);
5224 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5225 $formconfirm .=
'<div class="confirmtext">'.$formquestion[
'text'].
'</div>'.
"\n";
5227 if (!empty($more)) {
5228 $formconfirm .=
'<div class="confirmquestions">'.$more.
'</div>'.
"\n";
5230 $formconfirm .= ($question ?
'<div class="confirmmessage">'.img_help(
'',
'').
' '.$question.
'</div>' :
'');
5233 $formconfirm .=
"\n<!-- begin code of popup for formconfirm page=".$page.
" -->\n";
5234 $formconfirm .=
'<script type="text/javascript">'.
"\n";
5235 $formconfirm .=
"/* Code for the jQuery('#dialogforpopup').dialog() */\n";
5238 $( "#'.$dialogconfirm.
'" ).dialog(
5240 autoOpen: '.($autoOpen ?
"true" :
"false").
',';
5241 if ($newselectedchoice ==
'no') {
5244 $(this).parent().find("button.ui-button:eq(2)").focus();
5249 if ($useajax == 1) {
5250 $jsforcursor =
'// The call to urljump can be slow, so we set the wait cursor'.
"\n";
5251 $jsforcursor .=
'jQuery("html,body,#id-container").addClass("cursorwait");'.
"\n";
5254 $postconfirmas =
'GET';
5258 height: "'.$height.
'",
5259 width: "'.$width.
'",
5261 closeOnEscape: false,
5263 "'.
dol_escape_js($langs->transnoentities($labelbuttonyes)).
'": function() {
5264 var options = "token='.urlencode(
newToken()).
'";
5265 var inputok = '.json_encode($inputok).
'; /* List of fields into form */
5267 var pageyes = "'.
dol_escape_js(!empty($pageyes) ? $pageyes :
'').
'";
5269 if (inputok.length > 0) {
5270 $.each(inputok, function(i, inputname) {
5273 if ($("input[name=\'" + inputname + "\']").attr("type") == "radio") {
5274 inputvalue = $("input[name=\'" + inputname + "\']:checked").val();
5276 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5277 inputvalue = $("#" + inputname + more).val();
5279 if (typeof inputvalue == "undefined") { inputvalue=""; }
5280 console.log("formconfirm check inputname="+inputname+" inputvalue="+inputvalue);
5281 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5284 var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
5285 if (pageyes.length > 0) {';
5286 if ($postconfirmas ==
'GET') {
5293 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5297 console.log("after post ok");
5299 $(this).dialog("close");
5301 "'.dol_escape_js($langs->transnoentities($labelbuttonno)).
'": function() {
5302 var options = "token='.urlencode(
newToken()).
'";
5303 var inputko = '.json_encode($inputko).
'; /* List of fields into form */
5305 var pageno="'.
dol_escape_js(!empty($pageno) ? $pageno :
'').
'";
5306 if (inputko.length > 0) {
5307 $.each(inputko, function(i, inputname) {
5309 if ($("#" + inputname).attr("type") == "checkbox") { more = ":checked"; }
5310 var inputvalue = $("#" + inputname + more).val();
5311 if (typeof inputvalue == "undefined") { inputvalue=""; }
5312 options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
5315 var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
5317 if (pageno.length > 0) {';
5318 if ($postconfirmas ==
'GET') {
5325 function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
5329 console.log("after post ko");
5331 $(this).dialog("close");
5337 var button = "'.$button.
'";
5338 if (button.length > 0) {
5339 $( "#" + button ).click(function() {
5340 $("#'.$dialogconfirm.
'").dialog("open");
5348 $formconfirm .=
"\n<!-- begin formconfirm page=".dol_escape_htmltag($page).
" -->\n";
5350 if (empty($disableformtag)) {
5351 $formconfirm .=
'<form method="POST" action="'.$page.
'" class="notoptoleftroright">'.
"\n";
5354 $formconfirm .=
'<input type="hidden" name="action" value="'.$action.
'">'.
"\n";
5355 $formconfirm .=
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
5357 $formconfirm .=
'<table class="valid centpercent">'.
"\n";
5360 $formconfirm .=
'<tr class="validtitre"><td class="validtitre" colspan="2">';
5365 if (is_array($formquestion) && !empty($formquestion[
'text'])) {
5366 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">'.$formquestion[
'text'].
'</td></tr>'.
"\n";
5371 $formconfirm .=
'<tr class="valid"><td class="valid" colspan="2">'.
"\n";
5378 $formconfirm .=
'<td class="valid">'.$question.
'</td>';
5380 $formconfirm .= $this->
selectyesno(
"confirm", $newselectedchoice, 0,
false, 0, 0,
'marginleftonly marginrightonly', $labelbuttonyes, $labelbuttonno);
5381 $formconfirm .=
'<input class="button valignmiddle confirmvalidatebutton small" type="submit" value="'.$langs->trans(
"Validate").
'">';
5387 if (empty($disableformtag)) {
5392 if (!empty($conf->use_javascript_ajax)) {
5393 $formconfirm .=
'<!-- code to disable button to avoid double clic -->';
5394 $formconfirm .=
'<script type="text/javascript">'.
"\n";
5396 $(document).ready(function () {
5397 $(".confirmvalidatebutton").on("click", function() {
5398 console.log("We click on button");
5399 $(this).attr("disabled", "disabled");
5400 setTimeout(\'$(".confirmvalidatebutton").removeAttr("disabled")\', 3000);
5401 //console.log($(this).closest("form"));
5402 $(this).closest("form").submit();
5432 public function form_project($page, $socid, $selected =
'', $htmlname =
'projectid', $discard_closed = 0, $maxlength = 20, $forcefocus = 0, $nooutput = 0, $textifnoproject =
'', $morecss =
'')
5437 require_once DOL_DOCUMENT_ROOT.
'/core/lib/project.lib.php';
5438 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
5444 $langs->load(
"project");
5445 if ($htmlname !=
"none") {
5446 $out .=
'<form method="post" action="'.$page.
'">';
5447 $out .=
'<input type="hidden" name="action" value="classin">';
5448 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
5449 $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0,
'', 1, 0, $morecss);
5450 $out .=
'<input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5453 $out .=
'<span class="project_head_block">';
5456 $projet->fetch($selected);
5457 $out .= $projet->getNomUrl(0,
'', 1);
5459 $out .=
'<span class="opacitymedium">'.$textifnoproject.
'</span>';
5464 if (empty($nooutput)) {
5487 public function form_conditions_reglement($page, $selected =
'', $htmlname =
'cond_reglement_id', $addempty = 0, $type =
'', $filtertype = -1, $deposit_percent = -1, $nooutput = 0)
5494 if ($htmlname !=
"none") {
5495 $out .=
'<form method="POST" action="'.$page.
'">';
5496 $out .=
'<input type="hidden" name="action" value="setconditions">';
5497 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
5499 $out .=
'<input type="hidden" name="type" value="'.dol_escape_htmltag($type).
'">';
5502 $out .=
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5507 if (isset($this->cache_conditions_paiements[$selected])) {
5508 $label = $this->cache_conditions_paiements[$selected][
'label'];
5510 if (!empty($this->cache_conditions_paiements[$selected][
'deposit_percent'])) {
5511 $label = str_replace(
'__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected][
'deposit_percent'], $label);
5516 $langs->load(
'errors');
5517 $out .= $langs->trans(
'ErrorNotInDictionaryPaymentConditions');
5524 if (empty($nooutput)) {
5545 if ($htmlname !=
"none") {
5546 print
'<form method="post" action="'.$page.
'">';
5547 print
'<input type="hidden" name="action" value="setavailability">';
5548 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5550 print
'<input type="submit" name="modify" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5551 print
'<input type="submit" name="cancel" class="button smallpaddingimp" value="'.$langs->trans(
"Cancel").
'">';
5556 print $this->cache_availability[$selected][
'label'];
5573 public function formInputReason($page, $selected =
'', $htmlname =
'demandreason', $addempty = 0)
5576 if ($htmlname !=
"none") {
5577 print
'<form method="post" action="'.$page.
'">';
5578 print
'<input type="hidden" name="action" value="setdemandreason">';
5579 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5581 print
'<input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
5586 foreach ($this->cache_demand_reason as $key => $val) {
5587 if ($val[
'id'] == $selected) {
5588 print $val[
'label'];
5612 public function form_date($page, $selected, $htmlname, $displayhour = 0, $displaymin = 0, $nooutput = 0, $type =
'')
5619 if ($htmlname !=
"none") {
5620 $ret .=
'<form method="POST" action="'.$page.
'" name="form'.$htmlname.
'">';
5621 $ret .=
'<input type="hidden" name="action" value="set'.$htmlname.
'">';
5622 $ret .=
'<input type="hidden" name="token" value="'.newToken().
'">';
5624 $ret .=
'<input type="hidden" name="type" value="'.dol_escape_htmltag($type).
'">';
5626 $ret .=
'<table class="nobordernopadding">';
5628 $ret .= $this->
selectDate($selected, $htmlname, $displayhour, $displaymin, 1,
'form'.$htmlname, 1, 0);
5630 $ret .=
'<td class="left"><input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'"></td>';
5631 $ret .=
'</tr></table></form>';
5640 if (empty($nooutput)) {
5658 public function form_users($page, $selected =
'', $htmlname =
'userid', $exclude =
'', $include =
'')
5663 if ($htmlname !=
"none") {
5664 print
'<form method="POST" action="'.$page.
'" name="form'.$htmlname.
'">';
5665 print
'<input type="hidden" name="action" value="set'.$htmlname.
'">';
5666 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5667 print $this->
select_dolusers($selected, $htmlname, 1, $exclude, 0, $include);
5668 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5672 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
5673 $theuser =
new User($this->
db);
5674 $theuser->fetch($selected);
5675 print $theuser->getNomUrl(1);
5697 public function form_modes_reglement($page, $selected =
'', $htmlname =
'mode_reglement_id', $filtertype =
'', $active = 1, $addempty = 0, $type =
'', $nooutput = 0)
5703 if ($htmlname !=
"none") {
5704 $out .=
'<form method="POST" action="'.$page.
'">';
5705 $out .=
'<input type="hidden" name="action" value="setmode">';
5706 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
5708 $out .=
'<input type="hidden" name="type" value="'.dol_escape_htmltag($type).
'">';
5710 $out .= $this->
select_types_paiements($selected, $htmlname, $filtertype, 0, $addempty, 0, 0, $active,
'', 1);
5711 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5716 $out .= $this->cache_types_paiements[$selected][
'label'];
5742 if ($htmlname !=
"none") {
5743 print
'<form method="POST" action="'.$page.
'">';
5744 print
'<input type="hidden" name="action" value="settransportmode">';
5745 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5747 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5752 print $this->cache_transport_mode[$selected][
'label'];
5772 if ($htmlname !=
"none") {
5773 print
'<form method="POST" action="'.$page.
'">';
5774 print
'<input type="hidden" name="action" value="setmulticurrencycode">';
5775 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5777 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5781 print !empty($selected) ?
currency_name($selected, 1) :
' ';
5798 global $langs, $mysoc, $conf;
5800 if ($htmlname !=
"none") {
5801 print
'<form method="POST" action="'.$page.
'">';
5802 print
'<input type="hidden" name="action" value="setmulticurrencyrate">';
5803 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5804 print
'<input type="text" class="maxwidth100" name="'.$htmlname.
'" value="'.(!empty($rate) ?
price(
price2num($rate,
'CU')) : 1).
'" /> ';
5805 print
'<select name="calculation_mode">';
5806 print
'<option value="1">Change '.$langs->trans(
"PriceUHT").
' of lines</option>';
5807 print
'<option value="2">Change '.$langs->trans(
"PriceUHTCurrency").
' of lines</option>';
5809 print
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5812 if (!empty($rate)) {
5813 print
price($rate, 1, $langs, 1, 0);
5814 if ($currency && $rate != 1) {
5815 print
' ('.price($rate, 1, $langs, 1, 0).
' '.$currency.
' = 1 '.$conf->currency.
')';
5840 public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter =
'', $maxvalue = 0, $more =
'', $hidelist = 0, $discount_type = 0)
5843 global $conf, $langs;
5844 if ($htmlname !=
"none") {
5845 print
'<form method="post" action="'.$page.
'">';
5846 print
'<input type="hidden" name="action" value="setabsolutediscount">';
5847 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5848 print
'<div class="inline-block">';
5849 if (!empty($discount_type)) {
5850 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
5851 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL") {
5852 $translationKey =
'HasAbsoluteDiscountFromSupplier';
5854 $translationKey =
'HasCreditNoteFromSupplier';
5857 if (!$filter || $filter ==
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
5858 $translationKey =
'HasAbsoluteDiscountFromSupplier';
5860 $translationKey =
'HasCreditNoteFromSupplier';
5864 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
5865 if (!$filter || $filter ==
"fk_facture_source IS NULL") {
5866 $translationKey =
'CompanyHasAbsoluteDiscount';
5868 $translationKey =
'CompanyHasCreditNote';
5871 if (!$filter || $filter ==
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
5872 $translationKey =
'CompanyHasAbsoluteDiscount';
5874 $translationKey =
'CompanyHasCreditNote';
5878 print $langs->trans($translationKey,
price($amount, 0, $langs, 0, 0, -1, $conf->currency));
5879 if (empty($hidelist)) {
5883 if (empty($hidelist)) {
5884 print
'<div class="inline-block" style="padding-right: 10px">';
5885 $newfilter =
'discount_type='.intval($discount_type);
5886 if (!empty($discount_type)) {
5887 $newfilter .=
' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL';
5889 $newfilter .=
' AND fk_facture IS NULL AND fk_facture_line IS NULL';
5892 $newfilter .=
' AND ('.$filter.
')';
5895 $nbqualifiedlines = $this->
select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
5896 if ($nbqualifiedlines > 0) {
5897 print
' <input type="submit" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans(
"UseLine")).
'"';
5898 if (!empty($discount_type) && $filter && $filter !=
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
5899 print
' title="'.$langs->trans(
"UseCreditNoteInInvoicePayment").
'"';
5901 if (empty($discount_type) && $filter && $filter !=
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
5902 print
' title="'.$langs->trans(
"UseCreditNoteInInvoicePayment").
'"';
5910 print
'<div class="inline-block">';
5935 public function form_contacts($page, $societe, $selected =
'', $htmlname =
'contactid')
5938 global $langs, $conf;
5940 if ($htmlname !=
"none") {
5941 print
'<form method="post" action="'.$page.
'">';
5942 print
'<input type="hidden" name="action" value="set_contact">';
5943 print
'<input type="hidden" name="token" value="'.newToken().
'">';
5944 print
'<table class="nobordernopadding">';
5949 $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans(
"AddContact") : $langs->trans(
"AddContactAddress"));
5950 print
'<a href="'.DOL_URL_ROOT.
'/contact/card.php?socid='.$societe->id.
'&action=create&backtoreferer=1">'.$addcontact.
'</a>';
5953 print
'<td class="left"><input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'"></td>';
5954 print
'</tr></table></form>';
5957 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
5959 $contact->fetch($selected);
5960 print $contact->getFullName($langs);
5984 public function form_thirdparty($page, $selected =
'', $htmlname =
'socid', $filter =
'', $showempty = 0, $showtype = 0, $forcecombo = 0, $events = array(), $nooutput = 0, $excludeids = array(), $textifnothirdparty =
'')
5990 if ($htmlname !=
"none") {
5991 $out .=
'<form method="post" action="'.$page.
'">';
5992 $out .=
'<input type="hidden" name="action" value="set_thirdparty">';
5993 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
5994 $out .= $this->
select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, 0,
'minwidth100',
'',
'', 1, array(),
false, $excludeids);
5995 $out .=
'<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans(
"Modify").
'">';
5999 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
6001 $soc->fetch($selected);
6002 $out .= $soc->getNomUrl(0,
'');
6004 $out .=
'<span class="opacitymedium">'.$textifnothirdparty.
'</span>';
6039 public function selectCurrency($selected =
'', $htmlname =
'currency_id', $mode = 0, $useempty =
'')
6041 global $conf, $langs, $user;
6043 $langs->loadCacheCurrencies(
'');
6047 if ($selected ==
'euro' || $selected ==
'euros') {
6051 $out .=
'<select class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.
'" id="'.$htmlname.
'">';
6053 $out .=
'<option value="-1" selected></option>';
6055 foreach ($langs->cache_currencies as $code_iso => $currency) {
6056 $labeltoshow = $currency[
'label'];
6058 $labeltoshow .=
' <span class="opacitymedium">('.$code_iso.
')</span>';
6060 $labeltoshow .=
' <span class="opacitymedium">('.$langs->getCurrencySymbol($code_iso).
')</span>';
6063 if ($selected && $selected == $code_iso) {
6064 $out .=
'<option value="'.$code_iso.
'" selected data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
6066 $out .=
'<option value="'.$code_iso.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
6068 $out .= $labeltoshow;
6069 $out .=
'</option>';
6071 $out .=
'</select>';
6073 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
6077 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
6095 public function selectMultiCurrency($selected =
'', $htmlname =
'multicurrency_code', $useempty = 0, $filter =
'', $excludeConfCurrency =
false, $morecss =
'')
6097 global $conf, $langs;
6099 $langs->loadCacheCurrencies(
'');
6101 $TCurrency = array();
6103 $sql =
"SELECT code FROM ".$this->db->prefix().
"multicurrency";
6104 $sql .=
" WHERE entity IN ('".getEntity(
'mutlicurrency').
"')";
6106 $sql .=
" AND ".$filter;
6110 while ($obj = $this->
db->fetch_object(
$resql)) {
6111 $TCurrency[$obj->code] = $obj->code;
6116 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'" name="'.$htmlname.
'" id="'.$htmlname.
'">';
6118 $out .=
'<option value=""> </option>';
6121 if (!in_array($conf->currency, $TCurrency) && !$excludeConfCurrency) {
6122 $TCurrency[$conf->currency] = $conf->currency;
6124 if (count($TCurrency) > 0) {
6125 foreach ($langs->cache_currencies as $code_iso => $currency) {
6126 if (isset($TCurrency[$code_iso])) {
6127 if (!empty($selected) && $selected == $code_iso) {
6128 $out .=
'<option value="'.$code_iso.
'" selected="selected">';
6130 $out .=
'<option value="'.$code_iso.
'">';
6133 $out .= $currency[
'label'];
6134 $out .=
' ('.$langs->getCurrencySymbol($code_iso).
')';
6135 $out .=
'</option>';
6140 $out .=
'</select>';
6143 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
6161 $num = count($this->cache_vatrates);
6168 $sql =
"SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly";
6169 $sql .=
" FROM ".$this->db->prefix().
"c_tva as t, ".$this->
db->prefix().
"c_country as c";
6170 $sql .=
" WHERE t.fk_pays = c.rowid";
6171 $sql .=
" AND t.active > 0";
6172 $sql .=
" AND c.code IN (".$this->db->sanitize($country_code, 1).
")";
6173 $sql .=
" ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
6177 $num = $this->
db->num_rows(
$resql);
6179 for ($i = 0; $i < $num; $i++) {
6180 $obj = $this->
db->fetch_object(
$resql);
6181 $this->cache_vatrates[$i][
'rowid'] = $obj->rowid;
6182 $this->cache_vatrates[$i][
'code'] = $obj->code;
6183 $this->cache_vatrates[$i][
'txtva'] = $obj->taux;
6184 $this->cache_vatrates[$i][
'nprtva'] = $obj->recuperableonly;
6185 $this->cache_vatrates[$i][
'localtax1'] = $obj->localtax1;
6186 $this->cache_vatrates[$i][
'localtax1_type'] = $obj->localtax1_type;
6187 $this->cache_vatrates[$i][
'localtax2'] = $obj->localtax2;
6188 $this->cache_vatrates[$i][
'localtax2_type'] = $obj->localtax1_type;
6190 $this->cache_vatrates[$i][
'label'] = $obj->taux.
'%'.($obj->code ?
' ('.$obj->code.
')' :
'');
6191 $this->cache_vatrates[$i][
'labelallrates'] = $obj->taux.
'/'.($obj->localtax1 ? $obj->localtax1 :
'0').
'/'.($obj->localtax2 ? $obj->localtax2 :
'0').($obj->code ?
' ('.$obj->code.
')' :
'');
6192 $positiverates =
'';
6194 $positiverates .= ($positiverates ?
'/' :
'').$obj->taux;
6196 if ($obj->localtax1) {
6197 $positiverates .= ($positiverates ?
'/' :
'').$obj->localtax1;
6199 if ($obj->localtax2) {
6200 $positiverates .= ($positiverates ?
'/' :
'').$obj->localtax2;
6202 if (empty($positiverates)) {
6203 $positiverates =
'0';
6205 $this->cache_vatrates[$i][
'labelpositiverates'] = $positiverates.($obj->code ?
' ('.$obj->code.
')' :
'');
6210 $this->error =
'<span class="error">'.$langs->trans(
"ErrorNoVATRateDefinedForSellerCountry", $country_code).
'</span>';
6214 $this->error =
'<span class="error">'.$this->db->error().
'</span>';
6241 public function load_tva($htmlname =
'tauxtva', $selectedrate =
'', $societe_vendeuse =
'', $societe_acheteuse =
'', $idprod = 0, $info_bits = 0, $type =
'', $options_only =
false, $mode = 0)
6244 global $langs, $conf, $mysoc;
6246 $langs->load(
'errors');
6251 $defaultnpr = ($info_bits & 0x01);
6252 $defaultnpr = (preg_match(
'/\*/', $selectedrate) ? 1 : $defaultnpr);
6253 $defaulttx = str_replace(
'*',
'', $selectedrate);
6256 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6257 $defaultcode = $reg[1];
6258 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6263 if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
6264 if ($societe_vendeuse->id == $mysoc->id) {
6265 $return .=
'<span class="error">'.$langs->trans(
"ErrorYourCountryIsNotDefined").
'</span>';
6267 $return .=
'<span class="error">'.$langs->trans(
"ErrorSupplierCountryIsNotDefined").
'</span>';
6278 if (is_object($societe_vendeuse)) {
6279 $code_country =
"'".$societe_vendeuse->country_code.
"'";
6281 $code_country =
"'".$mysoc->country_code.
"'";
6283 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6284 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6285 if (!
isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (
isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()))) {
6287 if (is_numeric($type)) {
6289 $code_country .=
",'".$societe_acheteuse->country_code.
"'";
6291 } elseif (!$idprod) {
6292 $code_country .=
",'".$societe_acheteuse->country_code.
"'";
6295 $prodstatic->fetch($idprod);
6297 $code_country .=
",'".$societe_acheteuse->country_code.
"'";
6308 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6309 $tmpthirdparty =
new Societe($this->
db);
6311 $defaulttx =
get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6312 $defaultnpr =
get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod);
6314 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6315 $defaultcode = $reg[1];
6316 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6318 if (empty($defaulttx)) {
6325 if ($defaulttx < 0 ||
dol_strlen($defaulttx) == 0) {
6326 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6328 $defaulttx = $this->cache_vatrates[$num - 1][
'txtva'];
6332 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6333 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6335 if (preg_match(
'/\((.*)\)/', $defaulttx, $reg)) {
6336 $defaultcode = $reg[1];
6337 $defaulttx = preg_replace(
'/\s*\(.*\)/',
'', $defaulttx);
6345 if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj ==
"0") {
6348 if (empty($conf->global->EXPENSEREPORT_OVERRIDE_VAT)) {
6349 $title =
' title="'.dol_escape_htmltag($langs->trans(
'VATIsNotUsed')).
'"';
6354 if (!$options_only) {
6355 $return .=
'<select class="flat minwidth50imp maxwidth100" id="'.$htmlname.
'" name="'.$htmlname.
'"'.($disabled ?
' disabled' :
'').$title.
'>';
6358 $selectedfound =
false;
6359 foreach ($this->cache_vatrates as $rate) {
6361 if ($disabled && $rate[
'txtva'] != 0) {
6366 $key = $rate[
'txtva'];
6367 $key .= $rate[
'nprtva'] ?
'*' :
'';
6368 if ($mode > 0 && $rate[
'code']) {
6369 $key .=
' ('.$rate[
'code'].
')';
6372 $key = $rate[
'rowid'];
6375 $return .=
'<option value="'.$key.
'"';
6376 if (!$selectedfound) {
6378 if ($defaultcode == $rate[
'code']) {
6379 $return .=
' selected';
6380 $selectedfound =
true;
6382 } elseif ($rate[
'txtva'] == $defaulttx && $rate[
'nprtva'] == $defaultnpr) {
6383 $return .=
' selected';
6384 $selectedfound =
true;
6390 if ($mysoc->country_code ==
'IN' || !empty($conf->global->MAIN_VAT_LABEL_IS_POSITIVE_RATES)) {
6392 $return .= $rate[
'labelpositiverates'];
6395 $return .=
vatrate($rate[
'label']);
6399 $return .= (empty($rate[
'code']) && $rate[
'nprtva']) ?
' *' :
'';
6401 $return .=
'</option>';
6404 if (!$options_only) {
6405 $return .=
'</select>';
6409 $return .= $this->error;
6442 public function select_date($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $nooutput = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'')
6445 $retstring = $this->
selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof);
6446 if (!empty($nooutput)) {
6468 public function selectDateToDate($set_time =
'', $set_time_end =
'', $prefix =
're', $empty = 0, $forcenewline = 0)
6472 $ret = $this->
selectDate($set_time, $prefix.
'_start', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"from"),
'tzuserrel');
6473 if ($forcenewline) {
6476 $ret .= $this->
selectDate($set_time_end, $prefix.
'_end', 0, 0, $empty,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
"to"),
'tzuserrel');
6507 public function selectDate($set_time =
'', $prefix =
're', $h = 0, $m = 0, $empty = 0, $form_name =
"", $d = 1, $addnowlink = 0, $disabled = 0, $fullday =
'', $addplusone =
'', $adddateof =
'', $openinghours =
'', $stepminutes = 1, $labeladddateof =
'', $placeholder =
'', $gm =
'auto')
6509 global $conf, $langs;
6511 if ($gm ===
'auto') {
6512 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
6517 if ($prefix ==
'') {
6528 if ($stepminutes <= 0 || $stepminutes > 30) {
6539 $orig_set_time = $set_time;
6541 if ($set_time ===
'' && $emptydate == 0) {
6542 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
6543 if ($gm ==
'tzuser' || $gm ==
'tzuserrel') {
6555 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
6557 $syear = (!empty($reg[1]) ? $reg[1] :
'');
6558 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
6559 $sday = (!empty($reg[3]) ? $reg[3] :
'');
6560 $shour = (!empty($reg[4]) ? $reg[4] :
'');
6561 $smin = (!empty($reg[5]) ? $reg[5] :
'');
6562 } elseif (strval($set_time) !=
'' && $set_time != -1) {
6567 if ($orig_set_time !=
'') {
6577 $shour = !isset($conf->global->MAIN_DEFAULT_DATE_HOUR) ? ($h == -1 ?
'23' :
'') : $conf->global->MAIN_DEFAULT_DATE_HOUR;
6578 $smin = !isset($conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ?
'59' :
'') : $conf->global->MAIN_DEFAULT_DATE_MIN;
6579 $ssec = !isset($conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ?
'59' :
'') : $conf->global->MAIN_DEFAULT_DATE_SEC;
6592 $usecalendar =
'combo';
6593 if (!empty($conf->use_javascript_ajax) && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR !=
"none")) {
6594 $usecalendar = ((empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR ==
'eldy') ?
'jquery' : $conf->global->MAIN_POPUP_CALENDAR);
6599 if ($usecalendar !=
'combo') {
6600 $formated_date =
'';
6602 if (strval($set_time) !=
'' && $set_time != -1) {
6604 $formated_date =
dol_print_date($set_time, $langs->trans(
"FormatDateShortInput"), $gm);
6608 if ($usecalendar ==
"eldy") {
6610 $retstring .=
'<input id="'.$prefix.
'" name="'.$prefix.
'" type="text" class="maxwidthdate" maxlength="11" value="'.$formated_date.
'"';
6611 $retstring .= ($disabled ?
' disabled' :
'');
6612 $retstring .=
' onChange="dpChangeDay(\''.$prefix.
'\',\
''.$langs->trans(
"FormatDateShortJavaInput").
'\');
"'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
6616 $retstringbuttom = '';
6618 $retstringbuttom = '<button id="'.$prefix.'Button
" type="button" class="dpInvisibleButtons
"';
6619 $base = DOL_URL_ROOT.'/core/';
6620 $retstringbuttom .= ' onClick="showDP(\
''.$base.
'\',\
''.$prefix.
'\',\
''.$langs->trans(
"FormatDateShortJavaInput").
'\',\
''.$langs->defaultlang.
'\');
"';
6621 $retstringbuttom .= '>'.img_object($langs->trans("SelectDate
"), 'calendarday', 'class="datecallink
"').'</button>';
6623 $retstringbuttom = '<button id="'.$prefix.'Button
" type="button" class="dpInvisibleButtons