document.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2021 Jesus Jerez <jesusballesteros@protonmail.com>
  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/paiement/document.php
  26. * \ingroup facture, fournisseur
  27. * \brief Management page of attached documents to a payment
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.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/lib/fourn.lib.php';
  36. if (!empty($conf->projet->enabled)) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('bills', 'banks', 'companies', 'suppliers', 'other'));
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. $action = GETPOST('action', 'aZ09');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. // Security check
  46. if ($user->socid) {
  47. $socid = $user->socid;
  48. }
  49. $result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
  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. // Load object
  68. $object = new PaiementFourn($db);
  69. if ($object->fetch($id, $ref)) {
  70. $object->fetch_thirdparty();
  71. $ref = dol_sanitizeFileName($object->ref);
  72. $upload_dir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
  73. }
  74. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
  75. /*
  76. * Actions
  77. */
  78. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  79. /*
  80. * View
  81. */
  82. $form = new Form($db);
  83. $title = $langs->trans('Payment')." - ".$langs->trans('Documents');
  84. llxHeader('', $title);
  85. if ($object->id > 0) {
  86. $head = payment_supplier_prepare_head($object);
  87. print dol_get_fiche_head($head, 'documents', $langs->trans("SupplierPayment"), -1, 'payment');
  88. // Supplier order card
  89. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  90. $morehtmlref = '<div class="refidno">';
  91. // Date of payment
  92. $morehtmlref .= $form->editfieldkey("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'datehourpicker', '', null, 3).': ';
  93. $morehtmlref .= $form->editfieldval("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
  94. // Payment mode
  95. $morehtmlref .= '<br>'.$langs->trans('PaymentMode').' : ';
  96. $morehtmlref .= $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
  97. $morehtmlref .= $object->num_payment ? ' - '.$object->num_payment : '';
  98. // Thirdparty
  99. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  100. // Amount
  101. $morehtmlref .= '<br>'.$langs->trans('Amount').' : '. price($object->amount, '', $langs, 0, 0, -1, $conf->currency);
  102. $allow_delete = 1;
  103. // Bank account
  104. if (!empty($conf->banque->enabled)) {
  105. if ($object->fk_account) {
  106. $bankline = new AccountLine($db);
  107. $bankline->fetch($object->bank_line);
  108. if ($bankline->rappro) {
  109. $allow_delete = 0;
  110. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
  111. }
  112. $morehtmlref .= '<br>'.$langs->trans('BankAccount').' : ';
  113. $accountstatic = new Account($db);
  114. $accountstatic->fetch($bankline->fk_account);
  115. $morehtmlref .= $accountstatic->getNomUrl(1);
  116. $morehtmlref .= '<br>'.$langs->trans('BankTransactionLine').' : ';
  117. $morehtmlref .= $bankline->getNomUrl(1, 0, 'showconciliated');
  118. }
  119. }
  120. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  121. // Build file list
  122. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  123. $totalsize = 0;
  124. foreach ($filearray as $key => $file) {
  125. $totalsize += $file['size'];
  126. }
  127. print '<div class="fichecenter">';
  128. print '<div class="underbanner clearboth"></div>';
  129. print '<table class="border tableforfield centpercent">';
  130. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  131. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  132. print "</table>\n";
  133. print "</div>\n";
  134. print dol_get_fiche_end();
  135. $modulepart = 'supplier_payment';
  136. // TODO: get the appropriate permission
  137. $permissiontoadd = true;
  138. $permtoedit = true;
  139. $param = '&id='.$object->id;
  140. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  141. } else {
  142. header('Location: index.php');
  143. exit;
  144. }
  145. // End of page
  146. llxFooter();
  147. $db->close();