From cce38a9e6d3e992439e265d4cc4bdc34d72ad18d Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Thu, 28 Jan 2021 16:58:55 +0100 Subject: [PATCH 1/5] NEW : fk_user on social charge --- htdocs/compta/sociales/card.php | 41 ++++++++++++++++++- .../sociales/class/chargesociales.class.php | 9 ++-- htdocs/compta/sociales/list.php | 34 +++++++++++++-- .../mysql/tables/llx_chargesociales.sql | 1 + 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index d7f20622a43..486049159b2 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2016-2018 Frédéric France * Copyright (C) 2017 Alexandre Spangaro + * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,9 +28,11 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; if (!empty($conf->projet->enabled)) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -40,7 +43,7 @@ if (!empty($conf->accounting->enabled)) { } // Load translation files required by the page -$langs->loadLangs(array('compta', 'bills', 'banks')); +$langs->loadLangs(array('compta', 'bills', 'banks', 'hrm')); $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); @@ -51,6 +54,7 @@ $dateech = dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), $dateperiod = dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear')); $label = GETPOST('label', 'alpha'); $actioncode = GETPOST('actioncode'); +$fk_user = GETPOST('userid', 'int'); // Security check $socid = GETPOST('socid', 'int'); @@ -94,6 +98,12 @@ if ($action == 'classin' && $user->rights->tax->charges->creer) $object->setProject(GETPOST('projectid')); } +if($action == 'setfk_user' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $object->fk_user = $fk_user; + $object->update($user); +} + if ($action == 'setlib' && $user->rights->tax->charges->creer) { $object->fetch($id); @@ -173,6 +183,7 @@ if ($action == 'add' && $user->rights->tax->charges->creer) $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = $amount; + $object->fk_user = $fk_user; $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_account = GETPOST('fk_account', 'int'); $object->fk_project = GETPOST('fk_project'); @@ -218,6 +229,7 @@ if ($action == 'update' && !$_POST["cancel"] && $user->rights->tax->charges->cre $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = price2num($amount); + $object->fk_user = $fk_user; $result = $object->update($user); if ($result <= 0) @@ -365,6 +377,12 @@ if ($action == 'create') print ''; print ''; + // Employee + print ''; + print $langs->trans('Employee'); + print ''; + print ''.$form->select_dolusers($fk_user, 'userid', 1).''; + // Project if (!empty($conf->projet->enabled)) { @@ -467,6 +485,26 @@ if ($id > 0) // Ref customer $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1); + + // Employee + if($action != 'editfk_user') { + $morehtmlref .= '
' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); + + if(!empty($object->fk_user)) { + $userstatic = new User($db); + $userstatic->fetch($object->fk_user); + $morehtmlref .= $userstatic->getNomUrl(1); + } + } else { + $morehtmlref .= '
'.$langs->trans('Employee').' : '; + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } + // Project if (!empty($conf->projet->enabled)) { @@ -553,6 +591,7 @@ if ($id > 0) print ''.$langs->trans("AmountTTC").''.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).''; } + // Mode of payment print ''; print ''; // Type print ''; // Ref Project if (!empty($conf->projet->enabled)) print ''; @@ -256,6 +267,7 @@ if ($resql) print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "id", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "cs.libelle", "", $param, 'class="left"', $sortfield, $sortorder); print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "type", "", $param, 'class="left"', $sortfield, $sortorder); + print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'class="left"', $sortfield, $sortorder); if (!empty($conf->projet->enabled)) print_liste_field_titre('ProjectRef', $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "cs.date_ech", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "periode", "", $param, 'align="center"', $sortfield, $sortorder); @@ -265,7 +277,7 @@ if ($resql) print "\n"; $i = 0; - $totalarray = array(); + $totalarray = $TLoadedUsers = array(); while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -294,6 +306,20 @@ if ($resql) print "\n"; if (!$i) $totalarray['nbfield']++; + // Employee + print "\n"; + if (!$i) $totalarray['nbfield']++; + // Project Ref if (!empty($conf->projet->enabled)) { print '
'; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 6d3f4dffa4a..7bee283fd2f 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -133,7 +133,7 @@ class ChargeSociales extends CommonObject { $sql = "SELECT cs.rowid, cs.date_ech"; $sql .= ", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key"; - $sql .= ", cs.fk_account, cs.fk_mode_reglement"; + $sql .= ", cs.fk_account, cs.fk_mode_reglement, cs.fk_user"; $sql .= ", c.libelle"; $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; @@ -164,6 +164,7 @@ class ChargeSociales extends CommonObject $this->mode_reglement = $obj->mode_reglement_libelle; $this->amount = $obj->amount; $this->fk_project = $obj->fk_project; + $this->fk_user = $obj->fk_user; $this->paye = $obj->paye; $this->periode = $this->db->jdate($obj->periode); $this->import_key = $this->import_key; @@ -226,7 +227,7 @@ class ChargeSociales extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, fk_user, date_creation)"; $sql .= " VALUES (".$this->type; $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL'); $sql .= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : "NULL"); @@ -237,6 +238,7 @@ class ChargeSociales extends CommonObject $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 'NULL'); $sql .= ", ".$conf->entity; $sql .= ", ".$user->id; + $sql .= ", ".($this->fk_user > 0 ? $this->db->escape($this->fk_user) : 'NULL'); $sql .= ", '".$this->db->idate($now)."'"; $sql .= ")"; @@ -354,7 +356,8 @@ class ChargeSociales extends CommonObject $sql .= ", date_ech='".$this->db->idate($this->date_ech)."'"; $sql .= ", periode='".$this->db->idate($this->periode)."'"; $sql .= ", amount='".price2num($this->amount, 'MT')."'"; - $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "NULL"); + $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "NULL"); + $sql .= ", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) : "NULL"); $sql .= ", fk_user_modif=".$user->id; $sql .= " WHERE rowid=".$this->id; diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php index 8ccd8aa35aa..50ac12e8517 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2016 Frédéric France * Copyright (C) 2020 Pierre Ardoin + * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; if (!empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; // Load translation files required by the page -$langs->loadLangs(array('compta', 'banks', 'bills')); +$langs->loadLangs(array('compta', 'banks', 'bills', 'hrm')); $action = GETPOST('action', 'alpha'); $massaction = GETPOST('massaction', 'alpha'); @@ -56,6 +57,7 @@ $search_month_lim = GETPOST('search_month_lim', 'int'); $search_year_lim = GETPOST('search_year_lim', 'int'); $search_project_ref = GETPOST('search_project_ref', 'alpha'); $search_project = GETPOST('search_project', 'alpha'); +$search_users = GETPOST('search_users'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); @@ -99,6 +101,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_month_lim = ''; $search_project_ref = ''; $search_project = ''; + $search_users = ''; $toselect = ''; $search_array_options = array(); } @@ -116,7 +119,7 @@ if (!empty($conf->projet->enabled)) $projectstatic = new Project($db); llxHeader('', $langs->trans("SocialContributions")); -$sql = "SELECT cs.rowid as id, cs.fk_type as type, "; +$sql = "SELECT cs.rowid as id, cs.fk_type as type, cs.fk_user, "; $sql .= " cs.amount, cs.date_ech, cs.libelle as label, cs.paye, cs.periode,"; if (!empty($conf->projet->enabled)) $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,"; $sql .= " c.libelle as type_label,"; @@ -125,12 +128,14 @@ $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql .= " ".MAIN_DB_PREFIX."chargesociales as cs"; if (!empty($conf->projet->enabled)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cs.fk_projet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON (cs.fk_user = u.rowid)"; $sql .= " WHERE cs.fk_type = c.id"; $sql .= " AND cs.entity = ".$conf->entity; // Search criteria if ($search_ref) $sql .= " AND cs.rowid=".$db->escape($search_ref); if ($search_label) $sql .= natural_search("cs.libelle", $search_label); if (!empty($conf->projet->enabled)) if ($search_project_ref != '') $sql .= natural_search("p.ref", $search_project_ref); +if (!empty($search_users)) $sql .= ' AND cs.fk_user IN('.implode(', ', $search_users).')'; if ($search_amount) $sql .= natural_search("cs.amount", $search_amount, 1); if ($search_status != '' && $search_status >= 0) $sql .= " AND cs.paye = ".$db->escape($search_status); $sql .= dolSqlDateFilter("cs.periode", $search_day_lim, $search_month_lim, $search_year_lim); @@ -177,6 +182,9 @@ if ($resql) if ($search_project_ref >= 0) $param .= "&search_project_ref=".urlencode($search_project_ref); if ($search_amount) $param .= '&search_amount='.urlencode($search_amount); if ($search_typeid) $param .= '&search_typeid='.urlencode($search_typeid); + if ($search_users) { + foreach ($search_users as $id_user) $param .= '&search_users[]='.urlencode($id_user); + } if ($search_status != '' && $search_status != '-1') $param .= '&search_status='.urlencode($search_status); if ($year) $param .= '&year='.urlencode($year); @@ -224,7 +232,10 @@ if ($resql) print ''; - $formsocialcontrib->select_type_socialcontrib($search_typeid, 'search_typeid', 1, 0, 0, 'maxwidth100onsmartphone'); + $formsocialcontrib->select_type_socialcontrib($search_typeid, 'search_typeid', 1, 0, 0, 'maxwidth100onsmartphone'); + // Employee + print ''; + print $form->select_dolusers($search_users, 'search_users', 1, null, 0, '', '', '0', '0', 0, '', 0, '', '', 0, 0, true); print '
".$obj->type_label.""; + if(!empty($obj->fk_user)) { + if(!empty($TLoadedUsers[$obj->fk_user])) $ustatic = $TLoadedUsers[$obj->fk_user]; + else { + $ustatic = new User($db); + $ustatic->fetch($obj->fk_user); + $TLoadedUsers[$obj->fk_user] = $ustatic; + } + print $ustatic->getNomUrl(-1); + } + print "'; diff --git a/htdocs/install/mysql/tables/llx_chargesociales.sql b/htdocs/install/mysql/tables/llx_chargesociales.sql index 57434c93d98..720fd45a62d 100644 --- a/htdocs/install/mysql/tables/llx_chargesociales.sql +++ b/htdocs/install/mysql/tables/llx_chargesociales.sql @@ -28,6 +28,7 @@ create table llx_chargesociales tms timestamp, date_creation datetime, -- date de creation date_valid datetime, -- date de validation + fk_user integer DEFAULT NULL, -- utilisateur concerné fk_user_author integer, -- user making creation fk_user_modif integer, -- user making last change fk_user_valid integer, -- user validating From d3647557920af982753d03842b8a36b0dc86b562 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Thu, 28 Jan 2021 17:20:01 +0100 Subject: [PATCH 2/5] NEW : migration script --- htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 1 + 1 file changed, 1 insertion(+) 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 9e1e6a15866..bfdecd334b7 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 @@ -121,3 +121,4 @@ ALTER TABLE llx_societe ADD INDEX idx_societe_warehouse(fk_warehouse); ALTER TABLE llx_socpeople MODIFY poste varchar(255); +ALTER TABLE llx_chargesociales ADD COLUMN fk_user integer DEFAULT NULL; From 5adcc3361bfd885b769b3d2edb842c75b61e9f44 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Thu, 28 Jan 2021 17:24:47 +0100 Subject: [PATCH 3/5] FIX : credits --- htdocs/install/mysql/tables/llx_chargesociales.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/tables/llx_chargesociales.sql b/htdocs/install/mysql/tables/llx_chargesociales.sql index e6ade132f60..220c85410ce 100644 --- a/htdocs/install/mysql/tables/llx_chargesociales.sql +++ b/htdocs/install/mysql/tables/llx_chargesociales.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2001-2002 Rodolphe Quiedeville -- Copyright (C) 2005-2009 Regis Houssin -- Copyright (C) 2017 Alexandre Spangaro +-- Copyright (C) 2021 Gauthier VERDOL -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by From b4d0668ceafe2ea19660cf7f92c28f29f4fd3e1e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 28 Jan 2021 16:27:55 +0000 Subject: [PATCH 4/5] Fixing style errors. --- htdocs/compta/sociales/card.php | 6 +++--- htdocs/compta/sociales/list.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 1775aa3efb9..d27155e572f 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -99,7 +99,7 @@ if ($action == 'classin' && $user->rights->tax->charges->creer) $object->setProject(GETPOST('projectid')); } -if($action == 'setfk_user' && $user->rights->tax->charges->creer) { +if ($action == 'setfk_user' && $user->rights->tax->charges->creer) { $object->fetch($id); $object->fk_user = $fk_user; $object->update($user); @@ -463,10 +463,10 @@ if ($id > 0) $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1); // Employee - if($action != 'editfk_user') { + if ($action != 'editfk_user') { $morehtmlref .= '
' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); - if(!empty($object->fk_user)) { + if (!empty($object->fk_user)) { $userstatic = new User($db); $userstatic->fetch($object->fk_user); $morehtmlref .= $userstatic->getNomUrl(1); diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php index 37383b633df..a8a71e3e254 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -418,8 +418,8 @@ while ($i < min($num, $limit)) if (!empty($arrayfields['cs.fk_user']['checked'])) { // Employee print "
"; - if(!empty($obj->fk_user)) { - if(!empty($TLoadedUsers[$obj->fk_user])) $ustatic = $TLoadedUsers[$obj->fk_user]; + if (!empty($obj->fk_user)) { + if (!empty($TLoadedUsers[$obj->fk_user])) $ustatic = $TLoadedUsers[$obj->fk_user]; else { $ustatic = new User($db); $ustatic->fetch($obj->fk_user); From 2915bf89d9c14c0121ca95eaf57a706a2a03c0d7 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Fri, 29 Jan 2021 09:32:00 +0100 Subject: [PATCH 5/5] FIX : stickler feedback on br tag --- htdocs/compta/sociales/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 1775aa3efb9..a900fe73d67 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -464,7 +464,7 @@ if ($id > 0) // Employee if($action != 'editfk_user') { - $morehtmlref .= '
' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); + $morehtmlref .= '
' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1); if(!empty($object->fk_user)) { $userstatic = new User($db);