document.php 7.2 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. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. if (isModEnabled('project')) {
  37. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbticketcounter.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array('propal', 'compta', 'other', 'bills', 'companies'));
  42. $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  43. $ref = GETPOST('ref', 'alpha');
  44. $socid = GETPOST('socid', 'int');
  45. $action = GETPOST('action', 'aZ09');
  46. $confirm = GETPOST('confirm', 'alpha');
  47. $Bbticketcounter = new Bbticketcounter();
  48. // Get parameters
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (!$sortorder) {
  60. $sortorder = "ASC";
  61. }
  62. if (!$sortfield) {
  63. $sortfield = "name";
  64. }
  65. $object = new Facture($db);
  66. if ($object->fetch($id, $ref)) {
  67. $object->fetch_thirdparty();
  68. $upload_dir = $conf->facture->dir_output."/".dol_sanitizeFileName($object->ref);
  69. }
  70. $permissiontoadd = $user->rights->facture->creer;
  71. // Security check
  72. if ($user->socid) {
  73. $socid = $user->socid;
  74. }
  75. $result = restrictedArea($user, 'facture', $object->id, '');
  76. $usercancreate = $user->hasRight("facture", "creer");
  77. /*
  78. * Actions
  79. */
  80. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  81. /*
  82. * View
  83. */
  84. $form = new Form($db);
  85. if (empty($object->id)) {
  86. $title = $langs->trans('Documents');
  87. } else {
  88. $title = $object->ref." - ".$langs->trans('Documents');
  89. }
  90. $help_url = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  91. llxHeader('', $title, $help_url);
  92. if (empty($object->id)) {
  93. $langs->load('errors');
  94. echo '<div class="error">'.$langs->trans("ErrorRecordNotFound").'</div>';
  95. llxFooter();
  96. exit;
  97. }
  98. if ($id > 0 || !empty($ref)) {
  99. if ($object->fetch($id, $ref) > 0) {
  100. $object->fetch_thirdparty();
  101. $upload_dir = $conf->facture->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  102. $head = facture_prepare_head($object);
  103. print dol_get_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill');
  104. print '<input type="hidden" id="printedTicketsNumber" name="printedticketsnumber" value="' . $Bbticketcounter->numberOfPrintedTickets . '">';
  105. $totalpaid = $object->getSommePaiement();
  106. // Build file list
  107. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  108. $totalsize = 0;
  109. foreach ($filearray as $key => $file) {
  110. $totalsize += $file['size'];
  111. }
  112. // Invoice content
  113. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  114. $morehtmlref = '<div class="refidno">';
  115. // Ref customer
  116. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  117. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  118. // Thirdparty
  119. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  120. // Project
  121. if (isModEnabled('project')) {
  122. $langs->load("projects");
  123. $morehtmlref .= '<br>';
  124. if (0) {
  125. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  126. if ($action != 'classify') {
  127. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  128. }
  129. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  130. } else {
  131. if (!empty($object->fk_project)) {
  132. $proj = new Project($db);
  133. $proj->fetch($object->fk_project);
  134. $morehtmlref .= $proj->getNomUrl(1);
  135. if ($proj->title) {
  136. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  137. }
  138. }
  139. }
  140. }
  141. $morehtmlref .= '</div>';
  142. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  143. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
  144. print '<div class="fichecenter">';
  145. print '<div class="underbanner clearboth"></div>';
  146. print '<table class="border tableforfield centpercent">';
  147. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  148. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  149. print "</table>\n";
  150. print "</div>\n";
  151. print dol_get_fiche_end();
  152. $modulepart = 'facture';
  153. $permissiontoadd = $user->rights->facture->creer;
  154. $permtoedit = $user->rights->facture->creer;
  155. $param = '&id='.$object->id;
  156. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  157. } else {
  158. dol_print_error($db);
  159. }
  160. } else {
  161. print $langs->trans("ErrorUnknown");
  162. }
  163. // End of page
  164. llxFooter();
  165. $db->close();
  166. ?>
  167. <link rel="stylesheet" type="text/css" href="/custom/bbus/views/bbus.css">
  168. <script src="/custom/bbus/js/bbus.js"></script>;