PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/supplier_order/mod_commande_fournisseur_muguet.php

https://github.com/asterix14/dolibarr
PHP | 137 lines | 70 code | 20 blank | 47 comment | 8 complexity | 8d0c47ea53d0b76989d9a87272677fe6 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  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. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/supplier_order/mod_commande_fournisseur_muguet.php
  21. * \ingroup commande
  22. * \brief Fichier contenant la classe du modele de numerotation de reference de commande fournisseur Muguet
  23. */
  24. require_once(DOL_DOCUMENT_ROOT ."/core/modules/supplier_order/modules_commandefournisseur.php");
  25. /** \class mod_commande_fournisseur_muguet
  26. * \brief Classe du modele de numerotation de reference de commande fournisseur Muguet
  27. */
  28. class mod_commande_fournisseur_muguet extends ModeleNumRefSuppliersOrders
  29. {
  30. var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
  31. var $error = '';
  32. var $nom = 'Muguet';
  33. var $prefix='CF';
  34. /** \brief Return description of numbering module
  35. * \return string Text with description
  36. */
  37. function info()
  38. {
  39. global $langs;
  40. return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
  41. }
  42. /** \brief Renvoi un exemple de numerotation
  43. * \return string Example
  44. */
  45. function getExample()
  46. {
  47. return $this->prefix."0501-0001";
  48. }
  49. /** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
  50. * de conflits qui empechera cette numerotation de fonctionner.
  51. * \return boolean false si conflit, true si ok
  52. */
  53. function canBeActivated()
  54. {
  55. global $conf,$langs;
  56. $coyymm=''; $max='';
  57. $posindice=8;
  58. $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";
  59. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
  60. $sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
  61. $sql.= " AND entity = ".$conf->entity;
  62. $resql=$db->query($sql);
  63. if ($resql)
  64. {
  65. $row = $db->fetch_row($resql);
  66. if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
  67. }
  68. if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
  69. {
  70. return true;
  71. }
  72. else
  73. {
  74. $langs->load("errors");
  75. $this->error=$langs->trans('ErrorNumRefModel',$max);
  76. return false;
  77. }
  78. }
  79. /** \brief Return next value
  80. * \param objsoc Object third party
  81. * \param object Object
  82. * \return string Valeur
  83. */
  84. function getNextValue($objsoc=0,$object='')
  85. {
  86. global $db,$conf;
  87. // D'abord on recupere la valeur max
  88. $posindice=8;
  89. $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";
  90. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
  91. $sql.= " WHERE ref like '".$this->prefix."____-%'";
  92. $sql.= " AND entity = ".$conf->entity;
  93. $resql=$db->query($sql);
  94. if ($resql)
  95. {
  96. $obj = $db->fetch_object($resql);
  97. if ($obj) $max = intval($obj->max);
  98. else $max=0;
  99. }
  100. //$date=time();
  101. $date=$object->date_commande; // Not always defined
  102. if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders
  103. $yymm = strftime("%y%m",$date);
  104. $num = sprintf("%04s",$max+1);
  105. return $this->prefix.$yymm."-".$num;
  106. }
  107. /** \brief Renvoie la reference de commande suivante non utilisee
  108. * \param objsoc Object third party
  109. * \param object Object
  110. * \return string Texte descripif
  111. */
  112. function commande_get_num($objsoc=0,$object='')
  113. {
  114. return $this->getNextValue($objsoc,$object);
  115. }
  116. }
  117. ?>