dolibarr  13.0.2
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 <https://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 = '".$db->escape($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  } else {
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  $sql .= " ORDER BY label";
64 
65  dol_syslog("facturation_dhtml.php", LOG_DEBUG);
66  $result = $db->query($sql);
67 
68  if ($result)
69  {
70  if ($nbr = $db->num_rows($result))
71  {
72  $resultat = '<ul class="dhtml_bloc">';
73 
74  $ret = array(); $i = 0;
75  while ($tab = $db->fetch_array($result))
76  {
77  foreach ($tab as $cle => $valeur)
78  {
79  $ret[$i][$cle] = $valeur;
80  }
81  $i++;
82  }
83  $tab = $ret;
84 
85  $tab_size = count($tab);
86  for ($i = 0; $i < $tab_size; $i++)
87  {
88  $resultat .= '
89  <li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
90  onMouseOver="javascript: this.className = \'dhtml_selection\';"
91  onMouseOut="javascript: this.className = \'dhtml_defaut\';"
92  >'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
93  ';
94  }
95 
96  $resultat .= '</ul>';
97 
98  print $resultat;
99  } else {
100  $langs->load("cashdesk");
101 
102  print '<ul class="dhtml_bloc">';
103  print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
104  print '</ul>';
105  }
106  }
107 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1214
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
Definition: index.php:89