document.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 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@capnetworks.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/facture/document.php
  23. * \ingroup facture
  24. * \brief Page for attached files on invoices
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.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/class/html.formfile.class.php';
  33. $langs->load('propal');
  34. $langs->load('compta');
  35. $langs->load('other');
  36. $langs->load("bills");
  37. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  38. $ref=GETPOST('ref','alpha');
  39. $socid=GETPOST('socid','int');
  40. $action=GETPOST('action','alpha');
  41. $confirm=GETPOST('confirm', 'alpha');
  42. // Security check
  43. if ($user->societe_id)
  44. {
  45. $action='';
  46. $socid = $user->societe_id;
  47. }
  48. $result=restrictedArea($user,'facture',$id,'');
  49. // Get parameters
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page",'int');
  53. if ($page == -1) { $page = 0; }
  54. $offset = $conf->liste_limit * $page;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (! $sortorder) $sortorder="ASC";
  58. if (! $sortfield) $sortfield="name";
  59. $object = new Facture($db);
  60. if ($object->fetch($id))
  61. {
  62. $object->fetch_thirdparty();
  63. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  64. }
  65. /*
  66. * Actions
  67. */
  68. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
  69. /*
  70. * View
  71. */
  72. llxHeader();
  73. $form = new Form($db);
  74. if ($id > 0 || ! empty($ref))
  75. {
  76. if ($object->fetch($id,$ref) > 0)
  77. {
  78. $object->fetch_thirdparty();
  79. $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
  80. $head = facture_prepare_head($object);
  81. dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), 0, 'bill');
  82. // Construit liste des fichiers
  83. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  84. $totalsize=0;
  85. foreach($filearray as $key => $file)
  86. {
  87. $totalsize+=$file['size'];
  88. }
  89. print '<table class="border" width="100%">';
  90. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  91. // Ref
  92. print '<tr><td width="30%">'.$langs->trans('Ref').'</td>';
  93. print '<td colspan="3">';
  94. $morehtmlref='';
  95. $discount=new DiscountAbsolute($db);
  96. $result=$discount->fetch(0,$object->id);
  97. if ($result > 0)
  98. {
  99. $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
  100. }
  101. if ($result < 0)
  102. {
  103. dol_print_error('',$discount->error);
  104. }
  105. print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
  106. print '</td></tr>';
  107. // Ref customer
  108. print '<tr><td width="20%">';
  109. print '<table class="nobordernopadding" width="100%"><tr><td>';
  110. print $langs->trans('RefCustomer');
  111. print '</td>';
  112. print '</tr></table>';
  113. print '</td>';
  114. print '<td colspan="5">';
  115. print $object->ref_client;
  116. print '</td></tr>';
  117. // Company
  118. print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  119. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  120. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  121. print "</table>\n";
  122. print "</div>\n";
  123. $modulepart = 'facture';
  124. $permission = $user->rights->facture->creer;
  125. $param = '&id=' . $object->id;
  126. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  127. }
  128. else
  129. {
  130. dol_print_error($db);
  131. }
  132. }
  133. else
  134. {
  135. print $langs->trans("ErrorUnknown");
  136. }
  137. $db->close();
  138. llxFooter();