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
27/**
28 *       \file       htdocs/salaries/document.php
29 *       \ingroup    salaries
30 *       \brief      Page of linked files onto salaries
31 */
32
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
41
42$id = GETPOST('id', 'int');
43$ref = GETPOST('ref', 'alpha');
44$action = GETPOST('action', 'aZ09');
45$confirm = GETPOST('confirm', 'alpha');
46
47// Get parameters
48$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
49$sortfield = GETPOST('sortfield', 'aZ09comma');
50$sortorder = GETPOST('sortorder', 'aZ09comma');
51$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52if (empty($page) || $page == -1) {
53	$page = 0;
54}     // If $page is not defined, or '' or -1
55$offset = $limit * $page;
56$pageprev = $page - 1;
57$pagenext = $page + 1;
58if (!$sortorder) {
59	$sortorder = "ASC";
60}
61if (!$sortfield) {
62	$sortfield = "name";
63}
64
65$object = new Salary($db);
66if ($id > 0 || !empty($ref)) {
67	$object->fetch($id, $ref);
68}
69
70$upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id);
71$modulepart = 'salaries';
72
73// Security check
74$socid = GETPOSTINT('socid');
75if ($user->socid) {
76	$socid = $user->socid;
77}
78restrictedArea($user, 'salaries', $object->id, 'salary', '');
79
80
81/*
82 * Actions
83 */
84
85include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
86
87
88/*
89 * View
90 */
91
92$form = new Form($db);
93
94$title = $langs->trans('Salary')." - ".$langs->trans('Documents');
95$help_url = "";
96llxHeader("", $title, $help_url);
97
98if ($object->id) {
99	$object->fetch_thirdparty();
100
101	$head = salaries_prepare_head($object);
102
103	print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
104
105	// Build file list
106	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
107	$totalsize = 0;
108	foreach ($filearray as $key => $file) {
109		$totalsize += $file['size'];
110	}
111
112	$linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
113
114	$morehtmlref = '<div class="refidno">';
115
116	$userstatic = new User($db);
117	$userstatic->fetch($object->fk_user);
118
119	$morehtmlref .= $langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
120	$morehtmlref .= '</div>';
121
122	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
123
124	print '<div class="fichecenter">';
125	print '<div class="underbanner clearboth"></div>';
126
127	print '<table class="border tableforfield centpercent">';
128
129	print "<tr>";
130	print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
131	print dol_print_date($object->datesp, 'day');
132	print '</td></tr>';
133
134	print "<tr>";
135	print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
136	print dol_print_date($object->dateep, 'day');
137	print '</td></tr>';
138
139	print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</td></tr>';
140
141	print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
142
143	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
144
145	print '</table>';
146
147	print '</div>';
148
149	print dol_get_fiche_end();
150
151	$modulepart = 'salaries';
152	$permissiontoadd = $user->rights->salaries->write;
153	$param = '&id='.$object->id;
154	include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
155} else {
156	print $langs->trans("ErrorUnknown");
157}
158
159// End of page
160llxFooter();
161$db->close();
162