dolibarr  17.0.4
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-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
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
34 require '../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
39 if (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');
60 if (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;
66 if (!$sortorder) {
67  $sortorder = "ASC";
68 }
69 if (!$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 
84 if ($id > 0 || !empty($ref)) {
85  $object->fetch($id, $ref);
86 
87  // Check current user can read this salary
88  $canread = 0;
89  if (!empty($user->rights->salaries->readall)) {
90  $canread = 1;
91  }
92  if (!empty($user->rights->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');
106 if ($user->socid) {
107  $socid = $user->socid;
108 }
109 restrictedArea($user, 'salaries', $object->id, 'salary', '');
110 
111 $permissiontoread = $user->rights->salaries->read;
112 $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
113 $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
114 
115 
116 /*
117  * Actions
118  */
119 
120 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
121 
122 // Link to a project
123 if ($action == 'classin' && $user->rights->banque->modifier) {
124  $object->fetch($id);
125  $object->setProject($projectid);
126 }
127 
128 // set label
129 if ($action == 'setlabel' && $user->rights->salaries->write) {
130  $object->fetch($id);
131  $object->label = $label;
132  $object->update($user);
133 }
134 
135 
136 /*
137  * View
138  */
139 
140 $form = new Form($db);
141 if (isModEnabled('project')) $formproject = new FormProjets($db);
142 
143 $title = $langs->trans('Salary')." - ".$langs->trans('Documents');
144 $help_url = "";
145 llxHeader("", $title, $help_url);
146 
147 if ($object->id) {
148  $object->fetch_thirdparty();
149 
150  $head = salaries_prepare_head($object);
151 
152  print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
153 
154  // Build file list
155  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
156  $totalsize = 0;
157  foreach ($filearray as $key => $file) {
158  $totalsize += $file['size'];
159  }
160 
161  $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
162 
163  $morehtmlref = '<div class="refidno">';
164 
165  $userstatic = new User($db);
166  $userstatic->fetch($object->fk_user);
167 
168  // Label
169  if ($action != 'editlabel') {
170  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
171  $morehtmlref .= $object->label;
172  } else {
173  $morehtmlref .= $langs->trans('Label').' :&nbsp;';
174  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
175  $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
176  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
177  $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
178  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
179  $morehtmlref .= '</form>';
180  }
181 
182  $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
183 
184  $usercancreate = $permissiontoadd;
185 
186  // Project
187  if (isModEnabled('project')) {
188  $langs->load("projects");
189  $morehtmlref .= '<br>';
190  if ($usercancreate) {
191  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
192  if ($action != 'classify') {
193  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
194  }
195  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
196  } else {
197  if (!empty($object->fk_project)) {
198  $proj = new Project($db);
199  $proj->fetch($object->fk_project);
200  $morehtmlref .= $proj->getNomUrl(1);
201  if ($proj->title) {
202  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
203  }
204  }
205  }
206  }
207 
208  $morehtmlref .= '</div>';
209 
210  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
211 
212  print '<div class="fichecenter">';
213  print '<div class="underbanner clearboth"></div>';
214 
215  print '<table class="border tableforfield centpercent">';
216 
217  print "<tr>";
218  print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
219  print dol_print_date($object->datesp, 'day');
220  print '</td></tr>';
221 
222  print "<tr>";
223  print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
224  print dol_print_date($object->dateep, 'day');
225  print '</td></tr>';
226 
227  print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
228 
229  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
230 
231  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
232 
233  print '</table>';
234 
235  print '</div>';
236 
237  print dol_get_fiche_end();
238 
239  $modulepart = 'salaries';
240  $permissiontoadd = $user->rights->salaries->write;
241  $param = '&id='.$object->id;
242  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
243 } else {
244  print $langs->trans("ErrorUnknown");
245 }
246 
247 // End of page
248 llxFooter();
249 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
llxFooter()
Footer empty.
Definition: document.php:89
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:61
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
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.