note.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/fourn/facture/note.php
  24. * \ingroup facture
  25. * \brief Fiche de notes sur une facture fournisseur
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.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. if (isModEnabled('project')) {
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. }
  35. $langs->loadLangs(array("bills", "companies"));
  36. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. // Security check
  40. if ($user->socid) {
  41. $socid = $user->socid;
  42. }
  43. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  44. $hookmanager->initHooks(array('invoicesuppliernote'));
  45. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  46. $object = new FactureFournisseur($db);
  47. $object->fetch($id, $ref);
  48. $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  49. $permissiontoadd = $usercancreate;
  50. $permissionnote = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
  51. /*
  52. * Actions
  53. */
  54. $reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
  55. if ($reshook < 0) {
  56. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  57. }
  58. if (empty($reshook)) {
  59. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  60. }
  61. // Set label
  62. if ($action == 'setlabel' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  63. $object->label = GETPOST('label');
  64. $result = $object->update($user);
  65. if ($result < 0) {
  66. dol_print_error($db);
  67. }
  68. }
  69. /*
  70. * View
  71. */
  72. $form = new Form($db);
  73. $title = $object->ref." - ".$langs->trans('Notes');
  74. $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
  75. llxHeader('', $title, $helpurl);
  76. if ($object->id > 0) {
  77. $object->fetch_thirdparty();
  78. $alreadypaid = $object->getSommePaiement();
  79. $head = facturefourn_prepare_head($object);
  80. $titre = $langs->trans('SupplierInvoice');
  81. print dol_get_fiche_head($head, 'note', $titre, -1, 'supplier_invoice');
  82. // Supplier invoice card
  83. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  84. $morehtmlref = '<div class="refidno">';
  85. // Ref supplier
  86. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  87. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  88. // Thirdparty
  89. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  90. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  91. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  92. }
  93. // Project
  94. if (isModEnabled('project')) {
  95. $langs->load("projects");
  96. $morehtmlref .= '<br>';
  97. if (0) {
  98. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  99. if ($action != 'classify') {
  100. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  101. }
  102. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  103. } else {
  104. if (!empty($object->fk_project)) {
  105. $proj = new Project($db);
  106. $proj->fetch($object->fk_project);
  107. $morehtmlref .= $proj->getNomUrl(1);
  108. if ($proj->title) {
  109. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  110. }
  111. }
  112. }
  113. }
  114. $morehtmlref .= '</div>';
  115. $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  116. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  117. print '<div class="fichecenter">';
  118. print '<div class="underbanner clearboth"></div>';
  119. print '<table class="border centpercent tableforfield">';
  120. // Type
  121. print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
  122. print '<span class="badgeneutral">';
  123. print $object->getLibType();
  124. print '</span>';
  125. if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
  126. $facreplaced = new FactureFournisseur($db);
  127. $facreplaced->fetch($object->fk_facture_source);
  128. print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
  129. }
  130. if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  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. $invoicecredits = array();
  138. foreach ($facidavoir as $facid) {
  139. $facavoir = new FactureFournisseur($db);
  140. $facavoir->fetch($facid);
  141. $invoicecredits[] = $facavoir->getNomUrl(1);
  142. }
  143. print ' ('.$langs->transnoentities("InvoiceHasAvoir") . implode(',', $invoicecredits) . ')';
  144. }
  145. /*
  146. if ($facidnext > 0) {
  147. $facthatreplace = new FactureFournisseur($db);
  148. $facthatreplace->fetch($facidnext);
  149. print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
  150. }
  151. */
  152. print '</td></tr>';
  153. // Label
  154. print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
  155. print $form->editfieldval("Label", 'label', $object->label, $object, 0);
  156. print '</td></tr>';
  157. // Amount
  158. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  159. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  160. // Amount Local Taxes
  161. //TODO: Place into a function to control showing by country or study better option
  162. if ($mysoc->localtax1_assuj == "1") { //Localtax1
  163. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  164. print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  165. print '</tr>';
  166. }
  167. if ($mysoc->localtax2_assuj == "1") { //Localtax2
  168. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  169. print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  170. print '</tr>';
  171. }
  172. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  173. print "</table>";
  174. print '<br>';
  175. print '<div class="underbanner clearboth"></div>';
  176. $cssclass = "titlefield";
  177. include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
  178. print dol_get_fiche_end();
  179. }
  180. // End of page
  181. llxFooter();
  182. $db->close();