';
- 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