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