From 30e04714513f99c9f31a23078fa2f11558794d30 Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Thu, 10 Jun 2021 23:04:56 +0200
Subject: [PATCH 1/8] NEW: leave requests: add field into type dictionary to
block request if balance is negative
---
htdocs/admin/dict.php | 20 +++++++++++++++----
htdocs/holiday/class/holiday.class.php | 11 ++++++++++
.../install/mysql/migration/13.0.0-14.0.0.sql | 2 +-
.../mysql/tables/llx_c_holiday_types.sql | 1 +
htdocs/langs/en_US/holiday.lang | 2 ++
5 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index b8bf1a5998a..2d4c651255f 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -223,7 +223,7 @@ $tabsql[24] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFI
$tabsql[25] = "SELECT rowid as rowid, code, label, active, module FROM ".MAIN_DB_PREFIX."c_type_container as t WHERE t.entity IN (".getEntity('c_type_container').")";
//$tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
$tabsql[27] = "SELECT id as rowid, code, libelle, picto, active FROM ".MAIN_DB_PREFIX."c_stcomm";
-$tabsql[28] = "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
+$tabsql[28] = "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.block_if_negative, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
$tabsql[29] = "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status";
$tabsql[30] = "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards";
//$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s";
@@ -315,7 +315,7 @@ $tabfield[24] = "code,label";
$tabfield[25] = "code,label";
//$tabfield[26]= "code,label,short_label";
$tabfield[27] = "code,libelle,picto";
-$tabfield[28] = "code,label,affect,delay,newbymonth,country_id,country";
+$tabfield[28] = "code,label,affect,delay,newbymonth,country_id,country,block_if_negative";
$tabfield[29] = "code,label,percent,position";
$tabfield[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
//$tabfield[31]= "pcg_version,label";
@@ -361,7 +361,7 @@ $tabfieldvalue[24] = "code,label";
$tabfieldvalue[25] = "code,label";
//$tabfieldvalue[26]= "code,label,short_label";
$tabfieldvalue[27] = "code,libelle,picto";
-$tabfieldvalue[28] = "code,label,affect,delay,newbymonth,country";
+$tabfieldvalue[28] = "code,label,affect,delay,newbymonth,country,block_if_negative";
$tabfieldvalue[29] = "code,label,percent,position";
$tabfieldvalue[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
//$tabfieldvalue[31]= "pcg_version,label";
@@ -407,7 +407,7 @@ $tabfieldinsert[24] = "code,label";
$tabfieldinsert[25] = "code,label";
//$tabfieldinsert[26]= "code,label,short_label";
$tabfieldinsert[27] = "code,libelle,picto";
-$tabfieldinsert[28] = "code,label,affect,delay,newbymonth,fk_country";
+$tabfieldinsert[28] = "code,label,affect,delay,newbymonth,fk_country,block_if_negative";
$tabfieldinsert[29] = "code,label,percent,position";
$tabfieldinsert[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
//$tabfieldinsert[31]= "pcg_version,label";
@@ -1413,6 +1413,9 @@ if ($id) {
if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
$valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center';
}
+ if ($value == 'block_if_negative') {
+ $valuetoshow = $langs->trans('BlockHolidayIfNegative');
+ }
if ($id == 2) { // Special case for state page
if ($value == 'region_id') {
@@ -1758,6 +1761,9 @@ if ($id) {
if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
$valuetoshow = $langs->trans('TicketGroupIsPublic'); $cssprefix = 'center ';
}
+ if ($value == 'block_if_negative') {
+ $valuetoshow = $langs->trans('BlockHolidayIfNegative');
+ }
if ($value == 'region_id' || $value == 'country_id') {
$showfield = 0;
@@ -1984,6 +1990,8 @@ if ($id) {
} elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_productbatch_qcstatus') {
$langs->load("productbatch");
$valuetoshow = $langs->trans($obj->{$value});
+ } elseif ($value == 'block_if_negative') {
+ $valuetoshow = yn($obj->{$value});
}
$class .= ($class ? ' ' : '').'tddict';
if ($value == 'note' && $id == 10) {
@@ -2366,6 +2374,10 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
print '
';
print $form->selectExpenseRanges($obj->fk_range);
print ' | ';
+ } elseif ($value == 'block_if_negative') {
+ print '';
+ print $form->selectyesno("block_if_negative", (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
+ print ' | ';
} else {
$fieldValue = isset($obj->{$value}) ? $obj->{$value}:'';
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index 7e3585bd5bc..dc992e53285 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -259,6 +259,17 @@ class Holiday extends CommonObject
$this->error = "ErrorBadParameterFkType"; return -1;
}
+ $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+
+ if ($checkBalance > 0) {
+ $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
+
+ if ($balance < 0) {
+ $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
+ return -1;
+ }
+ }
+
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
$sql .= "ref,";
diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
index 741d92a88a1..6cc9bbeafd6 100644
--- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
+++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql
@@ -543,4 +543,4 @@ create table llx_c_partnership_type
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;
-
+ALTER TABLE llx_c_holiday_types ADD COLUMN block_if_negative integer NOT NULL DEFAULT 0 AFTER fk_country;
diff --git a/htdocs/install/mysql/tables/llx_c_holiday_types.sql b/htdocs/install/mysql/tables/llx_c_holiday_types.sql
index 9c09d486bec..612df739d04 100644
--- a/htdocs/install/mysql/tables/llx_c_holiday_types.sql
+++ b/htdocs/install/mysql/tables/llx_c_holiday_types.sql
@@ -24,5 +24,6 @@ CREATE TABLE llx_c_holiday_types (
delay integer NOT NULL, -- Minimum delay to be allowed to make request
newByMonth double(8,5) DEFAULT 0 NOT NULL, -- Amount of new days for each user each month
fk_country integer DEFAULT NULL, -- This type is dedicated to a country
+ block_if_negative integer NOT NULL DEFAULT 0,
active integer DEFAULT 1
) ENGINE=innodb;
diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang
index 2393a02ee50..95e77130564 100644
--- a/htdocs/langs/en_US/holiday.lang
+++ b/htdocs/langs/en_US/holiday.lang
@@ -132,3 +132,5 @@ FreeLegalTextOnHolidays=Free text on PDF
WatermarkOnDraftHolidayCards=Watermarks on draft leave requests
HolidaysToApprove=Holidays to approve
NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays
+BlockHolidayIfNegative=Block if balance negative
+LeaveRequestCreationBlockedBecauseBalanceIsNegative=The creation of this leave request is blocked because your balance is negative
From 084abe45474def01903f404227d2bbc71bfc4120 Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Tue, 22 Jun 2021 16:27:43 +0200
Subject: [PATCH 2/8] FIX: holiday: also block if balance is negative at
request update, validation and approval
---
htdocs/holiday/class/holiday.class.php | 33 ++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index dc992e53285..2db0f36115f 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -703,6 +703,17 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
+ $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+
+ if ($checkBalance > 0) {
+ $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
+
+ if ($balance < 0) {
+ $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
+ return -1;
+ }
+ }
+
// Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) {
$num = $this->getNextNumRef(null);
@@ -767,6 +778,17 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
+ $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+
+ if ($checkBalance > 0) {
+ $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
+
+ if ($balance < 0) {
+ $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
+ return -1;
+ }
+ }
+
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
@@ -876,6 +898,17 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
+ $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+
+ if ($checkBalance > 0) {
+ $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
+
+ if ($balance < 0) {
+ $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
+ return -1;
+ }
+ }
+
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
From 78b593c067a8b957ecaaafe9f18606edaa039720 Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Thu, 30 Sep 2021 17:42:59 +0200
Subject: [PATCH 3/8] FIX: leave request block moved to v15
---
htdocs/install/mysql/migration/14.0.0-15.0.0.sql | 3 +++
1 file changed, 3 insertions(+)
diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql
index 912eb7fe0eb..b5c7ec5013b 100644
--- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql
+++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql
@@ -150,3 +150,6 @@ INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2010', '
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2011', 'Ideell förening');
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2012', 'Stiftelse');
+
+ALTER TABLE llx_c_holiday_types ADD COLUMN block_if_negative integer NOT NULL DEFAULT 0 AFTER fk_country;
+
From 7c8fb4a5fb3c917a57025f980c7e103fb8fa6238 Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Thu, 30 Sep 2021 17:48:20 +0200
Subject: [PATCH 4/8] FIX: leave request blocking when balance negative: don't
check when creating, check only when updating not in draft
---
htdocs/holiday/class/holiday.class.php | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index 5c82f0ab4b3..31d850846e2 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -270,17 +270,6 @@ class Holiday extends CommonObject
$this->error = "ErrorBadParameterFkType"; return -1;
}
- $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
-
- if ($checkBalance > 0) {
- $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
-
- if ($balance < 0) {
- $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
- return -1;
- }
- }
-
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
$sql .= "ref,";
@@ -910,7 +899,7 @@ class Holiday extends CommonObject
$checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
- if ($checkBalance > 0) {
+ if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT) {
$balance = $this->getCPforUser($this->fk_user, $this->fk_type);
if ($balance < 0) {
From 901bab2ca2608559d8865800e8768fc24c29fde4 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 20 Oct 2021 14:33:22 +0200
Subject: [PATCH 5/8] Update holiday.class.php
---
htdocs/holiday/class/holiday.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index 31d850846e2..7b64048997e 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -703,7 +703,7 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
- $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+ $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
if ($checkBalance > 0) {
$balance = $this->getCPforUser($this->fk_user, $this->fk_type);
@@ -778,7 +778,7 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
- $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+ $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
if ($checkBalance > 0) {
$balance = $this->getCPforUser($this->fk_user, $this->fk_type);
From b03bad98ae87f1899fa3327732871e0815e5bb66 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 20 Oct 2021 14:42:56 +0200
Subject: [PATCH 6/8] Update dict.php
---
htdocs/admin/dict.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 8853e1f0813..5ce504a1b50 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -1979,7 +1979,7 @@ if ($id) {
}
}
} elseif ($value == 'fk_c_exp_tax_cat') {
- $valuetoshow = getDictvalue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow);
+ $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow);
$valuetoshow = $langs->trans($valuetoshow);
} elseif ($tabname[$id] == MAIN_DB_PREFIX.'c_exp_tax_cat') {
$valuetoshow = $langs->trans($valuetoshow);
From 4bb17745682cbd0739544dd38eba54e5731149ed Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 20 Oct 2021 14:43:47 +0200
Subject: [PATCH 7/8] Update holiday.class.php
---
htdocs/holiday/class/holiday.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index 7b64048997e..79b6b81e680 100644
--- a/htdocs/holiday/class/holiday.class.php
+++ b/htdocs/holiday/class/holiday.class.php
@@ -897,7 +897,7 @@ class Holiday extends CommonObject
global $conf, $langs;
$error = 0;
- $checkBalance = getDictvalue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
+ $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type);
if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT) {
$balance = $this->getCPforUser($this->fk_user, $this->fk_type);
From 69d92adb8a03cfa0f4362d430a710f6330925534 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 20 Oct 2021 14:45:24 +0200
Subject: [PATCH 8/8] Update dict.php
---
htdocs/admin/dict.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 5ce504a1b50..9116d8410fe 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -1979,8 +1979,9 @@ if ($id) {
}
}
} elseif ($value == 'fk_c_exp_tax_cat') {
- $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow);
- $valuetoshow = $langs->trans($valuetoshow);
+ $tmpid = $valuetoshow;
+ $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $tmpid);
+ $valuetoshow = $langs->trans($valuetoshow ? $valuetoshow : $tmpid);
} elseif ($tabname[$id] == MAIN_DB_PREFIX.'c_exp_tax_cat') {
$valuetoshow = $langs->trans($valuetoshow);
} elseif ($value == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_units') {