Fix numbering of holidays

This commit is contained in:
Laurent Destailleur 2018-10-25 18:50:53 +02:00
parent 094bcc519f
commit 8b601bd7fd
9 changed files with 123 additions and 83 deletions

View File

@ -297,8 +297,13 @@ foreach ($dirmodels as $reldir)
print '</table><br>'; print '</table><br>';
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
/* /*
* Documents models for Contracts * Documents models for Holidays
*/ */
print load_fiche_titre($langs->trans("TemplatePDFHolidays"),'',''); print load_fiche_titre($langs->trans("TemplatePDFHolidays"),'','');
@ -455,9 +460,9 @@ foreach ($dirmodels as $reldir)
print '</table>'; print '</table>';
print "<br>"; print "<br>";
/* /*
* Other options * Other options
*
*/ */
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
@ -509,6 +514,9 @@ print '</div>';
print '</form>'; print '</form>';
}
dol_fiche_end(); dol_fiche_end();
// End of page // End of page

View File

@ -44,7 +44,7 @@ class mod_holiday_immaculate extends ModelNumRefHolidays
/** /**
* @var string Nom du modele * @var string Nom du modele
* @deprecated * @deprecated
* @see name * @see $name
*/ */
public $nom='Immaculate'; public $nom='Immaculate';

View File

@ -45,7 +45,7 @@ class mod_holiday_madonna extends ModelNumRefHolidays
/** /**
* @var string Nom du modele * @var string Nom du modele
* @deprecated * @deprecated
* @see name * @see $name
*/ */
public $nom='Madonna'; public $nom='Madonna';
@ -117,10 +117,10 @@ class mod_holiday_madonna extends ModelNumRefHolidays
* Return next value * Return next value
* *
* @param Societe $objsoc third party object * @param Societe $objsoc third party object
* @param Object $contract contract object * @param Object $holiday Holiday object
* @return string Value if OK, 0 if KO * @return string Value if OK, 0 if KO
*/ */
function getNextValue($objsoc,$contract) function getNextValue($objsoc, $holiday)
{ {
global $db,$conf; global $db,$conf;
@ -143,7 +143,7 @@ class mod_holiday_madonna extends ModelNumRefHolidays
return -1; return -1;
} }
$date=$contract->date_contrat; $date=$holiday->date_debut;
$yymm = strftime("%y%m",$date); $yymm = strftime("%y%m",$date);
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is

View File

@ -41,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
// Get parameters // Get parameters
$action=GETPOST('action', 'alpha'); $action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int'); $id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha');
$fuserid = (GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id); $fuserid = (GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id);
// Protection if external user // Protection if external user
@ -325,7 +326,7 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights-
} }
} }
// Si envoi de la demande // Action validate (+ send email for approval)
if ($action == 'confirm_send') if ($action == 'confirm_send')
{ {
$object = new Holiday($db); $object = new Holiday($db);
@ -761,7 +762,7 @@ $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->tran
llxHeader('', $langs->trans('CPTitreMenu')); llxHeader('', $langs->trans('CPTitreMenu'));
if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') if ((empty($id) && empty($ref)) || $action == 'add' || $action == 'request' || $action == 'create')
{ {
// Si l'utilisateur n'a pas le droit de faire une demande // Si l'utilisateur n'a pas le droit de faire une demande
if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all)))
@ -998,9 +999,9 @@ else
else else
{ {
// Affichage de la fiche d'une demande de congés payés // Affichage de la fiche d'une demande de congés payés
if ($id > 0) if (($id > 0) || $ref)
{ {
$object->fetch($id); $result = $object->fetch($id, $ref);
$valideur = new User($db); $valideur = new User($db);
$valideur->fetch($object->fk_validator); $valideur->fetch($object->fk_validator);
@ -1064,7 +1065,7 @@ else
$linkback='<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref'); dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
print '<div class="fichecenter">'; print '<div class="fichecenter">';
@ -1260,7 +1261,7 @@ else
} }
// Si envoi en validation // Si envoi en validation
if ($action == 'sendToValidate' && $object->statut == 1) if ($action == 'sendToValidate' && $object->statut == Holiday::STATUS_DRAFT)
{ {
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1);
} }
@ -1291,10 +1292,10 @@ else
} }
if ($action == 'edit' && $object->statut == 1) if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT)
{ {
print '<div align="center">'; print '<div align="center">';
if ($cancreate && $object->statut == 1) if ($cancreate && $object->statut == Holiday::STATUS_DRAFT)
{ {
print '<input type="submit" value="'.$langs->trans("Save").'" class="button">'; print '<input type="submit" value="'.$langs->trans("Save").'" class="button">';
} }

View File

@ -57,7 +57,7 @@ class Holiday extends CommonObject
/** /**
* @deprecated * @deprecated
* @see id * @see $id
*/ */
public $rowid; public $rowid;
@ -154,6 +154,67 @@ class Holiday extends CommonObject
} }
/**
* Returns the reference to the following non used Order depending on the active numbering module
* defined into HOLIDAY_ADDON
*
* @param Societe $objsoc third party object
* @return string Holiday free reference
*/
function getNextNumRef($objsoc)
{
global $langs, $conf;
$langs->load("order");
if (empty($conf->global->HOLIDAY_ADDON))
{
$conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
}
if (! empty($conf->global->HOLIDAY_ADDON))
{
$mybool=false;
$file = $conf->global->HOLIDAY_ADDON.".php";
$classname = $conf->global->HOLIDAY_ADDON;
// Include file with class
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir)
{
$dir = dol_buildpath($reldir."core/modules/holiday/");
// Load file with numbering class (if found)
$mybool|=@include_once $dir.$file;
}
if (! $mybool)
{
dol_print_error('',"Failed to include file ".$file);
return '';
}
$obj = new $classname();
$numref = $obj->getNextValue($objsoc,$this);
if ($numref != "")
{
return $numref;
}
else
{
$this->error=$obj->error;
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
return "";
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_HOLIDAY_ADDON_NotDefined");
return "";
}
}
/** /**
* Update balance of vacations and check table of users for holidays is complete. If not complete. * Update balance of vacations and check table of users for holidays is complete. If not complete.
* *
@ -271,14 +332,16 @@ class Holiday extends CommonObject
* Load object in memory from database * Load object in memory from database
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Ref object
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id) function fetch($id, $ref='')
{ {
global $langs; global $langs;
$sql = "SELECT"; $sql = "SELECT";
$sql.= " cp.rowid,"; $sql.= " cp.rowid,";
$sql.= " cp.ref,";
$sql.= " cp.fk_user,"; $sql.= " cp.fk_user,";
$sql.= " cp.date_create,"; $sql.= " cp.date_create,";
$sql.= " cp.description,"; $sql.= " cp.description,";
@ -300,7 +363,8 @@ class Holiday extends CommonObject
$sql.= " cp.fk_type,"; $sql.= " cp.fk_type,";
$sql.= " cp.entity"; $sql.= " cp.entity";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
$sql.= " WHERE cp.rowid = ".$id; if ($id > 0) $sql.= " WHERE cp.rowid = ".$id;
else $sql.=" WHERE cp.ref = '".$this->db->escape($ref)."'";
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -312,7 +376,7 @@ class Holiday extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->rowid = $obj->rowid; // deprecated $this->rowid = $obj->rowid; // deprecated
$this->ref = $obj->rowid; $this->ref = ($obj->ref?$obj->ref:$obj->rowid);
$this->fk_user = $obj->fk_user; $this->fk_user = $obj->fk_user;
$this->date_create = $this->db->jdate($obj->date_create); $this->date_create = $this->db->jdate($obj->date_create);
$this->description = $obj->description; $this->description = $obj->description;
@ -361,6 +425,7 @@ class Holiday extends CommonObject
$sql = "SELECT"; $sql = "SELECT";
$sql.= " cp.rowid,"; $sql.= " cp.rowid,";
$sql.= " cp.ref,";
$sql.= " cp.fk_user,"; $sql.= " cp.fk_user,";
$sql.= " cp.fk_type,"; $sql.= " cp.fk_type,";
@ -427,7 +492,8 @@ class Holiday extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid; $tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['ref'] = $obj->rowid; $tab_result[$i]['ref'] = ($obj->ref?$obj->ref:$obj->rowid);
$tab_result[$i]['fk_user'] = $obj->fk_user; $tab_result[$i]['fk_user'] = $obj->fk_user;
$tab_result[$i]['fk_type'] = $obj->fk_type; $tab_result[$i]['fk_type'] = $obj->fk_type;
$tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
@ -487,6 +553,7 @@ class Holiday extends CommonObject
$sql = "SELECT"; $sql = "SELECT";
$sql.= " cp.rowid,"; $sql.= " cp.rowid,";
$sql.= " cp.ref,";
$sql.= " cp.fk_user,"; $sql.= " cp.fk_user,";
$sql.= " cp.fk_type,"; $sql.= " cp.fk_type,";
@ -552,7 +619,7 @@ class Holiday extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab_result[$i]['rowid'] = $obj->rowid; $tab_result[$i]['rowid'] = $obj->rowid;
$tab_result[$i]['ref'] = $obj->rowid; $tab_result[$i]['ref'] = ($obj->ref?$obj->ref:$obj->rowid);
$tab_result[$i]['fk_user'] = $obj->fk_user; $tab_result[$i]['fk_user'] = $obj->fk_user;
$tab_result[$i]['fk_type'] = $obj->fk_type; $tab_result[$i]['fk_type'] = $obj->fk_type;
$tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
@ -611,68 +678,25 @@ class Holiday extends CommonObject
global $conf, $langs; global $conf, $langs;
$error=0; $error=0;
// Update request // Define new ref
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id))
{
$num = $this->getNextNumRef(null);
}
else
{
$num = $this->ref;
}
$this->newref = $num;
// Update status
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
$sql.= " description= '".$this->db->escape($this->description)."',";
if(!empty($this->date_debut)) {
$sql.= " date_debut = '".$this->db->idate($this->date_debut)."',";
} else {
$error++;
}
if(!empty($this->date_fin)) {
$sql.= " date_fin = '".$this->db->idate($this->date_fin)."',";
} else {
$error++;
}
$sql.= " halfday = ".$this->halfday.",";
if(!empty($this->statut) && is_numeric($this->statut)) { if(!empty($this->statut) && is_numeric($this->statut)) {
$sql.= " statut = ".$this->statut.","; $sql.= " statut = ".$this->statut.",";
} else { } else {
$error++; $error++;
} }
if(!empty($this->fk_validator)) { $sql.= " ref = '".$num."'";
$sql.= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
} else {
$error++;
}
if(!empty($this->date_valid)) {
$sql.= " date_valid = '".$this->db->idate($this->date_valid)."',";
} else {
$sql.= " date_valid = NULL,";
}
if(!empty($this->fk_user_valid)) {
$sql.= " fk_user_valid = '".$this->db->escape($this->fk_user_valid)."',";
} else {
$sql.= " fk_user_valid = NULL,";
}
if(!empty($this->date_refuse)) {
$sql.= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
} else {
$sql.= " date_refuse = NULL,";
}
if(!empty($this->fk_user_refuse)) {
$sql.= " fk_user_refuse = '".$this->db->escape($this->fk_user_refuse)."',";
} else {
$sql.= " fk_user_refuse = NULL,";
}
if(!empty($this->date_cancel)) {
$sql.= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
} else {
$sql.= " date_cancel = NULL,";
}
if(!empty($this->fk_user_cancel)) {
$sql.= " fk_user_cancel = '".$this->db->escape($this->fk_user_cancel)."',";
} else {
$sql.= " fk_user_cancel = NULL,";
}
if(!empty($this->detail_refuse)) {
$sql.= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
} else {
$sql.= " detail_refuse = NULL";
}
$sql.= " WHERE rowid= ".$this->id; $sql.= " WHERE rowid= ".$this->id;
$this->db->begin(); $this->db->begin();

View File

@ -512,7 +512,7 @@ print '</td>';
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"cp.rowid","",$param,'',$sortfield,$sortorder); print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"cp.ref","",$param,'',$sortfield,$sortorder);
print_liste_field_titre("DateCreateCP",$_SERVER["PHP_SELF"],"cp.date_create","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre("DateCreateCP",$_SERVER["PHP_SELF"],"cp.date_create","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"cp.fk_user","",$param,'',$sortfield,$sortorder); print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"cp.fk_user","",$param,'',$sortfield,$sortorder);
print_liste_field_titre("ValidatorCP",$_SERVER["PHP_SELF"],"cp.fk_validator","",$param,'',$sortfield,$sortorder); print_liste_field_titre("ValidatorCP",$_SERVER["PHP_SELF"],"cp.fk_validator","",$param,'',$sortfield,$sortorder);
@ -546,7 +546,7 @@ elseif (! empty($holiday->holiday) && !empty($mysoc->country_id))
{ {
// Leave request // Leave request
$holidaystatic->id=$infos_CP['rowid']; $holidaystatic->id=$infos_CP['rowid'];
$holidaystatic->ref=$infos_CP['rowid']; $holidaystatic->ref=($infos_CP['ref']?$infos_CP['ref']:$infos_CP['rowid']);
// User // User
$userstatic->id=$infos_CP['fk_user']; $userstatic->id=$infos_CP['fk_user'];

View File

@ -132,3 +132,5 @@ CREATE TABLE llx_takepos_floor_tables(
UPDATE llx_c_payment_term SET decalage = nbjour, nbjour = 0 where decalage IS NULL AND type_cdr = 2; UPDATE llx_c_payment_term SET decalage = nbjour, nbjour = 0 where decalage IS NULL AND type_cdr = 2;
UPDATE llx_holiday SET ref = rowid WHERE ref IS NULL;

View File

@ -32,9 +32,9 @@ date_debut DATE NOT NULL,
date_fin DATE NOT NULL, date_fin DATE NOT NULL,
halfday integer DEFAULT 0, -- 0=start morning and end afternoon, -1=start afternoon end afternoon, 1=start morning and end morning, 2=start afternoon and end morning halfday integer DEFAULT 0, -- 0=start morning and end afternoon, -1=start afternoon end afternoon, 1=start morning and end morning, 2=start afternoon and end morning
statut integer NOT NULL DEFAULT '1', statut integer NOT NULL DEFAULT '1',
fk_validator integer NOT NULL, fk_validator integer NOT NULL, -- who should approve
date_valid DATETIME DEFAULT NULL, date_valid DATETIME DEFAULT NULL, -- date approval
fk_user_valid integer DEFAULT NULL, fk_user_valid integer DEFAULT NULL, -- user approval
date_refuse DATETIME DEFAULT NULL, date_refuse DATETIME DEFAULT NULL,
fk_user_refuse integer DEFAULT NULL, fk_user_refuse integer DEFAULT NULL,
date_cancel DATETIME DEFAULT NULL, date_cancel DATETIME DEFAULT NULL,

View File

@ -122,3 +122,8 @@ HolidaysCanceledBody=Your leave request for %s to %s has been canceled.
FollowedByACounter=1: This type of leave need to be followed by a counter. Counter is incremented manually or automatically and when a leave request is validated, counter is decremented.<br>0: Not followed by a counter. FollowedByACounter=1: This type of leave need to be followed by a counter. Counter is incremented manually or automatically and when a leave request is validated, counter is decremented.<br>0: Not followed by a counter.
NoLeaveWithCounterDefined=There is no leave types defined that need to be followed by a counter NoLeaveWithCounterDefined=There is no leave types defined that need to be followed by a counter
GoIntoDictionaryHolidayTypes=Go into <strong>Home - Setup - Dictionaries - Type of leave</strong> to setup the different types of leaves. GoIntoDictionaryHolidayTypes=Go into <strong>Home - Setup - Dictionaries - Type of leave</strong> to setup the different types of leaves.
HolidaySetup=Setup of module Holiday
HolidaysNumberingModules=Leave requests numbering models
TemplatePDFHolidays=Template for leave requests PDF
FreeLegalTextOnHolidays=Free text on PDF
WatermarkOnDraftHolidayCards=Watermarks on draft leave requests