From 8b601bd7fd93340c8786535fe0c08b8fd4812065 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 Oct 2018 18:50:53 +0200 Subject: [PATCH] Fix numbering of holidays --- htdocs/admin/holiday.php | 12 +- .../holiday/mod_holiday_immaculate.php | 2 +- .../modules/holiday/mod_holiday_madonna.php | 8 +- htdocs/holiday/card.php | 17 +- htdocs/holiday/class/holiday.class.php | 150 ++++++++++-------- htdocs/holiday/list.php | 4 +- .../install/mysql/migration/8.0.0-9.0.0.sql | 2 + htdocs/install/mysql/tables/llx_holiday.sql | 6 +- htdocs/langs/en_US/holiday.lang | 5 + 9 files changed, 123 insertions(+), 83 deletions(-) diff --git a/htdocs/admin/holiday.php b/htdocs/admin/holiday.php index f6306f787c3..c02c9bd480d 100644 --- a/htdocs/admin/holiday.php +++ b/htdocs/admin/holiday.php @@ -297,8 +297,13 @@ foreach ($dirmodels as $reldir) print '
'; + + +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) +{ + /* - * Documents models for Contracts + * Documents models for Holidays */ print load_fiche_titre($langs->trans("TemplatePDFHolidays"),'',''); @@ -455,9 +460,9 @@ foreach ($dirmodels as $reldir) print ''; print "
"; + /* * Other options - * */ print '
'; @@ -509,6 +514,9 @@ print ''; print '
'; +} + + dol_fiche_end(); // End of page diff --git a/htdocs/core/modules/holiday/mod_holiday_immaculate.php b/htdocs/core/modules/holiday/mod_holiday_immaculate.php index b63326ca276..338b553166e 100644 --- a/htdocs/core/modules/holiday/mod_holiday_immaculate.php +++ b/htdocs/core/modules/holiday/mod_holiday_immaculate.php @@ -44,7 +44,7 @@ class mod_holiday_immaculate extends ModelNumRefHolidays /** * @var string Nom du modele * @deprecated - * @see name + * @see $name */ public $nom='Immaculate'; diff --git a/htdocs/core/modules/holiday/mod_holiday_madonna.php b/htdocs/core/modules/holiday/mod_holiday_madonna.php index 98380d9fae5..f53e55be6fd 100644 --- a/htdocs/core/modules/holiday/mod_holiday_madonna.php +++ b/htdocs/core/modules/holiday/mod_holiday_madonna.php @@ -45,7 +45,7 @@ class mod_holiday_madonna extends ModelNumRefHolidays /** * @var string Nom du modele * @deprecated - * @see name + * @see $name */ public $nom='Madonna'; @@ -117,10 +117,10 @@ class mod_holiday_madonna extends ModelNumRefHolidays * Return next value * * @param Societe $objsoc third party object - * @param Object $contract contract object + * @param Object $holiday Holiday object * @return string Value if OK, 0 if KO */ - function getNextValue($objsoc,$contract) + function getNextValue($objsoc, $holiday) { global $db,$conf; @@ -143,7 +143,7 @@ class mod_holiday_madonna extends ModelNumRefHolidays return -1; } - $date=$contract->date_contrat; + $date=$holiday->date_debut; $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 diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 9c89124c577..d170a1c9acc 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -41,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; // Get parameters $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); +$ref=GETPOST('ref', 'alpha'); $fuserid = (GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id); // 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') { $object = new Holiday($db); @@ -761,7 +762,7 @@ $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->tran 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 if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) @@ -998,9 +999,9 @@ else else { // 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->fetch($object->fk_validator); @@ -1064,7 +1065,7 @@ else $linkback=''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref'); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); print '
'; @@ -1260,7 +1261,7 @@ else } // 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); } @@ -1291,10 +1292,10 @@ else } - if ($action == 'edit' && $object->statut == 1) + if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) { print '
'; - if ($cancreate && $object->statut == 1) + if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) { print ''; } diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index bc964ec7fc6..26e11383b9d 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -57,7 +57,7 @@ class Holiday extends CommonObject /** * @deprecated - * @see id + * @see $id */ public $rowid; @@ -77,7 +77,7 @@ class Holiday extends CommonObject public $date_fin=''; // Date end in PHP server TZ public $date_debut_gmt=''; // Date start in GMT public $date_fin_gmt=''; // Date end in GMT - public $halfday=''; // 0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning + public $halfday=''; // 0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning public $statut=''; // 1=draft, 2=validated, 3=approved /** @@ -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. * @@ -271,14 +332,16 @@ class Holiday extends CommonObject * Load object in memory from database * * @param int $id Id object + * @param string $ref Ref object * @return int <0 if KO, >0 if OK */ - function fetch($id) + function fetch($id, $ref='') { global $langs; $sql = "SELECT"; $sql.= " cp.rowid,"; + $sql.= " cp.ref,"; $sql.= " cp.fk_user,"; $sql.= " cp.date_create,"; $sql.= " cp.description,"; @@ -300,7 +363,8 @@ class Holiday extends CommonObject $sql.= " cp.fk_type,"; $sql.= " cp.entity"; $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); $resql=$this->db->query($sql); @@ -312,7 +376,7 @@ class Holiday extends CommonObject $this->id = $obj->rowid; $this->rowid = $obj->rowid; // deprecated - $this->ref = $obj->rowid; + $this->ref = ($obj->ref?$obj->ref:$obj->rowid); $this->fk_user = $obj->fk_user; $this->date_create = $this->db->jdate($obj->date_create); $this->description = $obj->description; @@ -361,6 +425,7 @@ class Holiday extends CommonObject $sql = "SELECT"; $sql.= " cp.rowid,"; + $sql.= " cp.ref,"; $sql.= " cp.fk_user,"; $sql.= " cp.fk_type,"; @@ -427,7 +492,8 @@ class Holiday extends CommonObject $obj = $this->db->fetch_object($resql); $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_type'] = $obj->fk_type; $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); @@ -487,6 +553,7 @@ class Holiday extends CommonObject $sql = "SELECT"; $sql.= " cp.rowid,"; + $sql.= " cp.ref,"; $sql.= " cp.fk_user,"; $sql.= " cp.fk_type,"; @@ -552,7 +619,7 @@ class Holiday extends CommonObject $obj = $this->db->fetch_object($resql); $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_type'] = $obj->fk_type; $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); @@ -611,68 +678,25 @@ class Holiday extends CommonObject global $conf, $langs; $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.= " 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)) { $sql.= " statut = ".$this->statut.","; } else { $error++; } - if(!empty($this->fk_validator)) { - $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.= " ref = '".$num."'"; $sql.= " WHERE rowid= ".$this->id; $this->db->begin(); diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index fcd5cc9d8b0..8d7f8fb666e 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -512,7 +512,7 @@ print ''; print "\n"; print ''; -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("Employee",$_SERVER["PHP_SELF"],"cp.fk_user","",$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 $holidaystatic->id=$infos_CP['rowid']; - $holidaystatic->ref=$infos_CP['rowid']; + $holidaystatic->ref=($infos_CP['ref']?$infos_CP['ref']:$infos_CP['rowid']); // User $userstatic->id=$infos_CP['fk_user']; diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index 9048c681aa1..f98c932943c 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -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_holiday SET ref = rowid WHERE ref IS NULL; diff --git a/htdocs/install/mysql/tables/llx_holiday.sql b/htdocs/install/mysql/tables/llx_holiday.sql index f6994810021..47c68647ffb 100644 --- a/htdocs/install/mysql/tables/llx_holiday.sql +++ b/htdocs/install/mysql/tables/llx_holiday.sql @@ -32,9 +32,9 @@ date_debut 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 statut integer NOT NULL DEFAULT '1', -fk_validator integer NOT NULL, -date_valid DATETIME DEFAULT NULL, -fk_user_valid integer DEFAULT NULL, +fk_validator integer NOT NULL, -- who should approve +date_valid DATETIME DEFAULT NULL, -- date approval +fk_user_valid integer DEFAULT NULL, -- user approval date_refuse DATETIME DEFAULT NULL, fk_user_refuse integer DEFAULT NULL, date_cancel DATETIME DEFAULT NULL, diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 1411ae3ad56..8cf5ec2c1e6 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -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.
0: Not followed by a counter. NoLeaveWithCounterDefined=There is no leave types defined that need to be followed by a counter GoIntoDictionaryHolidayTypes=Go into Home - Setup - Dictionaries - Type of leave 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 \ No newline at end of file