document.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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@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. $langs->load('companies');
  38. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  39. $ref=GETPOST('ref','alpha');
  40. $socid=GETPOST('socid','int');
  41. $action=GETPOST('action','alpha');
  42. $confirm=GETPOST('confirm', 'alpha');
  43. // Security check
  44. if ($user->societe_id)
  45. {
  46. $action='';
  47. $socid = $user->societe_id;
  48. }
  49. $result=restrictedArea($user,'facture',$id,'');
  50. // Get parameters
  51. $sortfield = GETPOST("sortfield",'alpha');
  52. $sortorder = GETPOST("sortorder",'alpha');
  53. $page = GETPOST("page",'int');
  54. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  55. $offset = $conf->liste_limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (! $sortorder) $sortorder="ASC";
  59. if (! $sortfield) $sortfield="name";
  60. $object = new Facture($db);
  61. if ($object->fetch($id))
  62. {
  63. $object->fetch_thirdparty();
  64. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  65. }
  66. /*
  67. * Actions
  68. */
  69. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  70. /*
  71. * View
  72. */
  73. $title = $langs->trans('InvoiceCustomer') . " - " . $langs->trans('Documents');
  74. $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  75. llxHeader('', $title, $helpurl);
  76. $form = new Form($db);
  77. if ($id > 0 || ! empty($ref))
  78. {
  79. if ($object->fetch($id,$ref) > 0)
  80. {
  81. $object->fetch_thirdparty();
  82. $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
  83. $head = facture_prepare_head($object);
  84. dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill');
  85. $totalpaye = $object->getSommePaiement();
  86. // Construit liste des fichiers
  87. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  88. $totalsize=0;
  89. foreach($filearray as $key => $file)
  90. {
  91. $totalsize+=$file['size'];
  92. }
  93. // Invoice content
  94. $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  95. $morehtmlref='<div class="refidno">';
  96. // Ref customer
  97. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  98. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  99. // Thirdparty
  100. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  101. // Project
  102. if (! empty($conf->projet->enabled))
  103. {
  104. $langs->load("projects");
  105. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  106. if ($user->rights->facture->creer)
  107. {
  108. if ($action != 'classify')
  109. //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  110. $morehtmlref.=' : ';
  111. if ($action == 'classify') {
  112. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  113. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  114. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  115. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  116. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  117. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  118. $morehtmlref.='</form>';
  119. } else {
  120. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  121. }
  122. } else {
  123. if (! empty($object->fk_project)) {
  124. $proj = new Project($db);
  125. $proj->fetch($object->fk_project);
  126. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  127. $morehtmlref.=$proj->ref;
  128. $morehtmlref.='</a>';
  129. } else {
  130. $morehtmlref.='';
  131. }
  132. }
  133. }
  134. $morehtmlref.='</div>';
  135. $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  136. dol_banner_tab($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref, '', 0);
  137. print '<div class="fichecenter">';
  138. print '<div class="underbanner clearboth"></div>';
  139. print '<table class="border" width="100%">';
  140. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  141. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  142. print "</table>\n";
  143. print "</div>\n";
  144. dol_fiche_end();
  145. $modulepart = 'facture';
  146. $permission = $user->rights->facture->creer;
  147. $permtoedit = $user->rights->facture->creer;
  148. $param = '&id=' . $object->id;
  149. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  150. }
  151. else
  152. {
  153. dol_print_error($db);
  154. }
  155. }
  156. else
  157. {
  158. print $langs->trans("ErrorUnknown");
  159. }
  160. $db->close();
  161. llxFooter();