facturation_dhtml.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2008-2009 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. * Copyright (C) 2015 Regis Houssin <regis.houssin@inodbox.com>
  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 3 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. */
  19. /**
  20. * \file htdocs/cashdesk/facturation_dhtml.php
  21. * \ingroup cashdesk
  22. * \brief This page is called each time we press a key in the code search form to show product combo list.
  23. */
  24. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  26. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  27. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  28. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  29. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  30. // Change this following line to use the correct relative path (../, ../../, etc)
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php';
  33. top_httphead('text/html');
  34. $search = GETPOST("code", "alpha");
  35. // Search from criteria
  36. if (dol_strlen($search) >= 0) // If search criteria is on char length at least
  37. {
  38. $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
  39. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  40. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  41. if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
  42. $sql.= " WHERE p.entity IN (".getEntity('product').")";
  43. $sql.= " AND p.tosell = 1";
  44. $sql.= " AND p.fk_product_type = 0";
  45. // Add criteria on ref/label
  46. if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
  47. {
  48. $sql.= " AND (p.ref LIKE '".$db->escape($search)."%' OR p.label LIKE '".$db->escape($search)."%'";
  49. if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($search)."%'";
  50. $sql.= ")";
  51. }
  52. else
  53. {
  54. $sql.= " AND (p.ref LIKE '%".$db->escape($search)."%' OR p.label LIKE '%".$db->escape($search)."%'";
  55. if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '%".$db->escape($search)."%'";
  56. $sql.= ")";
  57. }
  58. $sql.= " ORDER BY label";
  59. dol_syslog("facturation_dhtml.php", LOG_DEBUG);
  60. $result = $db->query($sql);
  61. if ($result)
  62. {
  63. if ( $nbr = $db->num_rows($result) )
  64. {
  65. $resultat = '<ul class="dhtml_bloc">';
  66. $ret=array(); $i=0;
  67. while ( $tab = $db->fetch_array($result) )
  68. {
  69. foreach ( $tab as $cle => $valeur )
  70. {
  71. $ret[$i][$cle] = $valeur;
  72. }
  73. $i++;
  74. }
  75. $tab=$ret;
  76. $tab_size=count($tab);
  77. for($i=0;$i < $tab_size;$i++)
  78. {
  79. $resultat .= '
  80. <li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
  81. onMouseOver="javascript: this.className = \'dhtml_selection\';"
  82. onMouseOut="javascript: this.className = \'dhtml_defaut\';"
  83. >'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
  84. ';
  85. }
  86. $resultat .= '</ul>';
  87. print $resultat;
  88. }
  89. else
  90. {
  91. $langs->load("cashdesk");
  92. print '<ul class="dhtml_bloc">';
  93. print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
  94. print '</ul>';
  95. }
  96. }
  97. }