document.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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@inodbox.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/fourn/facture/document.php
  26. * \ingroup facture, fournisseur
  27. * \brief Page to manage documents joined to vendor invoices
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.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 (!empty($conf->projet->enabled)) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. $langs->loadLangs(array('bills', 'other', 'companies'));
  40. $id = GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int');
  41. $action = GETPOST('action', 'aZ09');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. $ref = GETPOST('ref', 'alpha');
  44. // Security check
  45. if ($user->socid) {
  46. $socid = $user->socid;
  47. }
  48. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  49. $hookmanager->initHooks(array('invoicesuppliercarddocument'));
  50. // Get parameters
  51. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (!$sortorder) {
  62. $sortorder = "ASC";
  63. }
  64. if (!$sortfield) {
  65. $sortfield = "name";
  66. }
  67. $object = new FactureFournisseur($db);
  68. if ($object->fetch($id, $ref)) {
  69. $object->fetch_thirdparty();
  70. $ref = dol_sanitizeFileName($object->ref);
  71. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
  72. }
  73. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
  74. /*
  75. * Actions
  76. */
  77. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  78. /*
  79. * View
  80. */
  81. $form = new Form($db);
  82. $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Documents');
  83. $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
  84. llxHeader('', $title, $helpurl);
  85. if ($object->id > 0) {
  86. $head = facturefourn_prepare_head($object);
  87. print dol_get_fiche_head($head, 'documents', $langs->trans('SupplierInvoice'), -1, 'supplier_invoice');
  88. $totalpaid = $object->getSommePaiement();
  89. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  90. $morehtmlref = '<div class="refidno">';
  91. // Ref supplier
  92. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  93. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  94. // Thirdparty
  95. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  96. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  97. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  98. }
  99. // Project
  100. if (!empty($conf->projet->enabled)) {
  101. $langs->load("projects");
  102. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  103. if ($user->rights->facture->creer) {
  104. if ($action != 'classify') {
  105. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  106. $morehtmlref .= ' : ';
  107. }
  108. if ($action == 'classify') {
  109. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  110. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  111. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  112. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  113. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  114. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  115. $morehtmlref .= '</form>';
  116. } else {
  117. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  118. }
  119. } else {
  120. if (!empty($object->fk_project)) {
  121. $proj = new Project($db);
  122. $proj->fetch($object->fk_project);
  123. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  124. if ($proj->title) {
  125. $morehtmlref .= ' - '.$proj->title;
  126. }
  127. } else {
  128. $morehtmlref .= '';
  129. }
  130. }
  131. }
  132. $morehtmlref .= '</div>';
  133. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  134. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
  135. print '<div class="fichecenter">';
  136. print '<div class="underbanner clearboth"></div>';
  137. // Build file list
  138. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  139. $totalsize = 0;
  140. foreach ($filearray as $key => $file) {
  141. $totalsize += $file['size'];
  142. }
  143. /*
  144. * Confirm delete file
  145. */
  146. if ($action == 'delete') {
  147. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  148. }
  149. print '<table class="border tableforfield centpercent">';
  150. // Type
  151. print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
  152. print '<span class="badgeneutral">';
  153. print $object->getLibType();
  154. print '</span>';
  155. if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
  156. $facreplaced = new FactureFournisseur($db);
  157. $facreplaced->fetch($object->fk_facture_source);
  158. print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
  159. }
  160. if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  161. $facusing = new FactureFournisseur($db);
  162. $facusing->fetch($object->fk_facture_source);
  163. print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
  164. }
  165. $facidavoir = $object->getListIdAvoirFromInvoice();
  166. if (count($facidavoir) > 0) {
  167. $invoicecredits = array();
  168. foreach ($facidavoir as $facid) {
  169. $facavoir = new FactureFournisseur($db);
  170. $facavoir->fetch($facid);
  171. $invoicecredits[] = $facavoir->getNomUrl(1);
  172. }
  173. print ' ('.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits) . ')';
  174. }
  175. /*
  176. if ($facidnext > 0) {
  177. $facthatreplace = new FactureFournisseur($db);
  178. $facthatreplace->fetch($facidnext);
  179. print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
  180. }
  181. */
  182. print '</td></tr>';
  183. // Label
  184. print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
  185. print $form->editfieldval("Label", 'label', $object->label, $object, 0);
  186. print '</td>';
  187. // Amount
  188. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  189. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  190. // Amount Local Taxes
  191. //TODO: Place into a function to control showing by country or study better option
  192. if ($mysoc->localtax1_assuj == "1") { //Localtax1
  193. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  194. print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  195. print '</tr>';
  196. }
  197. if ($mysoc->localtax2_assuj == "1") { //Localtax2
  198. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  199. print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  200. print '</tr>';
  201. }
  202. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  203. print '</table><br>';
  204. print '<div class="underbanner clearboth"></div>';
  205. print '<table class="border tableforfield centpercent">';
  206. // Nb of files
  207. print '<tr><td class="titlefield nowrap">'.$langs->trans('NbOfAttachedFiles').'</td><td>'.count($filearray).'</td></tr>';
  208. print '<tr><td>'.$langs->trans('TotalSizeOfAttachedFiles').'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  209. print '</table>';
  210. print '</div>';
  211. print '<div class="clearboth"></div>';
  212. print dol_get_fiche_end();
  213. $modulepart = 'facture_fournisseur';
  214. $permission = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  215. $permtoedit = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  216. $param = '&facid='.$object->id;
  217. $defaulttpldir = '/core/tpl';
  218. $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
  219. foreach ($dirtpls as $module => $reldir) {
  220. if (!empty($module)) {
  221. $tpl = dol_buildpath($reldir.'/document_actions_post_headers.tpl.php');
  222. } else {
  223. $tpl = DOL_DOCUMENT_ROOT.$reldir.'/document_actions_post_headers.tpl.php';
  224. }
  225. if (empty($conf->file->strict_mode)) {
  226. $res = @include $tpl;
  227. } else {
  228. $res = include $tpl; // for debug
  229. }
  230. if ($res) {
  231. break;
  232. }
  233. }
  234. } else {
  235. print $langs->trans('ErrorUnknown');
  236. }
  237. // End of page
  238. llxFooter();
  239. $db->close();