PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/livraison/mod_livraison_jade.php

https://github.com/asterix14/dolibarr
PHP | 150 lines | 75 code | 22 blank | 53 comment | 8 complexity | 5bc3b1e4022d763755f5b7748eb334a1 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/livraison/mod_livraison_jade.php
  22. * \ingroup delivery
  23. * \brief Fichier contenant la classe du modele de numerotation de reference de bon de livraison Jade
  24. */
  25. require_once(DOL_DOCUMENT_ROOT ."/core/modules/livraison/modules_livraison.php");
  26. /**
  27. * \class mod_livraison_jade
  28. * \brief Classe du modele de numerotation de reference de bon de livraison Jade
  29. */
  30. class mod_livraison_jade extends ModeleNumRefDeliveryOrder
  31. {
  32. var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
  33. var $error = '';
  34. var $nom = "Jade";
  35. var $prefix='BL';
  36. /**
  37. * \brief Renvoi la description du modele de numerotation
  38. * \return string Texte descripif
  39. */
  40. function info()
  41. {
  42. global $langs;
  43. return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
  44. }
  45. /**
  46. * \brief Renvoi un exemple de numerotation
  47. * \return string Example
  48. */
  49. function getExample()
  50. {
  51. return $this->prefix."0501-0001";
  52. }
  53. /** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
  54. * de conflits qui empechera cette numerotation de fonctionner.
  55. * \return boolean false si conflit, true si ok
  56. */
  57. function canBeActivated()
  58. {
  59. global $langs,$conf;
  60. $langs->load("bills");
  61. // Check invoice num
  62. $fayymm=''; $max='';
  63. $posindice=8;
  64. $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
  65. $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
  66. $sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
  67. $sql.= " AND entity = ".$conf->entity;
  68. $resql=$db->query($sql);
  69. if ($resql)
  70. {
  71. $row = $db->fetch_row($resql);
  72. if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
  73. }
  74. if ($fayymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$fayymm))
  75. {
  76. $langs->load("errors");
  77. $this->error=$langs->trans('ErrorNumRefModel',$max);
  78. return false;
  79. }
  80. return true;
  81. }
  82. /**
  83. * \brief Return next value
  84. * \param objsoc Object third party
  85. * \param delivery Object delivery
  86. * \return string Value if OK, 0 if KO
  87. */
  88. function getNextValue($objsoc=0,$delivery='')
  89. {
  90. global $db,$conf;
  91. // D'abord on recupere la valeur max
  92. $posindice=8;
  93. $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
  94. $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
  95. $sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
  96. $sql.= " AND entity = ".$conf->entity;
  97. $resql=$db->query($sql);
  98. dol_syslog("mod_livraison_jade::getNextValue sql=".$sql);
  99. if ($resql)
  100. {
  101. $obj = $db->fetch_object($resql);
  102. if ($obj) $max = intval($obj->max);
  103. else $max=0;
  104. }
  105. else
  106. {
  107. dol_syslog("mod_livraison_jade::getNextValue sql=".$sql, LOG_ERR);
  108. return -1;
  109. }
  110. $date=$delivery->date_delivery;
  111. if (empty($date)) $date=dol_now();
  112. $yymm = strftime("%y%m",$date);
  113. $num = sprintf("%04s",$max+1);
  114. dol_syslog("mod_livraison_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
  115. return $this->prefix.$yymm."-".$num;
  116. }
  117. /**
  118. * \brief Renvoie la reference de commande suivante non utilisee
  119. * \param objsoc Objet societe
  120. * \param livraison Objet livraison
  121. * \return string Texte descripif
  122. */
  123. function livraison_get_num($objsoc=0,$livraison='')
  124. {
  125. return $this->getNextValue($objsoc,$livraison);
  126. }
  127. }
  128. ?>