dolibarr 19.0.3
document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
7 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
9 * Copyright (C) 2015-2023 Alexandre Spangaro <aspangaro@easya.solutions>
10 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
39if (isModEnabled('project')) {
40 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
42}
43
44// Load translation files required by the page
45$langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
46
47$id = GETPOST('id', 'int');
48$ref = GETPOST('ref', 'alpha');
49$action = GETPOST('action', 'aZ09');
50$confirm = GETPOST('confirm', 'alpha');
51
52$label = GETPOST('label', 'alphanohtml');
53$projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
54
55// Get parameters
56$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$sortorder = GETPOST('sortorder', 'aZ09comma');
59$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60if (empty($page) || $page == -1) {
61 $page = 0;
62} // If $page is not defined, or '' or -1
63$offset = $limit * $page;
64$pageprev = $page - 1;
65$pagenext = $page + 1;
66if (!$sortorder) {
67 $sortorder = "ASC";
68}
69if (!$sortfield) {
70 $sortfield = "name";
71}
72
73$object = new Salary($db);
74$extrafields = new ExtraFields($db);
75
76$childids = $user->getAllChildIds(1);
77
78// fetch optionals attributes and labels
79$extrafields->fetch_name_optionals_label($object->table_element);
80
81// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82$hookmanager->initHooks(array('salarydoc', 'globalcard'));
83
84if ($id > 0 || !empty($ref)) {
85 $object->fetch($id, $ref);
86
87 // Check current user can read this salary
88 $canread = 0;
89 if ($user->hasRight('salaries', 'readall')) {
90 $canread = 1;
91 }
92 if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
93 $canread = 1;
94 }
95
96 if (!$canread) {
98 }
99}
100
101$upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id);
102$modulepart = 'salaries';
103
104// Security check
105$socid = GETPOSTINT('socid');
106if ($user->socid) {
107 $socid = $user->socid;
108}
109restrictedArea($user, 'salaries', $object->id, 'salary', '');
110
111$permissiontoread = $user->hasRight('salaries', 'read');
112$permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
113$permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
114
115/*
116 * Actions
117 */
118
119include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
120
121// Link to a project
122if ($action == 'classin' && $permissiontoadd) {
123 $object->fetch($id);
124 $object->setProject($projectid);
125}
126
127// set label
128if ($action == 'setlabel' && $permissiontoadd) {
129 $object->fetch($id);
130 $object->label = $label;
131 $object->update($user);
132}
133
134
135/*
136 * View
137 */
138
139$form = new Form($db);
140if (isModEnabled('project')) {
141 $formproject = new FormProjets($db);
142}
143
144$title = $langs->trans('Salary')." - ".$langs->trans('Documents');
145$help_url = "";
146llxHeader("", $title, $help_url);
147
148if ($object->id) {
149 $object->fetch_thirdparty();
150
151 $head = salaries_prepare_head($object);
152
153 print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
154
155 // Build file list
156 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
157 $totalsize = 0;
158 foreach ($filearray as $key => $file) {
159 $totalsize += $file['size'];
160 }
161
162 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
163
164 $morehtmlref = '<div class="refidno">';
165
166 $userstatic = new User($db);
167 $userstatic->fetch($object->fk_user);
168
169 // Label
170 if ($action != 'editlabel') {
171 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
172 $morehtmlref .= $object->label;
173 } else {
174 $morehtmlref .= $langs->trans('Label').' :&nbsp;';
175 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
176 $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
177 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
178 $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
179 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
180 $morehtmlref .= '</form>';
181 }
182
183 $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
184
185 $usercancreate = $permissiontoadd;
186
187 // Project
188 if (isModEnabled('project')) {
189 $langs->load("projects");
190 $morehtmlref .= '<br>';
191 if ($usercancreate) {
192 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
193 if ($action != 'classify') {
194 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
195 }
196 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
197 } else {
198 if (!empty($object->fk_project)) {
199 $proj = new Project($db);
200 $proj->fetch($object->fk_project);
201 $morehtmlref .= $proj->getNomUrl(1);
202 if ($proj->title) {
203 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
204 }
205 }
206 }
207 }
208
209 $morehtmlref .= '</div>';
210
211 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
212
213 print '<div class="fichecenter">';
214 print '<div class="underbanner clearboth"></div>';
215
216 print '<table class="border tableforfield centpercent">';
217
218 print "<tr>";
219 print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
220 print dol_print_date($object->datesp, 'day');
221 print '</td></tr>';
222
223 print "<tr>";
224 print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
225 print dol_print_date($object->dateep, 'day');
226 print '</td></tr>';
227
228 print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
229
230 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
231
232 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
233
234 print '</table>';
235
236 print '</div>';
237
238 print dol_get_fiche_end();
239
240 $modulepart = 'salaries';
241 $permissiontoadd = $permissiontoadd;
242 $param = '&id='.$object->id;
243 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
244} else {
245 print $langs->trans("ErrorUnknown");
246}
247
248// End of page
249llxFooter();
250$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage projects.
Class to manage salary payments.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.