Skip to content

Commit

Permalink
[Session] fix: change automatic ref to yymm-xxxx
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Aug 16, 2022
1 parent b2772b3 commit 8b2462e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
19 changes: 13 additions & 6 deletions core/modules/dolimeet/mod_audit_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function info()
*/
public function getExample()
{
return $this->prefix."1";
return $this->prefix."2208-0001";
}

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getNextValue($object) {
$posindice = strlen($this->prefix) + 1;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql .= " FROM ".MAIN_DB_PREFIX."dolimeet_session";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."%'";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
if ($object->ismultientitymanaged == 1) {
$sql .= " AND entity = ".$conf->entity;
}
Expand All @@ -137,10 +137,17 @@ public function getNextValue($object) {
return -1;
}

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
else $num = sprintf("%s", $max + 1);
$date = empty($object->date_creation) ?dol_now() : $object->date_creation;

dol_syslog("mod_audit_standard::getNextValue return ".$this->prefix.$num);
return $this->prefix.$num;
$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
} else {
$num = sprintf("%04s", $max + 1);
}

dol_syslog("mod_audit_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}
}
19 changes: 13 additions & 6 deletions core/modules/dolimeet/mod_meeting_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function info()
*/
public function getExample()
{
return $this->prefix."1";
return $this->prefix."2208-0001";
}

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getNextValue($object) {
$posindice = strlen($this->prefix) + 1;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql .= " FROM ".MAIN_DB_PREFIX."dolimeet_session";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."%'";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
if ($object->ismultientitymanaged == 1) {
$sql .= " AND entity = ".$conf->entity;
}
Expand All @@ -137,10 +137,17 @@ public function getNextValue($object) {
return -1;
}

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
else $num = sprintf("%s", $max + 1);
$date = empty($object->date_creation) ?dol_now() : $object->date_creation;

dol_syslog("mod_meeting_standard::getNextValue return ".$this->prefix.$num);
return $this->prefix.$num;
$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
} else {
$num = sprintf("%04s", $max + 1);
}

dol_syslog("mod_meeting_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}
}
19 changes: 13 additions & 6 deletions core/modules/dolimeet/mod_trainingsession_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function info()
*/
public function getExample()
{
return $this->prefix."1";
return $this->prefix."2208-0001";
}

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getNextValue($object) {
$posindice = strlen($this->prefix) + 1;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql .= " FROM ".MAIN_DB_PREFIX."dolimeet_session";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."%'";
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
if ($object->ismultientitymanaged == 1) {
$sql .= " AND entity = ".$conf->entity;
}
Expand All @@ -137,10 +137,17 @@ public function getNextValue($object) {
return -1;
}

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
else $num = sprintf("%s", $max + 1);
$date = empty($object->date_creation) ?dol_now() : $object->date_creation;

dol_syslog("mod_trainingsession_standard::getNextValue return ".$this->prefix.$num);
return $this->prefix.$num;
$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
} else {
$num = sprintf("%04s", $max + 1);
}

dol_syslog("mod_trainingsession_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}
}

0 comments on commit 8b2462e

Please sign in to comment.