diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index ccb413ecf6f..cfe938ce974 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 @@ -28,10 +29,13 @@ 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.'/compta/sociales/class/paymentsocialcontribution.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'; -if (!empty($conf->projet->enabled)) { +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'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } @@ -40,7 +44,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 +55,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 +99,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); @@ -163,6 +174,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 = (int) GETPOST('mode_reglement_id', 'int'); $object->fk_account = (int) GETPOST('fk_account', 'int'); $object->fk_project = (int) GETPOST('fk_project', 'int'); @@ -202,6 +214,7 @@ if ($action == 'update' && !$_POST["cancel"] && $user->rights->tax->charges->cre $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = $amount; + $object->fk_user = $fk_user; $result = $object->update($user); if ($result <= 0) { @@ -342,6 +355,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)) { @@ -442,6 +461,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)) { diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index ffb2d04e155..95e4bd1df77 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2016-2020 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 @@ -133,7 +134,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 +165,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; @@ -222,7 +224,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"); @@ -233,6 +235,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 .= ")"; @@ -346,6 +349,7 @@ class ChargeSociales extends CommonObject $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_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 746a8480453..a8a71e3e254 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -5,7 +5,8 @@ * Copyright (C) 2016 Frédéric France * Copyright (C) 2020 Pierre Ardoin * Copyright (C) 2020 Tobias Sekan - + * 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 * the Free Software Foundation; either version 3 of the License, or @@ -40,7 +41,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', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); @@ -56,7 +57,8 @@ $search_day_lim = GETPOST('search_day_lim', 'int'); $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_project = GETPOST('search_project', 'alpha'); +$search_users = GETPOST('search_users'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); @@ -91,6 +93,7 @@ $arrayfields = array( 'cs.rowid' =>array('label'=>"Ref", 'checked'=>1, 'position'=>10), 'cs.libelle' =>array('label'=>"Label", 'checked'=>1, 'position'=>20), 'cs.fk_type' =>array('label'=>"Type", 'checked'=>1, 'position'=>30), + 'cs.fk_user' =>array('label'=>"Employee", 'checked'=>1, 'position'=>30), 'p.ref' =>array('label'=>"ProjectRef", 'checked'=>1, 'position'=>40, 'enable'=>(!empty($conf->projet->enabled))), 'cs.date_ech' =>array('label'=>"Date", 'checked'=>1, 'position'=>50), 'cs.periode' =>array('label'=>"PeriodEndDate", 'checked'=>1, 'position'=>60), @@ -128,6 +131,7 @@ if (empty($reshook)) { $search_month_lim = ''; $search_project_ref = ''; $search_project = ''; + $search_users = ''; $search_array_options = array(); } } @@ -144,7 +148,7 @@ if (!empty($conf->projet->enabled)) $projectstatic = new Project($db); llxHeader('', $langs->trans("SocialContributions")); -$sql = "SELECT cs.rowid, cs.fk_type as type, "; +$sql = "SELECT cs.rowid, cs.fk_type as type, cs.fk_user, "; $sql .= " cs.amount, cs.date_ech, cs.libelle, 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,"; @@ -153,12 +157,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); @@ -211,6 +217,9 @@ if ($search_label) $param .= '&search_label='.urlencode($search_label); 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); @@ -289,6 +298,12 @@ if (!empty($arrayfields['cs.fk_type']['checked'])) { print ''; } +if (!empty($arrayfields['cs.fk_user']['checked'])) { + // Employee + print ''; + print $form->select_dolusers($search_users, 'search_users', 1, null, 0, '', '', '0', '0', 0, '', 0, '', '', 0, 0, true); +} + // Filter: Project ref if (!empty($arrayfields['p.ref']['checked'])) { print ''; @@ -343,6 +358,7 @@ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titr if (!empty($arrayfields['cs.rowid']['checked'])) print_liste_field_titre($arrayfields['cs.rowid']['label'], $_SERVER["PHP_SELF"], "cs.rowid", '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cs.libelle']['checked'])) print_liste_field_titre($arrayfields['cs.libelle']['label'], $_SERVER["PHP_SELF"], "cs.libelle", '', $param, 'class="left"', $sortfield, $sortorder); if (!empty($arrayfields['cs.fk_type']['checked'])) print_liste_field_titre($arrayfields['cs.fk_type']['label'], $_SERVER["PHP_SELF"], "cs.fk_type", '', $param, 'class="left"', $sortfield, $sortorder); +if (!empty($arrayfields['cs.fk_user']['checked'])) print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'class="left"', $sortfield, $sortorder); if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cs.date_ech']['checked'])) print_liste_field_titre($arrayfields['cs.date_ech']['label'], $_SERVER["PHP_SELF"], "cs.date_ech", '', $param, 'align="center"', $sortfield, $sortorder); if (!empty($arrayfields['cs.periode']['checked'])) print_liste_field_titre($arrayfields['cs.periode']['label'], $_SERVER["PHP_SELF"], "cs.periode", '', $param, 'align="center"', $sortfield, $sortorder); @@ -358,7 +374,7 @@ print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], '', '', '', '', $ print ''; $i = 0; -$totalarray = array(); + $totalarray = $TLoadedUsers = array(); while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -399,6 +415,22 @@ while ($i < min($num, $limit)) if (!$i) $totalarray['nbfield']++; } + 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]; + else { + $ustatic = new User($db); + $ustatic->fetch($obj->fk_user); + $TLoadedUsers[$obj->fk_user] = $ustatic; + } + print $ustatic->getNomUrl(-1); + } + print "\n"; + if (!$i) $totalarray['nbfield']++; + } + // Project ref if (!empty($arrayfields['p.ref']['checked'])) { print ''; 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; diff --git a/htdocs/install/mysql/tables/llx_chargesociales.sql b/htdocs/install/mysql/tables/llx_chargesociales.sql index db9e82ac779..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 @@ -28,6 +29,7 @@ create table llx_chargesociales tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_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