note.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  31. if (!empty($conf->projet->enabled)) {
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. }
  34. $langs->loadLangs(array("bills", "companies"));
  35. $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int'));
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. // Security check
  39. if ($user->socid) {
  40. $socid = $user->socid;
  41. }
  42. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  43. $hookmanager->initHooks(array('invoicesuppliernote'));
  44. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  45. $object = new FactureFournisseur($db);
  46. $object->fetch($id, $ref);
  47. $permissionnote = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); // Used by the include of actions_setnotes.inc.php
  48. /*
  49. * Actions
  50. */
  51. $reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks
  52. if ($reshook < 0) {
  53. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  54. }
  55. if (empty($reshook)) {
  56. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  57. }
  58. // Set label
  59. if ($action == 'setlabel' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  60. $object->label = GETPOST('label');
  61. $result = $object->update($user);
  62. if ($result < 0) {
  63. dol_print_error($db);
  64. }
  65. }
  66. /*
  67. * View
  68. */
  69. $form = new Form($db);
  70. $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('Notes');
  71. $helpurl = "EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores";
  72. llxHeader('', $title, $helpurl);
  73. if ($object->id > 0) {
  74. $object->fetch_thirdparty();
  75. $alreadypaid = $object->getSommePaiement();
  76. $head = facturefourn_prepare_head($object);
  77. $titre = $langs->trans('SupplierInvoice');
  78. print dol_get_fiche_head($head, 'note', $titre, -1, 'supplier_invoice');
  79. // Supplier invoice card
  80. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  81. $morehtmlref = '<div class="refidno">';
  82. // Ref supplier
  83. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  84. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  85. // Thirdparty
  86. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  87. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  88. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
  89. }
  90. // Project
  91. if (!empty($conf->projet->enabled)) {
  92. $langs->load("projects");
  93. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  94. if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
  95. if ($action != 'classify') {
  96. // $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  97. $morehtmlref .= ' : ';
  98. }
  99. if ($action == 'classify') {
  100. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  101. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  102. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  103. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  104. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  105. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  106. $morehtmlref .= '</form>';
  107. } else {
  108. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  109. }
  110. } else {
  111. if (!empty($object->fk_project)) {
  112. $proj = new Project($db);
  113. $proj->fetch($object->fk_project);
  114. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  115. if ($proj->title) {
  116. $morehtmlref .= ' - '.$proj->title;
  117. }
  118. } else {
  119. $morehtmlref .= '';
  120. }
  121. }
  122. }
  123. $morehtmlref .= '</div>';
  124. $object->totalpaid = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  125. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  126. print '<div class="fichecenter">';
  127. print '<div class="underbanner clearboth"></div>';
  128. print '<table class="border centpercent tableforfield">';
  129. // Type
  130. print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
  131. print '<span class="badgeneutral">';
  132. print $object->getLibType();
  133. print '</span>';
  134. if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
  135. $facreplaced = new FactureFournisseur($db);
  136. $facreplaced->fetch($object->fk_facture_source);
  137. print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
  138. }
  139. if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  140. $facusing = new FactureFournisseur($db);
  141. $facusing->fetch($object->fk_facture_source);
  142. print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
  143. }
  144. $facidavoir = $object->getListIdAvoirFromInvoice();
  145. if (count($facidavoir) > 0) {
  146. $invoicecredits = array();
  147. foreach ($facidavoir as $facid) {
  148. $facavoir = new FactureFournisseur($db);
  149. $facavoir->fetch($facid);
  150. $invoicecredits[] = $facavoir->getNomUrl(1);
  151. }
  152. print ' ('.$langs->transnoentities("InvoiceHasAvoir") . implode(',', $invoicecredits) . ')';
  153. }
  154. if ($facidnext > 0) {
  155. $facthatreplace = new FactureFournisseur($db);
  156. $facthatreplace->fetch($facidnext);
  157. print ' ('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')';
  158. }
  159. print '</td></tr>';
  160. // Label
  161. print '<tr><td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td><td>';
  162. print $form->editfieldval("Label", 'label', $object->label, $object, 0);
  163. print '</td></tr>';
  164. // Amount
  165. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($object->total_ht, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  166. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  167. // Amount Local Taxes
  168. //TODO: Place into a function to control showing by country or study better option
  169. if ($societe->localtax1_assuj == "1") { //Localtax1
  170. print '<tr><td>'.$langs->transcountry("AmountLT1", $societe->country_code).'</td>';
  171. print '<td>'.price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  172. print '</tr>';
  173. }
  174. if ($societe->localtax2_assuj == "1") { //Localtax2
  175. print '<tr><td>'.$langs->transcountry("AmountLT2", $societe->country_code).'</td>';
  176. print '<td>'.price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency).'</td>';
  177. print '</tr>';
  178. }
  179. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($object->total_ttc, 1, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
  180. print "</table>";
  181. print '<br>';
  182. print '<div class="underbanner clearboth"></div>';
  183. $cssclass = "titlefield";
  184. include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
  185. print dol_get_fiche_end();
  186. }
  187. // End of page
  188. llxFooter();
  189. $db->close();