27 if (!defined(
'NOREQUIRESOC')) {
28 define(
'NOREQUIRESOC',
'1');
30 if (!defined(
'NOCSRFCHECK')) {
31 define(
'NOCSRFCHECK', 1);
33 if (!defined(
'NOTOKENRENEWAL')) {
34 define(
'NOTOKENRENEWAL', 1);
36 if (!defined(
'NOLOGIN')) {
39 if (!defined(
'NOREQUIREMENU')) {
40 define(
'NOREQUIREMENU', 1);
42 if (!defined(
'NOREQUIREHTML')) {
43 define(
'NOREQUIREHTML', 1);
45 if (!defined(
'NOREQUIREAJAX')) {
46 define(
'NOREQUIREAJAX',
'1');
49 session_cache_limiter(
'public');
51 require_once
'../../main.inc.php';
61 if (empty($dolibarr_nocache)) {
62 header(
'Cache-Control: max-age=10800, public, must-revalidate');
64 header(
'Cache-Control: no-cache');
85 $tradMonthsShort = array(
86 $langs->trans(
"MonthShort01"),
87 $langs->trans(
"MonthShort02"),
88 $langs->trans(
"MonthShort03"),
89 $langs->trans(
"MonthShort04"),
90 $langs->trans(
"MonthShort05"),
91 $langs->trans(
"MonthShort06"),
92 $langs->trans(
"MonthShort07"),
93 $langs->trans(
"MonthShort08"),
94 $langs->trans(
"MonthShort09"),
95 $langs->trans(
"MonthShort10"),
96 $langs->trans(
"MonthShort11"),
97 $langs->trans(
"MonthShort12")
101 $langs->trans(
"Sunday"),
102 $langs->trans(
"Monday"),
103 $langs->trans(
"Tuesday"),
104 $langs->trans(
"Wednesday"),
105 $langs->trans(
"Thursday"),
106 $langs->trans(
"Friday"),
107 $langs->trans(
"Saturday")
110 $tradDaysShort = array(
111 $langs->trans(
"ShortSunday"),
112 $langs->trans(
"ShortMonday"),
113 $langs->trans(
"ShortTuesday"),
114 $langs->trans(
"ShortWednesday"),
115 $langs->trans(
"ShortThursday"),
116 $langs->trans(
"ShortFriday"),
117 $langs->trans(
"ShortSaturday")
120 $tradDaysMin = array(
121 $langs->trans(
"SundayMin"),
122 $langs->trans(
"MondayMin"),
123 $langs->trans(
"TuesdayMin"),
124 $langs->trans(
"WednesdayMin"),
125 $langs->trans(
"ThursdayMin"),
126 $langs->trans(
"FridayMin"),
127 $langs->trans(
"SaturdayMin")
133 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
134 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
136 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
137 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
139 if ($thousand ==
'Space') {
147 var tradMonths = <?php echo json_encode($tradMonths) ?>;
148 var tradMonthsShort = <?php echo json_encode($tradMonthsShort) ?>;
149 var tradDays = <?php echo json_encode($tradDays) ?>;
150 var tradDaysShort = <?php echo json_encode($tradDaysShort) ?>;
151 var tradDaysMin = <?php echo json_encode($tradDaysMin) ?>;
152 var currencyCache = <?php echo json_encode($langs->cache_currencies) ?>;
155 $(document).ready(
function() {
156 $.datepicker.setDefaults({
160 altField:
'#timestamp',
166 $.datepicker.regional[
'<?php echo $langs->defaultlang ?>'] = {
167 closeText:
'<?php echo $langs->trans("Close2") ?>',
168 prevText:
'<?php echo $langs->trans("Previous") ?>',
169 nextText:
'<?php echo $langs->trans("Next") ?>',
170 currentText:
'<?php echo $langs->trans("Now") ?>',
171 monthNames: tradMonths,
172 monthNamesShort: tradMonthsShort,
174 dayNamesShort: tradDaysShort,
175 dayNamesMin: tradDaysMin,
176 weekHeader:
'<?php echo $langs->trans("Week"); ?>',
177 dateFormat:
'<?php echo $langs->trans("FormatDateShortJQuery"); ?>',
178 firstDay: <?php echo (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK :
'1'); ?>,
179 isRTL: <?php echo ($langs->trans(
"DIRECTION") ==
'rtl' ?
'true' :
'false'); ?>,
180 showMonthAfterYear:
false,
183 $.datepicker.setDefaults($.datepicker.regional[
'<?php echo $langs->defaultlang ?>']);
192 var select2arrayoflanguage = {
193 matches:
function (matches) {
return matches +
" <?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2ResultFoundUseArrows
")); ?>"; },
194 noResults:
function () {
return "<?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2NotFound
")); ?>"; },
195 inputTooShort:
function (input) {
196 var n = input.minimum;
199 if (n > 1)
return "<?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2Enter
")); ?> " + n +
" <?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2MoreCharacters
")); ?>";
200 else return "<?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2Enter
")); ?> " + n +
" <?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2MoreCharacter
")); ?>"
202 loadMore:
function (pageNumber) {
return "<?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2LoadingMoreResults
")); ?>"; },
203 searching:
function () {
return "<?php echo dol_escape_js($langs->transnoentitiesnoconv("Select2SearchInProgress
")); ?>"; }
212 function getObjectFromID(
id){
214 if(document.getElementById)
215 theObject=document.getElementById(
id);
217 theObject=document.all[id];
222 function dpChangeDay(dateFieldID, format)
225 console.log(
"Call dpChangeDay, we save date into detailed fields from format = "+format);
227 var thefield=getObjectFromID(dateFieldID);
228 var thefieldday=getObjectFromID(dateFieldID+
"day");
229 var thefieldmonth=getObjectFromID(dateFieldID+
"month");
230 var thefieldyear=getObjectFromID(dateFieldID+
"year");
232 var date=getDateFromFormat(thefield.value, format);
236 thefieldday.value=date.getDate();
237 if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
238 thefieldmonth.value=date.getMonth()+1;
239 if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
240 thefieldyear.value=date.getFullYear();
241 if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
245 thefieldday.value=
'';
246 if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
247 thefieldmonth.value=
'';
248 if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
249 thefieldyear.value=
'';
250 if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
267 function formatDate(date,format)
276 var year=date.getYear()+
"";
if (year.length < 4) { year=
""+(year-0+1900); }
277 var month=date.getMonth()+1;
278 var day=date.getDate();
279 var hour=date.getHours();
280 var minute=date.getMinutes();
281 var seconde=date.getSeconds();
284 while (i < format.length)
289 while ((format.charAt(j)==c) && (j < format.length))
291 substr += format.charAt(j++);
295 if (substr ==
'yyyy') { result=result+year; }
296 else if (substr ==
'yy') { result=result+year.substring(2,4); }
297 else if (substr ==
'M') { result=result+month; }
298 else if (substr ==
'MM') { result=result+(month<1||month>9?
"":
"0")+month; }
299 else if (substr ==
'd') { result=result+day; }
300 else if (substr ==
'dd') { result=result+(day<1||day>9?
"":
"0")+day; }
301 else if (substr ==
'hh') {
if (hour > 12) hour-=12; result=result+(hour<0||hour>9?
"":
"0")+hour; }
302 else if (substr ==
'HH') { result=result+(hour<0||hour>9?
"":
"0")+hour; }
303 else if (substr ==
'mm') { result=result+(minute<0||minute>9?
"":
"0")+minute; }
304 else if (substr ==
'ss') { result=result+(seconde<0||seconde>9?
"":
"0")+seconde; }
305 else { result=result+substr; }
335 function getDateFromFormat(val,format)
343 if (val ==
'')
return 0;
346 var year=now.getYear();
if (year.length < 4) { year=
""+(year-0+1900); }
347 var month=now.getMonth()+1;
348 var day=now.getDate();
349 var hour=now.getHours();
350 var minute=now.getMinutes();
351 var seconde=now.getSeconds();
357 while (i < format.length)
362 while ((format.charAt(j)==c) && (j < format.length))
366 substr += format.charAt(j++);
370 if (substr ==
"yyyy") year=getIntegerInString(val,d,4,4);
371 if (substr ==
"yy") year=
""+(getIntegerInString(val,d,2,2)-0+1900);
372 if (substr ==
"MM" ||substr ==
"M")
374 month=getIntegerInString(val,d,1,2);
375 if (month) d -= 2- month.length;
379 day=getIntegerInString(val,d,1,2);
380 if (day) d -= 2- day.length;
382 if (substr ==
"HH" ||substr ==
"hh" )
384 hour=getIntegerInString(val,d,1,2);
385 if (dhouray) d -= 2- hour.length;
388 minute=getIntegerInString(val,d,1,2);
389 if (minute) d -= 2- minute.length;
393 seconde=getIntegerInString(val,d,1,2);
394 if (seconde) d -= 2- seconde.length;
402 if (year==
null||year<1) {
return 0; }
403 if (month==
null||(month<1)||(month>12)) {
return 0; }
404 if (day==
null||(day<1)||(day>31)) {
return 0; }
405 if (hour==
null||(hour<0)||(hour>24)) {
return 0; }
406 if (minute==
null||(minute<0)||(minute>60)) {
return 0; }
407 if (seconde==
null||(seconde<0)||(seconde>60)) {
return 0; }
410 return new Date(year,month-1,day,hour,minute,seconde);
419 function stringIsInteger(str)
421 var digits=
"1234567890";
422 for (var i=0; i < str.length; i++)
424 if (digits.indexOf(str.charAt(i))==-1)
438 function getIntegerInString(str,i,minlength,maxlength)
440 for (var x=maxlength; x>=minlength; x--)
442 var substr=str.substring(i,i+x);
443 if (substr.length < minlength) {
return null; }
444 if (stringIsInteger(substr)) {
return substr; }
458 function urlencode(s) {
460 news=news.replace(/\+/gi,
'%2B');
461 news=news.replace(/&/gi,
'%26');
473 function htmlEntityDecodeJs(inp){
474 var replacements = {
'<':
'<',
'>':
'>',
'/':
'/',
'"':
'"',
''':
'\'',
'&':
'&',
' ':
' '};
477 for(var r in replacements){
478 inp = inp.replace(
new RegExp(r,
'g'),replacements[r]);
480 return inp.replace(/&#(\d+);/g,
function(match, dec) {
481 return String.fromCharCode(dec);
496 function ac_delay(funct,delay) {
498 setTimeout(funct,delay);
511 function cleanSerialize(expr) {
512 if (typeof(expr) !=
'string')
return '';
513 var reg =
new RegExp(
"(&)",
"g");
514 var reg2 =
new RegExp(
"[^A-Z0-9,]",
"g");
515 var liste1 = expr.replace(reg,
",");
516 return liste1.replace(reg2,
"");
530 function displayMessage(fieldId,message) {
531 var textbox = document.getElementById(fieldId);
532 if (textbox.value ==
'') {
533 textbox.style.color =
'grey';
534 textbox.value = message;
548 function hideMessage(fieldId,message) {
549 var textbox = document.getElementById(fieldId);
550 textbox.style.color =
'black';
551 if (textbox.value == message) textbox.value =
'';
569 function setConstant(url,
code, input, entity, strict, forcereload, userid, token, value) {
579 console.log(
"Ajax url request to set constant is a success. Make complementary actions and then forcereload="+forcereload+
" value="+value);
581 $(
"#set_" +
code).show();
582 $(
"#del_" +
code).hide();
584 $(
"#set_" +
code).hide();
585 $(
"#del_" +
code).show();
587 $.each(input,
function(
type, data) {
589 if (
type ==
"disabled" && strict != 1) {
590 $.each(data,
function(key, value) {
591 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
592 $(newvalue).removeAttr(
"disabled");
593 if ($(newvalue).hasClass(
"butActionRefused") ==
true) {
594 $(newvalue).removeClass(
"butActionRefused");
595 $(newvalue).addClass(
"butAction");
598 }
else if (
type ==
"enabled") {
599 $.each(data,
function(key, value) {
600 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
602 $(newvalue).removeAttr(
"disabled");
604 $(newvalue).attr(
"disabled",
true);
605 if ($(newvalue).hasClass(
"butAction") ==
true) {
606 $(newvalue).removeClass(
"butAction");
607 $(newvalue).addClass(
"butActionRefused");
611 }
else if (
type ==
"showhide" ||
type ==
"show") {
612 $.each(data,
function(key, value) {
613 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
617 }
else if (
type ==
"set") {
618 $.each(data,
function(key, value) {
619 $(
"#set_" + key).hide();
620 $(
"#del_" + key).show();
632 var url = window.location.href;
633 if (url.indexOf(
'dol_resetcache') < 0) {
634 if (url.indexOf(
'?') > -1) {
635 url = url +
"&dol_resetcache=1";
637 url = url +
"?dol_resetcache=1";
640 var page_y = $(document).scrollTop();
641 url = url.replace(/page_y=\d+/g,
'');
643 if (url.indexOf(
'?') > -1) {
644 url = url +
"&page_y="+page_y;
646 url = url +
"?page_y="+page_y;
649 url = url.replace(/&&+/,
'&');
650 console.log(
"url ro redirect = "+url);
652 window.location.href = url;
656 }).
fail(
function(error) { console.log(
"Error, we force reload"); location.reload(); });
672 function delConstant(url,
code, input, entity, strict, forcereload, userid, token) {
681 console.log(
"Ajax url request to delete constant is success. Make complementary actions and then forcereload="+forcereload);
682 $(
"#del_" +
code).hide();
683 $(
"#set_" +
code).show();
684 $.each(input,
function(
type, data) {
686 if (
type ==
"disabled") {
687 $.each(data,
function(key, value) {
688 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
689 $(newvalue).attr(
"disabled",
true);
690 if ($(newvalue).hasClass(
"butAction") ==
true) {
691 $(newvalue).removeClass(
"butAction");
692 $(newvalue).addClass(
"butActionRefused");
695 }
else if (
type ==
"enabled" && strict != 1) {
696 $.each(data,
function(key, value) {
697 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
698 $(newvalue).removeAttr(
"disabled");
699 if ($(newvalue).hasClass(
"butActionRefused") ==
true) {
700 $(newvalue).removeClass(
"butActionRefused");
701 $(newvalue).addClass(
"butAction");
705 }
else if (
type ==
"showhide" ||
type ==
"hide") {
706 $.each(data,
function(key, value) {
707 var newvalue=((value.search(
"^#") < 0 && value.search(
"^\.") < 0) ?
"#" :
"") + value;
711 }
else if (
type ==
"del") {
712 $.each(data,
function(key, value) {
713 $(
"#del_" + value).hide();
714 $(
"#set_" + value).show();
725 var url = window.location.href;
726 if (url.indexOf(
'dol_resetcache') < 0) {
727 if (url.indexOf(
'?') > -1) {
728 url = url +
"&dol_resetcache=1";
730 url = url +
"?dol_resetcache=1";
733 var page_y = $(document).scrollTop();
734 url = url.replace(/page_y=\d+/g,
'');
736 if (url.indexOf(
'?') > -1) {
737 url = url +
"&page_y="+page_y;
739 url = url +
"?page_y="+page_y;
742 url = url.replace(/&&+/,
'&');
743 console.log(
"url ro redirect = "+url);
745 window.location.href = url;
749 }).
fail(
function(error) { console.log(
"Error, we force reload"); location.reload(); });
768 function confirmConstantAction(action, url,
code, input, box, entity, yesButton, noButton, strict, userid, token) {
769 var boxConfirm = box;
770 $(
"#confirm_" +
code)
771 .attr(
"title", boxConfirm.title)
772 .html(boxConfirm.content)
780 id :
'yesButton_' +
code,
783 if (action ==
"set") {
784 setConstant(url,
code, input, entity, strict, 0, userid, token, 1);
785 }
else if (action ==
"del") {
786 delConstant(url,
code, input, entity, strict, 0, userid, token);
789 $(
this).dialog(
"close");
791 if (boxConfirm.method) {
792 var fnName = boxConfirm.method;
793 if (window.hasOwnProperty(fnName)) {
800 id :
'noButton_' +
code,
803 $(
this).dialog(
"close");
809 if (boxConfirm.info) {
824 $.widget(
"ui.combobox", {
826 minLengthToAutocomplete: 0
828 _create:
function() {
829 var savMinLengthToAutocomplete = this.options.minLengthToAutocomplete;
831 select = this.element.hide(),
832 selected = select.children(
":selected" ),
833 value = selected.val() ? selected.text() :
"";
834 var input = this.input = $(
"<input>" )
835 .insertAfter( select )
837 .attr(
'id',
'inputautocomplete'+select.attr(
'id'))
840 minLength: this.options.minLengthToAutocomplete,
841 source:
function( request, response ) {
842 var matcher =
new RegExp( $.ui.autocomplete.escapeRegex(request.term),
"i" );
843 response( select.children(
"option:enabled" ).map(
function() {
844 var text = $( this ).text();
845 if ( this.value && ( !request.term || matcher.test(text) ) )
849 "(?![^&;]+;)(?!<[^<>]*)(" +
850 $.ui.autocomplete.escapeRegex(request.term) +
851 ")(?![^<>]*>)(?![^&;]+;)",
"gi"
852 ),
"<strong>$1</strong>" ),
858 select:
function( event, ui ) {
859 ui.item.option.selected =
true;
860 self._trigger(
"selected", event, {
864 change:
function( event, ui ) {
866 var matcher =
new RegExp(
"^" + $.ui.autocomplete.escapeRegex( $(
this).val() ) +
"$",
"i" ),
868 select.children(
"option" ).each(
function() {
869 if ( $(
this ).text().match( matcher ) ) {
870 this.selected = valid =
true;
878 input.data(
"ui-autocomplete").term =
"";
884 .addClass(
"ui-widget ui-widget-content ui-corner-left dolibarrcombobox" );
886 input.data(
"ui-autocomplete")._renderItem =
function( ul, item ) {
888 .data(
"ui-autocomplete-item", item )
889 .append(
"<a>" + item.label +
"</a>" )
893 this.
button = $(
"<button type=\'button\'> </button>" )
894 .attr(
"tabIndex", -1 )
895 .attr(
"title",
"Show All Items" )
896 .insertAfter( input )
899 primary:
"ui-icon-triangle-1-s"
903 .removeClass(
"ui-corner-all" )
904 .addClass(
"ui-corner-right ui-button-icon" )
907 if ( input.autocomplete(
"widget" ).is(
":visible" ) ) {
908 input.autocomplete(
"close" );
913 input.autocomplete({ minLength: 0 });
914 input.autocomplete(
"search",
"" );
915 input.autocomplete({ minLength: savMinLengthToAutocomplete });
920 destroy:
function() {
924 $.Widget.prototype.destroy.call(
this );
939 text = text.replace(/<br>/g,
"\n");
940 var newElem =
'<textarea id="coordsforpopup" style="border: none; width: 90%; height: 120px;">'+text+
'</textarea><br><br>'+text2;
942 $(
"#dialogforpopup").html(newElem);
943 $(
"#dialogforpopup").dialog();
944 $(
"#coordsforpopup").select();
959 var argc =
newpopup.arguments.length;
961 console.log(
"newpopup "+argv[2]+
" "+argv[3]);
962 var l = (argc > 2) ? argv[2] : 600;
963 var h = (argc > 3) ? argv[3] : 400;
964 var left = (screen.width - l)/2;
965 var top = (screen.height - h)/2;
966 var wfeatures =
"directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width=" + l +
",height=" + h +
",left=" + left +
",top=" + top;
967 fen=window.open(tmp,title,wfeatures);
983 var ValidImageTypes = [
"image/gif",
"image/jpeg",
"image/png",
"image/webp"];
984 var showOriginalSizeButton =
false;
986 console.log(
"document_preview A click was done. file="+file+
", type="+
type+
", title="+title);
988 if ($.inArray(
type, ValidImageTypes) < 0) {
991 var object_width=
'100%';
992 var height = ($( window ).height() - 60) * 0.90;
993 var object_height=
'98%';
995 show_preview(
'notimage');
1000 var object_height=0;
1002 var img =
new Image();
1004 img.onload =
function() {
1005 object_width = this.width;
1006 object_height = this.height;
1008 width = $( window ).width()*0.90;
1009 console.log(
"object_width="+object_width+
" window width="+width);
1010 if(object_width < width){
1011 console.log(
"Object width is small, we set width of popup according to image width.");
1012 width = object_width + 30
1014 height = $( window ).height()*0.85;
1015 console.log(
"object_height="+object_height+
" window height="+height);
1016 if(object_height < height){
1017 console.log(
"Object height is small, we set height of popup according to image height.");
1018 height = object_height + 80
1022 showOriginalSizeButton =
true;
1025 show_preview(
'image');
1032 function show_preview(mode) {
1034 var newElem =
'<object name="objectpreview" data="'+file+
'" type="'+
type+
'" width="'+object_width+
'" height="'+object_height+
'" param="noparam"></object>';
1037 if (mode ==
'image' && showOriginalSizeButton)
1040 "<?php echo dol_escape_js($langs->transnoentitiesnoconv("OriginalSize
")); ?>":
function() { console.log(
"Click on original size"); jQuery(
".ui-dialog-content.ui-widget-content > object").css({
"max-height":
"none" }); },
1041 "<?php echo dol_escape_js($langs->transnoentitiesnoconv("CloseWindow
")); ?>":
function() { $( this ).dialog(
"close" ); }
1045 $(
"#dialogforpopup").html(newElem);
1047 $(
"#dialogforpopup").dialog({
1048 closeOnEscape:
true,
1054 buttons: optionsbuttons
1057 if (showOriginalSizeButton)
1059 jQuery(
".ui-dialog-content.ui-widget-content > object").css({
"max-height":
"100%",
"width":
"auto",
"margin-left":
"auto",
"margin-right":
"auto",
"display":
"block" });
1073 name =
name.replace(/[\[]/,
"\\[").replace(/[\]]/,
"\\]");
1074 var regex =
new RegExp(
"[\\?&]" +
name +
"=([^&#]*)"),
1075 results = regex.exec(location.search);
1076 return results ===
null ? valueifnotfound : decodeURIComponent(results[1].replace(/\+/g,
" "));
1090 function decimalAdjust(
type, value, exp) {
1092 if (typeof exp ===
'undefined' || +exp === 0) {
1093 return Math[
type](value);
1098 if (isNaN(value) || !(typeof exp ===
'number' && exp % 1 === 0)) {
1102 value = value.toString().split(
'e');
1103 value = Math[
type](+(value[0] +
'e' + (value[1] ? (+value[1] - exp) : -exp)));
1105 value = value.toString().split(
'e');
1106 return +(value[0] +
'e' + (value[1] ? (+value[1] + exp) : exp));
1110 if (!Math.round10) {
1111 Math.round10 =
function(value, exp) {
1112 return decimalAdjust(
'round', value, exp);
1116 if (!Math.floor10) {
1117 Math.floor10 =
function(value, exp) {
1118 return decimalAdjust(
'floor', value, exp);
1123 Math.ceil10 =
function(value, exp) {
1124 return decimalAdjust(
'ceil', value, exp);
1130 function dolroundjs(number, decimals) {
return +(Math.round(number +
"e+" + decimals) +
"e-" + decimals); }
1149 function pricejs(amount, mode =
'MT', currency_code =
'', force_locale =
'') {
1150 var main_max_dec_shown = <?php echo (
int) str_replace(
'.',
'', $conf->global->MAIN_MAX_DECIMALS_SHOWN); ?>;
1151 var main_rounding_unit = <?php echo (
int) $conf->global->MAIN_MAX_DECIMALS_UNIT; ?>;
1152 var main_rounding_tot = <?php echo (
int) $conf->global->MAIN_MAX_DECIMALS_TOT; ?>;
1153 var main_decimal_separator = <?php echo json_encode($dec) ?>;
1154 var main_thousand_separator = <?php echo json_encode($thousand) ?>;
1155 var locale_code = force_locale || <?php echo json_encode($langs->defaultlang) ?>;
1156 var amountAsLocalizedString;
1157 var useIntl = Boolean(Intl && Intl.NumberFormat);
1159 if (currency_code ===
'auto') currency_code = <?php echo json_encode($conf->currency) ?>;
1161 if (mode ===
'MU') nDigits = main_rounding_unit;
1162 else if (mode ===
'MT') nDigits = main_rounding_tot;
1163 else return 'Bad value for parameter mode';
1168 var formattingOptions = {
1169 minimumFractionDigits: nDigits,
1170 maximumFractionDigits: nDigits
1172 if (currency_code) {
1173 formattingOptions[
'style'] =
'currency';
1174 formattingOptions[
'currency'] = currency_code;
1176 return Intl.NumberFormat(locale_code.replace(
'_',
'-'), formattingOptions).format(amount);
1180 amountAsLocalizedString = amount.toFixed(nDigits).replace(
1181 /((?!^)(?:\d{3})*)(?:\.(\d+))?$/,
1182 (fullMatch, digitsByThree, decimals) =>
1183 digitsByThree.replace(
1185 (groupOfThree) => main_thousand_separator + groupOfThree
1186 ) + (decimals !== undefined ? main_decimal_separator + decimals :
'')
1187 ).replace(/ /,
' ');
1188 if (!currency_code)
return amountAsLocalizedString;
1191 var currency_symbol = currency_code;
1194 var currencyBeforeAmountCodes = {
1195 currency: [
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD'],
1199 if (currencyCache[currency_code]
1200 && currencyCache[currency_code][
'unicode']
1201 && currencyCache[currency_code][
'unicode'].length) {
1202 currency_symbol = currencyCache[currency_code][
'unicode'].reduce(
function (res, cur) {
return res + cur},
'');
1205 if (currencyBeforeAmountCodes.currency.indexOf(currency_code) >= 0
1206 || currencyBeforeAmountCodes.language.indexOf(locale_code)) {
1208 return currency_symbol + amountAsLocalizedString;
1212 return amountAsLocalizedString +
' ' + currency_symbol;
1223 if (amount ==
'')
return '';
1225 var dec = <?php echo json_encode($dec) ?>;
1226 var thousand = <?php echo json_encode($thousand) ?>;
1228 var main_max_dec_shown = <?php echo (
int) str_replace(
'.',
'', $conf->global->MAIN_MAX_DECIMALS_SHOWN); ?>;
1229 var main_rounding_unit = <?php echo (
int) $conf->global->MAIN_MAX_DECIMALS_UNIT; ?>;
1230 var main_rounding_tot = <?php echo (
int) $conf->global->MAIN_MAX_DECIMALS_TOT; ?>;
1232 var amount = amount.toString();
1235 var rounding = main_rounding_unit;
1236 var pos = amount.indexOf(dec);
1238 if (pos >= 0) decpart = amount.substr(pos + 1).replace(
'/0+$/i',
'');
1239 var nbdec = decpart.length;
1240 if (nbdec > rounding) rounding = nbdec;
1242 if (rounding > main_max_dec_shown) rounding = main_max_dec_shown;
1243 if (thousand !=
',' && thousand !=
'.') amount = amount.replace(
',',
'.');
1244 amount = amount.replace(
' ',
'');
1245 amount = amount.replace(thousand,
'');
1246 amount = amount.replace(dec,
'.');
1248 var res = Math.round10(amount, - rounding);
1251 console.log(
"price2numjs text="+amount+
" return="+res);
1257 if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined(
'DISABLE_JQUERY_JNOTIFY')) {
1260 $(document).ready(
function() {
1261 if (typeof $.jnotify ==
'function')
1266 , closeLabel:
"×"
1270 , classContainer:
"jnotify-container"
1271 , classNotification:
"jnotify-notification"
1272 , classBackground:
"jnotify-background"
1273 , classClose:
"jnotify-close"
1274 , classMessage:
"jnotify-message"
1277 , beforeRemove:
null
1284 $(document).ready(
function() {
1285 if (window.location && window.location.pathname.indexOf(
"externalsite/frametop.php") == -1 && window.location !== window.parent.location ) {
1286 console.log(
"Page is detected to be into an iframe, we hide by CSS the menus");
1288 jQuery(
".side-nav-vert, .side-nav, .websitebar").hide();
1289 jQuery(
".id-container").css(
'width',
'100%');
1302 $(document).on(
'select2:open', () => {
1303 console.log(
"Execute the focus (click on combo or use space when on component");
1304 let allFound = document.querySelectorAll(
'.select2-container--open .select2-search__field');
1305 $(
this).one(
'mouseup keyup',()=>{
1307 allFound[allFound.length - 1].focus();
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
if(empty($user->rights->takepos->run) &&!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) if((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT')==1 && $conf->browser->layout=='phone')||defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) fail($message)
Abort invoice creationg with a given error message.
getParameterByName(name, valueifnotfound)
copyToClipboard(text, text2)
Function to output a dialog box for copy/paste.
document_preview(file, type, title)
Function show document preview.
pricejs(amount, mode='MT', currency_code='', force_locale='')
Function similar to PHP price()
newpopup(url, title)
Show a popup HTML page.
price2numjs(amount)
Function similar to PHP price2num()
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...