PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fourn/facture/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 214 lines | 134 code | 35 blank | 45 comment | 30 complexity | 1c74671c4fe0be04807fbcd2662ae435 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/fourn/facture/document.php
  22. * \ingroup facture, fournisseur
  23. * \brief Page de gestion des documents attachees a une facture fournisseur
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. $langs->load('bills');
  33. $langs->load('other');
  34. $langs->load("companies");
  35. $id = GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int');
  36. $action=GETPOST('action','alpha');
  37. $confirm=GETPOST('confirm','alpha');
  38. // Security check
  39. if ($user->societe_id) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture');
  41. // Get parameters
  42. $sortfield = GETPOST("sortfield",'alpha');
  43. $sortorder = GETPOST("sortorder",'alpha');
  44. $page = GETPOST("page",'int');
  45. if ($page == -1) {
  46. $page = 0;
  47. }
  48. $offset = $conf->liste_limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="name";
  53. $object = new FactureFournisseur($db);
  54. if ($object->fetch($id))
  55. {
  56. $object->fetch_thirdparty();
  57. $ref=dol_sanitizeFileName($object->ref);
  58. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref;
  59. }
  60. /*
  61. * Actions
  62. */
  63. // Envoi fichier
  64. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  65. {
  66. if ($object->id > 0) {
  67. dol_add_file_process($upload_dir, 0, 1, 'userfile');
  68. }
  69. }
  70. // Delete
  71. else if ($action == 'confirm_deletefile' && $confirm == 'yes')
  72. {
  73. if ($object->id > 0)
  74. {
  75. $langs->load("other");
  76. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  77. $ret=dol_delete_file($file,0,0,0,$object);
  78. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  79. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  80. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  81. exit;
  82. }
  83. }
  84. /*
  85. * View
  86. */
  87. $form = new Form($db);
  88. llxHeader();
  89. if ($object->id > 0)
  90. {
  91. $head = facturefourn_prepare_head($object);
  92. dol_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), 0, 'bill');
  93. // Construit liste des fichiers
  94. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  95. $totalsize=0;
  96. foreach($filearray as $key => $file)
  97. {
  98. $totalsize+=$file['size'];
  99. }
  100. /*
  101. * Confirm delete file
  102. */
  103. if ($action == 'delete')
  104. {
  105. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  106. if ($ret == 'html') print '<br>';
  107. }
  108. print '<table class="border" width="100%">';
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  110. // Ref
  111. print '<tr><td width="30%" nowrap="nowrap">'.$langs->trans("Ref").'</td><td colspan="3">';
  112. print $form->showrefnav($object, 'facid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  113. print '</td>';
  114. print "</tr>\n";
  115. // Ref supplier
  116. print '<tr><td nowrap="nowrap">'.$langs->trans("RefSupplier").'</td><td colspan="3">'.$object->ref_supplier.'</td>';
  117. print "</tr>\n";
  118. // Thirdparty
  119. print '<tr><td>'.$langs->trans('Supplier').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  120. // Type
  121. print '<tr><td>'.$langs->trans('Type').'</td><td colspan="4">';
  122. print $object->getLibType();
  123. if ($object->type == 1)
  124. {
  125. $facreplaced=new FactureFournisseur($db);
  126. $facreplaced->fetch($object->fk_facture_source);
  127. print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
  128. }
  129. if ($object->type == 2)
  130. {
  131. $facusing=new FactureFournisseur($db);
  132. $facusing->fetch($object->fk_facture_source);
  133. print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
  134. }
  135. $facidavoir=$object->getListIdAvoirFromInvoice();
  136. if (count($facidavoir) > 0)
  137. {
  138. print ' ('.$langs->transnoentities("InvoiceHasAvoir");
  139. $i=0;
  140. foreach($facidavoir as $id)
  141. {
  142. if ($i==0) print ' ';
  143. else print ',';
  144. $facavoir=new FactureFournisseur($db);
  145. $facavoir->fetch($id);
  146. print $facavoir->getNomUrl(1);
  147. }
  148. print ')';
  149. }
  150. if ($facidnext > 0)
  151. {
  152. $facthatreplace=new FactureFournisseur($db);
  153. $facthatreplace->fetch($facidnext);
  154. print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
  155. }
  156. print '</td></tr>';
  157. // Label
  158. print '<tr><td>'.$form->editfieldkey("Label",'label',$object->label,$object,0).'</td><td colspan="3">';
  159. print $form->editfieldval("Label",'label',$object->label,$object,0);
  160. print '</td>';
  161. // Nb of files
  162. print '<tr><td>'.$langs->trans('NbOfAttachedFiles').'</td><td colspan="3">'.count($filearray).'</td></tr>';
  163. print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td colspan="3">'.$totalsize.' '.$langs->trans('bytes').'</td></tr>';
  164. print '</table>';
  165. print '</div>';
  166. // Affiche formulaire upload
  167. $formfile=new FormFile($db);
  168. $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id,'',0,0,$user->rights->fournisseur->facture->creer, 50, $object);
  169. // List of document
  170. $param='&facid='.$object->id;
  171. $formfile->list_of_documents($filearray,$object,'facture_fournisseur',$param,0,get_exdir($object->id,2,0).$object->id.'/');
  172. }
  173. else
  174. {
  175. print $langs->trans('UnkownError');
  176. }
  177. llxFooter();
  178. $db->close();
  179. ?>