PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/facture/note.php

https://github.com/asterix14/dolibarr
PHP | 194 lines | 122 code | 37 blank | 35 comment | 21 complexity | bb224174e08c8b4e17ecf9ee64e8f5fe MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/facture/note.php
  20. * \ingroup facture
  21. * \brief Fiche de notes sur une facture
  22. */
  23. require("../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  25. require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
  26. require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php');
  27. $socid=isset($_GET["socid"])?$_GET["socid"]:isset($_POST["socid"])?$_POST["socid"]:"";
  28. if (!$user->rights->facture->lire)
  29. accessforbidden();
  30. $langs->load("companies");
  31. $langs->load("bills");
  32. // Security check
  33. if ($user->societe_id > 0)
  34. {
  35. unset($_GET["action"]);
  36. $socid = $user->societe_id;
  37. }
  38. $fac = new Facture($db);
  39. $fac->fetch($_GET["facid"]);
  40. /******************************************************************************/
  41. /* Actions */
  42. /******************************************************************************/
  43. if ($_POST["action"] == 'update_public' && $user->rights->facture->creer)
  44. {
  45. $db->begin();
  46. $res=$fac->update_note_public($_POST["note_public"],$user);
  47. if ($res < 0)
  48. {
  49. $mesg='<div class="error">'.$fac->error.'</div>';
  50. $db->rollback();
  51. }
  52. else
  53. {
  54. $db->commit();
  55. }
  56. }
  57. if ($_POST["action"] == 'update' && $user->rights->facture->creer)
  58. {
  59. $db->begin();
  60. $res=$fac->update_note($_POST["note"],$user);
  61. if ($res < 0)
  62. {
  63. $mesg='<div class="error">'.$fac->error.'</div>';
  64. $db->rollback();
  65. }
  66. else
  67. {
  68. $db->commit();
  69. }
  70. }
  71. /******************************************************************************/
  72. /* Affichage fiche */
  73. /******************************************************************************/
  74. llxHeader();
  75. $form = new Form($db);
  76. $id = $_GET['facid'];
  77. $ref= $_GET['ref'];
  78. if ($id > 0 || ! empty($ref))
  79. {
  80. $fac = new Facture($db);
  81. $fac->fetch($id,$ref);
  82. $soc = new Societe($db);
  83. $soc->fetch($fac->socid);
  84. $head = facture_prepare_head($fac);
  85. dol_fiche_head($head, 'note', $langs->trans("InvoiceCustomer"), 0, 'bill');
  86. print '<table class="border" width="100%">';
  87. // Ref
  88. print '<tr><td width="20%">'.$langs->trans('Ref').'</td>';
  89. print '<td colspan="3">';
  90. $morehtmlref='';
  91. $discount=new DiscountAbsolute($db);
  92. $result=$discount->fetch(0,$fac->id);
  93. if ($result > 0)
  94. {
  95. $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
  96. }
  97. if ($result < 0)
  98. {
  99. dol_print_error('',$discount->error);
  100. }
  101. print $form->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref);
  102. print '</td></tr>';
  103. // Company
  104. print '<tr><td>'.$langs->trans("Company").'</td>';
  105. print '<td colspan="3">'.$soc->getNomUrl(1,'compta').'</td>';
  106. // Note publique
  107. print '<tr><td valign="top">'.$langs->trans("NotePublic").' :</td>';
  108. print '<td valign="top" colspan="3">';
  109. if ($_GET["action"] == 'edit')
  110. {
  111. print '<form method="post" action="note.php?facid='.$fac->id.'">';
  112. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  113. print '<input type="hidden" name="action" value="update_public">';
  114. print '<textarea name="note_public" cols="80" rows="8">'.$fac->note_public."</textarea><br>";
  115. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  116. print '</form>';
  117. }
  118. else
  119. {
  120. print ($fac->note_public?nl2br($fac->note_public):"&nbsp;");
  121. }
  122. print "</td></tr>";
  123. // Note priv�e
  124. if (! $user->societe_id)
  125. {
  126. print '<tr><td valign="top">'.$langs->trans("NotePrivate").' :</td>';
  127. print '<td valign="top" colspan="3">';
  128. if ($_GET["action"] == 'edit')
  129. {
  130. print '<form method="post" action="note.php?facid='.$fac->id.'">';
  131. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  132. print '<input type="hidden" name="action" value="update">';
  133. print '<textarea name="note" cols="80" rows="8">'.$fac->note."</textarea><br>";
  134. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  135. print '</form>';
  136. }
  137. else
  138. {
  139. print ($fac->note?nl2br($fac->note):"&nbsp;");
  140. }
  141. print "</td></tr>";
  142. }
  143. print "</table>";
  144. /*
  145. * Actions
  146. */
  147. print '</div>';
  148. print '<div class="tabsAction">';
  149. if ($user->rights->facture->creer && $_GET["action"] <> 'edit')
  150. {
  151. print "<a class=\"butAction\" href=\"note.php?facid=$fac->id&amp;action=edit\">".$langs->trans('Modify')."</a>";
  152. }
  153. print "</div>";
  154. }
  155. $db->close();
  156. llxFooter();
  157. ?>