dolibarr  9.0.0
facturation_dhtml.php
Go to the documentation of this file.
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 
27 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
28 if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
29 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
30 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
31 if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
32 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
33 
34 // Change this following line to use the correct relative path (../, ../../, etc)
35 require '../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php';
37 
38 top_httphead('text/html');
39 
40 $search = GETPOST("code", "alpha");
41 
42 // Search from criteria
43 if (dol_strlen($search) >= 0) // If search criteria is on char length at least
44 {
45  $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
46  if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
47  $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
48  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."'";
49  $sql.= " WHERE p.entity IN (".getEntity('product').")";
50  $sql.= " AND p.tosell = 1";
51  $sql.= " AND p.fk_product_type = 0";
52  // Add criteria on ref/label
53  if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
54  {
55  $sql.= " AND (p.ref LIKE '".$db->escape($search)."%' OR p.label LIKE '".$db->escape($search)."%'";
56  if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($search)."%'";
57  $sql.= ")";
58  }
59  else
60  {
61  $sql.= " AND (p.ref LIKE '%".$db->escape($search)."%' OR p.label LIKE '%".$db->escape($search)."%'";
62  if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '%".$db->escape($search)."%'";
63  $sql.= ")";
64  }
65  $sql.= " ORDER BY label";
66 
67  dol_syslog("facturation_dhtml.php", LOG_DEBUG);
68  $result = $db->query($sql);
69 
70  if ($result)
71  {
72  if ( $nbr = $db->num_rows($result) )
73  {
74  $resultat = '<ul class="dhtml_bloc">';
75 
76  $ret=array(); $i=0;
77  while ( $tab = $db->fetch_array($result) )
78  {
79  foreach ( $tab as $cle => $valeur )
80  {
81  $ret[$i][$cle] = $valeur;
82  }
83  $i++;
84  }
85  $tab=$ret;
86 
87  $tab_size=count($tab);
88  for($i=0;$i < $tab_size;$i++)
89  {
90  $resultat .= '
91  <li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
92  onMouseOver="javascript: this.className = \'dhtml_selection\';"
93  onMouseOut="javascript: this.className = \'dhtml_defaut\';"
94  >'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
95  ';
96  }
97 
98  $resultat .= '</ul>';
99 
100  print $resultat;
101  }
102  else
103  {
104  $langs->load("cashdesk");
105 
106  print '<ul class="dhtml_bloc">';
107  print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
108  print '</ul>';
109  }
110  }
111 }
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! defined('NOREQUIREMENU')) if(! function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1107
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.