document.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 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 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/sociales/document.php
  25. * \ingroup tax
  26. * \brief Page with attached files on social contributions
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. if (!empty($conf->projet->enabled)) {
  35. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  37. }
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('other', 'companies', 'compta', 'bills'));
  40. $id = GETPOST('id', 'int');
  41. $action = GETPOST('action', 'aZ09');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. // Get parameters
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. }
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "ASC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "name";
  59. }
  60. $object = new ChargeSociales($db);
  61. if ($id > 0) {
  62. $object->fetch($id);
  63. }
  64. $upload_dir = $conf->tax->dir_output.'/'.dol_sanitizeFileName($object->ref);
  65. $modulepart = 'tax';
  66. // Security check
  67. if ($user->socid) {
  68. $socid = $user->socid;
  69. }
  70. $result = restrictedArea($user, 'tax', $object->id, 'chargesociales', 'charges');
  71. $permissiontoadd = $user->rights->tax->charges->creer; // Used by the include of actions_dellink.inc.php
  72. /*
  73. * Actions
  74. */
  75. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  76. if ($action == 'setlib' && $user->rights->tax->charges->creer) {
  77. $object->fetch($id);
  78. $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY');
  79. if ($result < 0) {
  80. setEventMessages($object->error, $object->errors, 'errors');
  81. }
  82. }
  83. /*
  84. * View
  85. */
  86. $form = new Form($db);
  87. if (!empty($conf->projet->enabled)) {
  88. $formproject = new FormProjets($db);
  89. }
  90. $title = $langs->trans("SocialContribution").' - '.$langs->trans("Documents");
  91. $help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
  92. llxHeader("", $title, $help_url);
  93. if ($object->id) {
  94. $alreadypayed = $object->getSommePaiement();
  95. $head = tax_prepare_head($object);
  96. print dol_get_fiche_head($head, 'documents', $langs->trans("SocialContribution"), -1, 'bill');
  97. $morehtmlref = '<div class="refidno">';
  98. // Label of social contribution
  99. $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
  100. $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
  101. // Project
  102. if (!empty($conf->projet->enabled)) {
  103. $langs->load("projects");
  104. $morehtmlref .= '<br>'.$langs->trans('Project').' : ';
  105. if (!empty($object->fk_project)) {
  106. $proj = new Project($db);
  107. $proj->fetch($object->fk_project);
  108. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  109. if ($proj->title) {
  110. $morehtmlref .= ' - '.$proj->title;
  111. }
  112. } else {
  113. $morehtmlref .= '';
  114. }
  115. }
  116. $morehtmlref .= '</div>';
  117. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  118. $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  119. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  120. print '<div class="fichecenter">';
  121. print '<div class="underbanner clearboth"></div>';
  122. // Build file list
  123. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  124. $totalsize = 0;
  125. foreach ($filearray as $key => $file) {
  126. $totalsize += $file['size'];
  127. }
  128. print '<table class="border tableforfield centpercent">';
  129. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  130. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  131. print '</table>';
  132. print '</div>';
  133. print '<div class="clearboth"></div>';
  134. print dol_get_fiche_end();
  135. $modulepart = 'tax';
  136. $permissiontoadd = $user->rights->tax->charges->creer;
  137. $permtoedit = $user->rights->tax->charges->creer;
  138. $param = '&id='.$object->id;
  139. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  140. } else {
  141. print $langs->trans("ErrorUnknown");
  142. }
  143. // End of page
  144. llxFooter();
  145. $db->close();