mod_contract_magre.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/contract/mod_contract_magre.php
  20. * \ingroup contract
  21. * \brief File of class to manage contract numbering rules Magre
  22. */
  23. require_once DOL_DOCUMENT_ROOT .'/core/modules/contract/modules_contract.php';
  24. /**
  25. * Class to manage contract numbering rules Magre
  26. */
  27. class mod_contract_magre extends ModelNumRefContracts
  28. {
  29. var $version='dolibarr';
  30. var $error = '';
  31. var $nom = 'Magre';
  32. /**
  33. * Return default description of numbering model
  34. *
  35. * @return string text description
  36. */
  37. function info()
  38. {
  39. global $conf,$langs;
  40. $langs->load("bills");
  41. $form = new Form($this->db);
  42. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  43. $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  44. $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  45. $texte.= '<input type="hidden" name="action" value="updateMask">';
  46. $texte.= '<input type="hidden" name="maskconstcontract" value="CONTRACT_MAGRE_MASK">';
  47. $texte.= '<table class="nobordernopadding" width="100%">';
  48. $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Contract"),$langs->transnoentities("Contract"));
  49. $tooltip.=$langs->trans("GenericMaskCodes2");
  50. $tooltip.=$langs->trans("GenericMaskCodes3");
  51. $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Contract"),$langs->transnoentities("Contract"));
  52. $tooltip.=$langs->trans("GenericMaskCodes5");
  53. $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
  54. $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcontract" value="'.$conf->global->CONTRACT_MAGRE_MASK.'">',$tooltip,1,1).'</td>';
  55. $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
  56. $texte.= '</tr>';
  57. $texte.= '</table>';
  58. $texte.= '</form>';
  59. return $texte;
  60. }
  61. /**
  62. * Return numbering example
  63. *
  64. * @return string Example
  65. */
  66. function getExample()
  67. {
  68. global $conf,$langs,$mysoc;
  69. $old_code_client=$mysoc->code_client;
  70. $mysoc->code_client='CCCCCCCCCC';
  71. $numExample = $this->getNextValue($mysoc,'');
  72. $mysoc->code_client=$old_code_client;
  73. if (! $numExample)
  74. {
  75. $numExample = $langs->trans('NotConfigured');
  76. }
  77. return $numExample;
  78. }
  79. /**
  80. * Return next value
  81. *
  82. * @param Societe $objsoc third party object
  83. * @param Object $contract contract object
  84. * @return string Value if OK, 0 if KO
  85. */
  86. function getNextValue($objsoc,$contract)
  87. {
  88. global $db,$conf;
  89. require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
  90. $mask=$conf->global->CONTRACT_MAGRE_MASK;
  91. if (! $mask)
  92. {
  93. $this->error='NotConfigured';
  94. return 0;
  95. }
  96. $numFinal=get_next_value($db,$mask,'contrat','ref','',$objsoc->code_client,$contract->date_contrat);
  97. return $numFinal;
  98. }
  99. /**
  100. * Return next value
  101. *
  102. * @param Societe $objsoc third party object
  103. * @param Object $objforref contract object
  104. * @return string Value if OK, 0 if KO
  105. */
  106. function contract_get_num($objsoc,$objforref)
  107. {
  108. return $this->getNextValue($objsoc,$objforref);
  109. }
  110. }
  111. ?>