document.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2017 Frédéric France <frederic.france@netlogic.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/facture/document.php
  25. * \ingroup facture
  26. * \brief Page for attached files on invoices
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. if (!empty($conf->projet->enabled)) {
  36. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. }
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('propal', 'compta', 'other', 'bills', 'companies'));
  40. $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  41. $ref = GETPOST('ref', 'alpha');
  42. $socid = GETPOST('socid', 'int');
  43. $action = GETPOST('action', 'aZ09');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. // Get parameters
  46. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST("sortfield", 'alpha');
  48. $sortorder = GETPOST("sortorder", 'alpha');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page == -1) {
  51. $page = 0;
  52. } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!$sortorder) {
  57. $sortorder = "ASC";
  58. }
  59. if (!$sortfield) {
  60. $sortfield = "name";
  61. }
  62. $object = new Facture($db);
  63. if ($object->fetch($id, $ref)) {
  64. $object->fetch_thirdparty();
  65. $upload_dir = $conf->facture->dir_output."/".dol_sanitizeFileName($object->ref);
  66. }
  67. $permissiontoadd = $user->rights->facture->creer;
  68. // Security check
  69. if ($user->socid) {
  70. $socid = $user->socid;
  71. }
  72. $result = restrictedArea($user, 'facture', $object->id, '');
  73. /*
  74. * Actions
  75. */
  76. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  77. /*
  78. * View
  79. */
  80. if (empty($object->id)) {
  81. llxHeader();
  82. $head = facture_prepare_head($object);
  83. $langs->load('errors');
  84. echo dol_get_fiche_head($head, 'documents', $langs->trans("InvoiceCustomer"), -1, 'bill'),
  85. '<div class="error">' . $langs->trans("ErrorRecordNotFound") . '</div>';
  86. llxFooter();
  87. exit;
  88. }
  89. $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Documents');
  90. $help_url = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  91. llxHeader('', $title, $help_url);
  92. $form = new Form($db);
  93. if ($id > 0 || !empty($ref)) {
  94. if ($object->fetch($id, $ref) > 0) {
  95. $object->fetch_thirdparty();
  96. $upload_dir = $conf->facture->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  97. $head = facture_prepare_head($object);
  98. print dol_get_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill');
  99. $totalpaye = $object->getSommePaiement();
  100. // Build file list
  101. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  102. $totalsize = 0;
  103. foreach ($filearray as $key => $file) {
  104. $totalsize += $file['size'];
  105. }
  106. // Invoice content
  107. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  108. $morehtmlref = '<div class="refidno">';
  109. // Ref customer
  110. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  111. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  112. // Thirdparty
  113. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
  114. // Project
  115. if (!empty($conf->projet->enabled)) {
  116. $langs->load("projects");
  117. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  118. if ($user->rights->facture->creer) {
  119. if ($action != 'classify') {
  120. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  121. $morehtmlref .= ' : ';
  122. }
  123. if ($action == 'classify') {
  124. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  125. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  126. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  127. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  128. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  129. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  130. $morehtmlref .= '</form>';
  131. } else {
  132. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  133. }
  134. } else {
  135. if (!empty($object->fk_project)) {
  136. $proj = new Project($db);
  137. $proj->fetch($object->fk_project);
  138. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  139. $morehtmlref .= $proj->ref;
  140. $morehtmlref .= '</a>';
  141. } else {
  142. $morehtmlref .= '';
  143. }
  144. }
  145. }
  146. $morehtmlref .= '</div>';
  147. $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  148. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
  149. print '<div class="fichecenter">';
  150. print '<div class="underbanner clearboth"></div>';
  151. print '<table class="border tableforfield centpercent">';
  152. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  153. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  154. print "</table>\n";
  155. print "</div>\n";
  156. print dol_get_fiche_end();
  157. $modulepart = 'facture';
  158. $permissiontoadd = $user->rights->facture->creer;
  159. $permtoedit = $user->rights->facture->creer;
  160. $param = '&id='.$object->id;
  161. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  162. } else {
  163. dol_print_error($db);
  164. }
  165. } else {
  166. print $langs->trans("ErrorUnknown");
  167. }
  168. // End of page
  169. llxFooter();
  170. $db->close();