NEW Can set/unset the usual working day of the week

This commit is contained in:
Laurent Destailleur 2021-08-05 14:42:28 +02:00
parent f6abeca246
commit 047bbbb298
6 changed files with 265 additions and 170 deletions

View File

@ -274,18 +274,11 @@ print '</div>';
print '<br>'; print '<br>';
if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
print dol_get_fiche_end();
// End of page
llxFooter();
$db->close();
exit;
}
/* /*
* Documents models for Holidays * Documents models for Holidays
*/ */
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
print load_fiche_titre($langs->trans("TemplatePDFHolidays"), '', ''); print load_fiche_titre($langs->trans("TemplatePDFHolidays"), '', '');
// Defined model definition table // Defined model definition table
@ -427,6 +420,7 @@ foreach ($dirmodels as $reldir) {
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print "<br>"; print "<br>";
}
/* /*
@ -446,6 +440,89 @@ print '<td>'.$langs->trans("Parameter").'</td>';
print '<td align="center" width="60">'.$langs->trans("Value").'</td>'; print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
print "</tr>\n"; print "</tr>\n";
/*var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY);
*/
if (!isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY)) {
$conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY = 1;
}
if (!isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY)) {
$conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY = 1;
}
/*
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY);
var_dump($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY);
*/
// Set working days
print '<tr class="oddeven">';
print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Monday"))."</td>";
print '<td class="center">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', array(), null, 0);
} else {
if (!empty($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
}
}
print "</td>";
print "</tr>";
// Set working days
print '<tr class="oddeven">';
print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Friday"))."</td>";
print '<td class="center">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', array(), null, 0);
} else {
if (!empty($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
}
}
print "</td>";
print "</tr>";
// Set working days
print '<tr class="oddeven">';
print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Saturday"))."</td>";
print '<td class="center">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', array(), null, 0, 0, 0, 2, 0, 1);
} else {
if (!empty($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
}
}
print "</td>";
print "</tr>";
// Set working days
print '<tr class="oddeven">';
print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Sunday"))."</td>";
print '<td class="center">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', array(), null, 0, 0, 0, 2, 0, 1);
} else {
if (!empty($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
}
}
print "</td>";
print "</tr>";
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
$substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2); $substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation"); $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>'; $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
@ -474,6 +551,7 @@ print $form->textwithpicto($langs->trans("WatermarkOnDraftHolidayCards"), $htmlt
print '</td><td>'; print '</td><td>';
print '<input class="flat minwidth200" type="text" name="HOLIDAY_DRAFT_WATERMARK" value="'.$conf->global->HOLIDAY_DRAFT_WATERMARK.'">'; print '<input class="flat minwidth200" type="text" name="HOLIDAY_DRAFT_WATERMARK" value="'.$conf->global->HOLIDAY_DRAFT_WATERMARK.'">';
print '</td></tr>'."\n"; print '</td></tr>'."\n";
}
print '</table>'; print '</table>';
print '</div>'; print '</div>';

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com> /* Copyright (C) 2011-2015 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -47,6 +48,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$action = GETPOST('action', 'aZ09'); // set or del $action = GETPOST('action', 'aZ09'); // set or del
$name = GETPOST('name', 'alpha'); $name = GETPOST('name', 'alpha');
$entity = GETPOST('entity', 'int');
$value = ((GETPOST('value', 'int') || GETPOST('value', 'int') == '0') ? GETPOST('value', 'int') : 1);
/* /*
@ -64,9 +67,6 @@ top_httphead();
// Registering the new value of constant // Registering the new value of constant
if (!empty($action) && !empty($name)) { if (!empty($action) && !empty($name)) {
$entity = GETPOST('entity', 'int');
$value = (GETPOST('value') ?GETPOST('value') : 1);
if ($user->admin) { if ($user->admin) {
if ($action == 'set') { if ($action == 'set') {
dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity); dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);

View File

@ -549,20 +549,27 @@ function hideMessage(fieldId,message) {
* @param int strict Strict * @param int strict Strict
* @param int forcereload Force reload * @param int forcereload Force reload
* @param int userid User id * @param int userid User id
* @param int value Value to set
* @param string token Token * @param string token Token
*/ */
function setConstant(url, code, input, entity, strict, forcereload, userid, token) { function setConstant(url, code, input, entity, strict, forcereload, userid, token, value) {
var saved_url = url; /* avoid undefined url */ var saved_url = url; /* avoid undefined url */
$.post( url, { $.post( url, {
action: "set", action: "set",
name: code, name: code,
entity: entity, entity: entity,
token: token token: token,
value: value
}, },
function() { /* handler for success of post */ function() { /* handler for success of post */
console.log("url request success forcereload="+forcereload); console.log("url request success forcereload="+forcereload+" value="+value);
if (value == 0) {
$("#set_" + code).show();
$("#del_" + code).hide();
} else {
$("#set_" + code).hide(); $("#set_" + code).hide();
$("#del_" + code).show(); $("#del_" + code).show();
}
$.each(input, function(type, data) { $.each(input, function(type, data) {
// Enable another element // Enable another element
if (type == "disabled" && strict != 1) { if (type == "disabled" && strict != 1) {
@ -610,7 +617,7 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke
if (forcereload) { if (forcereload) {
location.reload(); location.reload();
} }
}).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */ }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */
} }
/* /*
@ -681,7 +688,7 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke
if (forcereload) { if (forcereload) {
location.reload(); location.reload();
} }
}).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */ }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */
} }
/* /*
@ -716,7 +723,7 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
text : yesButton, text : yesButton,
click : function() { click : function() {
if (action == "set") { if (action == "set") {
setConstant(url, code, input, entity, strict, 0, userid, token); setConstant(url, code, input, entity, strict, 0, userid, token, 1);
} else if (action == "del") { } else if (action == "del") {
delConstant(url, code, input, entity, strict, 0, userid, token); delConstant(url, code, input, entity, strict, 0, userid, token);
} }

View File

@ -540,14 +540,15 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
* @param string $code Name of constant * @param string $code Name of constant
* @param array $input Array of complementary actions to do if success ("disabled"|"enabled'|'set'|'del') => CSS element to switch, 'alert' => message to show, ... Example: array('disabled'=>array(0=>'cssid')) * @param array $input Array of complementary actions to do if success ("disabled"|"enabled'|'set'|'del') => CSS element to switch, 'alert' => message to show, ... Example: array('disabled'=>array(0=>'cssid'))
* @param int $entity Entity. Current entity is used if null. * @param int $entity Entity. Current entity is used if null.
* @param int $revertonoff Revert on/off * @param int $revertonoff 1=Revert on/off
* @param int $strict Use only "disabled" with delConstant and "enabled" with setConstant * @param int $strict Use only "disabled" with delConstant and "enabled" with setConstant
* @param int $forcereload Force to reload page if we click/change value (this is supported only when there is no 'alert' option in input) * @param int $forcereload Force to reload page if we click/change value (this is supported only when there is no 'alert' option in input)
* @param string $marginleftonlyshort 1 = Add a short left margin on picto, 2 = Add a larger left margin on picto, 0 = No left margin. Works for fontawesome picto only. * @param string $marginleftonlyshort 1 = Add a short left margin on picto, 2 = Add a larger left margin on picto, 0 = No left margin. Works for fontawesome picto only.
* @param int $forcenoajax 1 = Force to use a ahref link instead of ajax code. * @param int $forcenoajax 1 = Force to use a ahref link instead of ajax code.
* @param int $setzeroinsteadofdel 1 = Set constantto '0' instead of deleting it
* @return string * @return string
*/ */
function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0) function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0, $setzeroinsteadofdel = 0)
{ {
global $conf, $langs, $user; global $conf, $langs, $user;
@ -593,9 +594,13 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof
if (input.alert.del.yesButton) yesButton = input.alert.del.yesButton; if (input.alert.del.yesButton) yesButton = input.alert.del.yesButton;
if (input.alert.del.noButton) noButton = input.alert.del.noButton; if (input.alert.del.noButton) noButton = input.alert.del.noButton;
confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token); confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token);
} else {';
if (empty($setzeroinsteadofdel)) {
$out .=' delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token);';
} else { } else {
delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token); $out .=' setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token, 0);';
} }
$out .= ' }
}); });
}); });
</script>'."\n"; </script>'."\n";

View File

@ -673,10 +673,11 @@ function getGMTEasterDatetime($year)
* @param int $includesaturday Include saturday as non working day (-1=use setup, 0=no, 1=yes) * @param int $includesaturday Include saturday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includesunday Include sunday as non working day (-1=use setup, 0=no, 1=yes) * @param int $includesunday Include sunday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includefriday Include friday as non working day (-1=use setup, 0=no, 1=yes) * @param int $includefriday Include friday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includemonday Include monday as non working day (-1=use setup, 0=no, 1=yes)
* @return int|string Number of non working days or error message string if error * @return int|string Number of non working days or error message string if error
* @see num_between_day(), num_open_day() * @see num_between_day(), num_open_day()
*/ */
function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1) function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
{ {
global $db, $conf, $mysoc; global $db, $conf, $mysoc;
@ -690,6 +691,9 @@ function num_public_holiday($timestampStart, $timestampEnd, $country_code = '',
if (empty($country_code)) { if (empty($country_code)) {
$country_code = $mysoc->country_code; $country_code = $mysoc->country_code;
} }
if ($includemonday < 0) {
$includemonday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY : 0);
}
if ($includefriday < 0) { if ($includefriday < 0) {
$includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 0); $includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 0);
} }

View File

@ -133,3 +133,4 @@ WatermarkOnDraftHolidayCards=Watermarks on draft leave requests
HolidaysToApprove=Holidays to approve HolidaysToApprove=Holidays to approve
NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays
HolidayBalanceMonthlyUpdate=Monthly update of holiday balance HolidayBalanceMonthlyUpdate=Monthly update of holiday balance
XIsAUsualNonWorkingDay=%s is usualy a NON working day