dolibarr  18.0.0
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  if (!$canread) {
97  }
98 }
99 
100 $upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id);
101 $modulepart = 'salaries';
102 
103 // Security check
104 $socid = GETPOSTINT('socid');
105 if ($user->socid) {
106  $socid = $user->socid;
107 }
108 restrictedArea($user, 'salaries', $object->id, 'salary', '');
109 
110 $permissiontoread = $user->rights->salaries->read;
111 $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
112 $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
113 
114 
115 /*
116  * Actions
117  */
118 
119 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
120 
121 // Link to a project
122 if ($action == 'classin' && $user->rights->banque->modifier) {
123  $object->fetch($id);
124  $object->setProject($projectid);
125 }
126 
127 // set label
128 if ($action == 'setlabel' && $user->rights->salaries->write) {
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);
140 if (isModEnabled('project')) $formproject = new FormProjets($db);
141 
142 $title = $langs->trans('Salary')." - ".$langs->trans('Documents');
143 $help_url = "";
144 llxHeader("", $title, $help_url);
145 
146 if ($object->id) {
147  $object->fetch_thirdparty();
148 
149  $head = salaries_prepare_head($object);
150 
151  print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
152 
153  // Build file list
154  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
155  $totalsize = 0;
156  foreach ($filearray as $key => $file) {
157  $totalsize += $file['size'];
158  }
159 
160  $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
161 
162  $morehtmlref = '<div class="refidno">';
163 
164  $userstatic = new User($db);
165  $userstatic->fetch($object->fk_user);
166 
167  // Label
168  if ($action != 'editlabel') {
169  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
170  $morehtmlref .= $object->label;
171  } else {
172  $morehtmlref .= $langs->trans('Label').' :&nbsp;';
173  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
174  $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
175  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
176  $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
177  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
178  $morehtmlref .= '</form>';
179  }
180 
181  $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
182 
183  $usercancreate = $permissiontoadd;
184 
185  // Project
186  if (isModEnabled('project')) {
187  $langs->load("projects");
188  $morehtmlref .= '<br>';
189  if ($usercancreate) {
190  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
191  if ($action != 'classify') {
192  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
193  }
194  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
195  } else {
196  if (!empty($object->fk_project)) {
197  $proj = new Project($db);
198  $proj->fetch($object->fk_project);
199  $morehtmlref .= $proj->getNomUrl(1);
200  if ($proj->title) {
201  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
202  }
203  }
204  }
205  }
206 
207  $morehtmlref .= '</div>';
208 
209  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
210 
211  print '<div class="fichecenter">';
212  print '<div class="underbanner clearboth"></div>';
213 
214  print '<table class="border tableforfield centpercent">';
215 
216  print "<tr>";
217  print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
218  print dol_print_date($object->datesp, 'day');
219  print '</td></tr>';
220 
221  print "<tr>";
222  print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
223  print dol_print_date($object->dateep, 'day');
224  print '</td></tr>';
225 
226  print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
227 
228  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
229 
230  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
231 
232  print '</table>';
233 
234  print '</div>';
235 
236  print dol_get_fiche_end();
237 
238  $modulepart = 'salaries';
239  $permissiontoadd = $user->rights->salaries->write;
240  $param = '&id='.$object->id;
241  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
242 } else {
243  print $langs->trans("ErrorUnknown");
244 }
245 
246 // End of page
247 llxFooter();
248 $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:48
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:82
llxFooter()
Footer empty.
Definition: document.php:91
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)
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.